Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Toggle][ToggleGroup] Create Toggle and ToggleGroup #763

Merged
merged 46 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
19e65d2
Add ToggleButton component and hooks
mj12albert Oct 28, 2024
b8fe44c
Update dir structure
mj12albert Oct 29, 2024
23d35f2
Add ToggleButtonGroup
mj12albert Oct 29, 2024
5d3ceab
Add tests for composite
mj12albert Oct 25, 2024
405c854
Add isRtl prop to CompositeRoot for lists only
mj12albert Nov 5, 2024
f50c212
Add RTL support
mj12albert Nov 6, 2024
f62060a
Simplify value type
mj12albert Nov 8, 2024
b00d92e
Update docs
mj12albert Nov 8, 2024
d431760
Rename isRtl to rtl
mj12albert Nov 11, 2024
8d02970
data-highlighted
mj12albert Nov 11, 2024
f824a81
Rename direction prop to dir
mj12albert Nov 18, 2024
d65fe40
Merge remote-tracking branch 'upstream/master' into feat/toggle-button
mj12albert Nov 19, 2024
adfa26c
No need to pass dir prop to Composite
mj12albert Nov 19, 2024
5ac2910
Fix data-highlighted
mj12albert Nov 19, 2024
0fff41b
Merge remote-tracking branch 'upstream/master' into feat/toggle-button
mj12albert Nov 20, 2024
fea48bd
Fix conflicts
mj12albert Nov 20, 2024
50c3932
Merge remote-tracking branch 'upstream/master' into feat/toggle-button
mj12albert Nov 21, 2024
957eeb4
Revert "Rename direction prop to dir"
mj12albert Nov 21, 2024
5335ee4
Use Composite for RTL detection
mj12albert Nov 21, 2024
91c25e6
Merge remote-tracking branch 'upstream/master' into feat/toggle-button
mj12albert Nov 21, 2024
5ee7939
Move to new package dir
mj12albert Nov 21, 2024
815ebe2
Merge remote-tracking branch 'upstream/master' into feat/toggle-button
mj12albert Nov 21, 2024
4ff9fc2
Fix proptypes and docs
mj12albert Nov 21, 2024
e0296ad
Fix eslint
mj12albert Nov 21, 2024
264d067
Merge remote-tracking branch 'upstream/master' into feat/toggle-button
mj12albert Nov 22, 2024
c732f08
Merge remote-tracking branch 'upstream/master' into feat/toggle-button
mj12albert Nov 25, 2024
e754568
Merge remote-tracking branch 'upstream/master' into feat/toggle-button
mj12albert Nov 27, 2024
cd1fc79
Update casing
mj12albert Nov 27, 2024
bfa2774
Update RTL handling
mj12albert Nov 27, 2024
f1e3786
Merge remote-tracking branch 'upstream/master' into feat/toggle-button
mj12albert Nov 28, 2024
2a5089a
Merge remote-tracking branch 'upstream/master' into feat/toggle-button
mj12albert Nov 29, 2024
f715087
Make hook params required
mj12albert Nov 29, 2024
41e343e
Merge remote-tracking branch 'upstream/master' into feat/toggle-button
mj12albert Dec 1, 2024
cc42da7
Merge remote-tracking branch 'upstream/master' into feat/toggle-button
mj12albert Dec 2, 2024
04e8057
Merge remote-tracking branch 'upstream/master' into feat/toggle-button
mj12albert Dec 2, 2024
f887a05
Merge remote-tracking branch 'upstream/master' into feat/toggle-button
mj12albert Dec 2, 2024
4248ce8
Merge remote-tracking branch 'upstream/master' into feat/toggle-button
mj12albert Dec 2, 2024
2d8ec7e
Simplify API
mj12albert Dec 2, 2024
7e9c9a9
Rename components
mj12albert Dec 2, 2024
98746a3
Allow any for value
mj12albert Dec 2, 2024
33893f8
Update docs
mj12albert Dec 3, 2024
54ecce7
Merge remote-tracking branch 'upstream/master' into feat/toggle-button
mj12albert Dec 3, 2024
8d57a75
Merge remote-tracking branch 'upstream/master' into feat/toggle-button
mj12albert Dec 3, 2024
039e083
Merge remote-tracking branch 'upstream/master' into feat/toggle-button
mj12albert Dec 3, 2024
f668074
Fixes
mj12albert Dec 3, 2024
5a051ba
Merge remote-tracking branch 'upstream/master' into feat/toggle-button
mj12albert Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/data/api/toggle-group-root.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"props": {
"className": { "type": { "name": "union", "description": "func<br>&#124;&nbsp;string" } },
"defaultValue": { "type": { "name": "arrayOf", "description": "Array&lt;string&gt;" } },
"onValueChange": {
"type": { "name": "func" },
"signature": {
"type": "function(groupValue: Array<any>, event: Event) => void",
"describedArgs": ["groupValue", "event"]
}
},
"render": { "type": { "name": "union", "description": "element<br>&#124;&nbsp;func" } },
"toggleMultiple": { "type": { "name": "bool" }, "default": "false" },
"value": { "type": { "name": "arrayOf", "description": "Array&lt;string&gt;" } }
},
"name": "ToggleGroupRoot",
"imports": [
"import { ToggleGroup } from '@base-ui-components/react/toggle-group';\nconst ToggleGroupRoot = ToggleGroup.Root;"
],
"classes": [],
"spread": true,
"themeDefaultProps": true,
"muiName": "ToggleGroupRoot",
"forwardsRefTo": "HTMLDivElement",
"filename": "/packages/react/src/toggle-group/root/ToggleGroupRoot.tsx",
"inheritance": null,
"demos": "<ul><li><a href=\"/components/react-toggle-group/\">ToggleGroup</a></li></ul>",
"cssComponent": false
}
32 changes: 32 additions & 0 deletions docs/data/api/toggle-root.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"props": {
"aria-label": { "type": { "name": "string" } },
"aria-labelledby": { "type": { "name": "string" } },
"className": { "type": { "name": "union", "description": "func<br>&#124;&nbsp;string" } },
"defaultPressed": { "type": { "name": "bool" }, "default": "false" },
"disabled": { "type": { "name": "bool" }, "default": "false" },
"onPressedChange": {
"type": { "name": "func" },
"default": "NOOP",
"signature": {
"type": "function(pressed: boolean, event: Event) => void",
"describedArgs": ["pressed", "event"]
}
},
"pressed": { "type": { "name": "bool" }, "default": "undefined" },
"render": { "type": { "name": "union", "description": "element<br>&#124;&nbsp;func" } }
},
"name": "ToggleRoot",
"imports": [
"import { Toggle } from '@base-ui-components/react/toggle';\nconst ToggleRoot = Toggle.Root;"
],
"classes": [],
"spread": true,
"themeDefaultProps": true,
"muiName": "ToggleRoot",
"forwardsRefTo": "HTMLButtonElement",
"filename": "/packages/react/src/toggle/root/ToggleRoot.tsx",
"inheritance": null,
"demos": "<ul><li><a href=\"/components/react-toggle/\">Toggle</a></li></ul>",
"cssComponent": false
}
74 changes: 74 additions & 0 deletions docs/data/components/toggle-group/ToggleGroupIntroduction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'use client';
import * as React from 'react';
import { ToggleGroup } from '@base-ui-components/react/toggle-group';
import { Toggle } from '@base-ui-components/react/toggle';
import classes from './styles.module.css';

export default function ToggleGroupIntroduction() {
const [value, setValue] = React.useState(['align-center']);
return (
<ToggleGroup
className={classes.root}
value={value}
onValueChange={(newValue) => {
if (newValue.length > 0) {
setValue(newValue);
}
}}
aria-label="Text alignment"
>
<Toggle className={classes.button} value="align-left" aria-label="Align left">
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
className={classes.icon}
>
<line x1="17" y1="10" x2="3" y2="10" />
<line x1="21" y1="6" x2="3" y2="6" />
<line x1="21" y1="14" x2="3" y2="14" />
<line x1="17" y1="18" x2="3" y2="18" />
</svg>
</Toggle>

<Toggle
className={classes.button}
value="align-center"
aria-label="Align center"
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
className={classes.icon}
>
<line x1="18" y1="10" x2="6" y2="10" />
<line x1="21" y1="6" x2="3" y2="6" />
<line x1="21" y1="14" x2="3" y2="14" />
<line x1="18" y1="18" x2="6" y2="18" />
</svg>
</Toggle>

<Toggle
className={classes.button}
value="align-right"
aria-label="Align right"
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
className={classes.icon}
>
<line x1="21" y1="10" x2="7" y2="10" />
<line x1="21" y1="6" x2="3" y2="6" />
<line x1="21" y1="14" x2="3" y2="14" />
<line x1="21" y1="18" x2="7" y2="18" />
</svg>
</Toggle>
</ToggleGroup>
);
}
74 changes: 74 additions & 0 deletions docs/data/components/toggle-group/ToggleGroupIntroduction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'use client';
import * as React from 'react';
import { ToggleGroup } from '@base-ui-components/react/toggle-group';
import { Toggle } from '@base-ui-components/react/toggle';
import classes from './styles.module.css';

export default function ToggleGroupIntroduction() {
const [value, setValue] = React.useState(['align-center']);
return (
<ToggleGroup
className={classes.root}
value={value}
onValueChange={(newValue) => {
if (newValue.length > 0) {
setValue(newValue);
}
}}
aria-label="Text alignment"
>
<Toggle className={classes.button} value="align-left" aria-label="Align left">
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
className={classes.icon}
>
<line x1="17" y1="10" x2="3" y2="10" />
<line x1="21" y1="6" x2="3" y2="6" />
<line x1="21" y1="14" x2="3" y2="14" />
<line x1="17" y1="18" x2="3" y2="18" />
</svg>
</Toggle>

<Toggle
className={classes.button}
value="align-center"
aria-label="Align center"
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
className={classes.icon}
>
<line x1="18" y1="10" x2="6" y2="10" />
<line x1="21" y1="6" x2="3" y2="6" />
<line x1="21" y1="14" x2="3" y2="14" />
<line x1="18" y1="18" x2="6" y2="18" />
</svg>
</Toggle>

<Toggle
className={classes.button}
value="align-right"
aria-label="Align right"
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
className={classes.icon}
>
<line x1="21" y1="10" x2="7" y2="10" />
<line x1="21" y1="6" x2="3" y2="6" />
<line x1="21" y1="14" x2="3" y2="14" />
<line x1="21" y1="18" x2="7" y2="18" />
</svg>
</Toggle>
</ToggleGroup>
);
}
59 changes: 59 additions & 0 deletions docs/data/components/toggle-group/ToggleGroupToggleMultiple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use client';
import * as React from 'react';
import { ToggleGroup } from '@base-ui-components/react/toggle-group';
import { Toggle } from '@base-ui-components/react/toggle';
import classes from './styles.module.css';

export default function ToggleGroupToggleMultiple() {
return (
<ToggleGroup
toggleMultiple
aria-label="Text formatting"
className={classes.root}
>
<Toggle value="bold" aria-label="Toggle bold" className={classes.button}>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
className={classes.icon}
>
<path d="M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" />
<path d="M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" />
</svg>
</Toggle>

<Toggle value="italics" aria-label="Toggle italics" className={classes.button}>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
className={classes.icon}
>
<line x1="19" y1="4" x2="10" y2="4" />
<line x1="14" y1="20" x2="5" y2="20" />
<line x1="15" y1="4" x2="9" y2="20" />
</svg>
</Toggle>

<Toggle
value="underline"
aria-label="Toggle underline"
className={classes.button}
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
className={classes.icon}
>
<path d="M6 3v7a6 6 0 0 0 6 6 6 6 0 0 0 6-6V3" />
<line x1="4" y1="21" x2="20" y2="21" />
</svg>
</Toggle>
</ToggleGroup>
);
}
59 changes: 59 additions & 0 deletions docs/data/components/toggle-group/ToggleGroupToggleMultiple.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use client';
import * as React from 'react';
import { ToggleGroup } from '@base-ui-components/react/toggle-group';
import { Toggle } from '@base-ui-components/react/toggle';
import classes from './styles.module.css';

export default function ToggleGroupToggleMultiple() {
return (
<ToggleGroup
toggleMultiple
aria-label="Text formatting"
className={classes.root}
>
<Toggle value="bold" aria-label="Toggle bold" className={classes.button}>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
className={classes.icon}
>
<path d="M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" />
<path d="M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" />
</svg>
</Toggle>

<Toggle value="italics" aria-label="Toggle italics" className={classes.button}>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
className={classes.icon}
>
<line x1="19" y1="4" x2="10" y2="4" />
<line x1="14" y1="20" x2="5" y2="20" />
<line x1="15" y1="4" x2="9" y2="20" />
</svg>
</Toggle>

<Toggle
value="underline"
aria-label="Toggle underline"
className={classes.button}
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
className={classes.icon}
>
<path d="M6 3v7a6 6 0 0 0 6 6 6 6 0 0 0 6-6V3" />
<line x1="4" y1="21" x2="20" y2="21" />
</svg>
</Toggle>
</ToggleGroup>
);
}
66 changes: 66 additions & 0 deletions docs/data/components/toggle-group/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
.root {
display: flex;
}

.button {
--size: 2.5rem;
--corner-radius: 0.4rem;
--border-color: var(--gray-outline-2);
--border-radius-right: 0 var(--corner-radius) var(--corner-radius) 0;
--border-radius-left: var(--corner-radius) 0 0 var(--corner-radius);

display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
height: var(--size);
width: var(--size);
border: 1px solid var(--border-color);
background-color: var(--gray-container-2);
color: var(--gray-400);
}

.button:first-child {
border-radius: var(--border-radius-left);
border-inline-end-color: transparent;
}

.button:last-child {
border-radius: var(--border-radius-right);
border-inline-start-color: transparent;
}

.button:first-child:dir(rtl) {
border-radius: var(--border-radius-right);
}

.button:last-child:dir(rtl) {
border-radius: var(--border-radius-left);
}

.button:not(:disabled):hover {
background-color: var(--gray-surface-1);
outline: 1px solid var(--gray-500);
outline-offset: -1px;
color: var(--gray-text-2);
cursor: pointer;
z-index: 1;
}

.button:focus-visible {
outline: 2px solid var(--color-violet);
z-index: 1;
}

.icon {
fill: none;
stroke: currentColor;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
}

.button[data-pressed] {
background-color: #fefefe;
color: var(--gray-text-2);
}
Loading
Loading