@atlaskit/primitives 8.2.0 → 8.2.1
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 +9 -0
- package/dist/cjs/components/anchor.js +91 -55
- package/dist/cjs/components/pressable.js +83 -51
- package/dist/es2019/components/anchor.js +93 -51
- package/dist/es2019/components/pressable.js +85 -47
- package/dist/esm/components/anchor.js +93 -53
- package/dist/esm/components/pressable.js +85 -49
- package/dist/types/components/anchor.d.ts +73 -10
- package/dist/types/components/pressable.d.ts +8 -4
- package/dist/types-ts4.5/components/anchor.d.ts +73 -10
- package/dist/types-ts4.5/components/pressable.d.ts +8 -4
- package/package.json +1 -1
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @jsxRuntime classic
|
|
4
|
+
*/
|
|
5
|
+
/** @jsx jsx */
|
|
6
|
+
import { forwardRef, useCallback, useContext } from 'react';
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
9
|
+
import { css, jsx } from '@emotion/react';
|
|
3
10
|
import { uid } from 'react-uid';
|
|
4
11
|
import invariant from 'tiny-invariant';
|
|
5
12
|
import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next';
|
|
@@ -7,36 +14,47 @@ import { useRouterLink } from '@atlaskit/app-provider';
|
|
|
7
14
|
import noop from '@atlaskit/ds-lib/noop';
|
|
8
15
|
import InteractionContext from '@atlaskit/interaction-context';
|
|
9
16
|
import VisuallyHidden from '@atlaskit/visually-hidden';
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
//
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
//
|
|
25
|
-
':focus':
|
|
26
|
-
// Remove default focus styles for mouse interactions if :focus-visible is supported
|
|
27
|
-
':focus:not(:focus-visible)': {
|
|
17
|
+
import { backgroundColorStylesMap, borderColorMap, borderWidthMap, isSurfaceColorToken, paddingStylesMap, positiveSpaceMap, surfaceColorStylesMap } from '../xcss/style-maps.partial';
|
|
18
|
+
import { parseXcss } from '../xcss/xcss';
|
|
19
|
+
import { SurfaceContext } from './internal/surface-provider';
|
|
20
|
+
// TODO: duplicates FocusRing styles from `@atlaskit/focus-ring`.
|
|
21
|
+
const focusRingStyles = css({
|
|
22
|
+
'&:focus, &:focus-visible': {
|
|
23
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values
|
|
24
|
+
outlineColor: borderColorMap['color.border.focused'],
|
|
25
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values
|
|
26
|
+
outlineOffset: positiveSpaceMap['space.025'],
|
|
27
|
+
outlineStyle: 'solid',
|
|
28
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values
|
|
29
|
+
outlineWidth: borderWidthMap['border.width.outline']
|
|
30
|
+
},
|
|
31
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-selectors
|
|
32
|
+
'&:focus:not(:focus-visible)': {
|
|
28
33
|
outline: 'none'
|
|
29
34
|
},
|
|
30
|
-
':focus-visible': baseFocusRingStyles,
|
|
31
35
|
'@media screen and (forced-colors: active), screen and (-ms-high-contrast: active)': {
|
|
32
|
-
'
|
|
36
|
+
'&:focus-visible': {
|
|
33
37
|
outline: '1px solid'
|
|
34
38
|
}
|
|
35
39
|
}
|
|
36
40
|
});
|
|
41
|
+
const baseStyles = css({
|
|
42
|
+
boxSizing: 'border-box',
|
|
43
|
+
textDecoration: 'underline'
|
|
44
|
+
});
|
|
37
45
|
const IS_EXTERNAL_LINK_REGEX = /^(?:(http|https):\/\/)/;
|
|
38
46
|
const IS_NON_HTTP_BASED = /^(((mailto|tel|sms):)|(#))/;
|
|
39
47
|
const OPENS_NEW_WINDOW_LABEL = '(opens new window)';
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* __Anchor__
|
|
51
|
+
*
|
|
52
|
+
* A primitive for building custom anchor links.
|
|
53
|
+
*
|
|
54
|
+
* - [Examples](https://atlassian.design/components/primitives/anchor/examples)
|
|
55
|
+
* - [Code](https://atlassian.design/components/primitives/anchor/code)
|
|
56
|
+
* - [Usage](https://atlassian.design/components/primitives/anchor/usage)
|
|
57
|
+
*/
|
|
40
58
|
const AnchorNoRef = ({
|
|
41
59
|
href,
|
|
42
60
|
children,
|
|
@@ -48,15 +66,16 @@ const AnchorNoRef = ({
|
|
|
48
66
|
paddingInline,
|
|
49
67
|
paddingInlineStart,
|
|
50
68
|
paddingInlineEnd,
|
|
51
|
-
testId,
|
|
52
|
-
xcss: xcssStyles,
|
|
53
|
-
target,
|
|
54
69
|
onClick: providedOnClick = noop,
|
|
55
70
|
interactionName,
|
|
56
71
|
componentName,
|
|
57
72
|
analyticsContext,
|
|
58
73
|
'aria-label': ariaLabel,
|
|
59
74
|
'aria-labelledby': ariaLabelledBy,
|
|
75
|
+
style,
|
|
76
|
+
target,
|
|
77
|
+
testId,
|
|
78
|
+
xcss,
|
|
60
79
|
...htmlAttributes
|
|
61
80
|
}, ref) => {
|
|
62
81
|
const interactionContext = useContext(InteractionContext);
|
|
@@ -64,6 +83,7 @@ const AnchorNoRef = ({
|
|
|
64
83
|
interactionContext && interactionContext.tracePress(interactionName, e.timeStamp);
|
|
65
84
|
providedOnClick(e, analyticsEvent);
|
|
66
85
|
}, [providedOnClick, interactionContext, interactionName]);
|
|
86
|
+
|
|
67
87
|
// TODO: Use React 18's useId() hook when we update.
|
|
68
88
|
// eslint-disable-next-line @repo/internal/react/disallow-unstable-values
|
|
69
89
|
const opensNewWindowLabelId = uid({
|
|
@@ -74,16 +94,19 @@ const AnchorNoRef = ({
|
|
|
74
94
|
action: 'clicked',
|
|
75
95
|
componentName: componentName || 'Anchor',
|
|
76
96
|
packageName: "@atlaskit/primitives",
|
|
77
|
-
packageVersion: "8.2.
|
|
97
|
+
packageVersion: "8.2.1",
|
|
78
98
|
analyticsData: analyticsContext,
|
|
79
99
|
actionSubject: 'link'
|
|
80
100
|
});
|
|
81
|
-
const RouterLink = useRouterLink();
|
|
82
101
|
|
|
83
|
-
//
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
|
|
102
|
+
// This is to remove className from safeHtmlAttributes
|
|
103
|
+
// @ts-expect-error className doesn't exist in the prop definition but we want to ensure it cannot be applied even if types are bypassed
|
|
104
|
+
const {
|
|
105
|
+
className: _spreadClass,
|
|
106
|
+
...safeHtmlAttributes
|
|
107
|
+
} = htmlAttributes;
|
|
108
|
+
const resolvedStyles = parseXcss(xcss);
|
|
109
|
+
const RouterLink = useRouterLink();
|
|
87
110
|
const isExternal = typeof href === 'string' && IS_EXTERNAL_LINK_REGEX.test(href);
|
|
88
111
|
const isNonHttpBased = typeof href === 'string' && IS_NON_HTTP_BASED.test(href);
|
|
89
112
|
|
|
@@ -97,33 +120,52 @@ const AnchorNoRef = ({
|
|
|
97
120
|
const isRouterLink = RouterLink && !isExternal && !isNonHttpBased;
|
|
98
121
|
const hrefObjectUsedWithoutRouterLink = RouterLink === undefined && typeof href === 'object';
|
|
99
122
|
invariant(!hrefObjectUsedWithoutRouterLink, `@atlaskit/primitives: Anchor primitive cannot pass an object to 'href' unless a router link is configured in the AppProvider`);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
ref: ref
|
|
106
|
-
|
|
107
|
-
|
|
123
|
+
const Component = isRouterLink ? RouterLink : 'a';
|
|
124
|
+
const node = jsx(Component
|
|
125
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
126
|
+
, _extends({
|
|
127
|
+
style: style,
|
|
128
|
+
ref: ref
|
|
129
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
130
|
+
,
|
|
131
|
+
className: resolvedStyles.static
|
|
132
|
+
// eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
|
|
133
|
+
}, safeHtmlAttributes, {
|
|
134
|
+
// @ts-expect-error
|
|
108
135
|
href: !isRouterLink && typeof href !== 'string' ? undefined : href,
|
|
109
136
|
target: target,
|
|
110
|
-
backgroundColor: backgroundColor,
|
|
111
|
-
padding: padding,
|
|
112
|
-
paddingBlock: paddingBlock,
|
|
113
|
-
paddingBlockStart: paddingBlockStart,
|
|
114
|
-
paddingBlockEnd: paddingBlockEnd,
|
|
115
|
-
paddingInline: paddingInline,
|
|
116
|
-
paddingInlineStart: paddingInlineStart,
|
|
117
|
-
paddingInlineEnd: paddingInlineEnd,
|
|
118
137
|
onClick: onClick,
|
|
119
138
|
"aria-label": ariaLabel && target === '_blank' && !ariaLabelledBy ? `${ariaLabel} ${OPENS_NEW_WINDOW_LABEL}` : ariaLabel,
|
|
120
|
-
"aria-labelledby": ariaLabelledBy && target === '_blank' ? `${ariaLabelledBy} ${opensNewWindowLabelId}` : ariaLabelledBy
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
139
|
+
"aria-labelledby": ariaLabelledBy && target === '_blank' ? `${ariaLabelledBy} ${opensNewWindowLabelId}` : ariaLabelledBy,
|
|
140
|
+
css: [baseStyles, focusRingStyles,
|
|
141
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
142
|
+
backgroundColor && backgroundColorStylesMap[backgroundColor],
|
|
143
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
144
|
+
isSurfaceColorToken(backgroundColor) && surfaceColorStylesMap[backgroundColor],
|
|
145
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
146
|
+
padding && paddingStylesMap.padding[padding],
|
|
147
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
148
|
+
paddingBlock && paddingStylesMap.paddingBlock[paddingBlock],
|
|
149
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
150
|
+
paddingBlockStart && paddingStylesMap.paddingBlockStart[paddingBlockStart],
|
|
151
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
152
|
+
paddingBlockEnd && paddingStylesMap.paddingBlockEnd[paddingBlockEnd],
|
|
153
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
154
|
+
paddingInline && paddingStylesMap.paddingInline[paddingInline],
|
|
155
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
156
|
+
paddingInlineStart && paddingStylesMap.paddingInlineStart[paddingInlineStart],
|
|
157
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
158
|
+
paddingInlineEnd && paddingStylesMap.paddingInlineEnd[paddingInlineEnd],
|
|
159
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
160
|
+
resolvedStyles.emotion],
|
|
161
|
+
"data-testid": testId,
|
|
162
|
+
"data-is-router-link": testId ? isRouterLink ? 'true' : 'false' : undefined
|
|
163
|
+
}), children, target === '_blank' && (children && !ariaLabel && !ariaLabelledBy || ariaLabelledBy) && jsx(VisuallyHidden, {
|
|
125
164
|
id: opensNewWindowLabelId
|
|
126
165
|
}, OPENS_NEW_WINDOW_LABEL));
|
|
166
|
+
return backgroundColor ? jsx(SurfaceContext.Provider, {
|
|
167
|
+
value: backgroundColor
|
|
168
|
+
}, node) : node;
|
|
127
169
|
};
|
|
128
170
|
|
|
129
171
|
// Workarounds to support generic types with forwardRef
|
|
@@ -1,32 +1,50 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @jsxRuntime classic
|
|
4
|
+
*/
|
|
5
|
+
/** @jsx jsx */
|
|
6
|
+
import { forwardRef, useCallback, useContext } from 'react';
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
9
|
+
import { css, jsx } from '@emotion/react';
|
|
3
10
|
import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next';
|
|
4
11
|
import noop from '@atlaskit/ds-lib/noop';
|
|
5
12
|
import InteractionContext from '@atlaskit/interaction-context';
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
import { backgroundColorStylesMap, borderColorMap, borderWidthMap, isSurfaceColorToken, paddingStylesMap, positiveSpaceMap, surfaceColorStylesMap } from '../xcss/style-maps.partial';
|
|
14
|
+
import { parseXcss } from '../xcss/xcss';
|
|
15
|
+
import { SurfaceContext } from './internal/surface-provider';
|
|
16
|
+
// This duplicates FocusRing styles from `@atlaskit/focus-ring`.
|
|
17
|
+
const focusRingStyles = css({
|
|
18
|
+
'&:focus, &:focus-visible': {
|
|
19
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values
|
|
20
|
+
outlineColor: borderColorMap['color.border.focused'],
|
|
21
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values
|
|
22
|
+
outlineOffset: positiveSpaceMap['space.025'],
|
|
23
|
+
outlineStyle: 'solid',
|
|
24
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values
|
|
25
|
+
outlineWidth: borderWidthMap['border.width.outline']
|
|
26
|
+
},
|
|
27
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-selectors
|
|
28
|
+
'&:focus:not(:focus-visible)': {
|
|
21
29
|
outline: 'none'
|
|
22
30
|
},
|
|
23
|
-
':focus-visible': baseFocusRingStyles,
|
|
24
31
|
'@media screen and (forced-colors: active), screen and (-ms-high-contrast: active)': {
|
|
25
|
-
'
|
|
32
|
+
'&:focus-visible': {
|
|
26
33
|
outline: '1px solid'
|
|
27
34
|
}
|
|
28
35
|
}
|
|
29
36
|
});
|
|
37
|
+
const baseStyles = css({
|
|
38
|
+
boxSizing: 'border-box',
|
|
39
|
+
appearance: 'none',
|
|
40
|
+
border: 'none'
|
|
41
|
+
});
|
|
42
|
+
const enabledStyles = css({
|
|
43
|
+
cursor: 'pointer'
|
|
44
|
+
});
|
|
45
|
+
const disabledStyles = css({
|
|
46
|
+
cursor: 'not-allowed'
|
|
47
|
+
});
|
|
30
48
|
|
|
31
49
|
/**
|
|
32
50
|
* __Pressable__
|
|
@@ -49,12 +67,13 @@ const Pressable = /*#__PURE__*/forwardRef(({
|
|
|
49
67
|
paddingInlineEnd,
|
|
50
68
|
isDisabled,
|
|
51
69
|
type = 'button',
|
|
52
|
-
testId,
|
|
53
|
-
xcss: xcssStyles,
|
|
54
70
|
onClick: providedOnClick = noop,
|
|
55
71
|
interactionName,
|
|
56
72
|
componentName,
|
|
57
73
|
analyticsContext,
|
|
74
|
+
style,
|
|
75
|
+
testId,
|
|
76
|
+
xcss,
|
|
58
77
|
...htmlAttributes
|
|
59
78
|
}, ref) => {
|
|
60
79
|
const interactionContext = useContext(InteractionContext);
|
|
@@ -67,39 +86,58 @@ const Pressable = /*#__PURE__*/forwardRef(({
|
|
|
67
86
|
action: 'clicked',
|
|
68
87
|
componentName: componentName || 'Pressable',
|
|
69
88
|
packageName: "@atlaskit/primitives",
|
|
70
|
-
packageVersion: "8.2.
|
|
89
|
+
packageVersion: "8.2.1",
|
|
71
90
|
analyticsData: analyticsContext,
|
|
72
91
|
actionSubject: 'button'
|
|
73
92
|
});
|
|
74
93
|
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
ref: ref
|
|
88
|
-
|
|
94
|
+
// This is to remove className from safeHtmlAttributes
|
|
95
|
+
// @ts-expect-error className doesn't exist in the prop definition but we want to ensure it cannot be applied even if types are bypassed
|
|
96
|
+
const {
|
|
97
|
+
className: _spreadClass,
|
|
98
|
+
...safeHtmlAttributes
|
|
99
|
+
} = htmlAttributes;
|
|
100
|
+
const resolvedStyles = parseXcss(xcss);
|
|
101
|
+
const node =
|
|
102
|
+
// eslint-disable-next-line @atlaskit/design-system/no-html-button
|
|
103
|
+
jsx("button", _extends({
|
|
104
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
105
|
+
style: style,
|
|
106
|
+
ref: ref
|
|
107
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
108
|
+
,
|
|
109
|
+
className: resolvedStyles.static
|
|
110
|
+
// eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
|
|
111
|
+
}, safeHtmlAttributes, {
|
|
112
|
+
// eslint-disable-next-line react/button-has-type
|
|
89
113
|
type: type,
|
|
90
114
|
onClick: onClick,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
// eslint-disable-next-line @atlaskit/
|
|
100
|
-
,
|
|
101
|
-
|
|
102
|
-
|
|
115
|
+
disabled: isDisabled,
|
|
116
|
+
css: [baseStyles, focusRingStyles, isDisabled ? disabledStyles : enabledStyles,
|
|
117
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
118
|
+
backgroundColor && backgroundColorStylesMap[backgroundColor],
|
|
119
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
120
|
+
isSurfaceColorToken(backgroundColor) && surfaceColorStylesMap[backgroundColor],
|
|
121
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
122
|
+
padding && paddingStylesMap.padding[padding],
|
|
123
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
124
|
+
paddingBlock && paddingStylesMap.paddingBlock[paddingBlock],
|
|
125
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
126
|
+
paddingBlockStart && paddingStylesMap.paddingBlockStart[paddingBlockStart],
|
|
127
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
128
|
+
paddingBlockEnd && paddingStylesMap.paddingBlockEnd[paddingBlockEnd],
|
|
129
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
130
|
+
paddingInline && paddingStylesMap.paddingInline[paddingInline],
|
|
131
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
132
|
+
paddingInlineStart && paddingStylesMap.paddingInlineStart[paddingInlineStart],
|
|
133
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
134
|
+
paddingInlineEnd && paddingStylesMap.paddingInlineEnd[paddingInlineEnd],
|
|
135
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
136
|
+
resolvedStyles.emotion],
|
|
137
|
+
"data-testid": testId
|
|
103
138
|
}), children);
|
|
139
|
+
return backgroundColor ? jsx(SurfaceContext.Provider, {
|
|
140
|
+
value: backgroundColor
|
|
141
|
+
}, node) : node;
|
|
104
142
|
});
|
|
105
143
|
export default Pressable;
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _typeof from "@babel/runtime/helpers/typeof";
|
|
3
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
4
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
5
|
-
var _excluded = ["href", "children", "backgroundColor", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd", "
|
|
6
|
-
|
|
4
|
+
var _excluded = ["href", "children", "backgroundColor", "padding", "paddingBlock", "paddingBlockStart", "paddingBlockEnd", "paddingInline", "paddingInlineStart", "paddingInlineEnd", "onClick", "interactionName", "componentName", "analyticsContext", "aria-label", "aria-labelledby", "style", "target", "testId", "xcss"],
|
|
5
|
+
_excluded2 = ["className"];
|
|
6
|
+
/**
|
|
7
|
+
* @jsxRuntime classic
|
|
8
|
+
*/
|
|
9
|
+
/** @jsx jsx */
|
|
10
|
+
import { forwardRef, useCallback, useContext } from 'react';
|
|
11
|
+
|
|
12
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
13
|
+
import { css, jsx } from '@emotion/react';
|
|
7
14
|
import { uid } from 'react-uid';
|
|
8
15
|
import invariant from 'tiny-invariant';
|
|
9
16
|
import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next';
|
|
@@ -11,36 +18,47 @@ import { useRouterLink } from '@atlaskit/app-provider';
|
|
|
11
18
|
import noop from '@atlaskit/ds-lib/noop';
|
|
12
19
|
import InteractionContext from '@atlaskit/interaction-context';
|
|
13
20
|
import VisuallyHidden from '@atlaskit/visually-hidden';
|
|
14
|
-
import {
|
|
15
|
-
import
|
|
16
|
-
|
|
17
|
-
//
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
//
|
|
29
|
-
':focus':
|
|
30
|
-
// Remove default focus styles for mouse interactions if :focus-visible is supported
|
|
31
|
-
':focus:not(:focus-visible)': {
|
|
21
|
+
import { backgroundColorStylesMap, borderColorMap, borderWidthMap, isSurfaceColorToken, paddingStylesMap, positiveSpaceMap, surfaceColorStylesMap } from '../xcss/style-maps.partial';
|
|
22
|
+
import { parseXcss } from '../xcss/xcss';
|
|
23
|
+
import { SurfaceContext } from './internal/surface-provider';
|
|
24
|
+
// TODO: duplicates FocusRing styles from `@atlaskit/focus-ring`.
|
|
25
|
+
var focusRingStyles = css({
|
|
26
|
+
'&:focus, &:focus-visible': {
|
|
27
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values
|
|
28
|
+
outlineColor: borderColorMap['color.border.focused'],
|
|
29
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values
|
|
30
|
+
outlineOffset: positiveSpaceMap['space.025'],
|
|
31
|
+
outlineStyle: 'solid',
|
|
32
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values
|
|
33
|
+
outlineWidth: borderWidthMap['border.width.outline']
|
|
34
|
+
},
|
|
35
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-selectors
|
|
36
|
+
'&:focus:not(:focus-visible)': {
|
|
32
37
|
outline: 'none'
|
|
33
38
|
},
|
|
34
|
-
':focus-visible': baseFocusRingStyles,
|
|
35
39
|
'@media screen and (forced-colors: active), screen and (-ms-high-contrast: active)': {
|
|
36
|
-
'
|
|
40
|
+
'&:focus-visible': {
|
|
37
41
|
outline: '1px solid'
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
});
|
|
45
|
+
var baseStyles = css({
|
|
46
|
+
boxSizing: 'border-box',
|
|
47
|
+
textDecoration: 'underline'
|
|
48
|
+
});
|
|
41
49
|
var IS_EXTERNAL_LINK_REGEX = /^(?:(http|https):\/\/)/;
|
|
42
50
|
var IS_NON_HTTP_BASED = /^(((mailto|tel|sms):)|(#))/;
|
|
43
51
|
var OPENS_NEW_WINDOW_LABEL = '(opens new window)';
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* __Anchor__
|
|
55
|
+
*
|
|
56
|
+
* A primitive for building custom anchor links.
|
|
57
|
+
*
|
|
58
|
+
* - [Examples](https://atlassian.design/components/primitives/anchor/examples)
|
|
59
|
+
* - [Code](https://atlassian.design/components/primitives/anchor/code)
|
|
60
|
+
* - [Usage](https://atlassian.design/components/primitives/anchor/usage)
|
|
61
|
+
*/
|
|
44
62
|
var AnchorNoRef = function AnchorNoRef(_ref, ref) {
|
|
45
63
|
var href = _ref.href,
|
|
46
64
|
children = _ref.children,
|
|
@@ -52,9 +70,6 @@ var AnchorNoRef = function AnchorNoRef(_ref, ref) {
|
|
|
52
70
|
paddingInline = _ref.paddingInline,
|
|
53
71
|
paddingInlineStart = _ref.paddingInlineStart,
|
|
54
72
|
paddingInlineEnd = _ref.paddingInlineEnd,
|
|
55
|
-
testId = _ref.testId,
|
|
56
|
-
xcssStyles = _ref.xcss,
|
|
57
|
-
target = _ref.target,
|
|
58
73
|
_ref$onClick = _ref.onClick,
|
|
59
74
|
providedOnClick = _ref$onClick === void 0 ? noop : _ref$onClick,
|
|
60
75
|
interactionName = _ref.interactionName,
|
|
@@ -62,12 +77,17 @@ var AnchorNoRef = function AnchorNoRef(_ref, ref) {
|
|
|
62
77
|
analyticsContext = _ref.analyticsContext,
|
|
63
78
|
ariaLabel = _ref['aria-label'],
|
|
64
79
|
ariaLabelledBy = _ref['aria-labelledby'],
|
|
80
|
+
style = _ref.style,
|
|
81
|
+
target = _ref.target,
|
|
82
|
+
testId = _ref.testId,
|
|
83
|
+
xcss = _ref.xcss,
|
|
65
84
|
htmlAttributes = _objectWithoutProperties(_ref, _excluded);
|
|
66
85
|
var interactionContext = useContext(InteractionContext);
|
|
67
86
|
var handleClick = useCallback(function (e, analyticsEvent) {
|
|
68
87
|
interactionContext && interactionContext.tracePress(interactionName, e.timeStamp);
|
|
69
88
|
providedOnClick(e, analyticsEvent);
|
|
70
89
|
}, [providedOnClick, interactionContext, interactionName]);
|
|
90
|
+
|
|
71
91
|
// TODO: Use React 18's useId() hook when we update.
|
|
72
92
|
// eslint-disable-next-line @repo/internal/react/disallow-unstable-values
|
|
73
93
|
var opensNewWindowLabelId = uid({
|
|
@@ -78,16 +98,17 @@ var AnchorNoRef = function AnchorNoRef(_ref, ref) {
|
|
|
78
98
|
action: 'clicked',
|
|
79
99
|
componentName: componentName || 'Anchor',
|
|
80
100
|
packageName: "@atlaskit/primitives",
|
|
81
|
-
packageVersion: "8.2.
|
|
101
|
+
packageVersion: "8.2.1",
|
|
82
102
|
analyticsData: analyticsContext,
|
|
83
103
|
actionSubject: 'link'
|
|
84
104
|
});
|
|
85
|
-
var RouterLink = useRouterLink();
|
|
86
105
|
|
|
87
|
-
//
|
|
88
|
-
//
|
|
89
|
-
|
|
90
|
-
|
|
106
|
+
// This is to remove className from safeHtmlAttributes
|
|
107
|
+
// @ts-expect-error className doesn't exist in the prop definition but we want to ensure it cannot be applied even if types are bypassed
|
|
108
|
+
var _spreadClass = htmlAttributes.className,
|
|
109
|
+
safeHtmlAttributes = _objectWithoutProperties(htmlAttributes, _excluded2);
|
|
110
|
+
var resolvedStyles = parseXcss(xcss);
|
|
111
|
+
var RouterLink = useRouterLink();
|
|
91
112
|
var isExternal = typeof href === 'string' && IS_EXTERNAL_LINK_REGEX.test(href);
|
|
92
113
|
var isNonHttpBased = typeof href === 'string' && IS_NON_HTTP_BASED.test(href);
|
|
93
114
|
|
|
@@ -101,33 +122,52 @@ var AnchorNoRef = function AnchorNoRef(_ref, ref) {
|
|
|
101
122
|
var isRouterLink = RouterLink && !isExternal && !isNonHttpBased;
|
|
102
123
|
var hrefObjectUsedWithoutRouterLink = RouterLink === undefined && _typeof(href) === 'object';
|
|
103
124
|
invariant(!hrefObjectUsedWithoutRouterLink, "@atlaskit/primitives: Anchor primitive cannot pass an object to 'href' unless a router link is configured in the AppProvider");
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
ref: ref
|
|
110
|
-
|
|
111
|
-
|
|
125
|
+
var Component = isRouterLink ? RouterLink : 'a';
|
|
126
|
+
var node = jsx(Component
|
|
127
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
128
|
+
, _extends({
|
|
129
|
+
style: style,
|
|
130
|
+
ref: ref
|
|
131
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
132
|
+
,
|
|
133
|
+
className: resolvedStyles.static
|
|
134
|
+
// eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
|
|
135
|
+
}, safeHtmlAttributes, {
|
|
136
|
+
// @ts-expect-error
|
|
112
137
|
href: !isRouterLink && typeof href !== 'string' ? undefined : href,
|
|
113
138
|
target: target,
|
|
114
|
-
backgroundColor: backgroundColor,
|
|
115
|
-
padding: padding,
|
|
116
|
-
paddingBlock: paddingBlock,
|
|
117
|
-
paddingBlockStart: paddingBlockStart,
|
|
118
|
-
paddingBlockEnd: paddingBlockEnd,
|
|
119
|
-
paddingInline: paddingInline,
|
|
120
|
-
paddingInlineStart: paddingInlineStart,
|
|
121
|
-
paddingInlineEnd: paddingInlineEnd,
|
|
122
139
|
onClick: onClick,
|
|
123
140
|
"aria-label": ariaLabel && target === '_blank' && !ariaLabelledBy ? "".concat(ariaLabel, " ").concat(OPENS_NEW_WINDOW_LABEL) : ariaLabel,
|
|
124
|
-
"aria-labelledby": ariaLabelledBy && target === '_blank' ? "".concat(ariaLabelledBy, " ").concat(opensNewWindowLabelId) : ariaLabelledBy
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
141
|
+
"aria-labelledby": ariaLabelledBy && target === '_blank' ? "".concat(ariaLabelledBy, " ").concat(opensNewWindowLabelId) : ariaLabelledBy,
|
|
142
|
+
css: [baseStyles, focusRingStyles,
|
|
143
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
144
|
+
backgroundColor && backgroundColorStylesMap[backgroundColor],
|
|
145
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
146
|
+
isSurfaceColorToken(backgroundColor) && surfaceColorStylesMap[backgroundColor],
|
|
147
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
148
|
+
padding && paddingStylesMap.padding[padding],
|
|
149
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
150
|
+
paddingBlock && paddingStylesMap.paddingBlock[paddingBlock],
|
|
151
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
152
|
+
paddingBlockStart && paddingStylesMap.paddingBlockStart[paddingBlockStart],
|
|
153
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
154
|
+
paddingBlockEnd && paddingStylesMap.paddingBlockEnd[paddingBlockEnd],
|
|
155
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
156
|
+
paddingInline && paddingStylesMap.paddingInline[paddingInline],
|
|
157
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
158
|
+
paddingInlineStart && paddingStylesMap.paddingInlineStart[paddingInlineStart],
|
|
159
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
|
|
160
|
+
paddingInlineEnd && paddingStylesMap.paddingInlineEnd[paddingInlineEnd],
|
|
161
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
162
|
+
resolvedStyles.emotion],
|
|
163
|
+
"data-testid": testId,
|
|
164
|
+
"data-is-router-link": testId ? isRouterLink ? 'true' : 'false' : undefined
|
|
165
|
+
}), children, target === '_blank' && (children && !ariaLabel && !ariaLabelledBy || ariaLabelledBy) && jsx(VisuallyHidden, {
|
|
129
166
|
id: opensNewWindowLabelId
|
|
130
167
|
}, OPENS_NEW_WINDOW_LABEL));
|
|
168
|
+
return backgroundColor ? jsx(SurfaceContext.Provider, {
|
|
169
|
+
value: backgroundColor
|
|
170
|
+
}, node) : node;
|
|
131
171
|
};
|
|
132
172
|
|
|
133
173
|
// Workarounds to support generic types with forwardRef
|