Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add separation between card elements static and reference values #242

Merged
merged 1 commit into from Oct 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 18 additions & 14 deletions src/types/elements/options.ts
Expand Up @@ -31,7 +31,6 @@ interface SanitizedElementOptions {
iconPosition?: string;
cardBrand?: string;
autoComplete?: string;
value?: string;
}

type ElementOptions = ElementInternalOptions & SanitizedElementOptions;
Expand All @@ -49,32 +48,35 @@ interface AutoCompleteOption {
type CustomizableElementOptions = Pick<ElementOptions, 'style' | 'disabled'> &
AutoCompleteOption;

interface CardElementValue {
number?: DataElementReference;
type ElementValueType = 'static' | 'reference';

interface CardElementValue<T extends ElementValueType> {
number?: T extends 'reference' ? DataElementReference : string;
// disabling camecalse so that the element value matches the API data
/* eslint-disable camelcase */
expiration_month?: DataElementReference;
expiration_year?: DataElementReference;
expiration_month?: T extends 'reference' ? DataElementReference : string;
expiration_year?: T extends 'reference' ? DataElementReference : string;
/* eslint-enable camelcase */
cvc?: DataElementReference;
cvc?: T extends 'reference' ? DataElementReference : string;
}

interface CardExpirationDateValue {
month: DataElementReference;
year: DataElementReference;
interface CardExpirationDateValue<T extends ElementValueType> {
month: T extends 'reference' ? DataElementReference : string;
year: T extends 'reference' ? DataElementReference : string;
}

type CreateCardElementOptions = CustomizableElementOptions & {
value?: CardElementValue;
value?: CardElementValue<'static'>;
};

type UpdateCardElementOptions = CreateCardElementOptions;

type CreateTextElementOptions = CustomizableElementOptions &
Pick<ElementOptions, 'placeholder' | 'mask' | 'password' | 'value'> &
Pick<ElementOptions, 'placeholder' | 'mask' | 'password'> &
TransformOption &
Required<Pick<ElementOptions, 'targetId'>> & {
'aria-label'?: string;
value?: string;
};

type UpdateTextElementOptions = Omit<
Expand All @@ -83,9 +85,10 @@ type UpdateTextElementOptions = Omit<
>;

type CreateCardNumberElementOptions = CustomizableElementOptions &
Pick<ElementOptions, 'placeholder' | 'iconPosition' | 'value'> &
Pick<ElementOptions, 'placeholder' | 'iconPosition'> &
Required<Pick<ElementOptions, 'targetId'>> & {
'aria-label'?: string;
value?: string;
};

type UpdateCardNumberElementOptions = Omit<
Expand All @@ -97,7 +100,7 @@ type CreateCardExpirationDateElementOptions = CustomizableElementOptions &
Pick<ElementOptions, 'placeholder'> &
Required<Pick<ElementOptions, 'targetId'>> & {
'aria-label'?: string;
value?: CardExpirationDateValue;
value?: CardExpirationDateValue<'static'>;
};

type UpdateCardExpirationDateElementOptions = Omit<
Expand All @@ -106,9 +109,10 @@ type UpdateCardExpirationDateElementOptions = Omit<
>;

type CreateCardVerificationCodeElementOptions = CustomizableElementOptions &
Pick<ElementOptions, 'placeholder' | 'cardBrand' | 'value'> &
Pick<ElementOptions, 'placeholder' | 'cardBrand'> &
Required<Pick<ElementOptions, 'targetId'>> & {
'aria-label'?: string;
value?: string;
};

type UpdateCardVerificationCodeElementOptions = Omit<
Expand Down