|
| 1 | +import React, { useState } from 'react' |
| 2 | +import { createRoot } from 'react-dom/client' |
| 3 | +import LoadingIndicator from '../../../../vendor/filament/support/resources/js/react/LoadingIndicator' |
| 4 | + |
| 5 | +function LoadingIndicatorReact() { |
| 6 | + const [size, setSize] = useState('md') |
| 7 | + const [loading, setLoading] = useState(true) |
| 8 | + const [accent, setAccent] = useState(false) |
| 9 | + return ( |
| 10 | + <div className="loading-indicator-demo" data-framework="react"> |
| 11 | + <h2 className="fi-section-header-heading">React · JavaScript</h2> |
| 12 | + <div role="status" className="loading-indicator-demo-status"> |
| 13 | + {loading && ( |
| 14 | + <LoadingIndicator |
| 15 | + size={size} |
| 16 | + className={ |
| 17 | + accent ? 'loading-indicator-demo-accent' : undefined |
| 18 | + } |
| 19 | + /> |
| 20 | + )} |
| 21 | + <span> |
| 22 | + {loading |
| 23 | + ? 'Preparing your report…' |
| 24 | + : 'Your report is ready'} |
| 25 | + </span> |
| 26 | + </div> |
| 27 | + <div className="loading-indicator-demo-controls"> |
| 28 | + <label> |
| 29 | + Size{' '} |
| 30 | + <select |
| 31 | + value={size} |
| 32 | + onChange={(event) => setSize(event.target.value)} |
| 33 | + > |
| 34 | + {['xs', 'sm', 'md', 'lg', 'xl', '2xl'].map((size) => ( |
| 35 | + <option key={size}>{size}</option> |
| 36 | + ))} |
| 37 | + </select> |
| 38 | + </label> |
| 39 | + <label> |
| 40 | + <input |
| 41 | + type="checkbox" |
| 42 | + checked={loading} |
| 43 | + onChange={(event) => setLoading(event.target.checked)} |
| 44 | + />{' '} |
| 45 | + Loading |
| 46 | + </label> |
| 47 | + <label> |
| 48 | + <input |
| 49 | + type="checkbox" |
| 50 | + checked={accent} |
| 51 | + onChange={(event) => setAccent(event.target.checked)} |
| 52 | + />{' '} |
| 53 | + Theme accent |
| 54 | + </label> |
| 55 | + </div> |
| 56 | + <button |
| 57 | + type="button" |
| 58 | + className="fi-btn fi-size-sm" |
| 59 | + onClick={() => { |
| 60 | + setSize('md') |
| 61 | + setLoading(true) |
| 62 | + setAccent(false) |
| 63 | + }} |
| 64 | + > |
| 65 | + Reset |
| 66 | + </button> |
| 67 | + </div> |
| 68 | + ) |
| 69 | +} |
| 70 | + |
| 71 | +export default function mountLoadingIndicatorReact({ |
| 72 | + host, |
| 73 | + props: initialProps, |
| 74 | +}) { |
| 75 | + const root = createRoot(host) |
| 76 | + const update = (props) => root.render(<LoadingIndicatorReact {...props} />) |
| 77 | + update(initialProps) |
| 78 | + |
| 79 | + return { update, destroy: () => root.unmount() } |
| 80 | +} |
0 commit comments