UNPKG

@workday/canvas-kit-preview-react

Version:

Canvas Kit Preview is made up of components that have the full design and a11y review, are part of the DS ecosystem and are approved for use in product. The API's could be subject to change, but not without strong communication and migration strategies.

58 lines (57 loc) 2.28 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SegmentedControl = void 0; const react_1 = __importDefault(require("react")); const common_1 = require("@workday/canvas-kit-react/common"); const useSegmentedControlModel_1 = require("./hooks/useSegmentedControlModel"); const SegmentedControlList_1 = require("./SegmentedControlList"); const SegmentedControlItem_1 = require("./SegmentedControlItem"); /** * `SegmentedControl` is a container component that is responsible for creating a * {@link SegmentedControlModel} and sharing it with its subcomponents using React context. It does * not represent a real element. * * ```tsx * <SegmentedControl items={[]}>{Child components}</SegmentedControl> * ``` * * Alternatively, you may pass in a model using the [hoisted model * pattern](/getting-started/for-developers/resources/compound-components/#configuring-a-model). * * ```tsx * const model = useSegmentedControlModel({ * items: [], * }); * * <SegmentedControl model={model}>{Child components}</SegmentedControl>; * ``` */ exports.SegmentedControl = (0, common_1.createContainer)()({ displayName: 'SegmentedControl', modelHook: useSegmentedControlModel_1.useSegmentedControlModel, subComponents: { /** * `SegmentedControl.List` renders {@link Grid} under the hood. It is a container for * {@link SegmentedControlItem SegmentedControl.Item} subcomponents. * * ```tsx * <SegmentedControl.List>{SegmentedControl.Items}</SegmentedControl.List> * ``` */ List: SegmentedControlList_1.SegmentedControlList, /** * `SegmentedControl.Item` is a `button` element built on `BaseButton`. `SegmentedControl.Item` * has a `data-id` prop to handle `onSelect` properly. * * ```tsx * <SegmentedControl.Item data-id="table">Table</SegmentedControl.Item> * ``` */ Item: SegmentedControlItem_1.SegmentedControlItem, }, })(({ children }) => { return react_1.default.createElement(react_1.default.Fragment, null, children); });