@atlaskit/primitives 3.0.0 → 3.2.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 (47) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/constellation/text/examples.mdx +16 -9
  3. package/dist/cjs/components/anchor.js +4 -2
  4. package/dist/cjs/components/bleed.js +3 -2
  5. package/dist/cjs/components/box.js +5 -5
  6. package/dist/cjs/components/flex.js +3 -2
  7. package/dist/cjs/components/grid.js +3 -2
  8. package/dist/cjs/components/inline.js +8 -3
  9. package/dist/cjs/components/pressable.js +5 -1
  10. package/dist/cjs/components/stack.js +8 -3
  11. package/dist/cjs/components/text.js +37 -21
  12. package/dist/cjs/xcss/xcss.js +52 -14
  13. package/dist/es2019/components/anchor.js +4 -2
  14. package/dist/es2019/components/bleed.js +3 -2
  15. package/dist/es2019/components/box.js +5 -5
  16. package/dist/es2019/components/flex.js +3 -2
  17. package/dist/es2019/components/grid.js +3 -2
  18. package/dist/es2019/components/inline.js +8 -3
  19. package/dist/es2019/components/pressable.js +5 -1
  20. package/dist/es2019/components/stack.js +8 -3
  21. package/dist/es2019/components/text.js +25 -13
  22. package/dist/es2019/xcss/xcss.js +38 -8
  23. package/dist/esm/components/anchor.js +4 -2
  24. package/dist/esm/components/bleed.js +3 -2
  25. package/dist/esm/components/box.js +5 -5
  26. package/dist/esm/components/flex.js +3 -2
  27. package/dist/esm/components/grid.js +3 -2
  28. package/dist/esm/components/inline.js +8 -3
  29. package/dist/esm/components/pressable.js +5 -1
  30. package/dist/esm/components/stack.js +8 -3
  31. package/dist/esm/components/text.js +28 -13
  32. package/dist/esm/xcss/xcss.js +52 -10
  33. package/dist/types/components/flex.d.ts +2 -2
  34. package/dist/types/components/grid.d.ts +3 -3
  35. package/dist/types/components/pressable.d.ts +1 -1
  36. package/dist/types/components/stack.d.ts +1 -1
  37. package/dist/types/components/text.d.ts +3 -3
  38. package/dist/types/components/types.d.ts +3 -2
  39. package/dist/types/xcss/xcss.d.ts +11 -5
  40. package/dist/types-ts4.5/components/flex.d.ts +2 -2
  41. package/dist/types-ts4.5/components/grid.d.ts +3 -3
  42. package/dist/types-ts4.5/components/pressable.d.ts +1 -1
  43. package/dist/types-ts4.5/components/stack.d.ts +1 -1
  44. package/dist/types-ts4.5/components/text.d.ts +3 -3
  45. package/dist/types-ts4.5/components/types.d.ts +3 -2
  46. package/dist/types-ts4.5/xcss/xcss.d.ts +11 -5
  47. package/package.json +2 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/primitives
2
2
 
3
+ ## 3.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#77488](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/77488) [`9e119dcbfd60`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9e119dcbfd60) - The `xcss` prop on select components have had its type expanded to support styles being passed from Compiled CSS-in-JS. This is still experimental and something we'll be iterating on.
8
+
9
+ ## 3.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#76431](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/76431) [`c6819de73d02`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c6819de73d02) - Default text color + allow color inheritance if explicitly defined
14
+
3
15
  ## 3.0.0
4
16
 
5
17
  ### Major Changes
@@ -4,9 +4,10 @@ description: Text is a token-backed typography component to display body and UI
4
4
  order: 0
5
5
  ---
6
6
 
7
- import TextDefault from '../../examples/constellation/text/basic';
8
- import TextAsElement from '../../examples/constellation/text/as-element';
7
+ import Basic from '../../examples/constellation/text/basic';
9
8
  import ColorInverse from '../../examples/constellation/text/color-inverse';
9
+ import Weight from '../../examples/constellation/text/weight';
10
+ import AsElement from '../../examples/constellation/text/as-element';
10
11
 
11
12
  ## Basic
12
13
 
@@ -14,16 +15,22 @@ Implements the [Atlassian typography system](/foundations/typography/) as a comp
14
15
 
15
16
  The `variant` prop expresses the visual appearance of the text element.
16
17
 
17
- <Example Component={TextDefault} pacckageName="@atlaskit/primitives" />
18
+ <Example Component={Basic} pacckageName="@atlaskit/primitives" />
18
19
 
19
- ## Rendered HTML tag
20
+ ## Color
20
21
 
21
- By default, `body` variants are rendered as `<p>` tags and `ui` variants are rendered as `<span>` tags. This can be ovrridden by the `as` prop.
22
+ Set `color` to change the text color, defaults to `text.color` if not nested in other Text components. When used within a [box component](/components/primitives/box) that has a bold background color, the text color will automatically be inverted.
22
23
 
23
- <Example Component={TextAsElement} packageName="@atlaskit/primitives" />
24
+ <Example Component={ColorInverse} pacckageName="@atlaskit/primitives" />
24
25
 
25
- ## Color
26
+ ## Weight
26
27
 
27
- Set `color` to change the text color. When used within a [box component](/components/primitives/box) that has a background color set, the text color can be automatically inverted without setting the `color` prop depending on the background color of the box.
28
+ Set `weight` to change the front weight.
28
29
 
29
- <Example Component={ColorInverse} pacckageName="@atlaskit/primitives" />
30
+ <Example Component={Weight} pacckageName="@atlaskit/primitives" />
31
+
32
+ ## Rendered HTML tag
33
+
34
+ Set `as` to change the rendered HTML element, defaults to `span`.
35
+
36
+ <Example Component={AsElement} packageName="@atlaskit/primitives" />
@@ -76,13 +76,15 @@ var Anchor = function Anchor(_ref, ref) {
76
76
  action: 'clicked',
77
77
  componentName: componentName || 'Anchor',
78
78
  packageName: "@atlaskit/primitives",
79
- packageVersion: "3.0.0",
79
+ packageVersion: "3.2.0",
80
80
  analyticsData: analyticsContext,
81
81
  actionSubject: 'link'
82
82
  });
83
83
  var RouterLink = (0, _appProvider.useRouterLink)();
84
84
 
85
- // Combine default styles with supplied styles. XCSS does not support deep nested arrays
85
+ // We're type coercing this as Compiled styles in an array isn't supported by the types
86
+ // But the runtime accepts it none-the-wiser. We can remove this entire block and replace
87
+ // it with cx(defaultStyles, focusRingStyles, xcssStyles) when we've moved away from Emotion.
86
88
  var styles = Array.isArray(xcssStyles) ? [defaultStyles, focusRingStyles].concat((0, _toConsumableArray2.default)(xcssStyles)) : [defaultStyles, focusRingStyles, xcssStyles];
87
89
  var isExternal = typeof href === 'string' && IS_EXTERNAL_LINK_REGEX.test(href);
88
90
  var isNonHttpBased = typeof href === 'string' && IS_NON_HTTP_BASED.test(href);
@@ -66,11 +66,12 @@ var Bleed = /*#__PURE__*/_react.default.memo(function (_ref) {
66
66
  block = _ref.block,
67
67
  all = _ref.all,
68
68
  xcss = _ref.xcss;
69
- var xcssStyles = xcss && (0, _xcss.parseXcss)(xcss);
69
+ var resolvedStyles = (0, _xcss.parseXcss)(xcss);
70
70
  return (0, _react2.jsx)("div", {
71
+ className: resolvedStyles.static,
71
72
  css: [baseStyles, (inline || all) && inlineBleedMap[inline || all], (block || all) && blockBleedMap[block || all],
72
73
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
73
- xcssStyles],
74
+ resolvedStyles.emotion],
74
75
  "data-testid": testId
75
76
  }, children);
76
77
  });
@@ -32,7 +32,7 @@ var _excluded = ["as", "children", "backgroundColor", "padding", "paddingBlock",
32
32
  */
33
33
  var Box = exports.Box = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
34
34
  var _ref$as = _ref.as,
35
- as = _ref$as === void 0 ? 'div' : _ref$as,
35
+ Component = _ref$as === void 0 ? 'div' : _ref$as,
36
36
  children = _ref.children,
37
37
  backgroundColor = _ref.backgroundColor,
38
38
  padding = _ref.padding,
@@ -46,24 +46,24 @@ var Box = exports.Box = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref)
46
46
  testId = _ref.testId,
47
47
  xcss = _ref.xcss,
48
48
  htmlAttributes = (0, _objectWithoutProperties2.default)(_ref, _excluded);
49
- var Component = as;
50
49
  // This is to remove className from safeHtmlAttributes
51
50
  // @ts-expect-error className doesn't exist in the prop definition but we want to ensure it cannot be applied even if types are bypassed
52
51
  var _spreadClass = htmlAttributes.className,
53
52
  safeHtmlAttributes = (0, _objectWithoutProperties2.default)(htmlAttributes, _excluded2);
54
- var className = xcss && (0, _xcss.parseXcss)(xcss);
53
+ var resolvedStyles = (0, _xcss.parseXcss)(xcss);
55
54
  var node =
56
55
  // @ts-expect-error Expression produces a union type that is too complex to represent. I think this is unavoidable
57
56
  (0, _react2.jsx)(Component, (0, _extends2.default)({
58
57
  style: style
59
58
  // @ts-expect-error Expression produces a union type that is too complex to represent. We may be able to narrow the type here but unsure.
60
59
  ,
61
- ref: ref
60
+ ref: ref,
61
+ className: resolvedStyles.static
62
62
  // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
63
63
  }, safeHtmlAttributes, {
64
64
  css: [baseStyles, backgroundColor && _styleMaps.backgroundColorStylesMap[backgroundColor], (0, _styleMaps.isSurfaceColorToken)(backgroundColor) && _styleMaps.surfaceColorStylesMap[backgroundColor], padding && _styleMaps.paddingStylesMap.padding[padding], paddingBlock && _styleMaps.paddingStylesMap.paddingBlock[paddingBlock], paddingBlockStart && _styleMaps.paddingStylesMap.paddingBlockStart[paddingBlockStart], paddingBlockEnd && _styleMaps.paddingStylesMap.paddingBlockEnd[paddingBlockEnd], paddingInline && _styleMaps.paddingStylesMap.paddingInline[paddingInline], paddingInlineStart && _styleMaps.paddingStylesMap.paddingInlineStart[paddingInlineStart], paddingInlineEnd && _styleMaps.paddingStylesMap.paddingInlineEnd[paddingInlineEnd],
65
65
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
66
- className],
66
+ resolvedStyles.emotion],
67
67
  "data-testid": testId
68
68
  }), children);
69
69
  return backgroundColor ? (0, _react2.jsx)(_surfaceProvider.SurfaceContext.Provider, {
@@ -105,12 +105,13 @@ var Flex = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef)(fu
105
105
  direction = _ref.direction,
106
106
  wrap = _ref.wrap,
107
107
  xcss = _ref.xcss;
108
- var xcssClassName = xcss && (0, _xcss.parseXcss)(xcss);
108
+ var resolvedStyles = (0, _xcss.parseXcss)(xcss);
109
109
  return (0, _react2.jsx)(Component, {
110
110
  role: role,
111
+ className: resolvedStyles.static,
111
112
  css: [baseStyles, gap && _styleMaps.spaceStylesMap.gap[gap], columnGap && _styleMaps.spaceStylesMap.columnGap[columnGap], rowGap && _styleMaps.spaceStylesMap.rowGap[rowGap], alignItems && alignItemsMap[alignItems], direction && flexDirectionMap[direction], justifyContent && justifyContentMap[justifyContent], wrap && flexWrapMap[wrap],
112
113
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
113
- xcssClassName && xcssClassName],
114
+ resolvedStyles.emotion],
114
115
  "data-testid": testId,
115
116
  ref: ref
116
117
  }, children);
@@ -152,7 +152,7 @@ var Grid = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef)(fu
152
152
  gridTemplateColumns = _ref.templateColumns,
153
153
  xcss = _ref.xcss;
154
154
  var Component = as || 'div';
155
- var xcssClassName = xcss && (0, _xcss.parseXcss)(xcss);
155
+ var resolvedStyles = (0, _xcss.parseXcss)(xcss);
156
156
 
157
157
  /**
158
158
  * We use CSS variables to allow for dynamic grid templates instead of dynamically setting to `props.style`
@@ -172,9 +172,10 @@ var Grid = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef)(fu
172
172
  id: id,
173
173
  role: role,
174
174
  style: style,
175
+ className: resolvedStyles.static,
175
176
  css: [baseStyles, gap && _styleMaps.spaceStylesMap.gap[gap], columnGap && _styleMaps.spaceStylesMap.columnGap[columnGap], rowGap && _styleMaps.spaceStylesMap.rowGap[rowGap], alignItems && alignItemsMap[alignItems], alignContent && alignContentMap[alignContent], justifyContent && justifyContentMap[justifyContent], autoFlow && gridAutoFlowMap[autoFlow],
176
177
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
177
- xcssClassName],
178
+ resolvedStyles.emotion],
178
179
  "data-testid": testId,
179
180
  ref: ref
180
181
  }, children);
@@ -73,6 +73,11 @@ var Inline = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef)(
73
73
  }, separator && index > 0 ? separatorComponent : null, child);
74
74
  }) : rawChildren;
75
75
  var justifyContent = spread || alignInline;
76
+
77
+ // We're type coercing this as Compiled styles in an array isn't supported by the types
78
+ // But the runtime accepts it none-the-wiser. We can remove this entire block and replace
79
+ // it with cx(defaultStyles, focusRingStyles, xcssStyles) when we've moved away from Emotion.
80
+ var styles = grow ? [flexGrowMap[grow]].concat((0, _toConsumableArray2.default)(Array.isArray(xcss) ? xcss : [xcss])) : xcss;
76
81
  return (0, _react2.jsx)(_flex.default, {
77
82
  as: as,
78
83
  role: role,
@@ -81,10 +86,10 @@ var Inline = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef)(
81
86
  direction: "row",
82
87
  gap: space,
83
88
  rowGap: rowSpace,
84
- wrap: shouldWrap ? 'wrap' : undefined,
85
- xcss: grow ? [flexGrowMap[grow]].concat((0, _toConsumableArray2.default)(Array.isArray(xcss) ? xcss : [xcss])) :
89
+ wrap: shouldWrap ? 'wrap' : undefined
86
90
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
87
- xcss,
91
+ ,
92
+ xcss: styles,
88
93
  testId: testId,
89
94
  ref: ref
90
95
  }, children);
@@ -80,7 +80,7 @@ var UNSAFE_PRESSABLE = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref)
80
80
  action: 'clicked',
81
81
  componentName: componentName || 'Pressable',
82
82
  packageName: "@atlaskit/primitives",
83
- packageVersion: "3.0.0",
83
+ packageVersion: "3.2.0",
84
84
  analyticsData: analyticsContext,
85
85
  actionSubject: 'button'
86
86
  });
@@ -89,6 +89,10 @@ var UNSAFE_PRESSABLE = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref)
89
89
  var styles = [(0, _xcss.xcss)({
90
90
  cursor: isDisabled ? 'not-allowed' : 'pointer'
91
91
  }), focusRingStyles];
92
+
93
+ // We're type coercing this as Compiled styles in an array isn't supported by the types
94
+ // But the runtime accepts it none-the-wiser. We can remove this entire block and replace
95
+ // it with cx(defaultStyles, focusRingStyles, xcssStyles) when we've moved away from Emotion.
92
96
  styles = Array.isArray(xcssStyles) ? [].concat((0, _toConsumableArray2.default)(styles), (0, _toConsumableArray2.default)(xcssStyles)) : [].concat((0, _toConsumableArray2.default)(styles), [xcssStyles]);
93
97
  return /*#__PURE__*/_react.default.createElement(_box.default, (0, _extends2.default)({}, htmlAttributes, {
94
98
  as: "button",
@@ -50,16 +50,21 @@ var Stack = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef)(f
50
50
  xcss = _ref.xcss,
51
51
  role = _ref.role;
52
52
  var justifyContent = spread || alignBlock;
53
+
54
+ // We're type coercing this as Compiled styles in an array isn't supported by the types
55
+ // But the runtime accepts it none-the-wiser. We can remove this entire block and replace
56
+ // it with cx(defaultStyles, focusRingStyles, xcssStyles) when we've moved away from Emotion.
57
+ var styles = grow ? [flexGrowMap[grow]].concat((0, _toConsumableArray2.default)(Array.isArray(xcss) ? xcss : [xcss])) : xcss;
53
58
  return (0, _react2.jsx)(_flex.default, {
54
59
  as: as,
55
60
  role: role,
56
61
  gap: space,
57
62
  direction: "column",
58
63
  alignItems: alignItems,
59
- justifyContent: justifyContent,
60
- xcss: grow ? [flexGrowMap[grow]].concat((0, _toConsumableArray2.default)(Array.isArray(xcss) ? xcss : [xcss])) :
64
+ justifyContent: justifyContent
61
65
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
62
- xcss,
66
+ ,
67
+ xcss: styles,
63
68
  testId: testId,
64
69
  ref: ref
65
70
  }, children);
@@ -7,7 +7,8 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = void 0;
8
8
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
9
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
- var _react = require("@emotion/react");
10
+ var _react = require("react");
11
+ var _react2 = require("@emotion/react");
11
12
  var _tinyInvariant = _interopRequireDefault(require("tiny-invariant"));
12
13
  var _styleMaps = require("../xcss/style-maps.partial");
13
14
  var _surfaceProvider = require("./internal/surface-provider");
@@ -18,50 +19,62 @@ var asAllowlist = ['span', 'p', 'strong', 'em'];
18
19
  // We're doing this because our CSS reset can add top margins to elements such as `p` which is totally insane.
19
20
  // Long term we should remove those instances from the reset - it should be a reset to 0.
20
21
  // For now, at least we know <Text> will be unaffected by this.
21
- var resetStyles = (0, _react.css)({
22
+ var resetStyles = (0, _react2.css)({
22
23
  margin: 0
23
24
  });
24
25
  var variantStyles = _objectSpread(_objectSpread({}, _styleMaps.bodyTextStylesMap), _styleMaps.uiTextStylesMap);
25
- var strongStyles = (0, _react.css)({
26
+ var strongStyles = (0, _react2.css)({
26
27
  fontWeight: 'bold'
27
28
  });
28
- var emStyles = (0, _react.css)({
29
+ var emStyles = (0, _react2.css)({
29
30
  fontStyle: 'italic'
30
31
  });
31
32
  var textAlignMap = {
32
- center: (0, _react.css)({
33
+ center: (0, _react2.css)({
33
34
  textAlign: 'center'
34
35
  }),
35
- end: (0, _react.css)({
36
+ end: (0, _react2.css)({
36
37
  textAlign: 'end'
37
38
  }),
38
- start: (0, _react.css)({
39
+ start: (0, _react2.css)({
39
40
  textAlign: 'start'
40
41
  })
41
42
  };
42
- var truncationStyles = (0, _react.css)({
43
+ var truncationStyles = (0, _react2.css)({
43
44
  display: '-webkit-box',
44
45
  overflow: 'hidden',
45
46
  WebkitBoxOrient: 'vertical'
46
47
  });
47
48
  var wordBreakMap = {
48
- breakAll: (0, _react.css)({
49
+ breakAll: (0, _react2.css)({
49
50
  wordBreak: 'break-all'
50
51
  })
51
52
  };
53
+ var HasTextAncestorContext = /*#__PURE__*/(0, _react.createContext)(false);
54
+ var useHasTextAncestor = function useHasTextAncestor() {
55
+ return (0, _react.useContext)(HasTextAncestorContext);
56
+ };
52
57
 
53
58
  /**
54
59
  * Custom hook designed to abstract the parsing of the color props and make it clearer in the future how color is reconciled between themes and tokens.
55
60
  */
56
- var useColor = function useColor(colorProp) {
61
+ var useColor = function useColor(colorProp, hasTextAncestor) {
57
62
  var surface = (0, _surfaceProvider.useSurface)();
58
63
 
59
64
  /**
60
- * Where the color of the surface is inverted we override the user choice
65
+ * Where the color of the surface is inverted we always override the color
61
66
  * as there is no valid choice that is not covered by the override.
62
67
  */
63
- var color = _styleMaps.inverseColorMap.hasOwnProperty(surface) ? _styleMaps.inverseColorMap[surface] : colorProp;
64
- return color;
68
+ if (_styleMaps.inverseColorMap.hasOwnProperty(surface)) {
69
+ return _styleMaps.inverseColorMap[surface];
70
+ }
71
+ if (colorProp === 'inherit') {
72
+ return undefined;
73
+ }
74
+ if (!colorProp && hasTextAncestor) {
75
+ return undefined;
76
+ }
77
+ return colorProp || 'color.text';
65
78
  };
66
79
 
67
80
  /**
@@ -76,7 +89,8 @@ var useColor = function useColor(colorProp) {
76
89
  var Text = function Text(_ref) {
77
90
  var children = _ref.children,
78
91
  props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
79
- var asElement = props.as,
92
+ var _props$as = props.as,
93
+ Component = _props$as === void 0 ? 'span' : _props$as,
80
94
  colorProp = props.color,
81
95
  textAlign = props.textAlign,
82
96
  testId = props.testId,
@@ -84,10 +98,6 @@ var Text = function Text(_ref) {
84
98
  _props$variant = props.variant,
85
99
  variant = _props$variant === void 0 ? 'body' : _props$variant,
86
100
  weight = props.weight;
87
-
88
- // body variants -> p
89
- // ui variants -> span
90
- var Component = asElement || (variant.includes('body') ? 'p' : 'span');
91
101
  (0, _tinyInvariant.default)(asAllowlist.includes(Component), "@atlaskit/primitives: Text received an invalid \"as\" value of \"".concat(Component, "\""));
92
102
 
93
103
  // Remove the ability to bypass typescript errors for maxLines
@@ -95,14 +105,20 @@ var Text = function Text(_ref) {
95
105
  if ('maxLines' in props && variant.includes('body')) {
96
106
  maxLines = props.maxLines;
97
107
  }
98
- var color = useColor(colorProp);
99
- return (0, _react.jsx)(Component, {
100
- css: [resetStyles, variant && variantStyles[variant], color && _styleMaps.textColorStylesMap[color], maxLines && truncationStyles, maxLines === 1 && wordBreakMap.breakAll, textAlign && textAlignMap[textAlign], weight && _styleMaps.fontWeightStylesMap[weight], asElement === 'em' && emStyles, asElement === 'strong' && strongStyles],
108
+ var hasTextAncestor = useHasTextAncestor();
109
+ var color = useColor(colorProp, hasTextAncestor);
110
+ var component = (0, _react2.jsx)(Component, {
111
+ css: [resetStyles, variantStyles[variant], color && _styleMaps.textColorStylesMap[color], maxLines && truncationStyles, maxLines === 1 && wordBreakMap.breakAll, textAlign && textAlignMap[textAlign], weight && _styleMaps.fontWeightStylesMap[weight], Component === 'em' && emStyles, Component === 'strong' && strongStyles],
101
112
  style: {
102
113
  WebkitLineClamp: maxLines
103
114
  },
104
115
  "data-testid": testId,
105
116
  id: id
106
117
  }, children);
118
+ return hasTextAncestor ?
119
+ // no need to re-apply context if the text is already wrapped
120
+ component : (0, _react2.jsx)(HasTextAncestorContext.Provider, {
121
+ value: true
122
+ }, component);
107
123
  };
108
124
  var _default = exports.default = Text;
@@ -6,15 +6,15 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.tokensMap = exports.parseXcss = void 0;
8
8
  exports.xcss = xcss;
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
11
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
12
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
12
13
  var _react = require("@emotion/react");
13
14
  var _styleMaps = require("./style-maps.partial");
14
- /* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
15
-
16
- // eslint-disable-next-line import/no-extraneous-dependencies
17
-
15
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
16
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
17
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } /* eslint-disable @atlaskit/design-system/ensure-design-token-usage */ // eslint-disable-next-line import/no-extraneous-dependencies
18
18
  var tokensMap = exports.tokensMap = {
19
19
  backgroundColor: _styleMaps.backgroundColorMap,
20
20
  blockSize: _styleMaps.dimensionMap,
@@ -155,21 +155,59 @@ var baseXcss = function baseXcss(style) {
155
155
  };
156
156
 
157
157
  /**
158
- * @internal used in primitives
159
- * @returns a collection of styles that can be applied to the respective primitive
158
+ * Picks out runtime XCSS objects and build-time XCSS strings. This is needed
159
+ * to supported both Emotion and Compiled styles until we've fully migrated
160
+ * to Compiled.
161
+ *
162
+ * @private
163
+ * @deprecated
160
164
  */
161
-
162
165
  var parseXcss = exports.parseXcss = function parseXcss(args) {
163
166
  if (Array.isArray(args)) {
164
- return args.map(function (x) {
165
- return x && parseXcss(x);
166
- }).filter(Boolean);
167
+ var emotion = [];
168
+ var staticArr = [];
169
+ var _iterator = _createForOfIteratorHelper(args),
170
+ _step;
171
+ try {
172
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
173
+ var arg = _step.value;
174
+ var result = parseXcss(arg);
175
+ if (result.emotion) {
176
+ emotion.push.apply(emotion, (0, _toConsumableArray2.default)(result.emotion));
177
+ }
178
+ if (result.static) {
179
+ staticArr.push(result.static);
180
+ }
181
+ }
182
+ } catch (err) {
183
+ _iterator.e(err);
184
+ } finally {
185
+ _iterator.f();
186
+ }
187
+ return {
188
+ emotion: emotion,
189
+ static: staticArr.join(' ')
190
+ };
167
191
  }
168
- var styles = args[uniqueSymbol];
169
- if ((typeof process === "undefined" ? "undefined" : (0, _typeof2.default)(process)) && process.env.NODE_ENV === 'development' && typeof styles === 'undefined') {
170
- throw new Error('Styles generated from unsafe source, use the `xcss` export from `@atlaskit/primitives`.');
192
+ var objArgs = args;
193
+ var _ref4 = objArgs || {},
194
+ styles = _ref4[uniqueSymbol];
195
+ if (styles) {
196
+ return {
197
+ emotion: [styles]
198
+ };
199
+ }
200
+ if (args) {
201
+ // We use string interpolation here instead of .toString() just
202
+ // in case the resulting object doesn't have the method available.
203
+ var stringifiedArgs = "".concat(args);
204
+ if (stringifiedArgs) {
205
+ return {
206
+ static: stringifiedArgs
207
+ };
208
+ }
171
209
  }
172
- return styles;
210
+ return {};
173
211
  };
174
212
 
175
213
  // Media queries should not contain nested media queries
@@ -62,13 +62,15 @@ const Anchor = ({
62
62
  action: 'clicked',
63
63
  componentName: componentName || 'Anchor',
64
64
  packageName: "@atlaskit/primitives",
65
- packageVersion: "3.0.0",
65
+ packageVersion: "3.2.0",
66
66
  analyticsData: analyticsContext,
67
67
  actionSubject: 'link'
68
68
  });
69
69
  const RouterLink = useRouterLink();
70
70
 
71
- // Combine default styles with supplied styles. XCSS does not support deep nested arrays
71
+ // We're type coercing this as Compiled styles in an array isn't supported by the types
72
+ // But the runtime accepts it none-the-wiser. We can remove this entire block and replace
73
+ // it with cx(defaultStyles, focusRingStyles, xcssStyles) when we've moved away from Emotion.
72
74
  const styles = Array.isArray(xcssStyles) ? [defaultStyles, focusRingStyles, ...xcssStyles] : [defaultStyles, focusRingStyles, xcssStyles];
73
75
  const isExternal = typeof href === 'string' && IS_EXTERNAL_LINK_REGEX.test(href);
74
76
  const isNonHttpBased = typeof href === 'string' && IS_NON_HTTP_BASED.test(href);
@@ -59,11 +59,12 @@ const Bleed = /*#__PURE__*/React.memo(({
59
59
  all,
60
60
  xcss
61
61
  }) => {
62
- const xcssStyles = xcss && parseXcss(xcss);
62
+ const resolvedStyles = parseXcss(xcss);
63
63
  return jsx("div", {
64
+ className: resolvedStyles.static,
64
65
  css: [baseStyles, (inline || all) && inlineBleedMap[inline || all], (block || all) && blockBleedMap[block || all],
65
66
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
66
- xcssStyles],
67
+ resolvedStyles.emotion],
67
68
  "data-testid": testId
68
69
  }, children);
69
70
  });
@@ -21,7 +21,7 @@ import { SurfaceContext } from './internal/surface-provider';
21
21
  * - [Usage](https://atlassian.design/components/primitives/box/usage)
22
22
  */
23
23
  export const Box = /*#__PURE__*/forwardRef(({
24
- as = 'div',
24
+ as: Component = 'div',
25
25
  children,
26
26
  backgroundColor,
27
27
  padding,
@@ -36,26 +36,26 @@ export const Box = /*#__PURE__*/forwardRef(({
36
36
  xcss,
37
37
  ...htmlAttributes
38
38
  }, ref) => {
39
- const Component = as;
40
39
  // This is to remove className from safeHtmlAttributes
41
40
  // @ts-expect-error className doesn't exist in the prop definition but we want to ensure it cannot be applied even if types are bypassed
42
41
  const {
43
42
  className: _spreadClass,
44
43
  ...safeHtmlAttributes
45
44
  } = htmlAttributes;
46
- const className = xcss && parseXcss(xcss);
45
+ const resolvedStyles = parseXcss(xcss);
47
46
  const node =
48
47
  // @ts-expect-error Expression produces a union type that is too complex to represent. I think this is unavoidable
49
48
  jsx(Component, _extends({
50
49
  style: style
51
50
  // @ts-expect-error Expression produces a union type that is too complex to represent. We may be able to narrow the type here but unsure.
52
51
  ,
53
- ref: ref
52
+ ref: ref,
53
+ className: resolvedStyles.static
54
54
  // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
55
55
  }, safeHtmlAttributes, {
56
56
  css: [baseStyles, backgroundColor && backgroundColorStylesMap[backgroundColor], isSurfaceColorToken(backgroundColor) && surfaceColorStylesMap[backgroundColor], padding && paddingStylesMap.padding[padding], paddingBlock && paddingStylesMap.paddingBlock[paddingBlock], paddingBlockStart && paddingStylesMap.paddingBlockStart[paddingBlockStart], paddingBlockEnd && paddingStylesMap.paddingBlockEnd[paddingBlockEnd], paddingInline && paddingStylesMap.paddingInline[paddingInline], paddingInlineStart && paddingStylesMap.paddingInlineStart[paddingInlineStart], paddingInlineEnd && paddingStylesMap.paddingInlineEnd[paddingInlineEnd],
57
57
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
58
- className],
58
+ resolvedStyles.emotion],
59
59
  "data-testid": testId
60
60
  }), children);
61
61
  return backgroundColor ? jsx(SurfaceContext.Provider, {
@@ -98,12 +98,13 @@ const Flex = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
98
98
  wrap,
99
99
  xcss
100
100
  }, ref) => {
101
- const xcssClassName = xcss && parseXcss(xcss);
101
+ const resolvedStyles = parseXcss(xcss);
102
102
  return jsx(Component, {
103
103
  role: role,
104
+ className: resolvedStyles.static,
104
105
  css: [baseStyles, gap && spaceStylesMap.gap[gap], columnGap && spaceStylesMap.columnGap[columnGap], rowGap && spaceStylesMap.rowGap[rowGap], alignItems && alignItemsMap[alignItems], direction && flexDirectionMap[direction], justifyContent && justifyContentMap[justifyContent], wrap && flexWrapMap[wrap],
105
106
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
106
- xcssClassName && xcssClassName],
107
+ resolvedStyles.emotion],
107
108
  "data-testid": testId,
108
109
  ref: ref
109
110
  }, children);
@@ -144,7 +144,7 @@ const Grid = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
144
144
  xcss
145
145
  }, ref) => {
146
146
  const Component = as || 'div';
147
- const xcssClassName = xcss && parseXcss(xcss);
147
+ const resolvedStyles = parseXcss(xcss);
148
148
 
149
149
  /**
150
150
  * We use CSS variables to allow for dynamic grid templates instead of dynamically setting to `props.style`
@@ -163,9 +163,10 @@ const Grid = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
163
163
  id: id,
164
164
  role: role,
165
165
  style: style,
166
+ className: resolvedStyles.static,
166
167
  css: [baseStyles, gap && spaceStylesMap.gap[gap], columnGap && spaceStylesMap.columnGap[columnGap], rowGap && spaceStylesMap.rowGap[rowGap], alignItems && alignItemsMap[alignItems], alignContent && alignContentMap[alignContent], justifyContent && justifyContentMap[justifyContent], autoFlow && gridAutoFlowMap[autoFlow],
167
168
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
168
- xcssClassName],
169
+ resolvedStyles.emotion],
169
170
  "data-testid": testId,
170
171
  ref: ref
171
172
  }, children);
@@ -62,6 +62,11 @@ const Inline = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
62
62
  }, separator && index > 0 ? separatorComponent : null, child);
63
63
  }) : rawChildren;
64
64
  const justifyContent = spread || alignInline;
65
+
66
+ // We're type coercing this as Compiled styles in an array isn't supported by the types
67
+ // But the runtime accepts it none-the-wiser. We can remove this entire block and replace
68
+ // it with cx(defaultStyles, focusRingStyles, xcssStyles) when we've moved away from Emotion.
69
+ const styles = grow ? [flexGrowMap[grow], ...(Array.isArray(xcss) ? xcss : [xcss])] : xcss;
65
70
  return jsx(Flex, {
66
71
  as: as,
67
72
  role: role,
@@ -70,10 +75,10 @@ const Inline = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
70
75
  direction: "row",
71
76
  gap: space,
72
77
  rowGap: rowSpace,
73
- wrap: shouldWrap ? 'wrap' : undefined,
74
- xcss: grow ? [flexGrowMap[grow], ...(Array.isArray(xcss) ? xcss : [xcss])] :
78
+ wrap: shouldWrap ? 'wrap' : undefined
75
79
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
76
- xcss,
80
+ ,
81
+ xcss: styles,
77
82
  testId: testId,
78
83
  ref: ref
79
84
  }, children);
@@ -66,7 +66,7 @@ const UNSAFE_PRESSABLE = /*#__PURE__*/forwardRef(({
66
66
  action: 'clicked',
67
67
  componentName: componentName || 'Pressable',
68
68
  packageName: "@atlaskit/primitives",
69
- packageVersion: "3.0.0",
69
+ packageVersion: "3.2.0",
70
70
  analyticsData: analyticsContext,
71
71
  actionSubject: 'button'
72
72
  });
@@ -75,6 +75,10 @@ const UNSAFE_PRESSABLE = /*#__PURE__*/forwardRef(({
75
75
  let styles = [xcss({
76
76
  cursor: isDisabled ? 'not-allowed' : 'pointer'
77
77
  }), focusRingStyles];
78
+
79
+ // We're type coercing this as Compiled styles in an array isn't supported by the types
80
+ // But the runtime accepts it none-the-wiser. We can remove this entire block and replace
81
+ // it with cx(defaultStyles, focusRingStyles, xcssStyles) when we've moved away from Emotion.
78
82
  styles = Array.isArray(xcssStyles) ? [...styles, ...xcssStyles] : [...styles, xcssStyles];
79
83
  return /*#__PURE__*/React.createElement(Box, _extends({}, htmlAttributes, {
80
84
  as: "button",