@workday/canvas-kit-docs 13.1.4 → 13.2.0-1152-next.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/dist/es6/lib/docs.js +55 -16
- package/dist/es6/lib/stackblitzFiles/packageJSONFile.js +5 -5
- package/dist/es6/lib/stackblitzFiles/packageJSONFile.ts +5 -5
- package/dist/mdx/styling/mdx/CreateStyles.mdx +111 -0
- package/dist/mdx/styling/mdx/CustomizingStyles.mdx +179 -0
- package/dist/mdx/styling/mdx/FromEmotion.mdx +178 -0
- package/dist/mdx/styling/mdx/MergingStyles.mdx +164 -0
- package/dist/mdx/styling/mdx/Overview.mdx +254 -0
- package/dist/mdx/styling/mdx/Stencils.mdx +459 -0
- package/dist/mdx/styling/mdx/Utilities.mdx +246 -0
- package/dist/mdx/styling/mdx/WhyCanvasStyling.mdx +136 -0
- package/dist/mdx/styling/mdx/examples/CSProp.tsx +36 -0
- package/dist/mdx/styling/mdx/examples/CreateModifiers.tsx +27 -0
- package/dist/mdx/styling/mdx/examples/CreateStencil.tsx +63 -0
- package/dist/mdx/styling/mdx/examples/CreateStyles.tsx +13 -0
- package/dist/mdx/styling/mdx/examples/CreateVars.tsx +20 -0
- package/dist/mdx/styling/mdx/examples/CustomButton.tsx +69 -0
- package/dist/mdx/styling/mdx/examples/CustomIcon.tsx +23 -0
- package/dist/mdx/styling/mdx/examples/EmotionButton.tsx +111 -0
- package/dist/mdx/styling/mdx/examples/ManualStylesButton.tsx +107 -0
- package/dist/mdx/styling/mdx/examples/StyledButton.tsx +31 -0
- package/dist/mdx/styling/mdx/examples/StylingButton.tsx +107 -0
- package/dist/mdx/styling/mdx/examples/StylingOverrides.tsx +158 -0
- package/package.json +6 -6
package/dist/es6/lib/docs.js
CHANGED
|
@@ -376878,7 +376878,9 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
376878
376878
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
376879
376879
|
}
|
|
376880
376880
|
],
|
|
376881
|
-
"tags": {
|
|
376881
|
+
"tags": {
|
|
376882
|
+
"deprecated": "Use brand or system color tokens from `@workday/canvas-tokens-web` instead. View Docs [here](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs)."
|
|
376883
|
+
}
|
|
376882
376884
|
},
|
|
376883
376885
|
{
|
|
376884
376886
|
"kind": "property",
|
|
@@ -376963,7 +376965,9 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
376963
376965
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
376964
376966
|
}
|
|
376965
376967
|
],
|
|
376966
|
-
"tags": {
|
|
376968
|
+
"tags": {
|
|
376969
|
+
"deprecated": "Use system color tokens from `@workday/canvas-tokens-web` instead. View Docs [here](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs)."
|
|
376970
|
+
}
|
|
376967
376971
|
},
|
|
376968
376972
|
{
|
|
376969
376973
|
"kind": "property",
|
|
@@ -378442,7 +378446,9 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
378442
378446
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
378443
378447
|
}
|
|
378444
378448
|
],
|
|
378445
|
-
"tags": {
|
|
378449
|
+
"tags": {
|
|
378450
|
+
"deprecated": "Use system color tokens from `@workday/canvas-tokens-web` instead. View Docs [here](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs)."
|
|
378451
|
+
}
|
|
378446
378452
|
},
|
|
378447
378453
|
{
|
|
378448
378454
|
"kind": "property",
|
|
@@ -381213,7 +381219,9 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
381213
381219
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
381214
381220
|
}
|
|
381215
381221
|
],
|
|
381216
|
-
"tags": {
|
|
381222
|
+
"tags": {
|
|
381223
|
+
"deprecated": "Use system color tokens from `@workday/canvas-tokens-web` instead. View Docs [here](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs)."
|
|
381224
|
+
}
|
|
381217
381225
|
},
|
|
381218
381226
|
{
|
|
381219
381227
|
"kind": "property",
|
|
@@ -381332,7 +381340,10 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
381332
381340
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
381333
381341
|
}
|
|
381334
381342
|
],
|
|
381335
|
-
"tags": {
|
|
381343
|
+
"tags": {
|
|
381344
|
+
"deprecated": "Use system color tokens from `@workday/canvas-tokens-web` instead. View Docs [here](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs).",
|
|
381345
|
+
"see": "| Old Token | New Token |\n|----------------|---------------------|\n| `commonColors.background` | `system.color.bg.default` |\n| `commonColors.backgroundAlt` | `system.color.bg.alt.default` |\n| `commonColors.focusOutline` | `system.color.border.primary.default` |\n| `commonColors.focusBackground` | `system.color.bg.primary.default` |\n| `commonColors.hoverBackground` | `system.color.bg.alt.strong` |\n| `commonColors.divider` | `system.color.border.divider` |"
|
|
381346
|
+
}
|
|
381336
381347
|
},
|
|
381337
381348
|
{
|
|
381338
381349
|
"kind": "property",
|
|
@@ -381349,7 +381360,10 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
381349
381360
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
381350
381361
|
}
|
|
381351
381362
|
],
|
|
381352
|
-
"tags": {
|
|
381363
|
+
"tags": {
|
|
381364
|
+
"deprecated": "Use system depth tokens from `@workday/canvas-tokens-web` instead. View Docs [here](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs).",
|
|
381365
|
+
"see": "| Old Token | New Token |\n|----------------|---------------------|\n| `depth[0]` | `{boxShadow: 'none'}` |\n| `depth[1]` | `{boxShadow: system.depth[1]}` |\n| `depth[2]` | `{boxShadow: system.depth[2]}` |\n| `depth[3]` | `{boxShadow: system.depth[3]}` |\n| `depth[4]` | `{boxShadow: system.depth[4]}` |\n| `depth[5]` | `{boxShadow: system.depth[5]}` |\n| `depth[6]` | `{boxShadow: system.depth[6]}` |"
|
|
381366
|
+
}
|
|
381353
381367
|
},
|
|
381354
381368
|
{
|
|
381355
381369
|
"kind": "property",
|
|
@@ -381365,7 +381379,9 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
381365
381379
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
381366
381380
|
}
|
|
381367
381381
|
],
|
|
381368
|
-
"tags": {
|
|
381382
|
+
"tags": {
|
|
381383
|
+
"deprecated": "Use system color tokens from `@workday/canvas-tokens-web` instead. View Docs [here](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs)."
|
|
381384
|
+
}
|
|
381369
381385
|
},
|
|
381370
381386
|
{
|
|
381371
381387
|
"kind": "property",
|
|
@@ -381790,7 +381806,9 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
381790
381806
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
381791
381807
|
}
|
|
381792
381808
|
],
|
|
381793
|
-
"tags": {
|
|
381809
|
+
"tags": {
|
|
381810
|
+
"deprecated": "Use system color tokens from `@workday/canvas-tokens-web` instead. View Docs [here](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs)."
|
|
381811
|
+
}
|
|
381794
381812
|
},
|
|
381795
381813
|
{
|
|
381796
381814
|
"kind": "property",
|
|
@@ -381892,7 +381910,10 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
381892
381910
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
381893
381911
|
}
|
|
381894
381912
|
],
|
|
381895
|
-
"tags": {
|
|
381913
|
+
"tags": {
|
|
381914
|
+
"deprecated": "Use system color tokens from `@workday/canvas-tokens-web` instead. View Docs [here](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs).",
|
|
381915
|
+
"see": "| Old Token | New Token |\n|----------------|---------------------|\n| `iconColors.active` | `system.color.fg.primary.default` |\n| `iconColors.disabled` | `system.color.fg.disabled.default` |\n| `iconColors.hover` | `system.color.fg.muted.stronger` |\n| `iconColors.inverse` | `system.color.fg.inverse` |\n| `iconColors.standard` | `system.color.fg.muted.soft` |"
|
|
381916
|
+
}
|
|
381896
381917
|
},
|
|
381897
381918
|
{
|
|
381898
381919
|
"kind": "property",
|
|
@@ -382286,7 +382307,10 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
382286
382307
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
382287
382308
|
}
|
|
382288
382309
|
],
|
|
382289
|
-
"tags": {
|
|
382310
|
+
"tags": {
|
|
382311
|
+
"deprecated": "Use system color tokens from `@workday/canvas-tokens-web` instead. View Docs [here](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs).",
|
|
382312
|
+
"see": "| Old Token | New Token |\n|----------------|---------------------|\n| `inputColors.background` | `system.color.bg.default` |\n| `inputColors.border` | `system.color.border.input.default` |\n| `inputColors.placeholder` | `system.color.fg.muted.default` |\n| `inputColors.text` | `system.color.fg.default` |\n| `inputColors.icon` | `system.color.fg.muted.soft` |\n| `inputColors.iconHover` | `system.color.fg.muted.stronger` |\n| `inputColors.selectionControlFill` | `system.color.bg.primary.default` |\n| `inputColors.hoverBorder` | `system.color.border.input.strong` |\n| `inputColors.focusBorder` | `system.color.border.primary.default` |\n| `inputColors.disabled.background` | `system.color.bg.alt.softer` |\n| `inputColors.disabled.border` | `system.color.border.input.disabled` |\n| `inputColors.disabled.text` | `system.color.fg.disabled` |\n| `inputColors.disabled.icon` | `system.color.fg.disabled` |\n| `inputColors.error.border` | `system.color.border.critical.default` |\n| `inputColors.error.message` | `base.blackPepper100` |\n| `inputColors.error.icon` | `system.color.fg.critical.default` |\n| `inputColors.alert.border` | `system.color.border.caution.default` |\n| `inputColors.alert.message` | `base.blackPepper100` |\n| `inputColors.alert.icon` | `base.cantaloupe500` |"
|
|
382313
|
+
}
|
|
382290
382314
|
},
|
|
382291
382315
|
{
|
|
382292
382316
|
"kind": "property",
|
|
@@ -382302,7 +382326,9 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
382302
382326
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
382303
382327
|
}
|
|
382304
382328
|
],
|
|
382305
|
-
"tags": {
|
|
382329
|
+
"tags": {
|
|
382330
|
+
"deprecated": "Use system color tokens from `@workday/canvas-tokens-web` instead. View Docs [here](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs)."
|
|
382331
|
+
}
|
|
382306
382332
|
},
|
|
382307
382333
|
{
|
|
382308
382334
|
"kind": "property",
|
|
@@ -382319,7 +382345,10 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
382319
382345
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
382320
382346
|
}
|
|
382321
382347
|
],
|
|
382322
|
-
"tags": {
|
|
382348
|
+
"tags": {
|
|
382349
|
+
"deprecated": "Use system space tokens from `@workday/canvas-tokens-web` instead. Check new values column for the new tokens. View Docs [here](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs).",
|
|
382350
|
+
"example": "```ts\n// before\nimport { space } from '@workday/canvas-kit-react/tokens';\nconst space = space.zero;\n\n// now\nimport { system } from '@workday/canvas-tokens-web';\nimport { cssVar } from '@workday/canvas-kit-styling';\nconst space = cssVar(system.space.zero);\n```"
|
|
382351
|
+
}
|
|
382323
382352
|
},
|
|
382324
382353
|
{
|
|
382325
382354
|
"kind": "property",
|
|
@@ -382404,7 +382433,10 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
382404
382433
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
382405
382434
|
}
|
|
382406
382435
|
],
|
|
382407
|
-
"tags": {
|
|
382436
|
+
"tags": {
|
|
382437
|
+
"deprecated": "Use system color tokens from `@workday/canvas-tokens-web` instead. View Docs [here](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs).",
|
|
382438
|
+
"see": "| Old Property | Tokens for foreground (text and icons) | Tokens for border |\n|-------------------------|-------------------------------------|---------------------------------------|\n| `statusColors.active` | `system.color.fg.primary.default` | `system.color.border.primary.default` |\n| `statusColors.success` | `system.color.fg.success.default` | none |\n| `statusColors.warning` | `system.color.fg.caution.default` | `system.color.border.caution.default` |\n| `statusColors.error` | `system.color.fg.critical.default` | `system.color.border.critical.default`|"
|
|
382439
|
+
}
|
|
382408
382440
|
},
|
|
382409
382441
|
{
|
|
382410
382442
|
"kind": "property",
|
|
@@ -382421,7 +382453,11 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
382421
382453
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
382422
382454
|
}
|
|
382423
382455
|
],
|
|
382424
|
-
"tags": {
|
|
382456
|
+
"tags": {
|
|
382457
|
+
"deprecated": "Use system type tokens from `@workday/canvas-tokens-web` instead. View Docs [here](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs).",
|
|
382458
|
+
"see": "{@link \n}\n for values mapping table",
|
|
382459
|
+
"example": "```ts\n// before\nimport { type } from '@workday/canvas-kit-react/tokens';\nconst styles = css({\n ...type.levels.body.large,\n fontWeight: type.properties.fontWeights.bold,\n color: type.variants.error,\n})\n\n// now\nimport { system } from '@workday/canvas-tokens-web';\nimport { createStyles } from '@workday/canvas-kit-styling';\nconst styles = createStyles({\n ...system.type.body.large,\n fontWeight: system.fontWeight.bold,\n color: system.color.fg.critical.default,\n})\n```"
|
|
382460
|
+
}
|
|
382425
382461
|
},
|
|
382426
382462
|
{
|
|
382427
382463
|
"kind": "property",
|
|
@@ -382574,7 +382610,10 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
382574
382610
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
382575
382611
|
}
|
|
382576
382612
|
],
|
|
382577
|
-
"tags": {
|
|
382613
|
+
"tags": {
|
|
382614
|
+
"deprecated": "Use system color tokens from `@workday/canvas-tokens-web` instead. View Docs [here](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs).",
|
|
382615
|
+
"see": "| Old Property | Tokens for text |\n|-------------------------------------|-----------------------------------|\n| `typeColors.body` | `system.color.fg.default` |\n| `typeColors.heading` | `system.color.fg.strong` |\n| `typeColors.hint` | `system.color.fg.muted.default` |\n| `typeColors.inverse` | `system.color.fg.inverse` |\n| `typeColors.label` | `system.color.fg.default` |\n| `typeColors.link` | `system.color.fg.primary.default` |\n| `typeColors.selectHighlight` | `system.color.fg.primary.default` |\n| `typeColors.selectHighlightInverse` | `system.color.fg.inverse` |"
|
|
382616
|
+
}
|
|
382578
382617
|
}
|
|
382579
382618
|
]
|
|
382580
382619
|
}
|
|
@@ -384390,7 +384429,7 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
384390
384429
|
{
|
|
384391
384430
|
"name": "space",
|
|
384392
384431
|
"fileName": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/lib/space.ts",
|
|
384393
|
-
"description": "An object of space keys and rem values (strings)\n\nBelow is a table to show the equivalent values from `px` to `rem`.\nThis is based on the default browser font size which is `16px`.\n\n| px Value | rem Value | space token |\n| --------- | --------- | ----------- |\n| 0 | 0 | zero |\n| 4px | 0.25rem | xxxs |\n| 8px | 0.5rem | xxs |\n| 12px | 0.75rem | xs |\n| 16px | 1rem | s |\n| 24px | 1.5rem | m |\n| 32px | 2rem | l |\n| 40px | 2.5rem | xl |\n| 64px | 4rem | xxl |\n| 80px | 5rem | xxxl |",
|
|
384432
|
+
"description": "An object of space keys and rem values (strings)\n\nBelow is a table to show the equivalent values from `px` to `rem`.\nThis is based on the default browser font size which is `16px`.\n\n| px Value | rem Value | space token | new token |\n| --------- | --------- | ----------- | --------- |\n| 0 | 0 | zero | `system.space.zero` |\n| 4px | 0.25rem | xxxs | `system.space.x1` |\n| 8px | 0.5rem | xxs | `system.space.x2` |\n| 12px | 0.75rem | xs | `system.space.x3` |\n| 16px | 1rem | s | `system.space.x4` |\n| 24px | 1.5rem | m | `system.space.x6` |\n| 32px | 2rem | l | `system.space.x8` |\n| 40px | 2.5rem | xl | `system.space.x10` |\n| 64px | 4rem | xxl | `system.space.x16` |\n| 80px | 5rem | xxxl | `system.space.x20` |",
|
|
384394
384433
|
"declarations": [
|
|
384395
384434
|
{
|
|
384396
384435
|
"name": "space",
|
|
@@ -18,11 +18,11 @@ export const packageJSONFile = `{
|
|
|
18
18
|
"@emotion/react": "11.11.4",
|
|
19
19
|
"@types/react": "18.2.60",
|
|
20
20
|
"@types/react-dom": "18.2.19",
|
|
21
|
-
"@workday/canvas-kit-labs-react": "13.1.
|
|
22
|
-
"@workday/canvas-kit-preview-react": "13.1.
|
|
23
|
-
"@workday/canvas-kit-react": "13.1.
|
|
24
|
-
"@workday/canvas-kit-react-fonts": "^13.1.
|
|
25
|
-
"@workday/canvas-kit-styling": "13.1.
|
|
21
|
+
"@workday/canvas-kit-labs-react": "13.1.5",
|
|
22
|
+
"@workday/canvas-kit-preview-react": "13.1.5",
|
|
23
|
+
"@workday/canvas-kit-react": "13.1.5",
|
|
24
|
+
"@workday/canvas-kit-react-fonts": "^13.1.5",
|
|
25
|
+
"@workday/canvas-kit-styling": "13.1.5",
|
|
26
26
|
"@workday/canvas-system-icons-web": "3.0.22",
|
|
27
27
|
"@workday/canvas-tokens-web": "2.0.0"
|
|
28
28
|
},
|
|
@@ -18,11 +18,11 @@ export const packageJSONFile = `{
|
|
|
18
18
|
"@emotion/react": "11.11.4",
|
|
19
19
|
"@types/react": "18.2.60",
|
|
20
20
|
"@types/react-dom": "18.2.19",
|
|
21
|
-
"@workday/canvas-kit-labs-react": "13.1.
|
|
22
|
-
"@workday/canvas-kit-preview-react": "13.1.
|
|
23
|
-
"@workday/canvas-kit-react": "13.1.
|
|
24
|
-
"@workday/canvas-kit-react-fonts": "^13.1.
|
|
25
|
-
"@workday/canvas-kit-styling": "13.1.
|
|
21
|
+
"@workday/canvas-kit-labs-react": "13.1.5",
|
|
22
|
+
"@workday/canvas-kit-preview-react": "13.1.5",
|
|
23
|
+
"@workday/canvas-kit-react": "13.1.5",
|
|
24
|
+
"@workday/canvas-kit-react-fonts": "^13.1.5",
|
|
25
|
+
"@workday/canvas-kit-styling": "13.1.5",
|
|
26
26
|
"@workday/canvas-system-icons-web": "3.0.22",
|
|
27
27
|
"@workday/canvas-tokens-web": "2.0.0"
|
|
28
28
|
},
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {ExampleCodeBlock} from '@workday/canvas-kit-docs';
|
|
2
|
+
import {InformationHighlight} from '@workday/canvas-kit-preview-react/information-highlight';
|
|
3
|
+
import {system} from '@workday/canvas-tokens-web'
|
|
4
|
+
|
|
5
|
+
import CreateStyles from './examples/CreateStyles';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# Create Styles
|
|
9
|
+
|
|
10
|
+
The primary utility function is the `createStyles` function. It makes a call to the `css` function
|
|
11
|
+
from `@emotion/css`. Emotion still does most of the heavy lifting by handling the serialization,
|
|
12
|
+
hashing, caching, and style injection.
|
|
13
|
+
|
|
14
|
+
## Basic Example
|
|
15
|
+
|
|
16
|
+
In this example, the HTML will look like:
|
|
17
|
+
|
|
18
|
+
```html
|
|
19
|
+
<div class="css-m39zwu"></div>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The CSS will look like this:
|
|
23
|
+
|
|
24
|
+
```css
|
|
25
|
+
.css-m39zwu {
|
|
26
|
+
background: var(--cnvs-sys-color-bg-primary-default);
|
|
27
|
+
color: var(--cnvs-sys-color-text-inverse);
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
<InformationHighlight className="sb-unstyled" cs={{marginBlock: system.space.x4,}}>
|
|
31
|
+
<InformationHighlight.Icon />
|
|
32
|
+
<InformationHighlight.Heading> Note</InformationHighlight.Heading>
|
|
33
|
+
<InformationHighlight.Body>
|
|
34
|
+
The `createStyles` function handles wrapping our Tokens in `var(--${token})`.
|
|
35
|
+
</InformationHighlight.Body>
|
|
36
|
+
</InformationHighlight>
|
|
37
|
+
|
|
38
|
+
We're using `className` for simplicity here.
|
|
39
|
+
|
|
40
|
+
<ExampleCodeBlock code={CreateStyles} />
|
|
41
|
+
|
|
42
|
+
<InformationHighlight className="sb-unstyled" variant="caution" cs={{marginBlock: system.space.x4,}}>
|
|
43
|
+
<InformationHighlight.Icon />
|
|
44
|
+
<InformationHighlight.Heading> Caution: Performance Hit</InformationHighlight.Heading>
|
|
45
|
+
<InformationHighlight.Body>
|
|
46
|
+
Do not inline the call to `createStyles` in the render function of a component. This will cause performance issues as a new style is inserted into the browser on every render.
|
|
47
|
+
</InformationHighlight.Body>
|
|
48
|
+
</InformationHighlight>
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
// Bad example (inside render function)
|
|
52
|
+
import {system} from '@workday/canvas-tokens-webs';
|
|
53
|
+
import {PrimaryButton} from '@workday/canvas-kit-react/button';
|
|
54
|
+
|
|
55
|
+
function MyComponent() {
|
|
56
|
+
const styles = createStyles({color: system.color.static.red.default}); // Don't do this
|
|
57
|
+
return <PrimaryButton className={createStyles({color: system.color.static.red.default})}>Text</PrimaryButton>;
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## When to Use `createStyles`
|
|
62
|
+
|
|
63
|
+
`createStyles` is a great way to generate static styles when styling our components that don't rely
|
|
64
|
+
on dynamic styles. Use `createStyles` if you want to create re useable styles or need to apply
|
|
65
|
+
simple style overrides to our components.
|
|
66
|
+
|
|
67
|
+
## When to Use Something Else
|
|
68
|
+
|
|
69
|
+
You should use [stencils](/docs/styling-getting-started-stencils--docs) when styling our components
|
|
70
|
+
that have complex styles and dynamic properties.
|
|
71
|
+
|
|
72
|
+
## Proper Usage
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
// Bad example (inside render function)
|
|
76
|
+
import {system} from '@workday/canvas-tokens-webs';
|
|
77
|
+
import {PrimaryButton} from '@workday/canvas-kit-react/button';
|
|
78
|
+
|
|
79
|
+
function MyComponent() {
|
|
80
|
+
const styles = createStyles({color: system.color.static.red.default}); // Don't do this
|
|
81
|
+
return <PrimaryButton cs={styles}>Text</PrimaryButton>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Good example (outside render function)
|
|
85
|
+
import {system} from '@workday/canvas-tokens-webs';
|
|
86
|
+
import {PrimaryButton} from '@workday/canvas-kit-react/button';
|
|
87
|
+
|
|
88
|
+
const styles = createStyles({color: system.color.static.red.default});
|
|
89
|
+
|
|
90
|
+
function MyComponent() {
|
|
91
|
+
return <PrimaryButton cs={styles}>Text</PrimaryButton>;
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
<InformationHighlight className="sb-unstyled" cs={{marginBlock: system.space.x4,}}>
|
|
96
|
+
<InformationHighlight.Icon />
|
|
97
|
+
<InformationHighlight.Heading>Note</InformationHighlight.Heading>
|
|
98
|
+
<InformationHighlight.Body>
|
|
99
|
+
Most of our components support using the `cs` prop to apply the static styles. It merges everything together and applies `className` and `style` attributes to a React element
|
|
100
|
+
</InformationHighlight.Body>
|
|
101
|
+
</InformationHighlight>
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
## Performance Benefits
|
|
106
|
+
|
|
107
|
+
`createStyles` is performant because:
|
|
108
|
+
|
|
109
|
+
- Styles are statically evaluated when styles are defined outside the render function
|
|
110
|
+
- No new StyleSheets are injected during render
|
|
111
|
+
- It works well with the browser's selector cache
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# How To Customize Styles
|
|
2
|
+
|
|
3
|
+
There are multiple ways to customize styles for components within Canvas Kit. The approach you
|
|
4
|
+
choose will depend on your use case. Ranging from some simple overrides to fully custom solutions,
|
|
5
|
+
here are the following options:
|
|
6
|
+
|
|
7
|
+
- [Create Styles](#createstyles)
|
|
8
|
+
- [Stencils](#stencils)
|
|
9
|
+
|
|
10
|
+
## Create Styles
|
|
11
|
+
|
|
12
|
+
### Using `createStyles` with `cs` prop
|
|
13
|
+
|
|
14
|
+
Use `createStyles` in tandem with `cs` prop when you're overriding static styles and making small modifications to an
|
|
15
|
+
existing Canvas Kit component like padding, color and flex properties. Take our `Text` component as
|
|
16
|
+
an example.
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import {createStyles} from '@Workday/canvas-kit-styling';
|
|
20
|
+
import {system} from '@Workday/canvas-tokens-web';
|
|
21
|
+
import {Text} from '@Workday/canvas-kit-react/text';
|
|
22
|
+
|
|
23
|
+
const uppercaseTextStyles = createStyles({
|
|
24
|
+
textTransform: 'uppercase',
|
|
25
|
+
margin: system.space.x4
|
|
26
|
+
})
|
|
27
|
+
//...
|
|
28
|
+
<Text cs={uppercaseTextStyles}>My uppercased text</Text>;
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
> **Note:** `createStyles` handles wrapping our token variables in `var(--${token})`
|
|
32
|
+
|
|
33
|
+
You can also apply styles created via `createStyles` via `className`.
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import {createStyles} from '@Workday/canvas-kit-styling';
|
|
37
|
+
import {system} from '@Workday/canvas-tokens-web';
|
|
38
|
+
import {Text} from '@Workday/canvas-kit-react/text';
|
|
39
|
+
|
|
40
|
+
const uppercaseTextStyles = createStyles({
|
|
41
|
+
textTransform: 'uppercase',
|
|
42
|
+
margin: system.space.x4
|
|
43
|
+
})
|
|
44
|
+
//...
|
|
45
|
+
<Text className={uppercaseTextStyles}>My uppercased text</Text>;
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
If you need to dynamically apply styles based on some state or prop, use [Stencils](#stencils) instead.
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
## Stencils
|
|
52
|
+
|
|
53
|
+
Stencils can be useful when applying dynamic styles or building your own reusable component.
|
|
54
|
+
|
|
55
|
+
### Extending Stencils
|
|
56
|
+
|
|
57
|
+
[Stencils](https://workday.github.io/canvas-kit/?path=/docs/styling-basics--create-stencil) help you
|
|
58
|
+
organize the styling of reusable components into base styles, modifiers, and variables. The
|
|
59
|
+
organization makes it more natural to produce static and clean CSS with optional extraction into CSS
|
|
60
|
+
files.
|
|
61
|
+
|
|
62
|
+
Stencils that define variables, modifiers and base styles can be extended to create your own
|
|
63
|
+
reusable component using Canvas Kit styles.
|
|
64
|
+
|
|
65
|
+
If we take `SystemIcon` component as an example, it defines `systemIconStencil` which defines styles
|
|
66
|
+
for an icon. This stencil can be extended to build a custom icon component for your use case.
|
|
67
|
+
|
|
68
|
+
**Before v11** you'd have to use `systemIconStyles` function to overwrite styles for an icon:
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
// Before v11
|
|
72
|
+
import {systemIconStyles} from '@workday/canvas-kit-react';
|
|
73
|
+
import {space} from '@workday/canvas-kit-react/tokens'; // old tokens
|
|
74
|
+
|
|
75
|
+
// old way of styling with Emotion styled
|
|
76
|
+
const StyledNavIcon = styled('span')(({size, iconStyles}){
|
|
77
|
+
display: 'inline-flex',
|
|
78
|
+
pointerEvents: 'unset',
|
|
79
|
+
margin: `${space.xxxs} ${space.xxxs} 0 0`,
|
|
80
|
+
padding: '0',
|
|
81
|
+
'svg': {
|
|
82
|
+
...iconStyles,
|
|
83
|
+
width: size,
|
|
84
|
+
height: size,
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const NavIcon = ({iconColor, iconHover, iconBackground, iconBackgroundHover, icon, size}) => {
|
|
89
|
+
// old way of styling with systemIconStyles function
|
|
90
|
+
// systemIconStyles is deprecated in v11
|
|
91
|
+
const iconStyles = systemIconStyles({
|
|
92
|
+
fill: iconColor,
|
|
93
|
+
fillHover: iconHover,
|
|
94
|
+
background: iconBackground,
|
|
95
|
+
backgroundHover: iconBackgroundHover,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// insert icon function used by platform or any other functionality here
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<StyledNavIcon
|
|
102
|
+
icon={icon}
|
|
103
|
+
size={size}
|
|
104
|
+
iconStyles={iconStyles}
|
|
105
|
+
/>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**In v11** you'd extend `systemIconStencil` to reuse its styles:
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
// v11
|
|
114
|
+
import {createStencil} from '@workday/canvas-kit-styling';
|
|
115
|
+
import {system} from '@workday/canvas-tokens-web';
|
|
116
|
+
import {systemIconStencil} from '@workday/canvas-kit-react/icon';
|
|
117
|
+
|
|
118
|
+
const navIconStencil = createStencil({
|
|
119
|
+
// We extend `systemIconStencil` to inherit it's base styles, modifiers and variables so that we can customize it
|
|
120
|
+
extends: systemIconStencil,
|
|
121
|
+
vars: {
|
|
122
|
+
// These variables support our styling iconHover and iconBackgroundHover
|
|
123
|
+
// they can be removed later and overwritten by `cs`.
|
|
124
|
+
// Also note the variables have no value. This allows for cascading styles.
|
|
125
|
+
fillHover: '',
|
|
126
|
+
backgroundHover: '',
|
|
127
|
+
},
|
|
128
|
+
base: ({fillHover, backgroundHover}) => ({
|
|
129
|
+
display: 'inline-flex',
|
|
130
|
+
pointerEvents: 'unset',
|
|
131
|
+
// instead of using our old tokens it's better to use our new system tokens
|
|
132
|
+
margin: `${system.space.x1} ${system.space.x1} 0 0`,
|
|
133
|
+
padding: '0',
|
|
134
|
+
'&:hover, &.hover': {
|
|
135
|
+
// systemIconStencil doesn't have hover specific variables
|
|
136
|
+
// so we reassigned color and backgroundColor variables using pseudo-selector
|
|
137
|
+
[systemIconStencil.vars.color]: fillHover,
|
|
138
|
+
[systemIconStencil.vars.backgroundColor]: backgroundHover,
|
|
139
|
+
},
|
|
140
|
+
}),
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Your reusable NavIcon component using Stencils
|
|
144
|
+
const NavIcon = ({
|
|
145
|
+
iconColor,
|
|
146
|
+
iconHover,
|
|
147
|
+
iconBackground,
|
|
148
|
+
iconBackgroundHover,
|
|
149
|
+
icon,
|
|
150
|
+
size,
|
|
151
|
+
...elemProps
|
|
152
|
+
}) => {
|
|
153
|
+
// insert icon function used by platform or any other functionality here
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<span
|
|
157
|
+
icon={icon}
|
|
158
|
+
{...handleCsProp(
|
|
159
|
+
elemProps,
|
|
160
|
+
navIconStencil({
|
|
161
|
+
// Because we're extending systemIconStencil, it already has a size prop and applies size to the svg's width and height
|
|
162
|
+
// so we don't need to set these variables in our navIconStencil
|
|
163
|
+
size,
|
|
164
|
+
// systemIconStencil already has color (for icon fill) and backgroundColor variables
|
|
165
|
+
// so we assigned them to our prop values
|
|
166
|
+
color: iconColor,
|
|
167
|
+
backgroundColor: iconBackground,
|
|
168
|
+
fillHover: iconHover,
|
|
169
|
+
backgroundHover: iconBackgroundHover,
|
|
170
|
+
})
|
|
171
|
+
)}
|
|
172
|
+
/>
|
|
173
|
+
);
|
|
174
|
+
};
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Another example of Stencil extension and customization is our
|
|
178
|
+
[CustomButton](https://workday.github.io/canvas-kit/?path=/story/components-buttons--custom-styles)
|
|
179
|
+
example. This example highlights the power of inheritance that you get from extending stencils.
|