Skip to content

Commit fd53d62

Browse files
authored
Add size prop to Checkbox component (#2684)
<!-- How to write a good PR title: - Follow [the Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/). - Give as much context as necessary and as little as possible - Prefix it with [WIP] while it’s a work in progress --> ## Self Checklist - [x] I wrote a PR title in **English** and added an appropriate **label** to the PR. - [x] I wrote the commit message in **English** and to follow [**the Conventional Commits specification**](https://www.conventionalcommits.org/en/v1.0.0/). - [x] I [added the **changeset**](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md) about the changes that needed to be released. (or didn't have to) - [ ] I wrote or updated **documentation** related to the changes. (or didn't have to) - [ ] I wrote or updated **tests** related to the changes. (or didn't have to) - [x] I tested the changes in various browsers. (or didn't have to) - Windows: Chrome, Edge, (Optional) Firefox - macOS: Chrome, Edge, Safari, (Optional) Firefox ## Related Issue <!-- Please link to issue if one exists --> <!-- Fixes #0000 --> ## Summary <!-- Please brief explanation of the changes made --> - Checkbox 컴포넌트에 size prop을 추가합니다. - 더 작은 s 사이즈가 추가되었습니다.(기존 사이즈는 m사이즈) ## Details - s 사이즈 Checkbox는 컴포넌트 사이즈는 16x16, 아이콘 사이즈는 xxs(12x12), border-radius는 4.6px 입니다. - [피그마](https://www.figma.com/design/99k33ZxchcPKTz2tzJlZeE/Components?node-id=1307-312&m=dev) <!-- Please elaborate description of the changes --> ### Breaking change? (Yes/No) <!-- If Yes, please describe the impact and migration path for users --> - No (기본값으로 m 사이즈를 넣어주고 있어 기존 사용처들은 동일하게 사용 가능) ## References <!-- Please list any other resources or points the reviewer should be aware of --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Checkbox에 사이즈 옵션 추가(s, m) — 기본값은 m이며 s 선택 시 더 작게 표시됩니다. * 체크 표시 아이콘이 선택된 사이즈에 따라 자동으로 크기 조정됩니다. * 공개 API에 사이즈 타입과 size prop이 추가되어 타입 안전한 사이즈 지정이 가능합니다. * **Chores** *마이너 릴리스용 변경로그 항목(changeset) 추가됨. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent ca692df commit fd53d62

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

.changeset/floppy-moments-sink.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@channel.io/bezier-react': minor
3+
---
4+
5+
Add size prop to Checkbox component

packages/bezier-react/src/components/Checkbox/Checkbox.module.scss

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
box-shadow: inset 0 0 0 2px var(--bdr-black-dark);
2424

2525
/* stylelint-disable-next-line order/order */
26-
@include dimension.square(18px);
27-
2826
@include interaction.touchable-hover {
2927
&:where(:not([data-disabled], [data-state='unchecked'])) {
3028
background-color: var(--bgtxt-green-dark);
@@ -35,6 +33,17 @@
3533
}
3634
}
3735

36+
&:where(.size-s) {
37+
border-radius: 4.6px;
38+
39+
/* stylelint-disable-next-line order/order */
40+
@include dimension.square(16px);
41+
}
42+
43+
&:where(.size-m) {
44+
@include dimension.square(18px);
45+
}
46+
3847
&:where([data-disabled]) {
3948
background-color: var(--bg-black-dark);
4049
box-shadow: none;

packages/bezier-react/src/components/Checkbox/Checkbox.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const CheckIcon = forwardRef<SVGSVGElement, CheckIconProps>(
3737
className={styles.CheckIcon}
3838
ref={forwardedRef}
3939
source={!isIndeterminate ? CheckBoldIcon : HyphenBoldIcon}
40-
size="xs"
4140
color={isUnchecked ? 'bg-black-dark' : 'bgtxt-absolute-white-dark'}
4241
{...props}
4342
/>
@@ -46,7 +45,7 @@ const CheckIcon = forwardRef<SVGSVGElement, CheckIconProps>(
4645
)
4746

4847
function CheckboxImpl<Checked extends CheckedState>(
49-
{ children, className, checked, id: idProp, ...rest }: CheckboxProps<Checked>,
48+
{ children, className, checked, size = 'm', id: idProp, ...rest }: CheckboxProps<Checked>,
5049
forwardedRef: React.Ref<HTMLButtonElement>
5150
) {
5251
const {
@@ -56,14 +55,15 @@ function CheckboxImpl<Checked extends CheckedState>(
5655
} = useFormFieldProps(rest)
5756

5857
const id = useId(idProp ?? formFieldId, 'bezier-checkbox')
58+
const iconSize = size === 's' ? 'xxs' : 'xs'
5959

6060
return (
6161
<div
6262
className={classNames(styles.Container, getFormFieldSizeClassName('m'))}
6363
>
6464
<CheckboxPrimitive.Root
6565
asChild
66-
className={classNames(styles.Checkbox, className)}
66+
className={classNames(styles.Checkbox, styles[`size-${size}`], className)}
6767
ref={forwardedRef}
6868
id={id}
6969
checked={checked}
@@ -77,7 +77,7 @@ function CheckboxImpl<Checked extends CheckedState>(
7777
forceMount
7878
>
7979
{/* @ts-expect-error */}
80-
<CheckIcon />
80+
<CheckIcon size={iconSize} />
8181
</CheckboxPrimitive.Indicator>
8282
</BaseButton>
8383
</CheckboxPrimitive.Root>

packages/bezier-react/src/components/Checkbox/Checkbox.types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ import {
22
type BezierComponentProps,
33
type ChildrenProps,
44
type FormFieldProps,
5+
type SizeProps,
56
} from '~/src/types/props'
67

78
export type CheckedState = boolean | 'indeterminate'
89

10+
export type CheckboxSize = 's' | 'm'
11+
912
interface CheckboxOwnProps<Checked extends CheckedState> {
1013
/**
1114
* The controlled checked state of the checkbox.
@@ -42,4 +45,5 @@ export interface CheckboxProps<Checked extends CheckedState>
4245
extends Omit<BezierComponentProps<'button'>, keyof CheckboxOwnProps<Checked>>,
4346
ChildrenProps,
4447
FormFieldProps,
48+
SizeProps<CheckboxSize>,
4549
CheckboxOwnProps<Checked> {}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
export { Checkbox } from './Checkbox'
2-
export type { CheckboxProps, CheckedState } from './Checkbox.types'
2+
export type {
3+
CheckboxProps,
4+
CheckedState,
5+
CheckboxSize,
6+
} from './Checkbox.types'

0 commit comments

Comments
 (0)