Skip to content

Commit

Permalink
feat: add value prop to elements create and update objects (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
lcschy committed Oct 7, 2022
1 parent a0b2f6c commit b427e8d
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/types/elements/options.ts
Expand Up @@ -30,6 +30,7 @@ interface SanitizedElementOptions {
iconPosition?: string;
cardBrand?: string;
autoComplete?: string;
value?: string;
}

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

type CreateCardElementOptions = CustomizableElementOptions;
interface CardElementValue {
number?: string;
// disabling camecalse so that the element value matches the API data
/* eslint-disable camelcase */
expiration_month?: number;
expiration_year?: number;
/* eslint-enable camelcase */
cvc?: string;
}

interface CardExpirationDateValue {
month: number;
year: number;
}

type CreateCardElementOptions = CustomizableElementOptions & {
value?: CardElementValue;
};

type UpdateCardElementOptions = CreateCardElementOptions;

type CreateTextElementOptions = CustomizableElementOptions &
Pick<ElementOptions, 'placeholder' | 'mask' | 'password'> &
Pick<ElementOptions, 'placeholder' | 'mask' | 'password' | 'value'> &
TransformOption &
Required<Pick<ElementOptions, 'targetId'>> & {
'aria-label'?: string;
Expand All @@ -64,7 +82,7 @@ type UpdateTextElementOptions = Omit<
>;

type CreateCardNumberElementOptions = CustomizableElementOptions &
Pick<ElementOptions, 'placeholder' | 'iconPosition'> &
Pick<ElementOptions, 'placeholder' | 'iconPosition' | 'value'> &
Required<Pick<ElementOptions, 'targetId'>> & {
'aria-label'?: string;
};
Expand All @@ -78,6 +96,7 @@ type CreateCardExpirationDateElementOptions = CustomizableElementOptions &
Pick<ElementOptions, 'placeholder'> &
Required<Pick<ElementOptions, 'targetId'>> & {
'aria-label'?: string;
value?: CardExpirationDateValue;
};

type UpdateCardExpirationDateElementOptions = Omit<
Expand All @@ -86,7 +105,7 @@ type UpdateCardExpirationDateElementOptions = Omit<
>;

type CreateCardVerificationCodeElementOptions = CustomizableElementOptions &
Pick<ElementOptions, 'placeholder' | 'cardBrand'> &
Pick<ElementOptions, 'placeholder' | 'cardBrand' | 'value'> &
Required<Pick<ElementOptions, 'targetId'>> & {
'aria-label'?: string;
};
Expand All @@ -113,6 +132,8 @@ export type {
UpdateCardExpirationDateElementOptions,
CreateCardVerificationCodeElementOptions,
UpdateCardVerificationCodeElementOptions,
CardElementValue,
CardExpirationDateValue,
};

export { ELEMENTS_TYPES };

0 comments on commit b427e8d

Please sign in to comment.