@carbon/layout 12.0.0-alpha.1 → 12.0.0-alpha.3

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/umd/index.js ADDED
@@ -0,0 +1,277 @@
1
+ (function(global, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.CarbonLayout = {}));
3
+ })(this, function(exports) {
4
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
5
+ //#region js/generated/layout-tokens.js
6
+ const spacing01 = "0.125rem";
7
+ const spacing02 = "0.25rem";
8
+ const spacing03 = "0.5rem";
9
+ const spacing04 = "0.75rem";
10
+ const spacing05 = "1rem";
11
+ const spacing06 = "1.5rem";
12
+ const spacing07 = "2rem";
13
+ const spacing08 = "2.5rem";
14
+ const spacing09 = "3rem";
15
+ const spacing10 = "4rem";
16
+ const spacing11 = "5rem";
17
+ const spacing12 = "6rem";
18
+ const spacing13 = "10rem";
19
+ const fluidSpacing01 = 0;
20
+ const fluidSpacing02 = "2vw";
21
+ const fluidSpacing03 = "5vw";
22
+ const fluidSpacing04 = "10vw";
23
+ const container01 = "1.5rem";
24
+ const container02 = "2rem";
25
+ const container03 = "2.5rem";
26
+ const container04 = "3rem";
27
+ const container05 = "4rem";
28
+ const sizeXs = "1.5rem";
29
+ const sizeSm = "2rem";
30
+ const sizeMd = "2.5rem";
31
+ const sizeLg = "3rem";
32
+ const sizeXl = "4rem";
33
+ const size2xl = "5rem";
34
+ const iconSize01 = "1rem";
35
+ const iconSize02 = "1.25rem";
36
+ const borderRadius00 = "0px";
37
+ const borderRadius02 = "0.125rem";
38
+ const borderRadius04 = "0.25rem";
39
+ const borderRadius08 = "0.5rem";
40
+ const borderRadius16 = "1rem";
41
+ const borderRadius24 = "1.5rem";
42
+ const borderRadiusMax = "999999px";
43
+ const layout01 = "1rem";
44
+ const layout02 = "1.5rem";
45
+ const layout03 = "2rem";
46
+ const layout04 = "3rem";
47
+ const layout05 = "4rem";
48
+ const layout06 = "6rem";
49
+ const layout07 = "10rem";
50
+ //#endregion
51
+ //#region src/tokens.ts
52
+ /**
53
+ * Copyright IBM Corp. 2018, 2026
54
+ *
55
+ * This source code is licensed under the Apache-2.0 license found in the
56
+ * LICENSE file in the root directory of this source tree.
57
+ */
58
+ const unstable_tokens = [
59
+ "spacing01",
60
+ "spacing02",
61
+ "spacing03",
62
+ "spacing04",
63
+ "spacing05",
64
+ "spacing06",
65
+ "spacing07",
66
+ "spacing08",
67
+ "spacing09",
68
+ "spacing10",
69
+ "spacing11",
70
+ "spacing12",
71
+ "spacing13",
72
+ "fluidSpacing01",
73
+ "fluidSpacing02",
74
+ "fluidSpacing03",
75
+ "fluidSpacing04",
76
+ "container01",
77
+ "container02",
78
+ "container03",
79
+ "container04",
80
+ "container05",
81
+ "sizeXSmall",
82
+ "sizeSmall",
83
+ "sizeMedium",
84
+ "sizeLarge",
85
+ "sizeXLarge",
86
+ "size2XLarge",
87
+ "iconSize01",
88
+ "iconSize02",
89
+ "layout01",
90
+ "layout02",
91
+ "layout03",
92
+ "layout04",
93
+ "layout05",
94
+ "layout06",
95
+ "layout07"
96
+ ];
97
+ //#endregion
98
+ //#region src/index.ts
99
+ const baseFontSize = 16;
100
+ const rem = (px) => {
101
+ return `${px / 16}rem`;
102
+ };
103
+ const em = (px) => {
104
+ return `${px / 16}em`;
105
+ };
106
+ const px = (value) => {
107
+ return `${value}px`;
108
+ };
109
+ const breakpoints = {
110
+ sm: {
111
+ width: rem(320),
112
+ columns: 4,
113
+ margin: "0"
114
+ },
115
+ md: {
116
+ width: rem(672),
117
+ columns: 8,
118
+ margin: rem(16)
119
+ },
120
+ lg: {
121
+ width: rem(1056),
122
+ columns: 16,
123
+ margin: rem(16)
124
+ },
125
+ xlg: {
126
+ width: rem(1312),
127
+ columns: 16,
128
+ margin: rem(16)
129
+ },
130
+ max: {
131
+ width: rem(1584),
132
+ columns: 16,
133
+ margin: rem(24)
134
+ }
135
+ };
136
+ const breakpointUp = (name) => {
137
+ return `@media (min-width: ${breakpoints[name].width})`;
138
+ };
139
+ const breakpointDown = (name) => {
140
+ return `@media (max-width: ${breakpoints[name].width})`;
141
+ };
142
+ const breakpoint = breakpointUp;
143
+ const miniUnit = 8;
144
+ const miniUnits = (count) => {
145
+ return rem(8 * count);
146
+ };
147
+ const spacing = [
148
+ spacing01,
149
+ spacing02,
150
+ spacing03,
151
+ spacing04,
152
+ spacing05,
153
+ spacing06,
154
+ spacing07,
155
+ spacing08,
156
+ spacing09,
157
+ spacing10,
158
+ spacing11,
159
+ spacing12,
160
+ spacing13
161
+ ];
162
+ const fluidSpacing = [
163
+ 0,
164
+ "2vw",
165
+ "5vw",
166
+ fluidSpacing04
167
+ ];
168
+ const layout = [
169
+ layout01,
170
+ layout02,
171
+ layout03,
172
+ layout04,
173
+ layout05,
174
+ layout06,
175
+ layout07
176
+ ];
177
+ const container = [
178
+ container01,
179
+ container02,
180
+ container03,
181
+ container04,
182
+ container05
183
+ ];
184
+ const sizeXSmall = sizeXs;
185
+ const sizeSmall = sizeSm;
186
+ const sizeMedium = sizeMd;
187
+ const sizeLarge = sizeLg;
188
+ const sizeXLarge = sizeXl;
189
+ const size2XLarge = size2xl;
190
+ const sizes = {
191
+ XSmall: sizeXSmall,
192
+ Small: sizeSmall,
193
+ Medium: sizeMedium,
194
+ Large: sizeLarge,
195
+ XLarge: sizeXLarge,
196
+ "2XLarge": size2XLarge
197
+ };
198
+ const iconSize = [iconSize01, iconSize02];
199
+ const borderRadius = {
200
+ "border-radius-00": "0px",
201
+ "border-radius-02": borderRadius02,
202
+ "border-radius-04": borderRadius04,
203
+ "border-radius-08": borderRadius08,
204
+ "border-radius-16": borderRadius16,
205
+ "border-radius-24": borderRadius24,
206
+ "border-radius-max": borderRadiusMax
207
+ };
208
+ //#endregion
209
+ exports.baseFontSize = baseFontSize;
210
+ exports.borderRadius = borderRadius;
211
+ exports.borderRadius00 = borderRadius00;
212
+ exports.borderRadius02 = borderRadius02;
213
+ exports.borderRadius04 = borderRadius04;
214
+ exports.borderRadius08 = borderRadius08;
215
+ exports.borderRadius16 = borderRadius16;
216
+ exports.borderRadius24 = borderRadius24;
217
+ exports.borderRadiusMax = borderRadiusMax;
218
+ exports.breakpoint = breakpoint;
219
+ exports.breakpointDown = breakpointDown;
220
+ exports.breakpointUp = breakpointUp;
221
+ exports.breakpoints = breakpoints;
222
+ exports.container = container;
223
+ exports.container01 = container01;
224
+ exports.container02 = container02;
225
+ exports.container03 = container03;
226
+ exports.container04 = container04;
227
+ exports.container05 = container05;
228
+ exports.em = em;
229
+ exports.fluidSpacing = fluidSpacing;
230
+ exports.fluidSpacing01 = fluidSpacing01;
231
+ exports.fluidSpacing02 = fluidSpacing02;
232
+ exports.fluidSpacing03 = fluidSpacing03;
233
+ exports.fluidSpacing04 = fluidSpacing04;
234
+ exports.iconSize = iconSize;
235
+ exports.iconSize01 = iconSize01;
236
+ exports.iconSize02 = iconSize02;
237
+ exports.layout = layout;
238
+ exports.layout01 = layout01;
239
+ exports.layout02 = layout02;
240
+ exports.layout03 = layout03;
241
+ exports.layout04 = layout04;
242
+ exports.layout05 = layout05;
243
+ exports.layout06 = layout06;
244
+ exports.layout07 = layout07;
245
+ exports.miniUnit = miniUnit;
246
+ exports.miniUnits = miniUnits;
247
+ exports.px = px;
248
+ exports.rem = rem;
249
+ exports.size2XLarge = size2XLarge;
250
+ exports.size2xl = size2xl;
251
+ exports.sizeLarge = sizeLarge;
252
+ exports.sizeLg = sizeLg;
253
+ exports.sizeMd = sizeMd;
254
+ exports.sizeMedium = sizeMedium;
255
+ exports.sizeSm = sizeSm;
256
+ exports.sizeSmall = sizeSmall;
257
+ exports.sizeXLarge = sizeXLarge;
258
+ exports.sizeXSmall = sizeXSmall;
259
+ exports.sizeXl = sizeXl;
260
+ exports.sizeXs = sizeXs;
261
+ exports.sizes = sizes;
262
+ exports.spacing = spacing;
263
+ exports.spacing01 = spacing01;
264
+ exports.spacing02 = spacing02;
265
+ exports.spacing03 = spacing03;
266
+ exports.spacing04 = spacing04;
267
+ exports.spacing05 = spacing05;
268
+ exports.spacing06 = spacing06;
269
+ exports.spacing07 = spacing07;
270
+ exports.spacing08 = spacing08;
271
+ exports.spacing09 = spacing09;
272
+ exports.spacing10 = spacing10;
273
+ exports.spacing11 = spacing11;
274
+ exports.spacing12 = spacing12;
275
+ exports.spacing13 = spacing13;
276
+ exports.unstable_tokens = unstable_tokens;
277
+ });
@@ -1,266 +0,0 @@
1
- # Layout Tokens (DTCG Format)
2
-
3
- This directory contains `@carbon/layout` design tokens in the
4
- [Design Tokens Community Group (DTCG)](https://tr.designtokens.org/format/)
5
- format.
6
-
7
- ## File
8
-
9
- ```
10
- dtcg/
11
- └── layout.json # All layout tokens organised into DTCG groups
12
- ```
13
-
14
- Tokens are grouped using **native DTCG token groups**. Each top-level key in the
15
- JSON (e.g. `"spacing"`, `"border-radius"`) is a group, and the tokens live
16
- inside it:
17
-
18
- ```json
19
- {
20
- "spacing": {
21
- "$description": "Spacing scale based on the 8px mini-unit grid.",
22
- "spacing-05": {
23
- "$type": "dimension",
24
- "$value": 2,
25
- "$extensions": { "carbon.layout": { "converter": "miniUnits" } }
26
- }
27
- }
28
- }
29
- ```
30
-
31
- The group name is the **authoritative category** for a token. The Style
32
- Dictionary pipeline reads `token.path[0]` (the group key) to decide which
33
- generated file the token belongs to — no name-prefix inference, no hidden
34
- ordering rules.
35
-
36
- ## Token Format
37
-
38
- All tokens follow the DTCG specification. Every token has `$type`, `$value`, and
39
- `$description`. Some tokens carry a `carbon.layout` extension that describes how
40
- the value was derived.
41
-
42
- ### Keys
43
-
44
- | Key | Required | Description |
45
- | -------------- | -------- | --------------------------------------------------- |
46
- | `$type` | ✅ | Always `"dimension"` for layout tokens |
47
- | `$value` | ✅ | The token value — see **Authoring values** below |
48
- | `$description` | ✅ | Human-readable description of purpose and usage |
49
- | `$extensions` | — | Carbon-specific metadata — see **Extensions** below |
50
-
51
- ---
52
-
53
- ## Authoring values
54
-
55
- The `$value` field has two modes depending on whether `$extensions` is present.
56
-
57
- ### Without extensions — resolved CSS value
58
-
59
- When no `carbon.layout` extension is present, `$value` must be a **fully
60
- resolved CSS value** including its unit. The build pipeline uses it as-is.
61
-
62
- ```json
63
- "fluid-spacing-02": {
64
- "$type": "dimension",
65
- "$value": "2vw",
66
- "$description": "Fluid spacing token — 2vw."
67
- }
68
- ```
69
-
70
- Valid units: `rem`, `px`, `vw`, `vh`, `%`, or `0` (unitless zero).
71
-
72
- ### With extensions — raw numeric input + converter
73
-
74
- When `carbon.layout.converter` is present, `$value` is the **raw numeric input**
75
- to that converter function. The build pipeline resolves it to the final CSS
76
- value. Do **not** include a unit in `$value` in this case.
77
-
78
- ```json
79
- "spacing-05": {
80
- "$type": "dimension",
81
- "$value": 2,
82
- "$description": "Spacing token — 16px.",
83
- "$extensions": {
84
- "carbon.layout": {
85
- "converter": "miniUnits"
86
- }
87
- }
88
- }
89
- ```
90
-
91
- ---
92
-
93
- ## Extensions — `carbon.layout`
94
-
95
- ### `converter`
96
-
97
- Declares how to convert the raw `$value` number to a CSS value.
98
-
99
- | `converter` | Input | Formula | Example |
100
- | ------------- | --------------- | ------------------------ | ----------------- |
101
- | `"miniUnits"` | Grid step count | `steps × 8px ÷ 16 = rem` | `2` → `"1rem"` |
102
- | `"rem"` | Pixel value | `px ÷ 16 = rem` | `4` → `"0.25rem"` |
103
-
104
- **`miniUnits`** — Carbon's 8px base grid. Pass the number of grid steps. Use
105
- this for spacing, container, and layout-scale tokens.
106
-
107
- ```json
108
- "spacing-07": {
109
- "$type": "dimension",
110
- "$value": 4,
111
- "$description": "Spacing token — 32px.",
112
- "$extensions": {
113
- "carbon.layout": {
114
- "converter": "miniUnits"
115
- }
116
- }
117
- }
118
- ```
119
-
120
- **`rem`** — Direct pixel-to-rem conversion. Pass the value in pixels. Use this
121
- for border-radius tokens and any token defined by an explicit px measurement
122
- rather than a grid step.
123
-
124
- ```json
125
- "border-radius-04": {
126
- "$type": "dimension",
127
- "$value": 4,
128
- "$description": "Border radius token — 4px.",
129
- "$extensions": {
130
- "carbon.layout": {
131
- "converter": "rem"
132
- }
133
- }
134
- }
135
- ```
136
-
137
- ### `deprecated`
138
-
139
- Marks a token as deprecated. Set to `true` alongside any other extension keys.
140
- Tools and codemods can read this flag to warn consumers.
141
-
142
- ```json
143
- "layout-01": {
144
- "$type": "dimension",
145
- "$value": 2,
146
- "$description": "Deprecated. Replaced by spacing scale. Do not use in new work.",
147
- "$extensions": {
148
- "carbon.layout": {
149
- "converter": "miniUnits",
150
- "deprecated": true
151
- }
152
- }
153
- }
154
- ```
155
-
156
- ---
157
-
158
- ## Token naming and generated file routing
159
-
160
- Token names in `layout.json` use **kebab-case**. Routing to a generated Sass
161
- file is determined by the **DTCG group** the token belongs to — `token.path[0]`
162
- in Style Dictionary terms. There is no name-prefix inference.
163
-
164
- | DTCG group key | Generated Sass file | Sass map variable |
165
- | --------------- | ------------------------------------ | --------------------------- |
166
- | `spacing` | `scss/generated/_spacing.scss` | `$spacing` |
167
- | `fluid-spacing` | `scss/generated/_fluid-spacing.scss` | `$fluid-spacing` |
168
- | `container` | `scss/generated/_container.scss` | `$container` |
169
- | `icon-size` | `scss/generated/_icon-size.scss` | `$icon-size` |
170
- | `border-radius` | `scss/generated/_border-radius.scss` | `$border-radius` |
171
- | `layout` | `scss/generated/_layout.scss` | `$layout` |
172
- | `size` | `scss/generated/_size.scss` | _(no map — bare variables)_ |
173
-
174
- The JS export name is the camelCase version of the token's own key: `spacing-05`
175
- → `spacing05`, `border-radius-04` → `borderRadius04`, `fluid-spacing-02` →
176
- `fluidSpacing02`.
177
-
178
- ### Adding a token to an existing category
179
-
180
- Place the token inside the correct group object — it will automatically be
181
- included in the right file on the next build. For example, to add a new spacing
182
- step:
183
-
184
- ```json
185
- "spacing": {
186
- "spacing-14": {
187
- "$type": "dimension",
188
- "$value": 24,
189
- "$description": "Spacing token — 192px.",
190
- "$extensions": {
191
- "carbon.layout": {
192
- "converter": "miniUnits"
193
- }
194
- }
195
- }
196
- }
197
- ```
198
-
199
- This will add `$spacing-14: 12rem !default;` to `_spacing.scss` and
200
- `export const spacing14 = '12rem';` to `layout-tokens.js`.
201
-
202
- ### Adding a token in a new category
203
-
204
- If your token does not match any existing prefix (e.g. `gap-*`), you need to
205
- also update the Style Dictionary pipeline:
206
-
207
- 1. Add your token to `layout.json` with the appropriate name prefix.
208
- 2. Add a new format function in
209
- [`style-dictionary/formats/scss-layout.js`](../style-dictionary/formats/scss-layout.js):
210
- ```js
211
- function formatGap({ dictionary }) {
212
- const tokens = tokensForGroup(dictionary, 'gap-');
213
- return buildStandardFile(tokens, 'gap', BANNER_2023);
214
- }
215
- ```
216
- 3. Export it from the `module.exports` array at the bottom of that file.
217
- 4. Register the new output file in
218
- [`style-dictionary/sd.config.js`](../style-dictionary/sd.config.js) under the
219
- `scss` platform's `files` array:
220
- ```js
221
- { destination: '_gap.scss', format: 'carbon/scss-gap' }
222
- ```
223
- 5. Forward the new file from the appropriate `scss/_*.scss` entry point (or
224
- create a new one and forward it from `index.scss`).
225
-
226
- ---
227
-
228
- ## Adding a new token
229
-
230
- 1. Add an entry to `layout.json` following the examples above.
231
- 2. Choose the right name prefix (see table above).
232
- 3. Choose the right `$value` and `converter`:
233
- - Grid-aligned value? Use `converter: "miniUnits"` and pass the step count.
234
- - Explicit pixel value? Use `converter: "rem"` and pass the px number.
235
- - Non-rem unit (e.g. `vw`, `px`)? Omit extensions and write the full CSS
236
- value directly in `$value`.
237
- 4. Run the build to regenerate SCSS and JS outputs:
238
- ```bash
239
- cd packages/layout
240
- yarn build:dtcg
241
- ```
242
- 5. Verify the resolved value in `js/generated/layout-tokens.js` and the correct
243
- `scss/generated/_*.scss` file.
244
-
245
- ---
246
-
247
- ## Build pipeline
248
-
249
- ```
250
- src/dtcg/layout.json ← you edit this
251
- │
252
- ▼ yarn build:dtcg
253
- │ (style-dictionary/sd.config.js)
254
- │
255
- ├── scss/generated/*.scss (Sass variables + maps, one file per token group)
256
- └── js/generated/layout-tokens.{js,d.ts} (ES module + types)
257
- │
258
- ▼
259
- src/index.ts re-exports all tokens
260
- ```
261
-
262
- The SD pipeline in
263
- [`style-dictionary/sd.config.js`](../style-dictionary/sd.config.js) reads the
264
- `carbon.layout.converter` extension and resolves `$value` before emitting. The
265
- generated files always contain **resolved CSS values** regardless of how the
266
- token was authored.