Checkbox
תיבת סימון המבוססת על קלט תיבת הסימון המובנה.
- דפדפנים
- Chrome 123+, Firefox 121+, Safari 17.5+
- שכבה
- 0
- גודל חבילה דחוסה
- 933 B
- מגבלת פריסה כפויה
- 0 ms
- מגבלת Axe
- 0
- תואם SSR
- כן
- חוזה מפורסם
- סביבת בדיקות
מגרש ניסויים
Checkbox
ברירת מחדל
Indeterminate
מושבת
- 1
- 2
- 3
- 4
- 5
import { Checkbox } from "@gunkin/uiify";
export default function Example() {
return <Checkbox className="" id="terms" label="Accept terms" slotProps={{ input: { className: "" } }} />;
}- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
/* Checkbox, Radio, Switch — all native <input>s styled with appearance:none.
State comes from :checked / :indeterminate (works uncontrolled) and the
[data-state] / [data-disabled] attributes (set when controlled). Thumbs and
checkmarks are pseudo-elements on the input itself. */
@layer components {
:where([data-uiify-checkbox] > input, [data-uiify-radio]) {
appearance: none;
inline-size: 1.25rem;
block-size: 1.25rem;
margin: 0;
border: var(--border-width) solid var(--input);
background-color: var(--card);
display: inline-grid;
place-content: center;
cursor: pointer;
transition: var(--transition-colors);
}
[data-uiify-checkbox] {
display: inline-flex;
align-items: center;
gap: var(--space-sm);
cursor: pointer;
user-select: none;
color: var(--foreground);
font-size: var(--text-sm);
line-height: var(--leading-normal);
}
[data-uiify-checkbox] > input {
border-radius: var(--radius-xs);
}
[data-uiify-radio] {
border-radius: var(--radius-full);
}
/* Checked fill (covers controlled [data-state] and uncontrolled :checked). */
[data-uiify-checkbox] > input:checked,
[data-uiify-checkbox] > input[data-state="checked"] {
border-color: var(--primary);
background-color: var(--primary);
}
/* Radio checked state is a thick accent ring around a white center, not a
filled dot — matches the 2a/2b handoff's target/bullseye radio anatomy. */
[data-uiify-radio]:checked,
[data-uiify-radio][data-state="checked"] {
border-width: 5px;
border-color: var(--primary);
background-color: var(--card);
}
/* Checkmark. */
[data-uiify-checkbox] > input::before {
content: "";
inline-size: 1rem;
block-size: 1rem;
transform: scale(0);
transition: transform var(--duration-fast) var(--ease-out);
background-color: var(--primary-foreground);
clip-path: polygon(28.4% 46.4%, 20% 59%, 42.8% 80%, 80% 33.2%, 70.4% 23.6%, 42.8% 60.8%);
}
[data-uiify-checkbox] > input:checked::before,
[data-uiify-checkbox] > input[data-state="checked"]::before {
transform: scale(1);
}
/* Indeterminate dash. */
[data-uiify-checkbox] > input:indeterminate,
[data-uiify-checkbox] > input[data-state="indeterminate"] {
border-color: var(--primary);
background-color: var(--primary);
}
[data-uiify-checkbox] > input:indeterminate::before,
[data-uiify-checkbox] > input[data-state="indeterminate"]::before {
transform: scale(1);
clip-path: inset(42% 12% 42% 12%);
}
:where([data-uiify-checkbox] > input, [data-uiify-radio]):disabled,
:where([data-uiify-checkbox] > input, [data-uiify-radio])[data-disabled] {
opacity: 0.5;
cursor: not-allowed;
}
[data-uiify-checkbox]:has(> input:disabled) {
opacity: 0.5;
cursor: not-allowed;
}
[data-uiify-radio-group] {
display: flex;
flex-direction: column;
gap: var(--space-md);
}
/* Switch — a pill track with a sliding thumb pseudo-element. */
[data-uiify-switch] {
appearance: none;
position: relative;
inline-size: 2.25rem;
block-size: 1.25rem;
margin: 0;
flex: none;
border: none;
border-radius: var(--radius-full);
background-color: var(--input);
cursor: pointer;
transition: background-color var(--duration-fast) var(--ease-out);
}
[data-uiify-switch]::before {
content: "";
position: absolute;
inset-block-start: 2px;
inset-inline-start: 2px;
inline-size: calc(1.25rem - 4px);
block-size: calc(1.25rem - 4px);
border-radius: var(--radius-full);
background-color: var(--gray-0);
box-shadow: var(--shadow-1);
transition: translate var(--duration-fast) var(--ease-out);
}
[data-uiify-switch]:checked,
[data-uiify-switch][data-state="checked"] {
background-color: var(--primary);
}
[data-uiify-switch]:checked::before,
[data-uiify-switch][data-state="checked"]::before {
translate: 1rem 0;
}
[data-uiify-switch]:disabled,
[data-uiify-switch][data-disabled] {
opacity: 0.5;
cursor: not-allowed;
}
}
@layer components {
label:has([data-uiify-radio]),
[data-uiify-radio-group] label {
user-select: none;
cursor: pointer;
}
}- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
import { Checkbox } from "@gunkin/uiify";
export default function Example() {
return (
<Checkbox
className="
inline-flex items-center gap-sm cursor-pointer select-none text-foreground text-sm
[line-height:var(--leading-normal)] [&:has(>input:disabled)]:opacity-50
[&:has(>input:disabled)]:cursor-not-allowed
"
id="terms"
label="Accept terms"
slotProps={{
input: {
className:
"appearance-none [inline-size:1.25rem] [block-size:1.25rem] m-0 " +
"border-[length:var(--border-width)] border-solid border-input bg-card " +
"inline-grid place-content-center cursor-pointer " +
"[transition:var(--transition-colors)] rounded-xs focus-visible:[outline:none] " +
"focus-visible:[box-shadow:0_0_0_var(--ring-width)_color-mix(in_oklch,_var(--ring)_20%,_transparent)] " +
"checked:border-primary checked:bg-primary data-[state=checked]:border-primary " +
"data-[state=checked]:bg-primary before:content-[''] before:[inline-size:1rem] " +
"before:[block-size:1rem] before:[transform:scale(0)] " +
"before:[transition:transform_var(--duration-fast)_var(--ease-out)] " +
"before:bg-primary-foreground " +
"before:[clip-path:polygon(28.4%_46.4%,20%_59%,42.8%_80%,80%_33.2%,70.4%_23.6%,42.8%_60.8%)] " +
"checked:before:[transform:scale(1)] " +
"data-[state=checked]:before:[transform:scale(1)] indeterminate:border-primary " +
"indeterminate:bg-primary data-[state=indeterminate]:border-primary " +
"data-[state=indeterminate]:bg-primary indeterminate:before:[transform:scale(1)] " +
"indeterminate:before:[clip-path:inset(42%_12%_42%_12%)] " +
"data-[state=indeterminate]:before:[transform:scale(1)] " +
"data-[state=indeterminate]:before:[clip-path:inset(42%_12%_42%_12%)] " +
"disabled:opacity-50 disabled:cursor-not-allowed data-[disabled]:opacity-50 " +
"data-[disabled]:cursor-not-allowed",
},
}}
/>
);
}API
Checkbox
| מאפיין | טיפוס | ברירת מחדל | תיאור |
|---|---|---|---|
id* | string | — | מזהה הקלט המובנה, המשמש גם לקישור אלמנט התווית. |
label | ReactNode | — | תוכן התווית המוצג לצד הקלט בתוך אלמנט תווית עוטף. |
checked | boolean | "indeterminate" | — | מצב הסימון, ההופך את תיבת הסימון למבוקרת; "indeterminate" מציג מצב מעורב. |
defaultChecked | boolean | — | מצב הסימון ההתחלתי של תיבת הסימון הלא מבוקרת, שלאחר מכן מנוהל על ידי הדפדפן. |
disabled | boolean | false | משבית את הקלט המובנה ומגדיר את המאפיין data-disabled. |
name | string | — | השם המשמש לשליחת תיבת הסימון עם טופס. |
value | string | — | הערך הנשלח כשתיבת הסימון מסומנת. |
className | string | — | המחלקה המוחלת על אלמנט התווית העוטף כשמסופקת תווית. |
onCheckedChange | (checked: boolean) => void | — | נקראת עם מצב הסימון החדש כשהמשתמש משנה את מצב תיבת הסימון. |
aria-label | string | — | שם נגיש המשמש כשלא סופקה תווית. |
slotProps | CheckboxSlotProps | — | מאפיינים מובנים לקלט ולתווית העוטפת שנוצרים. |
מקלדת
| מקש | פעולה |
|---|---|
| Space | החלפת מצב בעת מיקוד |
נגישות
קלט תיבת סימון מובנה. מצב לא מוגדר כשמתאים.
נקודות חיבור לעיצוב
data-statedata-disabled