diff --git a/README.md b/README.md index 6ea0df0..974fa5d 100644 --- a/README.md +++ b/README.md @@ -323,7 +323,8 @@ Along with Collect Element we can define other options which takes a object of o const options = { required: false, // Optional, indicates whether the field is marked as required. Defaults to 'false'. enableCardIcon: true, // Optional, indicates whether card icon should be enabled (only applicable for CARD_NUMBER ElementType). - format: String, // Optional, format for the element (only applicable currently for EXPIRATION_DATE ElementType). + format: String, // Optional, format for the element. + translation: {}, // Optional, indicates the allowed data type value for format. enableCopy: false, // Optional, enables the copy icon in collect and reveal elements to copy text to clipboard. Defaults to 'false'). allowedFileType: string[], // Optional, allowed extensions for the file to be uploaded. cardMetadata: {}, // Optional, metadata to control card number element behavior. (only applicable for CARD_NUMBER ElementType). @@ -336,25 +337,57 @@ const options = { - `enableCardIcon` parameter indicates whether the icon is visible for the CARD_NUMBER element, defaults to true -- `format` parameter takes string value and indicates the format pattern applicable to the element type, It's currently only applicable to `EXPIRATION_DATE` and `EXPIRATION_YEAR` element types. - `enableCopy` parameter indicates whether the copy icon is visible in collect and reveal elements. - `allowedFileType` parameter indicates the allowedFileType extensions to be uploaded. -The values that are accepted for `EXPIRATION_DATE` are +- `format`: A string value that indicates the format pattern applicable to the element type. + Only applicable to EXPIRATION_DATE, CARD_NUMBER, EXPIRATION_YEAR, and INPUT_FIELD elements. -- `MM/YY` (default) -- `MM/YYYY` -- `YY/MM` -- `YYYY/MM` + - For INPUT_FIELD elements, + - the length of `format` determines the expected length of the user input. + - if `translation` isn't specified, the `format` value is considered a string literal. -The values that are accepted for `EXPIRATION_YEAR` are + `translation`: An object of key value pairs, where the key is a character that appears in `format` and the value is a simple regex pattern of acceptable inputs for that character. Each key can only appear once. Only applicable for INPUT_FIELD elements. -- `YY` (default) -- `YYYY` + Accepted values by element type: + + | Element type | `format` and `translation` values | Examples | + | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ | + | EXPIRATION_DATE |
+ Sample for Input Formatting +
+Sample Composable Elements Dynamic properties update diff --git a/samples/SkyflowElements/src/components/InputFormatting/index.tsx b/samples/SkyflowElements/src/components/InputFormatting/index.tsx new file mode 100644 index 0000000..4408aef --- /dev/null +++ b/samples/SkyflowElements/src/components/InputFormatting/index.tsx @@ -0,0 +1,139 @@ +import React from 'react'; +import { + useCollectContainer, + InputFieldElement, + useMakeSkyflowStyles, + CardNumberElement, +} from 'skyflow-react-js'; + +const InputFormatting = () => { + const container = useCollectContainer(); + + const handleCollect = () => { + const response = container.collect(); + response + .then((res: unknown) => { + console.log(JSON.stringify(res)); + }) + .catch((e: unknown) => { + console.log(e); + }); + }; + + const useStyles = useMakeSkyflowStyles({ + inputStyles: { + base: { + border: '1px solid black', + borderRadius: '4px', + color: '#1d1d1d', + padding: '10px 16px', + fontFamily: '"Roboto", sans-serif' + }, + complete: { + color: '#4caf50', + }, + empty: {}, + focus: {}, + invalid: { + color: '#f44336', + }, + global: { + '@import': 'url("https://fonts.googleapis.com/css2?family=Roboto&display=swap")', + } + }, + labelStyles: { + base: { + fontSize: '16px', + fontWeight: 'bold', + fontFamily: '"Roboto", sans-serif' + }, + global: { + '@import': 'url("https://fonts.googleapis.com/css2?family=Roboto&display=swap")', + }, + requiredAsterisk: { + color: 'red' + } + }, + errorTextStyles: { + base: { + color: 'red', + fontFamily: '"Roboto", sans-serif' + }, + global: { + '@import': 'url("https://fonts.googleapis.com/css2?family=Roboto&display=swap")', + }, + }, + }); + + const classes = useStyles(); + + // Phone Number (+91 XXXXX-XXXXX) + const numberOptions = { + format: '+91 XXXXX-XXXXX', + translation: { 'X': '[0-9]' } + }; + + // Email (XXXXX@XXXXX.XXX) + const emailOptions = { + format: 'XXXXXXXXXX@XXXXXXXXXX.XXX', + translation: { 'X': '[A-Za-z0-9._%+-]' } + }; + + // OTP spaced format: "XXX-XXX" + const otpOptions = { + format: 'XXX-XXX', + translation: { 'X': '[0-9]' } + }; + + return ( +