@atlaskit/primitives 5.1.1 → 5.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/primitives
2
2
 
3
+ ## 5.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#86279](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/86279) [`0988fda99a0d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0988fda99a0d) - Renaming text alignment prop for Text component from `textAlign` to `align`
8
+
9
+ ## 5.1.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [#80174](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/80174) [`2a4fd6ccba31`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/2a4fd6ccba31) - Add forwardRef to text component
14
+
3
15
  ## 5.1.1
4
16
 
5
17
  ### Patch Changes
@@ -7,6 +7,7 @@ order: 0
7
7
  import Basic from '../../examples/constellation/text/basic';
8
8
  import ColorInverse from '../../examples/constellation/text/color-inverse';
9
9
  import Weight from '../../examples/constellation/text/weight';
10
+ import Align from '../../examples/constellation/text/align';
10
11
  import AsElement from '../../examples/constellation/text/as-element';
11
12
 
12
13
  ## Basic
@@ -15,19 +16,25 @@ Implements the [Atlassian typography system](/foundations/typography/) as a comp
15
16
 
16
17
  The `size` prop expresses the visual appearance of the text element.
17
18
 
18
- <Example Component={Basic} pacckageName="@atlaskit/primitives" />
19
+ <Example Component={Basic} packageName="@atlaskit/primitives" />
19
20
 
20
21
  ## Color
21
22
 
22
23
  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.
23
24
 
24
- <Example Component={ColorInverse} pacckageName="@atlaskit/primitives" />
25
+ <Example Component={ColorInverse} packageName="@atlaskit/primitives" />
25
26
 
26
27
  ## Weight
27
28
 
28
29
  Set `weight` to change the font weight.
29
30
 
30
- <Example Component={Weight} pacckageName="@atlaskit/primitives" />
31
+ <Example Component={Weight} packageName="@atlaskit/primitives" />
32
+
33
+ ## Alignment
34
+
35
+ Set `align` to change the text alignment.
36
+
37
+ <Example Component={Align} packageName="@atlaskit/primitives" />
31
38
 
32
39
  ## Rendered HTML tag
33
40
 
@@ -76,7 +76,7 @@ var Anchor = function Anchor(_ref, ref) {
76
76
  action: 'clicked',
77
77
  componentName: componentName || 'Anchor',
78
78
  packageName: "@atlaskit/primitives",
79
- packageVersion: "5.1.1",
79
+ packageVersion: "5.2.0",
80
80
  analyticsData: analyticsContext,
81
81
  actionSubject: 'link'
82
82
  });
@@ -8,10 +8,7 @@ exports.default = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _react2 = require("@emotion/react");
10
10
  var _xcss = require("../xcss/xcss");
11
- /**
12
- * @jsxRuntime classic
13
- * @jsx jsx
14
- */
11
+ /** @jsx jsx */
15
12
 
16
13
  var baseStyles = (0, _react2.css)({
17
14
  boxSizing: 'border-box'
@@ -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: "5.1.1",
83
+ packageVersion: "5.2.0",
84
84
  analyticsData: analyticsContext,
85
85
  actionSubject: 'button'
86
86
  });
@@ -5,14 +5,13 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
9
8
  var _react = require("react");
10
9
  var _react2 = require("@emotion/react");
11
10
  var _tinyInvariant = _interopRequireDefault(require("tiny-invariant"));
12
11
  var _styleMaps = require("../xcss/style-maps.partial");
13
12
  var _surfaceProvider = require("./internal/surface-provider");
14
- var _excluded = ["children"];
15
13
  /** @jsx jsx */
14
+
16
15
  var asAllowlist = ['span', 'p', 'strong', 'em'];
17
16
  // We're doing this because our CSS reset can add top margins to elements such as `p` which is totally insane.
18
17
  // Long term we should remove those instances from the reset - it should be a reset to 0.
@@ -83,24 +82,26 @@ var useColor = function useColor(colorProp, hasTextAncestor) {
83
82
  *
84
83
  * @internal
85
84
  */
86
- var Text = function Text(_ref) {
87
- var children = _ref.children,
88
- props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
89
- var _props$as = props.as,
90
- Component = _props$as === void 0 ? 'span' : _props$as,
91
- colorProp = props.color,
92
- textAlign = props.textAlign,
93
- testId = props.testId,
94
- id = props.id,
95
- _props$size = props.size,
96
- size = _props$size === void 0 ? 'medium' : _props$size,
97
- weight = props.weight,
98
- maxLines = props.maxLines;
85
+ var Text = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
86
+ var _ref$as = _ref.as,
87
+ Component = _ref$as === void 0 ? 'span' : _ref$as,
88
+ colorProp = _ref.color,
89
+ textAlign = _ref.textAlign,
90
+ _ref$align = _ref.align,
91
+ align = _ref$align === void 0 ? textAlign : _ref$align,
92
+ testId = _ref.testId,
93
+ id = _ref.id,
94
+ _ref$size = _ref.size,
95
+ size = _ref$size === void 0 ? 'medium' : _ref$size,
96
+ weight = _ref.weight,
97
+ maxLines = _ref.maxLines,
98
+ children = _ref.children;
99
99
  (0, _tinyInvariant.default)(asAllowlist.includes(Component), "@atlaskit/primitives: Text received an invalid \"as\" value of \"".concat(Component, "\""));
100
100
  var hasTextAncestor = useHasTextAncestor();
101
101
  var color = useColor(colorProp, hasTextAncestor);
102
102
  var component = (0, _react2.jsx)(Component, {
103
- css: [resetStyles, _styleMaps.fontStylesMap[size], color && _styleMaps.textColorStylesMap[color], maxLines && truncationStyles, maxLines === 1 && wordBreakMap.breakAll, textAlign && textAlignMap[textAlign], weight && _styleMaps.fontWeightStylesMap[weight], Component === 'em' && emStyles, Component === 'strong' && strongStyles],
103
+ ref: ref,
104
+ css: [resetStyles, _styleMaps.fontStylesMap[size], color && _styleMaps.textColorStylesMap[color], maxLines && truncationStyles, maxLines === 1 && wordBreakMap.breakAll, align && textAlignMap[align], weight && _styleMaps.fontWeightStylesMap[weight], Component === 'em' && emStyles, Component === 'strong' && strongStyles],
104
105
  style: {
105
106
  WebkitLineClamp: maxLines
106
107
  },
@@ -112,5 +113,5 @@ var Text = function Text(_ref) {
112
113
  component : (0, _react2.jsx)(HasTextAncestorContext.Provider, {
113
114
  value: true
114
115
  }, component);
115
- };
116
+ });
116
117
  var _default = exports.default = Text;
@@ -62,7 +62,7 @@ const Anchor = ({
62
62
  action: 'clicked',
63
63
  componentName: componentName || 'Anchor',
64
64
  packageName: "@atlaskit/primitives",
65
- packageVersion: "5.1.1",
65
+ packageVersion: "5.2.0",
66
66
  analyticsData: analyticsContext,
67
67
  actionSubject: 'link'
68
68
  });
@@ -1,7 +1,4 @@
1
- /**
2
- * @jsxRuntime classic
3
- * @jsx jsx
4
- */
1
+ /** @jsx jsx */
5
2
  import React from 'react';
6
3
  import { css, jsx } from '@emotion/react';
7
4
  import { parseXcss } from '../xcss/xcss';
@@ -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: "5.1.1",
69
+ packageVersion: "5.2.0",
70
70
  analyticsData: analyticsContext,
71
71
  actionSubject: 'button'
72
72
  });
@@ -1,5 +1,5 @@
1
1
  /** @jsx jsx */
2
- import { createContext, useContext } from 'react';
2
+ import { createContext, forwardRef, useContext } from 'react';
3
3
  import { css, jsx } from '@emotion/react';
4
4
  import invariant from 'tiny-invariant';
5
5
  import { fontStylesMap, fontWeightStylesMap, inverseColorMap, textColorStylesMap } from '../xcss/style-maps.partial';
@@ -72,25 +72,24 @@ const useColor = (colorProp, hasTextAncestor) => {
72
72
  *
73
73
  * @internal
74
74
  */
75
- const Text = ({
76
- children,
77
- ...props
78
- }) => {
79
- const {
80
- as: Component = 'span',
81
- color: colorProp,
82
- textAlign,
83
- testId,
84
- id,
85
- size = 'medium',
86
- weight,
87
- maxLines
88
- } = props;
75
+ const Text = /*#__PURE__*/forwardRef(({
76
+ as: Component = 'span',
77
+ color: colorProp,
78
+ textAlign,
79
+ align = textAlign,
80
+ testId,
81
+ id,
82
+ size = 'medium',
83
+ weight,
84
+ maxLines,
85
+ children
86
+ }, ref) => {
89
87
  invariant(asAllowlist.includes(Component), `@atlaskit/primitives: Text received an invalid "as" value of "${Component}"`);
90
88
  const hasTextAncestor = useHasTextAncestor();
91
89
  const color = useColor(colorProp, hasTextAncestor);
92
90
  const component = jsx(Component, {
93
- css: [resetStyles, fontStylesMap[size], color && textColorStylesMap[color], maxLines && truncationStyles, maxLines === 1 && wordBreakMap.breakAll, textAlign && textAlignMap[textAlign], weight && fontWeightStylesMap[weight], Component === 'em' && emStyles, Component === 'strong' && strongStyles],
91
+ ref: ref,
92
+ css: [resetStyles, fontStylesMap[size], color && textColorStylesMap[color], maxLines && truncationStyles, maxLines === 1 && wordBreakMap.breakAll, align && textAlignMap[align], weight && fontWeightStylesMap[weight], Component === 'em' && emStyles, Component === 'strong' && strongStyles],
94
93
  style: {
95
94
  WebkitLineClamp: maxLines
96
95
  },
@@ -102,5 +101,5 @@ const Text = ({
102
101
  component : jsx(HasTextAncestorContext.Provider, {
103
102
  value: true
104
103
  }, component);
105
- };
104
+ });
106
105
  export default Text;
@@ -66,7 +66,7 @@ var Anchor = function Anchor(_ref, ref) {
66
66
  action: 'clicked',
67
67
  componentName: componentName || 'Anchor',
68
68
  packageName: "@atlaskit/primitives",
69
- packageVersion: "5.1.1",
69
+ packageVersion: "5.2.0",
70
70
  analyticsData: analyticsContext,
71
71
  actionSubject: 'link'
72
72
  });
@@ -1,7 +1,4 @@
1
- /**
2
- * @jsxRuntime classic
3
- * @jsx jsx
4
- */
1
+ /** @jsx jsx */
5
2
  import React from 'react';
6
3
  import { css, jsx } from '@emotion/react';
7
4
  import { parseXcss } from '../xcss/xcss';
@@ -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: "5.1.1",
73
+ packageVersion: "5.2.0",
74
74
  analyticsData: analyticsContext,
75
75
  actionSubject: 'button'
76
76
  });
@@ -1,7 +1,5 @@
1
- import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
- var _excluded = ["children"];
3
1
  /** @jsx jsx */
4
- import { createContext, useContext } from 'react';
2
+ import { createContext, forwardRef, useContext } from 'react';
5
3
  import { css, jsx } from '@emotion/react';
6
4
  import invariant from 'tiny-invariant';
7
5
  import { fontStylesMap, fontWeightStylesMap, inverseColorMap, textColorStylesMap } from '../xcss/style-maps.partial';
@@ -76,24 +74,26 @@ var useColor = function useColor(colorProp, hasTextAncestor) {
76
74
  *
77
75
  * @internal
78
76
  */
79
- var Text = function Text(_ref) {
80
- var children = _ref.children,
81
- props = _objectWithoutProperties(_ref, _excluded);
82
- var _props$as = props.as,
83
- Component = _props$as === void 0 ? 'span' : _props$as,
84
- colorProp = props.color,
85
- textAlign = props.textAlign,
86
- testId = props.testId,
87
- id = props.id,
88
- _props$size = props.size,
89
- size = _props$size === void 0 ? 'medium' : _props$size,
90
- weight = props.weight,
91
- maxLines = props.maxLines;
77
+ var Text = /*#__PURE__*/forwardRef(function (_ref, ref) {
78
+ var _ref$as = _ref.as,
79
+ Component = _ref$as === void 0 ? 'span' : _ref$as,
80
+ colorProp = _ref.color,
81
+ textAlign = _ref.textAlign,
82
+ _ref$align = _ref.align,
83
+ align = _ref$align === void 0 ? textAlign : _ref$align,
84
+ testId = _ref.testId,
85
+ id = _ref.id,
86
+ _ref$size = _ref.size,
87
+ size = _ref$size === void 0 ? 'medium' : _ref$size,
88
+ weight = _ref.weight,
89
+ maxLines = _ref.maxLines,
90
+ children = _ref.children;
92
91
  invariant(asAllowlist.includes(Component), "@atlaskit/primitives: Text received an invalid \"as\" value of \"".concat(Component, "\""));
93
92
  var hasTextAncestor = useHasTextAncestor();
94
93
  var color = useColor(colorProp, hasTextAncestor);
95
94
  var component = jsx(Component, {
96
- css: [resetStyles, fontStylesMap[size], color && textColorStylesMap[color], maxLines && truncationStyles, maxLines === 1 && wordBreakMap.breakAll, textAlign && textAlignMap[textAlign], weight && fontWeightStylesMap[weight], Component === 'em' && emStyles, Component === 'strong' && strongStyles],
95
+ ref: ref,
96
+ css: [resetStyles, fontStylesMap[size], color && textColorStylesMap[color], maxLines && truncationStyles, maxLines === 1 && wordBreakMap.breakAll, align && textAlignMap[align], weight && fontWeightStylesMap[weight], Component === 'em' && emStyles, Component === 'strong' && strongStyles],
97
97
  style: {
98
98
  WebkitLineClamp: maxLines
99
99
  },
@@ -105,5 +105,5 @@ var Text = function Text(_ref) {
105
105
  component : jsx(HasTextAncestorContext.Provider, {
106
106
  value: true
107
107
  }, component);
108
- };
108
+ });
109
109
  export default Text;
@@ -1,7 +1,4 @@
1
- /**
2
- * @jsxRuntime classic
3
- * @jsx jsx
4
- */
1
+ /** @jsx jsx */
5
2
  import React, { ReactNode } from 'react';
6
3
  import { jsx } from '@emotion/react';
7
4
  import type { BasePrimitiveProps } from './types';
@@ -1,10 +1,10 @@
1
1
  /** @jsx jsx */
2
- import { FC, ReactNode } from 'react';
2
+ import { ComponentPropsWithRef, ElementType, ReactNode } from 'react';
3
3
  import { FontSize, FontWeight, TextColor } from '../xcss/style-maps.partial';
4
4
  import type { BasePrimitiveProps } from './types';
5
5
  declare const asAllowlist: readonly ["span", "p", "strong", "em"];
6
6
  type AsElement = (typeof asAllowlist)[number];
7
- type TextPropsBase = {
7
+ type TextPropsBase<T extends ElementType = 'span'> = {
8
8
  /**
9
9
  * HTML tag to be rendered. Defaults to `span`.
10
10
  */
@@ -30,9 +30,13 @@ type TextPropsBase = {
30
30
  */
31
31
  maxLines?: number;
32
32
  /**
33
- * The [HTML `text-align` attribute](https://developer.mozilla.org/en-US/docs/Web/CSS/text-align).
33
+ * @deprecated The [HTML `text-align` attribute](https://developer.mozilla.org/en-US/docs/Web/CSS/text-align).
34
34
  */
35
35
  textAlign?: TextAlign;
36
+ /**
37
+ * Text alignment.
38
+ */
39
+ align?: TextAlign;
36
40
  /**
37
41
  * Text size.
38
42
  */
@@ -41,8 +45,12 @@ type TextPropsBase = {
41
45
  * The [HTML `font-weight` attribute](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight).
42
46
  */
43
47
  weight?: FontWeight;
48
+ /**
49
+ * Forwarded ref.
50
+ */
51
+ ref?: ComponentPropsWithRef<T>['ref'];
44
52
  };
45
- export type TextProps = TextPropsBase & Omit<BasePrimitiveProps, 'xcss'>;
53
+ export type TextProps<T extends ElementType = 'span'> = TextPropsBase<T> & Omit<BasePrimitiveProps, 'xcss'>;
46
54
  type TextAlign = keyof typeof textAlignMap;
47
55
  declare const textAlignMap: {
48
56
  center: import("@emotion/react").SerializedStyles;
@@ -58,5 +66,5 @@ declare const textAlignMap: {
58
66
  *
59
67
  * @internal
60
68
  */
61
- declare const Text: FC<TextProps>;
69
+ declare const Text: import("react").ForwardRefExoticComponent<Pick<TextPropsBase<ElementType> & Omit<BasePrimitiveProps, "xcss">, "color" | "maxLines" | "textAlign" | "size" | "weight" | "children" | "as" | "id" | "role" | "align" | "testId" | "data-testid"> & import("react").RefAttributes<any>>;
62
70
  export default Text;
@@ -1,7 +1,4 @@
1
- /**
2
- * @jsxRuntime classic
3
- * @jsx jsx
4
- */
1
+ /** @jsx jsx */
5
2
  import React, { ReactNode } from 'react';
6
3
  import { jsx } from '@emotion/react';
7
4
  import type { BasePrimitiveProps } from './types';
@@ -1,5 +1,5 @@
1
1
  /** @jsx jsx */
2
- import { FC, ReactNode } from 'react';
2
+ import { ComponentPropsWithRef, ElementType, ReactNode } from 'react';
3
3
  import { FontSize, FontWeight, TextColor } from '../xcss/style-maps.partial';
4
4
  import type { BasePrimitiveProps } from './types';
5
5
  declare const asAllowlist: readonly [
@@ -9,7 +9,7 @@ declare const asAllowlist: readonly [
9
9
  "em"
10
10
  ];
11
11
  type AsElement = (typeof asAllowlist)[number];
12
- type TextPropsBase = {
12
+ type TextPropsBase<T extends ElementType = 'span'> = {
13
13
  /**
14
14
  * HTML tag to be rendered. Defaults to `span`.
15
15
  */
@@ -35,9 +35,13 @@ type TextPropsBase = {
35
35
  */
36
36
  maxLines?: number;
37
37
  /**
38
- * The [HTML `text-align` attribute](https://developer.mozilla.org/en-US/docs/Web/CSS/text-align).
38
+ * @deprecated The [HTML `text-align` attribute](https://developer.mozilla.org/en-US/docs/Web/CSS/text-align).
39
39
  */
40
40
  textAlign?: TextAlign;
41
+ /**
42
+ * Text alignment.
43
+ */
44
+ align?: TextAlign;
41
45
  /**
42
46
  * Text size.
43
47
  */
@@ -46,8 +50,12 @@ type TextPropsBase = {
46
50
  * The [HTML `font-weight` attribute](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight).
47
51
  */
48
52
  weight?: FontWeight;
53
+ /**
54
+ * Forwarded ref.
55
+ */
56
+ ref?: ComponentPropsWithRef<T>['ref'];
49
57
  };
50
- export type TextProps = TextPropsBase & Omit<BasePrimitiveProps, 'xcss'>;
58
+ export type TextProps<T extends ElementType = 'span'> = TextPropsBase<T> & Omit<BasePrimitiveProps, 'xcss'>;
51
59
  type TextAlign = keyof typeof textAlignMap;
52
60
  declare const textAlignMap: {
53
61
  center: import("@emotion/react").SerializedStyles;
@@ -63,5 +71,5 @@ declare const textAlignMap: {
63
71
  *
64
72
  * @internal
65
73
  */
66
- declare const Text: FC<TextProps>;
74
+ declare const Text: import("react").ForwardRefExoticComponent<Pick<TextPropsBase<ElementType> & Omit<BasePrimitiveProps, "xcss">, "color" | "maxLines" | "textAlign" | "size" | "weight" | "children" | "as" | "id" | "role" | "align" | "testId" | "data-testid"> & import("react").RefAttributes<any>>;
67
75
  export default Text;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/primitives",
3
- "version": "5.1.1",
3
+ "version": "5.2.0",
4
4
  "description": "Primitives are token-backed low-level building blocks.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"