@kvell-group/ui 1.16.19 → 1.16.20

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@kvell-group/ui",
3
3
  "author": "Kvell Group",
4
4
  "private": false,
5
- "version": "1.16.19",
5
+ "version": "1.16.20",
6
6
  "type": "module",
7
7
  "main": "src/index.ts",
8
8
  "types": "src/index.ts",
@@ -0,0 +1,34 @@
1
+ import type { Meta, StoryObj } from '@storybook/react'
2
+
3
+ import { KvellUiProvider } from '@/components/KvellUiProvider'
4
+
5
+ import { theme } from '@/components/theme'
6
+
7
+ import { CardLogoByPan as CardLogoByPanComponent } from '@/components/CardLogoByPan/CardLogoByPan'
8
+
9
+ // ----------------------------------------------------------------------
10
+
11
+ const meta = {
12
+ title: 'Components/CardLogoByPan',
13
+
14
+ component: CardLogoByPanComponent,
15
+ decorators: (Story) => (
16
+ <KvellUiProvider theme={theme}>
17
+ <Story />
18
+ </KvellUiProvider>
19
+ ),
20
+ } satisfies Meta<typeof CardLogoByPanComponent>
21
+
22
+ type Story = StoryObj<typeof meta>
23
+
24
+ // ----------------------------------------------------------------------
25
+
26
+ export const CardLogoByPan: Story = {
27
+ args: {
28
+ value: '41111',
29
+ },
30
+ }
31
+
32
+ // ----------------------------------------------------------------------
33
+
34
+ export default meta
@@ -0,0 +1,16 @@
1
+ import { getCardLogoByPan } from './utils'
2
+
3
+ // ----------------------------------------------------------------------
4
+
5
+ interface CardLogoByPanProps extends React.SVGProps<SVGSVGElement> {
6
+ value: string
7
+ customColor?: string
8
+ }
9
+
10
+ // ----------------------------------------------------------------------
11
+
12
+ export const CardLogoByPan = ({ value, ...restSvgProps }: CardLogoByPanProps) => {
13
+ const Icon = getCardLogoByPan(value)
14
+
15
+ return Icon && <Icon {...restSvgProps} />
16
+ }
@@ -0,0 +1 @@
1
+ export { CardLogoByPan } from './CardLogoByPan'
@@ -1,11 +1,9 @@
1
- import { useEffect, useState } from 'react'
2
-
3
- import MaestroSVG from '../../../assets/card-logos/maestro.svg'
4
- import MastercardSVG from '../../../assets/card-logos/mastercard.svg'
5
- import MirSVG from '../../../assets/card-logos/mir.svg'
6
- import UnionPaySVG from '../../../assets/card-logos/unionpay.svg'
7
- import VisaElectronSVG from '../../../assets/card-logos/visa-electron.svg'
8
- import VisaSVG from '../../../assets/card-logos/visa.svg'
1
+ import MaestroSVG from '../../assets/card-logos/maestro.svg'
2
+ import MastercardSVG from '../../assets/card-logos/mastercard.svg'
3
+ import MirSVG from '../../assets/card-logos/mir.svg'
4
+ import UnionPaySVG from '../../assets/card-logos/unionpay.svg'
5
+ import VisaElectronSVG from '../../assets/card-logos/visa-electron.svg'
6
+ import VisaSVG from '../../assets/card-logos/visa.svg'
9
7
 
10
8
  // ----------------------------------------------------------------------
11
9
 
@@ -66,23 +64,4 @@ const getCardLogo = (cardLabel: CardLabel | null) => {
66
64
 
67
65
  // ----------------------------------------------------------------------
68
66
 
69
- export const useCardLogo = (cardPan?: string) => {
70
- const [cardLabel, setCardLabel] = useState<CardLabel | null>(null)
71
- const CardLogo = getCardLogo(cardLabel)
72
-
73
- useEffect(() => {
74
- if (!cardPan) {
75
- setCardLabel(null)
76
- } else {
77
- const detectedCardLabel = getCardLabel(cardPan)
78
-
79
- if (detectedCardLabel) {
80
- setCardLabel(detectedCardLabel)
81
- } else {
82
- setCardLabel(null)
83
- }
84
- }
85
- }, [cardPan])
86
-
87
- return CardLogo
88
- }
67
+ export const getCardLogoByPan = (cardNumber: string) => getCardLogo(getCardLabel(cardNumber))
@@ -1,20 +1,20 @@
1
1
  import { MaskedInput } from '../MaskedInput'
2
- import { useCardLogo } from './useCardLogo'
3
2
  import type { MaskedInputProps } from '../types'
4
3
  import { forwardRef } from 'react'
5
4
  import { CARD_NUMBER_MASK } from '../../../constants/masks'
6
5
  import { IMask } from 'react-imask'
7
6
  import { RiBankCardLine as CardSVG } from '@remixicon/react'
7
+ import { CardLogoByPan } from '../../CardLogoByPan'
8
8
 
9
9
  // ----------------------------------------------------------------------
10
10
 
11
11
  const mask = IMask.createMask({ mask: CARD_NUMBER_MASK })
12
12
 
13
- // ----------------------------------------------------------------------
13
+ type CardInputProps = Omit<MaskedInputProps, 'value'> & { value: string }
14
14
 
15
- export const CardInput = forwardRef<HTMLInputElement, MaskedInputProps>((props, ref) => {
16
- const CardLogo = useCardLogo(props.value)
15
+ // ----------------------------------------------------------------------
17
16
 
17
+ export const CardInput = forwardRef<HTMLInputElement, CardInputProps>((props, ref) => {
18
18
  return (
19
19
  <MaskedInput
20
20
  ref={ref}
@@ -22,7 +22,7 @@ export const CardInput = forwardRef<HTMLInputElement, MaskedInputProps>((props,
22
22
  autoComplete='cc-number'
23
23
  {...props}
24
24
  mask={mask}
25
- rightSection={CardLogo && <CardLogo />}
25
+ rightSection={<CardLogoByPan value={props.value} />}
26
26
  leftSection={<CardSVG size={20} />}
27
27
  placeholder='____ ____ ____ ____'
28
28
  />
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  // components
2
2
  export { Button } from './components/Button'
3
+ export { CardLogoByPan } from './components/CardLogoByPan'
3
4
 
4
5
  // constants
5
6
  export { theme } from './components/theme'