@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
@@ -41,16 +41,21 @@ const Stack = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
41
41
  role
42
42
  }, ref) => {
43
43
  const justifyContent = spread || alignBlock;
44
+
45
+ // We're type coercing this as Compiled styles in an array isn't supported by the types
46
+ // But the runtime accepts it none-the-wiser. We can remove this entire block and replace
47
+ // it with cx(defaultStyles, focusRingStyles, xcssStyles) when we've moved away from Emotion.
48
+ const styles = grow ? [flexGrowMap[grow], ...(Array.isArray(xcss) ? xcss : [xcss])] : xcss;
44
49
  return jsx(Flex, {
45
50
  as: as,
46
51
  role: role,
47
52
  gap: space,
48
53
  direction: "column",
49
54
  alignItems: alignItems,
50
- justifyContent: justifyContent,
51
- xcss: grow ? [flexGrowMap[grow], ...(Array.isArray(xcss) ? xcss : [xcss])] :
55
+ justifyContent: justifyContent
52
56
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
53
- xcss,
57
+ ,
58
+ xcss: styles,
54
59
  testId: testId,
55
60
  ref: ref
56
61
  }, children);
@@ -1,5 +1,5 @@
1
1
  /** @jsx jsx */
2
-
2
+ import { createContext, useContext } from 'react';
3
3
  import { css, jsx } from '@emotion/react';
4
4
  import invariant from 'tiny-invariant';
5
5
  import { bodyTextStylesMap, fontWeightStylesMap, inverseColorMap, textColorStylesMap, uiTextStylesMap } from '../xcss/style-maps.partial';
@@ -42,19 +42,29 @@ const wordBreakMap = {
42
42
  wordBreak: 'break-all'
43
43
  })
44
44
  };
45
+ const HasTextAncestorContext = /*#__PURE__*/createContext(false);
46
+ const useHasTextAncestor = () => useContext(HasTextAncestorContext);
45
47
 
46
48
  /**
47
49
  * 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.
48
50
  */
49
- const useColor = colorProp => {
51
+ const useColor = (colorProp, hasTextAncestor) => {
50
52
  const surface = useSurface();
51
53
 
52
54
  /**
53
- * Where the color of the surface is inverted we override the user choice
55
+ * Where the color of the surface is inverted we always override the color
54
56
  * as there is no valid choice that is not covered by the override.
55
57
  */
56
- const color = inverseColorMap.hasOwnProperty(surface) ? inverseColorMap[surface] : colorProp;
57
- return color;
58
+ if (inverseColorMap.hasOwnProperty(surface)) {
59
+ return inverseColorMap[surface];
60
+ }
61
+ if (colorProp === 'inherit') {
62
+ return undefined;
63
+ }
64
+ if (!colorProp && hasTextAncestor) {
65
+ return undefined;
66
+ }
67
+ return colorProp || 'color.text';
58
68
  };
59
69
 
60
70
  /**
@@ -71,7 +81,7 @@ const Text = ({
71
81
  ...props
72
82
  }) => {
73
83
  const {
74
- as: asElement,
84
+ as: Component = 'span',
75
85
  color: colorProp,
76
86
  textAlign,
77
87
  testId,
@@ -79,10 +89,6 @@ const Text = ({
79
89
  variant = 'body',
80
90
  weight
81
91
  } = props;
82
-
83
- // body variants -> p
84
- // ui variants -> span
85
- const Component = asElement || (variant.includes('body') ? 'p' : 'span');
86
92
  invariant(asAllowlist.includes(Component), `@atlaskit/primitives: Text received an invalid "as" value of "${Component}"`);
87
93
 
88
94
  // Remove the ability to bypass typescript errors for maxLines
@@ -90,14 +96,20 @@ const Text = ({
90
96
  if ('maxLines' in props && variant.includes('body')) {
91
97
  maxLines = props.maxLines;
92
98
  }
93
- const color = useColor(colorProp);
94
- return jsx(Component, {
95
- css: [resetStyles, variant && variantStyles[variant], color && textColorStylesMap[color], maxLines && truncationStyles, maxLines === 1 && wordBreakMap.breakAll, textAlign && textAlignMap[textAlign], weight && fontWeightStylesMap[weight], asElement === 'em' && emStyles, asElement === 'strong' && strongStyles],
99
+ const hasTextAncestor = useHasTextAncestor();
100
+ const color = useColor(colorProp, hasTextAncestor);
101
+ const component = jsx(Component, {
102
+ css: [resetStyles, variantStyles[variant], color && textColorStylesMap[color], maxLines && truncationStyles, maxLines === 1 && wordBreakMap.breakAll, textAlign && textAlignMap[textAlign], weight && fontWeightStylesMap[weight], Component === 'em' && emStyles, Component === 'strong' && strongStyles],
96
103
  style: {
97
104
  WebkitLineClamp: maxLines
98
105
  },
99
106
  "data-testid": testId,
100
107
  id: id
101
108
  }, children);
109
+ return hasTextAncestor ?
110
+ // no need to re-apply context if the text is already wrapped
111
+ component : jsx(HasTextAncestorContext.Provider, {
112
+ value: true
113
+ }, component);
102
114
  };
103
115
  export default Text;
@@ -141,21 +141,51 @@ const baseXcss = style => {
141
141
  };
142
142
 
143
143
  /**
144
- * @internal used in primitives
145
- * @returns a collection of styles that can be applied to the respective primitive
144
+ * Picks out runtime XCSS objects and build-time XCSS strings. This is needed
145
+ * to supported both Emotion and Compiled styles until we've fully migrated
146
+ * to Compiled.
147
+ *
148
+ * @private
149
+ * @deprecated
146
150
  */
147
-
148
151
  export const parseXcss = args => {
149
152
  if (Array.isArray(args)) {
150
- return args.map(x => x && parseXcss(x)).filter(Boolean);
153
+ const emotion = [];
154
+ const staticArr = [];
155
+ for (const arg of args) {
156
+ const result = parseXcss(arg);
157
+ if (result.emotion) {
158
+ emotion.push(...result.emotion);
159
+ }
160
+ if (result.static) {
161
+ staticArr.push(result.static);
162
+ }
163
+ }
164
+ return {
165
+ emotion,
166
+ static: staticArr.join(' ')
167
+ };
151
168
  }
169
+ const objArgs = args;
152
170
  const {
153
171
  [uniqueSymbol]: styles
154
- } = args;
155
- if (typeof process && process.env.NODE_ENV === 'development' && typeof styles === 'undefined') {
156
- throw new Error('Styles generated from unsafe source, use the `xcss` export from `@atlaskit/primitives`.');
172
+ } = objArgs || {};
173
+ if (styles) {
174
+ return {
175
+ emotion: [styles]
176
+ };
177
+ }
178
+ if (args) {
179
+ // We use string interpolation here instead of .toString() just
180
+ // in case the resulting object doesn't have the method available.
181
+ const stringifiedArgs = `${args}`;
182
+ if (stringifiedArgs) {
183
+ return {
184
+ static: stringifiedArgs
185
+ };
186
+ }
157
187
  }
158
- return styles;
188
+ return {};
159
189
  };
160
190
 
161
191
  // Media queries should not contain nested media queries
@@ -66,13 +66,15 @@ var Anchor = function Anchor(_ref, ref) {
66
66
  action: 'clicked',
67
67
  componentName: componentName || 'Anchor',
68
68
  packageName: "@atlaskit/primitives",
69
- packageVersion: "3.0.0",
69
+ packageVersion: "3.2.0",
70
70
  analyticsData: analyticsContext,
71
71
  actionSubject: 'link'
72
72
  });
73
73
  var RouterLink = useRouterLink();
74
74
 
75
- // Combine default styles with supplied styles. XCSS does not support deep nested arrays
75
+ // We're type coercing this as Compiled styles in an array isn't supported by the types
76
+ // But the runtime accepts it none-the-wiser. We can remove this entire block and replace
77
+ // it with cx(defaultStyles, focusRingStyles, xcssStyles) when we've moved away from Emotion.
76
78
  var styles = Array.isArray(xcssStyles) ? [defaultStyles, focusRingStyles].concat(_toConsumableArray(xcssStyles)) : [defaultStyles, focusRingStyles, xcssStyles];
77
79
  var isExternal = typeof href === 'string' && IS_EXTERNAL_LINK_REGEX.test(href);
78
80
  var isNonHttpBased = typeof href === 'string' && IS_NON_HTTP_BASED.test(href);
@@ -58,11 +58,12 @@ var Bleed = /*#__PURE__*/React.memo(function (_ref) {
58
58
  block = _ref.block,
59
59
  all = _ref.all,
60
60
  xcss = _ref.xcss;
61
- var xcssStyles = xcss && parseXcss(xcss);
61
+ var resolvedStyles = parseXcss(xcss);
62
62
  return jsx("div", {
63
+ className: resolvedStyles.static,
63
64
  css: [baseStyles, (inline || all) && inlineBleedMap[inline || all], (block || all) && blockBleedMap[block || all],
64
65
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
65
- xcssStyles],
66
+ resolvedStyles.emotion],
66
67
  "data-testid": testId
67
68
  }, children);
68
69
  });
@@ -25,7 +25,7 @@ import { SurfaceContext } from './internal/surface-provider';
25
25
  */
26
26
  export var Box = /*#__PURE__*/forwardRef(function (_ref, ref) {
27
27
  var _ref$as = _ref.as,
28
- as = _ref$as === void 0 ? 'div' : _ref$as,
28
+ Component = _ref$as === void 0 ? 'div' : _ref$as,
29
29
  children = _ref.children,
30
30
  backgroundColor = _ref.backgroundColor,
31
31
  padding = _ref.padding,
@@ -39,24 +39,24 @@ export var Box = /*#__PURE__*/forwardRef(function (_ref, ref) {
39
39
  testId = _ref.testId,
40
40
  xcss = _ref.xcss,
41
41
  htmlAttributes = _objectWithoutProperties(_ref, _excluded);
42
- var Component = as;
43
42
  // This is to remove className from safeHtmlAttributes
44
43
  // @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
45
44
  var _spreadClass = htmlAttributes.className,
46
45
  safeHtmlAttributes = _objectWithoutProperties(htmlAttributes, _excluded2);
47
- var className = xcss && parseXcss(xcss);
46
+ var resolvedStyles = parseXcss(xcss);
48
47
  var node =
49
48
  // @ts-expect-error Expression produces a union type that is too complex to represent. I think this is unavoidable
50
49
  jsx(Component, _extends({
51
50
  style: style
52
51
  // @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.
53
52
  ,
54
- ref: ref
53
+ ref: ref,
54
+ className: resolvedStyles.static
55
55
  // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
56
56
  }, safeHtmlAttributes, {
57
57
  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],
58
58
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
59
- className],
59
+ resolvedStyles.emotion],
60
60
  "data-testid": testId
61
61
  }), children);
62
62
  return backgroundColor ? jsx(SurfaceContext.Provider, {
@@ -98,12 +98,13 @@ var Flex = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_ref, ref) {
98
98
  direction = _ref.direction,
99
99
  wrap = _ref.wrap,
100
100
  xcss = _ref.xcss;
101
- var xcssClassName = xcss && parseXcss(xcss);
101
+ var 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 @@ var Grid = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_ref, ref) {
144
144
  gridTemplateColumns = _ref.templateColumns,
145
145
  xcss = _ref.xcss;
146
146
  var Component = as || 'div';
147
- var xcssClassName = xcss && parseXcss(xcss);
147
+ var 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`
@@ -164,9 +164,10 @@ var Grid = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_ref, ref) {
164
164
  id: id,
165
165
  role: role,
166
166
  style: style,
167
+ className: resolvedStyles.static,
167
168
  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],
168
169
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
169
- xcssClassName],
170
+ resolvedStyles.emotion],
170
171
  "data-testid": testId,
171
172
  ref: ref
172
173
  }, children);
@@ -65,6 +65,11 @@ var Inline = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_ref2, ref) {
65
65
  }, separator && index > 0 ? separatorComponent : null, child);
66
66
  }) : rawChildren;
67
67
  var justifyContent = spread || alignInline;
68
+
69
+ // We're type coercing this as Compiled styles in an array isn't supported by the types
70
+ // But the runtime accepts it none-the-wiser. We can remove this entire block and replace
71
+ // it with cx(defaultStyles, focusRingStyles, xcssStyles) when we've moved away from Emotion.
72
+ var styles = grow ? [flexGrowMap[grow]].concat(_toConsumableArray(Array.isArray(xcss) ? xcss : [xcss])) : xcss;
68
73
  return jsx(Flex, {
69
74
  as: as,
70
75
  role: role,
@@ -73,10 +78,10 @@ var Inline = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_ref2, ref) {
73
78
  direction: "row",
74
79
  gap: space,
75
80
  rowGap: rowSpace,
76
- wrap: shouldWrap ? 'wrap' : undefined,
77
- xcss: grow ? [flexGrowMap[grow]].concat(_toConsumableArray(Array.isArray(xcss) ? xcss : [xcss])) :
81
+ wrap: shouldWrap ? 'wrap' : undefined
78
82
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
79
- xcss,
83
+ ,
84
+ xcss: styles,
80
85
  testId: testId,
81
86
  ref: ref
82
87
  }, children);
@@ -70,7 +70,7 @@ var UNSAFE_PRESSABLE = /*#__PURE__*/forwardRef(function (_ref, ref) {
70
70
  action: 'clicked',
71
71
  componentName: componentName || 'Pressable',
72
72
  packageName: "@atlaskit/primitives",
73
- packageVersion: "3.0.0",
73
+ packageVersion: "3.2.0",
74
74
  analyticsData: analyticsContext,
75
75
  actionSubject: 'button'
76
76
  });
@@ -79,6 +79,10 @@ var UNSAFE_PRESSABLE = /*#__PURE__*/forwardRef(function (_ref, ref) {
79
79
  var styles = [xcss({
80
80
  cursor: isDisabled ? 'not-allowed' : 'pointer'
81
81
  }), focusRingStyles];
82
+
83
+ // We're type coercing this as Compiled styles in an array isn't supported by the types
84
+ // But the runtime accepts it none-the-wiser. We can remove this entire block and replace
85
+ // it with cx(defaultStyles, focusRingStyles, xcssStyles) when we've moved away from Emotion.
82
86
  styles = Array.isArray(xcssStyles) ? [].concat(_toConsumableArray(styles), _toConsumableArray(xcssStyles)) : [].concat(_toConsumableArray(styles), [xcssStyles]);
83
87
  return /*#__PURE__*/React.createElement(Box, _extends({}, htmlAttributes, {
84
88
  as: "button",
@@ -42,16 +42,21 @@ var Stack = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_ref, ref) {
42
42
  xcss = _ref.xcss,
43
43
  role = _ref.role;
44
44
  var justifyContent = spread || alignBlock;
45
+
46
+ // We're type coercing this as Compiled styles in an array isn't supported by the types
47
+ // But the runtime accepts it none-the-wiser. We can remove this entire block and replace
48
+ // it with cx(defaultStyles, focusRingStyles, xcssStyles) when we've moved away from Emotion.
49
+ var styles = grow ? [flexGrowMap[grow]].concat(_toConsumableArray(Array.isArray(xcss) ? xcss : [xcss])) : xcss;
45
50
  return jsx(Flex, {
46
51
  as: as,
47
52
  role: role,
48
53
  gap: space,
49
54
  direction: "column",
50
55
  alignItems: alignItems,
51
- justifyContent: justifyContent,
52
- xcss: grow ? [flexGrowMap[grow]].concat(_toConsumableArray(Array.isArray(xcss) ? xcss : [xcss])) :
56
+ justifyContent: justifyContent
53
57
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
54
- xcss,
58
+ ,
59
+ xcss: styles,
55
60
  testId: testId,
56
61
  ref: ref
57
62
  }, children);
@@ -4,7 +4,7 @@ var _excluded = ["children"];
4
4
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
5
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
6
  /** @jsx jsx */
7
-
7
+ import { createContext, useContext } from 'react';
8
8
  import { css, jsx } from '@emotion/react';
9
9
  import invariant from 'tiny-invariant';
10
10
  import { bodyTextStylesMap, fontWeightStylesMap, inverseColorMap, textColorStylesMap, uiTextStylesMap } from '../xcss/style-maps.partial';
@@ -44,19 +44,31 @@ var wordBreakMap = {
44
44
  wordBreak: 'break-all'
45
45
  })
46
46
  };
47
+ var HasTextAncestorContext = /*#__PURE__*/createContext(false);
48
+ var useHasTextAncestor = function useHasTextAncestor() {
49
+ return useContext(HasTextAncestorContext);
50
+ };
47
51
 
48
52
  /**
49
53
  * 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.
50
54
  */
51
- var useColor = function useColor(colorProp) {
55
+ var useColor = function useColor(colorProp, hasTextAncestor) {
52
56
  var surface = useSurface();
53
57
 
54
58
  /**
55
- * Where the color of the surface is inverted we override the user choice
59
+ * Where the color of the surface is inverted we always override the color
56
60
  * as there is no valid choice that is not covered by the override.
57
61
  */
58
- var color = inverseColorMap.hasOwnProperty(surface) ? inverseColorMap[surface] : colorProp;
59
- return color;
62
+ if (inverseColorMap.hasOwnProperty(surface)) {
63
+ return inverseColorMap[surface];
64
+ }
65
+ if (colorProp === 'inherit') {
66
+ return undefined;
67
+ }
68
+ if (!colorProp && hasTextAncestor) {
69
+ return undefined;
70
+ }
71
+ return colorProp || 'color.text';
60
72
  };
61
73
 
62
74
  /**
@@ -71,7 +83,8 @@ var useColor = function useColor(colorProp) {
71
83
  var Text = function Text(_ref) {
72
84
  var children = _ref.children,
73
85
  props = _objectWithoutProperties(_ref, _excluded);
74
- var asElement = props.as,
86
+ var _props$as = props.as,
87
+ Component = _props$as === void 0 ? 'span' : _props$as,
75
88
  colorProp = props.color,
76
89
  textAlign = props.textAlign,
77
90
  testId = props.testId,
@@ -79,10 +92,6 @@ var Text = function Text(_ref) {
79
92
  _props$variant = props.variant,
80
93
  variant = _props$variant === void 0 ? 'body' : _props$variant,
81
94
  weight = props.weight;
82
-
83
- // body variants -> p
84
- // ui variants -> span
85
- var Component = asElement || (variant.includes('body') ? 'p' : 'span');
86
95
  invariant(asAllowlist.includes(Component), "@atlaskit/primitives: Text received an invalid \"as\" value of \"".concat(Component, "\""));
87
96
 
88
97
  // Remove the ability to bypass typescript errors for maxLines
@@ -90,14 +99,20 @@ var Text = function Text(_ref) {
90
99
  if ('maxLines' in props && variant.includes('body')) {
91
100
  maxLines = props.maxLines;
92
101
  }
93
- var color = useColor(colorProp);
94
- return jsx(Component, {
95
- css: [resetStyles, variant && variantStyles[variant], color && textColorStylesMap[color], maxLines && truncationStyles, maxLines === 1 && wordBreakMap.breakAll, textAlign && textAlignMap[textAlign], weight && fontWeightStylesMap[weight], asElement === 'em' && emStyles, asElement === 'strong' && strongStyles],
102
+ var hasTextAncestor = useHasTextAncestor();
103
+ var color = useColor(colorProp, hasTextAncestor);
104
+ var component = jsx(Component, {
105
+ css: [resetStyles, variantStyles[variant], color && textColorStylesMap[color], maxLines && truncationStyles, maxLines === 1 && wordBreakMap.breakAll, textAlign && textAlignMap[textAlign], weight && fontWeightStylesMap[weight], Component === 'em' && emStyles, Component === 'strong' && strongStyles],
96
106
  style: {
97
107
  WebkitLineClamp: maxLines
98
108
  },
99
109
  "data-testid": testId,
100
110
  id: id
101
111
  }, children);
112
+ return hasTextAncestor ?
113
+ // no need to re-apply context if the text is already wrapped
114
+ component : jsx(HasTextAncestorContext.Provider, {
115
+ value: true
116
+ }, component);
102
117
  };
103
118
  export default Text;
@@ -1,6 +1,10 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
1
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
3
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
4
  import _typeof from "@babel/runtime/helpers/typeof";
5
+ 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; } } }; }
6
+ 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); }
7
+ 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; }
4
8
  /* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
5
9
  import { css as cssEmotion } from '@emotion/react';
6
10
 
@@ -147,21 +151,59 @@ var baseXcss = function baseXcss(style) {
147
151
  };
148
152
 
149
153
  /**
150
- * @internal used in primitives
151
- * @returns a collection of styles that can be applied to the respective primitive
154
+ * Picks out runtime XCSS objects and build-time XCSS strings. This is needed
155
+ * to supported both Emotion and Compiled styles until we've fully migrated
156
+ * to Compiled.
157
+ *
158
+ * @private
159
+ * @deprecated
152
160
  */
153
-
154
161
  export var parseXcss = function parseXcss(args) {
155
162
  if (Array.isArray(args)) {
156
- return args.map(function (x) {
157
- return x && parseXcss(x);
158
- }).filter(Boolean);
163
+ var emotion = [];
164
+ var staticArr = [];
165
+ var _iterator = _createForOfIteratorHelper(args),
166
+ _step;
167
+ try {
168
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
169
+ var arg = _step.value;
170
+ var result = parseXcss(arg);
171
+ if (result.emotion) {
172
+ emotion.push.apply(emotion, _toConsumableArray(result.emotion));
173
+ }
174
+ if (result.static) {
175
+ staticArr.push(result.static);
176
+ }
177
+ }
178
+ } catch (err) {
179
+ _iterator.e(err);
180
+ } finally {
181
+ _iterator.f();
182
+ }
183
+ return {
184
+ emotion: emotion,
185
+ static: staticArr.join(' ')
186
+ };
187
+ }
188
+ var objArgs = args;
189
+ var _ref4 = objArgs || {},
190
+ styles = _ref4[uniqueSymbol];
191
+ if (styles) {
192
+ return {
193
+ emotion: [styles]
194
+ };
159
195
  }
160
- var styles = args[uniqueSymbol];
161
- if ((typeof process === "undefined" ? "undefined" : _typeof(process)) && process.env.NODE_ENV === 'development' && typeof styles === 'undefined') {
162
- throw new Error('Styles generated from unsafe source, use the `xcss` export from `@atlaskit/primitives`.');
196
+ if (args) {
197
+ // We use string interpolation here instead of .toString() just
198
+ // in case the resulting object doesn't have the method available.
199
+ var stringifiedArgs = "".concat(args);
200
+ if (stringifiedArgs) {
201
+ return {
202
+ static: stringifiedArgs
203
+ };
204
+ }
163
205
  }
164
- return styles;
206
+ return {};
165
207
  };
166
208
 
167
209
  // Media queries should not contain nested media queries
@@ -100,11 +100,11 @@ declare const Flex: import("react").MemoExoticComponent<import("react").ForwardR
100
100
  /**
101
101
  * Used to align children along the main axis.
102
102
  */
103
- justifyContent?: "space-around" | "space-between" | "space-evenly" | "stretch" | "center" | "end" | "start" | undefined;
103
+ justifyContent?: "center" | "space-around" | "space-between" | "space-evenly" | "stretch" | "end" | "start" | undefined;
104
104
  /**
105
105
  * Used to align children along the cross axis.
106
106
  */
107
- alignItems?: "stretch" | "center" | "end" | "start" | "baseline" | undefined;
107
+ alignItems?: "center" | "stretch" | "end" | "start" | "baseline" | undefined;
108
108
  /**
109
109
  * Represents the space between each child.
110
110
  */
@@ -136,11 +136,11 @@ declare const Grid: import("react").MemoExoticComponent<import("react").ForwardR
136
136
  /**
137
137
  * Used to align children along the inline axis.
138
138
  */
139
- justifyContent?: "space-around" | "space-between" | "space-evenly" | "stretch" | "center" | "end" | "start" | undefined;
139
+ justifyContent?: "center" | "space-around" | "space-between" | "space-evenly" | "stretch" | "end" | "start" | undefined;
140
140
  /**
141
141
  * Used to align the grid along the inline axis.
142
142
  */
143
- justifyItems?: "stretch" | "center" | "end" | "start" | undefined;
143
+ justifyItems?: "center" | "stretch" | "end" | "start" | undefined;
144
144
  /**
145
145
  * Used to align children along the block axis.
146
146
  */
@@ -148,7 +148,7 @@ declare const Grid: import("react").MemoExoticComponent<import("react").ForwardR
148
148
  /**
149
149
  * Used to align the grid along the block axis.
150
150
  */
151
- alignContent?: "space-around" | "space-between" | "space-evenly" | "stretch" | "center" | "end" | "start" | undefined;
151
+ alignContent?: "center" | "space-around" | "space-between" | "space-evenly" | "stretch" | "end" | "start" | undefined;
152
152
  /**
153
153
  * Represents the space between each column.
154
154
  */
@@ -63,5 +63,5 @@ declare const UNSAFE_PRESSABLE: React.ForwardRefExoticComponent<Pick<Omit<BoxPro
63
63
  * Additional information to be included in the `context` of analytics events that come from pressable.
64
64
  */
65
65
  analyticsContext?: Record<string, any> | undefined;
66
- }, "padding" | "paddingBlock" | "paddingBlockStart" | "paddingBlockEnd" | "paddingInline" | "paddingInlineStart" | "paddingInlineEnd" | "backgroundColor" | "color" | "translate" | "key" | "value" | "hidden" | "children" | "form" | "slot" | "title" | "name" | "type" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "radioGroup" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "autoFocus" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "testId" | "xcss" | "data-testid" | "isDisabled" | "interactionName" | "componentName" | "analyticsContext"> & React.RefAttributes<HTMLButtonElement>>;
66
+ }, "padding" | "paddingBlock" | "paddingBlockStart" | "paddingBlockEnd" | "paddingInline" | "paddingInlineStart" | "paddingInlineEnd" | "backgroundColor" | "color" | "translate" | "hidden" | "key" | "value" | "children" | "form" | "slot" | "title" | "name" | "type" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "radioGroup" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "autoFocus" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "testId" | "xcss" | "data-testid" | "isDisabled" | "interactionName" | "componentName" | "analyticsContext"> & React.RefAttributes<HTMLButtonElement>>;
67
67
  export default UNSAFE_PRESSABLE;
@@ -58,7 +58,7 @@ declare const Stack: import("react").MemoExoticComponent<import("react").Forward
58
58
  /**
59
59
  * Used to align children along the block axis (typically vertical).
60
60
  */
61
- alignBlock?: "stretch" | "center" | "end" | "start" | undefined;
61
+ alignBlock?: "center" | "stretch" | "end" | "start" | undefined;
62
62
  /**
63
63
  * Used to align children along the inline axis (typically horizontal).
64
64
  */
@@ -36,10 +36,10 @@ type TextPropsBase = {
36
36
  children: ReactNode;
37
37
  /**
38
38
  * Token representing text color with a built-in fallback value.
39
- * Will apply inverse text color automatically if placed within a Box with backgroundColor.
40
- *
39
+ * Will apply inverse text color automatically if placed within a Box with bold background color.
40
+ * Defaults to `text.color` if not nested in other Text components.
41
41
  */
42
- color?: TextColor;
42
+ color?: TextColor | 'inherit';
43
43
  /**
44
44
  * The [HTML `id` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id).
45
45
  */