@wedgekit/toggle
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

Toggle

Purpose

The Toggle is a styled HTML button which allows the user to switch between two pre-defined options.

import Toggle from '@wedgekit/toggle';

const Example = () => {
  const [value, setValue] = React.useState(1);

  return (
    <Toggle
      options={[
        { label: 'One', value: 1 },
        { label: 'Two', value: 2 },
      ]}
      value={value}
      onChange={setValue}
    />
  );
};

render(<Example />);

Props

options

Type: [{ label: string, value: unknown}, { label: string, value: unknown}]

Required:

A tuple representing the two toggle possibilities. The label is what will be displayed on the toggle button to the user. The value is used internally to determine which option is selected. It is typically a string but can be anything. Label and value can be the same value if desired.

value

Type: any

Required:

The selected value for the toggle. It must correspond to one of the values of the options tuple.

onChange

Type: (value: any) => void

Required:

The callback when the toggle is clicked. It will pass the value of the new option.

Further Reading

  • More advanced use cases documentation can be found here

/@wedgekit/toggle/

    Package Sidebar

    Install

    npm i @wedgekit/toggle

    Weekly Downloads

    0

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    10.1 kB

    Total Files

    13

    Last publish

    Collaborators

    • asayles-dmsi
    • tprettyman
    • rnimrod
    • jquerijero
    • brent-heavican
    • msuiter
    • rerskine
    • timmy2654
    • jfiller
    • mada1113
    • kolson
    • dreadman3716