@fpkit/acss 3.7.0 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/libs/components/checkbox/checkbox.css +1 -0
- package/libs/components/checkbox/checkbox.css.map +1 -0
- package/libs/components/checkbox/checkbox.min.css +3 -0
- package/libs/index.cjs +27 -26
- package/libs/index.cjs.map +1 -1
- package/libs/index.css +1 -1
- package/libs/index.css.map +1 -1
- package/libs/index.d.cts +356 -1
- package/libs/index.d.ts +356 -1
- package/libs/index.js +5 -5
- package/libs/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/checkbox/README.mdx +263 -0
- package/src/components/checkbox/STYLES.mdx +434 -0
- package/src/components/checkbox/checkbox.scss +432 -0
- package/src/components/checkbox/checkbox.stories.tsx +607 -0
- package/src/components/checkbox/checkbox.test.tsx +535 -0
- package/src/components/checkbox/checkbox.tsx +575 -0
- package/src/components/form/README.mdx +173 -146
- package/src/index.scss +1 -0
- package/src/index.ts +7 -0
- package/src/sass/_columns.scss +13 -9
- package/src/styles/checkbox/checkbox.css +372 -0
- package/src/styles/checkbox/checkbox.css.map +1 -0
- package/src/styles/index.css +371 -0
- package/src/styles/index.css.map +1 -1
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@fpkit/acss",
|
|
3
3
|
"description": "A lightweight React UI library for building modern and accessible components that leverage CSS custom properties for reactive Styles.",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "3.
|
|
5
|
+
"version": "3.8.0",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=22.12.0",
|
|
8
8
|
"npm": ">=8.0.0"
|
|
@@ -126,5 +126,5 @@
|
|
|
126
126
|
"publishConfig": {
|
|
127
127
|
"access": "public"
|
|
128
128
|
},
|
|
129
|
-
"gitHead": "
|
|
129
|
+
"gitHead": "28c554debc03c30107f61b62fd70961861b322ea"
|
|
130
130
|
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { Meta } from "@storybook/addon-docs/blocks";
|
|
2
|
+
import * as CheckboxStories from "./checkbox.stories";
|
|
3
|
+
|
|
4
|
+
<Meta of={CheckboxStories} />
|
|
5
|
+
|
|
6
|
+
# Checkbox
|
|
7
|
+
|
|
8
|
+
Accessible checkbox component with size and color variants, validation support,
|
|
9
|
+
and comprehensive ARIA attributes.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- ✅ **WCAG 2.1 AA Compliant** - Meets accessibility standards
|
|
14
|
+
- ✅ **Controlled & Uncontrolled** - Flexible state management
|
|
15
|
+
- ✅ **Indeterminate State** - Three-state checkbox support
|
|
16
|
+
- ✅ **Validation** - Built-in error messaging
|
|
17
|
+
- ✅ **Size Variants** - sm, md, lg
|
|
18
|
+
- ✅ **Color Variants** - primary, secondary, error, success
|
|
19
|
+
- ✅ **Keyboard Navigation** - Full keyboard support
|
|
20
|
+
- ✅ **Custom Styling** - CSS custom properties
|
|
21
|
+
|
|
22
|
+
## Basic Usage
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { Checkbox } from "@fpkit/acss";
|
|
26
|
+
|
|
27
|
+
function MyForm() {
|
|
28
|
+
return <Checkbox id="terms" label="I accept the terms and conditions" />;
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Controlled Mode
|
|
33
|
+
|
|
34
|
+
Use controlled mode when you need to manage checkbox state in your component:
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import { useState } from "react";
|
|
38
|
+
import { Checkbox } from "@fpkit/acss";
|
|
39
|
+
|
|
40
|
+
function ControlledExample() {
|
|
41
|
+
const [checked, setChecked] = useState(false);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<Checkbox
|
|
45
|
+
id="newsletter"
|
|
46
|
+
label="Subscribe to newsletter"
|
|
47
|
+
checked={checked}
|
|
48
|
+
onChange={(e) => setChecked(e.target.checked)}
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Uncontrolled Mode
|
|
55
|
+
|
|
56
|
+
Use uncontrolled mode for simple forms where you read the value on submission:
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
import { Checkbox } from "@fpkit/acss";
|
|
60
|
+
|
|
61
|
+
function UncontrolledExample() {
|
|
62
|
+
const handleSubmit = (e) => {
|
|
63
|
+
const formData = new FormData(e.target);
|
|
64
|
+
console.log(formData.get("agree")); // "on" if checked
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<form onSubmit={handleSubmit}>
|
|
69
|
+
<Checkbox id="agree" name="agree" label="I agree" defaultChecked={true} />
|
|
70
|
+
<button type="submit">Submit</button>
|
|
71
|
+
</form>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## With Validation
|
|
77
|
+
|
|
78
|
+
Display validation errors and helper text:
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
<Checkbox
|
|
82
|
+
id="required"
|
|
83
|
+
label="Required checkbox"
|
|
84
|
+
required
|
|
85
|
+
validationState="invalid"
|
|
86
|
+
errorMessage="This field is required"
|
|
87
|
+
description="You must check this box to continue"
|
|
88
|
+
/>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Indeterminate State
|
|
92
|
+
|
|
93
|
+
Use for "select all" patterns where some but not all items are selected:
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
import { useState } from "react";
|
|
97
|
+
import { Checkbox } from "@fpkit/acss";
|
|
98
|
+
|
|
99
|
+
function SelectAllExample() {
|
|
100
|
+
const [selectedItems, setSelectedItems] = useState([]);
|
|
101
|
+
const totalItems = 4;
|
|
102
|
+
|
|
103
|
+
const allSelected = selectedItems.length === totalItems;
|
|
104
|
+
const someSelected = selectedItems.length > 0 && !allSelected;
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<Checkbox
|
|
108
|
+
id="select-all"
|
|
109
|
+
label="Select all"
|
|
110
|
+
checked={allSelected}
|
|
111
|
+
indeterminate={someSelected}
|
|
112
|
+
onChange={(e) => {
|
|
113
|
+
if (e.target.checked) {
|
|
114
|
+
setSelectedItems([1, 2, 3, 4]);
|
|
115
|
+
} else {
|
|
116
|
+
setSelectedItems([]);
|
|
117
|
+
}
|
|
118
|
+
}}
|
|
119
|
+
/>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Size Variants
|
|
125
|
+
|
|
126
|
+
Choose from three sizes:
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
<Checkbox id="sm" label="Small" size="sm" />
|
|
130
|
+
<Checkbox id="md" label="Medium (default)" size="md" />
|
|
131
|
+
<Checkbox id="lg" label="Large" size="lg" />
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Color Variants
|
|
135
|
+
|
|
136
|
+
All colors meet WCAG 2.1 AA contrast requirements:
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
<Checkbox id="primary" label="Primary (Blue)" color="primary" />
|
|
140
|
+
<Checkbox id="secondary" label="Secondary (Gray)" color="secondary" />
|
|
141
|
+
<Checkbox id="error" label="Error (Red)" color="error" />
|
|
142
|
+
<Checkbox id="success" label="Success (Green)" color="success" />
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Label Positioning
|
|
146
|
+
|
|
147
|
+
Position labels before or after the checkbox:
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
<Checkbox id="left" label="Label on left" labelPosition="left" />
|
|
151
|
+
<Checkbox id="right" label="Label on right" labelPosition="right" />
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Custom Styling
|
|
155
|
+
|
|
156
|
+
Customize appearance using CSS custom properties:
|
|
157
|
+
|
|
158
|
+
```tsx
|
|
159
|
+
<Checkbox
|
|
160
|
+
id="custom"
|
|
161
|
+
label="Custom styled"
|
|
162
|
+
styles={{
|
|
163
|
+
"--checkbox-size": "2rem",
|
|
164
|
+
"--checkbox-checked-bg": "#7c3aed",
|
|
165
|
+
"--checkbox-radius": "0.5rem",
|
|
166
|
+
}}
|
|
167
|
+
/>
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
See [STYLES.mdx](./STYLES.mdx) for complete CSS variable reference.
|
|
171
|
+
|
|
172
|
+
## Accessibility
|
|
173
|
+
|
|
174
|
+
### WCAG 2.1 AA Compliance
|
|
175
|
+
|
|
176
|
+
The Checkbox component implements multiple WCAG success criteria:
|
|
177
|
+
|
|
178
|
+
- **3.2.2 On Input (Level A)** - Checking the box doesn't cause unexpected
|
|
179
|
+
context changes
|
|
180
|
+
- **4.1.2 Name, Role, Value (Level A)** - Proper ARIA attributes communicate
|
|
181
|
+
state
|
|
182
|
+
- **1.4.3 Contrast (Minimum) (Level AA)** - All color variants meet 4.5:1
|
|
183
|
+
contrast ratio
|
|
184
|
+
- **2.4.7 Focus Visible (Level AA)** - Clear focus indicators on keyboard
|
|
185
|
+
navigation
|
|
186
|
+
|
|
187
|
+
### Keyboard Support
|
|
188
|
+
|
|
189
|
+
- **Tab** - Move focus to/from checkbox
|
|
190
|
+
- **Space** - Toggle checkbox state
|
|
191
|
+
- **Shift+Tab** - Move focus backward
|
|
192
|
+
|
|
193
|
+
### Screen Reader Support
|
|
194
|
+
|
|
195
|
+
- Checkbox state announced (checked/unchecked/indeterminate)
|
|
196
|
+
- Label text announced
|
|
197
|
+
- Description text announced via `aria-describedby`
|
|
198
|
+
- Error messages announced via `aria-errormessage`
|
|
199
|
+
- Required state announced via `aria-required`
|
|
200
|
+
- Disabled state announced via `aria-disabled`
|
|
201
|
+
|
|
202
|
+
### Best Practices
|
|
203
|
+
|
|
204
|
+
1. **Always provide labels** - Use `label` or `children` prop for accessible
|
|
205
|
+
name
|
|
206
|
+
2. **Use semantic colors** - Use `error` variant for validation failures
|
|
207
|
+
3. **Provide descriptions** - Use `description` prop for additional context
|
|
208
|
+
4. **Group related checkboxes** - Use `<fieldset>` and `<legend>` for checkbox
|
|
209
|
+
groups
|
|
210
|
+
5. **Don't mix modes** - Use either controlled or uncontrolled, not both
|
|
211
|
+
|
|
212
|
+
## Props
|
|
213
|
+
|
|
214
|
+
See TypeScript types for complete prop reference with JSDoc documentation.
|
|
215
|
+
|
|
216
|
+
### Key Props
|
|
217
|
+
|
|
218
|
+
| Prop | Type | Default | Description |
|
|
219
|
+
| ----------------- | -------------------------------------------------- | ------------ | -------------------- |
|
|
220
|
+
| `id` | `string` | **required** | Unique identifier |
|
|
221
|
+
| `label` | `ReactNode` | - | Label text |
|
|
222
|
+
| `children` | `ReactNode` | - | Alternative to label |
|
|
223
|
+
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | Size variant |
|
|
224
|
+
| `color` | `"primary" \| "secondary" \| "error" \| "success"` | `"primary"` | Color variant |
|
|
225
|
+
| `checked` | `boolean` | - | Controlled mode |
|
|
226
|
+
| `defaultChecked` | `boolean` | - | Uncontrolled mode |
|
|
227
|
+
| `indeterminate` | `boolean` | `false` | Indeterminate state |
|
|
228
|
+
| `disabled` | `boolean` | - | Disabled state |
|
|
229
|
+
| `required` | `boolean` | `false` | Required field |
|
|
230
|
+
| `validationState` | `"valid" \| "invalid" \| "none"` | `"none"` | Validation state |
|
|
231
|
+
| `errorMessage` | `string` | - | Error message |
|
|
232
|
+
| `description` | `string` | - | Helper text |
|
|
233
|
+
|
|
234
|
+
## Examples
|
|
235
|
+
|
|
236
|
+
See Storybook stories for interactive examples:
|
|
237
|
+
|
|
238
|
+
- **Basic** - Simple checkbox with label
|
|
239
|
+
- **Sizes** - All size variants
|
|
240
|
+
- **Colors** - All color variants
|
|
241
|
+
- **States** - Checked, unchecked, indeterminate, disabled
|
|
242
|
+
- **WithDescription** - Checkbox with helper text
|
|
243
|
+
- **WithError** - Checkbox with validation error
|
|
244
|
+
- **LabelPositions** - Left and right label positioning
|
|
245
|
+
- **Controlled** - Controlled mode example
|
|
246
|
+
- **Uncontrolled** - Uncontrolled mode example
|
|
247
|
+
- **Required** - Required field indicator
|
|
248
|
+
- **ComplexForm** - Complete form example
|
|
249
|
+
- **SelectAll** - Indeterminate "select all" pattern
|
|
250
|
+
- **CustomStyling** - CSS custom property examples
|
|
251
|
+
|
|
252
|
+
## Related Components
|
|
253
|
+
|
|
254
|
+
- **Form** - Form wrapper component
|
|
255
|
+
- **Field** - Form field with label and error handling
|
|
256
|
+
- **Input** - Text input component
|
|
257
|
+
- **Select** - Dropdown select component
|
|
258
|
+
|
|
259
|
+
## Resources
|
|
260
|
+
|
|
261
|
+
- [ARIA Checkbox Pattern](https://www.w3.org/WAI/ARIA/apg/patterns/checkbox/)
|
|
262
|
+
- [WCAG 2.1 Guidelines](https://www.w3.org/WAI/WCAG21/quickref/)
|
|
263
|
+
- [CSS Variables Reference](./STYLES.mdx)
|
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import { Meta } from "@storybook/addon-docs/blocks";
|
|
2
|
+
|
|
3
|
+
<Meta title="FP.React Forms/Inputs/Checkbox/Styles" />
|
|
4
|
+
|
|
5
|
+
# Checkbox CSS Variables
|
|
6
|
+
|
|
7
|
+
Complete reference for customizing the Checkbox component using CSS custom
|
|
8
|
+
properties.
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
The Checkbox component uses CSS custom properties for flexible theming and
|
|
13
|
+
customization. All properties follow the standardized naming convention:
|
|
14
|
+
`--checkbox-{element}-{variant}-{property}`.
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
```css
|
|
19
|
+
/* Global customization */
|
|
20
|
+
:root {
|
|
21
|
+
--checkbox-size: 1.5rem;
|
|
22
|
+
--checkbox-checked-bg: #7c3aed;
|
|
23
|
+
--checkbox-radius: 0.5rem;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* Scoped customization */
|
|
27
|
+
.my-form {
|
|
28
|
+
--checkbox-checked-bg: #10b981;
|
|
29
|
+
--checkbox-focus-outline-color: #86efac;
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
/* Inline customization */
|
|
35
|
+
<Checkbox
|
|
36
|
+
id="custom"
|
|
37
|
+
label="Custom styled"
|
|
38
|
+
styles={{
|
|
39
|
+
"--checkbox-size": "2rem",
|
|
40
|
+
"--checkbox-checked-bg": "#7c3aed",
|
|
41
|
+
}}
|
|
42
|
+
/>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Size Tokens
|
|
46
|
+
|
|
47
|
+
Control checkbox dimensions with size tokens:
|
|
48
|
+
|
|
49
|
+
```css
|
|
50
|
+
--checkbox-size-sm: 1rem; /* 16px - Small */
|
|
51
|
+
--checkbox-size-md: 1.25rem; /* 20px - Medium (default) */
|
|
52
|
+
--checkbox-size-lg: 1.5rem; /* 24px - Large */
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**Usage:**
|
|
56
|
+
|
|
57
|
+
```css
|
|
58
|
+
[data-checkbox~="sm"] {
|
|
59
|
+
--checkbox-size: var(--checkbox-size-sm);
|
|
60
|
+
}
|
|
61
|
+
[data-checkbox~="md"] {
|
|
62
|
+
--checkbox-size: var(--checkbox-size-md);
|
|
63
|
+
}
|
|
64
|
+
[data-checkbox~="lg"] {
|
|
65
|
+
--checkbox-size: var(--checkbox-size-lg);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Base Properties
|
|
70
|
+
|
|
71
|
+
Core checkbox styling properties:
|
|
72
|
+
|
|
73
|
+
| Variable | Default | Description |
|
|
74
|
+
| ------------------------- | ---------------------------- | ---------------------------- |
|
|
75
|
+
| `--checkbox-size` | `var(--checkbox-size-md)` | Width and height of checkbox |
|
|
76
|
+
| `--checkbox-bg` | `#ffffff` | Background color (unchecked) |
|
|
77
|
+
| `--checkbox-border` | `0.125rem solid #6b7280` | Border style |
|
|
78
|
+
| `--checkbox-border-color` | `#6b7280` | Border color |
|
|
79
|
+
| `--checkbox-radius` | `0.25rem` | Border radius (4px) |
|
|
80
|
+
| `--checkbox-cursor` | `pointer` | Cursor style |
|
|
81
|
+
| `--checkbox-transition` | `all 0.2s cubic-bezier(...)` | Transition animation |
|
|
82
|
+
|
|
83
|
+
## Checkmark Properties
|
|
84
|
+
|
|
85
|
+
Styling for the checkmark indicator:
|
|
86
|
+
|
|
87
|
+
| Variable | Default | Description |
|
|
88
|
+
| -------------------------------- | ------------ | ---------------------- |
|
|
89
|
+
| `--checkbox-checkmark-color` | `#ffffff` | Checkmark color |
|
|
90
|
+
| `--checkbox-checkmark-opacity` | `0` | Opacity when unchecked |
|
|
91
|
+
| `--checkbox-checkmark-transform` | `scale(0.7)` | Scale when unchecked |
|
|
92
|
+
|
|
93
|
+
## Label Properties
|
|
94
|
+
|
|
95
|
+
Label text styling:
|
|
96
|
+
|
|
97
|
+
| Variable | Default | Description |
|
|
98
|
+
| ------------------------- | --------- | ------------------------------------ |
|
|
99
|
+
| `--checkbox-label-gap` | `0.5rem` | Gap between checkbox and label (8px) |
|
|
100
|
+
| `--checkbox-label-fs` | `1rem` | Label font size (16px) |
|
|
101
|
+
| `--checkbox-label-color` | `inherit` | Label text color |
|
|
102
|
+
| `--checkbox-label-cursor` | `pointer` | Label cursor style |
|
|
103
|
+
| `--checkbox-label-fw` | `400` | Label font weight |
|
|
104
|
+
|
|
105
|
+
## Description Properties
|
|
106
|
+
|
|
107
|
+
Helper text styling:
|
|
108
|
+
|
|
109
|
+
| Variable | Default | Description |
|
|
110
|
+
| --------------------------------------------- | ----------- | --------------------- |
|
|
111
|
+
| `--checkbox-description-fs` | `0.875rem` | Font size (14px) |
|
|
112
|
+
| `--checkbox-description-color` | `#6b7280` | Text color (Gray 500) |
|
|
113
|
+
| `--checkbox-description-margin-block-start` | `0.25rem` | Top margin (4px) |
|
|
114
|
+
| `--checkbox-description-padding-inline-start` | `calc(...)` | Left padding |
|
|
115
|
+
|
|
116
|
+
## Error Message Properties
|
|
117
|
+
|
|
118
|
+
Error text styling:
|
|
119
|
+
|
|
120
|
+
| Variable | Default | Description |
|
|
121
|
+
| --------------------------------------- | ----------- | -------------------- |
|
|
122
|
+
| `--checkbox-error-fs` | `0.875rem` | Font size (14px) |
|
|
123
|
+
| `--checkbox-error-color` | `#dc2626` | Text color (Red 600) |
|
|
124
|
+
| `--checkbox-error-margin-block-start` | `0.25rem` | Top margin (4px) |
|
|
125
|
+
| `--checkbox-error-padding-inline-start` | `calc(...)` | Left padding |
|
|
126
|
+
|
|
127
|
+
## Required Indicator
|
|
128
|
+
|
|
129
|
+
Required asterisk styling:
|
|
130
|
+
|
|
131
|
+
| Variable | Default | Description |
|
|
132
|
+
| --------------------------- | --------- | --------------- |
|
|
133
|
+
| `--checkbox-required-color` | `#dc2626` | Color (Red 600) |
|
|
134
|
+
| `--checkbox-required-fw` | `600` | Font weight |
|
|
135
|
+
|
|
136
|
+
## Color Variants
|
|
137
|
+
|
|
138
|
+
All color variants meet WCAG 2.1 AA contrast requirements (4.5:1 minimum).
|
|
139
|
+
|
|
140
|
+
### Primary (Blue)
|
|
141
|
+
|
|
142
|
+
```css
|
|
143
|
+
--checkbox-primary-checked-bg: #2563eb; /* 4.68:1 contrast */
|
|
144
|
+
--checkbox-primary-checked-border: #2563eb;
|
|
145
|
+
--checkbox-primary-hover-border: #3b82f6;
|
|
146
|
+
--checkbox-primary-focus-outline-color: #93c5fd;
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Secondary (Gray)
|
|
150
|
+
|
|
151
|
+
```css
|
|
152
|
+
--checkbox-secondary-checked-bg: #4b5563; /* 7.56:1 contrast */
|
|
153
|
+
--checkbox-secondary-checked-border: #4b5563;
|
|
154
|
+
--checkbox-secondary-hover-border: #6b7280;
|
|
155
|
+
--checkbox-secondary-focus-outline-color: #9ca3af;
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Error (Red)
|
|
159
|
+
|
|
160
|
+
```css
|
|
161
|
+
--checkbox-error-checked-bg: #dc2626; /* 5.14:1 contrast */
|
|
162
|
+
--checkbox-error-checked-border: #dc2626;
|
|
163
|
+
--checkbox-error-hover-border: #ef4444;
|
|
164
|
+
--checkbox-error-focus-outline-color: #fca5a5;
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Success (Green)
|
|
168
|
+
|
|
169
|
+
```css
|
|
170
|
+
--checkbox-success-checked-bg: #16a34a; /* 4.54:1 contrast */
|
|
171
|
+
--checkbox-success-checked-border: #16a34a;
|
|
172
|
+
--checkbox-success-hover-border: #22c55e;
|
|
173
|
+
--checkbox-success-focus-outline-color: #86efac;
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## State Properties
|
|
177
|
+
|
|
178
|
+
### Hover State
|
|
179
|
+
|
|
180
|
+
```css
|
|
181
|
+
--checkbox-hover-border-color: #9ca3af;
|
|
182
|
+
--checkbox-hover-bg: #f9fafb;
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Focus State
|
|
186
|
+
|
|
187
|
+
```css
|
|
188
|
+
--checkbox-focus-outline: 0.125rem solid;
|
|
189
|
+
--checkbox-focus-outline-offset: 0.125rem;
|
|
190
|
+
--checkbox-focus-outline-color: var(--checkbox-primary-focus-outline-color);
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Checked State
|
|
194
|
+
|
|
195
|
+
```css
|
|
196
|
+
--checkbox-checked-bg: var(--checkbox-primary-checked-bg);
|
|
197
|
+
--checkbox-checked-border: var(--checkbox-primary-checked-border);
|
|
198
|
+
--checkbox-checked-checkmark-opacity: 1;
|
|
199
|
+
--checkbox-checked-checkmark-transform: scale(1);
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Indeterminate State
|
|
203
|
+
|
|
204
|
+
```css
|
|
205
|
+
--checkbox-indeterminate-bg: var(--checkbox-primary-checked-bg);
|
|
206
|
+
--checkbox-indeterminate-border: var(--checkbox-primary-checked-border);
|
|
207
|
+
--checkbox-indeterminate-dash-width: 0.625rem;
|
|
208
|
+
--checkbox-indeterminate-dash-height: 0.125rem;
|
|
209
|
+
--checkbox-indeterminate-dash-opacity: 1;
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Disabled State
|
|
213
|
+
|
|
214
|
+
```css
|
|
215
|
+
--checkbox-disabled-bg: #f3f4f6;
|
|
216
|
+
--checkbox-disabled-border-color: #d1d5db;
|
|
217
|
+
--checkbox-disabled-opacity: 0.6;
|
|
218
|
+
--checkbox-disabled-cursor: not-allowed;
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Invalid State
|
|
222
|
+
|
|
223
|
+
```css
|
|
224
|
+
--checkbox-invalid-border-color: #dc2626;
|
|
225
|
+
--checkbox-invalid-focus-outline-color: #fca5a5;
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Customization Examples
|
|
229
|
+
|
|
230
|
+
### Example 1: Custom Brand Colors
|
|
231
|
+
|
|
232
|
+
```css
|
|
233
|
+
:root {
|
|
234
|
+
/* Purple brand theme */
|
|
235
|
+
--checkbox-checked-bg: #7c3aed;
|
|
236
|
+
--checkbox-checked-border: #7c3aed;
|
|
237
|
+
--checkbox-focus-outline-color: #c4b5fd;
|
|
238
|
+
--checkbox-hover-border-color: #a78bfa;
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Example 2: Larger Touch Targets
|
|
243
|
+
|
|
244
|
+
```css
|
|
245
|
+
.mobile-form {
|
|
246
|
+
/* Increase size for mobile devices */
|
|
247
|
+
--checkbox-size: 1.75rem; /* 28px */
|
|
248
|
+
--checkbox-label-fs: 1.125rem; /* 18px */
|
|
249
|
+
--checkbox-label-gap: 0.75rem; /* 12px */
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Example 3: Rounded/Pill Style
|
|
254
|
+
|
|
255
|
+
```css
|
|
256
|
+
.rounded-checkboxes {
|
|
257
|
+
--checkbox-radius: 100rem; /* Fully rounded */
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Example 4: Shadow Instead of Border
|
|
262
|
+
|
|
263
|
+
```css
|
|
264
|
+
.shadow-checkboxes {
|
|
265
|
+
--checkbox-border: none;
|
|
266
|
+
--checkbox-bg: #f3f4f6;
|
|
267
|
+
--checkbox-checked-bg: #10b981;
|
|
268
|
+
/* Add shadow via inline styles or custom class */
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Example 5: High Contrast Theme
|
|
273
|
+
|
|
274
|
+
```css
|
|
275
|
+
.high-contrast {
|
|
276
|
+
--checkbox-border: 0.1875rem solid #000000; /* 3px black border */
|
|
277
|
+
--checkbox-checked-bg: #000000;
|
|
278
|
+
--checkbox-focus-outline: 0.1875rem solid #000000;
|
|
279
|
+
--checkbox-focus-outline-offset: 0.25rem;
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Example 6: Dark Mode
|
|
284
|
+
|
|
285
|
+
```css
|
|
286
|
+
.dark-theme {
|
|
287
|
+
--checkbox-bg: #1f2937; /* Gray 800 */
|
|
288
|
+
--checkbox-border-color: #4b5563; /* Gray 600 */
|
|
289
|
+
--checkbox-checked-bg: #3b82f6; /* Blue 500 */
|
|
290
|
+
--checkbox-checked-border: #3b82f6;
|
|
291
|
+
--checkbox-label-color: #f3f4f6; /* Gray 100 */
|
|
292
|
+
--checkbox-description-color: #9ca3af; /* Gray 400 */
|
|
293
|
+
--checkbox-hover-bg: #374151; /* Gray 700 */
|
|
294
|
+
}
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Example 7: Minimal Style
|
|
298
|
+
|
|
299
|
+
```css
|
|
300
|
+
.minimal-checkboxes {
|
|
301
|
+
--checkbox-border: 0.0625rem solid #d1d5db; /* 1px thin border */
|
|
302
|
+
--checkbox-radius: 0.125rem; /* 2px small radius */
|
|
303
|
+
--checkbox-checked-bg: #000000;
|
|
304
|
+
--checkbox-transition: none; /* No animation */
|
|
305
|
+
}
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
## Complete Variable List
|
|
309
|
+
|
|
310
|
+
Here's every CSS variable available for customization:
|
|
311
|
+
|
|
312
|
+
```css
|
|
313
|
+
/* Size Tokens */
|
|
314
|
+
--checkbox-size-sm
|
|
315
|
+
--checkbox-size-md
|
|
316
|
+
--checkbox-size-lg
|
|
317
|
+
|
|
318
|
+
/* Base Properties */
|
|
319
|
+
--checkbox-size
|
|
320
|
+
--checkbox-bg
|
|
321
|
+
--checkbox-border
|
|
322
|
+
--checkbox-border-color
|
|
323
|
+
--checkbox-radius
|
|
324
|
+
--checkbox-cursor
|
|
325
|
+
--checkbox-transition
|
|
326
|
+
|
|
327
|
+
/* Checkmark */
|
|
328
|
+
--checkbox-checkmark-color
|
|
329
|
+
--checkbox-checkmark-opacity
|
|
330
|
+
--checkbox-checkmark-transform
|
|
331
|
+
|
|
332
|
+
/* Label */
|
|
333
|
+
--checkbox-label-gap
|
|
334
|
+
--checkbox-label-fs
|
|
335
|
+
--checkbox-label-color
|
|
336
|
+
--checkbox-label-cursor
|
|
337
|
+
--checkbox-label-fw
|
|
338
|
+
|
|
339
|
+
/* Description */
|
|
340
|
+
--checkbox-description-fs
|
|
341
|
+
--checkbox-description-color
|
|
342
|
+
--checkbox-description-margin-block-start
|
|
343
|
+
--checkbox-description-padding-inline-start
|
|
344
|
+
|
|
345
|
+
/* Error */
|
|
346
|
+
--checkbox-error-fs
|
|
347
|
+
--checkbox-error-color
|
|
348
|
+
--checkbox-error-margin-block-start
|
|
349
|
+
--checkbox-error-padding-inline-start
|
|
350
|
+
|
|
351
|
+
/* Required */
|
|
352
|
+
--checkbox-required-color
|
|
353
|
+
--checkbox-required-fw
|
|
354
|
+
|
|
355
|
+
/* Primary Variant */
|
|
356
|
+
--checkbox-primary-checked-bg
|
|
357
|
+
--checkbox-primary-checked-border
|
|
358
|
+
--checkbox-primary-hover-border
|
|
359
|
+
--checkbox-primary-focus-outline-color
|
|
360
|
+
|
|
361
|
+
/* Secondary Variant */
|
|
362
|
+
--checkbox-secondary-checked-bg
|
|
363
|
+
--checkbox-secondary-checked-border
|
|
364
|
+
--checkbox-secondary-hover-border
|
|
365
|
+
--checkbox-secondary-focus-outline-color
|
|
366
|
+
|
|
367
|
+
/* Error Variant */
|
|
368
|
+
--checkbox-error-checked-bg
|
|
369
|
+
--checkbox-error-checked-border
|
|
370
|
+
--checkbox-error-hover-border
|
|
371
|
+
--checkbox-error-focus-outline-color
|
|
372
|
+
|
|
373
|
+
/* Success Variant */
|
|
374
|
+
--checkbox-success-checked-bg
|
|
375
|
+
--checkbox-success-checked-border
|
|
376
|
+
--checkbox-success-hover-border
|
|
377
|
+
--checkbox-success-focus-outline-color
|
|
378
|
+
|
|
379
|
+
/* Hover State */
|
|
380
|
+
--checkbox-hover-border-color
|
|
381
|
+
--checkbox-hover-bg
|
|
382
|
+
|
|
383
|
+
/* Focus State */
|
|
384
|
+
--checkbox-focus-outline
|
|
385
|
+
--checkbox-focus-outline-offset
|
|
386
|
+
--checkbox-focus-outline-color
|
|
387
|
+
|
|
388
|
+
/* Checked State */
|
|
389
|
+
--checkbox-checked-bg
|
|
390
|
+
--checkbox-checked-border
|
|
391
|
+
--checkbox-checked-checkmark-opacity
|
|
392
|
+
--checkbox-checked-checkmark-transform
|
|
393
|
+
|
|
394
|
+
/* Indeterminate State */
|
|
395
|
+
--checkbox-indeterminate-bg
|
|
396
|
+
--checkbox-indeterminate-border
|
|
397
|
+
--checkbox-indeterminate-dash-width
|
|
398
|
+
--checkbox-indeterminate-dash-height
|
|
399
|
+
--checkbox-indeterminate-dash-opacity
|
|
400
|
+
|
|
401
|
+
/* Disabled State */
|
|
402
|
+
--checkbox-disabled-bg
|
|
403
|
+
--checkbox-disabled-border-color
|
|
404
|
+
--checkbox-disabled-opacity
|
|
405
|
+
--checkbox-disabled-cursor
|
|
406
|
+
|
|
407
|
+
/* Invalid State */
|
|
408
|
+
--checkbox-invalid-border-color
|
|
409
|
+
--checkbox-invalid-focus-outline-color
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
## Best Practices
|
|
413
|
+
|
|
414
|
+
### ✅ Do
|
|
415
|
+
|
|
416
|
+
- Use CSS custom properties for theming
|
|
417
|
+
- Follow the naming convention when creating new variables
|
|
418
|
+
- Test custom colors for WCAG contrast requirements
|
|
419
|
+
- Use rem units for all size-related properties
|
|
420
|
+
- Scope variables appropriately (:root, class, inline)
|
|
421
|
+
|
|
422
|
+
### ❌ Don't
|
|
423
|
+
|
|
424
|
+
- Use pixel units (use rem instead)
|
|
425
|
+
- Override library source files directly
|
|
426
|
+
- Create one-off variables that don't follow the naming pattern
|
|
427
|
+
- Remove required variables (checkbox will break)
|
|
428
|
+
- Use `!important` unless absolutely necessary
|
|
429
|
+
|
|
430
|
+
## Resources
|
|
431
|
+
|
|
432
|
+
- [CSS Variables Guide](../../docs/css-variables.md)
|
|
433
|
+
- [WCAG Color Contrast Checker](https://webaim.org/resources/contrastchecker/)
|
|
434
|
+
- [Checkbox Component README](./README.mdx)
|