|
| 1 | +'use client'; |
| 2 | +import * as React from 'react'; |
| 3 | +import { Toolbar } from '@base-ui-components/react/toolbar'; |
| 4 | +import { Toggle } from '@base-ui-components/react/toggle'; |
| 5 | +import { Switch } from '@base-ui-components/react/switch'; |
| 6 | +import { Dialog } from '@base-ui-components/react/dialog'; |
| 7 | +import toolbarClasses from './toolbar.module.css'; |
| 8 | +import triggerToolbarClasses from './triggers.module.css'; |
| 9 | +import switchClasses from '../../../(public)/(content)/react/components/switch/demos/hero/css-modules/index.module.css'; |
| 10 | +import dialogClasses from '../../../(public)/(content)/react/components/alert-dialog/demos/hero/css-modules/index.module.css'; |
| 11 | +import popoverClasses from '../../../(public)/(content)/react/components/popover/demos/hero/css-modules/index.module.css'; |
| 12 | +import { MessageCircleIcon } from './_icons'; |
| 13 | + |
| 14 | +const styles = { |
| 15 | + demo: triggerToolbarClasses, |
| 16 | + toolbar: toolbarClasses, |
| 17 | + switch: switchClasses, |
| 18 | + dialog: dialogClasses, |
| 19 | +}; |
| 20 | + |
| 21 | +const TEXT = `Shows toolbar buttons as various triggers: |
| 22 | +- Menu.Trigger |
| 23 | +- Dialog.Trigger |
| 24 | +- Popover.Trigger |
| 25 | +`; |
| 26 | + |
| 27 | +const DISABLED = false; |
| 28 | + |
| 29 | +function classNames(...c: Array<string | undefined | null | false>) { |
| 30 | + return c.filter(Boolean).join(' '); |
| 31 | +} |
| 32 | + |
| 33 | +export default function App() { |
| 34 | + return ( |
| 35 | + <React.Fragment> |
| 36 | + <a |
| 37 | + className={styles.toolbar.a} |
| 38 | + href="https://www.w3.org/WAI/ARIA/apg/patterns/toolbar/" |
| 39 | + target="_blank" |
| 40 | + rel="noreferrer" |
| 41 | + > |
| 42 | + <h3 className={styles.toolbar.h3}>Toolbar pattern</h3> |
| 43 | + </a> |
| 44 | + <div className={styles.toolbar.Wrapper}> |
| 45 | + <Toolbar.Root className={classNames(styles.toolbar.Root, styles.demo.Root)}> |
| 46 | + <Dialog.Root> |
| 47 | + <Toolbar.Button |
| 48 | + disabled={DISABLED} |
| 49 | + className={classNames(styles.toolbar.Toggle, styles.demo.Toggle)} |
| 50 | + render={ |
| 51 | + <Dialog.Trigger> |
| 52 | + <MessageCircleIcon className={styles.toolbar.Icon} /> |
| 53 | + </Dialog.Trigger> |
| 54 | + } |
| 55 | + /> |
| 56 | + |
| 57 | + <Dialog.Portal keepMounted> |
| 58 | + <Dialog.Backdrop className={styles.dialog.Backdrop} /> |
| 59 | + <Dialog.Popup className={styles.dialog.Popup}> |
| 60 | + <Dialog.Title className={styles.dialog.Title}> |
| 61 | + Write a comment |
| 62 | + </Dialog.Title> |
| 63 | + <textarea name="" id="" className={styles.toolbar.Textarea} /> |
| 64 | + <div className={styles.dialog.Actions}> |
| 65 | + <Dialog.Close data-color="red" className={styles.dialog.Button}> |
| 66 | + Close |
| 67 | + </Dialog.Close> |
| 68 | + <Dialog.Close className={styles.dialog.Button}> |
| 69 | + Submit |
| 70 | + </Dialog.Close> |
| 71 | + </div> |
| 72 | + </Dialog.Popup> |
| 73 | + </Dialog.Portal> |
| 74 | + </Dialog.Root> |
| 75 | + |
| 76 | + <Toolbar.Separator className={styles.demo.Separator} /> |
| 77 | + |
| 78 | + <Toolbar.Button |
| 79 | + disabled={DISABLED} |
| 80 | + className={classNames(styles.toolbar.Toggle, styles.demo.Toggle)} |
| 81 | + render={ |
| 82 | + <Switch.Root defaultChecked className={styles.switch.Switch}> |
| 83 | + <Switch.Thumb |
| 84 | + className={styles.switch.Thumb} |
| 85 | + style={{ marginRight: 'auto' }} |
| 86 | + /> |
| 87 | + </Switch.Root> |
| 88 | + } |
| 89 | + /> |
| 90 | + </Toolbar.Root> |
| 91 | + |
| 92 | + <textarea |
| 93 | + className={styles.toolbar.Textarea} |
| 94 | + name="" |
| 95 | + id="" |
| 96 | + rows={8} |
| 97 | + defaultValue={TEXT} |
| 98 | + /> |
| 99 | + </div> |
| 100 | + </React.Fragment> |
| 101 | + ); |
| 102 | +} |
0 commit comments