diff --git a/docs/data/api/toggle-group-root.json b/docs/data/api/toggle-group-root.json new file mode 100644 index 0000000000..afefa1e06c --- /dev/null +++ b/docs/data/api/toggle-group-root.json @@ -0,0 +1,29 @@ +{ + "props": { + "className": { "type": { "name": "union", "description": "func
| string" } }, + "defaultValue": { "type": { "name": "arrayOf", "description": "Array<string>" } }, + "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": "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": "", + "cssComponent": false +} diff --git a/docs/data/api/toggle-root.json b/docs/data/api/toggle-root.json new file mode 100644 index 0000000000..21a8f85ef2 --- /dev/null +++ b/docs/data/api/toggle-root.json @@ -0,0 +1,32 @@ +{ + "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" }, + "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
| 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": "", + "cssComponent": false +} diff --git a/docs/data/components/toggle-group/ToggleGroupIntroduction.js b/docs/data/components/toggle-group/ToggleGroupIntroduction.js new file mode 100644 index 0000000000..1f22e0675c --- /dev/null +++ b/docs/data/components/toggle-group/ToggleGroupIntroduction.js @@ -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 ( + { + if (newValue.length > 0) { + setValue(newValue); + } + }} + aria-label="Text alignment" + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); +} diff --git a/docs/data/components/toggle-group/ToggleGroupIntroduction.tsx b/docs/data/components/toggle-group/ToggleGroupIntroduction.tsx new file mode 100644 index 0000000000..1f22e0675c --- /dev/null +++ b/docs/data/components/toggle-group/ToggleGroupIntroduction.tsx @@ -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 ( + { + if (newValue.length > 0) { + setValue(newValue); + } + }} + aria-label="Text alignment" + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); +} diff --git a/docs/data/components/toggle-group/ToggleGroupToggleMultiple.js b/docs/data/components/toggle-group/ToggleGroupToggleMultiple.js new file mode 100644 index 0000000000..703e565e84 --- /dev/null +++ b/docs/data/components/toggle-group/ToggleGroupToggleMultiple.js @@ -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 ( + + + + + + + + + + + + + + + + + + + + + + + + ); +} diff --git a/docs/data/components/toggle-group/ToggleGroupToggleMultiple.tsx b/docs/data/components/toggle-group/ToggleGroupToggleMultiple.tsx new file mode 100644 index 0000000000..703e565e84 --- /dev/null +++ b/docs/data/components/toggle-group/ToggleGroupToggleMultiple.tsx @@ -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 ( + + + + + + + + + + + + + + + + + + + + + + + + ); +} diff --git a/docs/data/components/toggle-group/styles.module.css b/docs/data/components/toggle-group/styles.module.css new file mode 100644 index 0000000000..d2d07bcd2d --- /dev/null +++ b/docs/data/components/toggle-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-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); +} diff --git a/docs/data/components/toggle-group/toggle-group.mdx b/docs/data/components/toggle-group/toggle-group.mdx new file mode 100644 index 0000000000..18abca9987 --- /dev/null +++ b/docs/data/components/toggle-group/toggle-group.mdx @@ -0,0 +1,120 @@ +--- +productId: base-ui +title: React ToggleGroup component +description: ToggleGroup provides a set of two-state buttons that can either be off (not pressed) or on (pressed). +components: ToggleGroupRoot +githubLabel: 'component: toggle button' +waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/radio-group/ +packageName: '@base-ui-components/react' +--- + +# ToggleGroup + + + + + + + +## Installation + + + +## Anatomy + +ToggleGroups are composed with two components: + +- `` is the outer component that wraps a set of [`toggles`](/components/react-toggle) +- ``s renders the `