A checkbox toggles between checked and unchecked states, enabling users to make binary choices in forms and settings.
npm install @dt-dds/react-checkboxA checkbox toggles between checked and unchecked states, enabling users to make binary choices in forms and settings.
``jsx
import { Checkbox } from '@dt-dds/react-checkbox';
import { useState } from 'react';
export const App = () => {
const [checked, setChecked] = useState(false);
const handleChange = (evt) => {
setChecked(evt.target.checked);
};
return (
Accept terms and conditions
);
};
`
`jsx
const [checkedItems, setCheckedItems] = useState([false, false, false]);
const allChecked = checkedItems.every(Boolean);
const isIndeterminate = checkedItems.some(Boolean) && !allChecked;
indeterminate={isIndeterminate}
onChange={(e) => setCheckedItems([e.target.checked, e.target.checked, e.target.checked])}
>
Select all
`
| Property | Type | Default | Description |
|--------------------|-----------------------------------------------|---------------|-----------------------------------------------------------------------------|
| isChecked | boolean | — | Controls the checked state |(evt: ChangeEvent
| onChange | | — | Callback fired when the state changes. |boolean
| isDisabled | | false | If true, the checkbox is disabled. |boolean
| isIndeterminate | | false | If true, the checkbox appears in an indeterminate state. |boolean
| hasError | | false | If true, the checkbox displays an error state. |'small' \| 'large'
| size | | 'large' | Size of the checkbox. |ReactNode
| label | | — | Text or elements to display as the label. |ReactNode
| children | | — | Alternative way to provide label content. |string
| dataTestId | | 'checkbox' | Test identifier for testing libraries. |string
| id | | — | HTML id attribute for the input element. |string
| aria-label | | — | Accessibility label (required if no label or children provided). |CSSProperties
| style | | — | Inline styles for the wrapper. |Ref
| ref | | — | Ref forwarded to the input element. |
In addition to the above properties, this component also accepts all standard props of an input element.
- 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
- 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
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.
`bash``
checkbox
└── dist
├── index.d.ts <-- Types
├── index.js <-- CommonJS version
└── index.mjs <-- ES Modules version
...
Follows semantic versioning
Licensed under MIT License