# Checkbox
URL: /lynx/components/checkbox
Source: https://github.com/daangn/seed-design/blob/dev/docs/content/lynx/components/checkbox.mdx
A component that allows users to select one or more options. It is used for selecting multiple items in a list or for optional actions such as terms and conditions agreement.
Lynx Engine 최소 버전: 3.6
사용 가능 버전: @seed-design/lynx-react@0.1.0, @seed-design/lynx-css@0.1.0
## Preview
```tsx
import "./styles";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import { Checkbox, CheckboxGroup } from "@/components/ui/checkbox";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
Icon colors are not applied in the document preview. You can check the actual icon colors by running Lynx Explorer in the QR code tab.
## Installation
- npm: npx @seed-design/cli@latest add ui:checkbox
- pnpm: pnpm dlx @seed-design/cli@latest add ui:checkbox
- yarn: yarn dlx @seed-design/cli@latest add ui:checkbox
- bun: bun x @seed-design/cli@latest add ui:checkbox
## Props
### `CheckboxGroup`
### `Checkbox`
### `Checkmark`
### Accessibility Name
`Checkbox.Root` is exposed as an accessibility element by default. It also passes the `checkbox` role and the current checked state and disabled state. When you pass a string `label` to Registry `Checkbox`, the screen text is also connected to `accessibility-label`. When composing text with a non-string `label` or `children`, pass the same content directly to `accessibility-label`.
## Examples
### Sizes
```tsx
import "./styles";
import { HStack, useSeedClassName } from "@seed-design/lynx-react";
import { Checkbox, CheckboxGroup } from "@/components/ui/checkbox";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
### Tones and Variants
#### Brand
```tsx
import "./styles";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import { Checkbox, CheckboxGroup } from "@/components/ui/checkbox";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
#### Neutral
```tsx
import "./styles";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import { Checkbox, CheckboxGroup } from "@/components/ui/checkbox";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
### Indeterminate
```tsx
import "./styles";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import { Checkbox } from "@/components/ui/checkbox";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
### Weights
```tsx
import "./styles";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import { Checkbox, CheckboxGroup } from "@/components/ui/checkbox";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
### Long Label
```tsx
import "./styles";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import { Checkbox, CheckboxGroup } from "@/components/ui/checkbox";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
### Disabled
```tsx
import "./styles";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import { Checkbox, CheckboxGroup } from "@/components/ui/checkbox";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
### Listening to Value Changes
You can detect checkbox state changes with `onCheckedChange`.
```tsx
import "./styles";
import { useState } from "@lynx-js/react";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import { Checkbox } from "@/components/ui/checkbox";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
const [count, setCount] = useState(0);
const [lastValue, setLastValue] = useState(null);
function handleCheckedChange(checked: boolean) {
"background only";
setCount((previous) => previous + 1);
setLastValue(checked);
}
return (
onCheckedChange called: {count} times, last value:{" "}
{lastValue === null ? "-" : JSON.stringify(lastValue)}
);
}
```
### Use Cases
#### Using `Checkmark`
Lynx Registry's `Checkmark` includes its own `Checkbox.Root`. When used standalone, pass `accessibility-label`. To put the text in the same tap area, use `children` of Registry `Checkbox`. In this case, also pass `accessibility-label` directly.
```tsx
import "./styles";
import { HStack, Text, useSeedClassName } from "@seed-design/lynx-react";
import { Checkbox } from "@/components/ui/checkbox";
interface CustomCheckboxProps {
label: string;
textStyle: "t7Regular" | "t7Medium" | "t7Bold";
defaultChecked?: boolean;
}
function CustomCheckbox({ label, textStyle, defaultChecked }: CustomCheckboxProps) {
return (
{label}
);
}
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
### Fieldset Integration
You can use `CheckboxGroup` to group multiple checkboxes and use Fieldset-related props such as `label`, `description`, and `errorMessage`.
```tsx
import "./styles";
import { useState } from "@lynx-js/react";
import { ActionButton, HStack, VStack, useSeedClassName } from "@seed-design/lynx-react";
import { Checkbox, CheckboxGroup } from "@/components/ui/checkbox";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
const [apple, setApple] = useState(true);
const [banana, setBanana] = useState(false);
const [orange, setOrange] = useState(false);
const [firstErrorMessage, setFirstErrorMessage] = useState();
const [terms, setTerms] = useState(false);
const [privacy, setPrivacy] = useState(true);
const [marketing, setMarketing] = useState(false);
const [secondErrorMessage, setSecondErrorMessage] = useState();
const handleFirstSubmit = () => {
setFirstErrorMessage(apple ? "Apple은 선택할 수 없습니다." : undefined);
};
const handleSecondSubmit = () => {
setSecondErrorMessage(!terms || !privacy ? "필수 항목에 동의해 주세요." : undefined);
};
return (
제출
제출
);
}
```
## Differences from Web Version
Lynx `Checkbox` has the following differences from React `Checkbox`:
- **Icon injection method**: The `Checkbox` and `Checkmark` in the snippet automatically inject check / minus icons from `@karrotmarket/lynx-monochrome-icon`. When directly composing the compound component, you must pass a Lynx monochrome icon to `Checkbox.Indicator`. Raw `
## Lynx Unsupported Features
The following features are currently not supported due to Lynx platform constraints.
### Excluded due to Runtime Model Difference
| Feature | Web Equivalent | Description |
| --------------------------------------------------------------- | -------------------------------------- | ------------------------------------------------------------------ |
| `CheckboxHiddenInput` | `` | No HTML form submission model in Lynx |
| `inputProps` | hidden input props | Lynx snippet does not render hidden input |
| Individual `Checkbox` `name` / `value` / `required` / `invalid` | form field props | No native form submission model in Lynx |
| React Hook Form example | HTML form and hidden input integration | Must directly connect app state with `checked` / `onCheckedChange` |
| `focus` / `focusVisible` | Keyboard focus | No keyboard focus concept in Lynx |
| `onChange` (raw DOM event) | `React.ChangeEvent` | Not applicable. Replaced with `onCheckedChange` |
| `weight="default"` / `"stronger"` | deprecated compatibility mapping | Lynx only exposes `"regular"` / `"bold"` |