Skip to content

Commit

Permalink
feat: add autoComplete option for elements (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
lcschy committed Jun 30, 2022
1 parent 140ef8e commit 0a3c48e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/elements/constants.ts
Expand Up @@ -28,11 +28,14 @@ const CARD_BRANDS = [

const CARD_ICON_POSITIONS = ['left', 'right', 'none'] as const;

const AUTOCOMPLETE_VALUES = ['off', 'on'] as const;

export {
ELEMENTS_INIT_ERROR_MESSAGE,
ELEMENTS_NOM_DOM_ERROR_MESSAGE,
ELEMENTS_SCRIPT_LOAD_ERROR_MESSAGE,
ELEMENTS_SCRIPT_UNKNOWN_ERROR_MESSAGE,
CARD_BRANDS,
CARD_ICON_POSITIONS,
AUTOCOMPLETE_VALUES,
};
9 changes: 8 additions & 1 deletion src/types/elements/options.ts
@@ -1,3 +1,4 @@
import { AutoCompleteValue } from './shared';
import type { ElementStyle } from './styles';

const ELEMENTS_TYPES = [
Expand Down Expand Up @@ -28,6 +29,7 @@ interface SanitizedElementOptions {
ariaLabel?: string;
iconPosition?: string;
cardBrand?: string;
autoComplete?: string;
}

type ElementOptions = ElementInternalOptions & SanitizedElementOptions;
Expand All @@ -38,7 +40,12 @@ interface TransformOption {
transform?: Transform;
}

type CustomizableElementOptions = Pick<ElementOptions, 'style' | 'disabled'>;
interface AutoCompleteOption {
autoComplete?: AutoCompleteValue;
}

type CustomizableElementOptions = Pick<ElementOptions, 'style' | 'disabled'> &
AutoCompleteOption;

type CreateCardElementOptions = CustomizableElementOptions;

Expand Down
12 changes: 11 additions & 1 deletion src/types/elements/shared.ts
@@ -1,4 +1,8 @@
import { CARD_BRANDS, CARD_ICON_POSITIONS } from '@/elements/constants';
import {
AUTOCOMPLETE_VALUES,
CARD_BRANDS,
CARD_ICON_POSITIONS,
} from '@/elements/constants';

type FieldErrorType = 'incomplete' | 'invalid';

Expand Down Expand Up @@ -37,6 +41,11 @@ type Brand = typeof CARD_BRANDS[number];
*/
type CardIconPosition = typeof CARD_ICON_POSITIONS[number];

/**
* Values for the element input autocomplete attribute
*/
type AutoCompleteValue = typeof AUTOCOMPLETE_VALUES[number];

export type {
FieldErrorType,
ConfigErrorType,
Expand All @@ -47,4 +56,5 @@ export type {
PropertyError,
Brand,
CardIconPosition,
AutoCompleteValue,
};

0 comments on commit 0a3c48e

Please sign in to comment.