A UI element that uses a container with a clear border to select one or more options from a defined list.
@seed-design/lynx-react@0.6.0, @seed-design/lynx-css@0.10.0
import "./styles" ;
import { HStack, VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
CheckSelectBox,
CheckSelectBoxCheckmark,
CheckSelectBoxGroup,
RadioSelectBoxItem,
RadioSelectBoxRadiomark,
RadioSelectBoxRoot,
} from "@/components/ui/select-box" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-select-box-root` }>
< HStack className = "select-box-preview" gap = "x6" align = "flex-start" >
< VStack className = "select-box-preview__column" >
< CheckSelectBoxGroup accessibility-label = "Fruit" >
< CheckSelectBox label = "Apple" defaultChecked suffix = {< CheckSelectBoxCheckmark />} />
< CheckSelectBox
label = "Melon"
description = "Elit cupidatat dolore fugiat enim veniam culpa."
suffix = {< CheckSelectBoxCheckmark />}
/>
< CheckSelectBox label = "Mango" suffix = {< CheckSelectBoxCheckmark />} />
</ CheckSelectBoxGroup >
</ VStack >
< VStack className = "select-box-preview__column" >
< RadioSelectBoxRoot defaultValue = "apple" accessibility-label = "Fruit" >
< RadioSelectBoxItem value = "apple" label = "Apple" suffix = {< RadioSelectBoxRadiomark />} />
< RadioSelectBoxItem
value = "melon"
label = "Melon"
description = "Elit cupidatat dolore fugiat enim veniam culpa."
suffix = {< RadioSelectBoxRadiomark />}
/>
< RadioSelectBoxItem value = "mango" label = "Mango" suffix = {< RadioSelectBoxRadiomark />} />
</ RadioSelectBoxRoot >
</ VStack >
</ HStack >
</ view >
);
}
npx @seed-design/cli@latest add ui:select-box pnpm dlx @seed-design/cli@latest add ui:select-box yarn dlx @seed-design/cli@latest add ui:select-box bun x @seed-design/cli@latest add ui:select-box
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:select-box
* @requires @seed-design/lynx-react@>=0.6.0 <1.0.0
* @requires @seed-design/lynx-css@>=0.10.0 <1.0.0
* @requires @karrotmarket/lynx-monochrome-icon@>=1.20.0 <2.0.0
**/
import IconCheckmarkFatFill from "@karrotmarket/lynx-monochrome-icon/IconCheckmarkFatFill" ;
import * as React from "@lynx-js/react" ;
import {
CheckSelectBox as SeedCheckSelectBox,
PrefixIcon,
RadioGroup as SeedRadioGroup,
RadioSelectBox as SeedRadioSelectBox,
} from "@seed-design/lynx-react" ;
import type { LynxIconElementProps } from "@seed-design/lynx-react" ;
export interface RadioSelectBoxRootProps
extends Omit < SeedRadioGroup . RootProps , "children" | "className" | "style" >,
SeedRadioSelectBox . GroupProps {}
/**
* @see https://crispy.carrot-soft.tech/lynx/components/select-box
*/
export const RadioSelectBoxRoot = React. forwardRef < unknown , RadioSelectBoxRootProps >(
({ children , columns = 1 , className , style , ... rootProps }, ref ) => {
return (
< SeedRadioGroup.Root ref = {ref} { ... rootProps}>
< SeedRadioSelectBox.Group columns = {columns} className = {className} style = {style}>
{children}
</ SeedRadioSelectBox.Group >
</ SeedRadioGroup.Root >
);
},
);
RadioSelectBoxRoot.displayName = "RadioSelectBoxRoot" ;
export interface RadioSelectBoxItemProps extends Omit < SeedRadioSelectBox . ItemProps , "children" > {
label : React . ReactNode ;
description ?: React . ReactNode ;
prefixIcon ?: React . ReactElement < LynxIconElementProps >;
suffix ?: React . ReactNode ;
footer ?: React . ReactNode ;
}
export const RadioSelectBoxItem = React. forwardRef < unknown , RadioSelectBoxItemProps >(
(
{
label,
description,
prefixIcon,
suffix,
footer,
"accessibility-label" : accessibilityLabel,
... otherProps
},
ref,
) => {
return (
< SeedRadioSelectBox.Item
ref = {ref}
accessibility-label = {accessibilityLabel ?? ( typeof label === "string" ? label : undefined )}
{ ... otherProps}
>
< SeedRadioSelectBox.Trigger >
< SeedRadioSelectBox.Content >
{prefixIcon ? < PrefixIcon icon = {prefixIcon} /> : null }
< SeedRadioSelectBox.Body >
< SeedRadioSelectBox.Label >{label}</ SeedRadioSelectBox.Label >
{description != null ? (
< SeedRadioSelectBox.Description >{description}</ SeedRadioSelectBox.Description >
) : null }
</ SeedRadioSelectBox.Body >
</ SeedRadioSelectBox.Content >
{suffix}
</ SeedRadioSelectBox.Trigger >
{footer != null ? < SeedRadioSelectBox.Footer >{footer}</ SeedRadioSelectBox.Footer > : null }
</ SeedRadioSelectBox.Item >
);
},
);
RadioSelectBoxItem.displayName = "RadioSelectBoxItem" ;
export interface RadioSelectBoxRadiomarkProps extends SeedRadioGroup . ItemControlProps {}
export const RadioSelectBoxRadiomark = React. forwardRef < unknown , RadioSelectBoxRadiomarkProps >(
( props , ref ) => {
return (
< SeedRadioGroup.ItemControl ref = {ref} tone = "neutral" { ... props}>
< SeedRadioGroup.ItemIndicator />
</ SeedRadioGroup.ItemControl >
);
},
);
RadioSelectBoxRadiomark.displayName = "RadioSelectBoxRadiomark" ;
export interface CheckSelectBoxGroupProps extends SeedCheckSelectBox . GroupProps {}
export const CheckSelectBoxGroup = SeedCheckSelectBox.Group;
export interface CheckSelectBoxProps extends Omit < SeedCheckSelectBox . RootProps , "children" > {
label : React . ReactNode ;
description ?: React . ReactNode ;
prefixIcon ?: React . ReactElement < LynxIconElementProps >;
suffix ?: React . ReactNode ;
footer ?: React . ReactNode ;
}
/**
* @see https://crispy.carrot-soft.tech/lynx/components/select-box
*/
export const CheckSelectBox = React. forwardRef < unknown , CheckSelectBoxProps >(
(
{
label,
description,
prefixIcon,
suffix,
footer,
"accessibility-label" : accessibilityLabel,
... otherProps
},
ref,
) => {
return (
< SeedCheckSelectBox.Root
ref = {ref}
accessibility-label = {accessibilityLabel ?? ( typeof label === "string" ? label : undefined )}
{ ... otherProps}
>
< SeedCheckSelectBox.Trigger >
< SeedCheckSelectBox.Content >
{prefixIcon ? < PrefixIcon icon = {prefixIcon} /> : null }
< SeedCheckSelectBox.Body >
< SeedCheckSelectBox.Label >{label}</ SeedCheckSelectBox.Label >
{description != null ? (
< SeedCheckSelectBox.Description >{description}</ SeedCheckSelectBox.Description >
) : null }
</ SeedCheckSelectBox.Body >
</ SeedCheckSelectBox.Content >
{suffix}
</ SeedCheckSelectBox.Trigger >
{footer != null ? < SeedCheckSelectBox.Footer >{footer}</ SeedCheckSelectBox.Footer > : null }
</ SeedCheckSelectBox.Root >
);
},
);
CheckSelectBox.displayName = "CheckSelectBox" ;
export interface CheckSelectBoxCheckmarkProps extends SeedCheckSelectBox . CheckmarkControlProps {}
export const CheckSelectBoxCheckmark = React. forwardRef < unknown , CheckSelectBoxCheckmarkProps >(
( props , ref ) => {
return (
< SeedCheckSelectBox.CheckmarkControl ref = {ref} { ... props}>
< SeedCheckSelectBox.CheckmarkIcon icon = {< IconCheckmarkFatFill />} />
</ SeedCheckSelectBox.CheckmarkControl >
);
},
);
CheckSelectBoxCheckmark.displayName = "CheckSelectBoxCheckmark" ;
/**
* This file is a snippet from Crispy, helping you get started quickly with @seed-design/* packages.
* You can extend this snippet however you want.
*/
style?CSSProperties | undefined
children?React.ReactNode
className?string | undefined
labelReact.ReactNode
description?React.ReactNode
prefixIcon?React.ReactElement < LynxIconElementProps, string | React.JSXElementConstructor < any >> | undefined
suffix?React.ReactNode
className?string | undefined
checked?boolean | undefined
defaultChecked?boolean | undefined
indeterminate?boolean | undefined
onCheckedChange?(( checked : boolean ) => void ) | undefined
style?CSSProperties | undefined
style?CSSProperties | undefined
children?React.ReactNode
className?string | undefined
value?string | undefined
defaultValue?string | undefined
onValueChange?(( value : string ) => void ) | undefined
style?CSSProperties | undefined
children?React.ReactNode
className?string | undefined
labelReact.ReactNode
description?React.ReactNode
prefixIcon?React.ReactElement < LynxIconElementProps, string | React.JSXElementConstructor < any >> | undefined
suffix?React.ReactNode
className?string | undefined
disabled?boolean | undefined
style?CSSProperties | undefined
valuestring
style?CSSProperties | undefined
children?React.ReactNode
className?string | undefined
You can pass custom content combining multiple elements to the label prop.
import "./styles" ;
import { Badge, HStack, VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
CheckSelectBox,
CheckSelectBoxCheckmark,
CheckSelectBoxGroup,
RadioSelectBoxItem,
RadioSelectBoxRadiomark,
RadioSelectBoxRoot,
} from "@/components/ui/select-box" ;
function CustomizedLabel () {
return (
<>
< text >Melon</ text >
< Badge tone = "brand" variant = "solid" >
New
</ Badge >
</>
);
}
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-select-box-root` }>
< HStack className = "select-box-preview" gap = "x8" align = "flex-start" >
< VStack className = "select-box-preview__column" >
< CheckSelectBoxGroup accessibility-label = "Fruit" >
< CheckSelectBox label = "Apple" defaultChecked suffix = {< CheckSelectBoxCheckmark />} />
< CheckSelectBox
accessibility-label = "Melon New"
label = {< CustomizedLabel />}
description = "Elit cupidatat dolore fugiat enim veniam culpa."
suffix = {< CheckSelectBoxCheckmark />}
/>
< CheckSelectBox
label = "Mango"
description = "Aliqua ad aute eiusmod eiusmod nulla adipisicing proident ullamco in."
suffix = {< CheckSelectBoxCheckmark />}
/>
</ CheckSelectBoxGroup >
</ VStack >
< VStack className = "select-box-preview__column" >
< RadioSelectBoxRoot defaultValue = "apple" accessibility-label = "Fruit" >
< RadioSelectBoxItem value = "apple" label = "Apple" suffix = {< RadioSelectBoxRadiomark />} />
< RadioSelectBoxItem
value = "melon"
accessibility-label = "Melon New"
label = {< CustomizedLabel />}
description = "Elit cupidatat dolore fugiat enim veniam culpa."
suffix = {< RadioSelectBoxRadiomark />}
/>
< RadioSelectBoxItem
value = "mango"
label = "Mango"
description = "Aliqua ad aute eiusmod eiusmod nulla adipisicing proident ullamco in."
suffix = {< RadioSelectBoxRadiomark />}
/>
</ RadioSelectBoxRoot >
</ VStack >
</ HStack >
</ view >
);
}
CheckSelectBox can detect checkbox selection state changes using onCheckedChange.
RadioSelectBoxRoot can detect radio button selection value changes using onValueChange.
import "./styles" ;
import { useState } from "@lynx-js/react" ;
import { HStack, VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
CheckSelectBox,
CheckSelectBoxCheckmark,
CheckSelectBoxGroup,
RadioSelectBoxItem,
RadioSelectBoxRadiomark,
RadioSelectBoxRoot,
} from "@/components/ui/select-box" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
const [ checkCount , setCheckCount ] = useState ( 0 );
const [ checkLastValue , setCheckLastValue ] = useState < boolean | null >( null );
const [ radioCount , setRadioCount ] = useState ( 0 );
const [ radioLastValue , setRadioLastValue ] = useState < string | null >( null );
return (
< view className = { `${ seedClassName } docs-lynx-select-box-root` }>
< HStack className = "select-box-preview" gap = "x8" align = "center" >
< VStack className = "select-box-preview__column" gap = "x4" align = "center" >
< CheckSelectBoxGroup accessibility-label = "Fruit" >
< CheckSelectBox
label = "Apple"
suffix = {< CheckSelectBoxCheckmark />}
onCheckedChange = {( checked ) => {
setCheckCount (( previous ) => previous + 1 );
setCheckLastValue (checked);
}}
/>
</ CheckSelectBoxGroup >
< text className = "select-box-preview__status" >
onCheckedChange called: {checkCount} times, last value:{ " " }
{checkLastValue === null ? "-" : JSON . stringify (checkLastValue)}
</ text >
</ VStack >
< VStack className = "select-box-preview__column" gap = "x4" align = "center" >
< RadioSelectBoxRoot
defaultValue = "apple"
accessibility-label = "Fruit"
onValueChange = {( value ) => {
setRadioCount (( previous ) => previous + 1 );
setRadioLastValue (value);
}}
>
< RadioSelectBoxItem value = "apple" label = "Apple" suffix = {< RadioSelectBoxRadiomark />} />
< RadioSelectBoxItem
value = "banana"
label = "Banana"
suffix = {< RadioSelectBoxRadiomark />}
/>
</ RadioSelectBoxRoot >
< text className = "select-box-preview__status" >
onValueChange called: {radioCount} times, last value: {radioLastValue ?? "-" }
</ text >
</ VStack >
</ HStack >
</ view >
);
}
You can arrange items in multiple columns using the columns prop. If columns is greater than 1, the layout of child elements is automatically set to "vertical".
If needed, you can override the layout of individual items by setting the layout prop directly.
import "./styles" ;
import IconDiamond from "@karrotmarket/lynx-multicolor-icon/IconDiamond" ;
import IconIcecreamcone from "@karrotmarket/lynx-multicolor-icon/IconIcecreamcone" ;
import { VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
CheckSelectBox,
CheckSelectBoxCheckmark,
CheckSelectBoxGroup,
RadioSelectBoxItem,
RadioSelectBoxRadiomark,
RadioSelectBoxRoot,
} from "@/components/ui/select-box" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-select-box-root` }>
< VStack className = "select-box-preview" gap = "x8" >
< CheckSelectBoxGroup columns = { 2 } accessibility-label = "Grid 레이아웃 예제" >
< CheckSelectBox
prefixIcon = {< IconIcecreamcone />}
label = "옵션 1"
description = "layout=vertical"
suffix = {< CheckSelectBoxCheckmark />}
/>
< CheckSelectBox
prefixIcon = {< IconIcecreamcone />}
label = "옵션 2"
description = "layout=vertical"
suffix = {< CheckSelectBoxCheckmark />}
/>
< CheckSelectBox
prefixIcon = {< IconIcecreamcone />}
defaultChecked
layout = "horizontal"
label = "layout=horizontal"
description = "layout을 horizontal로 오버라이드"
suffix = {< CheckSelectBoxCheckmark />}
/>
< CheckSelectBox
prefixIcon = {< IconIcecreamcone />}
label = "옵션 4"
description = "layout=vertical"
suffix = {< CheckSelectBoxCheckmark />}
/>
</ CheckSelectBoxGroup >
< RadioSelectBoxRoot
columns = { 3 }
defaultValue = "option3"
accessibility-label = "Grid 레이아웃 예제"
>
< RadioSelectBoxItem
value = "option1"
prefixIcon = {< IconDiamond />}
label = "옵션 1"
suffix = {< RadioSelectBoxRadiomark />}
/>
< RadioSelectBoxItem
value = "option2"
prefixIcon = {< IconDiamond />}
label = "옵션 2"
suffix = {< RadioSelectBoxRadiomark />}
/>
< RadioSelectBoxItem
value = "option3"
prefixIcon = {< IconDiamond />}
label = "layout=horizontal"
description = "layout을 horizontal로 오버라이드"
layout = "horizontal"
suffix = {< RadioSelectBoxRadiomark />}
/>
< RadioSelectBoxItem
value = "option4"
prefixIcon = {< IconDiamond />}
label = "옵션 4"
suffix = {< RadioSelectBoxRadiomark />}
/>
< RadioSelectBoxItem
value = "option5"
prefixIcon = {< IconDiamond />}
label = "옵션 5"
suffix = {< RadioSelectBoxRadiomark />}
/>
< RadioSelectBoxItem
value = "option6"
prefixIcon = {< IconDiamond />}
label = "옵션 6"
suffix = {< RadioSelectBoxRadiomark />}
/>
</ RadioSelectBoxRoot >
</ VStack >
</ view >
);
}
You can display a checkmark, radio mark, or custom element using the suffix prop. You can use CheckSelectBoxCheckmark and RadioSelectBoxRadiomark, or pass any free-form element such as an icon or text.
import "./styles" ;
import IconPersonCircleLine from "@karrotmarket/lynx-monochrome-icon/IconPersonCircleLine" ;
import { HStack, VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
CheckSelectBox,
CheckSelectBoxCheckmark,
CheckSelectBoxGroup,
RadioSelectBoxItem,
RadioSelectBoxRadiomark,
RadioSelectBoxRoot,
} from "@/components/ui/select-box" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-select-box-root` }>
< HStack className = "select-box-preview" gap = "x8" align = "flex-start" >
< VStack className = "select-box-preview__column" >
< CheckSelectBoxGroup accessibility-label = "Suffix 예제" >
< CheckSelectBox label = "체크마크" suffix = {< CheckSelectBoxCheckmark />} />
< CheckSelectBox
label = "텍스트 suffix"
suffix = {< text className = "select-box-preview__suffix" >+1,000원</ text >}
/>
< CheckSelectBox
label = "suffix 없음"
description = "Commodo aliquip fugiat aute irure."
prefixIcon = {< IconPersonCircleLine />}
/>
</ CheckSelectBoxGroup >
</ VStack >
< VStack className = "select-box-preview__column" >
< RadioSelectBoxRoot defaultValue = "radiomark" accessibility-label = "Radiomark 예제" >
< RadioSelectBoxItem
value = "radiomark"
label = "라디오 마크"
suffix = {< RadioSelectBoxRadiomark />}
/>
< RadioSelectBoxItem
value = "text"
label = "텍스트 suffix"
description = "Commodo aliquip fugiat aute irure."
suffix = {< text className = "select-box-preview__suffix" >+1,000원</ text >}
/>
< RadioSelectBoxItem
value = "none"
label = "suffix 없음"
prefixIcon = {< IconPersonCircleLine />}
/>
</ RadioSelectBoxRoot >
</ VStack >
</ HStack >
</ view >
);
}
You can display additional content with the footer prop. You can control the footer display conditions with the footerVisibility prop.
"when-selected" (default): Display only when the item is selected
"when-not-selected": Display only when the item is not selected
"always": Always display
import "./styles" ;
import { HStack, VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
CheckSelectBox,
CheckSelectBoxCheckmark,
CheckSelectBoxGroup,
RadioSelectBoxItem,
RadioSelectBoxRadiomark,
RadioSelectBoxRoot,
} from "@/components/ui/select-box" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-select-box-root` }>
< HStack className = "select-box-preview" gap = "x8" align = "flex-start" >
< VStack className = "select-box-preview__column" >
< CheckSelectBoxGroup accessibility-label = "Footer 예제" >
< CheckSelectBox
label = "선택 시에만 표시 (기본값)"
description = "footerVisibility='when-selected'"
suffix = {< CheckSelectBoxCheckmark />}
footer = {< text className = "select-box-preview__footer" >선택되었을 때만 보입니다.</ text >}
/>
< CheckSelectBox
label = "항상 표시"
description = "footerVisibility='always'"
suffix = {< CheckSelectBoxCheckmark />}
footerVisibility = "always"
footer = {< text className = "select-box-preview__footer" >항상 보입니다.</ text >}
/>
< CheckSelectBox
label = "미선택 시에만 표시"
description = "footerVisibility='when-not-selected'"
suffix = {< CheckSelectBoxCheckmark />}
footerVisibility = "when-not-selected"
footer = {
< text className = "select-box-preview__footer" >선택되지 않았을 때만 보입니다.</ text >
}
/>
</ CheckSelectBoxGroup >
</ VStack >
< VStack className = "select-box-preview__column" >
< RadioSelectBoxRoot defaultValue = "when-selected" accessibility-label = "Footer 예제" >
< RadioSelectBoxItem
value = "when-selected"
label = "선택 시에만 표시 (기본값)"
description = "footerVisibility='when-selected'"
suffix = {< RadioSelectBoxRadiomark />}
footer = {< text className = "select-box-preview__footer" >선택되었을 때만 보입니다.</ text >}
/>
< RadioSelectBoxItem
value = "always"
label = "항상 표시"
description = "footerVisibility='always'"
suffix = {< RadioSelectBoxRadiomark />}
footerVisibility = "always"
footer = {< text className = "select-box-preview__footer" >항상 보입니다.</ text >}
/>
< RadioSelectBoxItem
value = "when-not-selected"
label = "미선택 시에만 표시"
description = "footerVisibility='when-not-selected'"
suffix = {< RadioSelectBoxRadiomark />}
footerVisibility = "when-not-selected"
footer = {
< text className = "select-box-preview__footer" >선택되지 않았을 때만 보입니다.</ text >
}
/>
</ RadioSelectBoxRoot >
</ VStack >
</ HStack >
</ view >
);
}
Lynx Select Box has the following differences from the React version.
React Hook Form not supported : Lynx does not have a native form submission model, so we do not provide React Hook Form examples.
No field wrapper : We do not provide integration with Fieldset and RadioGroupField from React Registry, or field label, description, and error message connections.
No form submission : We do not provide hidden input, inputProps, name, required, or invalid.
No keyboard focus : Uses native tap and accessibility navigation instead of browser keyboard focus.
Accessibility : Uses Lynx accessibility roles and selection values instead of HTML ARIA.