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 30, 2023
1 parent ebf161b commit 2e05b28
Show file tree
Hide file tree
Showing 2 changed files with 1,238 additions and 1,084 deletions.
42 changes: 36 additions & 6 deletions test/sandbox.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import { createPortal } from 'react-dom'
import React, { useState } from 'react'
import Swal from 'sweetalert2/dist/sweetalert2.all'
import withReactContent from '../src/index'
import { DayPicker } from 'react-day-picker'
import 'react-day-picker/dist/style.css'

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 2e05b28

Please sign in to comment.