2.0.0 • Published 2 years ago

@wedgekit/toggle v2.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

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
2.0.0

2 years ago

1.0.1

2 years ago

1.0.0

3 years ago

0.2.0

3 years ago

0.1.5-tc.0

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3-tc.0

3 years ago

0.1.2

3 years ago

0.1.3

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago