Skip to content

Commit

Permalink
feat: enables copy icon customization (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinperaza committed Jun 13, 2024
1 parent 87145c3 commit 03f1725
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 57 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"postinstall": "husky install"
},
"dependencies": {
"@basis-theory/basis-theory-js": "^4.2.2"
"@basis-theory/basis-theory-js": "^4.6.2"
},
"devDependencies": {
"@babel/cli": "^7.22.15",
Expand Down
4 changes: 4 additions & 0 deletions src/elements/CardElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ElementStyle,
CardElementValue,
CreditCardType,
CopyIconStyles,
} from '@basis-theory/basis-theory-js/types/elements';
import type { BasisTheoryReact } from '../core';
import { useElement } from './useElement';
Expand All @@ -17,6 +18,7 @@ interface CardElementProps {
autoComplete?: 'on' | 'off';
bt?: BasisTheoryReact;
cardTypes?: CreditCardType[];
copyIconStyles?: CopyIconStyles;
disabled?: boolean;
enableCopy?: boolean;
id: string;
Expand All @@ -39,6 +41,7 @@ const CardElementC: FC<
autoComplete,
bt,
cardTypes,
copyIconStyles,
disabled,
elementRef,
enableCopy,
Expand All @@ -63,6 +66,7 @@ const CardElementC: FC<
{
autoComplete,
cardTypes,
copyIconStyles,
disabled,
enableCopy,
inputMode,
Expand Down
6 changes: 5 additions & 1 deletion src/elements/CardExpirationDateElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
CardExpirationDateElementEvents,
CardExpirationDateValue,
InputMode,
CopyIconStyles,
} from '@basis-theory/basis-theory-js/types/elements';
import type { BasisTheoryReact } from '../core';
import { useElement } from './useElement';
Expand All @@ -16,6 +17,7 @@ interface CardExpirationDateElementProps {
'aria-label'?: string;
autoComplete?: 'on' | 'off';
bt?: BasisTheoryReact;
copyIconStyles?: CopyIconStyles;
disabled?: boolean;
enableCopy?: boolean;
id: string;
Expand All @@ -30,7 +32,7 @@ interface CardExpirationDateElementProps {
style?: ElementStyle;
validateOnChange?: boolean;
value?: CardExpirationDateValue<'static'> | string;
valueRef?: MutableRefObject<ICardExpirationDateElement>;
valueRef?: MutableRefObject<ICardExpirationDateElement | null>;
}

const CardExpirationDateElementC: FC<
Expand All @@ -41,6 +43,7 @@ const CardExpirationDateElementC: FC<
'aria-label': ariaLabel,
autoComplete,
bt,
copyIconStyles,
disabled,
elementRef,
enableCopy,
Expand Down Expand Up @@ -69,6 +72,7 @@ const CardExpirationDateElementC: FC<
{
'aria-label': ariaLabel,
autoComplete,
copyIconStyles,
disabled,
enableCopy,
inputMode,
Expand Down
4 changes: 4 additions & 0 deletions src/elements/CardNumberElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
SanitizedElementOptions,
InputMode,
CreditCardType,
CopyIconStyles,
} from '@basis-theory/basis-theory-js/types/elements';
import type { BasisTheoryReact } from '../core';
import { useElement } from './useElement';
Expand All @@ -18,6 +19,7 @@ interface CardNumberElementProps {
autoComplete?: 'on' | 'off';
bt?: BasisTheoryReact;
cardTypes?: CreditCardType[];
copyIconStyles?: CopyIconStyles;
disabled?: boolean;
enableCopy?: boolean;
iconPosition?: SanitizedElementOptions['iconPosition'];
Expand All @@ -44,6 +46,7 @@ const CardNumberElementC: FC<
autoComplete,
bt,
cardTypes,
copyIconStyles,
disabled,
elementRef,
enableCopy,
Expand Down Expand Up @@ -77,6 +80,7 @@ const CardNumberElementC: FC<
'aria-label': ariaLabel,
autoComplete,
cardTypes,
copyIconStyles,
disabled,
enableCopy,
iconPosition,
Expand Down
4 changes: 4 additions & 0 deletions src/elements/CardVerificationCodeElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
CardVerificationCodeElementEvents,
Brand,
InputMode,
CopyIconStyles,
} from '@basis-theory/basis-theory-js/types/elements';
import type { BasisTheoryReact } from '../core';
import { useElement } from './useElement';
Expand All @@ -17,6 +18,7 @@ interface CardVerificationCodeElementProps {
autoComplete?: 'on' | 'off';
bt?: BasisTheoryReact;
cardBrand?: Brand | string;
copyIconStyles?: CopyIconStyles;
disabled?: boolean;
enableCopy?: boolean;
id: string;
Expand Down Expand Up @@ -46,6 +48,7 @@ const CardVerificationCodeElementC: FC<
autoComplete,
bt,
cardBrand,
copyIconStyles,
disabled,
elementRef,
enableCopy,
Expand Down Expand Up @@ -75,6 +78,7 @@ const CardVerificationCodeElementC: FC<
'aria-label': ariaLabel,
autoComplete,
cardBrand,
copyIconStyles,
disabled,
enableCopy,
inputMode,
Expand Down
33 changes: 21 additions & 12 deletions test/elements/CardElement.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
CardElementValue,
ElementStyle,
InputMode,
CopyIconStyles,
} from '@basis-theory/basis-theory-js/types/elements';
import { render } from '@testing-library/react';
import { Chance } from 'chance';
Expand All @@ -18,24 +19,25 @@ describe('CardElement', () => {
const chance = new Chance();
const refArray = [React.createRef<ICardElement>(), undefined];

let id: string;
let wrapperDiv: HTMLDivElement;
let style: ElementStyle;
let disabled: boolean;
let autoComplete: 'on' | 'off';
let inputMode: `${InputMode}`;
let value: CardElementValue<'static'>;
let validateOnChange: boolean;
let copyIconStyles: CopyIconStyles;
let disabled: boolean;
let element: unknown;
let enableCopy: boolean;
let readOnly: boolean;
let skipLuhnValidation: boolean;
let onReady: jest.Mock;
let id: string;
let inputMode: `${InputMode}`;
let onBlur: jest.Mock;
let onChange: jest.Mock;
let onFocus: jest.Mock;
let onBlur: jest.Mock;
let onKeyDown: jest.Mock;
let element: unknown;
let onReady: jest.Mock;
let readOnly: boolean;
let ref: any;
let skipLuhnValidation: boolean;
let style: ElementStyle;
let validateOnChange: boolean;
let value: CardElementValue<'static'>;
let wrapperDiv: HTMLDivElement;

beforeEach(() => {
id = 'my-card';
Expand All @@ -62,6 +64,11 @@ describe('CardElement', () => {
numeric: true,
}),
};
copyIconStyles = {
size: '10',
color: 'blue',
successColor: 'red',
};
validateOnChange = chance.bool();
enableCopy = chance.bool();
inputMode = 'numeric';
Expand All @@ -82,6 +89,7 @@ describe('CardElement', () => {
const { container } = render(
<CardElement
autoComplete={autoComplete}
copyIconStyles={copyIconStyles}
disabled={disabled}
enableCopy={enableCopy}
id={id}
Expand Down Expand Up @@ -110,6 +118,7 @@ describe('CardElement', () => {
disabled,
enableCopy,
inputMode,
copyIconStyles,
readOnly,
skipLuhnValidation,
style,
Expand Down
33 changes: 21 additions & 12 deletions test/elements/CardExpirationDateElement.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
CardExpirationDateValue,
ElementStyle,
InputMode,
CopyIconStyles,
} from '@basis-theory/basis-theory-js/types/elements';
import { render } from '@testing-library/react';
import { Chance } from 'chance';
Expand All @@ -20,25 +21,26 @@ describe('CardExpirationDateElement', () => {

const valueRef = React.createRef<ICardExpirationDateElement>();

let id: string;
let wrapperDiv: HTMLDivElement;
let style: ElementStyle;
let disabled: boolean;
let readOnly: boolean;
let autoComplete: 'on' | 'off';
let ariaLabel: string;
let placeholder: string;
let value: CardExpirationDateValue<'static'>;
let validateOnChange: boolean;
let autoComplete: 'on' | 'off';
let copyIconStyles: CopyIconStyles;
let disabled: boolean;
let element: unknown;
let enableCopy: boolean;
let id: string;
let inputMode: `${InputMode}`;
let onReady: jest.Mock;
let onBlur: jest.Mock;
let onChange: jest.Mock;
let onFocus: jest.Mock;
let onBlur: jest.Mock;
let onKeyDown: jest.Mock;
let element: unknown;
let onReady: jest.Mock;
let placeholder: string;
let readOnly: boolean;
let ref: any;
let style: ElementStyle;
let validateOnChange: boolean;
let value: CardExpirationDateValue<'static'>;
let wrapperDiv: HTMLDivElement;

beforeEach(() => {
id = 'my-card-expiration-date';
Expand All @@ -59,6 +61,11 @@ describe('CardExpirationDateElement', () => {
}),
year: new Date().getFullYear() + 1,
};
copyIconStyles = {
size: '10',
color: 'blue',
successColor: 'red',
};
validateOnChange = chance.bool();
enableCopy = chance.bool();
inputMode = 'numeric';
Expand All @@ -80,6 +87,7 @@ describe('CardExpirationDateElement', () => {
<CardExpirationDateElement
aria-label={ariaLabel}
autoComplete={autoComplete}
copyIconStyles={copyIconStyles}
disabled={disabled}
enableCopy={enableCopy}
id={id}
Expand Down Expand Up @@ -108,6 +116,7 @@ describe('CardExpirationDateElement', () => {
targetId: id,
style,
disabled,
copyIconStyles,
enableCopy,
autoComplete,
readOnly,
Expand Down
37 changes: 23 additions & 14 deletions test/elements/CardNumberElement.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
ElementStyle,
CreateCardNumberElementOptions,
InputMode,
CopyIconStyles,
} from '@basis-theory/basis-theory-js/types/elements';
import { render } from '@testing-library/react';
import { Chance } from 'chance';
Expand All @@ -20,27 +21,28 @@ describe('CardNumberElement', () => {

const valueRef = React.createRef<ICardNumberElement>();

let id: string;
let wrapperDiv: HTMLDivElement;
let style: ElementStyle;
let disabled: boolean;
let readOnly: boolean;
let autoComplete: 'on' | 'off';
let ariaLabel: string;
let placeholder: string;
let iconPosition: CreateCardNumberElementOptions['iconPosition'];
let value: string;
let validateOnChange: boolean;
let autoComplete: 'on' | 'off';
let copyIconStyles: CopyIconStyles;
let disabled: boolean;
let element: unknown;
let enableCopy: boolean;
let skipLuhnValidation: boolean;
let iconPosition: CreateCardNumberElementOptions['iconPosition'];
let id: string;
let inputMode: `${InputMode}`;
let onReady: jest.Mock;
let onBlur: jest.Mock;
let onChange: jest.Mock;
let onFocus: jest.Mock;
let onBlur: jest.Mock;
let onKeyDown: jest.Mock;
let element: unknown;
let onReady: jest.Mock;
let placeholder: string;
let readOnly: boolean;
let ref: any;
let skipLuhnValidation: boolean;
let style: ElementStyle;
let validateOnChange: boolean;
let value: string;
let wrapperDiv: HTMLDivElement;

beforeEach(() => {
id = 'my-card-number';
Expand All @@ -49,6 +51,11 @@ describe('CardNumberElement', () => {
style = {
[chance.string()]: chance.string(),
};
copyIconStyles = {
size: '10',
color: 'blue',
successColor: 'red',
};
disabled = chance.bool();
readOnly = chance.bool();
autoComplete = chance.pickone(['on', 'off']);
Expand Down Expand Up @@ -78,6 +85,7 @@ describe('CardNumberElement', () => {
<CardNumberElement
aria-label={ariaLabel}
autoComplete={autoComplete}
copyIconStyles={copyIconStyles}
disabled={disabled}
enableCopy={enableCopy}
iconPosition={iconPosition}
Expand Down Expand Up @@ -108,6 +116,7 @@ describe('CardNumberElement', () => {
'aria-label': ariaLabel,
autoComplete,
disabled,
copyIconStyles,
enableCopy,
iconPosition,
inputMode,
Expand Down
Loading

0 comments on commit 03f1725

Please sign in to comment.