@workday/canvas-kit-react 10.0.4 → 10.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/button/lib/BaseButton.tsx +11 -15
- package/button/lib/DeleteButton.tsx +3 -2
- package/button/lib/PrimaryButton.tsx +3 -10
- package/button/lib/SecondaryButton.tsx +3 -9
- package/button/lib/TertiaryButton.tsx +3 -5
- package/common/lib/CanvasProvider.tsx +14 -10
- package/dist/commonjs/button/lib/BaseButton.d.ts.map +1 -1
- package/dist/commonjs/button/lib/BaseButton.js +31 -34
- package/dist/commonjs/button/lib/DeleteButton.d.ts.map +1 -1
- package/dist/commonjs/button/lib/DeleteButton.js +4 -3
- package/dist/commonjs/button/lib/PrimaryButton.d.ts.map +1 -1
- package/dist/commonjs/button/lib/PrimaryButton.js +5 -4
- package/dist/commonjs/button/lib/SecondaryButton.d.ts.map +1 -1
- package/dist/commonjs/button/lib/SecondaryButton.js +5 -4
- package/dist/commonjs/button/lib/TertiaryButton.d.ts +1 -1
- package/dist/commonjs/button/lib/TertiaryButton.d.ts.map +1 -1
- package/dist/commonjs/button/lib/TertiaryButton.js +25 -25
- package/dist/commonjs/common/lib/CanvasProvider.d.ts.map +1 -1
- package/dist/commonjs/common/lib/CanvasProvider.js +6 -3
- package/dist/commonjs/layout/index.d.ts +2 -1
- package/dist/commonjs/layout/index.d.ts.map +1 -1
- package/dist/commonjs/layout/index.js +4 -1
- package/dist/commonjs/layout/lib/utils/mergeStyles.d.ts +61 -0
- package/dist/commonjs/layout/lib/utils/mergeStyles.d.ts.map +1 -0
- package/dist/commonjs/layout/lib/utils/mergeStyles.js +160 -0
- package/dist/es6/button/lib/BaseButton.d.ts.map +1 -1
- package/dist/es6/button/lib/BaseButton.js +31 -34
- package/dist/es6/button/lib/DeleteButton.d.ts.map +1 -1
- package/dist/es6/button/lib/DeleteButton.js +4 -3
- package/dist/es6/button/lib/PrimaryButton.d.ts.map +1 -1
- package/dist/es6/button/lib/PrimaryButton.js +5 -4
- package/dist/es6/button/lib/SecondaryButton.d.ts.map +1 -1
- package/dist/es6/button/lib/SecondaryButton.js +5 -4
- package/dist/es6/button/lib/TertiaryButton.d.ts +1 -1
- package/dist/es6/button/lib/TertiaryButton.d.ts.map +1 -1
- package/dist/es6/button/lib/TertiaryButton.js +25 -25
- package/dist/es6/common/lib/CanvasProvider.d.ts.map +1 -1
- package/dist/es6/common/lib/CanvasProvider.js +7 -4
- package/dist/es6/layout/index.d.ts +2 -1
- package/dist/es6/layout/index.d.ts.map +1 -1
- package/dist/es6/layout/index.js +2 -0
- package/dist/es6/layout/lib/utils/mergeStyles.d.ts +61 -0
- package/dist/es6/layout/lib/utils/mergeStyles.d.ts.map +1 -0
- package/dist/es6/layout/lib/utils/mergeStyles.js +156 -0
- package/dist/es6/menu/lib/MenuItem.d.ts +1 -1
- package/dist/es6/tabs/lib/TabsItem.d.ts +1 -1
- package/layout/index.ts +4 -3
- package/layout/lib/utils/mergeStyles.ts +178 -0
- package/package.json +6 -4
|
@@ -2,35 +2,36 @@ import * as React from 'react';
|
|
|
2
2
|
import { buttonVars, getIconPosition } from './BaseButton';
|
|
3
3
|
import { createComponent, focusRing } from '@workday/canvas-kit-react/common';
|
|
4
4
|
import { createStyles, cssVar, createModifiers } from '@workday/canvas-kit-styling';
|
|
5
|
+
import { mergeStyles } from '@workday/canvas-kit-react/layout';
|
|
5
6
|
import { system, brand, base } from '@workday/canvas-tokens-web';
|
|
6
7
|
import { borderRadius, space } from '@workday/canvas-kit-react/tokens';
|
|
7
8
|
import { Button } from './Button';
|
|
8
|
-
const tertiaryStyles = createStyles({ name: "
|
|
9
|
+
const tertiaryStyles = createStyles({ name: "q08lh", styles: "padding-inline:var(--cnvs-sys-space-x2, 0.5rem);min-width:auto;text-decoration:underline;border:0px;--css-button-vars-default-background:transparent;--css-button-vars-default-border:transparent;--css-button-vars-default-borderRadius:var(--cnvs-sys-shape-x1, 0.25rem);--css-button-vars-default-label:var(--cnvs-brand-primary-base, rgba(8,117,226,1));--css-button-vars-default-icon:var(--cnvs-base-palette-black-pepper-400, rgba(51, 51, 51, 1));--css-button-vars-hover-background:var(--cnvs-base-palette-soap-200, rgba(241, 242, 243, 1));--css-button-vars-hover-border:transparent;--css-button-vars-hover-label:var(--cnvs-brand-primary-dark, rgba(0,92,184,1));--css-button-vars-hover-icon:var(--cnvs-base-palette-black-pepper-500, rgba(31,31,31,1));--css-button-vars-focus-background:transparent;--css-button-vars-focus-border:transparent;--css-button-vars-focus-label:var(--cnvs-brand-primary-base, rgba(8,117,226,1));--css-button-vars-focus-icon:var(--cnvs-base-palette-black-pepper-500, rgba(31,31,31,1));--css-button-vars-focus-boxShadowInner:var(--cnvs-brand-common-focus-outline, rgba(8,117,226,1));--css-button-vars-focus-boxShadowOuter:var(--cnvs-brand-common-focus-outline, rgba(8,117,226,1));--css-button-vars-active-background:var(--cnvs-base-palette-soap-300, rgba(232,235,237,1));--css-button-vars-active-border:transparent;--css-button-vars-active-label:var(--cnvs-brand-primary-dark, rgba(0,92,184,1));--css-button-vars-active-icon:var(--cnvs-base-palette-black-pepper-500, rgba(31,31,31,1));--css-button-vars-disabled-background:transparent;--css-button-vars-disabled-border:var(--cnvs-base-palette-french-vanilla-100, #fff);--css-button-vars-disabled-label:var(--cnvs-brand-primary-base, rgba(8,117,226,1));--css-button-vars-disabled-icon:var(--cnvs-base-palette-black-pepper-400, rgba(51, 51, 51, 1));--css-button-vars-disabled-opacity:0.4;&:focus-visible, &.focus{box-shadow:0 0 0 0px var(--cnvs-base-palette-french-vanilla-100, var(--css-button-vars-focus-boxShadowInner)), 0 0 0 calc(2px + 0px) var(--cnvs-brand-common-focus-outline, var(--css-button-vars-focus-boxShadowOuter));}" });
|
|
9
10
|
export const tertiaryButtonModifiers = createModifiers({
|
|
10
11
|
isThemeable: {
|
|
11
|
-
true: createStyles({ name: "
|
|
12
|
+
true: createStyles({ name: "q08li", styles: "--css-button-vars-default-icon:var(--cnvs-brand-primary-base, rgba(8,117,226,1));--css-button-vars-hover-icon:var(--cnvs-brand-primary-dark, rgba(0,92,184,1));--css-button-vars-focus-icon:var(--cnvs-brand-primary-base, rgba(8,117,226,1));--css-button-vars-active-icon:var(--cnvs-brand-primary-dark, rgba(0,92,184,1));--css-button-vars-disabled-icon:var(--cnvs-brand-primary-base, rgba(8,117,226,1));" }),
|
|
12
13
|
},
|
|
13
14
|
variant: {
|
|
14
|
-
inverse: createStyles({ name: "
|
|
15
|
+
inverse: createStyles({ name: "q08lj", styles: "--css-button-vars-default-background:transparent;--css-button-vars-default-border:transparent;--css-button-vars-default-label:var(--cnvs-base-palette-french-vanilla-100, #fff);--css-button-vars-default-icon:var(--cnvs-base-palette-french-vanilla-100, #fff);--css-button-vars-hover-background:var(--cnvs-base-palette-french-vanilla-100, #fff);--css-button-vars-hover-border:transparent;--css-button-vars-hover-label:var(--cnvs-base-palette-black-pepper-400, rgba(51, 51, 51, 1));--css-button-vars-hover-icon:var(--cnvs-base-palette-black-pepper-400, rgba(51, 51, 51, 1));--css-button-vars-focus-background:var(--cnvs-base-palette-french-vanilla-100, #fff);--css-button-vars-focus-border:transparent;--css-button-vars-focus-label:var(--cnvs-base-palette-black-pepper-400, rgba(51, 51, 51, 1));--css-button-vars-focus-icon:var(--cnvs-base-palette-black-pepper-400, rgba(51, 51, 51, 1));--css-button-vars-active-background:var(--cnvs-base-palette-soap-200, rgba(241, 242, 243, 1));--css-button-vars-active-border:transparent;--css-button-vars-active-label:var(--cnvs-base-palette-black-pepper-400, rgba(51, 51, 51, 1));--css-button-vars-active-icon:var(--cnvs-base-palette-black-pepper-400, rgba(51, 51, 51, 1));--css-button-vars-disabled-background:transparent;--css-button-vars-disabled-border:var(--cnvs-base-palette-french-vanilla-100, #fff);--css-button-vars-disabled-label:var(--cnvs-base-palette-french-vanilla-100, #fff);--css-button-vars-disabled-icon:var(--cnvs-base-palette-french-vanilla-100, #fff);&:focus-visible, &.focus{box-shadow:inset 0 0 0 2px var(--cnvs-base-palette-black-pepper-400, var(--css-button-vars-focus-boxShadowInner)), 0 0 0 2px var(--cnvs-base-palette-french-vanilla-100, var(--css-button-vars-focus-boxShadowOuter));}" }),
|
|
15
16
|
},
|
|
16
17
|
iconPosition: {
|
|
17
|
-
largeOnly: createStyles({ name: "
|
|
18
|
-
largeStart: createStyles({ name: "
|
|
19
|
-
largeEnd: createStyles({ name: "
|
|
20
|
-
mediumOnly: createStyles({ name: "
|
|
21
|
-
mediumStart: createStyles({ name: "
|
|
22
|
-
mediumEnd: createStyles({ name: "
|
|
23
|
-
smallOnly: createStyles({ name: "
|
|
24
|
-
smallStart: createStyles({ name: "
|
|
25
|
-
smallEnd: createStyles({ name: "
|
|
26
|
-
extraSmallOnly: createStyles({ name: "
|
|
27
|
-
extraSmallStart: createStyles({ name: "
|
|
28
|
-
extraSmallEnd: createStyles({ name: "
|
|
18
|
+
largeOnly: createStyles({ name: "q08lk", styles: "border-radius:999px;padding:0;min-width:calc(var(--cnvs-sys-space-x4, 1rem) * 3);" }),
|
|
19
|
+
largeStart: createStyles({ name: "q08ll", styles: "padding-inline-start:0.5rem;padding-inline-end:0.75rem;" }),
|
|
20
|
+
largeEnd: createStyles({ name: "q08lm", styles: "padding-inline-start:0.75rem;padding-inline-end:0.5rem;" }),
|
|
21
|
+
mediumOnly: createStyles({ name: "q08ln", styles: "padding:0;min-width:2.5rem;border-radius:999px;" }),
|
|
22
|
+
mediumStart: createStyles({ name: "q08lo", styles: "padding-inline-start:0.5rem;padding-inline-end:0.75rem;" }),
|
|
23
|
+
mediumEnd: createStyles({ name: "q08lp", styles: "padding-inline-start:0.75rem;padding-inline-end:0.5rem;" }),
|
|
24
|
+
smallOnly: createStyles({ name: "q08lq", styles: "padding:0;min-width:2rem;border-radius:999px;" }),
|
|
25
|
+
smallStart: createStyles({ name: "q08lr", styles: "padding-inline-start:0.5rem;padding-inline-end:0.75rem;" }),
|
|
26
|
+
smallEnd: createStyles({ name: "q08ls", styles: "padding-inline-start:0.75rem;padding-inline-end:0.5rem;" }),
|
|
27
|
+
extraSmallOnly: createStyles({ name: "q08lt", styles: "padding:0;min-width:1.5rem;border-radius:999px;" }),
|
|
28
|
+
extraSmallStart: createStyles({ name: "q08lu", styles: "padding-inline-start:0.25rem;padding-inline-end:0.5rem;" }),
|
|
29
|
+
extraSmallEnd: createStyles({ name: "q08lv", styles: "padding-inline-start:0.5rem;padding-inline-end:0.25rem;" }),
|
|
29
30
|
},
|
|
30
31
|
});
|
|
31
32
|
export const TertiaryButton = createComponent('button')({
|
|
32
33
|
displayName: 'TertiaryButton',
|
|
33
|
-
Component: ({ children, icon, colors, size = 'medium', isThemeable, variant, iconPosition,
|
|
34
|
+
Component: ({ children, icon, colors, size = 'medium', isThemeable, variant, iconPosition, ...elemProps }, ref, Element) => {
|
|
34
35
|
const baseIconPosition = iconPosition
|
|
35
36
|
? iconPosition
|
|
36
37
|
: icon
|
|
@@ -38,14 +39,13 @@ export const TertiaryButton = createComponent('button')({
|
|
|
38
39
|
? 'start'
|
|
39
40
|
: 'only'
|
|
40
41
|
: undefined;
|
|
41
|
-
return (React.createElement(Button, Object.assign({ as: Element, ref: ref, icon: icon, iconPosition: iconPosition, size: size,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
] }, elemProps), children));
|
|
42
|
+
return (React.createElement(Button, Object.assign({ as: Element, ref: ref, icon: icon, iconPosition: iconPosition, size: size }, mergeStyles(elemProps, [
|
|
43
|
+
tertiaryStyles,
|
|
44
|
+
tertiaryButtonModifiers({
|
|
45
|
+
isThemeable: (isThemeable || baseIconPosition !== 'only'),
|
|
46
|
+
variant: variant,
|
|
47
|
+
iconPosition: getIconPosition(size, baseIconPosition),
|
|
48
|
+
}),
|
|
49
|
+
])), children));
|
|
50
50
|
},
|
|
51
51
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CanvasProvider.d.ts","sourceRoot":"","sources":["../../../../common/lib/CanvasProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAqB,yBAAyB,EAAW,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"CanvasProvider.d.ts","sourceRoot":"","sources":["../../../../common/lib/CanvasProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAqB,yBAAyB,EAAW,MAAM,WAAW,CAAC;AAKlF,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,yBAAyB,CAAC;CACnC;AAkCD,eAAO,MAAM,cAAc,kCAIxB,mBAAmB,GAAG,MAAM,cAAc,CAAC,WAAW,CAAC,gBAezD,CAAC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { ThemeProvider } from '@emotion/react';
|
|
2
|
+
import { ThemeProvider, CacheProvider } from '@emotion/react';
|
|
3
3
|
import { InputProvider } from './InputProvider';
|
|
4
4
|
import { defaultCanvasTheme, useTheme } from './theming';
|
|
5
5
|
import { brand } from '@workday/canvas-tokens-web';
|
|
6
|
+
// eslint-disable-next-line @emotion/no-vanilla
|
|
7
|
+
import { cache } from '@emotion/css';
|
|
6
8
|
const mappedKeys = {
|
|
7
9
|
lightest: 'lightest',
|
|
8
10
|
light: 'light',
|
|
@@ -30,7 +32,8 @@ const useCanvasThemeToCssVars = (theme, elemProps) => {
|
|
|
30
32
|
export const CanvasProvider = ({ children, theme = { canvas: defaultCanvasTheme }, ...props }) => {
|
|
31
33
|
var _a;
|
|
32
34
|
const elemProps = useCanvasThemeToCssVars(theme, props);
|
|
33
|
-
return (React.createElement(
|
|
34
|
-
React.createElement(
|
|
35
|
-
|
|
35
|
+
return (React.createElement(CacheProvider, { value: cache },
|
|
36
|
+
React.createElement(ThemeProvider, { theme: theme },
|
|
37
|
+
React.createElement(InputProvider, null),
|
|
38
|
+
React.createElement("div", Object.assign({ dir: ((_a = theme === null || theme === void 0 ? void 0 : theme.canvas) === null || _a === void 0 ? void 0 : _a.direction) || defaultCanvasTheme.direction }, elemProps), children))));
|
|
36
39
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './lib/Box';
|
|
2
|
+
export * from './lib/utils/mergeStyles';
|
|
2
3
|
export * from './lib/utils/background';
|
|
3
4
|
export * from './lib/utils/border';
|
|
4
5
|
export * from './lib/utils/color';
|
|
@@ -18,6 +19,6 @@ export * from './lib/Flex';
|
|
|
18
19
|
export * from './lib/Grid';
|
|
19
20
|
export type { FlexStyleProps } from './lib/utils/flex';
|
|
20
21
|
export type { GridStyleProps } from './lib/utils/grid';
|
|
21
|
-
export
|
|
22
|
+
export { GridItemStyleProps, gridItemStyleFnConfigs } from './lib/utils/gridItem';
|
|
22
23
|
export * from './lib/utils/systemProps';
|
|
23
24
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../layout/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAC,eAAe,EAAE,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AACvE,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAC,eAAe,EAAE,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,wBAAwB,CAAC;AACvE,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../layout/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAC,eAAe,EAAE,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AACvE,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAC,eAAe,EAAE,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,wBAAwB,CAAC;AACvE,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,YAAY,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AACrD,YAAY,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAC,kBAAkB,EAAE,sBAAsB,EAAC,MAAM,sBAAsB,CAAC;AAChF,cAAc,yBAAyB,CAAC"}
|
package/dist/es6/layout/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './lib/Box';
|
|
2
|
+
export * from './lib/utils/mergeStyles';
|
|
2
3
|
export * from './lib/utils/background';
|
|
3
4
|
export * from './lib/utils/border';
|
|
4
5
|
export * from './lib/utils/color';
|
|
@@ -15,4 +16,5 @@ export { spaceStyleFnConfigs } from './lib/utils/space';
|
|
|
15
16
|
export * from './lib/utils/text';
|
|
16
17
|
export * from './lib/Flex';
|
|
17
18
|
export * from './lib/Grid';
|
|
19
|
+
export { gridItemStyleFnConfigs } from './lib/utils/gridItem';
|
|
18
20
|
export * from './lib/utils/systemProps';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CSToPropsInput } from '@workday/canvas-kit-styling';
|
|
2
|
+
import { CommonStyleProps } from './styleProps';
|
|
3
|
+
/**
|
|
4
|
+
* This is an opinionated function that will force style merging with Emotion's runtime APIs,
|
|
5
|
+
* including [styled components](https://emotion.sh/docs/styled) and the [css
|
|
6
|
+
* prop](https://emotion.sh/docs/css-prop). It will also handle style props for as long as those are
|
|
7
|
+
* supported. `mergeStyles` is exported from the layout package since it supports style props
|
|
8
|
+
* defined in the layout packages.
|
|
9
|
+
*
|
|
10
|
+
* It works by detecting styles added via Emotion's runtime APIs and forcing styling merging if use
|
|
11
|
+
* of runtime APIs have been detected. If only `createStyles` were used to style a component, the
|
|
12
|
+
* faster non-runtime styling will be used.
|
|
13
|
+
*
|
|
14
|
+
* You can use `mergeStyles` if you wish to use {@link createStyles} on your own components and want
|
|
15
|
+
* your components to be compatible with Emotion's runtime styling APIs.
|
|
16
|
+
*
|
|
17
|
+
* ```tsx
|
|
18
|
+
* import {createStyles, CSProps} from '@workday/canvas-kit-styling';
|
|
19
|
+
* import {mergeStyles} from '@workday/canvas-kit-react/layout';
|
|
20
|
+
*
|
|
21
|
+
* interface MyComponentProps extends CSProps {
|
|
22
|
+
* // other props
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* const myStyles = createStyles({
|
|
26
|
+
* background: 'green',
|
|
27
|
+
* height: 40,
|
|
28
|
+
* width: 40
|
|
29
|
+
* })
|
|
30
|
+
*
|
|
31
|
+
* const MyComponent = ({children, ...elemProps}: MyComponentProps) => {
|
|
32
|
+
* return (
|
|
33
|
+
* <div
|
|
34
|
+
* {...mergeStyles(elemProps, [myStyles])}
|
|
35
|
+
* >
|
|
36
|
+
* {children}
|
|
37
|
+
* </div>
|
|
38
|
+
* )
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* const StyledMyComponent(MyComponent)({
|
|
42
|
+
* background: 'red'
|
|
43
|
+
* })
|
|
44
|
+
*
|
|
45
|
+
* const myOverridingStyles = createStyles({
|
|
46
|
+
* background: 'blue'
|
|
47
|
+
* })
|
|
48
|
+
*
|
|
49
|
+
* // now everything works. Without `mergeStyles`, the last component would be a red box
|
|
50
|
+
* export default () => (
|
|
51
|
+
* <>
|
|
52
|
+
* <MyComponent>Green box</MyComponent>
|
|
53
|
+
* <StyledMyComponent>Red box</StyledMyComponent>
|
|
54
|
+
* <StyledMyComponent cs={myOverridingStyles}>Blue box</StyledMyComponent>
|
|
55
|
+
* </>
|
|
56
|
+
* )
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
*/
|
|
60
|
+
export declare function mergeStyles<T extends {}>(allProps: T, cs: CSToPropsInput): Omit<T, 'cs' | keyof CommonStyleProps>;
|
|
61
|
+
//# sourceMappingURL=mergeStyles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mergeStyles.d.ts","sourceRoot":"","sources":["../../../../../layout/lib/utils/mergeStyles.ts"],"names":[],"mappings":"AAGA,OAAO,EAAY,cAAc,EAAoB,MAAM,6BAA6B,CAAC;AAYzF,OAAO,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AA0B9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,EAAE,EACtC,QAAQ,EAAE,CAAC,EACX,EAAE,EAAE,cAAc,GACjB,IAAI,CAAC,CAAC,EAAE,IAAI,GAAG,MAAM,gBAAgB,CAAC,CA4ExC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { getRegisteredStyles } from '@emotion/utils';
|
|
2
|
+
// eslint-disable-next-line @emotion/no-vanilla
|
|
3
|
+
import { cache, css } from '@emotion/css';
|
|
4
|
+
import { csToProps, createStylesCache } from '@workday/canvas-kit-styling';
|
|
5
|
+
import { boxStyleFn } from '../Box';
|
|
6
|
+
import { backgroundStyleFnConfigs } from './background';
|
|
7
|
+
import { borderStyleFnConfigs } from './border';
|
|
8
|
+
import { colorStyleFnConfigs } from './color';
|
|
9
|
+
import { depthStyleFnConfigs } from './depth';
|
|
10
|
+
import { flexItemStyleFnConfigs } from './flexItem';
|
|
11
|
+
import { gridItemStyleFnConfigs } from './gridItem';
|
|
12
|
+
import { layoutStyleFnConfigs } from './layout';
|
|
13
|
+
import { otherStyleFnConfigs } from './other';
|
|
14
|
+
import { positionStyleFnConfigs } from './position';
|
|
15
|
+
import { spaceStyleFnConfigs } from './space';
|
|
16
|
+
import { textStyleFnConfigs } from './text';
|
|
17
|
+
// get a hash of all the style props for a faster lookup
|
|
18
|
+
const stylePropHash = [
|
|
19
|
+
...backgroundStyleFnConfigs,
|
|
20
|
+
...borderStyleFnConfigs,
|
|
21
|
+
...colorStyleFnConfigs,
|
|
22
|
+
...depthStyleFnConfigs,
|
|
23
|
+
...flexItemStyleFnConfigs,
|
|
24
|
+
...gridItemStyleFnConfigs,
|
|
25
|
+
...layoutStyleFnConfigs,
|
|
26
|
+
...otherStyleFnConfigs,
|
|
27
|
+
...positionStyleFnConfigs,
|
|
28
|
+
...spaceStyleFnConfigs,
|
|
29
|
+
...textStyleFnConfigs,
|
|
30
|
+
].reduce((result, prop) => {
|
|
31
|
+
//@ts-ignore
|
|
32
|
+
result[prop.name] = true;
|
|
33
|
+
return result;
|
|
34
|
+
}, {});
|
|
35
|
+
function isStyleProps(prop) {
|
|
36
|
+
return stylePropHash[prop] || false;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* This is an opinionated function that will force style merging with Emotion's runtime APIs,
|
|
40
|
+
* including [styled components](https://emotion.sh/docs/styled) and the [css
|
|
41
|
+
* prop](https://emotion.sh/docs/css-prop). It will also handle style props for as long as those are
|
|
42
|
+
* supported. `mergeStyles` is exported from the layout package since it supports style props
|
|
43
|
+
* defined in the layout packages.
|
|
44
|
+
*
|
|
45
|
+
* It works by detecting styles added via Emotion's runtime APIs and forcing styling merging if use
|
|
46
|
+
* of runtime APIs have been detected. If only `createStyles` were used to style a component, the
|
|
47
|
+
* faster non-runtime styling will be used.
|
|
48
|
+
*
|
|
49
|
+
* You can use `mergeStyles` if you wish to use {@link createStyles} on your own components and want
|
|
50
|
+
* your components to be compatible with Emotion's runtime styling APIs.
|
|
51
|
+
*
|
|
52
|
+
* ```tsx
|
|
53
|
+
* import {createStyles, CSProps} from '@workday/canvas-kit-styling';
|
|
54
|
+
* import {mergeStyles} from '@workday/canvas-kit-react/layout';
|
|
55
|
+
*
|
|
56
|
+
* interface MyComponentProps extends CSProps {
|
|
57
|
+
* // other props
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
* const myStyles = createStyles({
|
|
61
|
+
* background: 'green',
|
|
62
|
+
* height: 40,
|
|
63
|
+
* width: 40
|
|
64
|
+
* })
|
|
65
|
+
*
|
|
66
|
+
* const MyComponent = ({children, ...elemProps}: MyComponentProps) => {
|
|
67
|
+
* return (
|
|
68
|
+
* <div
|
|
69
|
+
* {...mergeStyles(elemProps, [myStyles])}
|
|
70
|
+
* >
|
|
71
|
+
* {children}
|
|
72
|
+
* </div>
|
|
73
|
+
* )
|
|
74
|
+
* }
|
|
75
|
+
*
|
|
76
|
+
* const StyledMyComponent(MyComponent)({
|
|
77
|
+
* background: 'red'
|
|
78
|
+
* })
|
|
79
|
+
*
|
|
80
|
+
* const myOverridingStyles = createStyles({
|
|
81
|
+
* background: 'blue'
|
|
82
|
+
* })
|
|
83
|
+
*
|
|
84
|
+
* // now everything works. Without `mergeStyles`, the last component would be a red box
|
|
85
|
+
* export default () => (
|
|
86
|
+
* <>
|
|
87
|
+
* <MyComponent>Green box</MyComponent>
|
|
88
|
+
* <StyledMyComponent>Red box</StyledMyComponent>
|
|
89
|
+
* <StyledMyComponent cs={myOverridingStyles}>Blue box</StyledMyComponent>
|
|
90
|
+
* </>
|
|
91
|
+
* )
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
*/
|
|
95
|
+
export function mergeStyles(allProps, cs) {
|
|
96
|
+
const styleProps = {};
|
|
97
|
+
let shouldRuntimeMergeStyles = false;
|
|
98
|
+
// TypeScript can't handle a type where I declare T extends `{className?: string}` for some
|
|
99
|
+
// reason, so we'll do a `as any` any time we check for possible props on `allProps`
|
|
100
|
+
let className = allProps.className || '';
|
|
101
|
+
// separate style props from all other props. `cs` is special and should be forwarded to the
|
|
102
|
+
// `handleCsProp` function.
|
|
103
|
+
const elemProps = Object.keys(allProps).reduce((result, prop) => {
|
|
104
|
+
if (isStyleProps(prop)) {
|
|
105
|
+
shouldRuntimeMergeStyles = true;
|
|
106
|
+
// @ts-ignore
|
|
107
|
+
styleProps[prop] = allProps[prop];
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
if (prop !== 'cs') {
|
|
111
|
+
// @ts-ignore
|
|
112
|
+
result[prop] = allProps[prop];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
}, {});
|
|
117
|
+
// We need to determine if style props have been used. If they have, we need to merge all the CSS
|
|
118
|
+
// classes into a single class name in the order that the class names are listed. This variable
|
|
119
|
+
// will collect the CSS class name created by Emotion if we detect style props.
|
|
120
|
+
let stylePropsClassName = '';
|
|
121
|
+
// We have style props. We need to create style and merge with our `csToProps` to get the correct
|
|
122
|
+
// merging order for styles
|
|
123
|
+
if (shouldRuntimeMergeStyles) {
|
|
124
|
+
const styles = boxStyleFn(styleProps);
|
|
125
|
+
stylePropsClassName = css(styles);
|
|
126
|
+
}
|
|
127
|
+
const returnProps = csToProps([
|
|
128
|
+
cs,
|
|
129
|
+
stylePropsClassName,
|
|
130
|
+
className,
|
|
131
|
+
allProps.cs,
|
|
132
|
+
allProps.style, // doesn't matter if `style` is undefined. csToProps will handle undefined. Thanks anyways, TypeScript
|
|
133
|
+
]);
|
|
134
|
+
// see if we need to do style merging based off use of Emotion runtime APIs. We do this by testing
|
|
135
|
+
// the Emotion cache for a match to any class names we find, filtering out those created via
|
|
136
|
+
// `createStyles`. If only `createStyles` is detected, there is no reason to merge styles
|
|
137
|
+
(returnProps.className || '').split(' ').forEach(name => {
|
|
138
|
+
if (!createStylesCache[name] && cache.registered[name]) {
|
|
139
|
+
shouldRuntimeMergeStyles = true;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
if (shouldRuntimeMergeStyles) {
|
|
143
|
+
const registeredStyles = [];
|
|
144
|
+
// We are using the raw `css` instead of `createStyles` because `css` uses style hashing and
|
|
145
|
+
// `createStyles` generates a new ID every time. We could use `createStyles` here, but it
|
|
146
|
+
// would be more wasteful and new styles would be generated each React render cycle. `css` is
|
|
147
|
+
// safe to use inside a render function while `createStyles` should always be used outside the
|
|
148
|
+
// React render cycle.
|
|
149
|
+
className = getRegisteredStyles(cache.registered, registeredStyles, returnProps.className || '');
|
|
150
|
+
className += css(registeredStyles);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
className = returnProps.className;
|
|
154
|
+
}
|
|
155
|
+
return { ...elemProps, ...returnProps, ...{ className } };
|
|
156
|
+
}
|
|
@@ -26,7 +26,7 @@ interface StyledMenuProps {
|
|
|
26
26
|
*/
|
|
27
27
|
isDisabled?: boolean;
|
|
28
28
|
}
|
|
29
|
-
export declare const StyledMenuItem: import("@emotion/styled").StyledComponent<import("@workday/canvas-kit-react/layout").BackgroundStyleProps & import("../../layout/lib/utils/border/color").BorderColorStyleProps & import("../../layout/lib/utils/border/lineStyle").BorderLineStyleProps & import("../../layout/lib/utils/border/radius").BorderRadiusStyleProps & import("../../layout/lib/utils/border/shorthand").BorderShorthandStyleProps & import("../../layout/lib/utils/border/width").BorderWidthStyleProps & import("@workday/canvas-kit-react/layout").ColorStyleProps & import("@workday/canvas-kit-react/layout").DepthStyleProps & import("@workday/canvas-kit-react/layout").FlexItemStyleProps & import("@workday/canvas-kit-react/layout").GridItemStyleProps & import("@workday/canvas-kit-react/layout").LayoutStyleProps & import("@workday/canvas-kit-react/layout").OtherStyleProps & import("@workday/canvas-kit-react/layout").PositionStyleProps & import("@workday/canvas-kit-react/layout").SpaceStyleProps & import("@workday/canvas-kit-react/layout").TextStyleProps & import("@workday/canvas-kit-styling").CSProps & Omit<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "left" | "right" | "top" | "bottom" | "fill" | "as" | "color" | "resize" | "width" | "height" | "alignSelf" | "appearance" | "backgroundAttachment" | "backgroundColor" | "backgroundImage" | "backgroundRepeat" | "backgroundSize" | "borderBottomColor" | "borderBottomLeftRadius" | "borderBottomRightRadius" | "borderBottomStyle" | "borderBottomWidth" | "borderCollapse" | "borderInlineEndColor" | "borderInlineEndStyle" | "borderInlineEndWidth" | "borderInlineStartColor" | "borderInlineStartStyle" | "borderInlineStartWidth" | "borderLeftColor" | "borderLeftStyle" | "borderLeftWidth" | "borderRightColor" | "borderRightStyle" | "borderRightWidth" | "borderSpacing" | "borderTopColor" | "borderTopLeftRadius" | "borderTopRightRadius" | "borderTopStyle" | "borderTopWidth" | "boxShadow" | "boxSizing" | "content" | "cursor" | "display" | "flexBasis" | "flexGrow" | "flexShrink" | "float" | "fontFamily" | "fontSize" | "fontStyle" | "fontWeight" | "gridColumnEnd" | "gridColumnStart" | "gridRowEnd" | "gridRowStart" | "inset" | "insetInlineEnd" | "insetInlineStart" | "justifySelf" | "letterSpacing" | "lineHeight" | "marginBottom" | "marginInlineEnd" | "marginInlineStart" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "objectFit" | "objectPosition" | "opacity" | "order" | "outlineOffset" | "overflowWrap" | "overflowX" | "overflowY" | "paddingBottom" | "paddingInlineEnd" | "paddingInlineStart" | "paddingLeft" | "paddingRight" | "paddingTop" | "pointerEvents" | "position" | "scrollMargin" | "scrollMarginBottom" | "scrollMarginInlineEnd" | "scrollMarginInlineStart" | "scrollMarginTop" | "scrollPadding" | "scrollPaddingBottom" | "scrollPaddingInlineEnd" | "scrollPaddingInlineStart" | "scrollPaddingTop" | "scrollSnapAlign" | "scrollSnapStop" | "scrollSnapType" | "textAlign" | "textOverflow" | "textShadow" | "textTransform" | "transform" | "userSelect" | "verticalAlign" | "visibility" | "whiteSpace" | "wordBreak" | "zIndex" | "animation" | "background" | "backgroundPosition" | "border" | "borderBottom" | "borderColor" | "borderInlineEnd" | "borderInlineStart" | "borderLeft" | "borderRadius" | "borderRight" | "borderStyle" | "borderTop" | "borderWidth" | "flex" | "gridArea" | "gridColumn" | "gridRow" | "listStyle" | "margin" | "outline" | "overflow" | "padding" | "placeSelf" | "textDecoration" | "transition" | "stroke" | "depth" | "marginX" | "marginY" | "paddingX" | "paddingY"
|
|
29
|
+
export declare const StyledMenuItem: import("@emotion/styled").StyledComponent<import("@workday/canvas-kit-react/layout").BackgroundStyleProps & import("../../layout/lib/utils/border/color").BorderColorStyleProps & import("../../layout/lib/utils/border/lineStyle").BorderLineStyleProps & import("../../layout/lib/utils/border/radius").BorderRadiusStyleProps & import("../../layout/lib/utils/border/shorthand").BorderShorthandStyleProps & import("../../layout/lib/utils/border/width").BorderWidthStyleProps & import("@workday/canvas-kit-react/layout").ColorStyleProps & import("@workday/canvas-kit-react/layout").DepthStyleProps & import("@workday/canvas-kit-react/layout").FlexItemStyleProps & import("@workday/canvas-kit-react/layout").GridItemStyleProps & import("@workday/canvas-kit-react/layout").LayoutStyleProps & import("@workday/canvas-kit-react/layout").OtherStyleProps & import("@workday/canvas-kit-react/layout").PositionStyleProps & import("@workday/canvas-kit-react/layout").SpaceStyleProps & import("@workday/canvas-kit-react/layout").TextStyleProps & import("@workday/canvas-kit-styling").CSProps & Omit<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "left" | "right" | "top" | "bottom" | "fill" | "as" | "color" | "resize" | "width" | "height" | "alignSelf" | "appearance" | "backgroundAttachment" | "backgroundColor" | "backgroundImage" | "backgroundRepeat" | "backgroundSize" | "borderBottomColor" | "borderBottomLeftRadius" | "borderBottomRightRadius" | "borderBottomStyle" | "borderBottomWidth" | "borderCollapse" | "borderInlineEndColor" | "borderInlineEndStyle" | "borderInlineEndWidth" | "borderInlineStartColor" | "borderInlineStartStyle" | "borderInlineStartWidth" | "borderLeftColor" | "borderLeftStyle" | "borderLeftWidth" | "borderRightColor" | "borderRightStyle" | "borderRightWidth" | "borderSpacing" | "borderTopColor" | "borderTopLeftRadius" | "borderTopRightRadius" | "borderTopStyle" | "borderTopWidth" | "boxShadow" | "boxSizing" | "content" | "cursor" | "display" | "flexBasis" | "flexGrow" | "flexShrink" | "float" | "fontFamily" | "fontSize" | "fontStyle" | "fontWeight" | "gridColumnEnd" | "gridColumnStart" | "gridRowEnd" | "gridRowStart" | "inset" | "insetInlineEnd" | "insetInlineStart" | "justifySelf" | "letterSpacing" | "lineHeight" | "marginBottom" | "marginInlineEnd" | "marginInlineStart" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "objectFit" | "objectPosition" | "opacity" | "order" | "outlineOffset" | "overflowWrap" | "overflowX" | "overflowY" | "paddingBottom" | "paddingInlineEnd" | "paddingInlineStart" | "paddingLeft" | "paddingRight" | "paddingTop" | "pointerEvents" | "position" | "scrollMargin" | "scrollMarginBottom" | "scrollMarginInlineEnd" | "scrollMarginInlineStart" | "scrollMarginTop" | "scrollPadding" | "scrollPaddingBottom" | "scrollPaddingInlineEnd" | "scrollPaddingInlineStart" | "scrollPaddingTop" | "scrollSnapAlign" | "scrollSnapStop" | "scrollSnapType" | "textAlign" | "textOverflow" | "textShadow" | "textTransform" | "transform" | "userSelect" | "verticalAlign" | "visibility" | "whiteSpace" | "wordBreak" | "zIndex" | "animation" | "background" | "backgroundPosition" | "border" | "borderBottom" | "borderColor" | "borderInlineEnd" | "borderInlineStart" | "borderLeft" | "borderRadius" | "borderRight" | "borderStyle" | "borderTop" | "borderWidth" | "flex" | "gridArea" | "gridColumn" | "gridRow" | "listStyle" | "margin" | "outline" | "overflow" | "padding" | "placeSelf" | "textDecoration" | "transition" | "stroke" | "cs" | "depth" | "marginX" | "marginY" | "paddingX" | "paddingY"> & {
|
|
30
30
|
ref?: React.Ref<HTMLButtonElement> | undefined;
|
|
31
31
|
} & {
|
|
32
32
|
theme?: import("@emotion/react").Theme | undefined;
|
|
@@ -53,7 +53,7 @@ export interface TabsItemProps extends ExtractProps<typeof Box, never>, Partial<
|
|
|
53
53
|
*/
|
|
54
54
|
tabIndex?: number;
|
|
55
55
|
}
|
|
56
|
-
export declare const StyledTabItem: import("@emotion/styled").StyledComponent<import("@workday/canvas-kit-react/layout").BackgroundStyleProps & import("../../layout/lib/utils/border/color").BorderColorStyleProps & import("../../layout/lib/utils/border/lineStyle").BorderLineStyleProps & import("../../layout/lib/utils/border/radius").BorderRadiusStyleProps & import("../../layout/lib/utils/border/shorthand").BorderShorthandStyleProps & import("../../layout/lib/utils/border/width").BorderWidthStyleProps & import("@workday/canvas-kit-react/layout").ColorStyleProps & import("@workday/canvas-kit-react/layout").DepthStyleProps & import("@workday/canvas-kit-react/layout").FlexItemStyleProps & import("@workday/canvas-kit-react/layout").GridItemStyleProps & import("@workday/canvas-kit-react/layout").LayoutStyleProps & import("@workday/canvas-kit-react/layout").OtherStyleProps & import("@workday/canvas-kit-react/layout").PositionStyleProps & import("@workday/canvas-kit-react/layout").SpaceStyleProps & import("@workday/canvas-kit-react/layout").TextStyleProps & import("@workday/canvas-kit-styling").CSProps & Omit<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "left" | "right" | "top" | "bottom" | "fill" | "as" | "color" | "resize" | "width" | "height" | "alignSelf" | "appearance" | "backgroundAttachment" | "backgroundColor" | "backgroundImage" | "backgroundRepeat" | "backgroundSize" | "borderBottomColor" | "borderBottomLeftRadius" | "borderBottomRightRadius" | "borderBottomStyle" | "borderBottomWidth" | "borderCollapse" | "borderInlineEndColor" | "borderInlineEndStyle" | "borderInlineEndWidth" | "borderInlineStartColor" | "borderInlineStartStyle" | "borderInlineStartWidth" | "borderLeftColor" | "borderLeftStyle" | "borderLeftWidth" | "borderRightColor" | "borderRightStyle" | "borderRightWidth" | "borderSpacing" | "borderTopColor" | "borderTopLeftRadius" | "borderTopRightRadius" | "borderTopStyle" | "borderTopWidth" | "boxShadow" | "boxSizing" | "content" | "cursor" | "display" | "flexBasis" | "flexGrow" | "flexShrink" | "float" | "fontFamily" | "fontSize" | "fontStyle" | "fontWeight" | "gridColumnEnd" | "gridColumnStart" | "gridRowEnd" | "gridRowStart" | "inset" | "insetInlineEnd" | "insetInlineStart" | "justifySelf" | "letterSpacing" | "lineHeight" | "marginBottom" | "marginInlineEnd" | "marginInlineStart" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "objectFit" | "objectPosition" | "opacity" | "order" | "outlineOffset" | "overflowWrap" | "overflowX" | "overflowY" | "paddingBottom" | "paddingInlineEnd" | "paddingInlineStart" | "paddingLeft" | "paddingRight" | "paddingTop" | "pointerEvents" | "position" | "scrollMargin" | "scrollMarginBottom" | "scrollMarginInlineEnd" | "scrollMarginInlineStart" | "scrollMarginTop" | "scrollPadding" | "scrollPaddingBottom" | "scrollPaddingInlineEnd" | "scrollPaddingInlineStart" | "scrollPaddingTop" | "scrollSnapAlign" | "scrollSnapStop" | "scrollSnapType" | "textAlign" | "textOverflow" | "textShadow" | "textTransform" | "transform" | "userSelect" | "verticalAlign" | "visibility" | "whiteSpace" | "wordBreak" | "zIndex" | "animation" | "background" | "backgroundPosition" | "border" | "borderBottom" | "borderColor" | "borderInlineEnd" | "borderInlineStart" | "borderLeft" | "borderRadius" | "borderRight" | "borderStyle" | "borderTop" | "borderWidth" | "flex" | "gridArea" | "gridColumn" | "gridRow" | "listStyle" | "margin" | "outline" | "overflow" | "padding" | "placeSelf" | "textDecoration" | "transition" | "stroke" | "depth" | "marginX" | "marginY" | "paddingX" | "paddingY"
|
|
56
|
+
export declare const StyledTabItem: import("@emotion/styled").StyledComponent<import("@workday/canvas-kit-react/layout").BackgroundStyleProps & import("../../layout/lib/utils/border/color").BorderColorStyleProps & import("../../layout/lib/utils/border/lineStyle").BorderLineStyleProps & import("../../layout/lib/utils/border/radius").BorderRadiusStyleProps & import("../../layout/lib/utils/border/shorthand").BorderShorthandStyleProps & import("../../layout/lib/utils/border/width").BorderWidthStyleProps & import("@workday/canvas-kit-react/layout").ColorStyleProps & import("@workday/canvas-kit-react/layout").DepthStyleProps & import("@workday/canvas-kit-react/layout").FlexItemStyleProps & import("@workday/canvas-kit-react/layout").GridItemStyleProps & import("@workday/canvas-kit-react/layout").LayoutStyleProps & import("@workday/canvas-kit-react/layout").OtherStyleProps & import("@workday/canvas-kit-react/layout").PositionStyleProps & import("@workday/canvas-kit-react/layout").SpaceStyleProps & import("@workday/canvas-kit-react/layout").TextStyleProps & import("@workday/canvas-kit-styling").CSProps & Omit<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "left" | "right" | "top" | "bottom" | "fill" | "as" | "color" | "resize" | "width" | "height" | "alignSelf" | "appearance" | "backgroundAttachment" | "backgroundColor" | "backgroundImage" | "backgroundRepeat" | "backgroundSize" | "borderBottomColor" | "borderBottomLeftRadius" | "borderBottomRightRadius" | "borderBottomStyle" | "borderBottomWidth" | "borderCollapse" | "borderInlineEndColor" | "borderInlineEndStyle" | "borderInlineEndWidth" | "borderInlineStartColor" | "borderInlineStartStyle" | "borderInlineStartWidth" | "borderLeftColor" | "borderLeftStyle" | "borderLeftWidth" | "borderRightColor" | "borderRightStyle" | "borderRightWidth" | "borderSpacing" | "borderTopColor" | "borderTopLeftRadius" | "borderTopRightRadius" | "borderTopStyle" | "borderTopWidth" | "boxShadow" | "boxSizing" | "content" | "cursor" | "display" | "flexBasis" | "flexGrow" | "flexShrink" | "float" | "fontFamily" | "fontSize" | "fontStyle" | "fontWeight" | "gridColumnEnd" | "gridColumnStart" | "gridRowEnd" | "gridRowStart" | "inset" | "insetInlineEnd" | "insetInlineStart" | "justifySelf" | "letterSpacing" | "lineHeight" | "marginBottom" | "marginInlineEnd" | "marginInlineStart" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "objectFit" | "objectPosition" | "opacity" | "order" | "outlineOffset" | "overflowWrap" | "overflowX" | "overflowY" | "paddingBottom" | "paddingInlineEnd" | "paddingInlineStart" | "paddingLeft" | "paddingRight" | "paddingTop" | "pointerEvents" | "position" | "scrollMargin" | "scrollMarginBottom" | "scrollMarginInlineEnd" | "scrollMarginInlineStart" | "scrollMarginTop" | "scrollPadding" | "scrollPaddingBottom" | "scrollPaddingInlineEnd" | "scrollPaddingInlineStart" | "scrollPaddingTop" | "scrollSnapAlign" | "scrollSnapStop" | "scrollSnapType" | "textAlign" | "textOverflow" | "textShadow" | "textTransform" | "transform" | "userSelect" | "verticalAlign" | "visibility" | "whiteSpace" | "wordBreak" | "zIndex" | "animation" | "background" | "backgroundPosition" | "border" | "borderBottom" | "borderColor" | "borderInlineEnd" | "borderInlineStart" | "borderLeft" | "borderRadius" | "borderRight" | "borderStyle" | "borderTop" | "borderWidth" | "flex" | "gridArea" | "gridColumn" | "gridRow" | "listStyle" | "margin" | "outline" | "overflow" | "padding" | "placeSelf" | "textDecoration" | "transition" | "stroke" | "cs" | "depth" | "marginX" | "marginY" | "paddingX" | "paddingY"> & {
|
|
57
57
|
ref?: React.Ref<HTMLButtonElement> | undefined;
|
|
58
58
|
} & {
|
|
59
59
|
theme?: import("@emotion/react").Theme | undefined;
|
package/layout/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './lib/Box';
|
|
2
|
+
export * from './lib/utils/mergeStyles';
|
|
2
3
|
export * from './lib/utils/background';
|
|
3
4
|
export * from './lib/utils/border';
|
|
4
5
|
export * from './lib/utils/color';
|
|
@@ -16,7 +17,7 @@ export {AllStyleProps, CommonStyleProps} from './lib/utils/styleProps';
|
|
|
16
17
|
export * from './lib/utils/text';
|
|
17
18
|
export * from './lib/Flex';
|
|
18
19
|
export * from './lib/Grid';
|
|
19
|
-
export type {
|
|
20
|
-
export type {
|
|
21
|
-
export
|
|
20
|
+
export type {FlexStyleProps} from './lib/utils/flex';
|
|
21
|
+
export type {GridStyleProps} from './lib/utils/grid';
|
|
22
|
+
export {GridItemStyleProps, gridItemStyleFnConfigs} from './lib/utils/gridItem';
|
|
22
23
|
export * from './lib/utils/systemProps';
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import {getRegisteredStyles} from '@emotion/utils';
|
|
2
|
+
// eslint-disable-next-line @emotion/no-vanilla
|
|
3
|
+
import {cache, css} from '@emotion/css';
|
|
4
|
+
import {csToProps, CSToPropsInput, createStylesCache} from '@workday/canvas-kit-styling';
|
|
5
|
+
import {boxStyleFn} from '../Box';
|
|
6
|
+
import {backgroundStyleFnConfigs} from './background';
|
|
7
|
+
import {borderStyleFnConfigs} from './border';
|
|
8
|
+
import {colorStyleFnConfigs} from './color';
|
|
9
|
+
import {depthStyleFnConfigs} from './depth';
|
|
10
|
+
import {flexItemStyleFnConfigs} from './flexItem';
|
|
11
|
+
import {gridItemStyleFnConfigs} from './gridItem';
|
|
12
|
+
import {layoutStyleFnConfigs} from './layout';
|
|
13
|
+
import {otherStyleFnConfigs} from './other';
|
|
14
|
+
import {positionStyleFnConfigs} from './position';
|
|
15
|
+
import {spaceStyleFnConfigs} from './space';
|
|
16
|
+
import {CommonStyleProps} from './styleProps';
|
|
17
|
+
import {textStyleFnConfigs} from './text';
|
|
18
|
+
|
|
19
|
+
// get a hash of all the style props for a faster lookup
|
|
20
|
+
const stylePropHash = [
|
|
21
|
+
...backgroundStyleFnConfigs,
|
|
22
|
+
...borderStyleFnConfigs,
|
|
23
|
+
...colorStyleFnConfigs,
|
|
24
|
+
...depthStyleFnConfigs,
|
|
25
|
+
...flexItemStyleFnConfigs,
|
|
26
|
+
...gridItemStyleFnConfigs,
|
|
27
|
+
...layoutStyleFnConfigs,
|
|
28
|
+
...otherStyleFnConfigs,
|
|
29
|
+
...positionStyleFnConfigs,
|
|
30
|
+
...spaceStyleFnConfigs,
|
|
31
|
+
...textStyleFnConfigs,
|
|
32
|
+
].reduce((result, prop) => {
|
|
33
|
+
//@ts-ignore
|
|
34
|
+
result[prop.name] = true;
|
|
35
|
+
return result;
|
|
36
|
+
}, {} as Record<string, boolean>);
|
|
37
|
+
|
|
38
|
+
function isStyleProps(prop: string): boolean {
|
|
39
|
+
return stylePropHash[prop] || false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* This is an opinionated function that will force style merging with Emotion's runtime APIs,
|
|
44
|
+
* including [styled components](https://emotion.sh/docs/styled) and the [css
|
|
45
|
+
* prop](https://emotion.sh/docs/css-prop). It will also handle style props for as long as those are
|
|
46
|
+
* supported. `mergeStyles` is exported from the layout package since it supports style props
|
|
47
|
+
* defined in the layout packages.
|
|
48
|
+
*
|
|
49
|
+
* It works by detecting styles added via Emotion's runtime APIs and forcing styling merging if use
|
|
50
|
+
* of runtime APIs have been detected. If only `createStyles` were used to style a component, the
|
|
51
|
+
* faster non-runtime styling will be used.
|
|
52
|
+
*
|
|
53
|
+
* You can use `mergeStyles` if you wish to use {@link createStyles} on your own components and want
|
|
54
|
+
* your components to be compatible with Emotion's runtime styling APIs.
|
|
55
|
+
*
|
|
56
|
+
* ```tsx
|
|
57
|
+
* import {createStyles, CSProps} from '@workday/canvas-kit-styling';
|
|
58
|
+
* import {mergeStyles} from '@workday/canvas-kit-react/layout';
|
|
59
|
+
*
|
|
60
|
+
* interface MyComponentProps extends CSProps {
|
|
61
|
+
* // other props
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* const myStyles = createStyles({
|
|
65
|
+
* background: 'green',
|
|
66
|
+
* height: 40,
|
|
67
|
+
* width: 40
|
|
68
|
+
* })
|
|
69
|
+
*
|
|
70
|
+
* const MyComponent = ({children, ...elemProps}: MyComponentProps) => {
|
|
71
|
+
* return (
|
|
72
|
+
* <div
|
|
73
|
+
* {...mergeStyles(elemProps, [myStyles])}
|
|
74
|
+
* >
|
|
75
|
+
* {children}
|
|
76
|
+
* </div>
|
|
77
|
+
* )
|
|
78
|
+
* }
|
|
79
|
+
*
|
|
80
|
+
* const StyledMyComponent(MyComponent)({
|
|
81
|
+
* background: 'red'
|
|
82
|
+
* })
|
|
83
|
+
*
|
|
84
|
+
* const myOverridingStyles = createStyles({
|
|
85
|
+
* background: 'blue'
|
|
86
|
+
* })
|
|
87
|
+
*
|
|
88
|
+
* // now everything works. Without `mergeStyles`, the last component would be a red box
|
|
89
|
+
* export default () => (
|
|
90
|
+
* <>
|
|
91
|
+
* <MyComponent>Green box</MyComponent>
|
|
92
|
+
* <StyledMyComponent>Red box</StyledMyComponent>
|
|
93
|
+
* <StyledMyComponent cs={myOverridingStyles}>Blue box</StyledMyComponent>
|
|
94
|
+
* </>
|
|
95
|
+
* )
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
*/
|
|
99
|
+
export function mergeStyles<T extends {}>(
|
|
100
|
+
allProps: T,
|
|
101
|
+
cs: CSToPropsInput
|
|
102
|
+
): Omit<T, 'cs' | keyof CommonStyleProps> {
|
|
103
|
+
const styleProps = {};
|
|
104
|
+
let shouldRuntimeMergeStyles = false;
|
|
105
|
+
// TypeScript can't handle a type where I declare T extends `{className?: string}` for some
|
|
106
|
+
// reason, so we'll do a `as any` any time we check for possible props on `allProps`
|
|
107
|
+
let className = (allProps as any).className || '';
|
|
108
|
+
|
|
109
|
+
// separate style props from all other props. `cs` is special and should be forwarded to the
|
|
110
|
+
// `handleCsProp` function.
|
|
111
|
+
const elemProps = Object.keys(allProps).reduce((result, prop) => {
|
|
112
|
+
if (isStyleProps(prop)) {
|
|
113
|
+
shouldRuntimeMergeStyles = true;
|
|
114
|
+
// @ts-ignore
|
|
115
|
+
styleProps[prop] = allProps[prop];
|
|
116
|
+
} else {
|
|
117
|
+
if (prop !== 'cs') {
|
|
118
|
+
// @ts-ignore
|
|
119
|
+
result[prop] = allProps[prop];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return result;
|
|
124
|
+
}, {});
|
|
125
|
+
|
|
126
|
+
// We need to determine if style props have been used. If they have, we need to merge all the CSS
|
|
127
|
+
// classes into a single class name in the order that the class names are listed. This variable
|
|
128
|
+
// will collect the CSS class name created by Emotion if we detect style props.
|
|
129
|
+
let stylePropsClassName = '';
|
|
130
|
+
|
|
131
|
+
// We have style props. We need to create style and merge with our `csToProps` to get the correct
|
|
132
|
+
// merging order for styles
|
|
133
|
+
if (shouldRuntimeMergeStyles) {
|
|
134
|
+
const styles = boxStyleFn(styleProps);
|
|
135
|
+
stylePropsClassName = css(styles);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const returnProps = csToProps([
|
|
139
|
+
cs,
|
|
140
|
+
stylePropsClassName, // if style props are not defined, this will be an empty string, which is fine
|
|
141
|
+
className, // This will come from `styled` components or the `css` prop or if a user manually sets the `className` prop
|
|
142
|
+
(allProps as any).cs, // doesn't matter if `cs` is undefined. csToProps will handle undefined. Thanks anyways, TypeScript
|
|
143
|
+
(allProps as any).style, // doesn't matter if `style` is undefined. csToProps will handle undefined. Thanks anyways, TypeScript
|
|
144
|
+
]);
|
|
145
|
+
|
|
146
|
+
// see if we need to do style merging based off use of Emotion runtime APIs. We do this by testing
|
|
147
|
+
// the Emotion cache for a match to any class names we find, filtering out those created via
|
|
148
|
+
// `createStyles`. If only `createStyles` is detected, there is no reason to merge styles
|
|
149
|
+
(returnProps.className || '').split(' ').forEach(name => {
|
|
150
|
+
if (!createStylesCache[name] && cache.registered[name]) {
|
|
151
|
+
shouldRuntimeMergeStyles = true;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
if (shouldRuntimeMergeStyles) {
|
|
156
|
+
const registeredStyles: string[] = [];
|
|
157
|
+
|
|
158
|
+
// We are using the raw `css` instead of `createStyles` because `css` uses style hashing and
|
|
159
|
+
// `createStyles` generates a new ID every time. We could use `createStyles` here, but it
|
|
160
|
+
// would be more wasteful and new styles would be generated each React render cycle. `css` is
|
|
161
|
+
// safe to use inside a render function while `createStyles` should always be used outside the
|
|
162
|
+
// React render cycle.
|
|
163
|
+
className = getRegisteredStyles(
|
|
164
|
+
cache.registered,
|
|
165
|
+
registeredStyles,
|
|
166
|
+
returnProps.className || ''
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
className += css(registeredStyles);
|
|
170
|
+
} else {
|
|
171
|
+
className = returnProps.className;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return {...elemProps, ...returnProps, ...{className}} as any as Omit<
|
|
175
|
+
T,
|
|
176
|
+
'cs' | keyof CommonStyleProps
|
|
177
|
+
>;
|
|
178
|
+
}
|