@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
@@ -1,7 +1,10 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import React, { forwardRef } from 'react';
2
+ import React, { forwardRef, useCallback, useContext } from 'react';
3
3
  import invariant from 'tiny-invariant';
4
+ import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next';
4
5
  import { useRouterLink } from '@atlaskit/app-provider';
6
+ import noop from '@atlaskit/ds-lib/noop';
7
+ import InteractionContext from '@atlaskit/interaction-context';
5
8
  import { xcss } from '../xcss/xcss';
6
9
  import Box from './box';
7
10
  // TODO: Duplicated FocusRing styles due to lack of `xcss` support
@@ -12,6 +15,9 @@ const baseFocusRingStyles = {
12
15
  outlineStyle: 'solid',
13
16
  outlineOffset: 'space.025'
14
17
  };
18
+ const defaultStyles = xcss({
19
+ textDecoration: 'underline'
20
+ });
15
21
  const focusRingStyles = xcss({
16
22
  ':focus-visible': baseFocusRingStyles,
17
23
  '@supports not selector(*:focus-visible)': {
@@ -25,7 +31,7 @@ const focusRingStyles = xcss({
25
31
  });
26
32
  const IS_EXTERNAL_LINK_REGEX = /^(?:(http|https):\/\/)/;
27
33
  const IS_NON_HTTP_BASED = /^(((mailto|tel|sms):)|(#))/;
28
- const Link = ({
34
+ const Anchor = ({
29
35
  href,
30
36
  children,
31
37
  backgroundColor,
@@ -40,12 +46,30 @@ const Link = ({
40
46
  xcss: xcssStyles,
41
47
  target,
42
48
  rel,
49
+ onClick: providedOnClick = noop,
50
+ interactionName,
51
+ componentName,
52
+ analyticsContext,
43
53
  ...htmlAttributes
44
54
  }, ref) => {
55
+ const interactionContext = useContext(InteractionContext);
56
+ const handleClick = useCallback((e, analyticsEvent) => {
57
+ interactionContext && interactionContext.tracePress(interactionName, e.timeStamp);
58
+ providedOnClick(e, analyticsEvent);
59
+ }, [providedOnClick, interactionContext, interactionName]);
60
+ const onClick = usePlatformLeafEventHandler({
61
+ fn: handleClick,
62
+ action: 'clicked',
63
+ componentName: componentName || 'Anchor',
64
+ packageName: "@atlaskit/primitives",
65
+ packageVersion: "3.0.0",
66
+ analyticsData: analyticsContext,
67
+ actionSubject: 'link'
68
+ });
45
69
  const RouterLink = useRouterLink();
46
70
 
47
71
  // Combine default styles with supplied styles. XCSS does not support deep nested arrays
48
- const styles = Array.isArray(xcssStyles) ? [focusRingStyles, ...xcssStyles] : [focusRingStyles, xcssStyles];
72
+ const styles = Array.isArray(xcssStyles) ? [defaultStyles, focusRingStyles, ...xcssStyles] : [defaultStyles, focusRingStyles, xcssStyles];
49
73
  const isExternal = typeof href === 'string' && IS_EXTERNAL_LINK_REGEX.test(href);
50
74
  const isNonHttpBased = typeof href === 'string' && IS_NON_HTTP_BASED.test(href);
51
75
 
@@ -58,7 +82,7 @@ const Link = ({
58
82
  */
59
83
  const isRouterLink = RouterLink && !isExternal && !isNonHttpBased;
60
84
  const hrefObjectUsedWithoutRouterLink = RouterLink === undefined && typeof href === 'object';
61
- invariant(!hrefObjectUsedWithoutRouterLink, `@atlaskit/primitives: Link primitive cannot pass an object to 'href' unless a router link is configured in the AppProvider`);
85
+ invariant(!hrefObjectUsedWithoutRouterLink, `@atlaskit/primitives: Anchor primitive cannot pass an object to 'href' unless a router link is configured in the AppProvider`);
62
86
  return /*#__PURE__*/React.createElement(Box
63
87
  // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
64
88
  , _extends({}, htmlAttributes, {
@@ -77,7 +101,8 @@ const Link = ({
77
101
  paddingBlockEnd: paddingBlockEnd,
78
102
  paddingInline: paddingInline,
79
103
  paddingInlineStart: paddingInlineStart,
80
- paddingInlineEnd: paddingInlineEnd
104
+ paddingInlineEnd: paddingInlineEnd,
105
+ onClick: onClick
81
106
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
82
107
  ,
83
108
  xcss: styles
@@ -86,16 +111,17 @@ const Link = ({
86
111
 
87
112
  // Workarounds to support generic types with forwardRef
88
113
  /**
89
- * __UNSAFE_LINK__
114
+ * __UNSAFE_ANCHOR__
90
115
  *
91
116
  * @internal Still under development. Do not use.
92
117
  *
93
- * A Link is a primitive component that renders an `<a>` anchor. It utilizes
94
- * the configured router link component in the AppProvider if set.
118
+ * 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.
119
+ *
120
+ * This component is mostly used by other design system components, such as the [link component](/components/link/usage).
95
121
  *
96
- * - [Examples](https://atlassian.design/components/primitives/link/examples)
97
- * - [Code](https://atlassian.design/components/primitives/link/code)
98
- * - [Usage](https://atlassian.design/components/primitives/link/usage)
122
+ * - [Examples](https://atlassian.design/components/primitives/anchor/examples)
123
+ * - [Code](https://atlassian.design/components/primitives/anchor/code)
124
+ * - [Usage](https://atlassian.design/components/primitives/anchor/usage)
99
125
  */
100
- const UNSAFE_LINK = /*#__PURE__*/forwardRef(Link);
101
- export default UNSAFE_LINK;
126
+ const UNSAFE_ANCHOR = /*#__PURE__*/forwardRef(Anchor);
127
+ export default UNSAFE_ANCHOR;
@@ -1,5 +1,8 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import React, { forwardRef } from 'react';
2
+ import React, { forwardRef, useCallback, useContext } from 'react';
3
+ import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next';
4
+ import noop from '@atlaskit/ds-lib/noop';
5
+ import InteractionContext from '@atlaskit/interaction-context';
3
6
  import { xcss } from '../xcss/xcss';
4
7
  import Box from './box';
5
8
  // TODO: Duplicated FocusRing styles due to lack of `xcss` support
@@ -47,8 +50,27 @@ const UNSAFE_PRESSABLE = /*#__PURE__*/forwardRef(({
47
50
  type = 'button',
48
51
  testId,
49
52
  xcss: xcssStyles,
53
+ onClick: providedOnClick = noop,
54
+ interactionName,
55
+ componentName,
56
+ analyticsContext,
50
57
  ...htmlAttributes
51
58
  }, ref) => {
59
+ const interactionContext = useContext(InteractionContext);
60
+ const handleClick = useCallback((e, analyticsEvent) => {
61
+ interactionContext && interactionContext.tracePress(interactionName, e.timeStamp);
62
+ providedOnClick(e, analyticsEvent);
63
+ }, [providedOnClick, interactionContext, interactionName]);
64
+ const onClick = usePlatformLeafEventHandler({
65
+ fn: handleClick,
66
+ action: 'clicked',
67
+ componentName: componentName || 'Pressable',
68
+ packageName: "@atlaskit/primitives",
69
+ packageVersion: "3.0.0",
70
+ analyticsData: analyticsContext,
71
+ actionSubject: 'button'
72
+ });
73
+
52
74
  // Combine default styles with supplied styles. XCSS does not support deep nested arrays
53
75
  let styles = [xcss({
54
76
  cursor: isDisabled ? 'not-allowed' : 'pointer'
@@ -59,6 +81,7 @@ const UNSAFE_PRESSABLE = /*#__PURE__*/forwardRef(({
59
81
  ref: ref,
60
82
  testId: testId,
61
83
  type: type,
84
+ onClick: onClick,
62
85
  backgroundColor: backgroundColor,
63
86
  padding: padding,
64
87
  paddingBlock: paddingBlock,
@@ -1,5 +1,5 @@
1
1
  /** @jsx jsx */
2
- import { createContext, Fragment, useContext } from 'react';
2
+
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';
@@ -48,17 +48,14 @@ const wordBreakMap = {
48
48
  */
49
49
  const useColor = colorProp => {
50
50
  const surface = useSurface();
51
- const inverseTextColor = inverseColorMap[surface];
52
51
 
53
52
  /**
54
53
  * Where the color of the surface is inverted we override the user choice
55
54
  * as there is no valid choice that is not covered by the override.
56
55
  */
57
- const color = inverseTextColor !== null && inverseTextColor !== void 0 ? inverseTextColor : colorProp;
56
+ const color = inverseColorMap.hasOwnProperty(surface) ? inverseColorMap[surface] : colorProp;
58
57
  return color;
59
58
  };
60
- const HasTextAncestorContext = /*#__PURE__*/createContext(false);
61
- const useHasTextAncestor = () => useContext(HasTextAncestorContext);
62
59
 
63
60
  /**
64
61
  * __Text__
@@ -75,7 +72,7 @@ const Text = ({
75
72
  }) => {
76
73
  const {
77
74
  as: asElement,
78
- color: colorProp = 'color.text',
75
+ color: colorProp,
79
76
  textAlign,
80
77
  testId,
81
78
  id,
@@ -94,16 +91,7 @@ const Text = ({
94
91
  maxLines = props.maxLines;
95
92
  }
96
93
  const color = useColor(colorProp);
97
- const isWrapped = useHasTextAncestor();
98
-
99
- /**
100
- * If the text is already wrapped and applies no props we can just
101
- * render the children directly as a fragment.
102
- */
103
- if (isWrapped && Object.keys(props).length === 0) {
104
- return jsx(Fragment, null, children);
105
- }
106
- const component = jsx(Component, {
94
+ return jsx(Component, {
107
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],
108
96
  style: {
109
97
  WebkitLineClamp: maxLines
@@ -111,10 +99,5 @@ const Text = ({
111
99
  "data-testid": testId,
112
100
  id: id
113
101
  }, children);
114
- return isWrapped ?
115
- // no need to re-apply context if the text is already wrapped
116
- component : jsx(HasTextAncestorContext.Provider, {
117
- value: true
118
- }, component);
119
102
  };
120
103
  export default Text;
@@ -6,4 +6,6 @@ export { default as Flex } from './components/flex';
6
6
  export { default as Grid } from './components/grid';
7
7
  export { default as Bleed } from './components/bleed';
8
8
  export { default as Text } from './components/text';
9
+ export { default as UNSAFE_PRESSABLE } from './components/pressable';
10
+ export { default as UNSAFE_ANCHOR } from './components/anchor';
9
11
  export { media, UNSAFE_media, UNSAFE_BREAKPOINTS_CONFIG } from './responsive';
@@ -2,10 +2,13 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import _typeof from "@babel/runtime/helpers/typeof";
3
3
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
5
- var _excluded = ["href", "children", "backgroundColor", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd", "testId", "xcss", "target", "rel"];
6
- import React, { forwardRef } from 'react';
5
+ var _excluded = ["href", "children", "backgroundColor", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd", "testId", "xcss", "target", "rel", "onClick", "interactionName", "componentName", "analyticsContext"];
6
+ import React, { forwardRef, useCallback, useContext } from 'react';
7
7
  import invariant from 'tiny-invariant';
8
+ import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next';
8
9
  import { useRouterLink } from '@atlaskit/app-provider';
10
+ import noop from '@atlaskit/ds-lib/noop';
11
+ import InteractionContext from '@atlaskit/interaction-context';
9
12
  import { xcss } from '../xcss/xcss';
10
13
  import Box from './box';
11
14
  // TODO: Duplicated FocusRing styles due to lack of `xcss` support
@@ -16,6 +19,9 @@ var baseFocusRingStyles = {
16
19
  outlineStyle: 'solid',
17
20
  outlineOffset: 'space.025'
18
21
  };
22
+ var defaultStyles = xcss({
23
+ textDecoration: 'underline'
24
+ });
19
25
  var focusRingStyles = xcss({
20
26
  ':focus-visible': baseFocusRingStyles,
21
27
  '@supports not selector(*:focus-visible)': {
@@ -29,7 +35,7 @@ var focusRingStyles = xcss({
29
35
  });
30
36
  var IS_EXTERNAL_LINK_REGEX = /^(?:(http|https):\/\/)/;
31
37
  var IS_NON_HTTP_BASED = /^(((mailto|tel|sms):)|(#))/;
32
- var Link = function Link(_ref, ref) {
38
+ var Anchor = function Anchor(_ref, ref) {
33
39
  var href = _ref.href,
34
40
  children = _ref.children,
35
41
  backgroundColor = _ref.backgroundColor,
@@ -44,11 +50,30 @@ var Link = function Link(_ref, ref) {
44
50
  xcssStyles = _ref.xcss,
45
51
  target = _ref.target,
46
52
  rel = _ref.rel,
53
+ _ref$onClick = _ref.onClick,
54
+ providedOnClick = _ref$onClick === void 0 ? noop : _ref$onClick,
55
+ interactionName = _ref.interactionName,
56
+ componentName = _ref.componentName,
57
+ analyticsContext = _ref.analyticsContext,
47
58
  htmlAttributes = _objectWithoutProperties(_ref, _excluded);
59
+ var interactionContext = useContext(InteractionContext);
60
+ var handleClick = useCallback(function (e, analyticsEvent) {
61
+ interactionContext && interactionContext.tracePress(interactionName, e.timeStamp);
62
+ providedOnClick(e, analyticsEvent);
63
+ }, [providedOnClick, interactionContext, interactionName]);
64
+ var onClick = usePlatformLeafEventHandler({
65
+ fn: handleClick,
66
+ action: 'clicked',
67
+ componentName: componentName || 'Anchor',
68
+ packageName: "@atlaskit/primitives",
69
+ packageVersion: "3.0.0",
70
+ analyticsData: analyticsContext,
71
+ actionSubject: 'link'
72
+ });
48
73
  var RouterLink = useRouterLink();
49
74
 
50
75
  // Combine default styles with supplied styles. XCSS does not support deep nested arrays
51
- var styles = Array.isArray(xcssStyles) ? [focusRingStyles].concat(_toConsumableArray(xcssStyles)) : [focusRingStyles, xcssStyles];
76
+ var styles = Array.isArray(xcssStyles) ? [defaultStyles, focusRingStyles].concat(_toConsumableArray(xcssStyles)) : [defaultStyles, focusRingStyles, xcssStyles];
52
77
  var isExternal = typeof href === 'string' && IS_EXTERNAL_LINK_REGEX.test(href);
53
78
  var isNonHttpBased = typeof href === 'string' && IS_NON_HTTP_BASED.test(href);
54
79
 
@@ -61,7 +86,7 @@ var Link = function Link(_ref, ref) {
61
86
  */
62
87
  var isRouterLink = RouterLink && !isExternal && !isNonHttpBased;
63
88
  var hrefObjectUsedWithoutRouterLink = RouterLink === undefined && _typeof(href) === 'object';
64
- invariant(!hrefObjectUsedWithoutRouterLink, "@atlaskit/primitives: Link primitive cannot pass an object to 'href' unless a router link is configured in the AppProvider");
89
+ invariant(!hrefObjectUsedWithoutRouterLink, "@atlaskit/primitives: Anchor primitive cannot pass an object to 'href' unless a router link is configured in the AppProvider");
65
90
  return /*#__PURE__*/React.createElement(Box
66
91
  // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
67
92
  , _extends({}, htmlAttributes, {
@@ -80,7 +105,8 @@ var Link = function Link(_ref, ref) {
80
105
  paddingBlockEnd: paddingBlockEnd,
81
106
  paddingInline: paddingInline,
82
107
  paddingInlineStart: paddingInlineStart,
83
- paddingInlineEnd: paddingInlineEnd
108
+ paddingInlineEnd: paddingInlineEnd,
109
+ onClick: onClick
84
110
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
85
111
  ,
86
112
  xcss: styles
@@ -89,16 +115,17 @@ var Link = function Link(_ref, ref) {
89
115
 
90
116
  // Workarounds to support generic types with forwardRef
91
117
  /**
92
- * __UNSAFE_LINK__
118
+ * __UNSAFE_ANCHOR__
93
119
  *
94
120
  * @internal Still under development. Do not use.
95
121
  *
96
- * A Link is a primitive component that renders an `<a>` anchor. It utilizes
97
- * the configured router link component in the AppProvider if set.
122
+ * 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.
123
+ *
124
+ * This component is mostly used by other design system components, such as the [link component](/components/link/usage).
98
125
  *
99
- * - [Examples](https://atlassian.design/components/primitives/link/examples)
100
- * - [Code](https://atlassian.design/components/primitives/link/code)
101
- * - [Usage](https://atlassian.design/components/primitives/link/usage)
126
+ * - [Examples](https://atlassian.design/components/primitives/anchor/examples)
127
+ * - [Code](https://atlassian.design/components/primitives/anchor/code)
128
+ * - [Usage](https://atlassian.design/components/primitives/anchor/usage)
102
129
  */
103
- var UNSAFE_LINK = /*#__PURE__*/forwardRef(Link);
104
- export default UNSAFE_LINK;
130
+ var UNSAFE_ANCHOR = /*#__PURE__*/forwardRef(Anchor);
131
+ export default UNSAFE_ANCHOR;
@@ -1,8 +1,11 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
- var _excluded = ["children", "backgroundColor", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd", "isDisabled", "type", "testId", "xcss"];
5
- import React, { forwardRef } from 'react';
4
+ var _excluded = ["children", "backgroundColor", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd", "isDisabled", "type", "testId", "xcss", "onClick", "interactionName", "componentName", "analyticsContext"];
5
+ import React, { forwardRef, useCallback, useContext } from 'react';
6
+ import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next';
7
+ import noop from '@atlaskit/ds-lib/noop';
8
+ import InteractionContext from '@atlaskit/interaction-context';
6
9
  import { xcss } from '../xcss/xcss';
7
10
  import Box from './box';
8
11
  // TODO: Duplicated FocusRing styles due to lack of `xcss` support
@@ -51,7 +54,27 @@ var UNSAFE_PRESSABLE = /*#__PURE__*/forwardRef(function (_ref, ref) {
51
54
  type = _ref$type === void 0 ? 'button' : _ref$type,
52
55
  testId = _ref.testId,
53
56
  xcssStyles = _ref.xcss,
57
+ _ref$onClick = _ref.onClick,
58
+ providedOnClick = _ref$onClick === void 0 ? noop : _ref$onClick,
59
+ interactionName = _ref.interactionName,
60
+ componentName = _ref.componentName,
61
+ analyticsContext = _ref.analyticsContext,
54
62
  htmlAttributes = _objectWithoutProperties(_ref, _excluded);
63
+ var interactionContext = useContext(InteractionContext);
64
+ var handleClick = useCallback(function (e, analyticsEvent) {
65
+ interactionContext && interactionContext.tracePress(interactionName, e.timeStamp);
66
+ providedOnClick(e, analyticsEvent);
67
+ }, [providedOnClick, interactionContext, interactionName]);
68
+ var onClick = usePlatformLeafEventHandler({
69
+ fn: handleClick,
70
+ action: 'clicked',
71
+ componentName: componentName || 'Pressable',
72
+ packageName: "@atlaskit/primitives",
73
+ packageVersion: "3.0.0",
74
+ analyticsData: analyticsContext,
75
+ actionSubject: 'button'
76
+ });
77
+
55
78
  // Combine default styles with supplied styles. XCSS does not support deep nested arrays
56
79
  var styles = [xcss({
57
80
  cursor: isDisabled ? 'not-allowed' : 'pointer'
@@ -62,6 +85,7 @@ var UNSAFE_PRESSABLE = /*#__PURE__*/forwardRef(function (_ref, ref) {
62
85
  ref: ref,
63
86
  testId: testId,
64
87
  type: type,
88
+ onClick: onClick,
65
89
  backgroundColor: backgroundColor,
66
90
  padding: padding,
67
91
  paddingBlock: paddingBlock,
@@ -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
- import { createContext, Fragment, useContext } from 'react';
7
+
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';
@@ -50,19 +50,14 @@ var wordBreakMap = {
50
50
  */
51
51
  var useColor = function useColor(colorProp) {
52
52
  var surface = useSurface();
53
- var inverseTextColor = inverseColorMap[surface];
54
53
 
55
54
  /**
56
55
  * Where the color of the surface is inverted we override the user choice
57
56
  * as there is no valid choice that is not covered by the override.
58
57
  */
59
- var color = inverseTextColor !== null && inverseTextColor !== void 0 ? inverseTextColor : colorProp;
58
+ var color = inverseColorMap.hasOwnProperty(surface) ? inverseColorMap[surface] : colorProp;
60
59
  return color;
61
60
  };
62
- var HasTextAncestorContext = /*#__PURE__*/createContext(false);
63
- var useHasTextAncestor = function useHasTextAncestor() {
64
- return useContext(HasTextAncestorContext);
65
- };
66
61
 
67
62
  /**
68
63
  * __Text__
@@ -77,8 +72,7 @@ var Text = function Text(_ref) {
77
72
  var children = _ref.children,
78
73
  props = _objectWithoutProperties(_ref, _excluded);
79
74
  var asElement = props.as,
80
- _props$color = props.color,
81
- colorProp = _props$color === void 0 ? 'color.text' : _props$color,
75
+ colorProp = props.color,
82
76
  textAlign = props.textAlign,
83
77
  testId = props.testId,
84
78
  id = props.id,
@@ -97,16 +91,7 @@ var Text = function Text(_ref) {
97
91
  maxLines = props.maxLines;
98
92
  }
99
93
  var color = useColor(colorProp);
100
- var isWrapped = useHasTextAncestor();
101
-
102
- /**
103
- * If the text is already wrapped and applies no props we can just
104
- * render the children directly as a fragment.
105
- */
106
- if (isWrapped && Object.keys(props).length === 0) {
107
- return jsx(Fragment, null, children);
108
- }
109
- var component = jsx(Component, {
94
+ return jsx(Component, {
110
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],
111
96
  style: {
112
97
  WebkitLineClamp: maxLines
@@ -114,10 +99,5 @@ var Text = function Text(_ref) {
114
99
  "data-testid": testId,
115
100
  id: id
116
101
  }, children);
117
- return isWrapped ?
118
- // no need to re-apply context if the text is already wrapped
119
- component : jsx(HasTextAncestorContext.Provider, {
120
- value: true
121
- }, component);
122
102
  };
123
103
  export default Text;
package/dist/esm/index.js CHANGED
@@ -6,4 +6,6 @@ export { default as Flex } from './components/flex';
6
6
  export { default as Grid } from './components/grid';
7
7
  export { default as Bleed } from './components/bleed';
8
8
  export { default as Text } from './components/text';
9
+ export { default as UNSAFE_PRESSABLE } from './components/pressable';
10
+ export { default as UNSAFE_ANCHOR } from './components/anchor';
9
11
  export { media, UNSAFE_media, UNSAFE_BREAKPOINTS_CONFIG } from './responsive';
@@ -0,0 +1,69 @@
1
+ import React, { type ReactNode, type Ref } from 'react';
2
+ import { UIAnalyticsEvent } from '@atlaskit/analytics-next';
3
+ import { type RouterLinkComponentProps } from '@atlaskit/app-provider';
4
+ import { type BoxProps } from './box';
5
+ export type AnchorProps<RouterLinkConfig extends Record<string, any> = never> = RouterLinkComponentProps<RouterLinkConfig> & Omit<BoxProps<'a'>, 'href' | 'as' | 'children' | 'style' | 'onClick'> & {
6
+ /**
7
+ * `children` should be defined to ensure links have text.
8
+ */
9
+ children: ReactNode;
10
+ /**
11
+ * Handler to be called on click. The second argument can be used to track analytics data. See the tutorial in the analytics-next package for details.
12
+ */
13
+ onClick?: (e: React.MouseEvent<HTMLAnchorElement>, analyticsEvent: UIAnalyticsEvent) => void;
14
+ /**
15
+ * An optional name used to identify the interaction type to press listeners. For example, interaction tracing. For more information,
16
+ * see [UFO integration into Design System components](https://go.atlassian.com/react-ufo-dst-integration).
17
+ */
18
+ interactionName?: string;
19
+ /**
20
+ * An optional component name used to identify this component to press listeners. This can be used if a parent component's name is preferred. For example, interaction tracing. For more information,
21
+ * see [UFO integration into Design System components](https://go.atlassian.com/react-ufo-dst-integration).
22
+ */
23
+ componentName?: string;
24
+ /**
25
+ * Additional information to be included in the `context` of analytics events that come from anchor.
26
+ */
27
+ analyticsContext?: Record<string, any>;
28
+ };
29
+ declare const Anchor: <RouterLinkConfig extends Record<string, any> = never>({ href, children, backgroundColor, padding, paddingBlock, paddingBlockStart, paddingBlockEnd, paddingInline, paddingInlineStart, paddingInlineEnd, testId, xcss: xcssStyles, target, rel, onClick: providedOnClick, interactionName, componentName, analyticsContext, ...htmlAttributes }: AnchorProps<RouterLinkConfig>, ref: Ref<HTMLAnchorElement>) => JSX.Element;
30
+ /**
31
+ * __UNSAFE_ANCHOR__
32
+ *
33
+ * @internal Still under development. Do not use.
34
+ *
35
+ * 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.
36
+ *
37
+ * This component is mostly used by other design system components, such as the [link component](/components/link/usage).
38
+ *
39
+ * - [Examples](https://atlassian.design/components/primitives/anchor/examples)
40
+ * - [Code](https://atlassian.design/components/primitives/anchor/code)
41
+ * - [Usage](https://atlassian.design/components/primitives/anchor/usage)
42
+ */
43
+ declare const UNSAFE_ANCHOR: <RouterLinkConfig extends Record<string, any> = never>(props: RouterLinkComponentProps<RouterLinkConfig> & Omit<BoxProps<"a">, "style" | "children" | "as" | "onClick" | "href"> & {
44
+ /**
45
+ * `children` should be defined to ensure links have text.
46
+ */
47
+ children: ReactNode;
48
+ /**
49
+ * Handler to be called on click. The second argument can be used to track analytics data. See the tutorial in the analytics-next package for details.
50
+ */
51
+ onClick?: ((e: React.MouseEvent<HTMLAnchorElement>, analyticsEvent: UIAnalyticsEvent) => void) | undefined;
52
+ /**
53
+ * An optional name used to identify the interaction type to press listeners. For example, interaction tracing. For more information,
54
+ * see [UFO integration into Design System components](https://go.atlassian.com/react-ufo-dst-integration).
55
+ */
56
+ interactionName?: string | undefined;
57
+ /**
58
+ * An optional component name used to identify this component to press listeners. This can be used if a parent component's name is preferred. For example, interaction tracing. For more information,
59
+ * see [UFO integration into Design System components](https://go.atlassian.com/react-ufo-dst-integration).
60
+ */
61
+ componentName?: string | undefined;
62
+ /**
63
+ * Additional information to be included in the `context` of analytics events that come from anchor.
64
+ */
65
+ analyticsContext?: Record<string, any> | undefined;
66
+ } & {
67
+ ref?: React.Ref<HTMLAnchorElement> | undefined;
68
+ }) => ReturnType<typeof Anchor>;
69
+ export default UNSAFE_ANCHOR;
@@ -1,14 +1,32 @@
1
- import { type ReactElement, type ReactNode } from 'react';
1
+ import React, { type ReactNode } from 'react';
2
+ import { UIAnalyticsEvent } from '@atlaskit/analytics-next';
2
3
  import { type BoxProps } from './box';
3
- export type PressableProps = Omit<BoxProps<'button'>, 'disabled' | 'as' | 'children' | 'role' | 'style'> & {
4
+ export type PressableProps = Omit<BoxProps<'button'>, 'disabled' | 'as' | 'children' | 'role' | 'style' | 'onClick'> & {
4
5
  /**
5
6
  * `children` should be defined to ensure buttons are not empty,
6
7
  * because they should have labels.
7
8
  */
8
9
  children: ReactNode;
9
10
  isDisabled?: boolean;
11
+ /**
12
+ * Handler to be called on click. The second argument can be used to track analytics data. See the tutorial in the analytics-next package for details.
13
+ */
14
+ onClick?: (e: React.MouseEvent<HTMLButtonElement>, analyticsEvent: UIAnalyticsEvent) => void;
15
+ /**
16
+ * An optional name used to identify the interaction type to press listeners. For example, interaction tracing. For more information,
17
+ * see [UFO integration into Design System components](https://go.atlassian.com/react-ufo-dst-integration).
18
+ */
19
+ interactionName?: string;
20
+ /**
21
+ * An optional component name used to identify this component to press listeners. This can be used if a parent component's name is preferred. For example, interaction tracing. For more information,
22
+ * see [UFO integration into Design System components](https://go.atlassian.com/react-ufo-dst-integration).
23
+ */
24
+ componentName?: string;
25
+ /**
26
+ * Additional information to be included in the `context` of analytics events that come from pressable.
27
+ */
28
+ analyticsContext?: Record<string, any>;
10
29
  };
11
- type PressableComponent = (props: PressableProps, displayName: string) => ReactElement | null;
12
30
  /**
13
31
  * __UNSAFE_PRESSABLE__
14
32
  *
@@ -20,5 +38,30 @@ type PressableComponent = (props: PressableProps, displayName: string) => ReactE
20
38
  * - [Code](https://atlassian.design/components/primitives/pressable/code)
21
39
  * - [Usage](https://atlassian.design/components/primitives/pressable/usage)
22
40
  */
23
- declare const UNSAFE_PRESSABLE: PressableComponent;
41
+ declare const UNSAFE_PRESSABLE: React.ForwardRefExoticComponent<Pick<Omit<BoxProps<"button">, "style" | "disabled" | "children" | "as" | "role" | "onClick"> & {
42
+ /**
43
+ * `children` should be defined to ensure buttons are not empty,
44
+ * because they should have labels.
45
+ */
46
+ children: ReactNode;
47
+ isDisabled?: boolean | undefined;
48
+ /**
49
+ * Handler to be called on click. The second argument can be used to track analytics data. See the tutorial in the analytics-next package for details.
50
+ */
51
+ onClick?: ((e: React.MouseEvent<HTMLButtonElement>, analyticsEvent: UIAnalyticsEvent) => void) | undefined;
52
+ /**
53
+ * An optional name used to identify the interaction type to press listeners. For example, interaction tracing. For more information,
54
+ * see [UFO integration into Design System components](https://go.atlassian.com/react-ufo-dst-integration).
55
+ */
56
+ interactionName?: string | undefined;
57
+ /**
58
+ * An optional component name used to identify this component to press listeners. This can be used if a parent component's name is preferred. For example, interaction tracing. For more information,
59
+ * see [UFO integration into Design System components](https://go.atlassian.com/react-ufo-dst-integration).
60
+ */
61
+ componentName?: string | undefined;
62
+ /**
63
+ * Additional information to be included in the `context` of analytics events that come from pressable.
64
+ */
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>>;
24
67
  export default UNSAFE_PRESSABLE;
@@ -15,5 +15,9 @@ export { default as Bleed } from './components/bleed';
15
15
  export type { BleedProps } from './components/bleed';
16
16
  export { default as Text } from './components/text';
17
17
  export type { TextProps } from './components/text';
18
+ export { default as UNSAFE_PRESSABLE } from './components/pressable';
19
+ export type { PressableProps as UNSAFE_PressableProps } from './components/pressable';
20
+ export { default as UNSAFE_ANCHOR } from './components/anchor';
21
+ export type { AnchorProps as UNSAFE_AnchorProps } from './components/anchor';
18
22
  export { media, UNSAFE_media, UNSAFE_BREAKPOINTS_CONFIG } from './responsive';
19
23
  export type { Breakpoint, MediaQuery } from './responsive';