diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/payment-card/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/payment-card/Examples.tsx index c040f909112..500ed8952d3 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/payment-card/Examples.tsx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/payment-card/Examples.tsx @@ -6,8 +6,8 @@ import React from 'react' import ComponentBox from '../../../../shared/tags/ComponentBox' import PaymentCard, { - getCardData, - Designs, + getCardDesign, + CustomCard, // ProductType, // CardType, // BankAxeptType, @@ -17,7 +17,7 @@ import { H4 } from '@dnb/eufemia/src' export function PaymentCardAllCardsExample() { return ( {() => { @@ -70,15 +70,15 @@ export function PaymentCardAllCardsExample() { const Cards = () => ( <> {demoCards.map((product_code) => { - const cardData = getCardData(product_code) + const cardData = getCardDesign(product_code) return (

- {cardData.cardDesign.name}({product_code}) + {cardData.displayName}({product_code})

) @@ -105,25 +105,23 @@ export const PaymentCardCustomExample = () => ( {() => { - const customData = { - productCode: '', - productName: 'DNB Custom Card', - displayName: 'Custom card', - cardDesign: Designs.gold, - cardType: 'VisaColored', - productType: 'None', - bankAxept: 'BankAxeptWhite', + const customData: CustomCard = { + displayName: 'custom card', + bankLogo: { type: 'DNB' }, + cardProvider: { type: 'Mastercard' }, + paymentType: { type: 'BankAxept' }, + background: 'gold', } return ( ) }} @@ -136,9 +134,9 @@ export const PaymentCardStatusExample = () => ( data-visual-test="payment-card-status" > ) @@ -150,8 +148,8 @@ export const PaymentCardCompactExample = () => ( >
) diff --git a/packages/dnb-eufemia/src/extensions/payment-card/PaymentCard.tsx b/packages/dnb-eufemia/src/extensions/payment-card/PaymentCard.tsx index b57dc7a802b..30f5447372f 100644 --- a/packages/dnb-eufemia/src/extensions/payment-card/PaymentCard.tsx +++ b/packages/dnb-eufemia/src/extensions/payment-card/PaymentCard.tsx @@ -2,9 +2,9 @@ import classnames from 'classnames' import { BankLogo, ProductLogo, - BankAxeptLogo, StatusIcon, CardProviderLogo, + PaymentTypeLogo, } from './icons' import Context from '../../shared/Context' import { @@ -19,24 +19,19 @@ import { import { useContext } from 'react' import { createSpacingClasses } from '../../components/space/SpacingUtils' import cardProducts from './utils/cardProducts' -import { defaultDesign } from './utils/CardDesigns' import { + CustomCard, PaymentCardCardStatus, PaymentCardProps, - PaymentCardRawData, } from './types' import { convertSnakeCaseProps } from '../../shared/helpers/withSnakeCaseProps' +import { defaultDesign } from './utils/CardDesigns' -const defaultCard: (productCode: string) => PaymentCardRawData = ( +const defaultCard: (productCode: string) => CustomCard = ( productCode ) => ({ productCode, - productName: '', - displayName: '', - cardDesign: defaultDesign, - cardType: 'None', - productType: 'None', - bankAxept: 'None', + ...defaultDesign, }) const defaultProps = { @@ -46,7 +41,9 @@ const defaultProps = { variant: 'normal', id: null, - rawData: null, + + customCard: null, + // rawData: null, skeleton: false, className: null, @@ -75,7 +72,8 @@ export default function PaymentCard(props: PaymentCardProps) { variant, digits, id, - rawData, + customCard: cardDesignProp, + // rawData, // locale, skeleton, className, @@ -91,7 +89,12 @@ export default function PaymentCard(props: PaymentCardProps) { } ) - const cardData: PaymentCardRawData = rawData || getCardData(productCode) + const cardDesign = { + ...getCardDesign(productCode), + ...cardDesignProp, + } + + // const cardData: CustomCard = rawData || getCardData(productCode) const params = { className: classnames( @@ -122,34 +125,29 @@ export default function PaymentCard(props: PaymentCardProps) { return (
- {cardData.productName} + {cardDesign.displayName}
- - - - + + + + +
- +
@@ -216,11 +211,18 @@ export function formatCardNumber(cardNumber, digits = 8) { return cardNumber.replace(formatCardNumberRegex, ' ').trim() } -export const getCardData: (productCode: string) => PaymentCardRawData = ( - productCode -) => { - const card = cardProducts.find( - (item) => item.productCode === productCode +export function getCardDesign(productCode: string): CustomCard { + return ( + cardProducts.find((item) => item.productCode === productCode) || + defaultCard(productCode) ) - return card || defaultCard(productCode) } + +// export const getCardData: (productCode: string) => PaymentCardRawData = ( +// productCode +// ) => { +// const card = cardProducts.find( +// (item) => item.productCode === productCode +// ) +// return card || defaultCard(productCode) +// } diff --git a/packages/dnb-eufemia/src/extensions/payment-card/icons/index.tsx b/packages/dnb-eufemia/src/extensions/payment-card/icons/index.tsx index 3848b4829b3..3946a83f46b 100644 --- a/packages/dnb-eufemia/src/extensions/payment-card/icons/index.tsx +++ b/packages/dnb-eufemia/src/extensions/payment-card/icons/index.tsx @@ -29,20 +29,22 @@ import { BankAxeptType, CardStatus, CardTypeDesign, + PaymentType, + CardProvider, + BankLogoType, } from '../types' type BankLogoProps = { - logoType?: LogoType + type?: BankLogoType color?: string - height?: string } -function BankLogo({ logoType, color, height }: BankLogoProps) { - switch (logoType) { +function BankLogo({ type, color }: BankLogoProps) { + switch (type) { case 'DNB': return ( @@ -51,33 +53,29 @@ function BankLogo({ logoType, color, height }: BankLogoProps) { case 'sbanken': return ( ) + default: + return null } } type ProductLogoProps = { - productType: ProductType - cardDesign: CardDesign + type?: ProductType + // color?: string } -function ProductLogo({ productType, cardDesign }: ProductLogoProps) { +function ProductLogo({ type }: ProductLogoProps) { const classname = 'dnb-payment-card__card__product-type' - switch (productType) { - case 'Saga': - switch (cardDesign) { - case 'SagaGold': - return - case 'SagaPlatinum': - return - case 'None': - default: - return null - } + switch (type) { + case 'SagaGold': + return + case 'SagaPlatinum': + return case 'Pluss': return case 'Intro': @@ -87,38 +85,30 @@ function ProductLogo({ productType, cardDesign }: ProductLogoProps) { case 'Bedrift': return case 'PrivateBanking': - return cardDesign !== 'None' ? : null - case 'None': + return default: return null } } -type BankAxeptProps = { - bankAxept: BankAxeptType +type PaymentTypeProps = { + type: PaymentType + color: string } -const BankAxeptLogo = ({ bankAxept }: BankAxeptProps) => { - const classname = 'dnb-payment-card__card__bank-axept' - - switch (bankAxept) { - case 'BankAxeptWhite': - return - case 'BankAxeptBlack20': - return - case 'BankAxeptGray': - return - case 'BankAxeptGrayDark': - return - case 'BankAxeptBlack': - return - case 'BankAxeptGold': - return +const PaymentTypeLogo = ({ type, color }: PaymentTypeProps) => { + switch (type) { + case 'BankAxept': + return ( + + ) case 'Credit': return ( - + ) - case 'None': default: return null } @@ -154,26 +144,43 @@ const StatusIcon = ({ status }: { status: CardStatus }) => { } const CardProviderLogo = ({ - cardTypeDesign, + type, color, }: { - cardTypeDesign: CardTypeDesign + type: CardProvider color?: string }) => { const id = 'dnb-payment-card__card__credit-type' - switch (cardTypeDesign) { - case 'VisaColored': - return - case 'VisaPlatinum': - return - case 'MastercardDefault': + switch (type) { + case 'Mastercard': return + case 'MastercardDark': return - case 'None': + + case 'Visa': + return + + case 'VisaPlatinum': + return + + default: return null } + + // switch (cardTypeDesign) { + // case 'VisaColored': + // return + // case 'VisaPlatinum': + // return + // case 'MastercardDefault': + // return + // case 'MastercardDark': + // return + // case 'None': + // return null + // } } export { @@ -181,5 +188,5 @@ export { ProductLogo, StatusIcon, CardProviderLogo, - BankAxeptLogo, + PaymentTypeLogo, } diff --git a/packages/dnb-eufemia/src/extensions/payment-card/stories/PaymentCard.stories.tsx b/packages/dnb-eufemia/src/extensions/payment-card/stories/PaymentCard.stories.tsx index cf2add9aea9..24b3608fedd 100644 --- a/packages/dnb-eufemia/src/extensions/payment-card/stories/PaymentCard.stories.tsx +++ b/packages/dnb-eufemia/src/extensions/payment-card/stories/PaymentCard.stories.tsx @@ -16,7 +16,7 @@ import cardData from '../utils/cardProducts' import { PaymentCardRawData } from '../types' import { H2 } from '../../../elements' -import PaymentCard, { getCardData, Designs } from '../' +import PaymentCard, { getCardDesign, Designs } from '../' export default { title: 'Eufemia/Extensions/PaymentCard', @@ -26,16 +26,16 @@ const CustomWrapper = styled(Wrapper)` /* empty */ ` -const customData: PaymentCardRawData = { - productCode: 'UNDEFINED', - productName: 'DNB Custom Card', - displayName: 'Custom card', // Only showed in compact variant - // cardDesign: 'gold', - cardDesign: Designs.gold, - cardType: 'MastercardDefault', - productType: 'Saga', - bankAxept: 'BankAxeptWhite', -} +// const customData: PaymentCardRawData = { +// productCode: 'UNDEFINED', +// productName: 'DNB Custom Card', +// displayName: 'Custom card', // Only showed in compact variant +// // cardDesign: 'gold', +// cardDesign: Designs.gold, +// cardType: 'MastercardDefault', +// productType: 'Saga', +// bankAxept: 'BankAxeptWhite', +// } export const PaymentCards = () => ( @@ -43,7 +43,7 @@ export const PaymentCards = () => (

Test

@@ -96,22 +96,22 @@ export const PaymentCards = () => ( @@ -120,11 +120,11 @@ export const PaymentCards = () => (

All Cards

{cards.map((productCode) => { - const cardData = getCardData(productCode) + const cardData = getCardDesign(productCode) return (

- {cardData.cardDesign.name}({productCode}) + {cardData.displayName}({productCode})