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

[ToggleButton][ToggleButtonGroup] Create ToggleButton and ToggleButtonGroup #763

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 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
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-button-group-item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"props": {
"value": { "type": { "name": "string" }, "required": true },
"aria-label": { "type": { "name": "string" } },
"aria-labelledby": { "type": { "name": "string" } },
"className": { "type": { "name": "union", "description": "func<br>&#124;&nbsp;string" } },
"onPressedChange": {
"type": { "name": "func" },
"signature": {
"type": "function(pressed: boolean, event: Event) => void",
"describedArgs": ["pressed", "event"]
}
},
"render": { "type": { "name": "union", "description": "element<br>&#124;&nbsp;func" } }
},
"name": "ToggleButtonGroupItem",
"imports": [
"import { ToggleButtonGroup } from '@base-ui-components/react/ToggleButtonGroup';\nconst ToggleButtonGroupItem = ToggleButtonGroup.Item;"
],
"classes": [],
"spread": true,
"themeDefaultProps": true,
"muiName": "ToggleButtonGroupItem",
"forwardsRefTo": "HTMLButtonElement",
"filename": "/packages/react/src/ToggleButtonGroup/Item/ToggleButtonGroupItem.tsx",
"inheritance": null,
"demos": "<ul><li><a href=\"/components/react-toggle-button-group/\">ToggleButtonGroup</a></li></ul>",
"cssComponent": false
}
33 changes: 33 additions & 0 deletions docs/data/api/toggle-button-group-root.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"props": {
"className": { "type": { "name": "union", "description": "func<br>&#124;&nbsp;string" } },
"defaultValue": { "type": { "name": "arrayOf", "description": "Array&lt;string&gt;" } },
"direction": {
"type": { "name": "enum", "description": "'ltr'<br>&#124;&nbsp;'rtl'" },
"default": "'ltr'"
},
"onValueChange": {
"type": { "name": "func" },
"signature": {
"type": "function(groupValue: Array<string>, 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": "ToggleButtonGroupRoot",
"imports": [
"import { ToggleButtonGroup } from '@base-ui-components/react/ToggleButtonGroup';\nconst ToggleButtonGroupRoot = ToggleButtonGroup.Root;"
],
"classes": [],
"spread": true,
"themeDefaultProps": true,
"muiName": "ToggleButtonGroupRoot",
"forwardsRefTo": "HTMLDivElement",
"filename": "/packages/react/src/ToggleButtonGroup/Root/ToggleButtonGroupRoot.tsx",
"inheritance": null,
"demos": "<ul><li><a href=\"/components/react-toggle-button-group/\">ToggleButtonGroup</a></li></ul>",
"cssComponent": false
}
31 changes: 31 additions & 0 deletions docs/data/api/toggle-button-root.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"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" },
"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": "ToggleButtonRoot",
"imports": [
"import { ToggleButton } from '@base-ui-components/react/ToggleButton';\nconst ToggleButtonRoot = ToggleButton.Root;"
],
"classes": [],
"spread": true,
"themeDefaultProps": true,
"muiName": "ToggleButtonRoot",
"forwardsRefTo": "HTMLButtonElement",
"filename": "/packages/react/src/ToggleButton/Root/ToggleButtonRoot.tsx",
"inheritance": null,
"demos": "<ul><li><a href=\"/components/react-toggle-button/\">ToggleButton</a></li></ul>",
"cssComponent": false
}
29 changes: 29 additions & 0 deletions docs/data/api/toggle-button.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"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" },
"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": "ToggleButton",
"imports": ["import { ToggleButton } from '@base-ui-components/react/ToggleButton';"],
"classes": [],
"spread": true,
"themeDefaultProps": true,
"muiName": "ToggleButton",
"forwardsRefTo": "HTMLButtonElement",
"filename": "/packages/mui-base/src/ToggleButton/ToggleButton.tsx",
"inheritance": null,
"demos": "<ul><li><a href=\"/components/react-toggle-button/\">ToggleButton</a></li></ul>",
"cssComponent": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
'use client';
import * as React from 'react';
import { ToggleButtonGroup } from '@base-ui-components/react/ToggleButtonGroup';
import classes from './styles.module.css';

export default function ToggleButtonGroupIntroduction() {
const [value, setValue] = React.useState(['align-center']);
return (
<ToggleButtonGroup.Root
className={classes.root}
value={value}
onValueChange={(newValue) => {
if (newValue.length > 0) {
setValue(newValue);
}
}}
aria-label="Text alignment"
>
<ToggleButtonGroup.Item
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>
</ToggleButtonGroup.Item>

<ToggleButtonGroup.Item
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>
</ToggleButtonGroup.Item>

<ToggleButtonGroup.Item
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>
</ToggleButtonGroup.Item>
</ToggleButtonGroup.Root>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
'use client';
import * as React from 'react';
import { ToggleButtonGroup } from '@base-ui-components/react/ToggleButtonGroup';
import classes from './styles.module.css';

export default function ToggleButtonGroupIntroduction() {
const [value, setValue] = React.useState(['align-center']);
return (
<ToggleButtonGroup.Root
className={classes.root}
value={value}
onValueChange={(newValue) => {
if (newValue.length > 0) {
setValue(newValue);
}
}}
aria-label="Text alignment"
>
<ToggleButtonGroup.Item
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>
</ToggleButtonGroup.Item>

<ToggleButtonGroup.Item
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>
</ToggleButtonGroup.Item>

<ToggleButtonGroup.Item
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>
</ToggleButtonGroup.Item>
</ToggleButtonGroup.Root>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use client';
import * as React from 'react';
import { ToggleButtonGroup } from '@base-ui-components/react/ToggleButtonGroup';
import classes from './styles.module.css';

export default function ToggleButtonGroupRtl() {
return (
<div dir="rtl">
<ToggleButtonGroup.Root
toggleMultiple
aria-label="Text formatting"
className={classes.root}
>
<ToggleButtonGroup.Item
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>
</ToggleButtonGroup.Item>

<ToggleButtonGroup.Item
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>
</ToggleButtonGroup.Item>

<ToggleButtonGroup.Item
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>
</ToggleButtonGroup.Item>
</ToggleButtonGroup.Root>
</div>
);
}
Loading
Loading