@fpkit/acss 3.1.1 → 3.2.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/{chunk-2NRIP6RB.cjs → chunk-2C3YLBWP.cjs} +3 -3
- package/libs/{chunk-NWJDAHP6.cjs → chunk-2GJHKWEK.cjs} +3 -3
- package/libs/{chunk-FVROL3V5.js → chunk-2JCDEC32.js} +3 -3
- package/libs/{chunk-IRLFZ3OL.js → chunk-3XJC4XUG.js} +2 -2
- package/libs/{chunk-L6PRDL6F.cjs → chunk-5CJPTDK3.cjs} +3 -3
- package/libs/{chunk-E4OSROCA.cjs → chunk-5QSNJQVH.cjs} +3 -3
- package/libs/{chunk-O3JIHC5M.cjs → chunk-6BUJZ4DJ.cjs} +3 -3
- package/libs/{chunk-WXBFBWYF.cjs → chunk-AFINOD2L.cjs} +3 -3
- package/libs/{chunk-HRRHPLER.js → chunk-AWZLSWDO.js} +2 -2
- package/libs/chunk-DDSXKOUB.js +7 -0
- package/libs/chunk-DDSXKOUB.js.map +1 -0
- package/libs/{chunk-CWRNJA4P.js → chunk-DIJBIOFE.js} +3 -3
- package/libs/chunk-EJ6KYBFE.cjs +13 -0
- package/libs/chunk-EJ6KYBFE.cjs.map +1 -0
- package/libs/{chunk-GUJSMQ3V.cjs → chunk-EKJYOCLY.cjs} +3 -3
- package/libs/{chunk-X5RKCLDC.cjs → chunk-F64GE6RG.cjs} +4 -4
- package/libs/{chunk-5RAWNUVD.js → chunk-IBUTNPTQ.js} +2 -2
- package/libs/chunk-IWP4VJEP.cjs +18 -0
- package/libs/chunk-IWP4VJEP.cjs.map +1 -0
- package/libs/{chunk-ZFJ4U45S.js → chunk-KDMX3FAW.js} +2 -2
- package/libs/{chunk-DYFAUAB7.cjs → chunk-LXODKKA3.cjs} +4 -4
- package/libs/{chunk-MPTMPBFT.js → chunk-M7JLT62Q.js} +2 -2
- package/libs/{chunk-IQ76HGVP.js → chunk-MBWI67UT.js} +2 -2
- package/libs/{chunk-O5XAJ7BY.cjs → chunk-NCGVF2QS.cjs} +4 -4
- package/libs/{chunk-W2UIN7EV.cjs → chunk-NPWHQVYB.cjs} +3 -3
- package/libs/{chunk-43TK2ICH.js → chunk-PMWL5XZ4.js} +3 -3
- package/libs/{chunk-KVKQLRJG.js → chunk-TF3GQKOY.js} +2 -2
- package/libs/{chunk-IEB64SWY.js → chunk-U5VA34SU.js} +2 -2
- package/libs/chunk-UGMP72J2.js +8 -0
- package/libs/chunk-UGMP72J2.js.map +1 -0
- package/libs/{chunk-EE3ZWSBY.cjs → chunk-URBGDUFN.cjs} +6 -6
- package/libs/{chunk-TPIB3RQP.js → chunk-ZF6Y7W57.js} +5 -5
- package/libs/component-props-50e69975.d.ts +66 -0
- package/libs/components/box/box.css +1 -0
- package/libs/components/box/box.css.map +1 -0
- package/libs/components/box/box.min.css +3 -0
- package/libs/components/breadcrumbs/breadcrumb.cjs +6 -6
- package/libs/components/breadcrumbs/breadcrumb.js +3 -3
- package/libs/components/button.cjs +4 -4
- package/libs/components/button.d.cts +10 -3
- package/libs/components/button.d.ts +10 -3
- package/libs/components/button.js +2 -2
- package/libs/components/card.cjs +7 -7
- package/libs/components/card.d.cts +13 -85
- package/libs/components/card.d.ts +13 -85
- package/libs/components/card.js +2 -2
- package/libs/components/cards/card.css +1 -1
- package/libs/components/cards/card.css.map +1 -1
- package/libs/components/cards/card.min.css +2 -2
- package/libs/components/cluster/cluster.css +1 -0
- package/libs/components/cluster/cluster.css.map +1 -0
- package/libs/components/cluster/cluster.min.css +3 -0
- package/libs/components/dialog/dialog.cjs +7 -7
- package/libs/components/dialog/dialog.js +5 -5
- package/libs/components/form/fields.cjs +4 -4
- package/libs/components/form/fields.js +2 -2
- package/libs/components/form/textarea.cjs +4 -4
- package/libs/components/form/textarea.js +2 -2
- package/libs/components/grid/grid.css +1 -0
- package/libs/components/grid/grid.css.map +1 -0
- package/libs/components/grid/grid.min.css +3 -0
- package/libs/components/heading/heading.cjs +3 -3
- package/libs/components/heading/heading.js +2 -2
- package/libs/components/icons/icon.cjs +4 -4
- package/libs/components/icons/icon.d.cts +2 -2
- package/libs/components/icons/icon.d.ts +2 -2
- package/libs/components/icons/icon.js +2 -2
- package/libs/components/link/link.cjs +6 -6
- package/libs/components/link/link.js +2 -2
- package/libs/components/list/list.cjs +5 -5
- package/libs/components/list/list.js +2 -2
- package/libs/components/modal.cjs +4 -4
- package/libs/components/modal.d.cts +1 -1
- package/libs/components/modal.d.ts +1 -1
- package/libs/components/modal.js +3 -3
- package/libs/components/nav/nav.cjs +7 -7
- package/libs/components/nav/nav.js +3 -3
- package/libs/components/stack/stack.css +1 -0
- package/libs/components/stack/stack.css.map +1 -0
- package/libs/components/stack/stack.min.css +3 -0
- package/libs/components/tables/table.d.cts +1 -1
- package/libs/components/tables/table.d.ts +1 -1
- package/libs/components/text/text.cjs +5 -5
- package/libs/components/text/text.js +2 -2
- package/libs/hooks.cjs +4 -4
- package/libs/hooks.js +3 -3
- package/libs/{icons-287fce3a.d.ts → icons-df8e744f.d.ts} +1 -1
- package/libs/icons.cjs +3 -3
- package/libs/icons.d.cts +2 -2
- package/libs/icons.d.ts +2 -2
- package/libs/icons.js +2 -2
- package/libs/index.cjs +64 -63
- 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 +923 -4
- package/libs/index.d.ts +923 -4
- package/libs/index.js +28 -28
- package/libs/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/alert/STYLES.mdx +790 -0
- package/src/components/badge/STYLES.mdx +610 -0
- package/src/components/box/README.mdx +401 -0
- package/src/components/box/STYLES.mdx +360 -0
- package/src/components/box/box.scss +245 -0
- package/src/components/box/box.stories.tsx +395 -0
- package/src/components/box/box.test.tsx +425 -0
- package/src/components/box/box.tsx +170 -0
- package/src/components/box/box.types.ts +166 -0
- package/src/components/breadcrumbs/STYLES.mdx +99 -0
- package/src/components/buttons/STYLES.mdx +766 -0
- package/src/components/cards/STYLES.mdx +835 -0
- package/src/components/cards/card.scss +29 -21
- package/src/components/cards/card.tsx +13 -3
- package/src/components/cards/card.types.ts +13 -0
- package/src/components/cluster/README.mdx +595 -0
- package/src/components/cluster/STYLES.mdx +626 -0
- package/src/components/cluster/cluster.scss +86 -0
- package/src/components/cluster/cluster.stories.tsx +385 -0
- package/src/components/cluster/cluster.test.tsx +655 -0
- package/src/components/cluster/cluster.tsx +94 -0
- package/src/components/cluster/cluster.types.ts +75 -0
- package/src/components/details/STYLES.mdx +445 -0
- package/src/components/dialog/STYLES.mdx +888 -0
- package/src/components/flexbox/STYLES.mdx +1 -1
- package/src/components/form/STYLES.mdx +821 -0
- package/src/components/grid/README.mdx +709 -0
- package/src/components/grid/STYLES.mdx +785 -0
- package/src/components/grid/grid.scss +287 -0
- package/src/components/grid/grid.stories.tsx +486 -0
- package/src/components/grid/grid.test.tsx +981 -0
- package/src/components/grid/grid.tsx +222 -0
- package/src/components/grid/grid.types.ts +344 -0
- package/src/components/icons/STYLES.mdx +56 -0
- package/src/components/images/STYLES.mdx +75 -0
- package/src/components/layout/STYLES.mdx +556 -0
- package/src/components/link/STYLES.mdx +75 -0
- package/src/components/list/STYLES.mdx +631 -0
- package/src/components/nav/STYLES.mdx +460 -0
- package/src/components/progress/STYLES.mdx +64 -0
- package/src/components/stack/README.mdx +400 -0
- package/src/components/stack/STYLES.mdx +414 -0
- package/src/components/stack/stack.scss +109 -0
- package/src/components/stack/stack.stories.tsx +559 -0
- package/src/components/stack/stack.test.tsx +426 -0
- package/src/components/stack/stack.tsx +141 -0
- package/src/components/stack/stack.types.ts +133 -0
- package/src/components/tag/STYLES.mdx +105 -0
- package/src/components/text-to-speech/STYLES.mdx +80 -0
- package/src/components/ui.tsx +3 -3
- package/src/index.scss +5 -1
- package/src/index.ts +305 -12
- package/src/sass/GLOBALS-STYLES.md +631 -0
- package/src/sass/_globals.scss +45 -24
- package/src/styles/box/box.css +220 -0
- package/src/styles/box/box.css.map +1 -0
- package/src/styles/cards/card.css +22 -17
- package/src/styles/cards/card.css.map +1 -1
- package/src/styles/cluster/cluster.css +71 -0
- package/src/styles/cluster/cluster.css.map +1 -0
- package/src/styles/grid/grid.css +238 -0
- package/src/styles/grid/grid.css.map +1 -0
- package/src/styles/index.css +667 -49
- package/src/styles/index.css.map +1 -1
- package/src/styles/stack/stack.css +86 -0
- package/src/styles/stack/stack.css.map +1 -0
- package/src/types/component-props.ts +42 -14
- package/src/types/layout-primitives.ts +48 -0
- package/src/types/shared.ts +10 -26
- package/libs/chunk-ENTCUJ3A.cjs +0 -13
- package/libs/chunk-ENTCUJ3A.cjs.map +0 -1
- package/libs/chunk-HHLNOC5T.js +0 -7
- package/libs/chunk-HHLNOC5T.js.map +0 -1
- package/libs/chunk-KK47SYZI.js +0 -8
- package/libs/chunk-KK47SYZI.js.map +0 -1
- package/libs/chunk-W5TKWBFC.cjs +0 -18
- package/libs/chunk-W5TKWBFC.cjs.map +0 -1
- package/libs/component-props-67d978a2.d.ts +0 -38
- /package/libs/{chunk-2NRIP6RB.cjs.map → chunk-2C3YLBWP.cjs.map} +0 -0
- /package/libs/{chunk-NWJDAHP6.cjs.map → chunk-2GJHKWEK.cjs.map} +0 -0
- /package/libs/{chunk-FVROL3V5.js.map → chunk-2JCDEC32.js.map} +0 -0
- /package/libs/{chunk-IRLFZ3OL.js.map → chunk-3XJC4XUG.js.map} +0 -0
- /package/libs/{chunk-L6PRDL6F.cjs.map → chunk-5CJPTDK3.cjs.map} +0 -0
- /package/libs/{chunk-E4OSROCA.cjs.map → chunk-5QSNJQVH.cjs.map} +0 -0
- /package/libs/{chunk-O3JIHC5M.cjs.map → chunk-6BUJZ4DJ.cjs.map} +0 -0
- /package/libs/{chunk-WXBFBWYF.cjs.map → chunk-AFINOD2L.cjs.map} +0 -0
- /package/libs/{chunk-HRRHPLER.js.map → chunk-AWZLSWDO.js.map} +0 -0
- /package/libs/{chunk-CWRNJA4P.js.map → chunk-DIJBIOFE.js.map} +0 -0
- /package/libs/{chunk-GUJSMQ3V.cjs.map → chunk-EKJYOCLY.cjs.map} +0 -0
- /package/libs/{chunk-X5RKCLDC.cjs.map → chunk-F64GE6RG.cjs.map} +0 -0
- /package/libs/{chunk-5RAWNUVD.js.map → chunk-IBUTNPTQ.js.map} +0 -0
- /package/libs/{chunk-ZFJ4U45S.js.map → chunk-KDMX3FAW.js.map} +0 -0
- /package/libs/{chunk-DYFAUAB7.cjs.map → chunk-LXODKKA3.cjs.map} +0 -0
- /package/libs/{chunk-MPTMPBFT.js.map → chunk-M7JLT62Q.js.map} +0 -0
- /package/libs/{chunk-IQ76HGVP.js.map → chunk-MBWI67UT.js.map} +0 -0
- /package/libs/{chunk-O5XAJ7BY.cjs.map → chunk-NCGVF2QS.cjs.map} +0 -0
- /package/libs/{chunk-W2UIN7EV.cjs.map → chunk-NPWHQVYB.cjs.map} +0 -0
- /package/libs/{chunk-43TK2ICH.js.map → chunk-PMWL5XZ4.js.map} +0 -0
- /package/libs/{chunk-KVKQLRJG.js.map → chunk-TF3GQKOY.js.map} +0 -0
- /package/libs/{chunk-IEB64SWY.js.map → chunk-U5VA34SU.js.map} +0 -0
- /package/libs/{chunk-EE3ZWSBY.cjs.map → chunk-URBGDUFN.cjs.map} +0 -0
- /package/libs/{chunk-TPIB3RQP.js.map → chunk-ZF6Y7W57.js.map} +0 -0
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import { Meta, Story, Canvas } from '@storybook/addon-docs/blocks';
|
|
2
|
+
import * as BoxStories from './box.stories';
|
|
3
|
+
|
|
4
|
+
<Meta of={BoxStories} />
|
|
5
|
+
|
|
6
|
+
# Box Component
|
|
7
|
+
|
|
8
|
+
A fundamental container primitive for spacing and sizing control.
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
The Box component is the foundational layout primitive in fpkit, providing a flexible, semantic container with comprehensive control over spacing (padding/margin), sizing, and visual appearance. It uses utility classes generated from props, ensuring consistent styling across your application.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- **Unified Spacing Scale**: Fluid responsive spacing using CSS `clamp()` for automatic adaptation across viewports
|
|
17
|
+
- **Logical Properties**: Uses `padding-inline`/`padding-block` for better internationalization support
|
|
18
|
+
- **Polymorphic Rendering**: Render as any semantic HTML element via the `as` prop
|
|
19
|
+
- **CSS Custom Properties**: All values customizable for theming
|
|
20
|
+
- **Type-Safe**: Full TypeScript support with IntelliSense
|
|
21
|
+
- **Zero Runtime**: Utility classes compiled at build time
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @fpkit/acss
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Basic Usage
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import { Box } from '@fpkit/acss';
|
|
33
|
+
import '@fpkit/acss/styles';
|
|
34
|
+
|
|
35
|
+
function App() {
|
|
36
|
+
return (
|
|
37
|
+
<Box padding="md">
|
|
38
|
+
<h1>Content</h1>
|
|
39
|
+
</Box>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## API Reference
|
|
45
|
+
|
|
46
|
+
### Props
|
|
47
|
+
|
|
48
|
+
| Prop | Type | Default | Description |
|
|
49
|
+
|------|------|---------|-------------|
|
|
50
|
+
| `padding` | `SpacingScale` | - | Padding on all sides |
|
|
51
|
+
| `paddingInline` | `SpacingScale` | - | Padding on inline axis (left/right in LTR) |
|
|
52
|
+
| `paddingBlock` | `SpacingScale` | - | Padding on block axis (top/bottom) |
|
|
53
|
+
| `margin` | `SpacingScale` | - | Margin on all sides |
|
|
54
|
+
| `marginInline` | `SpacingScale` | - | Margin on inline axis |
|
|
55
|
+
| `marginBlock` | `SpacingScale` | - | Margin on block axis |
|
|
56
|
+
| `width` | `'auto' \| 'full' \| 'fit' \| 'max'` | `'auto'` | Width behavior |
|
|
57
|
+
| `maxWidth` | `'xs' \| 'sm' \| 'md' \| 'lg' \| 'xl' \| 'container'` | - | Maximum width constraint |
|
|
58
|
+
| `radius` | `SpacingScale \| 'full'` | - | Border radius |
|
|
59
|
+
| `as` | `BoxElement` | `'div'` | HTML element to render |
|
|
60
|
+
| `className` | `string` | - | Additional CSS classes |
|
|
61
|
+
| `styles` | `CSSProperties` | - | Inline styles |
|
|
62
|
+
| `children` | `ReactNode` | - | Child elements |
|
|
63
|
+
|
|
64
|
+
#### SpacingScale
|
|
65
|
+
|
|
66
|
+
The spacing scale provides fluid, responsive values that adapt to viewport size:
|
|
67
|
+
|
|
68
|
+
- `'0'`: No spacing (0)
|
|
69
|
+
- `'xs'`: Extra small (4-8px responsive)
|
|
70
|
+
- `'sm'`: Small (8-12px responsive)
|
|
71
|
+
- `'md'`: Medium (12-18px responsive)
|
|
72
|
+
- `'lg'`: Large (16-24px responsive)
|
|
73
|
+
- `'xl'`: Extra large (24-32px responsive)
|
|
74
|
+
|
|
75
|
+
#### BoxElement
|
|
76
|
+
|
|
77
|
+
Semantic HTML elements supported via the `as` prop:
|
|
78
|
+
|
|
79
|
+
- `'div'` (default)
|
|
80
|
+
- `'section'`
|
|
81
|
+
- `'article'`
|
|
82
|
+
- `'aside'`
|
|
83
|
+
- `'main'`
|
|
84
|
+
- `'header'`
|
|
85
|
+
- `'footer'`
|
|
86
|
+
- `'nav'`
|
|
87
|
+
|
|
88
|
+
## Usage Examples
|
|
89
|
+
|
|
90
|
+
### Basic Container
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
<Box padding="md">
|
|
94
|
+
<h1>Page Title</h1>
|
|
95
|
+
<p>Content goes here...</p>
|
|
96
|
+
</Box>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Centered Container
|
|
100
|
+
|
|
101
|
+
A common pattern for page layouts with max-width and centered alignment:
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
<Box
|
|
105
|
+
padding="lg"
|
|
106
|
+
maxWidth="container"
|
|
107
|
+
style={{ marginInline: 'auto' }}
|
|
108
|
+
>
|
|
109
|
+
<article>
|
|
110
|
+
<h1>Article Title</h1>
|
|
111
|
+
<p>Centered content with 1200px max width...</p>
|
|
112
|
+
</article>
|
|
113
|
+
</Box>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Card-like Component
|
|
117
|
+
|
|
118
|
+
Create a card with padding, border radius, and shadow:
|
|
119
|
+
|
|
120
|
+
```tsx
|
|
121
|
+
<Box
|
|
122
|
+
padding="lg"
|
|
123
|
+
radius="md"
|
|
124
|
+
as="article"
|
|
125
|
+
styles={{
|
|
126
|
+
backgroundColor: '#fff',
|
|
127
|
+
boxShadow: '0 1px 3px rgba(0,0,0,0.1)',
|
|
128
|
+
border: '1px solid #e0e0e0'
|
|
129
|
+
}}
|
|
130
|
+
>
|
|
131
|
+
<h3>Card Title</h3>
|
|
132
|
+
<p>Card content goes here...</p>
|
|
133
|
+
<button>Action</button>
|
|
134
|
+
</Box>
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Asymmetric Spacing
|
|
138
|
+
|
|
139
|
+
Use logical properties for different horizontal and vertical padding:
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
<Box
|
|
143
|
+
paddingInline="xl"
|
|
144
|
+
paddingBlock="md"
|
|
145
|
+
as="section"
|
|
146
|
+
>
|
|
147
|
+
<p>Wide horizontal padding, narrow vertical padding</p>
|
|
148
|
+
</Box>
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Semantic Sections
|
|
152
|
+
|
|
153
|
+
Use semantic HTML elements for better accessibility:
|
|
154
|
+
|
|
155
|
+
```tsx
|
|
156
|
+
<Box as="main" padding="lg">
|
|
157
|
+
<Box as="section" padding="xl" margin="lg">
|
|
158
|
+
<h2>Section Title</h2>
|
|
159
|
+
<p>Section content...</p>
|
|
160
|
+
</Box>
|
|
161
|
+
|
|
162
|
+
<Box as="aside" padding="md" marginInline="lg">
|
|
163
|
+
<h3>Related Content</h3>
|
|
164
|
+
<p>Sidebar content...</p>
|
|
165
|
+
</Box>
|
|
166
|
+
</Box>
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Full-Width Hero Section
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
<Box
|
|
173
|
+
as="section"
|
|
174
|
+
width="full"
|
|
175
|
+
paddingBlock="xl"
|
|
176
|
+
paddingInline="lg"
|
|
177
|
+
styles={{
|
|
178
|
+
backgroundColor: '#0066cc',
|
|
179
|
+
color: '#fff'
|
|
180
|
+
}}
|
|
181
|
+
>
|
|
182
|
+
<h1>Hero Title</h1>
|
|
183
|
+
<p>Hero subtitle or description...</p>
|
|
184
|
+
</Box>
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Theming with CSS Custom Properties
|
|
188
|
+
|
|
189
|
+
Override CSS variables to customize spacing and appearance:
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
<Box
|
|
193
|
+
padding="lg"
|
|
194
|
+
radius="md"
|
|
195
|
+
styles={{
|
|
196
|
+
// Override spacing scale
|
|
197
|
+
'--spacing-lg': '2rem',
|
|
198
|
+
// Override border radius
|
|
199
|
+
'--box-radius-md': '1rem',
|
|
200
|
+
// Add custom styles
|
|
201
|
+
backgroundColor: '#f8f9fa'
|
|
202
|
+
} as React.CSSProperties}
|
|
203
|
+
>
|
|
204
|
+
<h3>Themed Box</h3>
|
|
205
|
+
<p>Custom spacing and radius via CSS variables</p>
|
|
206
|
+
</Box>
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Composition
|
|
210
|
+
|
|
211
|
+
Box components can be nested for complex layouts:
|
|
212
|
+
|
|
213
|
+
```tsx
|
|
214
|
+
<Box padding="lg" styles={{ backgroundColor: '#f8f9fa' }}>
|
|
215
|
+
<h2>Outer Container</h2>
|
|
216
|
+
|
|
217
|
+
<Box
|
|
218
|
+
padding="md"
|
|
219
|
+
margin="md"
|
|
220
|
+
radius="md"
|
|
221
|
+
styles={{ backgroundColor: '#fff', boxShadow: '0 1px 3px rgba(0,0,0,0.1)' }}
|
|
222
|
+
>
|
|
223
|
+
<h3>Nested Box 1</h3>
|
|
224
|
+
<p>Independent spacing and styling</p>
|
|
225
|
+
</Box>
|
|
226
|
+
|
|
227
|
+
<Box
|
|
228
|
+
padding="md"
|
|
229
|
+
margin="md"
|
|
230
|
+
radius="md"
|
|
231
|
+
styles={{ backgroundColor: '#fff', boxShadow: '0 1px 3px rgba(0,0,0,0.1)' }}
|
|
232
|
+
>
|
|
233
|
+
<h3>Nested Box 2</h3>
|
|
234
|
+
<p>Each Box is self-contained</p>
|
|
235
|
+
</Box>
|
|
236
|
+
</Box>
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Accessibility
|
|
240
|
+
|
|
241
|
+
### Semantic HTML
|
|
242
|
+
|
|
243
|
+
Always prefer semantic HTML elements over generic divs:
|
|
244
|
+
|
|
245
|
+
```tsx
|
|
246
|
+
// ✅ Good - semantic elements
|
|
247
|
+
<Box as="section" padding="lg">
|
|
248
|
+
<Box as="article" padding="md">
|
|
249
|
+
<h2>Article Title</h2>
|
|
250
|
+
</Box>
|
|
251
|
+
</Box>
|
|
252
|
+
|
|
253
|
+
// ❌ Avoid - generic divs when semantic elements make sense
|
|
254
|
+
<Box padding="lg">
|
|
255
|
+
<Box padding="md">
|
|
256
|
+
<h2>Article Title</h2>
|
|
257
|
+
</Box>
|
|
258
|
+
</Box>
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### ARIA Attributes
|
|
262
|
+
|
|
263
|
+
Box forwards all ARIA attributes for enhanced accessibility:
|
|
264
|
+
|
|
265
|
+
```tsx
|
|
266
|
+
<Box
|
|
267
|
+
as="section"
|
|
268
|
+
padding="lg"
|
|
269
|
+
aria-label="Featured content"
|
|
270
|
+
role="region"
|
|
271
|
+
>
|
|
272
|
+
<h2>Featured Articles</h2>
|
|
273
|
+
<p>Content...</p>
|
|
274
|
+
</Box>
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Focus Management
|
|
278
|
+
|
|
279
|
+
Use refs for programmatic focus control:
|
|
280
|
+
|
|
281
|
+
```tsx
|
|
282
|
+
function ScrollToSection() {
|
|
283
|
+
const sectionRef = useRef<HTMLElement>(null);
|
|
284
|
+
|
|
285
|
+
const scrollToSection = () => {
|
|
286
|
+
sectionRef.current?.scrollIntoView({ behavior: 'smooth' });
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
return (
|
|
290
|
+
<>
|
|
291
|
+
<button onClick={scrollToSection}>Jump to Section</button>
|
|
292
|
+
<Box as="section" ref={sectionRef} padding="xl">
|
|
293
|
+
<h2>Target Section</h2>
|
|
294
|
+
</Box>
|
|
295
|
+
</>
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## Best Practices
|
|
301
|
+
|
|
302
|
+
### 1. Use Semantic Elements
|
|
303
|
+
|
|
304
|
+
Choose the most appropriate HTML element for your content:
|
|
305
|
+
|
|
306
|
+
- Use `<section>` for thematic groupings
|
|
307
|
+
- Use `<article>` for self-contained content
|
|
308
|
+
- Use `<aside>` for tangentially related content
|
|
309
|
+
- Use `<main>` for primary page content
|
|
310
|
+
- Use `<header>`/`<footer>` for page or section headers/footers
|
|
311
|
+
- Use `<nav>` for navigation landmarks
|
|
312
|
+
|
|
313
|
+
### 2. Prefer Logical Properties
|
|
314
|
+
|
|
315
|
+
Use `paddingInline`/`paddingBlock` instead of directional padding for better i18n support:
|
|
316
|
+
|
|
317
|
+
```tsx
|
|
318
|
+
// ✅ Good - adapts to text direction
|
|
319
|
+
<Box paddingInline="lg" paddingBlock="md">
|
|
320
|
+
Content
|
|
321
|
+
</Box>
|
|
322
|
+
|
|
323
|
+
// ❌ Avoid - hardcoded direction
|
|
324
|
+
<Box style={{ paddingLeft: '2rem', paddingRight: '2rem' }}>
|
|
325
|
+
Content
|
|
326
|
+
</Box>
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### 3. Leverage the Spacing Scale
|
|
330
|
+
|
|
331
|
+
Use the spacing scale for consistency instead of arbitrary values:
|
|
332
|
+
|
|
333
|
+
```tsx
|
|
334
|
+
// ✅ Good - consistent spacing
|
|
335
|
+
<Box padding="md" margin="lg">
|
|
336
|
+
Content
|
|
337
|
+
</Box>
|
|
338
|
+
|
|
339
|
+
// ❌ Avoid - arbitrary values
|
|
340
|
+
<Box style={{ padding: '15px', margin: '22px' }}>
|
|
341
|
+
Content
|
|
342
|
+
</Box>
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### 4. Compose for Complex Layouts
|
|
346
|
+
|
|
347
|
+
Build complex layouts by composing simple Box components:
|
|
348
|
+
|
|
349
|
+
```tsx
|
|
350
|
+
<Box as="main" maxWidth="container" style={{ marginInline: 'auto' }}>
|
|
351
|
+
<Box as="section" paddingBlock="xl">
|
|
352
|
+
<h1>Main Content</h1>
|
|
353
|
+
</Box>
|
|
354
|
+
<Box as="aside" padding="lg" radius="md">
|
|
355
|
+
<h2>Sidebar</h2>
|
|
356
|
+
</Box>
|
|
357
|
+
</Box>
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
## Related Components
|
|
361
|
+
|
|
362
|
+
- **Stack**: Simplified vertical/horizontal layouts with gap spacing
|
|
363
|
+
- **Cluster**: Wrapping flex layout for inline groups (tags, buttons)
|
|
364
|
+
- **Grid**: CSS Grid primitive with responsive columns
|
|
365
|
+
- **Flex**: Full-featured flexbox container with advanced controls
|
|
366
|
+
|
|
367
|
+
## CSS Variables
|
|
368
|
+
|
|
369
|
+
See [STYLES.mdx](./STYLES.mdx) for a complete reference of CSS custom properties.
|
|
370
|
+
|
|
371
|
+
## TypeScript Support
|
|
372
|
+
|
|
373
|
+
Box is fully typed with TypeScript, providing IntelliSense and type checking:
|
|
374
|
+
|
|
375
|
+
```tsx
|
|
376
|
+
import type { BoxProps } from '@fpkit/acss';
|
|
377
|
+
|
|
378
|
+
const MyBox: React.FC<BoxProps> = (props) => {
|
|
379
|
+
return <Box {...props} />;
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
// Type-safe polymorphic rendering
|
|
383
|
+
const section: React.FC = () => (
|
|
384
|
+
<Box
|
|
385
|
+
as="section"
|
|
386
|
+
// TypeScript knows section-specific props are available
|
|
387
|
+
aria-labelledby="section-title"
|
|
388
|
+
>
|
|
389
|
+
<h2 id="section-title">Section</h2>
|
|
390
|
+
</Box>
|
|
391
|
+
);
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
## Browser Support
|
|
395
|
+
|
|
396
|
+
Box works in all modern browsers that support:
|
|
397
|
+
- CSS Custom Properties
|
|
398
|
+
- CSS Logical Properties
|
|
399
|
+
- CSS `clamp()` function
|
|
400
|
+
|
|
401
|
+
For legacy browser support, consider using PostCSS with appropriate polyfills.
|