@transferwise/components 45.10.1 → 45.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/es/no-polyfill/common/card/Card.js +21 -0
- package/build/es/no-polyfill/common/card/Card.spec.js +6 -0
- package/build/es/no-polyfill/common/card/Card.story.js +1 -0
- package/build/es/no-polyfill/common/card/index.js +1 -0
- package/build/es/no-polyfill/common/closeButton/CloseButton.js +1 -1
- package/build/es/no-polyfill/display/Display.js +1 -1
- package/build/es/no-polyfill/image/Image.js +1 -1
- package/build/es/no-polyfill/index.js +1 -1
- package/build/es/no-polyfill/loader/Loader.js +1 -1
- package/build/es/no-polyfill/promoCard/PromoCard.js +51 -0
- package/build/es/no-polyfill/promoCard/PromoCard.spec.js +13 -0
- package/build/es/no-polyfill/promoCard/PromoCard.story.js +1 -0
- package/build/es/no-polyfill/promoCard/PromoCardContext.js +19 -0
- package/build/es/no-polyfill/promoCard/PromoCardContext.spec.js +4 -0
- package/build/es/no-polyfill/promoCard/PromoCardGroup.js +20 -0
- package/build/es/no-polyfill/promoCard/PromoCardGroup.spec.js +5 -0
- package/build/es/no-polyfill/promoCard/PromoCardGroup.story.js +1 -0
- package/build/es/no-polyfill/promoCard/PromoCardIndicator.js +16 -0
- package/build/es/no-polyfill/promoCard/index.js +1 -0
- package/build/es/polyfill/common/card/Card.js +21 -0
- package/build/es/polyfill/common/card/Card.spec.js +6 -0
- package/build/es/polyfill/common/card/Card.story.js +1 -0
- package/build/es/polyfill/common/card/index.js +1 -0
- package/build/es/polyfill/common/closeButton/CloseButton.js +1 -1
- package/build/es/polyfill/display/Display.js +1 -1
- package/build/es/polyfill/image/Image.js +1 -1
- package/build/es/polyfill/index.js +1 -1
- package/build/es/polyfill/loader/Loader.js +1 -1
- package/build/es/polyfill/promoCard/PromoCard.js +51 -0
- package/build/es/polyfill/promoCard/PromoCard.spec.js +13 -0
- package/build/es/polyfill/promoCard/PromoCard.story.js +1 -0
- package/build/es/polyfill/promoCard/PromoCardContext.js +19 -0
- package/build/es/polyfill/promoCard/PromoCardContext.spec.js +4 -0
- package/build/es/polyfill/promoCard/PromoCardGroup.js +20 -0
- package/build/es/polyfill/promoCard/PromoCardGroup.spec.js +5 -0
- package/build/es/polyfill/promoCard/PromoCardGroup.story.js +1 -0
- package/build/es/polyfill/promoCard/PromoCardIndicator.js +16 -0
- package/build/es/polyfill/promoCard/index.js +1 -0
- package/build/main.css +1 -1
- package/build/styles/common/card/Card.css +1 -0
- package/build/styles/main.css +1 -1
- package/build/styles/promoCard/PromoCard.css +1 -0
- package/build/types/avatar/index.d.ts +1 -0
- package/build/types/common/card/Card.d.ts +40 -0
- package/build/types/common/card/Card.spec.d.ts +1 -0
- package/build/types/common/card/Card.story.d.ts +6 -0
- package/build/types/common/card/index.d.ts +1 -0
- package/build/types/common/closeButton/CloseButton.d.ts +4 -0
- package/build/types/display/Display.d.ts +1 -1
- package/build/types/image/Image.d.ts +1 -0
- package/build/types/index.d.ts +3 -0
- package/build/types/promoCard/PromoCard.d.ts +83 -0
- package/build/types/promoCard/PromoCard.spec.d.ts +1 -0
- package/build/types/promoCard/PromoCard.story.d.ts +11 -0
- package/build/types/promoCard/PromoCardContext.d.ts +45 -0
- package/build/types/promoCard/PromoCardContext.spec.d.ts +1 -0
- package/build/types/promoCard/PromoCardGroup.d.ts +38 -0
- package/build/types/promoCard/PromoCardGroup.spec.d.ts +1 -0
- package/build/types/promoCard/PromoCardGroup.story.d.ts +8 -0
- package/build/types/promoCard/PromoCardIndicator.d.ts +31 -0
- package/build/types/promoCard/index.d.ts +2 -0
- package/build/umd/no-polyfill/main.js +1 -1
- package/build/umd/polyfill/main.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import _defineProperty from"@babel/runtime/helpers/defineProperty";import _slicedToArray from"@babel/runtime/helpers/slicedToArray";function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}import"core-js/modules/es.array.map.js";import"core-js/modules/es.array.filter.js";import"core-js/modules/es.object.to-string.js";import"core-js/modules/es.object.keys.js";import"core-js/modules/es.symbol.js";import"core-js/modules/es.object.get-own-property-descriptor.js";import"core-js/modules/web.dom-collections.for-each.js";import"core-js/modules/es.object.get-own-property-descriptors.js";import classNames from"classnames";import React,{useState,useEffect,useMemo}from"react";import PromoCardContext from"./PromoCardContext";import{jsx as _jsx}from"react/jsx-runtime";/**
|
|
2
|
+
* PromoCardGroup component.
|
|
3
|
+
*
|
|
4
|
+
* A PromoCardGroup is a container for PromoCard components that allows the user to select one or more
|
|
5
|
+
* cards from a group. It can be used to display a set of related options, and can be customized with
|
|
6
|
+
* various props to suit different use cases.
|
|
7
|
+
*
|
|
8
|
+
* @param {ReactNode} children - The PromoCard components to display inside the group.
|
|
9
|
+
* @param {string} className - Optional class name(s) to add to the group container.
|
|
10
|
+
* @param {string} defaultChecked - The default value for the group.
|
|
11
|
+
* @param {string} id - Optional ID to add to the group container.
|
|
12
|
+
* @param {boolean} isDisabled=false - Whether the group is disabled or not.
|
|
13
|
+
* @param {string} label - Optional label to display above the group.
|
|
14
|
+
* @param {Function} onChange - Optional function to call when the group value changes.
|
|
15
|
+
* @param {string} testId - Optional ID to add to the group container for testing purposes.
|
|
16
|
+
* @returns {JSX.Element} - The PromoCardGroup component.
|
|
17
|
+
*/var PromoCardGroup=function(a){var b=a.children,c=a.className,d=a.defaultChecked,e=void 0===d?"":d,f=a.id,g=a.isDisabled,h=void 0!==g&&g,i=a.onChange,j=void 0===i?function(){}:i,k=a.testId,l=useState(e),m=_slicedToArray(l,2),n=m[0],o=m[1],p=useState(null),q=_slicedToArray(p,2),r=q[0],s=q[1],t=useMemo(function(){return{state:n,isDisabled:h,onChange:function handleOnChange(a){o(a),j(a)}}},[n,h,j]),u=classNames(_defineProperty({"np-CardGroup":!0,"is-disabled":h},"".concat(c||""),c));return useEffect(function(){var a,c;o(e);// Collect an array of types from the children PromoCard components
|
|
18
|
+
var d=null!==(a=null===(c=React.Children.map(b,function(a){return/*#__PURE__*/React.isValidElement(a)&&a.props.type?a.props.type:null}))||void 0===c?void 0:c.filter(function(a){return null!==a&&void 0!==a}))&&void 0!==a?a:[],f=d.every(function(a){return a===d[0]});// Check if all types are the same
|
|
19
|
+
s(f&&"radio"===d[0]?"radiogroup":null)},[e,b]),/*#__PURE__*/_jsx(PromoCardContext.Provider,{value:t,children:/*#__PURE__*/_jsx("div",_objectSpread(_objectSpread({},{className:u,id:f,"data-testid":k,role:r// Add the role attribute here
|
|
20
|
+
}),{},{children:b}))})};export default/*#__PURE__*/React.memo(PromoCardGroup);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import _defineProperty from"@babel/runtime/helpers/defineProperty";import"core-js/modules/es.object.keys.js";import"core-js/modules/es.symbol.js";import"core-js/modules/es.array.filter.js";import"core-js/modules/es.object.to-string.js";import"core-js/modules/es.object.get-own-property-descriptor.js";import"core-js/modules/web.dom-collections.for-each.js";import"core-js/modules/es.object.get-own-property-descriptors.js";function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}import{render,screen}from"@testing-library/react";import PromoCard from"./PromoCard";import PromoCardGroup from"./PromoCardGroup";import{jsx as _jsx}from"react/jsx-runtime";describe("PromoCardGroup",function(){var a,b={title:"Test Card",description:"Test Description",imageSource:"https://via.placeholder.com/150",type:"radio"},c={testId:"test-promo-card-group",children:[/*#__PURE__*/_jsx(PromoCard,_objectSpread(_objectSpread({},b),{},{testId:"test-1",value:"radio-1",id:"radio-1"}),"radio-1"),/*#__PURE__*/_jsx(PromoCard,_objectSpread(_objectSpread({},b),{},{testId:"test-2",value:"radio-2",id:"radio-2"}),"radio-2")]};beforeEach(function(){var b=render(/*#__PURE__*/_jsx(PromoCardGroup,_objectSpread({},c))),d=b.rerender;a=function(a){d(/*#__PURE__*/_jsx(PromoCardGroup,_objectSpread(_objectSpread({},c),a)))}}),it("matches snapshot",function(){var a=render(/*#__PURE__*/_jsx(PromoCardGroup,_objectSpread({},c))),b=a.container;expect(b.firstChild).toMatchSnapshot()}),it("renders",function(){var d=_objectSpread(_objectSpread({},c),{},{children:[/*#__PURE__*/_jsx(PromoCard,_objectSpread(_objectSpread({},b),{},{type:"checkbox",testId:"test-3",value:"radio-3"}),"radio-3"),/*#__PURE__*/_jsx(PromoCard,_objectSpread(_objectSpread({},b),{},{type:"checkbox",testId:"test-4",value:"radio-4"}),"radio-4")]});// Change children
|
|
2
|
+
expect(screen.getByTestId("test-promo-card-group")).toBeInTheDocument(),expect(screen.getByTestId("test-promo-card-group")).toHaveClass("np-CardGroup"),expect(screen.getByRole("radiogroup")).toBeInTheDocument(),a(d),expect(screen.getByTestId("test-4")).toBeInTheDocument()}),it("sets the `defaultValue` for the group",function(){var b=_objectSpread(_objectSpread({},c),{},{defaultChecked:"radio-1"});// Change children
|
|
3
|
+
expect(screen.getByTestId("test-1")).not.toHaveClass("is-checked"),a(b),expect(screen.getByTestId("test-1")).toHaveClass("is-checked")}),it("not to render as a `radiogroup` if we have a mix of PromoCard types",function(){var d=_objectSpread(_objectSpread({},c),{},{children:[/*#__PURE__*/_jsx(PromoCard,_objectSpread(_objectSpread({},b),{},{type:"checkbox",testId:"test-3",value:"radio-3"}),"radio-3"),/*#__PURE__*/_jsx(PromoCard,_objectSpread(_objectSpread({},b),{},{type:"checkbox",testId:"test-4 ",value:"radio-4"}),"radio-4")]});// Change children
|
|
4
|
+
expect(screen.getByRole("radiogroup")).toBeInTheDocument(),a(d),expect(screen.queryByRole("radiogroup")).not.toBeInTheDocument(),expect(screen.getByTestId("test-4")).toBeInTheDocument()}),it("applies `is-disabled` class to all children when isDisabled is true",function(){var b=_objectSpread(_objectSpread({},c),{},{isDisabled:!0});// Change children
|
|
5
|
+
expect(screen.getByTestId("test-1")).not.toHaveClass("is-disabled"),expect(screen.getByTestId("test-2")).not.toHaveClass("is-disabled"),a(b),expect(screen.getByTestId("test-1")).toHaveClass("is-disabled"),expect(screen.getByTestId("test-2")).toHaveClass("is-disabled")})});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import PromoCard from"./PromoCard";import PromoCardGroup from"./PromoCardGroup";import{jsx as _jsx}from"react/jsx-runtime";import{Fragment as _Fragment}from"react/jsx-runtime";import{jsxs as _jsxs}from"react/jsx-runtime";var PromoCards=function(){return/*#__PURE__*/_jsxs(_Fragment,{children:[/*#__PURE__*/_jsx(PromoCard,{title:"Digital",description:"A card that lives online and works anywhere. Easy, secure, and always on hand.",type:"radio",value:"digital",id:"digital",imageAlt:"",indicatorLabel:"Free",imageSource:"https://wise.com/web-art/assets/illustrations/digital-card-2-medium@2x.webp"}),/*#__PURE__*/_jsx(PromoCard,{title:"Standard",description:"Spend and withdraw money around the world. In your wallet and on your side.",type:"radio",value:"standard",id:"standard",imageAlt:"",indicatorLabel:"7 GBP",imageSource:"https://wise.com/web-art/assets/illustrations/personal-card-medium@2x.webp"}),/*#__PURE__*/_jsx(PromoCard,{title:"Eco",description:"A debit card made to biodegrade \u2014 no toxic gases, no toxic fees.",type:"radio",value:"eco",id:"eco",imageAlt:"",indicatorLabel:"9 GBP",imageSource:"https://wise.com/web-art/assets/illustrations/eco-card-medium@2x.webp"})]})},meta={component:PromoCardGroup,title:"Layouts/PromoCardGroup",tags:["autodocs"]};export default meta;export var Default={args:{children:/*#__PURE__*/_jsx(_Fragment,{children:/*#__PURE__*/_jsx(PromoCards,{})})}};export var DefaultChecked={args:{children:/*#__PURE__*/_jsx(_Fragment,{children:/*#__PURE__*/_jsx(PromoCards,{})}),defaultChecked:"standard"}};export var Disabled={args:{children:/*#__PURE__*/_jsx(_Fragment,{children:/*#__PURE__*/_jsx(PromoCards,{})}),isDisabled:!0}};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import _defineProperty from"@babel/runtime/helpers/defineProperty";import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";var _excluded=["className","children","label","icon","testid"];import"core-js/modules/es.object.keys.js";import"core-js/modules/es.symbol.js";import"core-js/modules/es.array.filter.js";import"core-js/modules/es.object.to-string.js";import"core-js/modules/es.object.get-own-property-descriptor.js";import"core-js/modules/web.dom-collections.for-each.js";import"core-js/modules/es.object.get-own-property-descriptors.js";function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}import{ArrowRight,Check,Download}from"@transferwise/icons";import classNames from"classnames";import Body from"../body";import{Typography}from"../common";import{jsx as _jsx}from"react/jsx-runtime";import{jsxs as _jsxs}from"react/jsx-runtime";/**
|
|
2
|
+
* PromoCardIndicator component.
|
|
3
|
+
*
|
|
4
|
+
* A PromoCardIndicator is a small component that can be used to display
|
|
5
|
+
* additional information or actions related to a PromoCard. It can be
|
|
6
|
+
* customized with various props to suit different use cases.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} className - Optional class name(s) to add to the indicator container.
|
|
9
|
+
* @param {string} label - Optional label to display next to the indicator.
|
|
10
|
+
* @param {string} icon - Optional icon to display in the indicator.
|
|
11
|
+
* @param {string} testid - Optional ID to add to the indicator container for testing purposes.
|
|
12
|
+
* @param {ReactNode} children - Optional children to display inside the indicator.
|
|
13
|
+
* @returns {JSX.Element} - The PromoCardIndicator component.
|
|
14
|
+
* @example
|
|
15
|
+
* <PromoCardIndicator label="Download" icon="download" />
|
|
16
|
+
*/var PromoCardIndicator=function(a){var b=a.className,c=a.children,d=a.label,e=a.icon,f=a.testid,g=_objectWithoutProperties(a,_excluded),h=e&&{check:Check,arrow:ArrowRight,download:Download}[e];return/*#__PURE__*/_jsxs("div",_objectSpread(_objectSpread({className:classNames("np-Card-indicator",b),"data-testid":f},g),{},{children:[d&&/*#__PURE__*/_jsx(Body,{as:"span",type:Typography.BODY_LARGE_BOLD,className:"np-Card-indicatorText",children:d}),h&&/*#__PURE__*/_jsx("span",{className:"np-Card-indicatorIcon",children:/*#__PURE__*/_jsx(h,{size:24,"aria-hidden":"true"})}),c]}))};export default PromoCardIndicator;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{default}from"./PromoCard";export{default as PromoCardGroup}from"./PromoCardGroup";
|