@workday/canvas-kit-docs 14.0.0-alpha.1149-next.0 → 14.0.0-alpha.1153-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
|
@@ -395717,7 +395717,9 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
395717
395717
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
395718
395718
|
}
|
|
395719
395719
|
],
|
|
395720
|
-
"tags": {
|
|
395720
|
+
"tags": {
|
|
395721
|
+
"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)."
|
|
395722
|
+
}
|
|
395721
395723
|
},
|
|
395722
395724
|
{
|
|
395723
395725
|
"kind": "property",
|
|
@@ -395802,7 +395804,9 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
395802
395804
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
395803
395805
|
}
|
|
395804
395806
|
],
|
|
395805
|
-
"tags": {
|
|
395807
|
+
"tags": {
|
|
395808
|
+
"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)."
|
|
395809
|
+
}
|
|
395806
395810
|
},
|
|
395807
395811
|
{
|
|
395808
395812
|
"kind": "property",
|
|
@@ -397281,7 +397285,9 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
397281
397285
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
397282
397286
|
}
|
|
397283
397287
|
],
|
|
397284
|
-
"tags": {
|
|
397288
|
+
"tags": {
|
|
397289
|
+
"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)."
|
|
397290
|
+
}
|
|
397285
397291
|
},
|
|
397286
397292
|
{
|
|
397287
397293
|
"kind": "property",
|
|
@@ -400052,7 +400058,9 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
400052
400058
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
400053
400059
|
}
|
|
400054
400060
|
],
|
|
400055
|
-
"tags": {
|
|
400061
|
+
"tags": {
|
|
400062
|
+
"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)."
|
|
400063
|
+
}
|
|
400056
400064
|
},
|
|
400057
400065
|
{
|
|
400058
400066
|
"kind": "property",
|
|
@@ -400171,7 +400179,10 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
400171
400179
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
400172
400180
|
}
|
|
400173
400181
|
],
|
|
400174
|
-
"tags": {
|
|
400182
|
+
"tags": {
|
|
400183
|
+
"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).",
|
|
400184
|
+
"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` |"
|
|
400185
|
+
}
|
|
400175
400186
|
},
|
|
400176
400187
|
{
|
|
400177
400188
|
"kind": "property",
|
|
@@ -400188,7 +400199,10 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
400188
400199
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
400189
400200
|
}
|
|
400190
400201
|
],
|
|
400191
|
-
"tags": {
|
|
400202
|
+
"tags": {
|
|
400203
|
+
"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).",
|
|
400204
|
+
"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]}` |"
|
|
400205
|
+
}
|
|
400192
400206
|
},
|
|
400193
400207
|
{
|
|
400194
400208
|
"kind": "property",
|
|
@@ -400204,7 +400218,9 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
400204
400218
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
400205
400219
|
}
|
|
400206
400220
|
],
|
|
400207
|
-
"tags": {
|
|
400221
|
+
"tags": {
|
|
400222
|
+
"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)."
|
|
400223
|
+
}
|
|
400208
400224
|
},
|
|
400209
400225
|
{
|
|
400210
400226
|
"kind": "property",
|
|
@@ -400629,7 +400645,9 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
400629
400645
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
400630
400646
|
}
|
|
400631
400647
|
],
|
|
400632
|
-
"tags": {
|
|
400648
|
+
"tags": {
|
|
400649
|
+
"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)."
|
|
400650
|
+
}
|
|
400633
400651
|
},
|
|
400634
400652
|
{
|
|
400635
400653
|
"kind": "property",
|
|
@@ -400731,7 +400749,10 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
400731
400749
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
400732
400750
|
}
|
|
400733
400751
|
],
|
|
400734
|
-
"tags": {
|
|
400752
|
+
"tags": {
|
|
400753
|
+
"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).",
|
|
400754
|
+
"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` |"
|
|
400755
|
+
}
|
|
400735
400756
|
},
|
|
400736
400757
|
{
|
|
400737
400758
|
"kind": "property",
|
|
@@ -401125,7 +401146,10 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
401125
401146
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
401126
401147
|
}
|
|
401127
401148
|
],
|
|
401128
|
-
"tags": {
|
|
401149
|
+
"tags": {
|
|
401150
|
+
"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).",
|
|
401151
|
+
"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` |"
|
|
401152
|
+
}
|
|
401129
401153
|
},
|
|
401130
401154
|
{
|
|
401131
401155
|
"kind": "property",
|
|
@@ -401141,7 +401165,9 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
401141
401165
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
401142
401166
|
}
|
|
401143
401167
|
],
|
|
401144
|
-
"tags": {
|
|
401168
|
+
"tags": {
|
|
401169
|
+
"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)."
|
|
401170
|
+
}
|
|
401145
401171
|
},
|
|
401146
401172
|
{
|
|
401147
401173
|
"kind": "property",
|
|
@@ -401158,7 +401184,10 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
401158
401184
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
401159
401185
|
}
|
|
401160
401186
|
],
|
|
401161
|
-
"tags": {
|
|
401187
|
+
"tags": {
|
|
401188
|
+
"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).",
|
|
401189
|
+
"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```"
|
|
401190
|
+
}
|
|
401162
401191
|
},
|
|
401163
401192
|
{
|
|
401164
401193
|
"kind": "property",
|
|
@@ -401243,7 +401272,10 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
401243
401272
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
401244
401273
|
}
|
|
401245
401274
|
],
|
|
401246
|
-
"tags": {
|
|
401275
|
+
"tags": {
|
|
401276
|
+
"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).",
|
|
401277
|
+
"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`|"
|
|
401278
|
+
}
|
|
401247
401279
|
},
|
|
401248
401280
|
{
|
|
401249
401281
|
"kind": "property",
|
|
@@ -401260,7 +401292,11 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
401260
401292
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
401261
401293
|
}
|
|
401262
401294
|
],
|
|
401263
|
-
"tags": {
|
|
401295
|
+
"tags": {
|
|
401296
|
+
"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).",
|
|
401297
|
+
"see": "{@link \n}\n for values mapping table",
|
|
401298
|
+
"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```"
|
|
401299
|
+
}
|
|
401264
401300
|
},
|
|
401265
401301
|
{
|
|
401266
401302
|
"kind": "property",
|
|
@@ -401413,7 +401449,10 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
401413
401449
|
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/index.ts"
|
|
401414
401450
|
}
|
|
401415
401451
|
],
|
|
401416
|
-
"tags": {
|
|
401452
|
+
"tags": {
|
|
401453
|
+
"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).",
|
|
401454
|
+
"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` |"
|
|
401455
|
+
}
|
|
401417
401456
|
}
|
|
401418
401457
|
]
|
|
401419
401458
|
}
|
|
@@ -403229,7 +403268,7 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
403229
403268
|
{
|
|
403230
403269
|
"name": "space",
|
|
403231
403270
|
"fileName": "/home/runner/work/canvas-kit/canvas-kit/modules/react/tokens/lib/space.ts",
|
|
403232
|
-
"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 |",
|
|
403271
|
+
"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` |",
|
|
403233
403272
|
"declarations": [
|
|
403234
403273
|
{
|
|
403235
403274
|
"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.
|