@atlaskit/primitives 0.2.1 → 0.2.2

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 (35) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/components/inline.partial.js +46 -22
  3. package/dist/cjs/components/internal/base-box.partial.js +99 -78
  4. package/dist/cjs/components/internal/types.js +8 -0
  5. package/dist/cjs/components/internal/utils.js +16 -0
  6. package/dist/cjs/components/stack.partial.js +46 -22
  7. package/dist/cjs/constants.js +13 -0
  8. package/dist/cjs/version.json +1 -1
  9. package/dist/es2019/components/inline.partial.js +18 -18
  10. package/dist/es2019/components/internal/base-box.partial.js +75 -70
  11. package/dist/es2019/components/internal/types.js +1 -0
  12. package/dist/es2019/components/internal/utils.js +2 -0
  13. package/dist/es2019/components/stack.partial.js +18 -18
  14. package/dist/es2019/constants.js +3 -1
  15. package/dist/es2019/version.json +1 -1
  16. package/dist/esm/components/inline.partial.js +46 -21
  17. package/dist/esm/components/internal/base-box.partial.js +100 -79
  18. package/dist/esm/components/internal/types.js +1 -0
  19. package/dist/esm/components/internal/utils.js +7 -0
  20. package/dist/esm/components/stack.partial.js +46 -21
  21. package/dist/esm/constants.js +3 -1
  22. package/dist/esm/version.json +1 -1
  23. package/dist/types/components/box.d.ts +3 -5
  24. package/dist/types/components/inline.partial.d.ts +16 -18
  25. package/dist/types/components/internal/base-box.partial.d.ts +49 -50
  26. package/dist/types/components/internal/types.d.ts +6 -0
  27. package/dist/types/components/internal/utils.d.ts +3 -0
  28. package/dist/types/components/stack.partial.d.ts +16 -18
  29. package/dist/types/components/types.d.ts +49 -0
  30. package/dist/types/constants.d.ts +2 -0
  31. package/package.json +4 -2
  32. package/report.api.md +111 -78
  33. package/scripts/spacing-codegen-template.tsx +29 -24
  34. package/scripts/utils.tsx +4 -1
  35. package/tmp/api-report-tmp.d.ts +88 -77
@@ -2,7 +2,52 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  /** @jsx jsx */
3
3
  import { forwardRef } from 'react';
4
4
  import { css, jsx } from '@emotion/react';
5
- import { LAYERS } from '../../constants';
5
+ import invariant from 'tiny-invariant';
6
+ import { BREAKPOINTS_CONFIG, BREAKPOINTS_LIST, LAYERS } from '../../constants';
7
+ import { BOX_RESPONSIVE_PROPS } from './types';
8
+ import { isResponsiveStyleProp, isStaticStyleProp } from './utils';
9
+ const responsiveRules = BOX_RESPONSIVE_PROPS.reduce((mapping, cssProperty) => {
10
+ return Object.assign(mapping, {
11
+ [cssProperty]: BREAKPOINTS_LIST.reduce((configs, breakpoint) => {
12
+ const config = BREAKPOINTS_CONFIG[breakpoint];
13
+ return Object.assign(configs, {
14
+ [breakpoint]: css({
15
+ // eslint-disable-next-line @repo/internal/styles/no-nested-styles
16
+ [`@media (min-width: ${config.min}px)`]: {
17
+ [cssProperty]: `var(--ds-box-responsive-${cssProperty}-${breakpoint})`
18
+ }
19
+ })
20
+ });
21
+ }, {
22
+ static: css({
23
+ [cssProperty]: `var(--ds-box-static-${cssProperty})`
24
+ })
25
+ })
26
+ });
27
+ }, {});
28
+ const getResponsiveVars = (propertyName, propertyValue, mapping) => {
29
+ if (isResponsiveStyleProp(propertyValue)) {
30
+ return Object.keys(propertyValue).reduce((vars, breakpoint) => ({
31
+ ...vars,
32
+ [`--ds-box-responsive-${propertyName}-${breakpoint}`]: mapping[propertyValue[breakpoint]]
33
+ }), {});
34
+ } else if (isStaticStyleProp(propertyValue)) {
35
+ return {
36
+ [`--ds-box-static-${propertyName}`]: mapping[propertyValue]
37
+ };
38
+ }
39
+ };
40
+ const getResponsiveStyles = (propertyName, propertyValue) => {
41
+ invariant(typeof responsiveRules[propertyName] !== 'undefined', `Responsive rules for "${propertyName}" have not been statically defined.`);
42
+ if (isResponsiveStyleProp(propertyValue)) {
43
+ return Object.keys(propertyValue).map(responsiveProp => responsiveRules[propertyName][responsiveProp]);
44
+ } else if (isStaticStyleProp(propertyValue)) {
45
+ return responsiveRules[propertyName].static;
46
+ }
47
+ };
48
+
49
+ // Without this type annotation on Box we don't get autocomplete for props due to forwardRef types
50
+
6
51
  /**
7
52
  * __Box__
8
53
  *
@@ -39,20 +84,21 @@ export const BaseBox = /*#__PURE__*/forwardRef(({
39
84
  paddingInlineEnd,
40
85
  height,
41
86
  width,
42
- display = 'block',
87
+ display = displayMap.block,
43
88
  position = 'static',
44
89
  UNSAFE_style,
45
90
  testId,
46
91
  ...htmlAttributes
47
92
  }, ref) => {
48
93
  const Component = as || 'div';
94
+ const inlineStyles = Object.assign({}, UNSAFE_style, getResponsiveVars('borderWidth', borderWidth, borderWidthMap), getResponsiveVars('display', display, displayMap), getResponsiveVars('padding', padding, paddingMap), getResponsiveVars('paddingBlock', paddingBlock, paddingMap), getResponsiveVars('paddingBlockStart', paddingBlockStart, paddingMap), getResponsiveVars('paddingBlockEnd', paddingBlockEnd, paddingMap), getResponsiveVars('paddingInline', paddingInline, paddingMap), getResponsiveVars('paddingInlineStart', paddingInlineStart, paddingMap), getResponsiveVars('paddingInlineEnd', paddingInlineEnd, paddingMap));
49
95
  const node = jsx(Component, _extends({
50
- style: UNSAFE_style,
96
+ style: inlineStyles,
51
97
  ref: ref
52
98
  // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
53
99
  }, htmlAttributes, {
54
100
  className: className,
55
- css: [baseStyles, display && displayMap[display], backgroundColor && backgroundColorMap[backgroundColor], color && textColorMap[color], flex && flexMap[flex], flexGrow && flexGrowMap[flexGrow], flexShrink && flexShrinkMap[flexShrink], alignSelf && alignSelfMap[alignSelf], overflow && overflowMap[overflow], overflowInline && overflowInlineMap[overflowInline], overflowBlock && overflowBlockMap[overflowBlock], padding && paddingMap.padding[padding], position && positionMap[position], paddingBlock && paddingMap.paddingBlock[paddingBlock], paddingBlockStart && paddingMap.paddingBlockStart[paddingBlockStart], paddingBlockEnd && paddingMap.paddingBlockEnd[paddingBlockEnd], paddingInline && paddingMap.paddingInline[paddingInline], paddingInlineStart && paddingMap.paddingInlineStart[paddingInlineStart], paddingInlineEnd && paddingMap.paddingInlineEnd[paddingInlineEnd], borderColor && borderColorMap[borderColor], borderStyle && borderStyleMap[borderStyle], borderWidth && borderWidthMap[borderWidth], borderRadius && borderRadiusMap[borderRadius], shadow && shadowMap[shadow], layer && layerMap[layer], overflow && overflowMap[overflow], width && widthMap[width], height && heightMap[height]],
101
+ css: [baseStyles, ...[getResponsiveStyles('borderWidth', borderWidth), getResponsiveStyles('display', display), getResponsiveStyles('padding', padding), getResponsiveStyles('paddingBlock', paddingBlock), getResponsiveStyles('paddingBlockStart', paddingBlockStart), getResponsiveStyles('paddingBlockEnd', paddingBlockEnd), getResponsiveStyles('paddingInline', paddingInline), getResponsiveStyles('paddingInlineStart', paddingInlineStart), getResponsiveStyles('paddingInlineEnd', paddingInlineEnd)], backgroundColor && backgroundColorMap[backgroundColor], borderColor && borderColorMap[borderColor], color && textColorMap[color], flex && flexMap[flex], flexGrow && flexGrowMap[flexGrow], flexShrink && flexShrinkMap[flexShrink], alignSelf && alignSelfMap[alignSelf], overflow && overflowMap[overflow], overflowInline && overflowInlineMap[overflowInline], overflowBlock && overflowBlockMap[overflowBlock], position && positionMap[position], borderStyle && borderStyleMap[borderStyle], borderRadius && borderRadiusMap[borderRadius], shadow && shadowMap[shadow], layer && layerMap[layer], overflow && overflowMap[overflow], width && widthMap[width], height && heightMap[height]],
56
102
  "data-testid": testId
57
103
  }), children);
58
104
  return node;
@@ -71,12 +117,9 @@ const borderStyleMap = {
71
117
  })
72
118
  };
73
119
  const borderWidthMap = {
74
- 'size.050': css({
75
- borderWidth: "var(--ds-width-050, 1px)"
76
- }),
77
- 'size.100': css({
78
- borderWidth: "var(--ds-width-100, 2px)"
79
- })
120
+ 'size.0': "var(--ds-width-0, 0)",
121
+ 'size.050': "var(--ds-width-050, 1px)",
122
+ 'size.100': "var(--ds-width-100, 2px)"
80
123
  };
81
124
  const borderRadiusMap = {
82
125
  'radius.100': css({
@@ -134,21 +177,11 @@ const alignSelfMap = {
134
177
  })
135
178
  };
136
179
  const displayMap = {
137
- block: css({
138
- display: 'block'
139
- }),
140
- inline: css({
141
- display: 'inline'
142
- }),
143
- flex: css({
144
- display: 'flex'
145
- }),
146
- 'inline-flex': css({
147
- display: 'inline-flex'
148
- }),
149
- 'inline-block': css({
150
- display: 'inline-block'
151
- })
180
+ block: 'block',
181
+ inline: 'inline',
182
+ flex: 'flex',
183
+ 'inline-flex': 'inline-flex',
184
+ 'inline-block': 'inline-block'
152
185
  };
153
186
  const positionMap = {
154
187
  absolute: css({
@@ -363,56 +396,28 @@ const maxHeightMap = {
363
396
 
364
397
  /**
365
398
  * THIS SECTION WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
366
- * @codegen <<SignedSource::6da0ceaa2c227230e3a93bc724ff8648>>
399
+ * @codegen <<SignedSource::84fd352b0e6509d380a0dcf8ad023ca2>>
367
400
  * @codegenId spacing
368
401
  * @codegenCommand yarn codegen-styles
369
402
  * @codegenParams ["padding"]
370
403
  * @codegenDependency ../../../../tokens/src/artifacts/tokens-raw/atlassian-spacing.tsx <<SignedSource::167d3b69b159ae33e74d4ea5ab7eade6>>
371
404
  */
372
- const paddingMap = Object.fromEntries(['padding', 'paddingBlock', 'paddingBlockStart', 'paddingBlockEnd', 'paddingInline', 'paddingInlineStart', 'paddingInlineEnd'].map(property => [property, {
373
- 'space.0': css({
374
- [property]: "var(--ds-space-0, 0px)"
375
- }),
376
- 'space.025': css({
377
- [property]: "var(--ds-space-025, 2px)"
378
- }),
379
- 'space.050': css({
380
- [property]: "var(--ds-space-050, 4px)"
381
- }),
382
- 'space.075': css({
383
- [property]: "var(--ds-space-075, 6px)"
384
- }),
385
- 'space.100': css({
386
- [property]: "var(--ds-space-100, 8px)"
387
- }),
388
- 'space.150': css({
389
- [property]: "var(--ds-space-150, 12px)"
390
- }),
391
- 'space.200': css({
392
- [property]: "var(--ds-space-200, 16px)"
393
- }),
394
- 'space.250': css({
395
- [property]: "var(--ds-space-250, 20px)"
396
- }),
397
- 'space.300': css({
398
- [property]: "var(--ds-space-300, 24px)"
399
- }),
400
- 'space.400': css({
401
- [property]: "var(--ds-space-400, 32px)"
402
- }),
403
- 'space.500': css({
404
- [property]: "var(--ds-space-500, 40px)"
405
- }),
406
- 'space.600': css({
407
- [property]: "var(--ds-space-600, 48px)"
408
- }),
409
- 'space.800': css({
410
- [property]: "var(--ds-space-800, 64px)"
411
- }),
412
- 'space.1000': css({
413
- [property]: "var(--ds-space-1000, 80px)"
414
- })
415
- }]));
405
+ const paddingMap = {
406
+ 'space.0': "var(--ds-space-0, 0px)",
407
+ 'space.025': "var(--ds-space-025, 2px)",
408
+ 'space.050': "var(--ds-space-050, 4px)",
409
+ 'space.075': "var(--ds-space-075, 6px)",
410
+ 'space.100': "var(--ds-space-100, 8px)",
411
+ 'space.150': "var(--ds-space-150, 12px)",
412
+ 'space.200': "var(--ds-space-200, 16px)",
413
+ 'space.250': "var(--ds-space-250, 20px)",
414
+ 'space.300': "var(--ds-space-300, 24px)",
415
+ 'space.400': "var(--ds-space-400, 32px)",
416
+ 'space.500': "var(--ds-space-500, 40px)",
417
+ 'space.600': "var(--ds-space-600, 48px)",
418
+ 'space.800': "var(--ds-space-800, 64px)",
419
+ 'space.1000': "var(--ds-space-1000, 80px)"
420
+ };
416
421
  /**
417
422
  * @codegenEnd
418
423
  */
@@ -0,0 +1 @@
1
+ export const BOX_RESPONSIVE_PROPS = ['borderWidth', 'display', 'padding', 'paddingBlock', 'paddingBlockStart', 'paddingBlockEnd', 'paddingInline', 'paddingInlineStart', 'paddingInlineEnd'];
@@ -0,0 +1,2 @@
1
+ export const isResponsiveStyleProp = propertyValue => typeof propertyValue === 'object';
2
+ export const isStaticStyleProp = propertyValue => typeof propertyValue === 'string';
@@ -37,56 +37,56 @@ const flexGrowMap = {
37
37
 
38
38
  /**
39
39
  * THIS SECTION WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
40
- * @codegen <<SignedSource::0e30ffcc6aef7932f9d8ff2543327236>>
40
+ * @codegen <<SignedSource::41d7002b7f69aa44d0d8598e07a1afc6>>
41
41
  * @codegenId spacing
42
42
  * @codegenCommand yarn codegen-styles
43
43
  * @codegenParams ["space"]
44
44
  * @codegenDependency ../../../tokens/src/artifacts/tokens-raw/atlassian-spacing.tsx <<SignedSource::167d3b69b159ae33e74d4ea5ab7eade6>>
45
45
  */
46
- const spaceMap = Object.fromEntries(['gap'].map(property => [property, {
46
+ const spaceMap = {
47
47
  '0': css({
48
- [property]: "var(--ds-space-0, 0px)"
48
+ gap: "var(--ds-space-0, 0px)"
49
49
  }),
50
50
  '025': css({
51
- [property]: "var(--ds-space-025, 2px)"
51
+ gap: "var(--ds-space-025, 2px)"
52
52
  }),
53
53
  '050': css({
54
- [property]: "var(--ds-space-050, 4px)"
54
+ gap: "var(--ds-space-050, 4px)"
55
55
  }),
56
56
  '075': css({
57
- [property]: "var(--ds-space-075, 6px)"
57
+ gap: "var(--ds-space-075, 6px)"
58
58
  }),
59
59
  '100': css({
60
- [property]: "var(--ds-space-100, 8px)"
60
+ gap: "var(--ds-space-100, 8px)"
61
61
  }),
62
62
  '150': css({
63
- [property]: "var(--ds-space-150, 12px)"
63
+ gap: "var(--ds-space-150, 12px)"
64
64
  }),
65
65
  '200': css({
66
- [property]: "var(--ds-space-200, 16px)"
66
+ gap: "var(--ds-space-200, 16px)"
67
67
  }),
68
68
  '250': css({
69
- [property]: "var(--ds-space-250, 20px)"
69
+ gap: "var(--ds-space-250, 20px)"
70
70
  }),
71
71
  '300': css({
72
- [property]: "var(--ds-space-300, 24px)"
72
+ gap: "var(--ds-space-300, 24px)"
73
73
  }),
74
74
  '400': css({
75
- [property]: "var(--ds-space-400, 32px)"
75
+ gap: "var(--ds-space-400, 32px)"
76
76
  }),
77
77
  '500': css({
78
- [property]: "var(--ds-space-500, 40px)"
78
+ gap: "var(--ds-space-500, 40px)"
79
79
  }),
80
80
  '600': css({
81
- [property]: "var(--ds-space-600, 48px)"
81
+ gap: "var(--ds-space-600, 48px)"
82
82
  }),
83
83
  '800': css({
84
- [property]: "var(--ds-space-800, 64px)"
84
+ gap: "var(--ds-space-800, 64px)"
85
85
  }),
86
86
  '1000': css({
87
- [property]: "var(--ds-space-1000, 80px)"
87
+ gap: "var(--ds-space-1000, 80px)"
88
88
  })
89
- }]));
89
+ };
90
90
  /**
91
91
  * @codegenEnd
92
92
  */
@@ -122,7 +122,7 @@ const Stack = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
122
122
  }, ref) => {
123
123
  const justifyContent = spread || alignBlock;
124
124
  return jsx("div", {
125
- css: [baseStyles, space && spaceMap.gap[space], alignItems && alignItemsMap[alignItems], grow && flexGrowMap[grow], justifyContent && justifyContentMap[justifyContent]],
125
+ css: [baseStyles, space && spaceMap[space], alignItems && alignItemsMap[alignItems], grow && flexGrowMap[grow], justifyContent && justifyContentMap[justifyContent]],
126
126
  "data-testid": testId,
127
127
  ref: ref
128
128
  }, children);
@@ -1,3 +1,4 @@
1
+ import { UNSAFE_Breakpoint as Breakpoint, UNSAFE_BreakpointConfig as BreakpointConfig, UNSAFE_BREAKPOINTS_CONFIG as BREAKPOINTS_CONFIG, UNSAFE_BREAKPOINTS_LIST as BREAKPOINTS_LIST } from '@atlaskit/ds-explorations';
1
2
  export const LAYERS = {
2
3
  card: 100,
3
4
  navigation: 200,
@@ -8,4 +9,5 @@ export const LAYERS = {
8
9
  flag: 600,
9
10
  spotlight: 700,
10
11
  tooltip: 800
11
- };
12
+ };
13
+ export { BREAKPOINTS_CONFIG, BREAKPOINTS_LIST };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/primitives",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "sideEffects": false
5
5
  }
@@ -1,4 +1,3 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
1
  /** @jsx jsx */
3
2
  import { Children, forwardRef, Fragment, memo } from 'react';
4
3
  import { css, jsx } from '@emotion/react';
@@ -44,30 +43,56 @@ var flexWrapStyles = css({
44
43
 
45
44
  /**
46
45
  * THIS SECTION WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
47
- * @codegen <<SignedSource::0e30ffcc6aef7932f9d8ff2543327236>>
46
+ * @codegen <<SignedSource::41d7002b7f69aa44d0d8598e07a1afc6>>
48
47
  * @codegenId spacing
49
48
  * @codegenCommand yarn codegen-styles
50
49
  * @codegenParams ["space"]
51
50
  * @codegenDependency ../../../tokens/src/artifacts/tokens-raw/atlassian-spacing.tsx <<SignedSource::167d3b69b159ae33e74d4ea5ab7eade6>>
52
51
  */
53
- var spaceMap = Object.fromEntries(['gap'].map(function (property) {
54
- return [property, {
55
- '0': css(_defineProperty({}, property, "var(--ds-space-0, 0px)")),
56
- '025': css(_defineProperty({}, property, "var(--ds-space-025, 2px)")),
57
- '050': css(_defineProperty({}, property, "var(--ds-space-050, 4px)")),
58
- '075': css(_defineProperty({}, property, "var(--ds-space-075, 6px)")),
59
- '100': css(_defineProperty({}, property, "var(--ds-space-100, 8px)")),
60
- '150': css(_defineProperty({}, property, "var(--ds-space-150, 12px)")),
61
- '200': css(_defineProperty({}, property, "var(--ds-space-200, 16px)")),
62
- '250': css(_defineProperty({}, property, "var(--ds-space-250, 20px)")),
63
- '300': css(_defineProperty({}, property, "var(--ds-space-300, 24px)")),
64
- '400': css(_defineProperty({}, property, "var(--ds-space-400, 32px)")),
65
- '500': css(_defineProperty({}, property, "var(--ds-space-500, 40px)")),
66
- '600': css(_defineProperty({}, property, "var(--ds-space-600, 48px)")),
67
- '800': css(_defineProperty({}, property, "var(--ds-space-800, 64px)")),
68
- '1000': css(_defineProperty({}, property, "var(--ds-space-1000, 80px)"))
69
- }];
70
- }));
52
+ var spaceMap = {
53
+ '0': css({
54
+ gap: "var(--ds-space-0, 0px)"
55
+ }),
56
+ '025': css({
57
+ gap: "var(--ds-space-025, 2px)"
58
+ }),
59
+ '050': css({
60
+ gap: "var(--ds-space-050, 4px)"
61
+ }),
62
+ '075': css({
63
+ gap: "var(--ds-space-075, 6px)"
64
+ }),
65
+ '100': css({
66
+ gap: "var(--ds-space-100, 8px)"
67
+ }),
68
+ '150': css({
69
+ gap: "var(--ds-space-150, 12px)"
70
+ }),
71
+ '200': css({
72
+ gap: "var(--ds-space-200, 16px)"
73
+ }),
74
+ '250': css({
75
+ gap: "var(--ds-space-250, 20px)"
76
+ }),
77
+ '300': css({
78
+ gap: "var(--ds-space-300, 24px)"
79
+ }),
80
+ '400': css({
81
+ gap: "var(--ds-space-400, 32px)"
82
+ }),
83
+ '500': css({
84
+ gap: "var(--ds-space-500, 40px)"
85
+ }),
86
+ '600': css({
87
+ gap: "var(--ds-space-600, 48px)"
88
+ }),
89
+ '800': css({
90
+ gap: "var(--ds-space-800, 64px)"
91
+ }),
92
+ '1000': css({
93
+ gap: "var(--ds-space-1000, 80px)"
94
+ })
95
+ };
71
96
  /**
72
97
  * @codegenEnd
73
98
  */
@@ -125,7 +150,7 @@ var Inline = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_ref2, ref) {
125
150
  }) : rawChildren;
126
151
  var justifyContent = spread || alignInline;
127
152
  return jsx("div", {
128
- css: [baseStyles, space && spaceMap.gap[space], justifyContent && justifyContentMap[justifyContent], grow && flexGrowMap[grow], alignItems && alignItemsMap[alignItems], shouldWrap && flexWrapStyles],
153
+ css: [baseStyles, space && spaceMap[space], justifyContent && justifyContentMap[justifyContent], grow && flexGrowMap[grow], alignItems && alignItemsMap[alignItems], shouldWrap && flexWrapStyles],
129
154
  "data-testid": testId,
130
155
  ref: ref
131
156
  }, children);
@@ -1,11 +1,46 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
1
  import _extends from "@babel/runtime/helpers/extends";
3
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
4
  var _excluded = ["as", "className", "children", "color", "backgroundColor", "shadow", "borderStyle", "borderWidth", "borderRadius", "borderColor", "layer", "flex", "flexGrow", "flexShrink", "alignSelf", "overflow", "overflowInline", "overflowBlock", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd", "height", "width", "display", "position", "UNSAFE_style", "testId"];
5
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
5
7
  /** @jsx jsx */
6
8
  import { forwardRef } from 'react';
7
9
  import { css, jsx } from '@emotion/react';
8
- import { LAYERS } from '../../constants';
10
+ import invariant from 'tiny-invariant';
11
+ import { BREAKPOINTS_CONFIG, BREAKPOINTS_LIST, LAYERS } from '../../constants';
12
+ import { BOX_RESPONSIVE_PROPS } from './types';
13
+ import { isResponsiveStyleProp, isStaticStyleProp } from './utils';
14
+ var responsiveRules = BOX_RESPONSIVE_PROPS.reduce(function (mapping, cssProperty) {
15
+ return Object.assign(mapping, _defineProperty({}, cssProperty, BREAKPOINTS_LIST.reduce(function (configs, breakpoint) {
16
+ var config = BREAKPOINTS_CONFIG[breakpoint];
17
+ return Object.assign(configs, _defineProperty({}, breakpoint, css(_defineProperty({}, "@media (min-width: ".concat(config.min, "px)"), _defineProperty({}, cssProperty, "var(--ds-box-responsive-".concat(cssProperty, "-").concat(breakpoint, ")"))))));
18
+ }, {
19
+ static: css(_defineProperty({}, cssProperty, "var(--ds-box-static-".concat(cssProperty, ")")))
20
+ })));
21
+ }, {});
22
+ var getResponsiveVars = function getResponsiveVars(propertyName, propertyValue, mapping) {
23
+ if (isResponsiveStyleProp(propertyValue)) {
24
+ return Object.keys(propertyValue).reduce(function (vars, breakpoint) {
25
+ return _objectSpread(_objectSpread({}, vars), {}, _defineProperty({}, "--ds-box-responsive-".concat(propertyName, "-").concat(breakpoint), mapping[propertyValue[breakpoint]]));
26
+ }, {});
27
+ } else if (isStaticStyleProp(propertyValue)) {
28
+ return _defineProperty({}, "--ds-box-static-".concat(propertyName), mapping[propertyValue]);
29
+ }
30
+ };
31
+ var getResponsiveStyles = function getResponsiveStyles(propertyName, propertyValue) {
32
+ invariant(typeof responsiveRules[propertyName] !== 'undefined', "Responsive rules for \"".concat(propertyName, "\" have not been statically defined."));
33
+ if (isResponsiveStyleProp(propertyValue)) {
34
+ return Object.keys(propertyValue).map(function (responsiveProp) {
35
+ return responsiveRules[propertyName][responsiveProp];
36
+ });
37
+ } else if (isStaticStyleProp(propertyValue)) {
38
+ return responsiveRules[propertyName].static;
39
+ }
40
+ };
41
+
42
+ // Without this type annotation on Box we don't get autocomplete for props due to forwardRef types
43
+
9
44
  /**
10
45
  * __Box__
11
46
  *
@@ -14,49 +49,50 @@ import { LAYERS } from '../../constants';
14
49
  *
15
50
  * @internal
16
51
  */
17
- export var BaseBox = /*#__PURE__*/forwardRef(function (_ref, ref) {
18
- var as = _ref.as,
19
- className = _ref.className,
20
- children = _ref.children,
21
- color = _ref.color,
22
- backgroundColor = _ref.backgroundColor,
23
- shadow = _ref.shadow,
24
- borderStyle = _ref.borderStyle,
25
- borderWidth = _ref.borderWidth,
26
- borderRadius = _ref.borderRadius,
27
- borderColor = _ref.borderColor,
28
- layer = _ref.layer,
29
- flex = _ref.flex,
30
- flexGrow = _ref.flexGrow,
31
- flexShrink = _ref.flexShrink,
32
- alignSelf = _ref.alignSelf,
33
- overflow = _ref.overflow,
34
- overflowInline = _ref.overflowInline,
35
- overflowBlock = _ref.overflowBlock,
36
- padding = _ref.padding,
37
- paddingBlock = _ref.paddingBlock,
38
- paddingBlockStart = _ref.paddingBlockStart,
39
- paddingBlockEnd = _ref.paddingBlockEnd,
40
- paddingInline = _ref.paddingInline,
41
- paddingInlineStart = _ref.paddingInlineStart,
42
- paddingInlineEnd = _ref.paddingInlineEnd,
43
- height = _ref.height,
44
- width = _ref.width,
45
- _ref$display = _ref.display,
46
- display = _ref$display === void 0 ? 'block' : _ref$display,
47
- _ref$position = _ref.position,
48
- position = _ref$position === void 0 ? 'static' : _ref$position,
49
- UNSAFE_style = _ref.UNSAFE_style,
50
- testId = _ref.testId,
51
- htmlAttributes = _objectWithoutProperties(_ref, _excluded);
52
+ export var BaseBox = /*#__PURE__*/forwardRef(function (_ref2, ref) {
53
+ var as = _ref2.as,
54
+ className = _ref2.className,
55
+ children = _ref2.children,
56
+ color = _ref2.color,
57
+ backgroundColor = _ref2.backgroundColor,
58
+ shadow = _ref2.shadow,
59
+ borderStyle = _ref2.borderStyle,
60
+ borderWidth = _ref2.borderWidth,
61
+ borderRadius = _ref2.borderRadius,
62
+ borderColor = _ref2.borderColor,
63
+ layer = _ref2.layer,
64
+ flex = _ref2.flex,
65
+ flexGrow = _ref2.flexGrow,
66
+ flexShrink = _ref2.flexShrink,
67
+ alignSelf = _ref2.alignSelf,
68
+ overflow = _ref2.overflow,
69
+ overflowInline = _ref2.overflowInline,
70
+ overflowBlock = _ref2.overflowBlock,
71
+ padding = _ref2.padding,
72
+ paddingBlock = _ref2.paddingBlock,
73
+ paddingBlockStart = _ref2.paddingBlockStart,
74
+ paddingBlockEnd = _ref2.paddingBlockEnd,
75
+ paddingInline = _ref2.paddingInline,
76
+ paddingInlineStart = _ref2.paddingInlineStart,
77
+ paddingInlineEnd = _ref2.paddingInlineEnd,
78
+ height = _ref2.height,
79
+ width = _ref2.width,
80
+ _ref2$display = _ref2.display,
81
+ display = _ref2$display === void 0 ? displayMap.block : _ref2$display,
82
+ _ref2$position = _ref2.position,
83
+ position = _ref2$position === void 0 ? 'static' : _ref2$position,
84
+ UNSAFE_style = _ref2.UNSAFE_style,
85
+ testId = _ref2.testId,
86
+ htmlAttributes = _objectWithoutProperties(_ref2, _excluded);
52
87
  var Component = as || 'div';
88
+ var inlineStyles = Object.assign({}, UNSAFE_style, getResponsiveVars('borderWidth', borderWidth, borderWidthMap), getResponsiveVars('display', display, displayMap), getResponsiveVars('padding', padding, paddingMap), getResponsiveVars('paddingBlock', paddingBlock, paddingMap), getResponsiveVars('paddingBlockStart', paddingBlockStart, paddingMap), getResponsiveVars('paddingBlockEnd', paddingBlockEnd, paddingMap), getResponsiveVars('paddingInline', paddingInline, paddingMap), getResponsiveVars('paddingInlineStart', paddingInlineStart, paddingMap), getResponsiveVars('paddingInlineEnd', paddingInlineEnd, paddingMap));
53
89
  var node = jsx(Component, _extends({
54
- style: UNSAFE_style,
90
+ style: inlineStyles,
55
91
  ref: ref
56
92
  // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
57
93
  }, htmlAttributes, {
58
94
  className: className,
59
- css: [baseStyles, display && displayMap[display], backgroundColor && backgroundColorMap[backgroundColor], color && textColorMap[color], flex && flexMap[flex], flexGrow && flexGrowMap[flexGrow], flexShrink && flexShrinkMap[flexShrink], alignSelf && alignSelfMap[alignSelf], overflow && overflowMap[overflow], overflowInline && overflowInlineMap[overflowInline], overflowBlock && overflowBlockMap[overflowBlock], padding && paddingMap.padding[padding], position && positionMap[position], paddingBlock && paddingMap.paddingBlock[paddingBlock], paddingBlockStart && paddingMap.paddingBlockStart[paddingBlockStart], paddingBlockEnd && paddingMap.paddingBlockEnd[paddingBlockEnd], paddingInline && paddingMap.paddingInline[paddingInline], paddingInlineStart && paddingMap.paddingInlineStart[paddingInlineStart], paddingInlineEnd && paddingMap.paddingInlineEnd[paddingInlineEnd], borderColor && borderColorMap[borderColor], borderStyle && borderStyleMap[borderStyle], borderWidth && borderWidthMap[borderWidth], borderRadius && borderRadiusMap[borderRadius], shadow && shadowMap[shadow], layer && layerMap[layer], overflow && overflowMap[overflow], width && widthMap[width], height && heightMap[height]],
95
+ css: [baseStyles].concat([getResponsiveStyles('borderWidth', borderWidth), getResponsiveStyles('display', display), getResponsiveStyles('padding', padding), getResponsiveStyles('paddingBlock', paddingBlock), getResponsiveStyles('paddingBlockStart', paddingBlockStart), getResponsiveStyles('paddingBlockEnd', paddingBlockEnd), getResponsiveStyles('paddingInline', paddingInline), getResponsiveStyles('paddingInlineStart', paddingInlineStart), getResponsiveStyles('paddingInlineEnd', paddingInlineEnd)], [backgroundColor && backgroundColorMap[backgroundColor], borderColor && borderColorMap[borderColor], color && textColorMap[color], flex && flexMap[flex], flexGrow && flexGrowMap[flexGrow], flexShrink && flexShrinkMap[flexShrink], alignSelf && alignSelfMap[alignSelf], overflow && overflowMap[overflow], overflowInline && overflowInlineMap[overflowInline], overflowBlock && overflowBlockMap[overflowBlock], position && positionMap[position], borderStyle && borderStyleMap[borderStyle], borderRadius && borderRadiusMap[borderRadius], shadow && shadowMap[shadow], layer && layerMap[layer], overflow && overflowMap[overflow], width && widthMap[width], height && heightMap[height]]),
60
96
  "data-testid": testId
61
97
  }), children);
62
98
  return node;
@@ -75,12 +111,9 @@ var borderStyleMap = {
75
111
  })
76
112
  };
77
113
  var borderWidthMap = {
78
- 'size.050': css({
79
- borderWidth: "var(--ds-width-050, 1px)"
80
- }),
81
- 'size.100': css({
82
- borderWidth: "var(--ds-width-100, 2px)"
83
- })
114
+ 'size.0': "var(--ds-width-0, 0)",
115
+ 'size.050': "var(--ds-width-050, 1px)",
116
+ 'size.100': "var(--ds-width-100, 2px)"
84
117
  };
85
118
  var borderRadiusMap = {
86
119
  'radius.100': css({
@@ -138,21 +171,11 @@ var alignSelfMap = {
138
171
  })
139
172
  };
140
173
  var displayMap = {
141
- block: css({
142
- display: 'block'
143
- }),
144
- inline: css({
145
- display: 'inline'
146
- }),
147
- flex: css({
148
- display: 'flex'
149
- }),
150
- 'inline-flex': css({
151
- display: 'inline-flex'
152
- }),
153
- 'inline-block': css({
154
- display: 'inline-block'
155
- })
174
+ block: 'block',
175
+ inline: 'inline',
176
+ flex: 'flex',
177
+ 'inline-flex': 'inline-flex',
178
+ 'inline-block': 'inline-block'
156
179
  };
157
180
  var positionMap = {
158
181
  absolute: css({
@@ -367,30 +390,28 @@ var maxHeightMap = {
367
390
 
368
391
  /**
369
392
  * THIS SECTION WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
370
- * @codegen <<SignedSource::6da0ceaa2c227230e3a93bc724ff8648>>
393
+ * @codegen <<SignedSource::84fd352b0e6509d380a0dcf8ad023ca2>>
371
394
  * @codegenId spacing
372
395
  * @codegenCommand yarn codegen-styles
373
396
  * @codegenParams ["padding"]
374
397
  * @codegenDependency ../../../../tokens/src/artifacts/tokens-raw/atlassian-spacing.tsx <<SignedSource::167d3b69b159ae33e74d4ea5ab7eade6>>
375
398
  */
376
- var paddingMap = Object.fromEntries(['padding', 'paddingBlock', 'paddingBlockStart', 'paddingBlockEnd', 'paddingInline', 'paddingInlineStart', 'paddingInlineEnd'].map(function (property) {
377
- return [property, {
378
- 'space.0': css(_defineProperty({}, property, "var(--ds-space-0, 0px)")),
379
- 'space.025': css(_defineProperty({}, property, "var(--ds-space-025, 2px)")),
380
- 'space.050': css(_defineProperty({}, property, "var(--ds-space-050, 4px)")),
381
- 'space.075': css(_defineProperty({}, property, "var(--ds-space-075, 6px)")),
382
- 'space.100': css(_defineProperty({}, property, "var(--ds-space-100, 8px)")),
383
- 'space.150': css(_defineProperty({}, property, "var(--ds-space-150, 12px)")),
384
- 'space.200': css(_defineProperty({}, property, "var(--ds-space-200, 16px)")),
385
- 'space.250': css(_defineProperty({}, property, "var(--ds-space-250, 20px)")),
386
- 'space.300': css(_defineProperty({}, property, "var(--ds-space-300, 24px)")),
387
- 'space.400': css(_defineProperty({}, property, "var(--ds-space-400, 32px)")),
388
- 'space.500': css(_defineProperty({}, property, "var(--ds-space-500, 40px)")),
389
- 'space.600': css(_defineProperty({}, property, "var(--ds-space-600, 48px)")),
390
- 'space.800': css(_defineProperty({}, property, "var(--ds-space-800, 64px)")),
391
- 'space.1000': css(_defineProperty({}, property, "var(--ds-space-1000, 80px)"))
392
- }];
393
- }));
399
+ var paddingMap = {
400
+ 'space.0': "var(--ds-space-0, 0px)",
401
+ 'space.025': "var(--ds-space-025, 2px)",
402
+ 'space.050': "var(--ds-space-050, 4px)",
403
+ 'space.075': "var(--ds-space-075, 6px)",
404
+ 'space.100': "var(--ds-space-100, 8px)",
405
+ 'space.150': "var(--ds-space-150, 12px)",
406
+ 'space.200': "var(--ds-space-200, 16px)",
407
+ 'space.250': "var(--ds-space-250, 20px)",
408
+ 'space.300': "var(--ds-space-300, 24px)",
409
+ 'space.400': "var(--ds-space-400, 32px)",
410
+ 'space.500': "var(--ds-space-500, 40px)",
411
+ 'space.600': "var(--ds-space-600, 48px)",
412
+ 'space.800': "var(--ds-space-800, 64px)",
413
+ 'space.1000': "var(--ds-space-1000, 80px)"
414
+ };
394
415
  /**
395
416
  * @codegenEnd
396
417
  */
@@ -0,0 +1 @@
1
+ export var BOX_RESPONSIVE_PROPS = ['borderWidth', 'display', 'padding', 'paddingBlock', 'paddingBlockStart', 'paddingBlockEnd', 'paddingInline', 'paddingInlineStart', 'paddingInlineEnd'];
@@ -0,0 +1,7 @@
1
+ import _typeof from "@babel/runtime/helpers/typeof";
2
+ export var isResponsiveStyleProp = function isResponsiveStyleProp(propertyValue) {
3
+ return _typeof(propertyValue) === 'object';
4
+ };
5
+ export var isStaticStyleProp = function isStaticStyleProp(propertyValue) {
6
+ return typeof propertyValue === 'string';
7
+ };