@atlaskit/primitives 0.4.0 → 0.4.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 (36) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/components/box.js +20 -17
  3. package/dist/cjs/components/inline.partial.js +4 -2
  4. package/dist/cjs/components/internal/base-box.partial.js +3 -3
  5. package/dist/cjs/components/stack.partial.js +4 -2
  6. package/dist/cjs/index.js +7 -0
  7. package/dist/cjs/internal/style-maps.js +130 -0
  8. package/dist/cjs/internal/xcss.js +110 -0
  9. package/dist/cjs/version.json +1 -1
  10. package/dist/es2019/components/box.js +19 -12
  11. package/dist/es2019/components/inline.partial.js +3 -1
  12. package/dist/es2019/components/internal/base-box.partial.js +2 -2
  13. package/dist/es2019/components/stack.partial.js +3 -1
  14. package/dist/es2019/index.js +1 -0
  15. package/dist/es2019/internal/style-maps.js +117 -0
  16. package/dist/es2019/internal/xcss.js +97 -0
  17. package/dist/es2019/version.json +1 -1
  18. package/dist/esm/components/box.js +21 -14
  19. package/dist/esm/components/inline.partial.js +4 -2
  20. package/dist/esm/components/internal/base-box.partial.js +3 -3
  21. package/dist/esm/components/stack.partial.js +4 -2
  22. package/dist/esm/index.js +1 -0
  23. package/dist/esm/internal/style-maps.js +117 -0
  24. package/dist/esm/internal/xcss.js +100 -0
  25. package/dist/esm/version.json +1 -1
  26. package/dist/types/components/box.d.ts +9 -7
  27. package/dist/types/components/inline.partial.d.ts +8 -3
  28. package/dist/types/components/internal/base-box.partial.d.ts +43 -4
  29. package/dist/types/components/stack.partial.d.ts +8 -3
  30. package/dist/types/components/types.d.ts +9 -14
  31. package/dist/types/index.d.ts +1 -0
  32. package/dist/types/internal/style-maps.d.ts +151 -0
  33. package/dist/types/internal/xcss.d.ts +22 -0
  34. package/package.json +3 -2
  35. package/report.api.md +240 -38
  36. package/tmp/api-report-tmp.d.ts +209 -13
@@ -0,0 +1,117 @@
1
+ /* eslint-disable @atlaskit/design-system/no-unsafe-design-token-usage */
2
+
3
+ // TODO: All of these maps need to be codegen'd
4
+ export const backgroundColorMap = {
5
+ disabled: "var(--ds-background-disabled, #091e4289)",
6
+ input: "var(--ds-background-input, #FAFBFC)",
7
+ 'inverse.subtle': "var(--ds-background-inverse-subtle, #00000029)",
8
+ neutral: "var(--ds-background-neutral, #DFE1E6)",
9
+ 'neutral.subtle': "var(--ds-background-neutral-subtle, transparent)",
10
+ 'neutral.bold': "var(--ds-background-neutral-bold, #42526E)",
11
+ selected: "var(--ds-background-selected, #DEEBFF)",
12
+ 'selected.bold': "var(--ds-background-selected-bold, #0052CC)",
13
+ 'brand.bold': "var(--ds-background-brand-bold, #0052CC)",
14
+ danger: "var(--ds-background-danger, #FFEBE6)",
15
+ 'danger.bold': "var(--ds-background-danger-bold, #DE350B)",
16
+ warning: "var(--ds-background-warning, #FFFAE6)",
17
+ 'warning.bold': "var(--ds-background-warning-bold, #FFAB00)",
18
+ success: "var(--ds-background-success, #E3FCEF)",
19
+ 'success.bold': "var(--ds-background-success-bold, #00875A)",
20
+ discovery: "var(--ds-background-discovery, #EAE6FF)",
21
+ 'discovery.bold': "var(--ds-background-discovery-bold, #5243AA)",
22
+ information: "var(--ds-background-information, #DEEBFF)",
23
+ 'information.bold': "var(--ds-background-information-bold, #0052CC)",
24
+ 'color.blanket': "var(--ds-blanket, #091e4289)",
25
+ 'color.blanket.selected': "var(--ds-blanket-selected, #388BFF14)",
26
+ 'color.blanket.danger': "var(--ds-blanket-danger, #EF5C4814)",
27
+ 'elevation.surface': "var(--ds-surface, #FFFFFF)",
28
+ 'elevation.surface.overlay': "var(--ds-surface-overlay, #FFFFFF)",
29
+ 'elevation.surface.raised': "var(--ds-surface-raised, #FFFFFF)",
30
+ 'elevation.surface.sunken': "var(--ds-surface-sunken, #F4F5F7)"
31
+ };
32
+ export const borderColorMap = {
33
+ 'color.border': "var(--ds-border, #091e4221)",
34
+ disabled: "var(--ds-border-disabled, #FAFBFC)",
35
+ focused: "var(--ds-border-focused, #4C9AFF)",
36
+ input: "var(--ds-border-input, #FAFBFC)",
37
+ inverse: "var(--ds-border-inverse, #FFFFFF)",
38
+ selected: "var(--ds-border-selected, #0052CC)",
39
+ brand: "var(--ds-border-brand, #0052CC)",
40
+ danger: "var(--ds-border-danger, #FF5630)",
41
+ warning: "var(--ds-border-warning, #FFC400)",
42
+ success: "var(--ds-border-success, #00875A)",
43
+ discovery: "var(--ds-border-discovery, #998DD9)",
44
+ information: "var(--ds-border-information, #0065FF)",
45
+ bold: "var(--ds-border-bold, #344563)"
46
+ };
47
+ export const borderWidthMap = {
48
+ 'size.0': "var(--ds-width-0, 0)",
49
+ 'size.050': "var(--ds-width-050, 1px)",
50
+ 'size.100': "var(--ds-width-100, 2px)"
51
+ };
52
+ export const borderRadiusMap = {
53
+ 'radius.400': "var(--ds-radius-400, 16px)",
54
+ 'radius.300': "var(--ds-radius-300, 12px)",
55
+ 'radius.100': "var(--ds-radius-100, 4px)",
56
+ 'radius.050': "var(--ds-radius-050, 2px)",
57
+ 'radius.200': "var(--ds-radius-200, 8px)"
58
+ };
59
+ export const paddingMap = {
60
+ 'space.0': "var(--ds-space-0, 0px)",
61
+ 'space.025': "var(--ds-space-025, 2px)",
62
+ 'space.050': "var(--ds-space-050, 4px)",
63
+ 'space.075': "var(--ds-space-075, 6px)",
64
+ 'space.100': "var(--ds-space-100, 8px)",
65
+ 'space.150': "var(--ds-space-150, 12px)",
66
+ 'space.200': "var(--ds-space-200, 16px)",
67
+ 'space.250': "var(--ds-space-250, 20px)",
68
+ 'space.300': "var(--ds-space-300, 24px)",
69
+ 'space.400': "var(--ds-space-400, 32px)",
70
+ 'space.500': "var(--ds-space-500, 40px)",
71
+ 'space.600': "var(--ds-space-600, 48px)",
72
+ 'space.800': "var(--ds-space-800, 64px)",
73
+ 'space.1000': "var(--ds-space-1000, 80px)"
74
+ };
75
+ export const textColorMap = {
76
+ 'color.text': "var(--ds-text, #172B4D)",
77
+ 'accent.red': "var(--ds-text-accent-red, #DE350B)",
78
+ 'accent.red.bolder': "var(--ds-text-accent-red-bolder, #BF2600)",
79
+ 'accent.orange': "var(--ds-text-accent-orange, #F18D13)",
80
+ 'accent.orange.bolder': "var(--ds-text-accent-orange-bolder, #B65C02)",
81
+ 'accent.yellow': "var(--ds-text-accent-yellow, #FF991F)",
82
+ 'accent.yellow.bolder': "var(--ds-text-accent-yellow-bolder, #FF8B00)",
83
+ 'accent.green': "var(--ds-text-accent-green, #00875A)",
84
+ 'accent.green.bolder': "var(--ds-text-accent-green-bolder, #006644)",
85
+ 'accent.teal': "var(--ds-text-accent-teal, #00A3BF)",
86
+ 'accent.teal.bolder': "var(--ds-text-accent-teal-bolder, #008DA6)",
87
+ 'accent.blue': "var(--ds-text-accent-blue, #0052CC)",
88
+ 'accent.blue.bolder': "var(--ds-text-accent-blue-bolder, #0747A6)",
89
+ 'accent.purple': "var(--ds-text-accent-purple, #5243AA)",
90
+ 'accent.purple.bolder': "var(--ds-text-accent-purple-bolder, #403294)",
91
+ 'accent.magenta': "var(--ds-text-accent-magenta, #E774BB)",
92
+ 'accent.magenta.bolder': "var(--ds-text-accent-magenta-bolder, #DA62AC)",
93
+ 'accent.gray': "var(--ds-text-accent-gray, #505F79)",
94
+ 'accent.gray.bolder': "var(--ds-text-accent-gray-bolder, #172B4D)",
95
+ disabled: "var(--ds-text-disabled, #A5ADBA)",
96
+ inverse: "var(--ds-text-inverse, #FFFFFF)",
97
+ selected: "var(--ds-text-selected, #0052CC)",
98
+ brand: "var(--ds-text-brand, #0065FF)",
99
+ danger: "var(--ds-text-danger, #DE350B)",
100
+ warning: "var(--ds-text-warning, #974F0C)",
101
+ 'warning.inverse': "var(--ds-text-warning-inverse, #172B4D)",
102
+ success: "var(--ds-text-success, #006644)",
103
+ discovery: "var(--ds-text-discovery, #403294)",
104
+ information: "var(--ds-text-information, #0052CC)",
105
+ subtlest: "var(--ds-text-subtlest, #7A869A)",
106
+ subtle: "var(--ds-text-subtle, #42526E)"
107
+ };
108
+ export const dimensionMap = {
109
+ '100%': '100%',
110
+ 'size.100': '16px',
111
+ 'size.200': '24px',
112
+ 'size.300': '32px',
113
+ 'size.400': '40px',
114
+ 'size.500': '48px',
115
+ 'size.600': '96px',
116
+ 'size.1000': '192px'
117
+ };
@@ -0,0 +1,97 @@
1
+ import { css as cssEmotion } from '@emotion/react';
2
+ import { backgroundColorMap, borderColorMap, borderRadiusMap, borderWidthMap, dimensionMap, paddingMap, textColorMap } from './style-maps';
3
+ const tokensMap = {
4
+ backgroundColor: backgroundColorMap,
5
+ borderColor: borderColorMap,
6
+ borderRadius: borderRadiusMap,
7
+ borderWidth: borderWidthMap,
8
+ color: textColorMap,
9
+ height: dimensionMap,
10
+ maxHeight: dimensionMap,
11
+ maxWidth: dimensionMap,
12
+ minHeight: dimensionMap,
13
+ minWidth: dimensionMap,
14
+ padding: paddingMap,
15
+ paddingBlock: paddingMap,
16
+ paddingBlockEnd: paddingMap,
17
+ paddingBlockStart: paddingMap,
18
+ paddingInline: paddingMap,
19
+ paddingInlineEnd: paddingMap,
20
+ paddingInlineStart: paddingMap,
21
+ width: dimensionMap
22
+ };
23
+ const uniqueSymbol = Symbol('Internal symbol to verify xcss function is called safely');
24
+
25
+ /**
26
+ * Only exposed for testing.
27
+ * @internal
28
+ */
29
+ export const transformStyles = styleObj => {
30
+ if (!styleObj || typeof styleObj !== 'object') {
31
+ return styleObj;
32
+ }
33
+
34
+ // If styles are defined as an CSSObject[], recursively call on each element until we reach CSSObject
35
+ if (Array.isArray(styleObj)) {
36
+ return styleObj.map(transformStyles);
37
+ }
38
+
39
+ // Modifies styleObj in place. Be careful.
40
+ Object.entries(styleObj).forEach(([key, value]) => {
41
+ var _process, _process$env;
42
+ 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') {
43
+ // We don't support `.class`, `[data-testid]`, `> *`, `#some-id`
44
+ if (/(\.|\s|&+|\*\>|#|\[.*\])/.test(key)) {
45
+ throw new Error(`Styles not supported for key '${key}'.`);
46
+ }
47
+ }
48
+
49
+ // If key is a pseudo class or a pseudo element, then value should be an object.
50
+ // So, call transformStyles on the value
51
+ if (/^::?.*$/.test(key)) {
52
+ styleObj[key] = transformStyles(value);
53
+ return;
54
+ }
55
+
56
+ // TODO: Deal with media queries
57
+
58
+ // We have now dealt with all the special cases, so,
59
+ // check whether what remains is a style property
60
+ // that can be transformed.
61
+ if (!(key in tokensMap)) {
62
+ return;
63
+ }
64
+ const tokenValue = tokensMap[key][value];
65
+ if (!tokenValue) {
66
+ throw new Error('Invalid Token');
67
+ }
68
+ styleObj[key] = tokenValue;
69
+ });
70
+ return styleObj;
71
+ };
72
+ export const xcss = style => {
73
+ const transformedStyles = transformStyles(style);
74
+ return {
75
+ symbol: uniqueSymbol,
76
+ styles: cssEmotion(transformedStyles)
77
+ };
78
+ };
79
+
80
+ /**
81
+ * @internal used in primitives
82
+ * @returns
83
+ */
84
+ export const parseXcss = args => {
85
+ if (Array.isArray(args)) {
86
+ // @ts-expect-error FIXME
87
+ return args.map(parseXcss);
88
+ }
89
+ const {
90
+ symbol,
91
+ styles
92
+ } = args;
93
+ if (typeof process && process.env.NODE_ENV === 'development' && symbol !== uniqueSymbol) {
94
+ throw new Error('Styles generated from unsafe source, use the `xcss` export from `@atlaskit/primitives`.');
95
+ }
96
+ return styles;
97
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/primitives",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "sideEffects": false
5
5
  }
@@ -1,19 +1,21 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- var _excluded = ["as", "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", "customStyles", "testId"],
4
- _excluded2 = ["style", "className"];
5
- import React, { forwardRef } from 'react';
3
+ var _excluded = ["as", "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", "style", "testId", "xcss"],
4
+ _excluded2 = ["className"];
5
+ /** @jsx jsx */
6
+ import { forwardRef } from 'react';
7
+ import { jsx } from '@emotion/react';
8
+ import { parseXcss } from '../internal/xcss';
6
9
  import { BaseBox } from './internal/base-box.partial';
7
- // TODO: Fill in the component {description} and ensure links point to the correct {packageName} location.
8
- // Remove links that the component does not have (such as usage). If there are no links remove them all.
9
10
  /**
10
11
  * __Box__
11
12
  *
12
- * A box {description}.
13
+ * A Box is a primitive component that has the design decisions of the Atlassian Design System baked in.
14
+ * Renders a `div` by default.
13
15
  *
14
- * - [Examples](https://atlassian.design/components/{packageName}/examples)
15
- * - [Code](https://atlassian.design/components/{packageName}/code)
16
- * - [Usage](https://atlassian.design/components/{packageName}/usage)
16
+ * - [Examples](https://atlassian.design/components/primitives/box/examples)
17
+ * - [Code](https://atlassian.design/components/primitives/box/code)
18
+ * - [Usage](https://atlassian.design/components/primitives/box/usage)
17
19
  */
18
20
  var Box = /*#__PURE__*/forwardRef(function (_ref, ref) {
19
21
  var as = _ref.as,
@@ -46,13 +48,14 @@ var Box = /*#__PURE__*/forwardRef(function (_ref, ref) {
46
48
  display = _ref$display === void 0 ? 'block' : _ref$display,
47
49
  _ref$position = _ref.position,
48
50
  position = _ref$position === void 0 ? 'static' : _ref$position,
49
- customStyles = _ref.customStyles,
51
+ style = _ref.style,
50
52
  testId = _ref.testId,
53
+ xcss = _ref.xcss,
51
54
  htmlAttributes = _objectWithoutProperties(_ref, _excluded);
52
- var style = htmlAttributes.style,
53
- className = htmlAttributes.className,
55
+ var spreadClass = htmlAttributes.className,
54
56
  safeHtmlAttributes = _objectWithoutProperties(htmlAttributes, _excluded2);
55
- return /*#__PURE__*/React.createElement(BaseBox, _extends({
57
+ var className = xcss && parseXcss(xcss);
58
+ return jsx(BaseBox, _extends({
56
59
  as: as,
57
60
  color: color,
58
61
  backgroundColor: backgroundColor,
@@ -80,9 +83,13 @@ var Box = /*#__PURE__*/forwardRef(function (_ref, ref) {
80
83
  width: width,
81
84
  display: display,
82
85
  position: position,
83
- UNSAFE_style: customStyles,
86
+ style: style,
84
87
  testId: testId,
85
88
  ref: ref
89
+ // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
90
+ ,
91
+ css: className
86
92
  }, safeHtmlAttributes), children);
87
93
  });
94
+ Box.displayName = 'Box';
88
95
  export default Box;
@@ -177,7 +177,8 @@ var Separator = function Separator(_ref) {
177
177
  *
178
178
  */
179
179
  var Inline = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_ref2, ref) {
180
- var alignInline = _ref2.alignInline,
180
+ var as = _ref2.as,
181
+ alignInline = _ref2.alignInline,
181
182
  alignItems = _ref2.alignBlock,
182
183
  _ref2$shouldWrap = _ref2.shouldWrap,
183
184
  shouldWrap = _ref2$shouldWrap === void 0 ? false : _ref2$shouldWrap,
@@ -188,6 +189,7 @@ var Inline = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_ref2, ref) {
188
189
  separator = _ref2.separator,
189
190
  testId = _ref2.testId,
190
191
  rawChildren = _ref2.children;
192
+ var Component = as || 'div';
191
193
  var separatorComponent = typeof separator === 'string' ? jsx(Separator, null, separator) : separator;
192
194
  var children = separatorComponent ? Children.toArray(rawChildren).filter(Boolean).map(function (child, index) {
193
195
  return jsx(Fragment, {
@@ -195,7 +197,7 @@ var Inline = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_ref2, ref) {
195
197
  }, separator && index > 0 ? separatorComponent : null, child);
196
198
  }) : rawChildren;
197
199
  var justifyContent = spread || alignInline;
198
- return jsx("div", {
200
+ return jsx(Component, {
199
201
  css: [baseStyles, space && spaceMap[space], justifyContent && justifyContentMap[justifyContent], grow && flexGrowMap[grow], alignItems && alignItemsMap[alignItems], shouldWrap && flexWrapStyles, rowSpace && rowSpaceMap[rowSpace]],
200
202
  "data-testid": testId,
201
203
  ref: ref
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
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"];
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", "style", "testId"];
5
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
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; }
7
7
  /** @jsx jsx */
@@ -81,11 +81,11 @@ export var BaseBox = /*#__PURE__*/forwardRef(function (_ref3, ref) {
81
81
  display = _ref3$display === void 0 ? displayMap.block : _ref3$display,
82
82
  _ref3$position = _ref3.position,
83
83
  position = _ref3$position === void 0 ? 'static' : _ref3$position,
84
- UNSAFE_style = _ref3.UNSAFE_style,
84
+ style = _ref3.style,
85
85
  testId = _ref3.testId,
86
86
  htmlAttributes = _objectWithoutProperties(_ref3, _excluded);
87
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));
88
+ var inlineStyles = Object.assign({}, 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));
89
89
  var node = jsx(Component, _extends({
90
90
  style: inlineStyles,
91
91
  ref: ref
@@ -113,15 +113,17 @@ var baseStyles = css({
113
113
  *
114
114
  */
115
115
  var Stack = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_ref, ref) {
116
- var alignItems = _ref.alignInline,
116
+ var as = _ref.as,
117
+ alignItems = _ref.alignInline,
117
118
  alignBlock = _ref.alignBlock,
118
119
  spread = _ref.spread,
119
120
  grow = _ref.grow,
120
121
  space = _ref.space,
121
122
  children = _ref.children,
122
123
  testId = _ref.testId;
124
+ var Component = as || 'div';
123
125
  var justifyContent = spread || alignBlock;
124
- return jsx("div", {
126
+ return jsx(Component, {
125
127
  css: [baseStyles, space && spaceMap[space], alignItems && alignItemsMap[alignItems], grow && flexGrowMap[grow], justifyContent && justifyContentMap[justifyContent]],
126
128
  "data-testid": testId,
127
129
  ref: ref
package/dist/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { default as Box } from './components/box';
2
2
  export { default as Inline } from './components/inline.partial';
3
+ export { xcss } from './internal/xcss';
3
4
  export { default as Stack } from './components/stack.partial';
@@ -0,0 +1,117 @@
1
+ /* eslint-disable @atlaskit/design-system/no-unsafe-design-token-usage */
2
+
3
+ // TODO: All of these maps need to be codegen'd
4
+ export var backgroundColorMap = {
5
+ disabled: "var(--ds-background-disabled, #091e4289)",
6
+ input: "var(--ds-background-input, #FAFBFC)",
7
+ 'inverse.subtle': "var(--ds-background-inverse-subtle, #00000029)",
8
+ neutral: "var(--ds-background-neutral, #DFE1E6)",
9
+ 'neutral.subtle': "var(--ds-background-neutral-subtle, transparent)",
10
+ 'neutral.bold': "var(--ds-background-neutral-bold, #42526E)",
11
+ selected: "var(--ds-background-selected, #DEEBFF)",
12
+ 'selected.bold': "var(--ds-background-selected-bold, #0052CC)",
13
+ 'brand.bold': "var(--ds-background-brand-bold, #0052CC)",
14
+ danger: "var(--ds-background-danger, #FFEBE6)",
15
+ 'danger.bold': "var(--ds-background-danger-bold, #DE350B)",
16
+ warning: "var(--ds-background-warning, #FFFAE6)",
17
+ 'warning.bold': "var(--ds-background-warning-bold, #FFAB00)",
18
+ success: "var(--ds-background-success, #E3FCEF)",
19
+ 'success.bold': "var(--ds-background-success-bold, #00875A)",
20
+ discovery: "var(--ds-background-discovery, #EAE6FF)",
21
+ 'discovery.bold': "var(--ds-background-discovery-bold, #5243AA)",
22
+ information: "var(--ds-background-information, #DEEBFF)",
23
+ 'information.bold': "var(--ds-background-information-bold, #0052CC)",
24
+ 'color.blanket': "var(--ds-blanket, #091e4289)",
25
+ 'color.blanket.selected': "var(--ds-blanket-selected, #388BFF14)",
26
+ 'color.blanket.danger': "var(--ds-blanket-danger, #EF5C4814)",
27
+ 'elevation.surface': "var(--ds-surface, #FFFFFF)",
28
+ 'elevation.surface.overlay': "var(--ds-surface-overlay, #FFFFFF)",
29
+ 'elevation.surface.raised': "var(--ds-surface-raised, #FFFFFF)",
30
+ 'elevation.surface.sunken': "var(--ds-surface-sunken, #F4F5F7)"
31
+ };
32
+ export var borderColorMap = {
33
+ 'color.border': "var(--ds-border, #091e4221)",
34
+ disabled: "var(--ds-border-disabled, #FAFBFC)",
35
+ focused: "var(--ds-border-focused, #4C9AFF)",
36
+ input: "var(--ds-border-input, #FAFBFC)",
37
+ inverse: "var(--ds-border-inverse, #FFFFFF)",
38
+ selected: "var(--ds-border-selected, #0052CC)",
39
+ brand: "var(--ds-border-brand, #0052CC)",
40
+ danger: "var(--ds-border-danger, #FF5630)",
41
+ warning: "var(--ds-border-warning, #FFC400)",
42
+ success: "var(--ds-border-success, #00875A)",
43
+ discovery: "var(--ds-border-discovery, #998DD9)",
44
+ information: "var(--ds-border-information, #0065FF)",
45
+ bold: "var(--ds-border-bold, #344563)"
46
+ };
47
+ export var borderWidthMap = {
48
+ 'size.0': "var(--ds-width-0, 0)",
49
+ 'size.050': "var(--ds-width-050, 1px)",
50
+ 'size.100': "var(--ds-width-100, 2px)"
51
+ };
52
+ export var borderRadiusMap = {
53
+ 'radius.400': "var(--ds-radius-400, 16px)",
54
+ 'radius.300': "var(--ds-radius-300, 12px)",
55
+ 'radius.100': "var(--ds-radius-100, 4px)",
56
+ 'radius.050': "var(--ds-radius-050, 2px)",
57
+ 'radius.200': "var(--ds-radius-200, 8px)"
58
+ };
59
+ export var paddingMap = {
60
+ 'space.0': "var(--ds-space-0, 0px)",
61
+ 'space.025': "var(--ds-space-025, 2px)",
62
+ 'space.050': "var(--ds-space-050, 4px)",
63
+ 'space.075': "var(--ds-space-075, 6px)",
64
+ 'space.100': "var(--ds-space-100, 8px)",
65
+ 'space.150': "var(--ds-space-150, 12px)",
66
+ 'space.200': "var(--ds-space-200, 16px)",
67
+ 'space.250': "var(--ds-space-250, 20px)",
68
+ 'space.300': "var(--ds-space-300, 24px)",
69
+ 'space.400': "var(--ds-space-400, 32px)",
70
+ 'space.500': "var(--ds-space-500, 40px)",
71
+ 'space.600': "var(--ds-space-600, 48px)",
72
+ 'space.800': "var(--ds-space-800, 64px)",
73
+ 'space.1000': "var(--ds-space-1000, 80px)"
74
+ };
75
+ export var textColorMap = {
76
+ 'color.text': "var(--ds-text, #172B4D)",
77
+ 'accent.red': "var(--ds-text-accent-red, #DE350B)",
78
+ 'accent.red.bolder': "var(--ds-text-accent-red-bolder, #BF2600)",
79
+ 'accent.orange': "var(--ds-text-accent-orange, #F18D13)",
80
+ 'accent.orange.bolder': "var(--ds-text-accent-orange-bolder, #B65C02)",
81
+ 'accent.yellow': "var(--ds-text-accent-yellow, #FF991F)",
82
+ 'accent.yellow.bolder': "var(--ds-text-accent-yellow-bolder, #FF8B00)",
83
+ 'accent.green': "var(--ds-text-accent-green, #00875A)",
84
+ 'accent.green.bolder': "var(--ds-text-accent-green-bolder, #006644)",
85
+ 'accent.teal': "var(--ds-text-accent-teal, #00A3BF)",
86
+ 'accent.teal.bolder': "var(--ds-text-accent-teal-bolder, #008DA6)",
87
+ 'accent.blue': "var(--ds-text-accent-blue, #0052CC)",
88
+ 'accent.blue.bolder': "var(--ds-text-accent-blue-bolder, #0747A6)",
89
+ 'accent.purple': "var(--ds-text-accent-purple, #5243AA)",
90
+ 'accent.purple.bolder': "var(--ds-text-accent-purple-bolder, #403294)",
91
+ 'accent.magenta': "var(--ds-text-accent-magenta, #E774BB)",
92
+ 'accent.magenta.bolder': "var(--ds-text-accent-magenta-bolder, #DA62AC)",
93
+ 'accent.gray': "var(--ds-text-accent-gray, #505F79)",
94
+ 'accent.gray.bolder': "var(--ds-text-accent-gray-bolder, #172B4D)",
95
+ disabled: "var(--ds-text-disabled, #A5ADBA)",
96
+ inverse: "var(--ds-text-inverse, #FFFFFF)",
97
+ selected: "var(--ds-text-selected, #0052CC)",
98
+ brand: "var(--ds-text-brand, #0065FF)",
99
+ danger: "var(--ds-text-danger, #DE350B)",
100
+ warning: "var(--ds-text-warning, #974F0C)",
101
+ 'warning.inverse': "var(--ds-text-warning-inverse, #172B4D)",
102
+ success: "var(--ds-text-success, #006644)",
103
+ discovery: "var(--ds-text-discovery, #403294)",
104
+ information: "var(--ds-text-information, #0052CC)",
105
+ subtlest: "var(--ds-text-subtlest, #7A869A)",
106
+ subtle: "var(--ds-text-subtle, #42526E)"
107
+ };
108
+ export var dimensionMap = {
109
+ '100%': '100%',
110
+ 'size.100': '16px',
111
+ 'size.200': '24px',
112
+ 'size.300': '32px',
113
+ 'size.400': '40px',
114
+ 'size.500': '48px',
115
+ 'size.600': '96px',
116
+ 'size.1000': '192px'
117
+ };
@@ -0,0 +1,100 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import _typeof from "@babel/runtime/helpers/typeof";
3
+ import { css as cssEmotion } from '@emotion/react';
4
+ import { backgroundColorMap, borderColorMap, borderRadiusMap, borderWidthMap, dimensionMap, paddingMap, textColorMap } from './style-maps';
5
+ var tokensMap = {
6
+ backgroundColor: backgroundColorMap,
7
+ borderColor: borderColorMap,
8
+ borderRadius: borderRadiusMap,
9
+ borderWidth: borderWidthMap,
10
+ color: textColorMap,
11
+ height: dimensionMap,
12
+ maxHeight: dimensionMap,
13
+ maxWidth: dimensionMap,
14
+ minHeight: dimensionMap,
15
+ minWidth: dimensionMap,
16
+ padding: paddingMap,
17
+ paddingBlock: paddingMap,
18
+ paddingBlockEnd: paddingMap,
19
+ paddingBlockStart: paddingMap,
20
+ paddingInline: paddingMap,
21
+ paddingInlineEnd: paddingMap,
22
+ paddingInlineStart: paddingMap,
23
+ width: dimensionMap
24
+ };
25
+ var uniqueSymbol = Symbol('Internal symbol to verify xcss function is called safely');
26
+
27
+ /**
28
+ * Only exposed for testing.
29
+ * @internal
30
+ */
31
+ export var transformStyles = function transformStyles(styleObj) {
32
+ if (!styleObj || _typeof(styleObj) !== 'object') {
33
+ return styleObj;
34
+ }
35
+
36
+ // If styles are defined as an CSSObject[], recursively call on each element until we reach CSSObject
37
+ if (Array.isArray(styleObj)) {
38
+ return styleObj.map(transformStyles);
39
+ }
40
+
41
+ // Modifies styleObj in place. Be careful.
42
+ Object.entries(styleObj).forEach(function (_ref) {
43
+ var _process, _process$env;
44
+ var _ref2 = _slicedToArray(_ref, 2),
45
+ key = _ref2[0],
46
+ value = _ref2[1];
47
+ 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') {
48
+ // We don't support `.class`, `[data-testid]`, `> *`, `#some-id`
49
+ if (/(\.|\s|&+|\*\>|#|\[.*\])/.test(key)) {
50
+ throw new Error("Styles not supported for key '".concat(key, "'."));
51
+ }
52
+ }
53
+
54
+ // If key is a pseudo class or a pseudo element, then value should be an object.
55
+ // So, call transformStyles on the value
56
+ if (/^::?.*$/.test(key)) {
57
+ styleObj[key] = transformStyles(value);
58
+ return;
59
+ }
60
+
61
+ // TODO: Deal with media queries
62
+
63
+ // We have now dealt with all the special cases, so,
64
+ // check whether what remains is a style property
65
+ // that can be transformed.
66
+ if (!(key in tokensMap)) {
67
+ return;
68
+ }
69
+ var tokenValue = tokensMap[key][value];
70
+ if (!tokenValue) {
71
+ throw new Error('Invalid Token');
72
+ }
73
+ styleObj[key] = tokenValue;
74
+ });
75
+ return styleObj;
76
+ };
77
+ export var xcss = function xcss(style) {
78
+ var transformedStyles = transformStyles(style);
79
+ return {
80
+ symbol: uniqueSymbol,
81
+ styles: cssEmotion(transformedStyles)
82
+ };
83
+ };
84
+
85
+ /**
86
+ * @internal used in primitives
87
+ * @returns
88
+ */
89
+ export var parseXcss = function parseXcss(args) {
90
+ if (Array.isArray(args)) {
91
+ // @ts-expect-error FIXME
92
+ return args.map(parseXcss);
93
+ }
94
+ var symbol = args.symbol,
95
+ styles = args.styles;
96
+ if ((typeof process === "undefined" ? "undefined" : _typeof(process)) && process.env.NODE_ENV === 'development' && symbol !== uniqueSymbol) {
97
+ throw new Error('Styles generated from unsafe source, use the `xcss` export from `@atlaskit/primitives`.');
98
+ }
99
+ return styles;
100
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/primitives",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "sideEffects": false
5
5
  }
@@ -1,17 +1,19 @@
1
+ /** @jsx jsx */
1
2
  import { ElementType, FC, ReactElement } from 'react';
2
3
  import { BaseBoxProps } from './internal/base-box.partial';
3
- import { BoxResponsiveProp } from './internal/types';
4
- import { PublicBoxPropsBase } from './types';
5
- export declare type BoxProps<T extends ElementType = 'div'> = Omit<BaseBoxProps<T>, 'className' | 'UNSAFE_style' | BoxResponsiveProp> & PublicBoxPropsBase;
4
+ import type { BoxResponsiveProp } from './internal/types';
5
+ import type { PublicBoxPropsBase } from './types';
6
+ export declare type BoxProps<T extends ElementType = 'div'> = Omit<BaseBoxProps<T>, 'className' | BoxResponsiveProp> & PublicBoxPropsBase;
6
7
  declare type BoxComponent<T extends ElementType = 'div'> = (<T extends ElementType = 'div'>(props: BoxProps<T>) => ReactElement | null) & FC<BoxProps<T>>;
7
8
  /**
8
9
  * __Box__
9
10
  *
10
- * A box {description}.
11
+ * A Box is a primitive component that has the design decisions of the Atlassian Design System baked in.
12
+ * Renders a `div` by default.
11
13
  *
12
- * - [Examples](https://atlassian.design/components/{packageName}/examples)
13
- * - [Code](https://atlassian.design/components/{packageName}/code)
14
- * - [Usage](https://atlassian.design/components/{packageName}/usage)
14
+ * - [Examples](https://atlassian.design/components/primitives/box/examples)
15
+ * - [Code](https://atlassian.design/components/primitives/box/code)
16
+ * - [Usage](https://atlassian.design/components/primitives/box/usage)
15
17
  */
16
18
  declare const Box: BoxComponent;
17
19
  export default Box;
@@ -1,6 +1,10 @@
1
1
  /** @jsx jsx */
2
- import { ReactNode } from 'react';
3
- export interface InlineProps {
2
+ import { ComponentPropsWithRef, ElementType, ReactNode } from 'react';
3
+ export interface InlineProps<T extends ElementType = 'div'> {
4
+ /**
5
+ * The DOM element to render as the Inline. Defaults to `div`.
6
+ */
7
+ as?: 'div' | 'span' | 'ul' | 'ol';
4
8
  /**
5
9
  * Used to align children along the main axis.
6
10
  */
@@ -42,6 +46,7 @@ export interface InlineProps {
42
46
  * Elements to be rendered inside the Stack.
43
47
  */
44
48
  children: ReactNode;
49
+ ref?: ComponentPropsWithRef<T>['ref'];
45
50
  }
46
51
  export declare type AlignInline = 'start' | 'center' | 'end';
47
52
  export declare type AlignBlock = 'start' | 'center' | 'end' | 'baseline';
@@ -104,5 +109,5 @@ export declare type RowSpace = keyof typeof rowSpaceMap;
104
109
  * ```
105
110
  *
106
111
  */
107
- declare const Inline: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<InlineProps & import("react").RefAttributes<HTMLDivElement>>>;
112
+ declare const Inline: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<Pick<InlineProps<ElementType<any>>, "space" | "separator" | "as" | "children" | "testId" | "alignInline" | "alignBlock" | "shouldWrap" | "spread" | "grow" | "rowSpace"> & import("react").RefAttributes<any>>>;
108
113
  export default Inline;