@transferwise/components 0.0.0-experimental-0b6dfe0 → 0.0.0-experimental-6dd9117
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/index.esm.js +54 -109
- package/build/index.esm.js.map +1 -1
- package/build/index.js +54 -109
- package/build/index.js.map +1 -1
- package/build/main.css +1 -1
- package/build/styles/main.css +1 -1
- package/build/styles/promoCard/PromoCard.css +1 -1
- package/build/types/accordion/AccordionItem/AccordionItem.d.ts.map +1 -1
- package/build/types/common/card/Card.d.ts.map +1 -1
- package/build/types/common/card/index.d.ts +0 -1
- package/build/types/common/card/index.d.ts.map +1 -1
- package/build/types/common/index.d.ts +1 -0
- package/build/types/common/randomId.d.ts +13 -0
- package/build/types/common/randomId.d.ts.map +1 -0
- package/build/types/promoCard/PromoCard.d.ts +3 -9
- package/build/types/promoCard/PromoCard.d.ts.map +1 -1
- package/build/types/promoCard/PromoCardIndicator.d.ts +3 -5
- package/build/types/promoCard/PromoCardIndicator.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/accordion/AccordionItem/AccordionItem.spec.js +1 -0
- package/src/accordion/AccordionItem/AccordionItem.tsx +19 -11
- package/src/accordion/AccordionItem/__snapshots__/AccordionItem.spec.js.snap +18 -4
- package/src/common/card/Card.tsx +2 -6
- package/src/common/card/index.ts +0 -1
- package/src/common/index.js +1 -0
- package/src/common/randomId.ts +14 -0
- package/src/main.css +1 -1
- package/src/promoCard/PromoCard.css +1 -1
- package/src/promoCard/PromoCard.less +9 -9
- package/src/promoCard/PromoCard.spec.tsx +0 -1
- package/src/promoCard/PromoCard.story.tsx +30 -90
- package/src/promoCard/PromoCard.tsx +23 -85
- package/src/promoCard/PromoCardIndicator.tsx +8 -20
package/build/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var classNames = require('classnames');
|
|
4
4
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
5
|
var React = require('react');
|
|
6
|
+
var reactId = require('@radix-ui/react-id');
|
|
6
7
|
var icons = require('@transferwise/icons');
|
|
7
8
|
var PropTypes = require('prop-types');
|
|
8
9
|
var reactIntl = require('react-intl');
|
|
@@ -16,7 +17,6 @@ var mergeRefs = require('react-merge-refs');
|
|
|
16
17
|
var neptuneValidation = require('@transferwise/neptune-validation');
|
|
17
18
|
var reactPopper = require('react-popper');
|
|
18
19
|
var react$1 = require('@headlessui/react');
|
|
19
|
-
var reactId = require('@radix-ui/react-id');
|
|
20
20
|
var shim = require('use-sync-external-store/shim');
|
|
21
21
|
var react = require('@floating-ui/react');
|
|
22
22
|
var overlays = require('@react-aria/overlays');
|
|
@@ -490,6 +490,21 @@ function getDirectionFromLocale(locale) {
|
|
|
490
490
|
}
|
|
491
491
|
}
|
|
492
492
|
|
|
493
|
+
/**
|
|
494
|
+
* generateRandomId() function
|
|
495
|
+
*
|
|
496
|
+
* This function generates a random string of characters that can be used as
|
|
497
|
+
* an ID.
|
|
498
|
+
*
|
|
499
|
+
* @returns {string} A random string of characters.
|
|
500
|
+
* @example
|
|
501
|
+
* const id = generateRandomId();
|
|
502
|
+
* // id will be a random string of characters, such as "id-4711".
|
|
503
|
+
*/
|
|
504
|
+
const generateRandomId = () => {
|
|
505
|
+
return `id-${Math.random().toString(36).slice(7)}`;
|
|
506
|
+
};
|
|
507
|
+
|
|
493
508
|
const DEFAULT_TYPE$1 = exports.Typography.TITLE_GROUP;
|
|
494
509
|
const titleTypeMapping = {
|
|
495
510
|
[exports.Typography.TITLE_SCREEN]: 'h1',
|
|
@@ -673,8 +688,10 @@ const AccordionItem = ({
|
|
|
673
688
|
const iconElement = icon ? /*#__PURE__*/React.cloneElement(icon, {
|
|
674
689
|
size: 24
|
|
675
690
|
}) : null;
|
|
691
|
+
const fallbackId = reactId.useId();
|
|
692
|
+
const accordionId = id ?? fallbackId;
|
|
676
693
|
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
677
|
-
id:
|
|
694
|
+
id: accordionId,
|
|
678
695
|
className: classNames__default.default('np-accordion-item', iconElement ? 'np-accordion-item--with-icon' : null, {
|
|
679
696
|
'np-accordion-item--open': open
|
|
680
697
|
}),
|
|
@@ -688,14 +705,22 @@ const AccordionItem = ({
|
|
|
688
705
|
size: exports.Size.MEDIUM
|
|
689
706
|
}),
|
|
690
707
|
inverseMediaCircle: false,
|
|
708
|
+
"aria-expanded": open,
|
|
709
|
+
"aria-controls": `${accordionId}-section`,
|
|
710
|
+
id: `${accordionId}-control`,
|
|
691
711
|
onClick: onClick
|
|
692
|
-
}), open && /*#__PURE__*/jsxRuntime.jsx(
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
712
|
+
}), open && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
713
|
+
id: `${accordionId}-section`,
|
|
714
|
+
role: "region",
|
|
715
|
+
"aria-labelledby": `${accordionId}-control`,
|
|
716
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Body, {
|
|
717
|
+
as: "span",
|
|
718
|
+
type: exports.Typography.BODY_LARGE,
|
|
719
|
+
className: classNames__default.default('np-accordion-item__content', 'd-block', {
|
|
720
|
+
'has-icon': icon
|
|
721
|
+
}),
|
|
722
|
+
children: content
|
|
723
|
+
})
|
|
699
724
|
})]
|
|
700
725
|
});
|
|
701
726
|
};
|
|
@@ -2290,7 +2315,7 @@ var Card$2 = Card$1;
|
|
|
2290
2315
|
|
|
2291
2316
|
const Card = ({
|
|
2292
2317
|
className,
|
|
2293
|
-
children
|
|
2318
|
+
children,
|
|
2294
2319
|
id,
|
|
2295
2320
|
isDisabled = false,
|
|
2296
2321
|
isSmall = false,
|
|
@@ -2313,10 +2338,7 @@ const Card = ({
|
|
|
2313
2338
|
size: isSmall ? 'sm' : 'md',
|
|
2314
2339
|
isDisabled: isDisabled,
|
|
2315
2340
|
testId: "close-button",
|
|
2316
|
-
onClick:
|
|
2317
|
-
stopPropagation$1(e);
|
|
2318
|
-
onDismiss();
|
|
2319
|
-
}
|
|
2341
|
+
onClick: onDismiss
|
|
2320
2342
|
}), children]
|
|
2321
2343
|
});
|
|
2322
2344
|
};
|
|
@@ -10372,12 +10394,10 @@ const PromoCardIndicator = ({
|
|
|
10372
10394
|
children,
|
|
10373
10395
|
label,
|
|
10374
10396
|
icon,
|
|
10375
|
-
isSmall = false,
|
|
10376
10397
|
testid,
|
|
10377
10398
|
...rest
|
|
10378
10399
|
}) => {
|
|
10379
|
-
const
|
|
10380
|
-
const IconComponent = isIconString && {
|
|
10400
|
+
const IconComponent = icon && {
|
|
10381
10401
|
check: icons.Check,
|
|
10382
10402
|
arrow: icons.ArrowRight,
|
|
10383
10403
|
download: icons.Download
|
|
@@ -10391,63 +10411,16 @@ const PromoCardIndicator = ({
|
|
|
10391
10411
|
type: exports.Typography.BODY_LARGE_BOLD,
|
|
10392
10412
|
className: "np-Card-indicatorText",
|
|
10393
10413
|
children: label
|
|
10394
|
-
}),
|
|
10395
|
-
type: exports.AvatarType.ICON,
|
|
10396
|
-
size: isSmall ? 40 : 56,
|
|
10397
|
-
backgroundColor: "var(--Card-indicator-icon-background-color)",
|
|
10414
|
+
}), IconComponent && /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
10398
10415
|
className: "np-Card-indicatorIcon",
|
|
10399
|
-
children:
|
|
10416
|
+
children: /*#__PURE__*/jsxRuntime.jsx(IconComponent, {
|
|
10400
10417
|
size: 24,
|
|
10401
10418
|
"aria-hidden": "true"
|
|
10402
|
-
})
|
|
10419
|
+
})
|
|
10403
10420
|
}), children]
|
|
10404
10421
|
});
|
|
10405
10422
|
};
|
|
10406
10423
|
|
|
10407
|
-
const generateRandomId = () => {
|
|
10408
|
-
return `id-${Math.random().toString(36).slice(7)}`;
|
|
10409
|
-
};
|
|
10410
|
-
/**
|
|
10411
|
-
* PromoCard component.
|
|
10412
|
-
*
|
|
10413
|
-
* PromoCard is a marketing style component that is used to group marketing
|
|
10414
|
-
* product related information (such as choosing Card types). It can be used to
|
|
10415
|
-
* display information in a structured way, and can be customized with various
|
|
10416
|
-
* props to suit different use cases.
|
|
10417
|
-
*
|
|
10418
|
-
* @component
|
|
10419
|
-
* @param {string} className - Additional class name for the PromoCard.
|
|
10420
|
-
* @param {string} description - Description text for the PromoCard.
|
|
10421
|
-
* @param {boolean} defaultChecked - Initial checked state for checkboxes and radios.
|
|
10422
|
-
* @param {string} download - Download file name for links.
|
|
10423
|
-
* @param {string} href - URL for links.
|
|
10424
|
-
* @param {string} hrefLang - Language code for linked URL.
|
|
10425
|
-
* @param {string} id - ID of the PromoCard.
|
|
10426
|
-
* @param {string} imageAlt - Alt text for the image.
|
|
10427
|
-
* @param {string} imageSource - Source URL of the image.
|
|
10428
|
-
* @param {string} indicatorLabel - Label for the indicator icon.
|
|
10429
|
-
* @param {boolean} isChecked - Checked state for checkboxes and radios.
|
|
10430
|
-
* @param {boolean} isDisabled - Whether the PromoCard is disabled.
|
|
10431
|
-
* @param {Function} onClick - Click event handler for the PromoCard.
|
|
10432
|
-
* @param {string} rel - Relationship between the URL and the current page.
|
|
10433
|
-
* @param {number} tabIndex - Tab index for keyboard navigation.
|
|
10434
|
-
* @param {string} target - Target window for links.
|
|
10435
|
-
* @param {string} testId - ID used for testing.
|
|
10436
|
-
* @param {string} title - Title text of the PromoCard.
|
|
10437
|
-
* @param {('checkbox'|'radio')} type - Type of the PromoCard (checkbox, radio).
|
|
10438
|
-
* @param {string} value - Value for checkboxes and radios.
|
|
10439
|
-
* @returns {JSX.Element} The rendered PromoCard component.
|
|
10440
|
-
* @example
|
|
10441
|
-
* <PromoCard
|
|
10442
|
-
* title="Example PromoCard"
|
|
10443
|
-
* description="This is an example PromoCard with a link variation."
|
|
10444
|
-
* href="https://example.com"
|
|
10445
|
-
* target="_blank"
|
|
10446
|
-
* imageSource="https://example.com/image.png"
|
|
10447
|
-
* imageAlt="Example Image"
|
|
10448
|
-
* indicatorLabel="Learn More"
|
|
10449
|
-
* />
|
|
10450
|
-
*/
|
|
10451
10424
|
const PromoCard = /*#__PURE__*/React.forwardRef(({
|
|
10452
10425
|
className,
|
|
10453
10426
|
description,
|
|
@@ -10461,7 +10434,6 @@ const PromoCard = /*#__PURE__*/React.forwardRef(({
|
|
|
10461
10434
|
imageClass,
|
|
10462
10435
|
imageSource,
|
|
10463
10436
|
indicatorLabel,
|
|
10464
|
-
indicatorIcon,
|
|
10465
10437
|
isChecked,
|
|
10466
10438
|
isDisabled,
|
|
10467
10439
|
onClick,
|
|
@@ -10472,8 +10444,6 @@ const PromoCard = /*#__PURE__*/React.forwardRef(({
|
|
|
10472
10444
|
title,
|
|
10473
10445
|
type,
|
|
10474
10446
|
value,
|
|
10475
|
-
isSmall,
|
|
10476
|
-
useDisplayFont = true,
|
|
10477
10447
|
...props
|
|
10478
10448
|
}, reference) => {
|
|
10479
10449
|
// Set the `checked` state to the value of `defaultChecked` if it is truthy,
|
|
@@ -10497,19 +10467,7 @@ const PromoCard = /*#__PURE__*/React.forwardRef(({
|
|
|
10497
10467
|
// Set the icon to `'arrow'` if `href` is truthy and `type` is falsy, or
|
|
10498
10468
|
// `'download'` if `download` is truthy. If neither condition is true, set
|
|
10499
10469
|
// `icon` to `undefined`.
|
|
10500
|
-
|
|
10501
|
-
const getIconType = () => {
|
|
10502
|
-
if (indicatorIcon) {
|
|
10503
|
-
return indicatorIcon;
|
|
10504
|
-
}
|
|
10505
|
-
if (download) {
|
|
10506
|
-
return 'download';
|
|
10507
|
-
}
|
|
10508
|
-
if (href && !type) {
|
|
10509
|
-
return 'arrow';
|
|
10510
|
-
}
|
|
10511
|
-
return undefined;
|
|
10512
|
-
};
|
|
10470
|
+
const icon = href && download ? 'download' : href ? 'arrow' : undefined;
|
|
10513
10471
|
// Define all class names string based on the values of the `href`, `type`,
|
|
10514
10472
|
// `checked`, and `className` props.
|
|
10515
10473
|
const commonClasses = classNames__default.default({
|
|
@@ -10526,8 +10484,7 @@ const PromoCard = /*#__PURE__*/React.forwardRef(({
|
|
|
10526
10484
|
isDisabled: isDisabled || contextIsDisabled,
|
|
10527
10485
|
onClick,
|
|
10528
10486
|
ref: reference,
|
|
10529
|
-
'data-testid': testId
|
|
10530
|
-
isSmall
|
|
10487
|
+
'data-testid': testId
|
|
10531
10488
|
};
|
|
10532
10489
|
// Object with Anchor props that will be passed to the `a` element. These
|
|
10533
10490
|
// won't be refurned if set to `isDisabled`
|
|
@@ -10555,27 +10512,6 @@ const PromoCard = /*#__PURE__*/React.forwardRef(({
|
|
|
10555
10512
|
ref: reference,
|
|
10556
10513
|
tabIndex: 0
|
|
10557
10514
|
} : {};
|
|
10558
|
-
const getTitle = () => {
|
|
10559
|
-
const titleContent = href && !type ? /*#__PURE__*/jsxRuntime.jsx("a", {
|
|
10560
|
-
className: "np-Card-titleLink",
|
|
10561
|
-
...anchorProps,
|
|
10562
|
-
children: title
|
|
10563
|
-
}) : title;
|
|
10564
|
-
const titleProps = {
|
|
10565
|
-
id: `${componentId}-title`,
|
|
10566
|
-
as: headingLevel,
|
|
10567
|
-
className: 'np-Card-title'
|
|
10568
|
-
};
|
|
10569
|
-
return useDisplayFont ? /*#__PURE__*/jsxRuntime.jsx(Display, {
|
|
10570
|
-
type: exports.Typography.DISPLAY_SMALL,
|
|
10571
|
-
...titleProps,
|
|
10572
|
-
children: titleContent
|
|
10573
|
-
}) : /*#__PURE__*/jsxRuntime.jsx(Title, {
|
|
10574
|
-
type: exports.Typography.TITLE_SUBSECTION,
|
|
10575
|
-
...titleProps,
|
|
10576
|
-
children: titleContent
|
|
10577
|
-
});
|
|
10578
|
-
};
|
|
10579
10515
|
React.useEffect(() => {
|
|
10580
10516
|
setChecked(defaultChecked ?? isChecked ?? false);
|
|
10581
10517
|
}, [defaultChecked, isChecked]);
|
|
@@ -10589,7 +10525,17 @@ const PromoCard = /*#__PURE__*/React.forwardRef(({
|
|
|
10589
10525
|
size: 24,
|
|
10590
10526
|
"aria-hidden": "true"
|
|
10591
10527
|
})
|
|
10592
|
-
}),
|
|
10528
|
+
}), /*#__PURE__*/jsxRuntime.jsx(Display, {
|
|
10529
|
+
id: `${componentId}-title`,
|
|
10530
|
+
as: headingLevel,
|
|
10531
|
+
className: "np-Card-title",
|
|
10532
|
+
type: exports.Typography.DISPLAY_SMALL,
|
|
10533
|
+
children: href && !type ? /*#__PURE__*/jsxRuntime.jsx("a", {
|
|
10534
|
+
className: "np-Card-titleLink",
|
|
10535
|
+
...anchorProps,
|
|
10536
|
+
children: title
|
|
10537
|
+
}) : title
|
|
10538
|
+
}), /*#__PURE__*/jsxRuntime.jsx(Body, {
|
|
10593
10539
|
className: "np-Card-description",
|
|
10594
10540
|
children: description
|
|
10595
10541
|
}), imageSource && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
@@ -10603,8 +10549,7 @@ const PromoCard = /*#__PURE__*/React.forwardRef(({
|
|
|
10603
10549
|
})
|
|
10604
10550
|
}), /*#__PURE__*/jsxRuntime.jsx(PromoCardIndicator, {
|
|
10605
10551
|
label: indicatorLabel,
|
|
10606
|
-
icon:
|
|
10607
|
-
isSmall: isSmall
|
|
10552
|
+
icon: icon
|
|
10608
10553
|
})]
|
|
10609
10554
|
});
|
|
10610
10555
|
});
|