-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: upd sandbox to use createPortal
- Loading branch information
Showing
2 changed files
with
1,235 additions
and
1,084 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,38 @@ | ||
import React from 'react' | ||
import { createPortal } from 'react-dom' | ||
import React, { useState } from 'react' | ||
import Swal from 'sweetalert2/dist/sweetalert2.all' | ||
import withReactContent from '../src/index' | ||
|
||
let MySwal = withReactContent(Swal) | ||
|
||
MySwal.fire({ | ||
icon: 'success', | ||
title: <i>Test</i>, | ||
html: <i>Hello World</i>, | ||
}) | ||
function App() { | ||
const [swalShown, setSwalShown] = useState(false) | ||
const [inputValue, setInputValue] = useState('') | ||
|
||
function showSwal() { | ||
MySwal.fire({ | ||
didOpen: () => setSwalShown(true), | ||
didClose: () => setSwalShown(false), | ||
confirmButtonText: <i>Submit</i>, | ||
}) | ||
} | ||
|
||
return ( | ||
<> | ||
<button onClick={() => showSwal()}>show swal</button> | ||
{swalShown && ( | ||
<> | ||
{createPortal(inputValue, Swal.getTitle())} | ||
{createPortal( | ||
<input className="swal2-input" value={inputValue} onChange={(e) => setInputValue(e.target.value)} />, | ||
Swal.getHtmlContainer() | ||
)} | ||
{createPortal(inputValue.length, Swal.getFooter())} | ||
</> | ||
)} | ||
<div>input value: {inputValue}</div> | ||
</> | ||
) | ||
} | ||
|
||
ReactDOM.createRoot(document.getElementById('root')).render(<App />) |
Oops, something went wrong.