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.
@seed-design/lynx-react@0.1.0, @seed-design/lynx-css@0.1.0
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 (
< view className = { `${ seedClassName } docs-lynx-checkbox-root` }>
< VStack className = "checkbox-preview" >
< CheckboxGroup
label = "관심 분야"
description = "관심 있는 분야를 모두 선택해 주세요."
indicator = "선택"
>
< Checkbox label = "디자인" tone = "neutral" size = "large" />
< Checkbox label = "개발" tone = "neutral" size = "large" defaultChecked />
< Checkbox label = "마케팅" tone = "neutral" size = "large" />
</ CheckboxGroup >
</ VStack >
</ view >
);
}
npx @seed-design/cli@latest add ui:checkbox pnpm dlx @seed-design/cli@latest add ui:checkbox yarn dlx @seed-design/cli@latest add ui:checkbox bun x @seed-design/cli@latest add ui:checkbox
Install dependencies
npm install @karrotmarket/lynx-monochrome-icon @seed-design/lynx-react yarn add @karrotmarket/lynx-monochrome-icon @seed-design/lynx-react pnpm add @karrotmarket/lynx-monochrome-icon @seed-design/lynx-react bun add @karrotmarket/lynx-monochrome-icon @seed-design/lynx-react Copy the code below and paste it in /**
* @file ui:checkbox
* @requires @seed-design/lynx-react@>=0.4.0 <1.0.0
* @requires @seed-design/lynx-css@>=0.8.0 <1.0.0
**/
import * as React from "@lynx-js/react" ;
import IconCheckmarkFatFill from "@karrotmarket/lynx-monochrome-icon/IconCheckmarkFatFill" ;
import IconMinusFatFill from "@karrotmarket/lynx-monochrome-icon/IconMinusFatFill" ;
import { Checkbox as SeedCheckbox, Field as SeedField } from "@seed-design/lynx-react" ;
type FieldRootRef = React . ComponentRef < typeof SeedField.Root>;
export interface CheckboxProps extends SeedCheckbox . RootProps {
label ?: React . ReactNode ;
}
/**
* @see https://crispy.carrot-soft.tech/lynx/components/checkbox
*/
export const Checkbox = React. forwardRef < unknown , CheckboxProps >(
({ label , children , "accessibility-label" : accessibilityLabel , ... otherProps }, ref ) => {
return (
< SeedCheckbox.Root
ref = {ref}
accessibility-label = {accessibilityLabel ?? ( typeof label === "string" ? label : undefined )}
{ ... otherProps}
>
< SeedCheckbox.Control >
< SeedCheckbox.Indicator
unchecked = {otherProps.variant === "ghost" ? < IconCheckmarkFatFill /> : undefined }
checked = {< IconCheckmarkFatFill />}
indeterminate = {< IconMinusFatFill />}
/>
</ SeedCheckbox.Control >
{label != null ? < SeedCheckbox.Label >{label}</ SeedCheckbox.Label > : null }
{children}
</ SeedCheckbox.Root >
);
},
);
Checkbox.displayName = "Checkbox" ;
export interface CheckmarkProps extends Omit < SeedCheckbox . RootProps , "children" > {}
/**
* @see https://crispy.carrot-soft.tech/lynx/components/checkbox
*/
export const Checkmark = React. forwardRef < unknown , CheckmarkProps >(( props , ref ) => {
return (
< SeedCheckbox.Root ref = {ref} { ... props}>
< SeedCheckbox.Control >
< SeedCheckbox.Indicator
unchecked = {props.variant === "ghost" ? < IconCheckmarkFatFill /> : undefined }
checked = {< IconCheckmarkFatFill />}
indeterminate = {< IconMinusFatFill />}
/>
</ SeedCheckbox.Control >
</ SeedCheckbox.Root >
);
});
Checkmark.displayName = "Checkmark" ;
export interface CheckboxGroupProps
extends SeedCheckbox . GroupProps ,
Pick < SeedField . RootProps , "required" | "invalid" | "readOnly" > {
label ?: React . ReactNode ;
/**
* @default " medium "
*/
labelWeight ?: SeedField . LabelProps [ "weight" ];
indicator ?: React . ReactNode ;
showRequiredIndicator ?: boolean ;
description ?: React . ReactNode ;
errorMessage ?: React . ReactNode ;
}
/**
* @see https://crispy.carrot-soft.tech/lynx/components/checkbox
*/
export const CheckboxGroup = React. forwardRef < FieldRootRef , CheckboxGroupProps >(
(
{
label,
labelWeight,
indicator,
showRequiredIndicator,
description,
errorMessage,
children,
... fieldProps
},
ref,
) => {
const renderHeader = label != null || indicator != null ;
const renderErrorMessage = errorMessage != null ;
const renderDescription = description != null && ! renderErrorMessage;
const renderFooter = renderDescription || renderErrorMessage;
return (
< SeedField.Root ref = {ref} { ... fieldProps}>
{renderHeader ? (
< SeedField.Header >
< SeedField.Label weight = {labelWeight}>
{label}
{showRequiredIndicator ? < SeedField.RequiredIndicator /> : null }
{indicator != null ? (
< SeedField.IndicatorText >{indicator}</ SeedField.IndicatorText >
) : null }
</ SeedField.Label >
</ SeedField.Header >
) : null }
< SeedCheckbox.Group >{children}</ SeedCheckbox.Group >
{renderFooter ? (
< SeedField.Footer >
{renderDescription ? (
< SeedField.Description >{description}</ SeedField.Description >
) : null }
{renderErrorMessage ? (
< SeedField.ErrorMessage >{errorMessage}</ SeedField.ErrorMessage >
) : null }
</ SeedField.Footer >
) : null }
</ SeedField.Root >
);
},
);
CheckboxGroup.displayName = "CheckboxGroup" ;
/**
* This file is a snippet from Crispy, helping you get started quickly with @seed-design/* packages.
* You can extend this snippet however you want.
*/
label?React.ReactNode
indicator?React.ReactNode
showRequiredIndicator?boolean | undefined
description?React.ReactNode
errorMessage?React.ReactNode
style?CSSProperties | undefined
children?React.ReactNode
className?string | undefined
required?boolean | undefined
readOnly?boolean | undefined
label?React.ReactNode
checked?boolean | undefined
defaultChecked?boolean | undefined
indeterminate?boolean | undefined
onCheckedChange?(( checked : boolean ) => void ) | undefined
style?CSSProperties | undefined
children?React.ReactNode
className?string | undefined
className?string | undefined
style?CSSProperties | undefined
checked?boolean | undefined
indeterminate?boolean | undefined
defaultChecked?boolean | undefined
onCheckedChange?(( checked : boolean ) => void ) | undefined
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.
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 (
< view className = { `${ seedClassName } docs-lynx-checkbox-root` }>
< HStack className = "checkbox-preview" gap = "x8" >
< CheckboxGroup >
< Checkbox label = "Medium (default)" size = "medium" defaultChecked tone = "neutral" />
< Checkbox label = "Large" size = "large" defaultChecked tone = "neutral" />
</ CheckboxGroup >
< CheckboxGroup >
< Checkbox
label = "Medium (default)"
size = "medium"
variant = "ghost"
defaultChecked
tone = "neutral"
/>
< Checkbox label = "Large" size = "large" variant = "ghost" defaultChecked tone = "neutral" />
</ CheckboxGroup >
</ HStack >
</ view >
);
}
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 (
< view className = { `${ seedClassName } docs-lynx-checkbox-root` }>
< VStack className = "checkbox-preview" >
< CheckboxGroup >
< Checkbox
label = "Square (default)"
variant = "square"
tone = "brand"
size = "large"
defaultChecked
/>
< Checkbox label = "Ghost" variant = "ghost" tone = "brand" size = "large" defaultChecked />
</ CheckboxGroup >
</ VStack >
</ view >
);
}
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 (
< view className = { `${ seedClassName } docs-lynx-checkbox-root` }>
< VStack className = "checkbox-preview" >
< CheckboxGroup >
< Checkbox
label = "Square (default)"
variant = "square"
tone = "neutral"
size = "large"
defaultChecked
/>
< Checkbox label = "Ghost" variant = "ghost" tone = "neutral" size = "large" defaultChecked />
</ CheckboxGroup >
</ VStack >
</ view >
);
}
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 (
< view className = { `${ seedClassName } docs-lynx-checkbox-root` }>
< VStack className = "checkbox-preview" >
< Checkbox defaultChecked label = "indeterminate" indeterminate tone = "neutral" size = "large" />
</ VStack >
</ view >
);
}
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 (
< view className = { `${ seedClassName } docs-lynx-checkbox-root` }>
< VStack className = "checkbox-preview" >
< CheckboxGroup >
< Checkbox label = "Regular Label Text" weight = "regular" tone = "neutral" size = "large" />
< Checkbox label = "Bold Label Text" weight = "bold" tone = "neutral" size = "large" />
</ CheckboxGroup >
</ VStack >
</ view >
);
}
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 (
< view className = { `${ seedClassName } docs-lynx-checkbox-root` }>
< VStack className = "checkbox-preview" >
< CheckboxGroup >
< Checkbox
size = "medium"
tone = "neutral"
label = "Consequat ut veniam aliqua deserunt occaecat enim occaecat veniam et et cillum nulla officia incididunt incididunt. Sint laboris labore occaecat fugiat culpa voluptate ullamco in elit dolore exercitation nulla."
/>
< Checkbox
size = "large"
tone = "neutral"
label = "Consequat ut veniam aliqua deserunt occaecat enim occaecat veniam et et cillum nulla officia incididunt incididunt. Sint laboris labore occaecat fugiat culpa voluptate ullamco in elit dolore exercitation nulla."
/>
</ CheckboxGroup >
</ VStack >
</ view >
);
}
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 (
< view className = { `${ seedClassName } docs-lynx-checkbox-root` }>
< VStack className = "checkbox-preview" >
< CheckboxGroup >
< Checkbox
defaultChecked
label = "Disabled Checked, Square"
disabled
tone = "neutral"
size = "large"
/>
< Checkbox
checked = { false }
label = "Disabled without Checked, Square"
disabled
tone = "neutral"
size = "large"
/>
< Checkbox
variant = "ghost"
defaultChecked
label = "Disabled Checked, Ghost"
disabled
tone = "neutral"
size = "large"
/>
< Checkbox
variant = "ghost"
checked = { false }
label = "Disabled without Checked, Ghost"
disabled
tone = "neutral"
size = "large"
/>
</ CheckboxGroup >
</ VStack >
</ view >
);
}
You can detect checkbox state changes with onCheckedChange.
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 < boolean | null >( null );
function handleCheckedChange ( checked : boolean ) {
"background only" ;
setCount (( previous ) => previous + 1 );
setLastValue (checked);
}
return (
< view className = { `${ seedClassName } docs-lynx-checkbox-root` }>
< VStack className = "checkbox-preview" gap = "x4" >
< Checkbox
label = "Click me"
tone = "neutral"
size = "large"
onCheckedChange = {handleCheckedChange}
/>
< text className = "checkbox-preview__status" >
onCheckedChange called: {count} times, last value:{ " " }
{lastValue === null ? "-" : JSON . stringify (lastValue)}
</ text >
</ VStack >
</ view >
);
}
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.
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 (
< Checkbox
accessibility-label = {label}
tone = "neutral"
defaultChecked = {defaultChecked}
style = {{ flexDirection: "column" , rowGap: "8px" , alignItems: "center" }}
>
< Text textStyle = {textStyle}>{label}</ Text >
</ Checkbox >
);
}
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-checkbox-root` }>
< HStack className = "checkbox-preview" gap = "x6" >
< CustomCheckbox label = "regular" textStyle = "t7Regular" />
< CustomCheckbox label = "medium" textStyle = "t7Medium" defaultChecked />
< CustomCheckbox label = "bold" textStyle = "t7Bold" />
</ HStack >
</ view >
);
}
You can use CheckboxGroup to group multiple checkboxes and use Fieldset-related props such as label, description, and errorMessage.
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 < string | undefined >();
const [ terms , setTerms ] = useState ( false );
const [ privacy , setPrivacy ] = useState ( true );
const [ marketing , setMarketing ] = useState ( false );
const [ secondErrorMessage , setSecondErrorMessage ] = useState < string | undefined >();
const handleFirstSubmit = () => {
setFirstErrorMessage (apple ? "Apple은 선택할 수 없습니다." : undefined );
};
const handleSecondSubmit = () => {
setSecondErrorMessage ( ! terms || ! privacy ? "필수 항목에 동의해 주세요." : undefined );
};
return (
< view className = { `${ seedClassName } docs-lynx-checkbox-root` }>
< VStack className = "checkbox-preview" >
< HStack width = "full" gap = "x8" align = "flex-start" >
< VStack style = {{ flex: 1 }} gap = "spacingY.componentDefault" >
< CheckboxGroup
label = "좋아하는 과일"
indicator = "선택"
description = "Apple을 선택하고 제출해보세요."
errorMessage = {firstErrorMessage}
>
< Checkbox
label = "Apple"
tone = "neutral"
size = "large"
checked = {apple}
onCheckedChange = {setApple}
/>
< Checkbox
label = "Banana"
tone = "neutral"
size = "large"
checked = {banana}
onCheckedChange = {setBanana}
/>
< Checkbox
label = "Orange"
tone = "neutral"
size = "large"
checked = {orange}
onCheckedChange = {setOrange}
/>
</ CheckboxGroup >
< ActionButton variant = "neutralSolid" bindtap = {handleFirstSubmit}>
제출
</ ActionButton >
</ VStack >
< VStack style = {{ flex: 1 }} gap = "spacingY.componentDefault" >
< CheckboxGroup
label = "약관 동의"
labelWeight = "bold"
showRequiredIndicator
description = "이용약관을 선택하지 않고 제출해보세요."
errorMessage = {secondErrorMessage}
>
< Checkbox
label = "이용약관 동의 (필수)"
tone = "neutral"
size = "large"
checked = {terms}
onCheckedChange = {setTerms}
/>
< Checkbox
label = "개인정보 처리방침 동의 (필수)"
tone = "neutral"
size = "large"
checked = {privacy}
onCheckedChange = {setPrivacy}
/>
< Checkbox
label = "마케팅 수신 동의 (선택)"
tone = "neutral"
size = "large"
checked = {marketing}
onCheckedChange = {setMarketing}
/>
</ CheckboxGroup >
< ActionButton variant = "neutralSolid" bindtap = {handleSecondSubmit}>
제출
</ ActionButton >
</ VStack >
</ HStack >
</ VStack >
</ view >
);
}
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 <svg> injection is outside the Lynx scope.
Error guidance rendering : React keeps description in the accessibility tree when an error is displayed, but Lynx has no visually hidden processing method in the DOM, so it renders only errorMessage and excludes description from both the screen and accessibility tree.
Event handling : Only onCheckedChange is exposed instead of onChange. The tap handler is owned inside Root.
Pressed state : The internal press state is passed as a pressed boolean variant of the checkmark recipe instead of web's data-active.
Scale Feedback : Lynx expresses the pressed state with color and does not provide React's --seed-checkmark-feedback-scale CSS variable.
Accessibility attributes : Native <view> / <text> elements are rendered instead of HTML <label> / <input>. Checkbox.Root passes role and checked state with accessibility-element, accessibility-role-description, and accessibility-value.
Compound structure : The composition of Checkbox.Root → Checkbox.Control → Checkbox.Indicator + Checkbox.Label and the flow of sharing state and variant through Context are the same.
ref forwarding : Checkbox, Checkmark, and CheckboxGroup forward refs to the Root view. They do not provide a hidden input ref like the web snippet.
The following features are currently not supported due to Lynx platform constraints.
Feature Web Equivalent Description CheckboxHiddenInput<input type="checkbox">No HTML form submission model in Lynx inputPropshidden 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 / focusVisibleKeyboard focus No keyboard focus concept in Lynx onChange (raw DOM event)React.ChangeEventNot applicable. Replaced with onCheckedChange weight="default" / "stronger"deprecated compatibility mapping Lynx only exposes "regular" / "bold"