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 value prop to elements create and update objects #237

Merged
merged 5 commits into from Oct 7, 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
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 };