@transferwise/components 0.0.0-experimental-a656242 → 0.0.0-experimental-887f2e6
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/build/avatarLayout/AvatarLayout.js +9 -2
- package/build/avatarLayout/AvatarLayout.js.map +1 -1
- package/build/avatarLayout/AvatarLayout.mjs +9 -2
- package/build/avatarLayout/AvatarLayout.mjs.map +1 -1
- package/build/avatarView/AvatarView.js +1 -12
- package/build/avatarView/AvatarView.js.map +1 -1
- package/build/avatarView/AvatarView.mjs +1 -12
- package/build/avatarView/AvatarView.mjs.map +1 -1
- package/build/button/Button.js +78 -79
- package/build/button/Button.js.map +1 -1
- package/build/button/Button.mjs +79 -80
- package/build/button/Button.mjs.map +1 -1
- package/build/button/Button.resolver.js +78 -0
- package/build/button/Button.resolver.js.map +1 -0
- package/build/button/Button.resolver.mjs +76 -0
- package/build/button/Button.resolver.mjs.map +1 -0
- package/build/button/LegacyButton.js +114 -0
- package/build/button/LegacyButton.js.map +1 -0
- package/build/button/LegacyButton.mjs +112 -0
- package/build/button/LegacyButton.mjs.map +1 -0
- package/build/circularButton/CircularButton.js +21 -18
- package/build/circularButton/CircularButton.js.map +1 -1
- package/build/circularButton/CircularButton.mjs +22 -19
- package/build/circularButton/CircularButton.mjs.map +1 -1
- package/build/criticalBanner/CriticalCommsBanner.js +2 -2
- package/build/criticalBanner/CriticalCommsBanner.js.map +1 -1
- package/build/criticalBanner/CriticalCommsBanner.mjs +1 -1
- package/build/definitionList/DefinitionList.js.map +1 -1
- package/build/definitionList/DefinitionList.mjs.map +1 -1
- package/build/header/Header.js +2 -2
- package/build/header/Header.js.map +1 -1
- package/build/header/Header.mjs +1 -1
- package/build/i18n/de.json +0 -1
- package/build/i18n/de.json.js +0 -1
- package/build/i18n/de.json.js.map +1 -1
- package/build/i18n/de.json.mjs +0 -1
- package/build/i18n/de.json.mjs.map +1 -1
- package/build/i18n/it.json +0 -1
- package/build/i18n/it.json.js +0 -1
- package/build/i18n/it.json.js.map +1 -1
- package/build/i18n/it.json.mjs +0 -1
- package/build/i18n/it.json.mjs.map +1 -1
- package/build/i18n/th.json +0 -1
- package/build/i18n/th.json.js +0 -1
- package/build/i18n/th.json.js.map +1 -1
- package/build/i18n/th.json.mjs +0 -1
- package/build/i18n/th.json.mjs.map +1 -1
- package/build/index.js +2 -2
- package/build/index.mjs +1 -1
- package/build/link/Link.js +8 -3
- package/build/link/Link.js.map +1 -1
- package/build/link/Link.mjs +8 -3
- package/build/link/Link.mjs.map +1 -1
- package/build/main.css +416 -17
- package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.js +1 -3
- package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.js.map +1 -1
- package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.mjs +1 -3
- package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.mjs.map +1 -1
- package/build/primitives/PrimitiveButton/src/PrimitiveButton.js +1 -4
- package/build/primitives/PrimitiveButton/src/PrimitiveButton.js.map +1 -1
- package/build/primitives/PrimitiveButton/src/PrimitiveButton.mjs +1 -4
- package/build/primitives/PrimitiveButton/src/PrimitiveButton.mjs.map +1 -1
- package/build/select/Select.js +5 -3
- package/build/select/Select.js.map +1 -1
- package/build/select/Select.mjs +4 -2
- package/build/select/Select.mjs.map +1 -1
- package/build/styles/avatarLayout/AvatarLayout.css +11 -0
- package/build/styles/button/Button.css +240 -16
- package/build/styles/button/Button.vars.css +55 -0
- package/build/styles/button/LegacyButton.css +23 -0
- package/build/styles/circularButton/CircularButton.css +158 -17
- package/build/styles/main.css +416 -17
- package/build/types/avatarLayout/AvatarLayout.d.ts +1 -2
- package/build/types/avatarLayout/AvatarLayout.d.ts.map +1 -1
- package/build/types/avatarLayout/index.d.ts +1 -0
- package/build/types/avatarLayout/index.d.ts.map +1 -1
- package/build/types/avatarView/AvatarView.d.ts.map +1 -1
- package/build/types/button/Button.d.ts +1 -23
- package/build/types/button/Button.d.ts.map +1 -1
- package/build/types/button/Button.resolver.d.ts +31 -0
- package/build/types/button/Button.resolver.d.ts.map +1 -0
- package/build/types/button/Button.types.d.ts +67 -0
- package/build/types/button/Button.types.d.ts.map +1 -0
- package/build/types/button/LegacyButton.d.ts +30 -0
- package/build/types/button/LegacyButton.d.ts.map +1 -0
- package/build/types/button/index.d.ts +2 -2
- package/build/types/button/index.d.ts.map +1 -1
- package/build/types/circularButton/CircularButton.d.ts +4 -11
- package/build/types/circularButton/CircularButton.d.ts.map +1 -1
- package/build/types/definitionList/DefinitionList.d.ts +2 -1
- package/build/types/definitionList/DefinitionList.d.ts.map +1 -1
- package/build/types/link/Link.d.ts +2 -2
- package/build/types/link/Link.d.ts.map +1 -1
- package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.d.ts.map +1 -1
- package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.d.ts +1 -1
- package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.d.ts.map +1 -1
- package/build/types/primitives/PrimitiveButton/src/PrimitiveButton.d.ts.map +1 -1
- package/build/types/select/Select.d.ts.map +1 -1
- package/build/upload/steps/completeStep/completeStep.js +2 -2
- package/build/upload/steps/completeStep/completeStep.js.map +1 -1
- package/build/upload/steps/completeStep/completeStep.mjs +1 -1
- package/build/upload/steps/processingStep/processingStep.js +2 -2
- package/build/upload/steps/processingStep/processingStep.js.map +1 -1
- package/build/upload/steps/processingStep/processingStep.mjs +1 -1
- package/build/uploadInput/UploadInput.js +3 -3
- package/build/uploadInput/UploadInput.js.map +1 -1
- package/build/uploadInput/UploadInput.mjs +1 -1
- package/package.json +3 -3
- package/src/avatarLayout/AvatarLayout.css +11 -0
- package/src/avatarLayout/AvatarLayout.less +18 -1
- package/src/avatarLayout/AvatarLayout.tsx +11 -3
- package/src/avatarLayout/index.ts +1 -0
- package/src/avatarView/AvatarView.tsx +1 -15
- package/src/button/Button.css +240 -16
- package/src/button/Button.less +208 -14
- package/src/button/Button.resolver.tsx +120 -0
- package/src/button/Button.spec.tsx +54 -231
- package/src/button/Button.story.tsx +610 -137
- package/src/button/Button.tsx +88 -132
- package/src/button/Button.types.ts +88 -0
- package/src/button/Button.vars.css +55 -0
- package/src/button/Button.vars.less +69 -0
- package/src/button/LegacyButton.css +23 -0
- package/src/button/LegacyButton.less +24 -0
- package/src/button/LegacyButton.spec.tsx +146 -0
- package/src/button/LegacyButton.story.tsx +224 -0
- package/src/button/LegacyButton.tsx +161 -0
- package/src/button/index.ts +2 -3
- package/src/circularButton/CircularButton.css +158 -17
- package/src/circularButton/CircularButton.less +91 -22
- package/src/circularButton/CircularButton.story.tsx +24 -45
- package/src/circularButton/CircularButton.tsx +25 -38
- package/src/circularButton/_button-label-states.less +34 -0
- package/src/definitionList/DefinitionList.spec.js +91 -0
- package/src/definitionList/DefinitionList.story.tsx +57 -57
- package/src/definitionList/DefinitionList.tsx +1 -1
- package/src/flowNavigation/__snapshots__/FlowNavigation.spec.js.snap +1 -1
- package/src/i18n/de.json +0 -1
- package/src/i18n/it.json +0 -1
- package/src/i18n/th.json +0 -1
- package/src/iconButton/IconButton.story.tsx +6 -6
- package/src/inputs/SelectInput.story.tsx +1 -1
- package/src/link/Link.tsx +15 -6
- package/src/main.css +416 -17
- package/src/main.less +1 -0
- package/src/primitives/PrimitiveAnchor/src/PrimitiveAnchor.tsx +1 -7
- package/src/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.ts +1 -1
- package/src/primitives/PrimitiveAnchor/test/PrimitiveAnchor.spec.tsx +1 -3
- package/src/primitives/PrimitiveButton/src/PrimitiveButton.tsx +1 -8
- package/src/primitives/PrimitiveButton/test/PrimitiveButton.spec.tsx +2 -5
- package/src/select/Select.tsx +1 -0
- package/src/slidingPanel/SlidingPanel.spec.js +56 -0
- package/src/button/__snapshots__/Button.spec.tsx.snap +0 -309
- package/src/slidingPanel/SlidingPanel.spec.tsx +0 -69
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var clsx = require('clsx');
|
|
4
4
|
var AvatarView = require('../avatarView/AvatarView.js');
|
|
5
|
+
require('@transferwise/neptune-validation');
|
|
6
|
+
require('react');
|
|
7
|
+
var useDirection = require('../common/hooks/useDirection/useDirection.js');
|
|
8
|
+
require('../common/propsValues/breakpoint.js');
|
|
5
9
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
10
|
|
|
7
11
|
function AvatarLayout({
|
|
@@ -13,6 +17,9 @@ function AvatarLayout({
|
|
|
13
17
|
...restProps
|
|
14
18
|
}) {
|
|
15
19
|
const orientation = size === 16 && orientationProp === 'diagonal' ? 'horizontal' : orientationProp;
|
|
20
|
+
const {
|
|
21
|
+
isRTL
|
|
22
|
+
} = useDirection.useDirection();
|
|
16
23
|
const isDiagonal = orientation === 'diagonal';
|
|
17
24
|
const avatarSize = isDiagonal ? DIAGONAL_LAYOUT_STYLE_CONFIG[size]?.avatarSize : size;
|
|
18
25
|
return avatars.length < 1 ? null : avatars.length === 1 ? /*#__PURE__*/jsxRuntime.jsx(AvatarView, {
|
|
@@ -34,9 +41,9 @@ function AvatarLayout({
|
|
|
34
41
|
...avatar
|
|
35
42
|
}, index) => /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
36
43
|
className: clsx.clsx({
|
|
37
|
-
[`np-avatar-layout-${orientation}-child`]: index !== 0
|
|
44
|
+
[`np-avatar-layout-${orientation}-child`]: !isDiagonal && isRTL ? index !== avatars.length - 1 : index !== 0
|
|
38
45
|
}, {
|
|
39
|
-
[`np-avatar-layout-${orientation}-mask`]: index !== avatars.length - 1
|
|
46
|
+
[`np-avatar-layout-${orientation}-mask`]: !isDiagonal && isRTL ? index !== 0 : index !== avatars.length - 1
|
|
40
47
|
}),
|
|
41
48
|
children: /*#__PURE__*/jsxRuntime.jsx(AvatarView, {
|
|
42
49
|
...avatar,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AvatarLayout.js","sources":["../../src/avatarLayout/AvatarLayout.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport AvatarView, { AvatarViewProps } from '../avatarView';\n\
|
|
1
|
+
{"version":3,"file":"AvatarLayout.js","sources":["../../src/avatarLayout/AvatarLayout.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport AvatarView, { AvatarViewProps } from '../avatarView';\nimport { useDirection } from '../common/hooks';\n\nexport type SingleAvatarType = { asset?: AvatarViewProps['children'] } & Omit<\n AvatarViewProps,\n 'notification' | 'selected' | 'size' | 'badge' | 'children' | 'interactive'\n>;\n\nexport type Props = {\n avatars: SingleAvatarType[];\n orientation?: 'horizontal' | 'diagonal';\n} & Pick<\n AvatarViewProps,\n 'size' | 'interactive' | 'className' | 'role' | 'aria-label' | 'aria-labelledby' | 'aria-hidden'\n>;\n\nexport default function AvatarLayout({\n avatars = [],\n orientation: orientationProp = 'horizontal',\n size = 48,\n className,\n interactive,\n ...restProps\n}: Props) {\n const orientation =\n size === 16 && orientationProp === 'diagonal' ? 'horizontal' : orientationProp;\n const { isRTL } = useDirection();\n const isDiagonal = orientation === 'diagonal';\n const avatarSize = isDiagonal ? DIAGONAL_LAYOUT_STYLE_CONFIG[size]?.avatarSize : size;\n return avatars.length < 1 ? null : avatars.length === 1 ? (\n <AvatarView {...avatars[0]} size={size}>\n {avatars[0].asset}\n </AvatarView>\n ) : (\n <div\n className={clsx('np-avatar-layout', `np-avatar-layout-${orientation}`, className)}\n style={{\n // @ts-expect-error CSS custom props allowed\n '--np-avatar-layout-size': `${size}px`,\n '--np-avatar-size': `${avatarSize}px`,\n '--np-avatar-offset': `${isDiagonal ? DIAGONAL_LAYOUT_STYLE_CONFIG[size].offset : HORIZONTAL_LAYOUT_OFFSET[size]}px`,\n }}\n {...restProps}\n >\n {avatars.map(({ asset, style, ...avatar }, index) => (\n <div\n // eslint-disable-next-line react/no-array-index-key\n key={index}\n className={clsx(\n {\n [`np-avatar-layout-${orientation}-child`]:\n !isDiagonal && isRTL ? index !== avatars.length - 1 : index !== 0,\n },\n {\n [`np-avatar-layout-${orientation}-mask`]:\n !isDiagonal && isRTL ? index !== 0 : index !== avatars.length - 1,\n },\n )}\n >\n <AvatarView\n {...avatar}\n size={avatarSize as Props['size']}\n style={{\n ...(isDiagonal && {\n '--circle-size': `${avatarSize}px`,\n '--circle-icon-size': `${DIAGONAL_LAYOUT_STYLE_CONFIG[size].iconSize}px`,\n '--circle-font-size': `${DIAGONAL_LAYOUT_STYLE_CONFIG[size].fontSize}px`,\n }),\n ...style,\n }}\n interactive={interactive}\n >\n {asset}\n </AvatarView>\n </div>\n ))}\n </div>\n );\n}\n\n/** Diagonal layout have custom sizes for avatar, font and icon */\nconst DIAGONAL_LAYOUT_STYLE_CONFIG = {\n // Diagonal layout doesn't support 16 size\n 16: { avatarSize: undefined, offset: undefined, fontSize: undefined, iconSize: undefined },\n 24: { avatarSize: 15, offset: 2.5, fontSize: 8, iconSize: 11.25 },\n 32: { avatarSize: 20, offset: 2.5, fontSize: 12, iconSize: 15 },\n 40: { avatarSize: 24, offset: 4.5, fontSize: 12, iconSize: 18 },\n 48: { avatarSize: 30, offset: 3.5, fontSize: 14, iconSize: 16.87 },\n 56: { avatarSize: 34, offset: 5, fontSize: 14, iconSize: 19.12 },\n 72: { avatarSize: 44, offset: 6, fontSize: 22, iconSize: 22 },\n};\n\n/** Horizontal layout have custom offset between avatars */\nconst HORIZONTAL_LAYOUT_OFFSET = {\n 16: 2,\n 24: 2,\n 32: 4,\n 40: 4,\n 48: 4,\n 56: 5,\n 72: 5,\n};\n"],"names":["AvatarLayout","avatars","orientation","orientationProp","size","className","interactive","restProps","isRTL","useDirection","isDiagonal","avatarSize","DIAGONAL_LAYOUT_STYLE_CONFIG","length","_jsx","AvatarView","children","asset","clsx","style","offset","HORIZONTAL_LAYOUT_OFFSET","map","avatar","index","iconSize","fontSize","undefined"],"mappings":";;;;;;;;;;AAiBc,SAAUA,YAAYA,CAAC;AACnCC,EAAAA,OAAO,GAAG,EAAE;EACZC,WAAW,EAAEC,eAAe,GAAG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,EAAE,EAAE,CAAA;CACL;;;;"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { clsx } from 'clsx';
|
|
2
2
|
import AvatarView from '../avatarView/AvatarView.mjs';
|
|
3
|
+
import '@transferwise/neptune-validation';
|
|
4
|
+
import 'react';
|
|
5
|
+
import { useDirection } from '../common/hooks/useDirection/useDirection.mjs';
|
|
6
|
+
import '../common/propsValues/breakpoint.mjs';
|
|
3
7
|
import { jsx } from 'react/jsx-runtime';
|
|
4
8
|
|
|
5
9
|
function AvatarLayout({
|
|
@@ -11,6 +15,9 @@ function AvatarLayout({
|
|
|
11
15
|
...restProps
|
|
12
16
|
}) {
|
|
13
17
|
const orientation = size === 16 && orientationProp === 'diagonal' ? 'horizontal' : orientationProp;
|
|
18
|
+
const {
|
|
19
|
+
isRTL
|
|
20
|
+
} = useDirection();
|
|
14
21
|
const isDiagonal = orientation === 'diagonal';
|
|
15
22
|
const avatarSize = isDiagonal ? DIAGONAL_LAYOUT_STYLE_CONFIG[size]?.avatarSize : size;
|
|
16
23
|
return avatars.length < 1 ? null : avatars.length === 1 ? /*#__PURE__*/jsx(AvatarView, {
|
|
@@ -32,9 +39,9 @@ function AvatarLayout({
|
|
|
32
39
|
...avatar
|
|
33
40
|
}, index) => /*#__PURE__*/jsx("div", {
|
|
34
41
|
className: clsx({
|
|
35
|
-
[`np-avatar-layout-${orientation}-child`]: index !== 0
|
|
42
|
+
[`np-avatar-layout-${orientation}-child`]: !isDiagonal && isRTL ? index !== avatars.length - 1 : index !== 0
|
|
36
43
|
}, {
|
|
37
|
-
[`np-avatar-layout-${orientation}-mask`]: index !== avatars.length - 1
|
|
44
|
+
[`np-avatar-layout-${orientation}-mask`]: !isDiagonal && isRTL ? index !== 0 : index !== avatars.length - 1
|
|
38
45
|
}),
|
|
39
46
|
children: /*#__PURE__*/jsx(AvatarView, {
|
|
40
47
|
...avatar,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AvatarLayout.mjs","sources":["../../src/avatarLayout/AvatarLayout.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport AvatarView, { AvatarViewProps } from '../avatarView';\n\
|
|
1
|
+
{"version":3,"file":"AvatarLayout.mjs","sources":["../../src/avatarLayout/AvatarLayout.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport AvatarView, { AvatarViewProps } from '../avatarView';\nimport { useDirection } from '../common/hooks';\n\nexport type SingleAvatarType = { asset?: AvatarViewProps['children'] } & Omit<\n AvatarViewProps,\n 'notification' | 'selected' | 'size' | 'badge' | 'children' | 'interactive'\n>;\n\nexport type Props = {\n avatars: SingleAvatarType[];\n orientation?: 'horizontal' | 'diagonal';\n} & Pick<\n AvatarViewProps,\n 'size' | 'interactive' | 'className' | 'role' | 'aria-label' | 'aria-labelledby' | 'aria-hidden'\n>;\n\nexport default function AvatarLayout({\n avatars = [],\n orientation: orientationProp = 'horizontal',\n size = 48,\n className,\n interactive,\n ...restProps\n}: Props) {\n const orientation =\n size === 16 && orientationProp === 'diagonal' ? 'horizontal' : orientationProp;\n const { isRTL } = useDirection();\n const isDiagonal = orientation === 'diagonal';\n const avatarSize = isDiagonal ? DIAGONAL_LAYOUT_STYLE_CONFIG[size]?.avatarSize : size;\n return avatars.length < 1 ? null : avatars.length === 1 ? (\n <AvatarView {...avatars[0]} size={size}>\n {avatars[0].asset}\n </AvatarView>\n ) : (\n <div\n className={clsx('np-avatar-layout', `np-avatar-layout-${orientation}`, className)}\n style={{\n // @ts-expect-error CSS custom props allowed\n '--np-avatar-layout-size': `${size}px`,\n '--np-avatar-size': `${avatarSize}px`,\n '--np-avatar-offset': `${isDiagonal ? DIAGONAL_LAYOUT_STYLE_CONFIG[size].offset : HORIZONTAL_LAYOUT_OFFSET[size]}px`,\n }}\n {...restProps}\n >\n {avatars.map(({ asset, style, ...avatar }, index) => (\n <div\n // eslint-disable-next-line react/no-array-index-key\n key={index}\n className={clsx(\n {\n [`np-avatar-layout-${orientation}-child`]:\n !isDiagonal && isRTL ? index !== avatars.length - 1 : index !== 0,\n },\n {\n [`np-avatar-layout-${orientation}-mask`]:\n !isDiagonal && isRTL ? index !== 0 : index !== avatars.length - 1,\n },\n )}\n >\n <AvatarView\n {...avatar}\n size={avatarSize as Props['size']}\n style={{\n ...(isDiagonal && {\n '--circle-size': `${avatarSize}px`,\n '--circle-icon-size': `${DIAGONAL_LAYOUT_STYLE_CONFIG[size].iconSize}px`,\n '--circle-font-size': `${DIAGONAL_LAYOUT_STYLE_CONFIG[size].fontSize}px`,\n }),\n ...style,\n }}\n interactive={interactive}\n >\n {asset}\n </AvatarView>\n </div>\n ))}\n </div>\n );\n}\n\n/** Diagonal layout have custom sizes for avatar, font and icon */\nconst DIAGONAL_LAYOUT_STYLE_CONFIG = {\n // Diagonal layout doesn't support 16 size\n 16: { avatarSize: undefined, offset: undefined, fontSize: undefined, iconSize: undefined },\n 24: { avatarSize: 15, offset: 2.5, fontSize: 8, iconSize: 11.25 },\n 32: { avatarSize: 20, offset: 2.5, fontSize: 12, iconSize: 15 },\n 40: { avatarSize: 24, offset: 4.5, fontSize: 12, iconSize: 18 },\n 48: { avatarSize: 30, offset: 3.5, fontSize: 14, iconSize: 16.87 },\n 56: { avatarSize: 34, offset: 5, fontSize: 14, iconSize: 19.12 },\n 72: { avatarSize: 44, offset: 6, fontSize: 22, iconSize: 22 },\n};\n\n/** Horizontal layout have custom offset between avatars */\nconst HORIZONTAL_LAYOUT_OFFSET = {\n 16: 2,\n 24: 2,\n 32: 4,\n 40: 4,\n 48: 4,\n 56: 5,\n 72: 5,\n};\n"],"names":["AvatarLayout","avatars","orientation","orientationProp","size","className","interactive","restProps","isRTL","useDirection","isDiagonal","avatarSize","DIAGONAL_LAYOUT_STYLE_CONFIG","length","_jsx","AvatarView","children","asset","clsx","style","offset","HORIZONTAL_LAYOUT_OFFSET","map","avatar","index","iconSize","fontSize","undefined"],"mappings":";;;;;;;;AAiBc,SAAUA,YAAYA,CAAC;AACnCC,EAAAA,OAAO,GAA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ACL,EAAA,EAAE,EAAE,CAAC;AACL,EAAA,EAAE,EAAE,CAAA;CACL;;;;"}
|
|
@@ -67,8 +67,7 @@ function AvatarView({
|
|
|
67
67
|
enableBorder: !interactive || selected,
|
|
68
68
|
style: {
|
|
69
69
|
...(selected && {
|
|
70
|
-
'--circle-border-color': 'var(--color-interactive-primary)'
|
|
71
|
-
'--circle-border-width': `${MAP_SELECTED_BORDER_WIDTH[size]}px`
|
|
70
|
+
'--circle-border-color': 'var(--color-interactive-primary)'
|
|
72
71
|
}),
|
|
73
72
|
...style
|
|
74
73
|
},
|
|
@@ -92,16 +91,6 @@ const MAP_BADGE_ASSET_SIZE = {
|
|
|
92
91
|
56: 24,
|
|
93
92
|
72: 24
|
|
94
93
|
};
|
|
95
|
-
/** Border width for `selected` state determined by avatar size */
|
|
96
|
-
const MAP_SELECTED_BORDER_WIDTH = {
|
|
97
|
-
16: 1,
|
|
98
|
-
24: 1,
|
|
99
|
-
32: 1,
|
|
100
|
-
40: 2,
|
|
101
|
-
48: 2,
|
|
102
|
-
56: 2,
|
|
103
|
-
72: 2
|
|
104
|
-
};
|
|
105
94
|
/** Certain sizes of AvatarView has a custom offset for badge */
|
|
106
95
|
const MAP_BADGE_POSITION = {
|
|
107
96
|
24: -6,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AvatarView.js","sources":["../../src/avatarView/AvatarView.tsx"],"sourcesContent":["import Badge, { BadgeAssets, BadgeProps, BadgeAssetsProps } from '../badge';\nimport NotificationDot from './NotificationDot';\nimport Circle from '../common/circle';\nimport Image from '../image';\nimport { HTMLAttributes, PropsWithChildren, useState } from 'react';\nimport { clsx } from 'clsx';\nimport { getInitials, ProfileType, ProfileTypeBusiness, ProfileTypePersonal } from '../common';\nimport {\n Briefcase as BusinessProfileIcon,\n Profile as PersonalProfileIcon,\n} from '@transferwise/icons';\n\nexport type AvatarViewBadgeProps = Omit<BadgeAssetsProps, 'size'> &\n Pick<BadgeProps, 'aria-label'> & {\n /**\n * Custom badge content\n */\n asset?: React.ReactNode;\n };\n\nexport type Props = {\n imgSrc?: string | null;\n /**\n * Entity name (person (profile or recipient) or business name), it will be boilded down to 1 or 2 chars (initials)\n */\n profileName?: string | null;\n profileType?: ProfileTypeBusiness | ProfileTypePersonal;\n size?: 16 | 24 | 32 | 40 | 48 | 56 | 72;\n notification?: boolean;\n badge?: AvatarViewBadgeProps;\n interactive?: boolean;\n selected?: boolean;\n style?: Pick<React.CSSProperties, 'border' | 'backgroundColor' | 'color'>;\n} & Pick<\n HTMLAttributes<HTMLDivElement>,\n 'className' | 'children' | 'role' | 'aria-label' | 'aria-labelledby' | 'aria-hidden'\n>;\n\nfunction AvatarView({\n children = undefined,\n size = 48,\n selected,\n notification,\n badge,\n interactive = false,\n className,\n style,\n imgSrc,\n profileType,\n profileName,\n ...restProps\n}: Props) {\n return (\n <Circle\n size={size}\n fixedSize\n className={clsx(\n 'np-avatar-view',\n interactive ? 'np-avatar-view-interactive' : 'np-avatar-view-non-interactive',\n { 'np-avatar-view-selected': selected },\n className,\n )}\n {...restProps}\n >\n <Badges avatar={{ size, notification, selected }} {...badge}>\n <Circle\n size={size}\n fixedSize\n className={clsx('np-avatar-view-content')}\n enableBorder={!interactive || selected}\n style={{\n ...(selected && {
|
|
1
|
+
{"version":3,"file":"AvatarView.js","sources":["../../src/avatarView/AvatarView.tsx"],"sourcesContent":["import Badge, { BadgeAssets, BadgeProps, BadgeAssetsProps } from '../badge';\nimport NotificationDot from './NotificationDot';\nimport Circle from '../common/circle';\nimport Image from '../image';\nimport { HTMLAttributes, PropsWithChildren, useState } from 'react';\nimport { clsx } from 'clsx';\nimport { getInitials, ProfileType, ProfileTypeBusiness, ProfileTypePersonal } from '../common';\nimport {\n Briefcase as BusinessProfileIcon,\n Profile as PersonalProfileIcon,\n} from '@transferwise/icons';\n\nexport type AvatarViewBadgeProps = Omit<BadgeAssetsProps, 'size'> &\n Pick<BadgeProps, 'aria-label'> & {\n /**\n * Custom badge content\n */\n asset?: React.ReactNode;\n };\n\nexport type Props = {\n imgSrc?: string | null;\n /**\n * Entity name (person (profile or recipient) or business name), it will be boilded down to 1 or 2 chars (initials)\n */\n profileName?: string | null;\n profileType?: ProfileTypeBusiness | ProfileTypePersonal;\n size?: 16 | 24 | 32 | 40 | 48 | 56 | 72;\n notification?: boolean;\n badge?: AvatarViewBadgeProps;\n interactive?: boolean;\n selected?: boolean;\n style?: Pick<React.CSSProperties, 'border' | 'backgroundColor' | 'color'>;\n} & Pick<\n HTMLAttributes<HTMLDivElement>,\n 'className' | 'children' | 'role' | 'aria-label' | 'aria-labelledby' | 'aria-hidden'\n>;\n\nfunction AvatarView({\n children = undefined,\n size = 48,\n selected,\n notification,\n badge,\n interactive = false,\n className,\n style,\n imgSrc,\n profileType,\n profileName,\n ...restProps\n}: Props) {\n return (\n <Circle\n size={size}\n fixedSize\n className={clsx(\n 'np-avatar-view',\n interactive ? 'np-avatar-view-interactive' : 'np-avatar-view-non-interactive',\n { 'np-avatar-view-selected': selected },\n className,\n )}\n {...restProps}\n >\n <Badges avatar={{ size, notification, selected }} {...badge}>\n <Circle\n size={size}\n fixedSize\n className={clsx('np-avatar-view-content')}\n enableBorder={!interactive || selected}\n style={{\n ...(selected && { '--circle-border-color': 'var(--color-interactive-primary)' }),\n ...style,\n }}\n >\n <AvatarViewContent {...{ imgSrc, profileType, profileName }}>\n {children}\n </AvatarViewContent>\n </Circle>\n </Badges>\n </Circle>\n );\n}\n\n/** Size of badge depends on size of avatar */\nconst MAP_BADGE_ASSET_SIZE = {\n 16: 16,\n 24: 16,\n 32: 16,\n 40: 16,\n 48: 16,\n 56: 24,\n 72: 24,\n} satisfies Record<number, BadgeAssetsProps['size']>;\n\n/** Certain sizes of AvatarView has a custom offset for badge */\nconst MAP_BADGE_POSITION = {\n 24: -6,\n 32: -4,\n};\n\ntype BadgesProps = AvatarViewBadgeProps &\n PropsWithChildren<{\n avatar: Pick<Props, 'selected' | 'size' | 'notification'>;\n }>;\n\n/**\n * Adds build-in badges to AvatarView\n */\nfunction Badges({\n children,\n avatar,\n 'aria-label': ariaLabel,\n asset: customBadge,\n ...badgeAssets\n}: BadgesProps) {\n const { size = 48, selected, notification } = avatar;\n const anyBadge = Object.values({ customBadge, ...badgeAssets }).filter(Boolean).length > 0;\n if ((anyBadge || selected) && size > 16) {\n const badgeSize: BadgeAssetsProps['size'] = MAP_BADGE_ASSET_SIZE[size];\n return (\n <Badge\n aria-label={ariaLabel}\n size={badgeSize}\n badge={\n customBadge ? (\n <Circle fixedSize size={badgeSize}>\n {customBadge}\n </Circle>\n ) : (\n <BadgeAssets {...(selected ? { status: 'positive' } : badgeAssets)} size={badgeSize} />\n )\n }\n style={{\n // @ts-expect-error CSS custom props allowed\n '--badge-content-position': `${MAP_BADGE_POSITION[size] ?? 0}px`,\n }}\n >\n {children}\n </Badge>\n );\n }\n if (notification) {\n return <NotificationDot avatarSize={size}>{children}</NotificationDot>;\n }\n return children;\n}\n\nfunction AvatarViewContent({\n children,\n imgSrc,\n profileName: name,\n profileType: type,\n}: PropsWithChildren<Pick<Props, 'imgSrc' | 'profileName' | 'profileType'>>) {\n const [tryLoadImage, setTryLoadImage] = useState(true);\n if (children === undefined) {\n if (imgSrc && tryLoadImage) {\n return <Image src={imgSrc} alt=\"\" onError={() => setTryLoadImage(false)} />;\n }\n if (type) {\n return type === ProfileType.BUSINESS ? <BusinessProfileIcon /> : <PersonalProfileIcon />;\n }\n if (name) {\n return getInitials(name);\n }\n return <PersonalProfileIcon />;\n }\n return children;\n}\n\nexport default AvatarView;\n"],"names":["AvatarView","children","undefined","size","selected","notification","badge","interactive","className","style","imgSrc","profileType","profileName","restProps","_jsx","Circle","fixedSize","clsx","Badges","avatar","enableBorder","AvatarViewContent","MAP_BADGE_ASSET_SIZE","MAP_BADGE_POSITION","ariaLabel","asset","customBadge","badgeAssets","anyBadge","Object","values","filter","Boolean","length","badgeSize","Badge","BadgeAssets","status","NotificationDot","avatarSize","name","type","tryLoadImage","setTryLoadImage","useState","Image","src","alt","onError","ProfileType","BUSINESS","BusinessProfileIcon","PersonalProfileIcon","getInitials"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAASA,UAAUA,CAAC;AAClBC,EAAAA,QAAQ,GAAGC,SAAS;AACpBC,EAAAA,IAAI,GAAG,EAAE;EACTC,QAAQ;EACRC,YAAY;EACZC,KAAK;AACLC,EAAAA,WAAW,GAAG,KAAK;EACnBC,SAAS;EACTC,KAAK;EACLC,MAAM;EACNC,WAAW;EACXC,WAAW;EACX,GAAGC,SAAAA;AACG,CAAA,EAAA;EACN,oBACEC,cAAA,CAACC,MAAM,EAAA;AACLZ,IAAAA,IAAI,EAAEA,IAAK;IACXa,SAAS,EAAA,IAAA;IACTR,SAAS,EAAES,SAAI,CACb,gBAAgB,EAChBV,WAAW,GAAG,4BAA4B,GAAG,gCAAgC,EAC7E;AAAE,MAAA,yBAAyB,EAAEH,QAAAA;KAAU,EACvCI,SAAS,CACT;AAAA,IAAA,GACEK,SAAS;IAAAZ,QAAA,eAEba,cAAA,CAACI,MAAM,EAAA;AAACC,MAAAA,MAAM,EAAE;QAAEhB,IAAI;QAAEE,YAAY;AAAED,QAAAA,QAAAA;OAAW;AAAA,MAAA,GAAKE,KAAK;MAAAL,QAAA,eACzDa,cAAA,CAACC,MAAM,EAAA;AACLZ,QAAAA,IAAI,EAAEA,IAAK;QACXa,SAAS,EAAA,IAAA;AACTR,QAAAA,SAAS,EAAES,SAAI,CAAC,wBAAwB,CAAE;AAC1CG,QAAAA,YAAY,EAAE,CAACb,WAAW,IAAIH,QAAS;AACvCK,QAAAA,KAAK,EAAE;AACL,UAAA,IAAIL,QAAQ,IAAI;AAAE,YAAA,uBAAuB,EAAE,kCAAA;WAAoC,CAAC;UAChF,GAAGK,KAAAA;SACH;QAAAR,QAAA,eAEFa,cAAA,CAACO,iBAAiB,EAAA;UAAOX,MAAM;UAAEC,WAAW;UAAEC,WAAW;AAAAX,UAAAA,QA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IAAIF,IAAI,EAAE;AACR,MAAA,OAAOA,IAAI,KAAKQ,uBAAW,CAACC,QAAQ,gBAAGpC,cAAA,CAACqC,eAAmB,EAAA,EAAA,CAAG,gBAAGrC,cAAA,CAACsC,aAAmB,IAAA,CAAG,CAAA;AAC1F,KAAA;AACA,IAAA,IAAIZ,IAAI,EAAE;MACR,OAAOa,oBAAW,CAACb,IAAI,CAAC,CAAA;AAC1B,KAAA;AACA,IAAA,oBAAO1B,cAAA,CAACsC,aAAmB,EAAA,GAAG,CAAA;AAChC,GAAA;AACA,EAAA,OAAOnD,QAAQ,CAAA;AACjB;;;;"}
|
|
@@ -65,8 +65,7 @@ function AvatarView({
|
|
|
65
65
|
enableBorder: !interactive || selected,
|
|
66
66
|
style: {
|
|
67
67
|
...(selected && {
|
|
68
|
-
'--circle-border-color': 'var(--color-interactive-primary)'
|
|
69
|
-
'--circle-border-width': `${MAP_SELECTED_BORDER_WIDTH[size]}px`
|
|
68
|
+
'--circle-border-color': 'var(--color-interactive-primary)'
|
|
70
69
|
}),
|
|
71
70
|
...style
|
|
72
71
|
},
|
|
@@ -90,16 +89,6 @@ const MAP_BADGE_ASSET_SIZE = {
|
|
|
90
89
|
56: 24,
|
|
91
90
|
72: 24
|
|
92
91
|
};
|
|
93
|
-
/** Border width for `selected` state determined by avatar size */
|
|
94
|
-
const MAP_SELECTED_BORDER_WIDTH = {
|
|
95
|
-
16: 1,
|
|
96
|
-
24: 1,
|
|
97
|
-
32: 1,
|
|
98
|
-
40: 2,
|
|
99
|
-
48: 2,
|
|
100
|
-
56: 2,
|
|
101
|
-
72: 2
|
|
102
|
-
};
|
|
103
92
|
/** Certain sizes of AvatarView has a custom offset for badge */
|
|
104
93
|
const MAP_BADGE_POSITION = {
|
|
105
94
|
24: -6,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AvatarView.mjs","sources":["../../src/avatarView/AvatarView.tsx"],"sourcesContent":["import Badge, { BadgeAssets, BadgeProps, BadgeAssetsProps } from '../badge';\nimport NotificationDot from './NotificationDot';\nimport Circle from '../common/circle';\nimport Image from '../image';\nimport { HTMLAttributes, PropsWithChildren, useState } from 'react';\nimport { clsx } from 'clsx';\nimport { getInitials, ProfileType, ProfileTypeBusiness, ProfileTypePersonal } from '../common';\nimport {\n Briefcase as BusinessProfileIcon,\n Profile as PersonalProfileIcon,\n} from '@transferwise/icons';\n\nexport type AvatarViewBadgeProps = Omit<BadgeAssetsProps, 'size'> &\n Pick<BadgeProps, 'aria-label'> & {\n /**\n * Custom badge content\n */\n asset?: React.ReactNode;\n };\n\nexport type Props = {\n imgSrc?: string | null;\n /**\n * Entity name (person (profile or recipient) or business name), it will be boilded down to 1 or 2 chars (initials)\n */\n profileName?: string | null;\n profileType?: ProfileTypeBusiness | ProfileTypePersonal;\n size?: 16 | 24 | 32 | 40 | 48 | 56 | 72;\n notification?: boolean;\n badge?: AvatarViewBadgeProps;\n interactive?: boolean;\n selected?: boolean;\n style?: Pick<React.CSSProperties, 'border' | 'backgroundColor' | 'color'>;\n} & Pick<\n HTMLAttributes<HTMLDivElement>,\n 'className' | 'children' | 'role' | 'aria-label' | 'aria-labelledby' | 'aria-hidden'\n>;\n\nfunction AvatarView({\n children = undefined,\n size = 48,\n selected,\n notification,\n badge,\n interactive = false,\n className,\n style,\n imgSrc,\n profileType,\n profileName,\n ...restProps\n}: Props) {\n return (\n <Circle\n size={size}\n fixedSize\n className={clsx(\n 'np-avatar-view',\n interactive ? 'np-avatar-view-interactive' : 'np-avatar-view-non-interactive',\n { 'np-avatar-view-selected': selected },\n className,\n )}\n {...restProps}\n >\n <Badges avatar={{ size, notification, selected }} {...badge}>\n <Circle\n size={size}\n fixedSize\n className={clsx('np-avatar-view-content')}\n enableBorder={!interactive || selected}\n style={{\n ...(selected && {
|
|
1
|
+
{"version":3,"file":"AvatarView.mjs","sources":["../../src/avatarView/AvatarView.tsx"],"sourcesContent":["import Badge, { BadgeAssets, BadgeProps, BadgeAssetsProps } from '../badge';\nimport NotificationDot from './NotificationDot';\nimport Circle from '../common/circle';\nimport Image from '../image';\nimport { HTMLAttributes, PropsWithChildren, useState } from 'react';\nimport { clsx } from 'clsx';\nimport { getInitials, ProfileType, ProfileTypeBusiness, ProfileTypePersonal } from '../common';\nimport {\n Briefcase as BusinessProfileIcon,\n Profile as PersonalProfileIcon,\n} from '@transferwise/icons';\n\nexport type AvatarViewBadgeProps = Omit<BadgeAssetsProps, 'size'> &\n Pick<BadgeProps, 'aria-label'> & {\n /**\n * Custom badge content\n */\n asset?: React.ReactNode;\n };\n\nexport type Props = {\n imgSrc?: string | null;\n /**\n * Entity name (person (profile or recipient) or business name), it will be boilded down to 1 or 2 chars (initials)\n */\n profileName?: string | null;\n profileType?: ProfileTypeBusiness | ProfileTypePersonal;\n size?: 16 | 24 | 32 | 40 | 48 | 56 | 72;\n notification?: boolean;\n badge?: AvatarViewBadgeProps;\n interactive?: boolean;\n selected?: boolean;\n style?: Pick<React.CSSProperties, 'border' | 'backgroundColor' | 'color'>;\n} & Pick<\n HTMLAttributes<HTMLDivElement>,\n 'className' | 'children' | 'role' | 'aria-label' | 'aria-labelledby' | 'aria-hidden'\n>;\n\nfunction AvatarView({\n children = undefined,\n size = 48,\n selected,\n notification,\n badge,\n interactive = false,\n className,\n style,\n imgSrc,\n profileType,\n profileName,\n ...restProps\n}: Props) {\n return (\n <Circle\n size={size}\n fixedSize\n className={clsx(\n 'np-avatar-view',\n interactive ? 'np-avatar-view-interactive' : 'np-avatar-view-non-interactive',\n { 'np-avatar-view-selected': selected },\n className,\n )}\n {...restProps}\n >\n <Badges avatar={{ size, notification, selected }} {...badge}>\n <Circle\n size={size}\n fixedSize\n className={clsx('np-avatar-view-content')}\n enableBorder={!interactive || selected}\n style={{\n ...(selected && { '--circle-border-color': 'var(--color-interactive-primary)' }),\n ...style,\n }}\n >\n <AvatarViewContent {...{ imgSrc, profileType, profileName }}>\n {children}\n </AvatarViewContent>\n </Circle>\n </Badges>\n </Circle>\n );\n}\n\n/** Size of badge depends on size of avatar */\nconst MAP_BADGE_ASSET_SIZE = {\n 16: 16,\n 24: 16,\n 32: 16,\n 40: 16,\n 48: 16,\n 56: 24,\n 72: 24,\n} satisfies Record<number, BadgeAssetsProps['size']>;\n\n/** Certain sizes of AvatarView has a custom offset for badge */\nconst MAP_BADGE_POSITION = {\n 24: -6,\n 32: -4,\n};\n\ntype BadgesProps = AvatarViewBadgeProps &\n PropsWithChildren<{\n avatar: Pick<Props, 'selected' | 'size' | 'notification'>;\n }>;\n\n/**\n * Adds build-in badges to AvatarView\n */\nfunction Badges({\n children,\n avatar,\n 'aria-label': ariaLabel,\n asset: customBadge,\n ...badgeAssets\n}: BadgesProps) {\n const { size = 48, selected, notification } = avatar;\n const anyBadge = Object.values({ customBadge, ...badgeAssets }).filter(Boolean).length > 0;\n if ((anyBadge || selected) && size > 16) {\n const badgeSize: BadgeAssetsProps['size'] = MAP_BADGE_ASSET_SIZE[size];\n return (\n <Badge\n aria-label={ariaLabel}\n size={badgeSize}\n badge={\n customBadge ? (\n <Circle fixedSize size={badgeSize}>\n {customBadge}\n </Circle>\n ) : (\n <BadgeAssets {...(selected ? { status: 'positive' } : badgeAssets)} size={badgeSize} />\n )\n }\n style={{\n // @ts-expect-error CSS custom props allowed\n '--badge-content-position': `${MAP_BADGE_POSITION[size] ?? 0}px`,\n }}\n >\n {children}\n </Badge>\n );\n }\n if (notification) {\n return <NotificationDot avatarSize={size}>{children}</NotificationDot>;\n }\n return children;\n}\n\nfunction AvatarViewContent({\n children,\n imgSrc,\n profileName: name,\n profileType: type,\n}: PropsWithChildren<Pick<Props, 'imgSrc' | 'profileName' | 'profileType'>>) {\n const [tryLoadImage, setTryLoadImage] = useState(true);\n if (children === undefined) {\n if (imgSrc && tryLoadImage) {\n return <Image src={imgSrc} alt=\"\" onError={() => setTryLoadImage(false)} />;\n }\n if (type) {\n return type === ProfileType.BUSINESS ? <BusinessProfileIcon /> : <PersonalProfileIcon />;\n }\n if (name) {\n return getInitials(name);\n }\n return <PersonalProfileIcon />;\n }\n return children;\n}\n\nexport default AvatarView;\n"],"names":["AvatarView","children","undefined","size","selected","notification","badge","interactive","className","style","imgSrc","profileType","profileName","restProps","_jsx","Circle","fixedSize","clsx","Badges","avatar","enableBorder","AvatarViewContent","MAP_BADGE_ASSET_SIZE","MAP_BADGE_POSITION","ariaLabel","asset","customBadge","badgeAssets","anyBadge","Object","values","filter","Boolean","length","badgeSize","Badge","BadgeAssets","status","NotificationDot","avatarSize","name","type","tryLoadImage","setTryLoadImage","useState","Image","src","alt","onError","ProfileType","BUSINESS","BusinessProfileIcon","PersonalProfileIcon","getInitials"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAASA,UAAUA,CAAC;AAClBC,EAAAA,QAAQ,GAAGC,SAAS;AACpBC,EAAAA,IAAI,GAAG,EAAE;EACTC,QAAQ;EACRC,YAAY;EACZC,KAAK;AACLC,EAAAA,WAAW,GAAG,KAAK;EACnBC,SAAS;EACTC,KAAK;EACLC,MAAM;EACNC,WAAW;EACXC,WAAW;EACX,GAAGC,SAAAA;AACG,CAAA,EAAA;EACN,oBACEC,GAAA,CAACC,MAAM,EAAA;AACLZ,IAAAA,IAAI,EAAEA,IAAK;IACXa,SAAS,EAAA,IAAA;IACTR,SAAS,EAAES,IAAI,CACb,gBAAgB,EAChBV,WAAW,GAAG,4BAA4B,GAAG,gCAAgC,EAC7E;AAAE,MAAA,yBAAyB,EAAEH,QAAAA;KAAU,EACvCI,SAAS,CACT;AAAA,IAAA,GACEK,SAAS;IAAAZ,QAAA,eAEba,GAAA,CAACI,MAAM,EAAA;AAACC,MAAAA,MAAM,EAAE;QAAEhB,IAAI;QAAEE,YAAY;AAAED,QAAAA,QAAAA;OAAW;AAAA,MAAA,GAAKE,KAAK;MAAAL,QAAA,eACzDa,GAAA,CAACC,MAAM,EAAA;AACLZ,QAAAA,IAAI,EAAEA,IAAK;QACXa,SAAS,EAAA,IAAA;AACTR,QAAAA,SAAS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AAC,IAAI,CAAC,CAAA;EACtD,IAAI3C,QAAQ,KAAKC,SAAS,EAAE;IAC1B,IAAIQ,MAAM,IAAIgC,YAAY,EAAE;MAC1B,oBAAO5B,GAAA,CAAC+B,KAAK,EAAA;AAACC,QAAAA,GAAG,EAAEpC,MAAO;AAACqC,QAAAA,GAAG,EAAC,EAAE;AAACC,QAAAA,OAAO,EAAEA,MAAML,eAAe,CAAC,KAAK,CAAA;AAAE,OAAA,CAAG,CAAA;AAC7E,KAAA;AACA,IAAA,IAAIF,IAAI,EAAE;AACR,MAAA,OAAOA,IAAI,KAAKQ,WAAW,CAACC,QAAQ,gBAAGpC,GAAA,CAACqC,SAAmB,EAAA,EAAA,CAAG,gBAAGrC,GAAA,CAACsC,OAAmB,IAAA,CAAG,CAAA;AAC1F,KAAA;AACA,IAAA,IAAIZ,IAAI,EAAE;MACR,OAAOa,WAAW,CAACb,IAAI,CAAC,CAAA;AAC1B,KAAA;AACA,IAAA,oBAAO1B,GAAA,CAACsC,OAAmB,EAAA,GAAG,CAAA;AAChC,GAAA;AACA,EAAA,OAAOnD,QAAQ,CAAA;AACjB;;;;"}
|
package/build/button/Button.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var clsx = require('clsx');
|
|
4
3
|
var React = require('react');
|
|
5
|
-
var
|
|
4
|
+
var PrimitiveButton = require('../primitives/PrimitiveButton/src/PrimitiveButton.js');
|
|
5
|
+
var PrimitiveAnchor = require('../primitives/PrimitiveAnchor/src/PrimitiveAnchor.js');
|
|
6
|
+
var AvatarLayout = require('../avatarLayout/AvatarLayout.js');
|
|
7
|
+
var ProcessIndicator = require('../processIndicator/ProcessIndicator.js');
|
|
8
|
+
var clsx = require('clsx');
|
|
6
9
|
require('../common/theme.js');
|
|
7
10
|
require('../common/direction.js');
|
|
8
|
-
|
|
11
|
+
require('../common/propsValues/control.js');
|
|
9
12
|
require('../common/propsValues/breakpoint.js');
|
|
10
|
-
|
|
11
|
-
require('../common/propsValues/typography.js');
|
|
13
|
+
require('../common/propsValues/size.js');
|
|
14
|
+
var typography = require('../common/propsValues/typography.js');
|
|
12
15
|
require('../common/propsValues/width.js');
|
|
13
16
|
require('../common/propsValues/type.js');
|
|
14
17
|
require('../common/propsValues/dateMode.js');
|
|
@@ -23,90 +26,86 @@ require('../common/propsValues/scroll.js');
|
|
|
23
26
|
require('../common/propsValues/markdownNodeType.js');
|
|
24
27
|
require('../common/fileType.js');
|
|
25
28
|
require('@transferwise/icons');
|
|
29
|
+
require('react-intl');
|
|
26
30
|
require('../common/closeButton/CloseButton.messages.js');
|
|
27
31
|
var jsxRuntime = require('react/jsx-runtime');
|
|
28
|
-
var
|
|
29
|
-
var Button_messages = require('../i18n/commonMessages/Button.messages.js');
|
|
30
|
-
var classMap = require('./classMap.js');
|
|
31
|
-
var legacyUtils = require('./legacyUtils/legacyUtils.js');
|
|
32
|
+
var Body = require('../body/Body.js');
|
|
32
33
|
|
|
34
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
33
35
|
const Button = /*#__PURE__*/React.forwardRef(({
|
|
34
|
-
as
|
|
35
|
-
block = false,
|
|
36
|
+
as = 'button',
|
|
36
37
|
children,
|
|
37
38
|
className,
|
|
38
|
-
|
|
39
|
+
size = 'lg',
|
|
40
|
+
href,
|
|
41
|
+
disabled = false,
|
|
42
|
+
priority = 'primary',
|
|
43
|
+
sentiment = 'default',
|
|
44
|
+
iconStart: IconStart,
|
|
45
|
+
iconEnd: IconEnd,
|
|
46
|
+
avatars,
|
|
47
|
+
type = 'button',
|
|
39
48
|
loading = false,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
block = false,
|
|
50
|
+
...props
|
|
51
|
+
}, ref) => {
|
|
52
|
+
const classNames = clsx.clsx('wds-Button', {
|
|
53
|
+
[`wds-Button--block`]: block,
|
|
54
|
+
[`wds-Button--disabled`]: disabled,
|
|
55
|
+
[`wds-Button--loading`]: loading
|
|
56
|
+
}, `wds-Button--${{
|
|
57
|
+
sm: 'small',
|
|
58
|
+
md: 'medium',
|
|
59
|
+
lg: 'large'
|
|
60
|
+
}[size]}`, `wds-Button--${priority}`, `wds-Button--${sentiment}`, className);
|
|
61
|
+
const contentClassNames = clsx.clsx('wds-Button-content', {
|
|
62
|
+
[`wds-Button-content--loading`]: loading
|
|
50
63
|
});
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
64
|
+
const content = /*#__PURE__*/jsxRuntime.jsxs(Body, {
|
|
65
|
+
as: "span",
|
|
66
|
+
type: size === 'sm' ? typography.Typography.BODY_DEFAULT_BOLD : typography.Typography.BODY_LARGE_BOLD,
|
|
67
|
+
className: contentClassNames,
|
|
68
|
+
children: [loading && /*#__PURE__*/jsxRuntime.jsx(ProcessIndicator, {
|
|
69
|
+
size: "xs",
|
|
70
|
+
className: "wds-Button-loader",
|
|
71
|
+
"data-testid": "button-loader-indicator"
|
|
72
|
+
}), /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
73
|
+
className: "wds-Button-label",
|
|
74
|
+
"aria-hidden": loading,
|
|
75
|
+
children: size === 'lg' ? children : /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
76
|
+
children: [size === 'md' && avatars && /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
77
|
+
className: "wds-Button-avatars",
|
|
78
|
+
children: /*#__PURE__*/jsxRuntime.jsx(AvatarLayout, {
|
|
79
|
+
orientation: "horizontal",
|
|
80
|
+
avatars: avatars,
|
|
81
|
+
size: 24
|
|
82
|
+
})
|
|
83
|
+
}), !avatars && IconStart && /*#__PURE__*/jsxRuntime.jsx(IconStart, {
|
|
84
|
+
className: "wds-Button-icon wds-Button-icon--start"
|
|
85
|
+
}), children, IconEnd && /*#__PURE__*/jsxRuntime.jsx(IconEnd, {
|
|
86
|
+
className: "wds-Button-icon wds-Button-icon--end"
|
|
87
|
+
})]
|
|
88
|
+
})
|
|
89
|
+
})]
|
|
90
|
+
});
|
|
91
|
+
if (as === 'a') {
|
|
92
|
+
return /*#__PURE__*/jsxRuntime.jsx(PrimitiveAnchor, {
|
|
93
|
+
ref: ref,
|
|
94
|
+
...props,
|
|
95
|
+
href: href,
|
|
96
|
+
className: classNames,
|
|
97
|
+
disabled: disabled,
|
|
98
|
+
children: content
|
|
99
|
+
});
|
|
85
100
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
* when `aria-disabled` might be used over the `disabled` HTML attribute
|
|
89
|
-
*/
|
|
90
|
-
const handleClick = handler => event => {
|
|
91
|
-
if (disabled || loading) {
|
|
92
|
-
event.preventDefault();
|
|
93
|
-
} else if (typeof handler === 'function') {
|
|
94
|
-
handler(event);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
return /*#__PURE__*/jsxRuntime.jsxs(Element, {
|
|
98
|
-
ref: reference,
|
|
99
|
-
className: classes,
|
|
100
|
-
onClick: handleClick(onClick),
|
|
101
|
+
return /*#__PURE__*/jsxRuntime.jsx(PrimitiveButton, {
|
|
102
|
+
ref: ref,
|
|
101
103
|
...props,
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
className: "btn-loader",
|
|
108
|
-
"data-testid": "ButtonProgressIndicator"
|
|
109
|
-
})]
|
|
104
|
+
className: classNames,
|
|
105
|
+
disabled: disabled,
|
|
106
|
+
loading: loading,
|
|
107
|
+
type: type,
|
|
108
|
+
children: content
|
|
110
109
|
});
|
|
111
110
|
});
|
|
112
111
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.js","sources":["../../src/button/Button.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"Button.js","sources":["../../src/button/Button.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { forwardRef } from 'react';\nimport { ButtonProps as NewButtonProps } from './Button.types';\nimport { PrimitiveAnchor, PrimitiveButton } from '../primitives';\nimport AvatarLayout from '../avatarLayout';\nimport ProcessIndicator from '../processIndicator';\nimport { clsx } from 'clsx';\nimport { Typography } from '../common';\nimport Body from '../body';\n\nconst Button = forwardRef<HTMLButtonElement | HTMLAnchorElement, NewButtonProps>(\n (\n {\n as = 'button',\n children,\n className,\n size = 'lg',\n href,\n disabled = false,\n priority = 'primary',\n sentiment = 'default',\n iconStart: IconStart,\n iconEnd: IconEnd,\n avatars,\n type = 'button',\n loading = false,\n block = false,\n ...props\n },\n ref,\n ) => {\n const classNames = clsx(\n 'wds-Button',\n {\n [`wds-Button--block`]: block,\n [`wds-Button--disabled`]: disabled,\n [`wds-Button--loading`]: loading,\n },\n `wds-Button--${{ sm: 'small', md: 'medium', lg: 'large' }[size]}`,\n `wds-Button--${priority}`,\n `wds-Button--${sentiment}`,\n className,\n );\n\n const contentClassNames = clsx('wds-Button-content', {\n [`wds-Button-content--loading`]: loading,\n });\n\n const content = (\n <Body\n as=\"span\"\n type={size === 'sm' ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_LARGE_BOLD}\n className={contentClassNames}\n >\n {loading && (\n <ProcessIndicator\n size=\"xs\"\n className=\"wds-Button-loader\"\n data-testid=\"button-loader-indicator\"\n />\n )}\n <span className=\"wds-Button-label\" aria-hidden={loading}>\n {size === 'lg' ? (\n children\n ) : (\n <>\n {size === 'md' && avatars && (\n <span className=\"wds-Button-avatars\">\n <AvatarLayout orientation=\"horizontal\" avatars={avatars} size={24} />\n </span>\n )}\n {!avatars && IconStart && (\n <IconStart className=\"wds-Button-icon wds-Button-icon--start\" />\n )}\n {children}\n {IconEnd && <IconEnd className=\"wds-Button-icon wds-Button-icon--end\" />}\n </>\n )}\n </span>\n </Body>\n );\n\n if (as === 'a') {\n return (\n <PrimitiveAnchor\n ref={ref as React.Ref<HTMLAnchorElement>}\n {...(props as any)}\n href={href}\n className={classNames}\n disabled={disabled}\n >\n {content}\n </PrimitiveAnchor>\n );\n }\n\n return (\n <PrimitiveButton\n ref={ref as React.Ref<HTMLButtonElement>}\n {...(props as any)}\n className={classNames}\n disabled={disabled}\n loading={loading}\n type={type}\n >\n {content}\n </PrimitiveButton>\n );\n },\n);\n\nexport default Button;\n"],"names":["Button","forwardRef","as","children","className","size","href","disabled","priority","sentiment","iconStart","IconStart","iconEnd","IconEnd","avatars","type","loading","block","props","ref","classNames","clsx","sm","md","lg","contentClassNames","content","_jsxs","Body","Typography","BODY_DEFAULT_BOLD","BODY_LARGE_BOLD","_jsx","ProcessIndicator","_Fragment","AvatarLayout","orientation","PrimitiveAnchor","PrimitiveButton"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAUA,MAAMA,MAAM,gBAAGC,gBAAU,CACvB,CACE;AACEC,EAAAA,EAAE,GAAG,QAAQ;EACbC,QAAQ;EACRC,SAAS;AACTC,EAAAA,IAAI,GAAG,IAAI;EACXC,IAAI;AACJC,EAAAA,QAAQ,GAAG,KAAK;AAChBC,EAAAA,QAAQ,GAAG,SAAS;AACpBC,EAAAA,SAAS,GAAG,SAAS;AACrBC,EAAAA,SAAS,EAAEC,SAAS;AACpBC,EAAAA,OAAO,EAAEC,OAAO;EAChBC,OAAO;AACPC,EAAAA,IAAI,GAAG,QAAQ;AACfC,EAA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