@atlaskit/primitives 0.5.0 → 0.7.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.
Files changed (72) hide show
  1. package/.eslintrc.js +3 -0
  2. package/CHANGELOG.md +14 -0
  3. package/dist/cjs/components/box.js +3 -40
  4. package/dist/cjs/components/inline.partial.js +24 -91
  5. package/dist/cjs/components/internal/base-box.js +61 -0
  6. package/dist/cjs/components/stack.partial.js +24 -47
  7. package/dist/cjs/internal/style-maps.partial.js +370 -0
  8. package/dist/cjs/internal/xcss.js +17 -7
  9. package/dist/cjs/version.json +1 -1
  10. package/dist/es2019/components/box.js +1 -37
  11. package/dist/es2019/components/inline.partial.js +20 -63
  12. package/dist/es2019/components/internal/base-box.js +52 -0
  13. package/dist/es2019/components/stack.partial.js +20 -19
  14. package/dist/es2019/internal/style-maps.partial.js +341 -0
  15. package/dist/es2019/internal/xcss.js +13 -7
  16. package/dist/es2019/version.json +1 -1
  17. package/dist/esm/components/box.js +2 -40
  18. package/dist/esm/components/inline.partial.js +23 -91
  19. package/dist/esm/components/internal/base-box.js +53 -0
  20. package/dist/esm/components/stack.partial.js +23 -47
  21. package/dist/esm/internal/style-maps.partial.js +340 -0
  22. package/dist/esm/internal/xcss.js +17 -7
  23. package/dist/esm/version.json +1 -1
  24. package/dist/types/components/box.d.ts +2 -3
  25. package/dist/types/components/inline.partial.d.ts +23 -37
  26. package/dist/types/components/internal/base-box.d.ts +83 -0
  27. package/dist/types/components/stack.partial.d.ts +21 -19
  28. package/dist/types/components/types.d.ts +1 -47
  29. package/dist/types/internal/style-maps.partial.d.ts +396 -0
  30. package/dist/types/internal/xcss.d.ts +5 -5
  31. package/package.json +3 -3
  32. package/report.api.md +228 -394
  33. package/scripts/__tests__/__snapshots__/codegen.test.tsx.snap +313 -363
  34. package/scripts/border-codegen-template.tsx +79 -0
  35. package/scripts/codegen-file-templates/align-self.tsx +9 -0
  36. package/scripts/codegen-file-templates/border-style.tsx +6 -0
  37. package/scripts/codegen-file-templates/dimensions.tsx +17 -0
  38. package/scripts/codegen-file-templates/display.tsx +6 -0
  39. package/scripts/codegen-file-templates/flex-grow.tsx +6 -0
  40. package/scripts/codegen-file-templates/flex-shrink.tsx +6 -0
  41. package/scripts/codegen-file-templates/flex.tsx +5 -0
  42. package/scripts/codegen-file-templates/layer.tsx +13 -0
  43. package/scripts/codegen-file-templates/overflow.tsx +20 -0
  44. package/scripts/codegen-file-templates/position.tsx +8 -0
  45. package/scripts/codegen-styles.tsx +80 -120
  46. package/scripts/color-codegen-template.tsx +9 -19
  47. package/scripts/misc-codegen-template.tsx +20 -40
  48. package/scripts/spacing-codegen-template.tsx +22 -29
  49. package/scripts/utils.tsx +15 -4
  50. package/tmp/api-report-tmp.d.ts +223 -381
  51. package/dist/cjs/components/internal/base-box.partial.js +0 -843
  52. package/dist/cjs/components/internal/types.js +0 -8
  53. package/dist/cjs/components/internal/utils.js +0 -16
  54. package/dist/cjs/internal/color-map.js +0 -42
  55. package/dist/cjs/internal/style-maps.js +0 -130
  56. package/dist/es2019/components/internal/base-box.partial.js +0 -838
  57. package/dist/es2019/components/internal/types.js +0 -1
  58. package/dist/es2019/components/internal/utils.js +0 -2
  59. package/dist/es2019/internal/color-map.js +0 -35
  60. package/dist/es2019/internal/style-maps.js +0 -117
  61. package/dist/esm/components/internal/base-box.partial.js +0 -838
  62. package/dist/esm/components/internal/types.js +0 -1
  63. package/dist/esm/components/internal/utils.js +0 -7
  64. package/dist/esm/internal/color-map.js +0 -35
  65. package/dist/esm/internal/style-maps.js +0 -117
  66. package/dist/types/components/internal/base-box.partial.d.ts +0 -522
  67. package/dist/types/components/internal/types.d.ts +0 -8
  68. package/dist/types/components/internal/utils.d.ts +0 -3
  69. package/dist/types/internal/color-map.d.ts +0 -36
  70. package/dist/types/internal/style-maps.d.ts +0 -151
  71. package/scripts/color-map-template.tsx +0 -52
  72. package/scripts/dimension-codegen-template.tsx +0 -75
@@ -2,7 +2,8 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import _typeof from "@babel/runtime/helpers/typeof";
3
3
  /* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
4
4
  import { css as cssEmotion } from '@emotion/react';
5
- import { backgroundColorMap, borderColorMap, borderRadiusMap, borderWidthMap, dimensionMap, paddingMap, textColorMap } from './style-maps';
5
+ import warnOnce from '@atlaskit/ds-lib/warn-once';
6
+ import { backgroundColorMap, borderColorMap, borderRadiusMap, borderWidthMap, dimensionMap, paddingMap, shadowMap, textColorMap } from './style-maps.partial';
6
7
  var tokensMap = {
7
8
  backgroundColor: backgroundColorMap,
8
9
  borderColor: borderColorMap,
@@ -21,9 +22,13 @@ var tokensMap = {
21
22
  paddingInline: paddingMap,
22
23
  paddingInlineEnd: paddingMap,
23
24
  paddingInlineStart: paddingMap,
25
+ boxShadow: shadowMap,
24
26
  width: dimensionMap
25
27
  };
26
28
  var uniqueSymbol = Symbol('Internal symbol to verify xcss function is called safely');
29
+ var isSafeEnvToThrow = function isSafeEnvToThrow() {
30
+ return (typeof process === "undefined" ? "undefined" : _typeof(process)) === 'object' && _typeof(process.env) === 'object' && process.env.NODE_ENV !== 'production';
31
+ };
27
32
 
28
33
  /**
29
34
  * Only exposed for testing.
@@ -41,11 +46,10 @@ export var transformStyles = function transformStyles(styleObj) {
41
46
 
42
47
  // Modifies styleObj in place. Be careful.
43
48
  Object.entries(styleObj).forEach(function (_ref) {
44
- var _process, _process$env;
45
49
  var _ref2 = _slicedToArray(_ref, 2),
46
50
  key = _ref2[0],
47
51
  value = _ref2[1];
48
- if (((_process = process) === null || _process === void 0 ? void 0 : (_process$env = _process.env) === null || _process$env === void 0 ? void 0 : _process$env.NODE_ENV) === 'development') {
52
+ if (isSafeEnvToThrow()) {
49
53
  // We don't support `.class`, `[data-testid]`, `> *`, `#some-id`
50
54
  if (/(\.|\s|&+|\*\>|#|\[.*\])/.test(key)) {
51
55
  throw new Error("Styles not supported for key '".concat(key, "'."));
@@ -69,7 +73,11 @@ export var transformStyles = function transformStyles(styleObj) {
69
73
  }
70
74
  var tokenValue = tokensMap[key][value];
71
75
  if (!tokenValue) {
72
- throw new Error('Invalid Token');
76
+ var message = "Invalid token alias: ".concat(value);
77
+ warnOnce(message);
78
+ if (isSafeEnvToThrow()) {
79
+ throw new Error(message);
80
+ }
73
81
  }
74
82
  styleObj[key] = tokenValue;
75
83
  });
@@ -85,12 +93,14 @@ var baseXcss = function baseXcss(style) {
85
93
 
86
94
  /**
87
95
  * @internal used in primitives
88
- * @returns
96
+ * @returns a collection of styles that can be applied to the respective primitive
89
97
  */
98
+
90
99
  export var parseXcss = function parseXcss(args) {
91
100
  if (Array.isArray(args)) {
92
- // @ts-expect-error FIXME
93
- return args.map(parseXcss);
101
+ return args.map(function (x) {
102
+ return x && parseXcss(x);
103
+ }).filter(Boolean);
94
104
  }
95
105
  var symbol = args.symbol,
96
106
  styles = args.styles;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/primitives",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,9 +1,8 @@
1
1
  /** @jsx jsx */
2
2
  import { ElementType, FC, ReactElement } from 'react';
3
- import { BaseBoxProps } from './internal/base-box.partial';
4
- import type { BoxResponsiveProp } from './internal/types';
3
+ import { BaseBoxProps } from './internal/base-box';
5
4
  import type { PublicBoxPropsBase } from './types';
6
- export declare type BoxProps<T extends ElementType = 'div'> = Omit<BaseBoxProps<T>, 'className' | BoxResponsiveProp> & PublicBoxPropsBase;
5
+ export declare type BoxProps<T extends ElementType = 'div'> = Omit<BaseBoxProps<T>, 'className'> & PublicBoxPropsBase;
7
6
  declare type BoxComponent<T extends ElementType = 'div'> = (<T extends ElementType = 'div'>(props: BoxProps<T>) => ReactElement | null) & FC<BoxProps<T>>;
8
7
  /**
9
8
  * __Box__
@@ -28,12 +28,12 @@ export interface InlineProps<T extends ElementType = 'div'> {
28
28
  /**
29
29
  * Represents the space between each child.
30
30
  */
31
- space?: Space;
31
+ space?: Gap;
32
32
  /**
33
33
  * Represents the space between rows when content wraps.
34
34
  * Used to override the `space` value in between rows.
35
35
  */
36
- rowSpace?: RowSpace;
36
+ rowSpace?: RowGap;
37
37
  /**
38
38
  * Renders a separator string between each child.
39
39
  */
@@ -57,46 +57,32 @@ export declare type Spread = 'space-between';
57
57
  export declare type Grow = 'hug' | 'fill';
58
58
  /**
59
59
  * THIS SECTION WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
60
- * @codegen <<SignedSource::44cacef18982a4b0e43102900c42bdcf>>
60
+ * @codegen <<SignedSource::fb7587b114753ed19425e2b07b5deb0d>>
61
61
  * @codegenId spacing
62
62
  * @codegenCommand yarn codegen-styles
63
- * @codegenParams ["space", "rowSpace"]
63
+ * @codegenParams ["inlineSpace"]
64
64
  * @codegenDependency ../../../tokens/src/artifacts/tokens-raw/atlassian-spacing.tsx <<SignedSource::167d3b69b159ae33e74d4ea5ab7eade6>>
65
65
  */
66
- declare const spaceMap: {
67
- readonly '0': import("@emotion/react").SerializedStyles;
68
- readonly '025': import("@emotion/react").SerializedStyles;
69
- readonly '050': import("@emotion/react").SerializedStyles;
70
- readonly '075': import("@emotion/react").SerializedStyles;
71
- readonly '100': import("@emotion/react").SerializedStyles;
72
- readonly '150': import("@emotion/react").SerializedStyles;
73
- readonly '200': import("@emotion/react").SerializedStyles;
74
- readonly '250': import("@emotion/react").SerializedStyles;
75
- readonly '300': import("@emotion/react").SerializedStyles;
76
- readonly '400': import("@emotion/react").SerializedStyles;
77
- readonly '500': import("@emotion/react").SerializedStyles;
78
- readonly '600': import("@emotion/react").SerializedStyles;
79
- readonly '800': import("@emotion/react").SerializedStyles;
80
- readonly '1000': import("@emotion/react").SerializedStyles;
66
+ declare const inlineSpaceMap: {
67
+ [k: string]: {
68
+ readonly '0': import("@emotion/react").SerializedStyles;
69
+ readonly '025': import("@emotion/react").SerializedStyles;
70
+ readonly '050': import("@emotion/react").SerializedStyles;
71
+ readonly '075': import("@emotion/react").SerializedStyles;
72
+ readonly '100': import("@emotion/react").SerializedStyles;
73
+ readonly '150': import("@emotion/react").SerializedStyles;
74
+ readonly '200': import("@emotion/react").SerializedStyles;
75
+ readonly '250': import("@emotion/react").SerializedStyles;
76
+ readonly '300': import("@emotion/react").SerializedStyles;
77
+ readonly '400': import("@emotion/react").SerializedStyles;
78
+ readonly '500': import("@emotion/react").SerializedStyles;
79
+ readonly '600': import("@emotion/react").SerializedStyles;
80
+ readonly '800': import("@emotion/react").SerializedStyles;
81
+ readonly '1000': import("@emotion/react").SerializedStyles;
82
+ };
81
83
  };
82
- export declare type Space = keyof typeof spaceMap;
83
- declare const rowSpaceMap: {
84
- readonly '0': import("@emotion/react").SerializedStyles;
85
- readonly '025': import("@emotion/react").SerializedStyles;
86
- readonly '050': import("@emotion/react").SerializedStyles;
87
- readonly '075': import("@emotion/react").SerializedStyles;
88
- readonly '100': import("@emotion/react").SerializedStyles;
89
- readonly '150': import("@emotion/react").SerializedStyles;
90
- readonly '200': import("@emotion/react").SerializedStyles;
91
- readonly '250': import("@emotion/react").SerializedStyles;
92
- readonly '300': import("@emotion/react").SerializedStyles;
93
- readonly '400': import("@emotion/react").SerializedStyles;
94
- readonly '500': import("@emotion/react").SerializedStyles;
95
- readonly '600': import("@emotion/react").SerializedStyles;
96
- readonly '800': import("@emotion/react").SerializedStyles;
97
- readonly '1000': import("@emotion/react").SerializedStyles;
98
- };
99
- export declare type RowSpace = keyof typeof rowSpaceMap;
84
+ export declare type Gap = keyof typeof inlineSpaceMap.gap;
85
+ export declare type RowGap = keyof typeof inlineSpaceMap.rowGap;
100
86
  /**
101
87
  * __Inline__
102
88
  *
@@ -0,0 +1,83 @@
1
+ /** @jsx jsx */
2
+ import { ComponentPropsWithoutRef, ComponentPropsWithRef, ElementType, FC, ReactElement, ReactNode } from 'react';
3
+ import { BackgroundColor, Padding, PaddingBlock, PaddingBlockEnd, PaddingBlockStart, PaddingInline, PaddingInlineEnd, PaddingInlineStart } from '../../internal/style-maps.partial';
4
+ import type { BasePrimitiveProps } from '../types';
5
+ export declare type BaseBoxProps<T extends ElementType = 'div'> = Omit<ComponentPropsWithoutRef<T>, 'as' | 'className'> & BasePrimitiveProps & BaseBoxPropsFoundation<T>;
6
+ declare type BaseBoxPropsFoundation<T extends ElementType> = {
7
+ /**
8
+ * The DOM element to render as the Box. Defaults to `div`.
9
+ */
10
+ as?: 'div' | 'span' | 'li';
11
+ /**
12
+ * The HTML className attribute.
13
+ *
14
+ * Before using this prop please ensure:
15
+ * - The styles cannot otherwise be achieved through `Box` directly.
16
+ * - The use case needs custom styles that cannot be designed or implemented differently
17
+ *
18
+ * Ensure you're using the `@atlaskit/eslint-plugin-design-system` with this prop to prevent unbounded usage.
19
+ *
20
+ * @see `@atlaskit/eslint-plugin-design-system`
21
+ */
22
+ className?: string;
23
+ /**
24
+ * Elements to be rendered inside the Box.
25
+ */
26
+ children?: ReactNode;
27
+ /**
28
+ * Token representing background color with a built-in fallback value.
29
+ */
30
+ backgroundColor?: BackgroundColor;
31
+ /**
32
+ * Tokens representing CSS shorthand for `paddingBlock` and `paddingInline` together.
33
+ *
34
+ * @see paddingBlock
35
+ * @see paddingInline
36
+ */
37
+ padding?: Padding;
38
+ /**
39
+ * Tokens representing CSS shorthand `paddingBlock`.
40
+ *
41
+ * @see paddingBlockStart
42
+ * @see paddingBlockEnd
43
+ */
44
+ paddingBlock?: PaddingBlock;
45
+ /**
46
+ * Tokens representing CSS `paddingBlockStart`.
47
+ */
48
+ paddingBlockStart?: PaddingBlockStart;
49
+ /**
50
+ * Tokens representing CSS `paddingBlockEnd`.
51
+ */
52
+ paddingBlockEnd?: PaddingBlockEnd;
53
+ /**
54
+ * Tokens representing CSS shorthand `paddingInline`.
55
+ *
56
+ * @see paddingInlineStart
57
+ * @see paddingInlineEnd
58
+ */
59
+ paddingInline?: PaddingInline;
60
+ /**
61
+ * Tokens representing CSS `paddingInlineStart`.
62
+ */
63
+ paddingInlineStart?: PaddingInlineStart;
64
+ /**
65
+ * Tokens representing CSS `paddingInlineEnd`.
66
+ */
67
+ paddingInlineEnd?: PaddingInlineEnd;
68
+ /**
69
+ * Forwarded ref element
70
+ */
71
+ ref?: ComponentPropsWithRef<T>['ref'];
72
+ };
73
+ export declare type BaseBoxComponent<T extends ElementType = 'div'> = (<T extends ElementType = 'div'>(props: BaseBoxProps<T>) => ReactElement | null) & FC<BaseBoxProps<T>>;
74
+ /**
75
+ * __Box__
76
+ *
77
+ * Box is a primitive component that has the design decisions of the Atlassian Design System baked in.
78
+ * Renders a `div` by default.
79
+ *
80
+ * @internal
81
+ */
82
+ export declare const BaseBox: BaseBoxComponent;
83
+ export default BaseBox;
@@ -24,7 +24,7 @@ export interface StackProps<T extends ElementType = 'div'> {
24
24
  /**
25
25
  * Represents the space between each child.
26
26
  */
27
- space?: Space;
27
+ space?: Gap;
28
28
  /**
29
29
  * A unique string that appears as data attribute data-testid in the rendered code, serving as a hook for automated tests.
30
30
  */
@@ -44,29 +44,31 @@ export declare type Spread = 'space-between';
44
44
  export declare type Grow = 'hug' | 'fill';
45
45
  /**
46
46
  * THIS SECTION WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
47
- * @codegen <<SignedSource::41d7002b7f69aa44d0d8598e07a1afc6>>
47
+ * @codegen <<SignedSource::4eb2c996d6ce5791acad51e2b226635f>>
48
48
  * @codegenId spacing
49
49
  * @codegenCommand yarn codegen-styles
50
- * @codegenParams ["space"]
50
+ * @codegenParams ["stackSpace"]
51
51
  * @codegenDependency ../../../tokens/src/artifacts/tokens-raw/atlassian-spacing.tsx <<SignedSource::167d3b69b159ae33e74d4ea5ab7eade6>>
52
52
  */
53
- declare const spaceMap: {
54
- readonly '0': import("@emotion/react").SerializedStyles;
55
- readonly '025': import("@emotion/react").SerializedStyles;
56
- readonly '050': import("@emotion/react").SerializedStyles;
57
- readonly '075': import("@emotion/react").SerializedStyles;
58
- readonly '100': import("@emotion/react").SerializedStyles;
59
- readonly '150': import("@emotion/react").SerializedStyles;
60
- readonly '200': import("@emotion/react").SerializedStyles;
61
- readonly '250': import("@emotion/react").SerializedStyles;
62
- readonly '300': import("@emotion/react").SerializedStyles;
63
- readonly '400': import("@emotion/react").SerializedStyles;
64
- readonly '500': import("@emotion/react").SerializedStyles;
65
- readonly '600': import("@emotion/react").SerializedStyles;
66
- readonly '800': import("@emotion/react").SerializedStyles;
67
- readonly '1000': import("@emotion/react").SerializedStyles;
53
+ declare const stackSpaceMap: {
54
+ [k: string]: {
55
+ readonly '0': import("@emotion/react").SerializedStyles;
56
+ readonly '025': import("@emotion/react").SerializedStyles;
57
+ readonly '050': import("@emotion/react").SerializedStyles;
58
+ readonly '075': import("@emotion/react").SerializedStyles;
59
+ readonly '100': import("@emotion/react").SerializedStyles;
60
+ readonly '150': import("@emotion/react").SerializedStyles;
61
+ readonly '200': import("@emotion/react").SerializedStyles;
62
+ readonly '250': import("@emotion/react").SerializedStyles;
63
+ readonly '300': import("@emotion/react").SerializedStyles;
64
+ readonly '400': import("@emotion/react").SerializedStyles;
65
+ readonly '500': import("@emotion/react").SerializedStyles;
66
+ readonly '600': import("@emotion/react").SerializedStyles;
67
+ readonly '800': import("@emotion/react").SerializedStyles;
68
+ readonly '1000': import("@emotion/react").SerializedStyles;
69
+ };
68
70
  };
69
- export declare type Space = keyof typeof spaceMap;
71
+ export declare type Gap = keyof typeof stackSpaceMap.gap;
70
72
  /**
71
73
  * __Stack__
72
74
  *
@@ -1,6 +1,5 @@
1
1
  import type { CSSProperties } from 'react';
2
2
  import { type BoxXCSS } from '../internal/xcss';
3
- import type { BorderWidth, Display, Padding, PaddingBlock, PaddingBlockEnd, PaddingBlockStart, PaddingInline, PaddingInlineEnd, PaddingInlineStart } from './internal/base-box.partial';
4
3
  export declare type BasePrimitiveProps = {
5
4
  /**
6
5
  * A unique string that appears as data attribute `data-testid` in the rendered code, serving as a hook for automated tests.
@@ -12,53 +11,8 @@ export declare type BasePrimitiveProps = {
12
11
  style?: CSSProperties;
13
12
  };
14
13
  export declare type PublicBoxPropsBase = {
15
- /**
16
- * Defines border width.
17
- */
18
- borderWidth?: BorderWidth;
19
- /**
20
- * Defines display type and layout. Defaults to `block`.
21
- */
22
- display?: Display;
23
- /**
24
- * Tokens representing CSS shorthand for `paddingBlock` and `paddingInline` together.
25
- *
26
- * @see paddingBlock
27
- * @see paddingInline
28
- */
29
- padding?: Padding;
30
- /**
31
- * Tokens representing CSS shorthand `paddingBlock`.
32
- *
33
- * @see paddingBlockStart
34
- * @see paddingBlockEnd
35
- */
36
- paddingBlock?: PaddingBlock;
37
- /**
38
- * Tokens representing CSS `paddingBlockStart`.
39
- */
40
- paddingBlockStart?: PaddingBlockStart;
41
- /**
42
- * Tokens representing CSS `paddingBlockEnd`.
43
- */
44
- paddingBlockEnd?: PaddingBlockEnd;
45
- /**
46
- * Tokens representing CSS shorthand `paddingInline`.
47
- *
48
- * @see paddingInlineStart
49
- * @see paddingInlineEnd
50
- */
51
- paddingInline?: PaddingInline;
52
- /**
53
- * Tokens representing CSS `paddingInlineStart`.
54
- */
55
- paddingInlineStart?: PaddingInlineStart;
56
- /**
57
- * Tokens representing CSS `paddingInlineEnd`.
58
- */
59
- paddingInlineEnd?: PaddingInlineEnd;
60
14
  /**
61
15
  * Safe subset of styles that can be applied as a classname.
62
16
  */
63
- xcss?: BoxXCSS;
17
+ xcss?: BoxXCSS | Array<BoxXCSS | false | undefined>;
64
18
  };