UNPKG

@workday/canvas-kit-docs

Version:

Documentation components of Canvas Kit components

84 lines (50 loc) 2.39 kB
import {ExampleCodeBlock, Specifications, SymbolDoc} from '@workday/canvas-kit-docs'; import Basic from './examples/Basic'; import Caution from './examples/Caution'; import Disabled from './examples/Disabled'; import Error from './examples/Error'; import LabelPosition from './examples/LabelPosition'; import RTL from './examples/RTL'; import RefForwarding from './examples/RefForwarding'; # Canvas Kit Switch Switch is a selection control that is used to switch between two potential states. ## Installation ```sh yarn add @workday/canvas-kit-preview-react ``` ## Usage ### Basic Example Switch should be used in tandem with [Form Field](/components/inputs/form-field/) to meet accessibility standards. <ExampleCodeBlock code={Basic} /> ### Disabled Set the `disabled` prop of the Switch to prevent users from interacting with it. <ExampleCodeBlock code={Disabled} /> ### Ref Forwarding Switch supports [ref forwarding](https://reactjs.org/docs/forwarding-refs.html). It will forward `ref` to its underlying `<input type="checkbox">` element. <ExampleCodeBlock code={RefForwarding} /> ### Label Position Horizontal Set the `orientation` prop of the Form Field to designate the position of the label relative to the input component. By default, the orientation will be set to `vertical`. <ExampleCodeBlock code={LabelPosition} /> ### Error States Set the `error` prop of the wrapping Form Field to `"caution"` or `"error"` to set the Switch to the Caution or Error state, respectively. You will also need to use `<FormField.Hint/>` for hint or error text to meet accessibility standards. The `error` prop may be applied directly to the Switch with a value of `Switch.ErrorType.Caution` or `Switch.ErrorType.Error` if Form Field is not being used. #### Caution <ExampleCodeBlock code={Caution} /> #### Error <ExampleCodeBlock code={Error} /> ### Right-to-Left (RTL) Switch supports right-to-left languages when specified in the CanvasProvider theme. <ExampleCodeBlock code={RTL} /> ### Custom Styles Switch supports custom styling via the `cs` prop. For more information, check our ["How To Customize Styles"](https://workday.github.io/canvas-kit/?path=/docs/styling-guides-customizing-styles--docs). ## Component API <SymbolDoc name="Switch" fileName="/react/" /> ## Specifications <Specifications file="./cypress/component/Switch.spec.tsx" name="Switch" />