@atlaskit/primitives 2.0.3 → 3.0.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 (34) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/anchor/package.json +15 -0
  3. package/constellation/anchor/code.mdx +21 -0
  4. package/constellation/anchor/examples.mdx +33 -0
  5. package/constellation/anchor/usage.mdx +47 -0
  6. package/constellation/box/examples.mdx +5 -3
  7. package/constellation/pressable/code.mdx +21 -0
  8. package/constellation/pressable/examples.mdx +39 -0
  9. package/constellation/pressable/usage.mdx +23 -0
  10. package/constellation/xcss/examples.mdx +1 -1
  11. package/dist/cjs/components/{link.js → anchor.js} +40 -13
  12. package/dist/cjs/components/pressable.js +25 -1
  13. package/dist/cjs/components/text.js +12 -33
  14. package/dist/cjs/index.js +14 -0
  15. package/dist/es2019/components/{link.js → anchor.js} +39 -13
  16. package/dist/es2019/components/pressable.js +24 -1
  17. package/dist/es2019/components/text.js +4 -21
  18. package/dist/es2019/index.js +2 -0
  19. package/dist/esm/components/{link.js → anchor.js} +41 -14
  20. package/dist/esm/components/pressable.js +26 -2
  21. package/dist/esm/components/text.js +4 -24
  22. package/dist/esm/index.js +2 -0
  23. package/dist/types/components/anchor.d.ts +69 -0
  24. package/dist/types/components/pressable.d.ts +47 -4
  25. package/dist/types/index.d.ts +4 -0
  26. package/dist/types-ts4.5/components/anchor.d.ts +69 -0
  27. package/dist/types-ts4.5/components/pressable.d.ts +47 -4
  28. package/dist/types-ts4.5/index.d.ts +4 -0
  29. package/extract-react-types/anchor-props.tsx +103 -0
  30. package/extract-react-types/pressable-props.tsx +94 -0
  31. package/package.json +23 -3
  32. package/dist/types/components/link.d.ts +0 -31
  33. package/dist/types-ts4.5/components/link.d.ts +0 -31
  34. package/link/package.json +0 -15
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @atlaskit/primitives
2
2
 
3
+ ## 3.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#58240](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/58240) [`a45d2049a22c`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a45d2049a22c) - The "Link" primitive has been renamed to "Anchor" to avoid confusion with the upcoming "Link" component. Since Link is still in Alpha this should not cause any upgrade friction.
8
+
9
+ ### Minor Changes
10
+
11
+ - [#58240](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/58240) [`75b2ade8b254`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/75b2ade8b254) - Both the Pressable and Anchor primitives now support analytics tracking by default.
12
+ - [#58240](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/58240) [`39f3c929f0c4`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/39f3c929f0c4) - Add Pressable and Anchor primitives (in Alpha) to root export as `UNSAFE_PRESSABLE` and `UNSAFE_LINK`.
13
+
14
+ ### Patch Changes
15
+
16
+ - [#58240](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/58240) [`4951390bc0ae`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/4951390bc0ae) - [ux] Adds a default underline style to the Anchor primitive (Alpha)
17
+
18
+ ## 2.1.0
19
+
20
+ ### Minor Changes
21
+
22
+ - [#74930](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/74930) [`707a8fee2aee`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/707a8fee2aee) - Both the Pressable and Anchor primitives (in Alpha) now support analytics tracking in the same fashion as `@atlaskit/button`. An additional prop `componentName` allows analytics to be configured if a parent component name is desired to be tracked rather than the primitive names. For the time being this tracking is opt-in via use of the `componentName` prop. This will be made default behavior in an upcoming release once tracking is removed in the new Buttons, and `@atlaskit/button` is bumped to use the latest version of `@atlaskit/primitives`
23
+ - [#75221](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/75221) [`c15d58bff276`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c15d58bff276) - `Text` inherits color by default if `color` prop is not provided.
24
+ Removed auto-collapsing behaviour of `Text`
25
+
3
26
  ## 2.0.3
4
27
 
5
28
  ### Patch Changes
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@atlaskit/primitives/anchor",
3
+ "main": "../dist/cjs/components/anchor.js",
4
+ "module": "../dist/esm/components/anchor.js",
5
+ "module:es2019": "../dist/es2019/components/anchor.js",
6
+ "sideEffects": false,
7
+ "types": "../dist/types/components/anchor.d.ts",
8
+ "typesVersions": {
9
+ ">=4.5 <4.9": {
10
+ "*": [
11
+ "../dist/types-ts4.5/components/anchor.d.ts"
12
+ ]
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,21 @@
1
+ ---
2
+ title: Anchor
3
+ description: An anchor is a primitive for building custom links.
4
+ order: 1
5
+ ---
6
+
7
+ import { CodeDocsHeader } from '@af/design-system-docs-ui';
8
+
9
+ <CodeDocsHeader
10
+ name="@atlaskit/primitives"
11
+ repository="https://bitbucket.org/atlassian/atlassian-frontend-mirror"
12
+ directoryName="primitives"
13
+ />
14
+
15
+ import ERTAnchor from '!!extract-react-types-loader!../../extract-react-types/anchor-props';
16
+
17
+ ## Props
18
+
19
+ Anchor also supports all valid `HTMLAnchorElement` props.
20
+
21
+ <PropsTable heading="" props={ERTAnchor} />
@@ -0,0 +1,33 @@
1
+ ---
2
+ title: Anchor
3
+ description: An anchor is a primitive for building custom links.
4
+ order: 0
5
+ ---
6
+
7
+ import AnchorDefault from '../../examples/constellation/anchor/default';
8
+ import AnchorStyled from '../../examples/constellation/anchor/styled';
9
+
10
+ import { CodeDocsHeader } from '@af/design-system-docs-ui';
11
+ import SectionMessage from '@atlaskit/section-message';
12
+
13
+ <CodeDocsHeader
14
+ name="@atlaskit/primitives"
15
+ repository="https://bitbucket.org/atlassian/atlassian-frontend-mirror"
16
+ directoryName="primitives"
17
+ />
18
+
19
+ Anchor is a primitive used for building custom anchor links, with support for client-side routing and Atlassian Design System styling. This component is used by other design system components, such as the [Link component](/components/link/examples).
20
+
21
+ For most links, use the [Link component](/components/link/examples) wherever possible, and use [XCSS](/components/primitives/xcss/usage) for any necessary customization. Only use Anchor if you aren't able to use Link.
22
+
23
+ ## Default
24
+
25
+ Anchor comes unstyled, ready for styles to be applied. Note if you are using the [CSS reset](/components/css-reset/examples), anchor will inherit some default styles.
26
+
27
+ <Example Component={AnchorDefault} packageName="@atlaskit/primitives/anchor" />
28
+
29
+ ## Styling
30
+
31
+ Anchor consumes the Box primitive to provide a consistent styling API that supports design tokens. See [Box](/components/primitives/box/examples) for complete styling documentation and examples.
32
+
33
+ <Example Component={AnchorStyled} packageName="@atlaskit/primitives/anchor" />
@@ -0,0 +1,47 @@
1
+ ---
2
+ title: Anchor
3
+ description: An anchor is a primitive for building custom links.
4
+ order: 2
5
+ ---
6
+
7
+ ## When not to use Anchor
8
+
9
+ The [Link component](/components/link/usage) should be used whenever possible for links to maintain visual consistency. Only use Anchor when building custom links beyond the capabilities of the Link component. The decision to use Anchor should involve checking if the Link component can be customized to fit your needs using [XCSS](/components/primitives/XCSS/usage).
10
+
11
+ Do not use Anchor for buttons that perform actions rather than navigation. Use the equivalent [Pressable primitive](/components/primitives/pressable/usage) instead.
12
+
13
+ ## Link types
14
+
15
+ External links starting with `http://` or `https://` will automatically render with `target="_blank"` and `rel="noopener noreferrer"` attributes.
16
+
17
+ ### Router links
18
+
19
+ Anchor supports automatic consumption of configured router link components through the [App Provider](/components/app-provider/examples#router-links). If an App Provider is not present or a router link component is not configured, the link will render as a standard anchor link.
20
+
21
+ External links and non-HTTP-based links such as `tel:` and `mailto:` will not use router links and always render as standard anchor links.
22
+
23
+ Anchor accepts a generic type object matching the router link configuration, allowing advanced usage of `href` prop. These values can be mapped to the underlying router link component in the App Provider.
24
+
25
+ ```jsx
26
+ <Anchor<MyRouterLinkConfig>
27
+ href={{
28
+ to: '/home',
29
+ replace: true
30
+ }}
31
+ >
32
+ Home
33
+ </Anchor>
34
+ ```
35
+
36
+ ## Styling
37
+
38
+ Display behavior follows the same patterns as [Box](/components/primitives/box/usage). Use available props or [XCSS](/components/primitives/xcss/usage) to customize padding options, background color, and other styles.
39
+
40
+ ## Related
41
+
42
+ - [Configuring router link components with AppProvider](/components/app-provider/examples#router-links)
43
+ - [The underlying box component](/components/primitives/box/usage)
44
+ - [Counterpart pressable primitive for button tags](/components/primitives/button/usage)
45
+ - [Manage horizontal layout using an inline component](/components/primitives/inline/usage)
46
+ - [Manage vertical layout using a stack component](/components/primitives/stack/usage)
47
+ - [Use design tokens in code with XCSS](/components/primitives/XCSS/usage)
@@ -53,13 +53,15 @@ For more information on XCSS, see the dedicated [XCSS documentation](/components
53
53
 
54
54
  ## Conditional styles
55
55
 
56
- To achieve conditional styles, it is usually simpler to apply conditional behavior at the `xcss` object level, rather than applying conditional behavior to individual properties.
56
+ To achieve conditional styles, we suggest composing conditional styles via the `props.xcss` API rather than applying conditional behaviour to individual props.
57
57
 
58
58
  <Example Component={BoxConditional} packageName="@atlaskit/primitives/box" />
59
59
 
60
- ## Practical use case
60
+ ## Practical card example
61
61
 
62
- Box is designed to be used in conjunction with the inline and stack components to create layouts. This example demonstrates how these can be used to create familiar components and patterns.
62
+ Box is designed to be composed with inline, stack, and other components to create layouts.
63
+
64
+ Atlassian uses dozens of distinct card-like components across products. Therefore, rather than providing a strict component, the Atlassian Design System empowers and supports you to build your own card components in ways that are consistent and will scale over time.
63
65
 
64
66
  <Example
65
67
  Component={BoxPracticalUseCase}
@@ -0,0 +1,21 @@
1
+ ---
2
+ title: Pressable
3
+ description: A pressable is a primitive used for building custom buttons.
4
+ order: 1
5
+ ---
6
+
7
+ import { CodeDocsHeader } from '@af/design-system-docs-ui';
8
+
9
+ <CodeDocsHeader
10
+ name="@atlaskit/primitives"
11
+ repository="https://bitbucket.org/atlassian/atlassian-frontend-mirror"
12
+ directoryName="primitives"
13
+ />
14
+
15
+ import ERTPressable from '!!extract-react-types-loader!../../extract-react-types/pressable-props';
16
+
17
+ ## Props
18
+
19
+ Pressable also supports all valid `HTMLButtonElement` props, except for `disabled` which is replaced by the `isDisabled` prop.
20
+
21
+ <PropsTable heading="" props={ERTPressable} />
@@ -0,0 +1,39 @@
1
+ ---
2
+ title: Pressable
3
+ description: A pressable is a primitive used for building custom buttons.
4
+ order: 0
5
+ ---
6
+
7
+ import PressableDefault from '../../examples/constellation/pressable/default';
8
+ import PressableStyled from '../../examples/constellation/pressable/styled';
9
+
10
+ import { CodeDocsHeader } from '@af/design-system-docs-ui';
11
+ import SectionMessage from '@atlaskit/section-message';
12
+
13
+ <CodeDocsHeader
14
+ name="@atlaskit/primitives"
15
+ repository="https://bitbucket.org/atlassian/atlassian-frontend-mirror"
16
+ directoryName="primitives"
17
+ />
18
+
19
+ Pressable is a primitive used for building custom buttons with Atlassian Design System styling. This component is used by other design system components, such as the [Button component](/components/button/examples).
20
+
21
+ For most buttons, use the [Button component](/components/button/examples) wherever possible, and use [XCSS](/components/primitives/xcss/usage) for any necessary customization. Only use pressable if you aren't able to use the button component.
22
+
23
+ ## Default
24
+
25
+ Pressable comes unstyled, ready for styles to be applied.
26
+
27
+ <Example
28
+ Component={PressableDefault}
29
+ packageName="@atlaskit/primitives/pressable"
30
+ />
31
+
32
+ ## Styling
33
+
34
+ Pressable consumes the Box primitive to provide a consistent styling API that supports design tokens. See [Box](/components/primitives/box/examples) for complete styling documentation and examples.
35
+
36
+ <Example
37
+ Component={PressableStyled}
38
+ packageName="@atlaskit/primitives/pressable"
39
+ />
@@ -0,0 +1,23 @@
1
+ ---
2
+ title: Pressable
3
+ description: A pressable is a primitive used for building custom buttons.
4
+ order: 2
5
+ ---
6
+
7
+ ## When not to use pressable
8
+
9
+ The [Button component](/components/button/usage) should be used whenever possible for buttons to maintain visual consistency. Only use pressable when building custom buttons beyond the capabilities of the button component. The decision to use pressable should involve checking if the button component can be customized to fit your needs using [XCSS](/components/primitives/XCSS/usage).
10
+
11
+ Do not use Pressable for links (anchor tags). Use the equivalent [Anchor primitive](/components/primitives/anchor/usage) instead.
12
+
13
+ ## Styling
14
+
15
+ Display behavior follows the same patterns as [Box](/components/primitives/box/usage). Use available props or [XCSS](/components/primitives/xcss/usage) to customize padding options, background color, and other styles.
16
+
17
+ ## Related
18
+
19
+ - [The underlying box component](/components/primitives/box/usage)
20
+ - [Counterpart anchor primitive for anchor tags](/components/primitives/anchor/usage)
21
+ - [Manage horizontal layout using an inline component](/components/primitives/inline/usage)
22
+ - [Manage vertical layout using a stack component](/components/primitives/stack/usage)
23
+ - [Use design tokens in code with XCSS](/components/primitives/XCSS/usage)
@@ -37,6 +37,6 @@ XCSS also accepts a subset of media queries at [predefined breakpoints](/compone
37
37
 
38
38
  ## Conditional styles
39
39
 
40
- To achieve conditional styles, it is usually simpler to apply conditional behavior at the `xcss` object level, rather than applying conditional behavior to individual properties.
40
+ For conditional styles, try composing styles together via the array with ternary or boolean operators.
41
41
 
42
42
  <Example Component={xcssConditional} packageName="@atlaskit/primitives/xcss" />
@@ -12,10 +12,13 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
12
12
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
13
  var _react = _interopRequireWildcard(require("react"));
14
14
  var _tinyInvariant = _interopRequireDefault(require("tiny-invariant"));
15
+ var _analyticsNext = require("@atlaskit/analytics-next");
15
16
  var _appProvider = require("@atlaskit/app-provider");
17
+ var _noop = _interopRequireDefault(require("@atlaskit/ds-lib/noop"));
18
+ var _interactionContext = _interopRequireDefault(require("@atlaskit/interaction-context"));
16
19
  var _xcss = require("../xcss/xcss");
17
20
  var _box = _interopRequireDefault(require("./box"));
18
- var _excluded = ["href", "children", "backgroundColor", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd", "testId", "xcss", "target", "rel"];
21
+ var _excluded = ["href", "children", "backgroundColor", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd", "testId", "xcss", "target", "rel", "onClick", "interactionName", "componentName", "analyticsContext"];
19
22
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
20
23
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
24
  // TODO: Duplicated FocusRing styles due to lack of `xcss` support
@@ -26,6 +29,9 @@ var baseFocusRingStyles = {
26
29
  outlineStyle: 'solid',
27
30
  outlineOffset: 'space.025'
28
31
  };
32
+ var defaultStyles = (0, _xcss.xcss)({
33
+ textDecoration: 'underline'
34
+ });
29
35
  var focusRingStyles = (0, _xcss.xcss)({
30
36
  ':focus-visible': baseFocusRingStyles,
31
37
  '@supports not selector(*:focus-visible)': {
@@ -39,7 +45,7 @@ var focusRingStyles = (0, _xcss.xcss)({
39
45
  });
40
46
  var IS_EXTERNAL_LINK_REGEX = /^(?:(http|https):\/\/)/;
41
47
  var IS_NON_HTTP_BASED = /^(((mailto|tel|sms):)|(#))/;
42
- var Link = function Link(_ref, ref) {
48
+ var Anchor = function Anchor(_ref, ref) {
43
49
  var href = _ref.href,
44
50
  children = _ref.children,
45
51
  backgroundColor = _ref.backgroundColor,
@@ -54,11 +60,30 @@ var Link = function Link(_ref, ref) {
54
60
  xcssStyles = _ref.xcss,
55
61
  target = _ref.target,
56
62
  rel = _ref.rel,
63
+ _ref$onClick = _ref.onClick,
64
+ providedOnClick = _ref$onClick === void 0 ? _noop.default : _ref$onClick,
65
+ interactionName = _ref.interactionName,
66
+ componentName = _ref.componentName,
67
+ analyticsContext = _ref.analyticsContext,
57
68
  htmlAttributes = (0, _objectWithoutProperties2.default)(_ref, _excluded);
69
+ var interactionContext = (0, _react.useContext)(_interactionContext.default);
70
+ var handleClick = (0, _react.useCallback)(function (e, analyticsEvent) {
71
+ interactionContext && interactionContext.tracePress(interactionName, e.timeStamp);
72
+ providedOnClick(e, analyticsEvent);
73
+ }, [providedOnClick, interactionContext, interactionName]);
74
+ var onClick = (0, _analyticsNext.usePlatformLeafEventHandler)({
75
+ fn: handleClick,
76
+ action: 'clicked',
77
+ componentName: componentName || 'Anchor',
78
+ packageName: "@atlaskit/primitives",
79
+ packageVersion: "3.0.0",
80
+ analyticsData: analyticsContext,
81
+ actionSubject: 'link'
82
+ });
58
83
  var RouterLink = (0, _appProvider.useRouterLink)();
59
84
 
60
85
  // Combine default styles with supplied styles. XCSS does not support deep nested arrays
61
- var styles = Array.isArray(xcssStyles) ? [focusRingStyles].concat((0, _toConsumableArray2.default)(xcssStyles)) : [focusRingStyles, xcssStyles];
86
+ var styles = Array.isArray(xcssStyles) ? [defaultStyles, focusRingStyles].concat((0, _toConsumableArray2.default)(xcssStyles)) : [defaultStyles, focusRingStyles, xcssStyles];
62
87
  var isExternal = typeof href === 'string' && IS_EXTERNAL_LINK_REGEX.test(href);
63
88
  var isNonHttpBased = typeof href === 'string' && IS_NON_HTTP_BASED.test(href);
64
89
 
@@ -71,7 +96,7 @@ var Link = function Link(_ref, ref) {
71
96
  */
72
97
  var isRouterLink = RouterLink && !isExternal && !isNonHttpBased;
73
98
  var hrefObjectUsedWithoutRouterLink = RouterLink === undefined && (0, _typeof2.default)(href) === 'object';
74
- (0, _tinyInvariant.default)(!hrefObjectUsedWithoutRouterLink, "@atlaskit/primitives: Link primitive cannot pass an object to 'href' unless a router link is configured in the AppProvider");
99
+ (0, _tinyInvariant.default)(!hrefObjectUsedWithoutRouterLink, "@atlaskit/primitives: Anchor primitive cannot pass an object to 'href' unless a router link is configured in the AppProvider");
75
100
  return /*#__PURE__*/_react.default.createElement(_box.default
76
101
  // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
77
102
  , (0, _extends2.default)({}, htmlAttributes, {
@@ -90,7 +115,8 @@ var Link = function Link(_ref, ref) {
90
115
  paddingBlockEnd: paddingBlockEnd,
91
116
  paddingInline: paddingInline,
92
117
  paddingInlineStart: paddingInlineStart,
93
- paddingInlineEnd: paddingInlineEnd
118
+ paddingInlineEnd: paddingInlineEnd,
119
+ onClick: onClick
94
120
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
95
121
  ,
96
122
  xcss: styles
@@ -99,16 +125,17 @@ var Link = function Link(_ref, ref) {
99
125
 
100
126
  // Workarounds to support generic types with forwardRef
101
127
  /**
102
- * __UNSAFE_LINK__
128
+ * __UNSAFE_ANCHOR__
103
129
  *
104
130
  * @internal Still under development. Do not use.
105
131
  *
106
- * A Link is a primitive component that renders an `<a>` anchor. It utilizes
107
- * the configured router link component in the AppProvider if set.
132
+ * Anchor is a primitive for building custom anchor links. It's a wrapper around the HTML `<a>` element that provides a consistent API for handling client-side routing and Atlassian Design System styling.
133
+ *
134
+ * This component is mostly used by other design system components, such as the [link component](/components/link/usage).
108
135
  *
109
- * - [Examples](https://atlassian.design/components/primitives/link/examples)
110
- * - [Code](https://atlassian.design/components/primitives/link/code)
111
- * - [Usage](https://atlassian.design/components/primitives/link/usage)
136
+ * - [Examples](https://atlassian.design/components/primitives/anchor/examples)
137
+ * - [Code](https://atlassian.design/components/primitives/anchor/code)
138
+ * - [Usage](https://atlassian.design/components/primitives/anchor/usage)
112
139
  */
113
- var UNSAFE_LINK = /*#__PURE__*/(0, _react.forwardRef)(Link);
114
- var _default = exports.default = UNSAFE_LINK;
140
+ var UNSAFE_ANCHOR = /*#__PURE__*/(0, _react.forwardRef)(Anchor);
141
+ var _default = exports.default = UNSAFE_ANCHOR;
@@ -10,9 +10,12 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
10
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
11
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
12
12
  var _react = _interopRequireWildcard(require("react"));
13
+ var _analyticsNext = require("@atlaskit/analytics-next");
14
+ var _noop = _interopRequireDefault(require("@atlaskit/ds-lib/noop"));
15
+ var _interactionContext = _interopRequireDefault(require("@atlaskit/interaction-context"));
13
16
  var _xcss = require("../xcss/xcss");
14
17
  var _box = _interopRequireDefault(require("./box"));
15
- var _excluded = ["children", "backgroundColor", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd", "isDisabled", "type", "testId", "xcss"];
18
+ var _excluded = ["children", "backgroundColor", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd", "isDisabled", "type", "testId", "xcss", "onClick", "interactionName", "componentName", "analyticsContext"];
16
19
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
20
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
18
21
  // TODO: Duplicated FocusRing styles due to lack of `xcss` support
@@ -61,7 +64,27 @@ var UNSAFE_PRESSABLE = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref)
61
64
  type = _ref$type === void 0 ? 'button' : _ref$type,
62
65
  testId = _ref.testId,
63
66
  xcssStyles = _ref.xcss,
67
+ _ref$onClick = _ref.onClick,
68
+ providedOnClick = _ref$onClick === void 0 ? _noop.default : _ref$onClick,
69
+ interactionName = _ref.interactionName,
70
+ componentName = _ref.componentName,
71
+ analyticsContext = _ref.analyticsContext,
64
72
  htmlAttributes = (0, _objectWithoutProperties2.default)(_ref, _excluded);
73
+ var interactionContext = (0, _react.useContext)(_interactionContext.default);
74
+ var handleClick = (0, _react.useCallback)(function (e, analyticsEvent) {
75
+ interactionContext && interactionContext.tracePress(interactionName, e.timeStamp);
76
+ providedOnClick(e, analyticsEvent);
77
+ }, [providedOnClick, interactionContext, interactionName]);
78
+ var onClick = (0, _analyticsNext.usePlatformLeafEventHandler)({
79
+ fn: handleClick,
80
+ action: 'clicked',
81
+ componentName: componentName || 'Pressable',
82
+ packageName: "@atlaskit/primitives",
83
+ packageVersion: "3.0.0",
84
+ analyticsData: analyticsContext,
85
+ actionSubject: 'button'
86
+ });
87
+
65
88
  // Combine default styles with supplied styles. XCSS does not support deep nested arrays
66
89
  var styles = [(0, _xcss.xcss)({
67
90
  cursor: isDisabled ? 'not-allowed' : 'pointer'
@@ -72,6 +95,7 @@ var UNSAFE_PRESSABLE = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref)
72
95
  ref: ref,
73
96
  testId: testId,
74
97
  type: type,
98
+ onClick: onClick,
75
99
  backgroundColor: backgroundColor,
76
100
  padding: padding,
77
101
  paddingBlock: paddingBlock,
@@ -7,8 +7,7 @@ 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("react");
11
- var _react2 = require("@emotion/react");
10
+ var _react = require("@emotion/react");
12
11
  var _tinyInvariant = _interopRequireDefault(require("tiny-invariant"));
13
12
  var _styleMaps = require("../xcss/style-maps.partial");
14
13
  var _surfaceProvider = require("./internal/surface-provider");
@@ -19,34 +18,34 @@ var asAllowlist = ['span', 'p', 'strong', 'em'];
19
18
  // We're doing this because our CSS reset can add top margins to elements such as `p` which is totally insane.
20
19
  // Long term we should remove those instances from the reset - it should be a reset to 0.
21
20
  // For now, at least we know <Text> will be unaffected by this.
22
- var resetStyles = (0, _react2.css)({
21
+ var resetStyles = (0, _react.css)({
23
22
  margin: 0
24
23
  });
25
24
  var variantStyles = _objectSpread(_objectSpread({}, _styleMaps.bodyTextStylesMap), _styleMaps.uiTextStylesMap);
26
- var strongStyles = (0, _react2.css)({
25
+ var strongStyles = (0, _react.css)({
27
26
  fontWeight: 'bold'
28
27
  });
29
- var emStyles = (0, _react2.css)({
28
+ var emStyles = (0, _react.css)({
30
29
  fontStyle: 'italic'
31
30
  });
32
31
  var textAlignMap = {
33
- center: (0, _react2.css)({
32
+ center: (0, _react.css)({
34
33
  textAlign: 'center'
35
34
  }),
36
- end: (0, _react2.css)({
35
+ end: (0, _react.css)({
37
36
  textAlign: 'end'
38
37
  }),
39
- start: (0, _react2.css)({
38
+ start: (0, _react.css)({
40
39
  textAlign: 'start'
41
40
  })
42
41
  };
43
- var truncationStyles = (0, _react2.css)({
42
+ var truncationStyles = (0, _react.css)({
44
43
  display: '-webkit-box',
45
44
  overflow: 'hidden',
46
45
  WebkitBoxOrient: 'vertical'
47
46
  });
48
47
  var wordBreakMap = {
49
- breakAll: (0, _react2.css)({
48
+ breakAll: (0, _react.css)({
50
49
  wordBreak: 'break-all'
51
50
  })
52
51
  };
@@ -56,19 +55,14 @@ var wordBreakMap = {
56
55
  */
57
56
  var useColor = function useColor(colorProp) {
58
57
  var surface = (0, _surfaceProvider.useSurface)();
59
- var inverseTextColor = _styleMaps.inverseColorMap[surface];
60
58
 
61
59
  /**
62
60
  * Where the color of the surface is inverted we override the user choice
63
61
  * as there is no valid choice that is not covered by the override.
64
62
  */
65
- var color = inverseTextColor !== null && inverseTextColor !== void 0 ? inverseTextColor : colorProp;
63
+ var color = _styleMaps.inverseColorMap.hasOwnProperty(surface) ? _styleMaps.inverseColorMap[surface] : colorProp;
66
64
  return color;
67
65
  };
68
- var HasTextAncestorContext = /*#__PURE__*/(0, _react.createContext)(false);
69
- var useHasTextAncestor = function useHasTextAncestor() {
70
- return (0, _react.useContext)(HasTextAncestorContext);
71
- };
72
66
 
73
67
  /**
74
68
  * __Text__
@@ -83,8 +77,7 @@ var Text = function Text(_ref) {
83
77
  var children = _ref.children,
84
78
  props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
85
79
  var asElement = props.as,
86
- _props$color = props.color,
87
- colorProp = _props$color === void 0 ? 'color.text' : _props$color,
80
+ colorProp = props.color,
88
81
  textAlign = props.textAlign,
89
82
  testId = props.testId,
90
83
  id = props.id,
@@ -103,16 +96,7 @@ var Text = function Text(_ref) {
103
96
  maxLines = props.maxLines;
104
97
  }
105
98
  var color = useColor(colorProp);
106
- var isWrapped = useHasTextAncestor();
107
-
108
- /**
109
- * If the text is already wrapped and applies no props we can just
110
- * render the children directly as a fragment.
111
- */
112
- if (isWrapped && Object.keys(props).length === 0) {
113
- return (0, _react2.jsx)(_react.Fragment, null, children);
114
- }
115
- var component = (0, _react2.jsx)(Component, {
99
+ return (0, _react.jsx)(Component, {
116
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],
117
101
  style: {
118
102
  WebkitLineClamp: maxLines
@@ -120,10 +104,5 @@ var Text = function Text(_ref) {
120
104
  "data-testid": testId,
121
105
  id: id
122
106
  }, children);
123
- return isWrapped ?
124
- // no need to re-apply context if the text is already wrapped
125
- component : (0, _react2.jsx)(HasTextAncestorContext.Provider, {
126
- value: true
127
- }, component);
128
107
  };
129
108
  var _default = exports.default = Text;
package/dist/cjs/index.js CHANGED
@@ -46,12 +46,24 @@ Object.defineProperty(exports, "Text", {
46
46
  return _text.default;
47
47
  }
48
48
  });
49
+ Object.defineProperty(exports, "UNSAFE_ANCHOR", {
50
+ enumerable: true,
51
+ get: function get() {
52
+ return _anchor.default;
53
+ }
54
+ });
49
55
  Object.defineProperty(exports, "UNSAFE_BREAKPOINTS_CONFIG", {
50
56
  enumerable: true,
51
57
  get: function get() {
52
58
  return _responsive.UNSAFE_BREAKPOINTS_CONFIG;
53
59
  }
54
60
  });
61
+ Object.defineProperty(exports, "UNSAFE_PRESSABLE", {
62
+ enumerable: true,
63
+ get: function get() {
64
+ return _pressable.default;
65
+ }
66
+ });
55
67
  Object.defineProperty(exports, "UNSAFE_media", {
56
68
  enumerable: true,
57
69
  get: function get() {
@@ -84,4 +96,6 @@ var _flex = _interopRequireDefault(require("./components/flex"));
84
96
  var _grid = _interopRequireDefault(require("./components/grid"));
85
97
  var _bleed = _interopRequireDefault(require("./components/bleed"));
86
98
  var _text = _interopRequireDefault(require("./components/text"));
99
+ var _pressable = _interopRequireDefault(require("./components/pressable"));
100
+ var _anchor = _interopRequireDefault(require("./components/anchor"));
87
101
  var _responsive = require("./responsive");