playbook_ui 14.18.0.pre.rc.1 → 14.18.0.pre.rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_copy_button/_copy_button.tsx +19 -45
- data/app/pb_kits/playbook/pb_copy_button/docs/_copy_button_hook.jsx +54 -0
- data/app/pb_kits/playbook/pb_copy_button/docs/_copy_button_hook.md +3 -0
- data/app/pb_kits/playbook/pb_copy_button/docs/example.yml +1 -0
- data/app/pb_kits/playbook/pb_copy_button/docs/index.js +2 -1
- data/app/pb_kits/playbook/pb_copy_button/usePBCopy.ts +45 -0
- data/app/pb_kits/playbook/pb_form_group/_form_group.scss +5 -1
- data/app/pb_kits/playbook/pb_form_group/docs/_form_group_select.jsx +19 -1
- data/app/pb_kits/playbook/pb_table/_table.tsx +2 -2
- data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible_with_nested_rows.md +3 -1
- data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible_with_nested_rows_rails.md +3 -1
- data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible_with_nested_table.md +3 -1
- data/app/pb_kits/playbook/pb_table/docs/_table_with_collapsible_with_nested_table_rails.md +3 -1
- data/app/pb_kits/playbook/pb_table/styles/_collapsible.scss +1 -1
- data/app/pb_kits/playbook/pb_text_input/_text_input.tsx +13 -5
- data/app/pb_kits/playbook/pb_text_input/docs/_text_input_sanitize.jsx +94 -0
- data/app/pb_kits/playbook/pb_text_input/docs/_text_input_sanitize.md +1 -0
- data/app/pb_kits/playbook/pb_text_input/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_text_input/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_text_input/inputMask.ts +8 -1
- data/dist/chunks/{_typeahead-BY6AFq1l.js → _typeahead-DUI-4yjJ.js} +2 -2
- data/dist/chunks/_weekday_stacked-q9YP0zaF.js +45 -0
- data/dist/chunks/{lib-BGzBzFZX.js → lib-BV_AF_eh.js} +3 -3
- data/dist/chunks/{pb_form_validation-BvNy9Bd6.js → pb_form_validation-nsvkJU2J.js} +1 -1
- data/dist/chunks/vendor.js +1 -1
- data/dist/playbook-doc.js +19 -1
- data/dist/playbook-rails-react-bindings.js +1 -1
- data/dist/playbook-rails.js +1 -1
- data/dist/playbook.css +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +11 -6
- data/dist/chunks/_weekday_stacked-BwWArBYi.js +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6365ffa349a3400e9838c6825d30fea0a806ea9e2cef468b45911071fe84fd2f
|
4
|
+
data.tar.gz: 2f491f5d69a296241312690575ccf94a08b985e67595ce116ec00e63081c78a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1dda3b47457cd1a0fa42f75c445b061f0a63a69a512811166ac3ff0458a31375a4bbe563259cddcb64f0082de48cc8f22eecaa49d8842b400caa101b92c3d0b0
|
7
|
+
data.tar.gz: 78c8e1619dba55b47099e415283da83f47bd4b8cbc6740f16c83e4a7a6df0070e806e8b98b5ade9c51f1fb839b46681bfe15fd7f148b623c6d88eec1190c05a6
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
import React, { useState } from 'react'
|
1
|
+
import React from 'react'
|
3
2
|
import classnames from 'classnames'
|
4
3
|
import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
|
5
4
|
import { globalProps } from '../utilities/globalProps'
|
@@ -7,16 +6,19 @@ import { globalProps } from '../utilities/globalProps'
|
|
7
6
|
import Button from '../pb_button/_button'
|
8
7
|
import Tooltip from '../pb_tooltip/_tooltip'
|
9
8
|
|
9
|
+
import usePBCopy from './usePBCopy'
|
10
|
+
|
10
11
|
type CopyButtonProps = {
|
11
|
-
aria?: { [key: string]: string }
|
12
|
-
className?: string
|
13
|
-
data?: { [key: string]: string }
|
14
|
-
id?: string
|
15
|
-
from?: string
|
16
|
-
text?: string
|
17
|
-
tooltipPlacement?:
|
18
|
-
tooltipText?: string
|
19
|
-
value?: string
|
12
|
+
aria?: { [key: string]: string }
|
13
|
+
className?: string
|
14
|
+
data?: { [key: string]: string }
|
15
|
+
id?: string
|
16
|
+
from?: string
|
17
|
+
text?: string
|
18
|
+
tooltipPlacement?: 'top' | 'right' | 'bottom' | 'left'
|
19
|
+
tooltipText?: string
|
20
|
+
value?: string
|
21
|
+
timeout?: number
|
20
22
|
}
|
21
23
|
|
22
24
|
const CopyButton = (props: CopyButtonProps) => {
|
@@ -27,62 +29,34 @@ const CopyButton = (props: CopyButtonProps) => {
|
|
27
29
|
from = '',
|
28
30
|
id,
|
29
31
|
text= 'Copy',
|
32
|
+
timeout = 1000,
|
30
33
|
tooltipPlacement= 'bottom',
|
31
34
|
tooltipText = 'Copied!',
|
32
35
|
value = '',
|
33
36
|
} = props
|
34
37
|
|
35
|
-
const [copied,
|
38
|
+
const [copied, copy] = usePBCopy({ value, from, timeout })
|
36
39
|
|
37
40
|
const ariaProps = buildAriaProps(aria)
|
38
41
|
const dataProps = buildDataProps(data)
|
39
42
|
const classes = classnames(buildCss('pb_copy_button_kit'), globalProps(props), className)
|
40
43
|
|
41
|
-
const copy = () => {
|
42
|
-
if (!from && !value) {
|
43
|
-
return
|
44
|
-
}
|
45
|
-
|
46
|
-
if (value) {
|
47
|
-
navigator.clipboard.writeText(value)
|
48
|
-
} else if (from) {
|
49
|
-
const copyElement = document.getElementById(from);
|
50
|
-
let copyText = copyElement?.innerText
|
51
|
-
|
52
|
-
if (copyElement instanceof HTMLTextAreaElement || copyElement instanceof HTMLInputElement) {
|
53
|
-
copyText = copyElement.value;
|
54
|
-
}
|
55
|
-
|
56
|
-
if (copyText) {
|
57
|
-
navigator.clipboard.writeText(copyText)
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
|
-
setCopied(true)
|
62
|
-
|
63
|
-
setTimeout(() => {
|
64
|
-
setCopied(false)
|
65
|
-
}, 1000);
|
66
|
-
}
|
67
|
-
|
68
44
|
return (
|
69
|
-
<div
|
70
|
-
{...ariaProps}
|
45
|
+
<div {...ariaProps}
|
71
46
|
{...dataProps}
|
72
47
|
className={classes}
|
73
48
|
id={id}
|
74
49
|
>
|
75
|
-
<Tooltip
|
50
|
+
<Tooltip
|
76
51
|
forceOpenTooltip={copied}
|
77
52
|
placement={tooltipPlacement}
|
78
53
|
showTooltip={false}
|
79
54
|
text={tooltipText}
|
80
55
|
>
|
81
|
-
<Button
|
82
|
-
icon='copy'
|
56
|
+
<Button icon="copy"
|
83
57
|
onClick={copy}
|
84
58
|
>
|
85
|
-
{
|
59
|
+
{text}
|
86
60
|
</Button>
|
87
61
|
</Tooltip>
|
88
62
|
</div>
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import React, { useEffect, useState } from 'react'
|
2
|
+
import usePBCopy from '../../pb_copy_button/usePBCopy'
|
3
|
+
import Body from '../../pb_body/_body'
|
4
|
+
import Textarea from '../../pb_textarea/_textarea'
|
5
|
+
import Tooltip from '../../pb_tooltip/_tooltip'
|
6
|
+
|
7
|
+
const CopyButtonHook = ({...props}) => {
|
8
|
+
// This is how you can use the copy button hook to copy text to the clipboard
|
9
|
+
// eslint-disable-next-line no-unused-vars
|
10
|
+
const [copied, copyToClipboard] = usePBCopy({ from: 'hookbody' })
|
11
|
+
// I added a tooltip so it looks better in the ui
|
12
|
+
const [showTooltip, setShowTooltip] = useState(false)
|
13
|
+
|
14
|
+
const handleCopy = () => {
|
15
|
+
copyToClipboard()
|
16
|
+
setShowTooltip(true)
|
17
|
+
setTimeout(() => setShowTooltip(false), 1500)
|
18
|
+
}
|
19
|
+
|
20
|
+
useEffect(() => {
|
21
|
+
const el = document.getElementById('hookbody')
|
22
|
+
if (!el) return
|
23
|
+
|
24
|
+
el.addEventListener('click', handleCopy)
|
25
|
+
return () => {
|
26
|
+
el.removeEventListener('click', handleCopy)
|
27
|
+
}
|
28
|
+
}, [copyToClipboard])
|
29
|
+
|
30
|
+
return (
|
31
|
+
<div>
|
32
|
+
<Tooltip
|
33
|
+
delay={{ close: 1000 }}
|
34
|
+
forceOpenTooltip={showTooltip}
|
35
|
+
placement="top"
|
36
|
+
showTooltip={false}
|
37
|
+
text="Copied!"
|
38
|
+
>
|
39
|
+
<Body
|
40
|
+
cursor="pointer"
|
41
|
+
id="hookbody"
|
42
|
+
text="I'm a custom copy hook! Click this body to copy this text!"
|
43
|
+
/>
|
44
|
+
</Tooltip>
|
45
|
+
|
46
|
+
<Textarea
|
47
|
+
{...props}
|
48
|
+
placeholder="Paste here"
|
49
|
+
/>
|
50
|
+
</div>
|
51
|
+
)
|
52
|
+
}
|
53
|
+
|
54
|
+
export default CopyButtonHook
|
@@ -0,0 +1,3 @@
|
|
1
|
+
We provide a `usePBCopy` hook that you can import to your project. This hook will return a function that you can call to copy the text to the clipboard.
|
2
|
+
|
3
|
+
`usePBCopy({ from: 'your_id' })` will grab the `innerText` from `your_id` element, or `value` if it is an input element.
|
@@ -1,2 +1,3 @@
|
|
1
1
|
export { default as CopyButtonDefault } from './_copy_button_default.jsx'
|
2
|
-
export { default as CopyButtonFrom } from './_copy_button_from.jsx'
|
2
|
+
export { default as CopyButtonFrom } from './_copy_button_from.jsx'
|
3
|
+
export { default as CopyButtonHook } from './_copy_button_hook.jsx'
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import { useState, useRef, useEffect } from 'react'
|
2
|
+
|
3
|
+
type UsePBCopyProps = {
|
4
|
+
value?: string
|
5
|
+
from?: string
|
6
|
+
timeout?: number
|
7
|
+
}
|
8
|
+
|
9
|
+
export default function usePBCopy({
|
10
|
+
value = '',
|
11
|
+
from = '',
|
12
|
+
timeout = 0,
|
13
|
+
}: UsePBCopyProps) {
|
14
|
+
const [copied, setCopied] = useState(false)
|
15
|
+
const timerRef = useRef<number>()
|
16
|
+
|
17
|
+
const copy = () => {
|
18
|
+
if (!value && !from) return
|
19
|
+
|
20
|
+
if (value) {
|
21
|
+
navigator.clipboard.writeText(value)
|
22
|
+
} else {
|
23
|
+
const el = document.getElementById(from)
|
24
|
+
let text = el?.innerText
|
25
|
+
if (el instanceof HTMLTextAreaElement || el instanceof HTMLInputElement) {
|
26
|
+
text = el.value
|
27
|
+
}
|
28
|
+
if (text) navigator.clipboard.writeText(text)
|
29
|
+
}
|
30
|
+
|
31
|
+
setCopied(true)
|
32
|
+
window.clearTimeout(timerRef.current)
|
33
|
+
timerRef.current = window.setTimeout(() => {
|
34
|
+
setCopied(false)
|
35
|
+
}, timeout)
|
36
|
+
}
|
37
|
+
|
38
|
+
useEffect(() => {
|
39
|
+
return () => {
|
40
|
+
window.clearTimeout(timerRef.current)
|
41
|
+
}
|
42
|
+
}, [])
|
43
|
+
|
44
|
+
return [copied, copy] as const
|
45
|
+
}
|
@@ -97,7 +97,7 @@
|
|
97
97
|
}
|
98
98
|
}
|
99
99
|
|
100
|
-
& > [class^=pb_phone_number_input]:not(:first-child) {
|
100
|
+
& > [class^=pb_phone_number_input]:not(:first-child), [class^=pb_passphrase]:not(:first-child) {
|
101
101
|
.text_input_wrapper input, [class^=pb_text_input_kit] .text_input_wrapper .text_input {
|
102
102
|
border-bottom-left-radius: 0;
|
103
103
|
border-top-left-radius: 0;
|
@@ -243,4 +243,8 @@
|
|
243
243
|
padding-left: calc(var(--iti-flag-width) + 1px);
|
244
244
|
}
|
245
245
|
}
|
246
|
+
|
247
|
+
&:has(> [class^="pb_select"]):has(> .pb_passphrase) [class^="pb_select"] {
|
248
|
+
align-self: baseline;
|
249
|
+
}
|
246
250
|
}
|
@@ -1,12 +1,16 @@
|
|
1
|
-
import React from 'react'
|
1
|
+
import React, {useState} from 'react'
|
2
2
|
|
3
3
|
import FormGroup from '../_form_group'
|
4
4
|
import PhoneNumberInput from '../../pb_phone_number_input/_phone_number_input'
|
5
5
|
import Select from '../../pb_select/_select'
|
6
6
|
import TextInput from '../../pb_text_input/_text_input'
|
7
7
|
import Flex from '../../pb_flex/_flex'
|
8
|
+
import Passphrase from '../../pb_passphrase/_passphrase'
|
8
9
|
|
9
10
|
const FormGroupSelect = (props) => {
|
11
|
+
const [input, setInput] = useState("");
|
12
|
+
const handleChange = (e) => setInput(e.target.value);
|
13
|
+
|
10
14
|
const options = [
|
11
15
|
{ value: 'Country' },
|
12
16
|
{ value: 'Pop' },
|
@@ -63,6 +67,20 @@ const FormGroupSelect = (props) => {
|
|
63
67
|
{...props}
|
64
68
|
/>
|
65
69
|
</FormGroup>
|
70
|
+
<FormGroup>
|
71
|
+
<Select
|
72
|
+
blankSelection="Phone"
|
73
|
+
options={phoneOptions}
|
74
|
+
{...props}
|
75
|
+
/>
|
76
|
+
<Passphrase
|
77
|
+
id="my-passphrase"
|
78
|
+
label=""
|
79
|
+
onChange={handleChange}
|
80
|
+
value={input}
|
81
|
+
{...props}
|
82
|
+
/>
|
83
|
+
</FormGroup>
|
66
84
|
</Flex>
|
67
85
|
)
|
68
86
|
}
|
@@ -84,8 +84,8 @@ const Table = (props: TableProps): React.ReactElement => {
|
|
84
84
|
'single-line': singleLine,
|
85
85
|
'no-hover': disableHover,
|
86
86
|
'sticky-header': sticky,
|
87
|
-
'sticky-left-column': stickyLeftColumn,
|
88
|
-
'sticky-right-column': stickyRightColumn,
|
87
|
+
'sticky-left-column': stickyLeftColumn.length,
|
88
|
+
'sticky-right-column': stickyRightColumn.length,
|
89
89
|
'striped': striped,
|
90
90
|
'header-borderless': headerStyle === 'borderless',
|
91
91
|
'header-floating': headerStyle === 'floating',
|
@@ -1,3 +1,5 @@
|
|
1
1
|
The `collapsibleContent` can display any content, including nested Table Rows.
|
2
2
|
|
3
|
-
Additionally, the `collapsibleSideHighlight` can also be removed by setting it to false if needed. This prop is set to true by default.
|
3
|
+
Additionally, the `collapsibleSideHighlight` can also be removed by setting it to false if needed. This prop is set to true by default.
|
4
|
+
|
5
|
+
**NOTE**: We advise against using the `disableHover` Table prop when nesting Table Rows within a Table.
|
@@ -1,3 +1,5 @@
|
|
1
1
|
The `collapsible_content` can display any content, including nested Table Rows.
|
2
2
|
|
3
|
-
Additionally, the `collapsible_side_highlight` can also be removed by setting it to false if needed. This prop is set to true by default.
|
3
|
+
Additionally, the `collapsible_side_highlight` can also be removed by setting it to false if needed. This prop is set to true by default.
|
4
|
+
|
5
|
+
**NOTE**: We advise against using the `disable_hover` Table prop when nesting Table Rows within a Table.
|
@@ -1 +1,3 @@
|
|
1
|
-
The `collapsible_content` can also be used to display nested Tables within each Row.
|
1
|
+
The `collapsible_content` can also be used to display nested Tables within each Row.
|
2
|
+
|
3
|
+
**NOTE**: We advise against using the `disable_hover` Table prop when nesting Tables within a Table.
|
@@ -25,7 +25,7 @@ type TextInputProps = {
|
|
25
25
|
name: string,
|
26
26
|
label: string,
|
27
27
|
mask?: 'currency' | 'zipCode' | 'postalCode' | 'ssn',
|
28
|
-
onChange: (e: React.FormEvent<HTMLInputElement
|
28
|
+
onChange: (e: React.FormEvent<HTMLInputElement>, sanitizedValue?: string) => void,
|
29
29
|
placeholder: string,
|
30
30
|
required?: boolean,
|
31
31
|
type: string,
|
@@ -102,10 +102,16 @@ const TextInput = (props: TextInputProps, ref: React.LegacyRef<HTMLInputElement>
|
|
102
102
|
|
103
103
|
let cursorPosition = e.target.selectionStart;
|
104
104
|
const isAtEnd = cursorPosition === inputValue.length;
|
105
|
-
|
105
|
+
|
106
106
|
const formattedValue = INPUTMASKS[mask].format(inputValue)
|
107
|
+
|
108
|
+
let sanitizedValue = formattedValue;
|
109
|
+
if (INPUTMASKS[mask].sanitize) {
|
110
|
+
sanitizedValue = INPUTMASKS[mask].sanitize(formattedValue)
|
111
|
+
}
|
112
|
+
|
107
113
|
e.target.value = formattedValue
|
108
|
-
|
114
|
+
|
109
115
|
// Keep cursor position
|
110
116
|
if (!isAtEnd) {
|
111
117
|
// Account for extra characters (e.g., commas added/removed in currency)
|
@@ -116,9 +122,11 @@ const TextInput = (props: TextInputProps, ref: React.LegacyRef<HTMLInputElement>
|
|
116
122
|
}
|
117
123
|
e.target.selectionStart = e.target.selectionEnd = cursorPosition
|
118
124
|
}
|
125
|
+
|
126
|
+
onChange(e, sanitizedValue);
|
127
|
+
} else {
|
128
|
+
onChange(e)
|
119
129
|
}
|
120
|
-
|
121
|
-
onChange(e)
|
122
130
|
}
|
123
131
|
|
124
132
|
const childInput = children ? children.type === "input" : undefined
|
@@ -0,0 +1,94 @@
|
|
1
|
+
import React, { useState } from 'react'
|
2
|
+
|
3
|
+
import TextInput from '../../pb_text_input/_text_input'
|
4
|
+
|
5
|
+
const TextInputSanitize = (props) => {
|
6
|
+
const ref = React.createRef()
|
7
|
+
|
8
|
+
const [currency, setCurrency] = useState('')
|
9
|
+
const [sanitizedCurrency, setSanitizedCurrency] = useState('')
|
10
|
+
const handleOnChangeSanitizeCurrency = ({ target }, sanitizedValue) => {
|
11
|
+
setCurrency(target.value)
|
12
|
+
setSanitizedCurrency(sanitizedValue);
|
13
|
+
}
|
14
|
+
|
15
|
+
const [creditCard, setCreditCard] = useState('')
|
16
|
+
const [sanitizedCreditCard, setSanitizedCreditCard] = useState('')
|
17
|
+
const handleOnChangeSanitizeCC = ({ target }, sanitizedValue) => {
|
18
|
+
setCreditCard(target.value)
|
19
|
+
setSanitizedCreditCard(sanitizedValue);
|
20
|
+
}
|
21
|
+
|
22
|
+
const [ssn, setSSN] = useState('')
|
23
|
+
const [sanitizedSSN, setSanitizedSSN] = useState('')
|
24
|
+
const handleOnChangeSanitizeSSN = ({ target }, sanitizedValue) => {
|
25
|
+
setSSN(target.value)
|
26
|
+
setSanitizedSSN(sanitizedValue);
|
27
|
+
}
|
28
|
+
|
29
|
+
return (
|
30
|
+
<div>
|
31
|
+
<TextInput
|
32
|
+
label="Currency"
|
33
|
+
mask="currency"
|
34
|
+
onChange={handleOnChangeSanitizeCurrency}
|
35
|
+
placeholder="Enter Amount"
|
36
|
+
ref={ref}
|
37
|
+
value={currency}
|
38
|
+
{...props}
|
39
|
+
/>
|
40
|
+
|
41
|
+
{currency !== "" && (
|
42
|
+
<React.Fragment>{`The masked value is: ${currency}`}</React.Fragment>
|
43
|
+
)}
|
44
|
+
<br />
|
45
|
+
{sanitizedCurrency !== "" && (
|
46
|
+
<React.Fragment>{`The sanitized value is: ${sanitizedCurrency}`}</React.Fragment>
|
47
|
+
)}
|
48
|
+
|
49
|
+
<br />
|
50
|
+
<br />
|
51
|
+
|
52
|
+
<TextInput
|
53
|
+
label="Credit Card"
|
54
|
+
mask="creditCard"
|
55
|
+
onChange={handleOnChangeSanitizeCC}
|
56
|
+
placeholder="Enter Card"
|
57
|
+
ref={ref}
|
58
|
+
value={creditCard}
|
59
|
+
{...props}
|
60
|
+
/>
|
61
|
+
|
62
|
+
{creditCard !== "" && (
|
63
|
+
<React.Fragment>{`The masked value is: ${creditCard}`}</React.Fragment>
|
64
|
+
)}
|
65
|
+
<br />
|
66
|
+
{sanitizedCreditCard !== "" && (
|
67
|
+
<React.Fragment>{`The sanitized value is: ${sanitizedCreditCard}`}</React.Fragment>
|
68
|
+
)}
|
69
|
+
|
70
|
+
<br />
|
71
|
+
<br />
|
72
|
+
|
73
|
+
<TextInput
|
74
|
+
label="SSN"
|
75
|
+
mask="ssn"
|
76
|
+
onChange={handleOnChangeSanitizeSSN}
|
77
|
+
placeholder="Enter Amount"
|
78
|
+
ref={ref}
|
79
|
+
value={ssn}
|
80
|
+
{...props}
|
81
|
+
/>
|
82
|
+
|
83
|
+
{ssn !== "" && (
|
84
|
+
<React.Fragment>{`The masked value is: ${ssn}`}</React.Fragment>
|
85
|
+
)}
|
86
|
+
<br />
|
87
|
+
{sanitizedSSN !== "" && (
|
88
|
+
<React.Fragment>{`The sanitized value is: ${sanitizedSSN}`}</React.Fragment>
|
89
|
+
)}
|
90
|
+
</div>
|
91
|
+
)
|
92
|
+
}
|
93
|
+
|
94
|
+
export default TextInputSanitize
|
@@ -0,0 +1 @@
|
|
1
|
+
When utilizing the Mask prop, you can retrieve the sanitized value of your input through an event handler that targets `sanitizedValue`.
|
@@ -6,3 +6,4 @@ export { default as TextInputAddOn } from './_text_input_add_on.jsx'
|
|
6
6
|
export { default as TextInputInline } from './_text_input_inline.jsx'
|
7
7
|
export { default as TextInputNoLabel } from './_text_input_no_label.jsx'
|
8
8
|
export { default as TextInputMask } from './_text_input_mask.jsx'
|
9
|
+
export { default as TextInputSanitize } from './_text_input_sanitize.jsx'
|
@@ -3,6 +3,7 @@ type InputMask = {
|
|
3
3
|
formatDefaultValue: (value: string) => string
|
4
4
|
pattern: string
|
5
5
|
placeholder: string
|
6
|
+
sanitize?: (value: string) => string;
|
6
7
|
}
|
7
8
|
|
8
9
|
type InputMaskDictionary = {
|
@@ -73,35 +74,41 @@ export const INPUTMASKS: InputMaskDictionary = {
|
|
73
74
|
// eslint-disable-next-line no-useless-escape
|
74
75
|
pattern: '^\\$\\d{1,3}(?:,\\d{3})*(?:\\.\\d{2})?$',
|
75
76
|
placeholder: '$0.00',
|
77
|
+
sanitize: (value: string) => value.replace(/[$,]/g, ''),
|
76
78
|
},
|
77
79
|
zipCode: {
|
78
80
|
format: formatBasicPostal,
|
79
81
|
formatDefaultValue: formatBasicPostal,
|
80
82
|
pattern: '\\d{5}',
|
81
83
|
placeholder: '12345',
|
84
|
+
sanitize: (value: string) => value,
|
82
85
|
},
|
83
86
|
postalCode: {
|
84
87
|
format: formatExtendedPostal,
|
85
88
|
formatDefaultValue: formatExtendedPostal,
|
86
89
|
pattern: '\\d{5}-\\d{4}',
|
87
90
|
placeholder: '12345-6789',
|
91
|
+
sanitize: (value: string) => value.replace(/-/g, ''),
|
88
92
|
},
|
89
93
|
ssn: {
|
90
94
|
format: formatSSN,
|
91
95
|
formatDefaultValue: formatSSN,
|
92
96
|
pattern: '\\d{3}-\\d{2}-\\d{4}',
|
93
97
|
placeholder: '123-45-6789',
|
98
|
+
sanitize: (value: string) => value.replace(/-/g, ''),
|
94
99
|
},
|
95
100
|
creditCard: {
|
96
101
|
format: formatCreditCard,
|
97
102
|
formatDefaultValue: formatCreditCard,
|
98
103
|
pattern: '\\d{4} \\d{4} \\d{4} \\d{4}',
|
99
104
|
placeholder: '1234 5678 9012 3456',
|
105
|
+
sanitize: (value: string) => value.replace(/\s/g, ''),
|
100
106
|
},
|
101
107
|
cvv: {
|
102
108
|
format: formatCVV,
|
103
109
|
formatDefaultValue: formatCVV,
|
104
110
|
pattern: '\\d{3,4}',
|
105
111
|
placeholder: '123',
|
112
|
+
sanitize: (value: string) => value,
|
106
113
|
},
|
107
|
-
}
|
114
|
+
}
|