@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.
Files changed (33) hide show
  1. package/build/index.esm.js +54 -109
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +54 -109
  4. package/build/index.js.map +1 -1
  5. package/build/main.css +1 -1
  6. package/build/styles/main.css +1 -1
  7. package/build/styles/promoCard/PromoCard.css +1 -1
  8. package/build/types/accordion/AccordionItem/AccordionItem.d.ts.map +1 -1
  9. package/build/types/common/card/Card.d.ts.map +1 -1
  10. package/build/types/common/card/index.d.ts +0 -1
  11. package/build/types/common/card/index.d.ts.map +1 -1
  12. package/build/types/common/index.d.ts +1 -0
  13. package/build/types/common/randomId.d.ts +13 -0
  14. package/build/types/common/randomId.d.ts.map +1 -0
  15. package/build/types/promoCard/PromoCard.d.ts +3 -9
  16. package/build/types/promoCard/PromoCard.d.ts.map +1 -1
  17. package/build/types/promoCard/PromoCardIndicator.d.ts +3 -5
  18. package/build/types/promoCard/PromoCardIndicator.d.ts.map +1 -1
  19. package/package.json +3 -3
  20. package/src/accordion/AccordionItem/AccordionItem.spec.js +1 -0
  21. package/src/accordion/AccordionItem/AccordionItem.tsx +19 -11
  22. package/src/accordion/AccordionItem/__snapshots__/AccordionItem.spec.js.snap +18 -4
  23. package/src/common/card/Card.tsx +2 -6
  24. package/src/common/card/index.ts +0 -1
  25. package/src/common/index.js +1 -0
  26. package/src/common/randomId.ts +14 -0
  27. package/src/main.css +1 -1
  28. package/src/promoCard/PromoCard.css +1 -1
  29. package/src/promoCard/PromoCard.less +9 -9
  30. package/src/promoCard/PromoCard.spec.tsx +0 -1
  31. package/src/promoCard/PromoCard.story.tsx +30 -90
  32. package/src/promoCard/PromoCard.tsx +23 -85
  33. package/src/promoCard/PromoCardIndicator.tsx +8 -20
@@ -2,6 +2,7 @@ import classNames from 'classnames';
2
2
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
3
  import * as React from 'react';
4
4
  import React__default, { forwardRef, cloneElement, useState, useRef, useMemo, useEffect, useCallback, useLayoutEffect, createContext, useContext, PureComponent, createRef, Component, Children, Fragment as Fragment$1 } from 'react';
5
+ import { useId } from '@radix-ui/react-id';
5
6
  import { ChevronUp, CrossCircleFill, Cross, NavigateAway, Check, Info as Info$1, Alert as Alert$2, ClockBorderless, CheckCircle, InfoCircle, Warning, CrossCircle, Clock, Briefcase, Person, ArrowLeft, QuestionMarkCircle, AlertCircle, Search, ChevronDown, CheckCircleFill, ArrowRight, Download, ClockFill, Upload as Upload$2, Document, Plus, PlusCircle, AlertCircleFill } from '@transferwise/icons';
6
7
  import PropTypes from 'prop-types';
7
8
  import { defineMessages, useIntl, injectIntl, IntlProvider } from 'react-intl';
@@ -15,7 +16,6 @@ import mergeRefs from 'react-merge-refs';
15
16
  import { isUndefined, isKey, isNumber, isEmpty, isNull, isArray } from '@transferwise/neptune-validation';
16
17
  import { usePopper } from 'react-popper';
17
18
  import { Transition, Listbox } from '@headlessui/react';
18
- import { useId } from '@radix-ui/react-id';
19
19
  import { useSyncExternalStore } from 'use-sync-external-store/shim';
20
20
  import { useFloating, useDismiss, useRole, useInteractions, FloatingPortal, FloatingFocusManager, offset, flip, shift, size, autoUpdate } from '@floating-ui/react';
21
21
  import { usePreventScroll } from '@react-aria/overlays';
@@ -457,6 +457,21 @@ function getDirectionFromLocale(locale) {
457
457
  }
458
458
  }
459
459
 
460
+ /**
461
+ * generateRandomId() function
462
+ *
463
+ * This function generates a random string of characters that can be used as
464
+ * an ID.
465
+ *
466
+ * @returns {string} A random string of characters.
467
+ * @example
468
+ * const id = generateRandomId();
469
+ * // id will be a random string of characters, such as "id-4711".
470
+ */
471
+ const generateRandomId = () => {
472
+ return `id-${Math.random().toString(36).slice(7)}`;
473
+ };
474
+
460
475
  const DEFAULT_TYPE$1 = Typography.TITLE_GROUP;
461
476
  const titleTypeMapping = {
462
477
  [Typography.TITLE_SCREEN]: 'h1',
@@ -640,8 +655,10 @@ const AccordionItem = ({
640
655
  const iconElement = icon ? /*#__PURE__*/cloneElement(icon, {
641
656
  size: 24
642
657
  }) : null;
658
+ const fallbackId = useId();
659
+ const accordionId = id ?? fallbackId;
643
660
  return /*#__PURE__*/jsxs("div", {
644
- id: id,
661
+ id: accordionId,
645
662
  className: classNames('np-accordion-item', iconElement ? 'np-accordion-item--with-icon' : null, {
646
663
  'np-accordion-item--open': open
647
664
  }),
@@ -655,14 +672,22 @@ const AccordionItem = ({
655
672
  size: Size.MEDIUM
656
673
  }),
657
674
  inverseMediaCircle: false,
675
+ "aria-expanded": open,
676
+ "aria-controls": `${accordionId}-section`,
677
+ id: `${accordionId}-control`,
658
678
  onClick: onClick
659
- }), open && /*#__PURE__*/jsx(Body, {
660
- as: "span",
661
- type: Typography.BODY_LARGE,
662
- className: classNames('np-accordion-item__content', 'd-block', {
663
- 'has-icon': icon
664
- }),
665
- children: content
679
+ }), open && /*#__PURE__*/jsx("div", {
680
+ id: `${accordionId}-section`,
681
+ role: "region",
682
+ "aria-labelledby": `${accordionId}-control`,
683
+ children: /*#__PURE__*/jsx(Body, {
684
+ as: "span",
685
+ type: Typography.BODY_LARGE,
686
+ className: classNames('np-accordion-item__content', 'd-block', {
687
+ 'has-icon': icon
688
+ }),
689
+ children: content
690
+ })
666
691
  })]
667
692
  });
668
693
  };
@@ -2257,7 +2282,7 @@ var Card$2 = Card$1;
2257
2282
 
2258
2283
  const Card = ({
2259
2284
  className,
2260
- children = null,
2285
+ children,
2261
2286
  id,
2262
2287
  isDisabled = false,
2263
2288
  isSmall = false,
@@ -2280,10 +2305,7 @@ const Card = ({
2280
2305
  size: isSmall ? 'sm' : 'md',
2281
2306
  isDisabled: isDisabled,
2282
2307
  testId: "close-button",
2283
- onClick: e => {
2284
- stopPropagation$1(e);
2285
- onDismiss();
2286
- }
2308
+ onClick: onDismiss
2287
2309
  }), children]
2288
2310
  });
2289
2311
  };
@@ -10339,12 +10361,10 @@ const PromoCardIndicator = ({
10339
10361
  children,
10340
10362
  label,
10341
10363
  icon,
10342
- isSmall = false,
10343
10364
  testid,
10344
10365
  ...rest
10345
10366
  }) => {
10346
- const isIconString = icon && typeof icon === 'string';
10347
- const IconComponent = isIconString && {
10367
+ const IconComponent = icon && {
10348
10368
  check: Check,
10349
10369
  arrow: ArrowRight,
10350
10370
  download: Download
@@ -10358,63 +10378,16 @@ const PromoCardIndicator = ({
10358
10378
  type: Typography.BODY_LARGE_BOLD,
10359
10379
  className: "np-Card-indicatorText",
10360
10380
  children: label
10361
- }), icon && /*#__PURE__*/jsx(Avatar, {
10362
- type: AvatarType.ICON,
10363
- size: isSmall ? 40 : 56,
10364
- backgroundColor: "var(--Card-indicator-icon-background-color)",
10381
+ }), IconComponent && /*#__PURE__*/jsx("span", {
10365
10382
  className: "np-Card-indicatorIcon",
10366
- children: IconComponent ? /*#__PURE__*/jsx(IconComponent, {
10383
+ children: /*#__PURE__*/jsx(IconComponent, {
10367
10384
  size: 24,
10368
10385
  "aria-hidden": "true"
10369
- }) : icon
10386
+ })
10370
10387
  }), children]
10371
10388
  });
10372
10389
  };
10373
10390
 
10374
- const generateRandomId = () => {
10375
- return `id-${Math.random().toString(36).slice(7)}`;
10376
- };
10377
- /**
10378
- * PromoCard component.
10379
- *
10380
- * PromoCard is a marketing style component that is used to group marketing
10381
- * product related information (such as choosing Card types). It can be used to
10382
- * display information in a structured way, and can be customized with various
10383
- * props to suit different use cases.
10384
- *
10385
- * @component
10386
- * @param {string} className - Additional class name for the PromoCard.
10387
- * @param {string} description - Description text for the PromoCard.
10388
- * @param {boolean} defaultChecked - Initial checked state for checkboxes and radios.
10389
- * @param {string} download - Download file name for links.
10390
- * @param {string} href - URL for links.
10391
- * @param {string} hrefLang - Language code for linked URL.
10392
- * @param {string} id - ID of the PromoCard.
10393
- * @param {string} imageAlt - Alt text for the image.
10394
- * @param {string} imageSource - Source URL of the image.
10395
- * @param {string} indicatorLabel - Label for the indicator icon.
10396
- * @param {boolean} isChecked - Checked state for checkboxes and radios.
10397
- * @param {boolean} isDisabled - Whether the PromoCard is disabled.
10398
- * @param {Function} onClick - Click event handler for the PromoCard.
10399
- * @param {string} rel - Relationship between the URL and the current page.
10400
- * @param {number} tabIndex - Tab index for keyboard navigation.
10401
- * @param {string} target - Target window for links.
10402
- * @param {string} testId - ID used for testing.
10403
- * @param {string} title - Title text of the PromoCard.
10404
- * @param {('checkbox'|'radio')} type - Type of the PromoCard (checkbox, radio).
10405
- * @param {string} value - Value for checkboxes and radios.
10406
- * @returns {JSX.Element} The rendered PromoCard component.
10407
- * @example
10408
- * <PromoCard
10409
- * title="Example PromoCard"
10410
- * description="This is an example PromoCard with a link variation."
10411
- * href="https://example.com"
10412
- * target="_blank"
10413
- * imageSource="https://example.com/image.png"
10414
- * imageAlt="Example Image"
10415
- * indicatorLabel="Learn More"
10416
- * />
10417
- */
10418
10391
  const PromoCard = /*#__PURE__*/forwardRef(({
10419
10392
  className,
10420
10393
  description,
@@ -10428,7 +10401,6 @@ const PromoCard = /*#__PURE__*/forwardRef(({
10428
10401
  imageClass,
10429
10402
  imageSource,
10430
10403
  indicatorLabel,
10431
- indicatorIcon,
10432
10404
  isChecked,
10433
10405
  isDisabled,
10434
10406
  onClick,
@@ -10439,8 +10411,6 @@ const PromoCard = /*#__PURE__*/forwardRef(({
10439
10411
  title,
10440
10412
  type,
10441
10413
  value,
10442
- isSmall,
10443
- useDisplayFont = true,
10444
10414
  ...props
10445
10415
  }, reference) => {
10446
10416
  // Set the `checked` state to the value of `defaultChecked` if it is truthy,
@@ -10464,19 +10434,7 @@ const PromoCard = /*#__PURE__*/forwardRef(({
10464
10434
  // Set the icon to `'arrow'` if `href` is truthy and `type` is falsy, or
10465
10435
  // `'download'` if `download` is truthy. If neither condition is true, set
10466
10436
  // `icon` to `undefined`.
10467
- // Create a function to get icon type
10468
- const getIconType = () => {
10469
- if (indicatorIcon) {
10470
- return indicatorIcon;
10471
- }
10472
- if (download) {
10473
- return 'download';
10474
- }
10475
- if (href && !type) {
10476
- return 'arrow';
10477
- }
10478
- return undefined;
10479
- };
10437
+ const icon = href && download ? 'download' : href ? 'arrow' : undefined;
10480
10438
  // Define all class names string based on the values of the `href`, `type`,
10481
10439
  // `checked`, and `className` props.
10482
10440
  const commonClasses = classNames({
@@ -10493,8 +10451,7 @@ const PromoCard = /*#__PURE__*/forwardRef(({
10493
10451
  isDisabled: isDisabled || contextIsDisabled,
10494
10452
  onClick,
10495
10453
  ref: reference,
10496
- 'data-testid': testId,
10497
- isSmall
10454
+ 'data-testid': testId
10498
10455
  };
10499
10456
  // Object with Anchor props that will be passed to the `a` element. These
10500
10457
  // won't be refurned if set to `isDisabled`
@@ -10522,27 +10479,6 @@ const PromoCard = /*#__PURE__*/forwardRef(({
10522
10479
  ref: reference,
10523
10480
  tabIndex: 0
10524
10481
  } : {};
10525
- const getTitle = () => {
10526
- const titleContent = href && !type ? /*#__PURE__*/jsx("a", {
10527
- className: "np-Card-titleLink",
10528
- ...anchorProps,
10529
- children: title
10530
- }) : title;
10531
- const titleProps = {
10532
- id: `${componentId}-title`,
10533
- as: headingLevel,
10534
- className: 'np-Card-title'
10535
- };
10536
- return useDisplayFont ? /*#__PURE__*/jsx(Display, {
10537
- type: Typography.DISPLAY_SMALL,
10538
- ...titleProps,
10539
- children: titleContent
10540
- }) : /*#__PURE__*/jsx(Title, {
10541
- type: Typography.TITLE_SUBSECTION,
10542
- ...titleProps,
10543
- children: titleContent
10544
- });
10545
- };
10546
10482
  useEffect(() => {
10547
10483
  setChecked(defaultChecked ?? isChecked ?? false);
10548
10484
  }, [defaultChecked, isChecked]);
@@ -10556,7 +10492,17 @@ const PromoCard = /*#__PURE__*/forwardRef(({
10556
10492
  size: 24,
10557
10493
  "aria-hidden": "true"
10558
10494
  })
10559
- }), getTitle(), /*#__PURE__*/jsx(Body, {
10495
+ }), /*#__PURE__*/jsx(Display, {
10496
+ id: `${componentId}-title`,
10497
+ as: headingLevel,
10498
+ className: "np-Card-title",
10499
+ type: Typography.DISPLAY_SMALL,
10500
+ children: href && !type ? /*#__PURE__*/jsx("a", {
10501
+ className: "np-Card-titleLink",
10502
+ ...anchorProps,
10503
+ children: title
10504
+ }) : title
10505
+ }), /*#__PURE__*/jsx(Body, {
10560
10506
  className: "np-Card-description",
10561
10507
  children: description
10562
10508
  }), imageSource && /*#__PURE__*/jsx("div", {
@@ -10570,8 +10516,7 @@ const PromoCard = /*#__PURE__*/forwardRef(({
10570
10516
  })
10571
10517
  }), /*#__PURE__*/jsx(PromoCardIndicator, {
10572
10518
  label: indicatorLabel,
10573
- icon: getIconType(),
10574
- isSmall: isSmall
10519
+ icon: icon
10575
10520
  })]
10576
10521
  });
10577
10522
  });