|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <title>Base UI Radio Group</title> |
| 6 | + <style> |
| 7 | + body { font-family: Arial, sans-serif; padding: 20px; } |
| 8 | + [role="radiogroup"] { display: flex; gap: 8px; margin-bottom: 20px; } |
| 9 | + [role="radio"] { display: inline-block; padding: 8px 12px; border: 1px solid #ccc; border-radius: 4px; background: #fff; cursor: pointer; } |
| 10 | + [role="radio"][aria-checked="true"] { background: #333; color: #fff; } |
| 11 | + #result { font-family: monospace; } |
| 12 | + </style> |
| 13 | + <script type="importmap"> |
| 14 | + {"imports": { |
| 15 | + "react": "https://esm.sh/react@19.2.0", |
| 16 | + "react/jsx-runtime": "https://esm.sh/react@19.2.0/jsx-runtime", |
| 17 | + "react-dom": "https://esm.sh/react-dom@19.2.0", |
| 18 | + "react-dom/client": "https://esm.sh/react-dom@19.2.0/client" |
| 19 | + }} |
| 20 | + </script> |
| 21 | +</head> |
| 22 | +<body> |
| 23 | + <h1>Base UI Radio Group</h1> |
| 24 | + <div id="root"></div> |
| 25 | + <div id="result"></div> |
| 26 | + <script type="module"> |
| 27 | + import * as React from 'react' |
| 28 | + import { createRoot } from 'react-dom/client' |
| 29 | + import { RadioGroup } from 'https://esm.sh/@base-ui-components/react@1.0.0-rc.0/radio-group?external=react,react-dom' |
| 30 | + import { Radio } from 'https://esm.sh/@base-ui-components/react@1.0.0-rc.0/radio?external=react,react-dom' |
| 31 | +
|
| 32 | + const h = React.createElement |
| 33 | +
|
| 34 | + function App() { |
| 35 | + const [density, setDensity] = React.useState('comfortable') |
| 36 | + const [theme, setTheme] = React.useState('light') |
| 37 | +
|
| 38 | + React.useEffect(() => { |
| 39 | + document.getElementById('result').textContent = `density: ${density}, theme: ${theme}` |
| 40 | + window.__ready = true |
| 41 | + }, [density, theme]) |
| 42 | +
|
| 43 | + return h(React.Fragment, null, |
| 44 | + h(RadioGroup, { 'aria-label': 'Density', value: density, onValueChange: setDensity }, |
| 45 | + h(Radio.Root, { value: 'compact-mode' }, 'Compact mode'), |
| 46 | + h(Radio.Root, { value: 'compact' }, 'Compact'), |
| 47 | + h(Radio.Root, { value: 'comfortable' }, 'Comfortable')), |
| 48 | + h('h3', { id: 'theme-label' }, 'Theme'), |
| 49 | + h(RadioGroup, { 'aria-labelledby': 'theme-label', value: theme, onValueChange: setTheme }, |
| 50 | + h(Radio.Root, { value: 'light' }, 'Light'), |
| 51 | + h(Radio.Root, { value: 'dark' }, 'Dark'), |
| 52 | + h(Radio.Root, { value: 'system' }, 'System'))) |
| 53 | + } |
| 54 | +
|
| 55 | + createRoot(document.getElementById('root')).render(h(App)) |
| 56 | + </script> |
| 57 | +</body> |
| 58 | +</html> |
0 commit comments