@dt-dds/react-checkbox
v1.0.0-beta.57
Published
A checkbox toggles between checked and unchecked states, enabling users to make binary choices in forms and settings.
Readme
Checkbox Package
A checkbox toggles between checked and unchecked states, enabling users to make binary choices in forms and settings.
Checkbox Usage
import { Checkbox } from '@dt-dds/react-checkbox';
export const App = () => {
const [checked, setChecked] = React.useState(true);
const handleChange = (evt: React.ChangeEvent<HTMLInputElement>) => {
setChecked(evt.target.checked);
};
return (
<Checkbox isChecked={checked} onChange={handleChange}>
Label
</Checkbox>
);
};Properties
| Property | Type | Default | Description |
| ------------ | ---------------------------------------------- | ------------- | ----------------------------------------------------------------------------- |
| children | ReactNode | - | Child components to be rendered as the label. |
| onChange | (evt: ChangeEvent<HTMLInputElement>) => void | - | The triggered function when the input change. |
| isDisabled | boolean | false | Specifies if the element should be disabled. |
| isChecked | boolean | false | Specifies if the element should be pre-selected (checked) when the page loads |
| dataTestId | string | checkbox-id | Customizable test identifier |
Note
In addition to the above properties, this component also accepts all standard props of an input element.
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 testRun 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.
checkbox
└── dist
├── index.d.ts <-- Types
├── index.js <-- CommonJS version
└── index.mjs <-- ES Modules version
...Versioning
Follows semantic versioning
© License
Licensed under MIT License
