Skip to content

Commit

Permalink
chore: upd sandbox to use createPortal
Browse files Browse the repository at this point in the history
  • Loading branch information
limonte committed Oct 31, 2023
1 parent ebf161b commit 428def7
Show file tree
Hide file tree
Showing 2 changed files with 1,235 additions and 1,084 deletions.
39 changes: 33 additions & 6 deletions test/sandbox.jsx
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 />)
Loading

0 comments on commit 428def7

Please sign in to comment.