@companycam/slab-web 2.0.4 → 2.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@companycam/slab-web",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "main": "./index.js",
5
5
  "module": "./index.mjs",
6
6
  "types": "./index.d.ts",
@@ -0,0 +1,234 @@
1
+ ---
2
+ name: slab/using-tokens-web
3
+ description: >
4
+ Apply Slab design tokens in a React web app via CSS custom properties.
5
+ Covers required one-time CSS imports from @companycam/slab-tokens
6
+ (base.css, light_environment.css, dark_environment.css), CSS variable naming
7
+ (--cc_color_*, --cc_size_*), web color categories (brand, utility, background,
8
+ text, button, link, border, depth, label, collab), ccMargin spacing prop on
9
+ Slab components, spacing/border/text size tokens, and depth (shadow) tokens.
10
+ Load when writing custom styled-components, applying color or spacing outside
11
+ a Slab component, or selecting a token value to match a design spec.
12
+ type: core
13
+ library: slab-web
14
+ library_version: '2.0.4'
15
+ sources:
16
+ - 'CompanyCam/slab:packages/slab-tokens/src/tokens/colors/color.json'
17
+ - 'CompanyCam/slab:packages/slab-tokens/src/tokens/sizes/size.json'
18
+ - 'CompanyCam/slab:packages/slab-tokens/dist/css/base.css'
19
+ - 'CompanyCam/slab:packages/slab-tokens/dist/css/light_environment.css'
20
+ - 'CompanyCam/slab:packages/slab-web/src/lib/shared/styles.ts'
21
+ ---
22
+
23
+ # Slab Web — Design Tokens
24
+
25
+ ## Setup
26
+
27
+ Add three CSS imports once in your app's root stylesheet or entry file. All `--cc_*` CSS variables are undefined without them — this is an app-level setup, not per-component.
28
+
29
+ ```css
30
+ /* app root stylesheet — add once */
31
+ @import '@companycam/slab-tokens/css/base.css';
32
+ @import '@companycam/slab-tokens/css/light_environment.css';
33
+ @import '@companycam/slab-tokens/css/dark_environment.css';
34
+ ```
35
+
36
+ ## Core Patterns
37
+
38
+ ### Apply color tokens in a styled component
39
+
40
+ ```tsx
41
+ import styled from 'styled-components';
42
+
43
+ const ErrorText = styled.span`
44
+ color: var(--cc_color_utility_destroy);
45
+ `;
46
+
47
+ const Card = styled.div`
48
+ background-color: var(--cc_color_background_2);
49
+ border: var(--cc_size_border_width_s) solid var(--cc_color_border_default);
50
+ border-radius: var(--cc_size_border_radius_l);
51
+ box-shadow: 0 var(--cc_size_depth_2_y) var(--cc_size_depth_2_blur) var(--cc_color_depth_2);
52
+ `;
53
+ ```
54
+
55
+ ### Apply spacing via ccMargin on a Slab component
56
+
57
+ `ccMargin` accepts space-separated token names following CSS shorthand order (top right bottom left).
58
+
59
+ ```tsx
60
+ import { Button } from '@companycam/slab-web';
61
+
62
+ <Button ccMargin="m">Save</Button> // 16px all sides
63
+ <Button ccMargin="s m">Save</Button> // 8px vertical, 16px horizontal
64
+ <Button ccMargin="xl l m s">Save</Button> // top right bottom left
65
+ ```
66
+
67
+ ### Apply spacing tokens in CSS
68
+
69
+ ```css
70
+ .feature-section {
71
+ padding: var(--cc_size_spacing_l) var(--cc_size_spacing_m);
72
+ gap: var(--cc_size_spacing_s);
73
+ }
74
+ ```
75
+
76
+ ### Apply text size tokens in a styled component
77
+
78
+ For typography, prefer the `Text` component. When a custom element needs a size token:
79
+
80
+ ```tsx
81
+ import styled from 'styled-components';
82
+
83
+ const MetaLabel = styled.span`
84
+ font-size: var(--cc_size_text_xs); /* 12px */
85
+ color: var(--cc_color_text_subtle);
86
+ `;
87
+
88
+ const SectionTitle = styled.h2`
89
+ font-size: var(--cc_size_text_xl); /* 24px */
90
+ color: var(--cc_color_text_default);
91
+ `;
92
+ ```
93
+
94
+ ## Token Reference
95
+
96
+ ### Color tokens (`--cc_color_*`)
97
+
98
+ | Category | Key tokens |
99
+ | ------------ | -------------------------------------------------------------------------------------------------------------------------------- |
100
+ | `brand` | `brand_primary` (#0967D2), `brand_secondary` (#142334), `brand_accent` (#FFD000) |
101
+ | `utility` | `utility_destroy`, `utility_success`, `utility_caution`, `utility_info`, `utility_assigned`, `utility_add_on`, `utility_upgrade` |
102
+ | `background` | `background_1` (page default), `background_2` (sidebars/callouts), `background_3` (chips/avatars), `background_backdrop` |
103
+ | `text` | `text_default`, `text_subtle`, `text_nonessential` |
104
+ | `button` | `button_background_primary/secondary/subtle/destroy/success`, `button_text_primary/secondary/subtle/destroy/success` |
105
+ | `link` | `link_primary`, `link_secondary`, `link_subtle` |
106
+ | `border` | `border_default`, `border_input_inactive`, `border_input_active` |
107
+ | `depth` | `depth_1/2/3` (shadow color); pair with `--cc_size_depth_{n}_blur` and `--cc_size_depth_{n}_y` |
108
+ | `label` | `label_green/blue/purple/navy/yellow/orange/red/light-gray/dark-gray` |
109
+ | `collab` | `collab_purple/orange/green/blue/red/yellow/navy/plum/magenta/brown/owner` |
110
+
111
+ Note: New primitive color scales (`--cc_color_blue_500`, `--cc_color_slate_200`, etc.) exist in base.css but are not used by the Slab web component library. Use the semantic categories above. Only reach for primitives if a design explicitly specifies one.
112
+
113
+ ### Spacing tokens (`--cc_size_spacing_*`)
114
+
115
+ `xxs` 2px · `xs` 4px · `s` 8px · `m` 16px · `l` 24px · `xl` 32px · `xxl` 48px
116
+
117
+ ### Text size tokens (`--cc_size_text_*`)
118
+
119
+ `xxs` 10px · `xs` 12px · `s` 14px · `m` 16px · `l` 20px · `xl` 24px · `xxl` 32px · `xxxl` 42px
120
+
121
+ ### Border tokens
122
+
123
+ - Radius: `--cc_size_border_radius_s/m/l/xl/xxl/pill` (2/4/8/16/24/1000px)
124
+ - Width: `--cc_size_border_width_s/m/l/xl` (1/2/4/8px)
125
+
126
+ ### Depth (shadow) tokens
127
+
128
+ ```css
129
+ box-shadow: 0 var(--cc_size_depth_2_y) var(--cc_size_depth_2_blur) var(--cc_color_depth_2);
130
+ /* depth 1: tooltips · depth 2: cards/popovers · depth 3: modals/floating bars */
131
+ ```
132
+
133
+ ## Common Mistakes
134
+
135
+ ### HIGH Missing slab-tokens CSS imports — all variables undefined
136
+
137
+ Wrong:
138
+
139
+ ```css
140
+ /* no CSS imports — all --cc_* variables resolve to empty string */
141
+ ```
142
+
143
+ Correct:
144
+
145
+ ```css
146
+ /* once in app root stylesheet */
147
+ @import '@companycam/slab-tokens/css/base.css';
148
+ @import '@companycam/slab-tokens/css/light_environment.css';
149
+ @import '@companycam/slab-tokens/css/dark_environment.css';
150
+ ```
151
+
152
+ Without all three imports every `--cc_*` variable is undefined, components render unstyled, and no error is thrown. These are app-level — add once, not per component.
153
+
154
+ Source: `CompanyCam/slab:packages/slab-tokens/dist/css/`
155
+
156
+ ### HIGH Constructing CSS variable names with wrong separators or structure
157
+
158
+ Wrong:
159
+
160
+ ```css
161
+ color: var(--cc-color-primary); /* hyphens instead of underscores */
162
+ background: var(--cc_color_action_primary); /* "action" category doesn't exist */
163
+ border: var(--cc_color_border); /* missing subcategory */
164
+ ```
165
+
166
+ Correct:
167
+
168
+ ```css
169
+ color: var(--cc_color_button_background_primary);
170
+ background: var(--cc_color_background_1);
171
+ border-color: var(--cc_color_border_default);
172
+ ```
173
+
174
+ All Slab CSS variables use underscores and follow the full `--cc_{type}_{category}_{subcategory}` path. A plausible-but-wrong name resolves to empty silently.
175
+
176
+ Source: `CompanyCam/slab:packages/slab-tokens/dist/css/base.css`
177
+
178
+ ### HIGH Using hardcoded hex or rgb values instead of CSS variables
179
+
180
+ Wrong:
181
+
182
+ ```tsx
183
+ const ErrorText = styled.span`
184
+ color: #ef4e4e;
185
+ `;
186
+ ```
187
+
188
+ Correct:
189
+
190
+ ```tsx
191
+ const ErrorText = styled.span`
192
+ color: var(--cc_color_utility_destroy);
193
+ `;
194
+ ```
195
+
196
+ Hardcoded values don't respond to dark mode (light/dark env CSS files swap variable values automatically) and drift when the design system updates.
197
+
198
+ Source: `CompanyCam/slab:packages/slab-tokens/src/tokens/colors/color.json`
199
+
200
+ ### MEDIUM Passing px values to ccMargin instead of token strings
201
+
202
+ Wrong:
203
+
204
+ ```tsx
205
+ <Button ccMargin="16px 8px">Save</Button>
206
+ ```
207
+
208
+ Correct:
209
+
210
+ ```tsx
211
+ <Button ccMargin="m s">Save</Button>
212
+ ```
213
+
214
+ `ccMargin` passes values through `spacingTokensToCSS()` which maps token names to CSS variable calls. Passing `16px` produces invalid CSS output silently. Valid values: `xxs xs s m l xl xxl`.
215
+
216
+ Source: `CompanyCam/slab:packages/slab-web/src/lib/shared/styles.ts`
217
+
218
+ ### MEDIUM Using inline style with px instead of ccMargin or CSS variables
219
+
220
+ Wrong:
221
+
222
+ ```tsx
223
+ <Button style={{ margin: '16px' }}>Save</Button>
224
+ ```
225
+
226
+ Correct:
227
+
228
+ ```tsx
229
+ <Button ccMargin="m">Save</Button>
230
+ ```
231
+
232
+ Inline style bypasses the token system entirely and does not adapt to dark mode. Use `ccMargin` on Slab components and CSS variables in custom styled-components.
233
+
234
+ Source: `CompanyCam/slab:packages/slab-web/src/lib/shared/styles.ts`