Skip to content

Commit b3d1c0c

Browse files
committed
WIP triggers
1 parent 7fb3165 commit b3d1c0c

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed

docs/src/app/(private)/experiments/toolbar/_icons.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,32 @@ export function ChevronRightIcon(props: React.ComponentProps<'svg'>) {
171171
</svg>
172172
);
173173
}
174+
175+
export function MessageCircleIcon(props: React.ComponentProps<'svg'>) {
176+
return (
177+
<svg
178+
xmlns="http://www.w3.org/2000/svg"
179+
width="24"
180+
height="24"
181+
viewBox="0 0 24 24"
182+
{...props}
183+
>
184+
<path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" />
185+
</svg>
186+
);
187+
}
188+
189+
export function MousePointerIcon(props: React.ComponentProps<'svg'>) {
190+
return (
191+
<svg
192+
xmlns="http://www.w3.org/2000/svg"
193+
width="24"
194+
height="24"
195+
viewBox="0 0 24 24"
196+
{...props}
197+
>
198+
<path d="M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z" />
199+
<path d="M13 13l6 6" />
200+
</svg>
201+
);
202+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.Root {
2+
background-color: var(--color-gray-100);
3+
padding: 0 0.75rem;
4+
}
5+
6+
.Toggle {
7+
margin-block: 0.5rem;
8+
}
9+
10+
.Separator[data-orientation='vertical'] {
11+
width: 1px;
12+
align-self: stretch;
13+
background-color: var(--color-gray-200);
14+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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

Comments
 (0)