UNPKG

@base-ui-components/react

Version:

Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.

61 lines (59 loc) 1.9 kB
'use client'; import * as React from 'react'; import { CompositeRoot } from "../../composite/root/CompositeRoot.js"; import { ToolbarRootContext } from "./ToolbarRootContext.js"; /** * A container for grouping a set of controls, such as buttons, toggle groups, or menus. * Renders a `<div>` element. * * Documentation: [Base UI Toolbar](https://base-ui.com/react/components/toolbar) */ import { jsx as _jsx } from "react/jsx-runtime"; export const ToolbarRoot = /*#__PURE__*/React.forwardRef(function ToolbarRoot(componentProps, forwardedRef) { const { disabled = false, loopFocus = true, orientation = 'horizontal', className, render, ...elementProps } = componentProps; const [itemMap, setItemMap] = React.useState(() => new Map()); const disabledIndices = React.useMemo(() => { const output = []; for (const itemMetadata of itemMap.values()) { if (itemMetadata?.index && !itemMetadata.focusableWhenDisabled) { output.push(itemMetadata.index); } } return output; }, [itemMap]); const toolbarRootContext = React.useMemo(() => ({ disabled, orientation, setItemMap }), [disabled, orientation, setItemMap]); const state = React.useMemo(() => ({ disabled, orientation }), [disabled, orientation]); const defaultProps = { 'aria-orientation': orientation, role: 'toolbar' }; return /*#__PURE__*/_jsx(ToolbarRootContext.Provider, { value: toolbarRootContext, children: /*#__PURE__*/_jsx(CompositeRoot, { render: render, className: className, state: state, refs: [forwardedRef], props: [defaultProps, elementProps], disabledIndices: disabledIndices, loopFocus: loopFocus, onMapChange: setItemMap, orientation: orientation }) }); }); if (process.env.NODE_ENV !== "production") ToolbarRoot.displayName = "ToolbarRoot";