diff --git a/docs/data/api/toggle-button-group-item.json b/docs/data/api/toggle-button-group-item.json new file mode 100644 index 0000000000..beedd1982d --- /dev/null +++ b/docs/data/api/toggle-button-group-item.json @@ -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
| string" } }, + "onPressedChange": { + "type": { "name": "func" }, + "signature": { + "type": "function(pressed: boolean, event: Event) => void", + "describedArgs": ["pressed", "event"] + } + }, + "render": { "type": { "name": "union", "description": "element
| 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": "", + "cssComponent": false +} diff --git a/docs/data/api/toggle-button-group-root.json b/docs/data/api/toggle-button-group-root.json new file mode 100644 index 0000000000..ea5ac76f12 --- /dev/null +++ b/docs/data/api/toggle-button-group-root.json @@ -0,0 +1,33 @@ +{ + "props": { + "className": { "type": { "name": "union", "description": "func
| string" } }, + "defaultValue": { "type": { "name": "arrayOf", "description": "Array<string>" } }, + "direction": { + "type": { "name": "enum", "description": "'ltr'
| 'rtl'" }, + "default": "'ltr'" + }, + "onValueChange": { + "type": { "name": "func" }, + "signature": { + "type": "function(groupValue: Array, event: Event) => void", + "describedArgs": ["groupValue", "event"] + } + }, + "render": { "type": { "name": "union", "description": "element
| func" } }, + "toggleMultiple": { "type": { "name": "bool" }, "default": "false" }, + "value": { "type": { "name": "arrayOf", "description": "Array<string>" } } + }, + "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": "", + "cssComponent": false +} diff --git a/docs/data/api/toggle-button-root.json b/docs/data/api/toggle-button-root.json new file mode 100644 index 0000000000..b06930d80e --- /dev/null +++ b/docs/data/api/toggle-button-root.json @@ -0,0 +1,31 @@ +{ + "props": { + "aria-label": { "type": { "name": "string" } }, + "aria-labelledby": { "type": { "name": "string" } }, + "className": { "type": { "name": "union", "description": "func
| 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
| 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": "", + "cssComponent": false +} diff --git a/docs/data/api/toggle-button.json b/docs/data/api/toggle-button.json new file mode 100644 index 0000000000..57fdd49d01 --- /dev/null +++ b/docs/data/api/toggle-button.json @@ -0,0 +1,29 @@ +{ + "props": { + "aria-label": { "type": { "name": "string" } }, + "aria-labelledby": { "type": { "name": "string" } }, + "className": { "type": { "name": "union", "description": "func
| 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
| 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": "", + "cssComponent": false +} diff --git a/docs/data/components/toggle-button-group/ToggleButtonGroupIntroduction.js b/docs/data/components/toggle-button-group/ToggleButtonGroupIntroduction.js new file mode 100644 index 0000000000..6245721b16 --- /dev/null +++ b/docs/data/components/toggle-button-group/ToggleButtonGroupIntroduction.js @@ -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 ( + { + if (newValue.length > 0) { + setValue(newValue); + } + }} + aria-label="Text alignment" + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); +} diff --git a/docs/data/components/toggle-button-group/ToggleButtonGroupIntroduction.tsx b/docs/data/components/toggle-button-group/ToggleButtonGroupIntroduction.tsx new file mode 100644 index 0000000000..6245721b16 --- /dev/null +++ b/docs/data/components/toggle-button-group/ToggleButtonGroupIntroduction.tsx @@ -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 ( + { + if (newValue.length > 0) { + setValue(newValue); + } + }} + aria-label="Text alignment" + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); +} diff --git a/docs/data/components/toggle-button-group/ToggleButtonGroupRtl.js b/docs/data/components/toggle-button-group/ToggleButtonGroupRtl.js new file mode 100644 index 0000000000..56fe6c7c82 --- /dev/null +++ b/docs/data/components/toggle-button-group/ToggleButtonGroupRtl.js @@ -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 ( +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ ); +} diff --git a/docs/data/components/toggle-button-group/ToggleButtonGroupRtl.tsx b/docs/data/components/toggle-button-group/ToggleButtonGroupRtl.tsx new file mode 100644 index 0000000000..56fe6c7c82 --- /dev/null +++ b/docs/data/components/toggle-button-group/ToggleButtonGroupRtl.tsx @@ -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 ( +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ ); +} diff --git a/docs/data/components/toggle-button-group/ToggleButtonGroupToggleMultiple.js b/docs/data/components/toggle-button-group/ToggleButtonGroupToggleMultiple.js new file mode 100644 index 0000000000..1cdc80bfab --- /dev/null +++ b/docs/data/components/toggle-button-group/ToggleButtonGroupToggleMultiple.js @@ -0,0 +1,66 @@ +'use client'; +import * as React from 'react'; +import { ToggleButtonGroup } from '@base-ui-components/react/ToggleButtonGroup'; +import classes from './styles.module.css'; + +export default function ToggleButtonGroupToggleMultiple() { + return ( + + + + + + + + + + + + + + + + + + + + + + + + ); +} diff --git a/docs/data/components/toggle-button-group/ToggleButtonGroupToggleMultiple.tsx b/docs/data/components/toggle-button-group/ToggleButtonGroupToggleMultiple.tsx new file mode 100644 index 0000000000..1cdc80bfab --- /dev/null +++ b/docs/data/components/toggle-button-group/ToggleButtonGroupToggleMultiple.tsx @@ -0,0 +1,66 @@ +'use client'; +import * as React from 'react'; +import { ToggleButtonGroup } from '@base-ui-components/react/ToggleButtonGroup'; +import classes from './styles.module.css'; + +export default function ToggleButtonGroupToggleMultiple() { + return ( + + + + + + + + + + + + + + + + + + + + + + + + ); +} diff --git a/docs/data/components/toggle-button-group/styles.module.css b/docs/data/components/toggle-button-group/styles.module.css new file mode 100644 index 0000000000..b0d9b09e68 --- /dev/null +++ b/docs/data/components/toggle-button-group/styles.module.css @@ -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-right-color: transparent; +} + +.button:last-child { + border-radius: var(--border-radius-right); + border-left-color: transparent; +} + +[dir='rtl'] .button:first-child { + border-radius: var(--border-radius-right); +} + +[dir='rtl'] .button:last-child { + 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); +} diff --git a/docs/data/components/toggle-button-group/toggle-button-group.mdx b/docs/data/components/toggle-button-group/toggle-button-group.mdx new file mode 100644 index 0000000000..adc563dd8e --- /dev/null +++ b/docs/data/components/toggle-button-group/toggle-button-group.mdx @@ -0,0 +1,134 @@ +--- +productId: base-ui +title: React ToggleButtonGroup component +description: ToggleButtonGroup provides a set of two-state buttons that can either be off (not pressed) or on (pressed). +components: ToggleButtonGroupRoot, ToggleButtonGroupItem +githubLabel: 'component: toggle button' +waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/radio-group/ +packageName: '@base-ui-components/react' +--- + +# ToggleButtonGroup + + + + + + + +## Installation + + + +## Anatomy + +ToggleButtonGroups are composed with two components: + +- `` is the outer component that wraps a set of [`toggle buttons`](/components/react-toggle-button) +- ``s renders the `