@dt-dds/react-segmented-control
v1.0.0-beta.44
Published
Segmented Control is frequently used to let users toggle between different formatting or to filter, like a grid view and a table view.
Downloads
1,162
Readme
SegmentedControl Package
Segmented Control is frequently used to let users toggle between different formatting or to filter, like a grid view and a table view.
SegmentedControl Usage
import { SegmentedControl } from '@dt-dds/react-segmented-control';
export const App = () => {
return (
<SegmentedControl
selectedValue='list'
showLabel={false}
onChangeControl={handleChanges}
>
<SegmentedControl.Option label='List' value='list' iconCode='list' />
<SegmentedControl.Option
label='Gallery'
value='gallery'
iconCode='grid_view'
disabled
/>
</SegmentedControl>
);
};SegmentedControl Properties
| Property | Type | Default | Description |
| ----------------- | ---------- | ------- | ------------------------------------------------------------ |
| selectedValue | string | - | sets the selected value, useful to fulfill the initial value |
| showLabel | boolean | false | makes the labels visible or not for all options |
| onChangeControl | function | - | callback function to receive the control value changed |
| dataTestId | string | - | sets the id for testing purposes |
SegmentedControl.Option Properties
| Property | Type | Default | Description |
| ---------- | --------- | ------- | ----------------------------------------------------------------------------- |
| label | string | - | sets the option label, visible when showLabel is true or the icon is missing |
| value | string | false | value to control the option |
| iconCode | Code | - | sets the code for the icon to be used, check the package from @dt-dds/icons |
| disabled | boolean | false | disables the option |
Stack
- TypeScript for static type checking
- React — JavaScript library for user interfaces
- Emotion — for writing css styles with JavaScript
- Storybook — UI component environment powered by Vite
- Jest - JavaScript Testing Framework
- React Testing Library - to test UI components in a user-centric way
- ESLint for code linting
- Prettier for code formatting
- Tsup — TypeScript bundler powered by esbuild
- Yarn from managing packages
Commands
yarn build- Build the packageyarn dev- Run the package locallyyarn lint- Lint all files within this packageyarn test- Run all unit testsyarn test:report- Open the test coverage reportyarn test:update:snapshot- Run all unit tests and update the snapshot
Compilation
Running yarn build from the root of the package will use tsup to compile the raw TypeScript and React code to plain JavaScript.
The /dist folder contains the compiled output.
segmented-control
└── dist
├── index.d.ts <-- Types
├── index.js <-- CommonJS version
└── index.mjs <-- ES Modules version
...Versioning
Follows semantic versioning
© License
Licensed under MIT License
