@transferwise/components 0.0.0-experimental-2a40639 → 0.0.0-experimental-12d074a
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.
- package/build/button/Button.js +18 -4
- package/build/button/Button.js.map +1 -1
- package/build/button/Button.mjs +18 -4
- package/build/button/Button.mjs.map +1 -1
- package/build/main.css +3 -0
- package/build/styles/button/Button.css +3 -0
- package/build/styles/main.css +3 -0
- package/build/typeahead/Typeahead.js +1 -2
- package/build/typeahead/Typeahead.js.map +1 -1
- package/build/typeahead/Typeahead.mjs +1 -2
- package/build/typeahead/Typeahead.mjs.map +1 -1
- package/build/typeahead/typeaheadInput/TypeaheadInput.js +1 -1
- package/build/typeahead/typeaheadInput/TypeaheadInput.js.map +1 -1
- package/build/typeahead/typeaheadInput/TypeaheadInput.mjs +1 -1
- package/build/typeahead/typeaheadInput/TypeaheadInput.mjs.map +1 -1
- package/build/types/button/Button.d.ts.map +1 -1
- package/build/types/typeahead/Typeahead.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/button/Button.css +3 -0
- package/src/button/Button.less +6 -0
- package/src/button/Button.spec.js +42 -46
- package/src/button/Button.story.tsx +43 -20
- package/src/button/Button.tsx +21 -5
- package/src/button/__snapshots__/Button.spec.js.snap +43 -0
- package/src/main.css +3 -0
- package/src/typeahead/Typeahead.spec.js +6 -0
- package/src/typeahead/Typeahead.story.tsx +12 -9
- package/src/typeahead/Typeahead.tsx +16 -14
- package/src/typeahead/typeaheadInput/TypeaheadInput.spec.js +6 -0
- package/src/typeahead/typeaheadInput/TypeaheadInput.tsx +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeaheadInput.js","sources":["../../../src/typeahead/typeaheadInput/TypeaheadInput.tsx"],"sourcesContent":["/* eslint-disable jsx-a11y/no-autofocus */\n/* eslint-disable jsx-a11y/click-events-have-key-events */\n/* eslint-disable jsx-a11y/no-static-element-interactions */\nimport { clsx } from 'clsx';\nimport { Component, createRef, ReactNode } from 'react';\n\nimport { Input } from '../../inputs/Input';\nimport { TypeaheadOption, TypeaheadProps } from '../Typeahead';\n\nconst DEFAULT_INPUT_MIN_WIDTH = 10;\n\nexport type TypeaheadInputProps<T> = {\n typeaheadId: string;\n value: string;\n selected: readonly TypeaheadOption<T>[];\n dropdownOpen?: boolean;\n autoComplete: string;\n onChange: React.ChangeEventHandler<HTMLInputElement>;\n onKeyDown: React.KeyboardEventHandler<HTMLInputElement>;\n onFocus: () => void;\n onPaste: React.ClipboardEventHandler<HTMLInputElement>;\n renderChip: (chip: TypeaheadOption<T>, index: number) => ReactNode;\n} & Pick<TypeaheadProps<T>, 'id' | 'name' | 'autoFocus' | 'multiple' | 'placeholder' | 'maxHeight'>;\n\ntype TypeaheadInputState = {\n inputWidth: number;\n};\n\nexport default class TypeaheadInput<T> extends Component<\n TypeaheadInputProps<T>,\n TypeaheadInputState\n> {\n inputRef = createRef<HTMLInputElement>();\n sizerRef = createRef<HTMLDivElement>();\n\n constructor(props: TypeaheadInputProps<T>) {\n super(props);\n this.state = {\n inputWidth: DEFAULT_INPUT_MIN_WIDTH,\n };\n }\n\n componentDidMount() {\n const { autoFocus } = this.props;\n if (autoFocus) {\n this.inputRef.current?.focus();\n }\n }\n\n componentDidUpdate(previousProps: TypeaheadInputProps<T>) {\n if (previousProps.value !== this.props.value && this.props.multiple) {\n this.recalculateWidth();\n }\n }\n\n recalculateWidth = () => {\n requestAnimationFrame(() => {\n this.setState({\n inputWidth: Math.max(DEFAULT_INPUT_MIN_WIDTH, this.sizerRef.current?.scrollWidth ?? 0 + 10),\n });\n });\n };\n\n renderInput = () => {\n const {\n typeaheadId,\n autoFocus,\n multiple,\n name,\n dropdownOpen,\n placeholder,\n selected,\n value,\n onChange,\n onKeyDown,\n onFocus,\n onPaste,\n autoComplete,\n } = this.props;\n const { inputWidth } = this.state;\n\n const hasPlaceholder = !multiple || selected.length === 0;\n return (\n <Input\n ref={this.inputRef}\n className={clsx(multiple && 'typeahead__input')}\n name={name}\n id={`input-${typeaheadId}`}\n autoFocus={autoFocus}\n placeholder={hasPlaceholder ? placeholder : ''}\n aria-autocomplete=\"list\"\n aria-expanded={dropdownOpen}\n aria-haspopup=\"listbox\"\n aria-controls={`menu-${typeaheadId}`}\n autoComplete={autoComplete}\n role=\"combobox\"\n value={value}\n style={multiple && selected.length > 0 ? { width: inputWidth } : {}}\n onChange={onChange}\n onKeyDown={onKeyDown}\n onClick={onFocus}\n onFocus={onFocus}\n onPaste={onPaste}\n />\n );\n };\n\n render() {\n const { multiple, selected, value, maxHeight, renderChip } = this.props;\n\n return multiple ? (\n <div\n className=\"form-control typeahead__input-container\"\n style={{ maxHeight }}\n onClick={() => {\n this.inputRef.current?.focus();\n }}\n >\n <div className=\"typeahead__input-wrapper\">\n {selected && selected.map((chip, idx) => renderChip(chip, idx))}\n\n {this.renderInput()}\n <div className=\"typeahead__input-aligner\" />\n </div>\n <div ref={this.sizerRef} className=\"sizer form-control typeahead__input\">\n {value}\n </div>\n </div>\n ) : (\n this.renderInput()\n );\n }\n}\n"],"names":["DEFAULT_INPUT_MIN_WIDTH","TypeaheadInput","Component","inputRef","createRef","sizerRef","constructor","props","state","inputWidth","componentDidMount","autoFocus","current","focus","componentDidUpdate","previousProps","value","multiple","recalculateWidth","requestAnimationFrame","setState","Math","max","scrollWidth","renderInput","typeaheadId","name","dropdownOpen","placeholder","selected","onChange","onKeyDown","onFocus","onPaste","autoComplete","hasPlaceholder","length","_jsx","Input","ref","className","clsx","id","role","style","width","onClick","render","maxHeight","renderChip","_jsxs","children","map","chip","idx"],"mappings":";;;;;;;AAAA;AACA;AACA;AAOA,MAAMA,uBAAuB,GAAG,EAAE,CAAA;AAmBb,MAAAC,cAAkB,SAAQC,eAG9C,CAAA;EACCC,QAAQ,gBAAGC,eAAS,EAAoB,CAAA;EACxCC,QAAQ,gBAAGD,eAAS,EAAkB,CAAA;EAEtCE,WAAAA,CAAYC,KAA6B,EAAA;IACvC,KAAK,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,CAAA;IACzD,oBACEC,cAAA,CAACC,WAAK,EAAA;MACJC,GAAG,EAAE,IAAI,CAACpC,QAAS;AACnBqC,MAAAA,SAAS,EAAEC,SAAI,CAACxB,QAAQ,IAAI,kBAAkB,CAAE;AAChDS,MAAAA,IAAI,EAAEA,IAAK;MACXgB,EAAE,EAAE,CAASjB,MAAAA,EAAAA,WAAW,CAAG,CAAA;AAC3Bd,MAAAA,SAAS,EAAEA,SAAU;AACrBiB,MAAAA,WAAW,EAAEO,cAAc,GAAGP,WAAW,GAAG,EAAG;AAC/C,MAAA,mBAAA,EAAkB,MAAM;AACxB,MAAA,eAAA,EAAeD,YAAa;AAC5B,MAAA,eAAA,EAAc,SAAS;
|
|
1
|
+
{"version":3,"file":"TypeaheadInput.js","sources":["../../../src/typeahead/typeaheadInput/TypeaheadInput.tsx"],"sourcesContent":["/* eslint-disable jsx-a11y/no-autofocus */\n/* eslint-disable jsx-a11y/click-events-have-key-events */\n/* eslint-disable jsx-a11y/no-static-element-interactions */\nimport { clsx } from 'clsx';\nimport { Component, createRef, ReactNode } from 'react';\n\nimport { Input } from '../../inputs/Input';\nimport { TypeaheadOption, TypeaheadProps } from '../Typeahead';\n\nconst DEFAULT_INPUT_MIN_WIDTH = 10;\n\nexport type TypeaheadInputProps<T> = {\n typeaheadId: string;\n value: string;\n selected: readonly TypeaheadOption<T>[];\n dropdownOpen?: boolean;\n autoComplete: string;\n onChange: React.ChangeEventHandler<HTMLInputElement>;\n onKeyDown: React.KeyboardEventHandler<HTMLInputElement>;\n onFocus: () => void;\n onPaste: React.ClipboardEventHandler<HTMLInputElement>;\n renderChip: (chip: TypeaheadOption<T>, index: number) => ReactNode;\n} & Pick<TypeaheadProps<T>, 'id' | 'name' | 'autoFocus' | 'multiple' | 'placeholder' | 'maxHeight'>;\n\ntype TypeaheadInputState = {\n inputWidth: number;\n};\n\nexport default class TypeaheadInput<T> extends Component<\n TypeaheadInputProps<T>,\n TypeaheadInputState\n> {\n inputRef = createRef<HTMLInputElement>();\n sizerRef = createRef<HTMLDivElement>();\n\n constructor(props: TypeaheadInputProps<T>) {\n super(props);\n this.state = {\n inputWidth: DEFAULT_INPUT_MIN_WIDTH,\n };\n }\n\n componentDidMount() {\n const { autoFocus } = this.props;\n if (autoFocus) {\n this.inputRef.current?.focus();\n }\n }\n\n componentDidUpdate(previousProps: TypeaheadInputProps<T>) {\n if (previousProps.value !== this.props.value && this.props.multiple) {\n this.recalculateWidth();\n }\n }\n\n recalculateWidth = () => {\n requestAnimationFrame(() => {\n this.setState({\n inputWidth: Math.max(DEFAULT_INPUT_MIN_WIDTH, this.sizerRef.current?.scrollWidth ?? 0 + 10),\n });\n });\n };\n\n renderInput = () => {\n const {\n typeaheadId,\n autoFocus,\n multiple,\n name,\n dropdownOpen,\n placeholder,\n selected,\n value,\n onChange,\n onKeyDown,\n onFocus,\n onPaste,\n autoComplete,\n } = this.props;\n const { inputWidth } = this.state;\n\n const hasPlaceholder = !multiple || selected.length === 0;\n return (\n <Input\n ref={this.inputRef}\n className={clsx(multiple && 'typeahead__input')}\n name={name}\n id={`input-${typeaheadId}`}\n autoFocus={autoFocus}\n placeholder={hasPlaceholder ? placeholder : ''}\n aria-autocomplete=\"list\"\n aria-expanded={dropdownOpen}\n aria-haspopup=\"listbox\"\n aria-controls={dropdownOpen ? `menu-${typeaheadId}` : undefined}\n autoComplete={autoComplete}\n role=\"combobox\"\n value={value}\n style={multiple && selected.length > 0 ? { width: inputWidth } : {}}\n onChange={onChange}\n onKeyDown={onKeyDown}\n onClick={onFocus}\n onFocus={onFocus}\n onPaste={onPaste}\n />\n );\n };\n\n render() {\n const { multiple, selected, value, maxHeight, renderChip } = this.props;\n\n return multiple ? (\n <div\n className=\"form-control typeahead__input-container\"\n style={{ maxHeight }}\n onClick={() => {\n this.inputRef.current?.focus();\n }}\n >\n <div className=\"typeahead__input-wrapper\">\n {selected && selected.map((chip, idx) => renderChip(chip, idx))}\n\n {this.renderInput()}\n <div className=\"typeahead__input-aligner\" />\n </div>\n <div ref={this.sizerRef} className=\"sizer form-control typeahead__input\">\n {value}\n </div>\n </div>\n ) : (\n this.renderInput()\n );\n }\n}\n"],"names":["DEFAULT_INPUT_MIN_WIDTH","TypeaheadInput","Component","inputRef","createRef","sizerRef","constructor","props","state","inputWidth","componentDidMount","autoFocus","current","focus","componentDidUpdate","previousProps","value","multiple","recalculateWidth","requestAnimationFrame","setState","Math","max","scrollWidth","renderInput","typeaheadId","name","dropdownOpen","placeholder","selected","onChange","onKeyDown","onFocus","onPaste","autoComplete","hasPlaceholder","length","_jsx","Input","ref","className","clsx","id","undefined","role","style","width","onClick","render","maxHeight","renderChip","_jsxs","children","map","chip","idx"],"mappings":";;;;;;;AAAA;AACA;AACA;AAOA,MAAMA,uBAAuB,GAAG,EAAE,CAAA;AAmBb,MAAAC,cAAkB,SAAQC,eAG9C,CAAA;EACCC,QAAQ,gBAAGC,eAAS,EAAoB,CAAA;EACxCC,QAAQ,gBAAGD,eAAS,EAAkB,CAAA;EAEtCE,WAAAA,CAAYC,KAA6B,EAAA;IACvC,KAAK,CAACA,KAAK,CAAC,CAAA;IACZ,IAAI,CAACC,KAAK,GAAG;AACXC,MAAAA,UAAU,EAAET,uBAAAA;KACb,CAAA;AACH,GAAA;AAEAU,EAAAA,iBAAiBA,GAAA;IACf,MAAM;AAAEC,MAAAA,SAAAA;KAAW,GAAG,IAAI,CAACJ,KAAK,CAAA;AAChC,IAAA,IAAII,SAAS,EAAE;AACb,MAAA,IAAI,CAACR,QAAQ,CAACS,OAAO,EAAEC,KAAK,EAAE,CAAA;AAChC,KAAA;AACF,GAAA;EAEAC,kBAAkBA,CAACC,aAAqC,EAAA;AACtD,IAAA,IAAIA,aAAa,CAACC,KAAK,KAAK,IAAI,CAACT,KAAK,CAACS,KAAK,IAAI,IAAI,CAACT,KAAK,CAACU,QAAQ,EAAE;MACnE,IAAI,CAACC,gBAAgB,EAAE,CAAA;AACzB,KAAA;AACF,GAAA;EAEAA,gBAAgB,GAAGA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AClC,QAAS;AAACmC,QAAAA,SAAS,EAAC,qCAAqC;AAAAY,QAAAA,QAAA,EACrEpC,KAAAA;AAAK,OACH,CACP,CAAA;AAAA,KAAK,CAAC,GAEN,IAAI,CAACQ,WAAW,EACjB,CAAA;AACH,GAAA;AACD;;;;"}
|
|
@@ -66,7 +66,7 @@ class TypeaheadInput extends Component {
|
|
|
66
66
|
"aria-autocomplete": "list",
|
|
67
67
|
"aria-expanded": dropdownOpen,
|
|
68
68
|
"aria-haspopup": "listbox",
|
|
69
|
-
"aria-controls": `menu-${typeaheadId}
|
|
69
|
+
"aria-controls": dropdownOpen ? `menu-${typeaheadId}` : undefined,
|
|
70
70
|
autoComplete: autoComplete,
|
|
71
71
|
role: "combobox",
|
|
72
72
|
value: value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeaheadInput.mjs","sources":["../../../src/typeahead/typeaheadInput/TypeaheadInput.tsx"],"sourcesContent":["/* eslint-disable jsx-a11y/no-autofocus */\n/* eslint-disable jsx-a11y/click-events-have-key-events */\n/* eslint-disable jsx-a11y/no-static-element-interactions */\nimport { clsx } from 'clsx';\nimport { Component, createRef, ReactNode } from 'react';\n\nimport { Input } from '../../inputs/Input';\nimport { TypeaheadOption, TypeaheadProps } from '../Typeahead';\n\nconst DEFAULT_INPUT_MIN_WIDTH = 10;\n\nexport type TypeaheadInputProps<T> = {\n typeaheadId: string;\n value: string;\n selected: readonly TypeaheadOption<T>[];\n dropdownOpen?: boolean;\n autoComplete: string;\n onChange: React.ChangeEventHandler<HTMLInputElement>;\n onKeyDown: React.KeyboardEventHandler<HTMLInputElement>;\n onFocus: () => void;\n onPaste: React.ClipboardEventHandler<HTMLInputElement>;\n renderChip: (chip: TypeaheadOption<T>, index: number) => ReactNode;\n} & Pick<TypeaheadProps<T>, 'id' | 'name' | 'autoFocus' | 'multiple' | 'placeholder' | 'maxHeight'>;\n\ntype TypeaheadInputState = {\n inputWidth: number;\n};\n\nexport default class TypeaheadInput<T> extends Component<\n TypeaheadInputProps<T>,\n TypeaheadInputState\n> {\n inputRef = createRef<HTMLInputElement>();\n sizerRef = createRef<HTMLDivElement>();\n\n constructor(props: TypeaheadInputProps<T>) {\n super(props);\n this.state = {\n inputWidth: DEFAULT_INPUT_MIN_WIDTH,\n };\n }\n\n componentDidMount() {\n const { autoFocus } = this.props;\n if (autoFocus) {\n this.inputRef.current?.focus();\n }\n }\n\n componentDidUpdate(previousProps: TypeaheadInputProps<T>) {\n if (previousProps.value !== this.props.value && this.props.multiple) {\n this.recalculateWidth();\n }\n }\n\n recalculateWidth = () => {\n requestAnimationFrame(() => {\n this.setState({\n inputWidth: Math.max(DEFAULT_INPUT_MIN_WIDTH, this.sizerRef.current?.scrollWidth ?? 0 + 10),\n });\n });\n };\n\n renderInput = () => {\n const {\n typeaheadId,\n autoFocus,\n multiple,\n name,\n dropdownOpen,\n placeholder,\n selected,\n value,\n onChange,\n onKeyDown,\n onFocus,\n onPaste,\n autoComplete,\n } = this.props;\n const { inputWidth } = this.state;\n\n const hasPlaceholder = !multiple || selected.length === 0;\n return (\n <Input\n ref={this.inputRef}\n className={clsx(multiple && 'typeahead__input')}\n name={name}\n id={`input-${typeaheadId}`}\n autoFocus={autoFocus}\n placeholder={hasPlaceholder ? placeholder : ''}\n aria-autocomplete=\"list\"\n aria-expanded={dropdownOpen}\n aria-haspopup=\"listbox\"\n aria-controls={`menu-${typeaheadId}`}\n autoComplete={autoComplete}\n role=\"combobox\"\n value={value}\n style={multiple && selected.length > 0 ? { width: inputWidth } : {}}\n onChange={onChange}\n onKeyDown={onKeyDown}\n onClick={onFocus}\n onFocus={onFocus}\n onPaste={onPaste}\n />\n );\n };\n\n render() {\n const { multiple, selected, value, maxHeight, renderChip } = this.props;\n\n return multiple ? (\n <div\n className=\"form-control typeahead__input-container\"\n style={{ maxHeight }}\n onClick={() => {\n this.inputRef.current?.focus();\n }}\n >\n <div className=\"typeahead__input-wrapper\">\n {selected && selected.map((chip, idx) => renderChip(chip, idx))}\n\n {this.renderInput()}\n <div className=\"typeahead__input-aligner\" />\n </div>\n <div ref={this.sizerRef} className=\"sizer form-control typeahead__input\">\n {value}\n </div>\n </div>\n ) : (\n this.renderInput()\n );\n }\n}\n"],"names":["DEFAULT_INPUT_MIN_WIDTH","TypeaheadInput","Component","inputRef","createRef","sizerRef","constructor","props","state","inputWidth","componentDidMount","autoFocus","current","focus","componentDidUpdate","previousProps","value","multiple","recalculateWidth","requestAnimationFrame","setState","Math","max","scrollWidth","renderInput","typeaheadId","name","dropdownOpen","placeholder","selected","onChange","onKeyDown","onFocus","onPaste","autoComplete","hasPlaceholder","length","_jsx","Input","ref","className","clsx","id","role","style","width","onClick","render","maxHeight","renderChip","_jsxs","children","map","chip","idx"],"mappings":";;;;;AAAA;AACA;AACA;AAOA,MAAMA,uBAAuB,GAAG,EAAE,CAAA;AAmBb,MAAAC,cAAkB,SAAQC,SAG9C,CAAA;EACCC,QAAQ,gBAAGC,SAAS,EAAoB,CAAA;EACxCC,QAAQ,gBAAGD,SAAS,EAAkB,CAAA;EAEtCE,WAAAA,CAAYC,KAA6B,EAAA;IACvC,KAAK,CAACA,KAAK,CAAC,CAAA;IACZ,IAAI,CAACC,KAAK,GAAG;AACXC,MAAAA,UAAU,EAAET,uBAAAA;KACb,CAAA;AACH,GAAA;AAEAU,EAAAA,iBAAiBA,GAAA;IACf,MAAM;AAAEC,MAAAA,SAAAA;KAAW,GAAG,IAAI,CAACJ,KAAK,CAAA;AAChC,IAAA,IAAII,SAAS,EAAE;AACb,MAAA,IAAI,CAACR,QAAQ,CAACS,OAAO,EAAEC,KAAK,EAAE,CAAA;AAChC,KAAA;AACF,GAAA;EAEAC,kBAAkBA,CAACC,aAAqC,EAAA;AACtD,IAAA,IAAIA,aAAa,CAACC,KAAK,KAAK,IAAI,CAACT,KAAK,CAACS,KAAK,IAAI,IAAI,CAACT,KAAK,CAACU,QAAQ,EAAE;MACnE,IAAI,CAACC,gBAAgB,EAAE,CAAA;AACzB,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Content":["/* eslint-disable jsx-a11y/no-autofocus */\n/* eslint-disable jsx-a11y/click-events-have-key-events */\n/* eslint-disable jsx-a11y/no-static-element-interactions */\nimport { clsx } from 'clsx';\nimport { Component, createRef, ReactNode } from 'react';\n\nimport { Input } from '../../inputs/Input';\nimport { TypeaheadOption, TypeaheadProps } from '../Typeahead';\n\nconst DEFAULT_INPUT_MIN_WIDTH = 10;\n\nexport type TypeaheadInputProps<T> = {\n typeaheadId: string;\n value: string;\n selected: readonly TypeaheadOption<T>[];\n dropdownOpen?: boolean;\n autoComplete: string;\n onChange: React.ChangeEventHandler<HTMLInputElement>;\n onKeyDown: React.KeyboardEventHandler<HTMLInputElement>;\n onFocus: () => void;\n onPaste: React.ClipboardEventHandler<HTMLInputElement>;\n renderChip: (chip: TypeaheadOption<T>, index: number) => ReactNode;\n} & Pick<TypeaheadProps<T>, 'id' | 'name' | 'autoFocus' | 'multiple' | 'placeholder' | 'maxHeight'>;\n\ntype TypeaheadInputState = {\n inputWidth: number;\n};\n\nexport default class TypeaheadInput<T> extends Component<\n TypeaheadInputProps<T>,\n TypeaheadInputState\n> {\n inputRef = createRef<HTMLInputElement>();\n sizerRef = createRef<HTMLDivElement>();\n\n constructor(props: TypeaheadInputProps<T>) {\n super(props);\n this.state = {\n inputWidth: DEFAULT_INPUT_MIN_WIDTH,\n };\n }\n\n componentDidMount() {\n const { autoFocus } = this.props;\n if (autoFocus) {\n this.inputRef.current?.focus();\n }\n }\n\n componentDidUpdate(previousProps: TypeaheadInputProps<T>) {\n if (previousProps.value !== this.props.value && this.props.multiple) {\n this.recalculateWidth();\n }\n }\n\n recalculateWidth = () => {\n requestAnimationFrame(() => {\n this.setState({\n inputWidth: Math.max(DEFAULT_INPUT_MIN_WIDTH, this.sizerRef.current?.scrollWidth ?? 0 + 10),\n });\n });\n };\n\n renderInput = () => {\n const {\n typeaheadId,\n autoFocus,\n multiple,\n name,\n dropdownOpen,\n placeholder,\n selected,\n value,\n onChange,\n onKeyDown,\n onFocus,\n onPaste,\n autoComplete,\n } = this.props;\n const { inputWidth } = this.state;\n\n const hasPlaceholder = !multiple || selected.length === 0;\n return (\n <Input\n ref={this.inputRef}\n className={clsx(multiple && 'typeahead__input')}\n name={name}\n id={`input-${typeaheadId}`}\n autoFocus={autoFocus}\n placeholder={hasPlaceholder ? placeholder : ''}\n aria-autocomplete=\"list\"\n aria-expanded={dropdownOpen}\n aria-haspopup=\"listbox\"\n aria-controls={dropdownOpen ? `menu-${typeaheadId}` : undefined}\n autoComplete={autoComplete}\n role=\"combobox\"\n value={value}\n style={multiple && selected.length > 0 ? { width: inputWidth } : {}}\n onChange={onChange}\n onKeyDown={onKeyDown}\n onClick={onFocus}\n onFocus={onFocus}\n onPaste={onPaste}\n />\n );\n };\n\n render() {\n const { multiple, selected, value, maxHeight, renderChip } = this.props;\n\n return multiple ? (\n <div\n className=\"form-control typeahead__input-container\"\n style={{ maxHeight }}\n onClick={() => {\n this.inputRef.current?.focus();\n }}\n >\n <div className=\"typeahead__input-wrapper\">\n {selected && selected.map((chip, idx) => renderChip(chip, idx))}\n\n {this.renderInput()}\n <div className=\"typeahead__input-aligner\" />\n </div>\n <div ref={this.sizerRef} className=\"sizer form-control typeahead__input\">\n {value}\n </div>\n </div>\n ) : (\n this.renderInput()\n );\n }\n}\n"],"names":["DEFAULT_INPUT_MIN_WIDTH","TypeaheadInput","Component","inputRef","createRef","sizerRef","constructor","props","state","inputWidth","componentDidMount","autoFocus","current","focus","componentDidUpdate","previousProps","value","multiple","recalculateWidth","requestAnimationFrame","setState","Math","max","scrollWidth","renderInput","typeaheadId","name","dropdownOpen","placeholder","selected","onChange","onKeyDown","onFocus","onPaste","autoComplete","hasPlaceholder","length","_jsx","Input","ref","className","clsx","id","undefined","role","style","width","onClick","render","maxHeight","renderChip","_jsxs","children","map","chip","idx"],"mappings":";;;;;AAAA;AACA;AACA;AAOA,MAAMA,uBAAuB,GAAG,EAAE,CAAA;AAmBb,MAAAC,cAAkB,SAAQC,SAG9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C;IACnC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC;CACtD;wBAmdoF,CAAC,CAAC,EACrF,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,KACrB,KAAK,CAAC,YAAY;AAFvB,wBAEwB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transferwise/components",
|
|
3
|
-
"version": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-12d074a",
|
|
4
4
|
"description": "Neptune React components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -92,13 +92,13 @@
|
|
|
92
92
|
"rollup": "^4.18.1",
|
|
93
93
|
"rollup-preserve-directives": "^1.1.1",
|
|
94
94
|
"storybook": "^8.2.2",
|
|
95
|
-
"@transferwise/
|
|
96
|
-
"@
|
|
97
|
-
"@
|
|
95
|
+
"@transferwise/less-config": "3.1.0",
|
|
96
|
+
"@transferwise/neptune-css": "0.0.0-experimental-12d074a",
|
|
97
|
+
"@wise/components-theming": "1.6.0"
|
|
98
98
|
},
|
|
99
99
|
"peerDependencies": {
|
|
100
100
|
"@transferwise/icons": "^3.7.0",
|
|
101
|
-
"@transferwise/neptune-css": "
|
|
101
|
+
"@transferwise/neptune-css": "0.0.0-experimental-12d074a",
|
|
102
102
|
"@wise/art": "^2.7.0",
|
|
103
103
|
"@wise/components-theming": "^1.0.0",
|
|
104
104
|
"react": ">=18",
|
package/src/button/Button.css
CHANGED
package/src/button/Button.less
CHANGED
|
@@ -12,81 +12,77 @@ const { PRIMARY, SECONDARY, TERTIARY } = Priority;
|
|
|
12
12
|
const { SMALL, MEDIUM, LARGE } = Size;
|
|
13
13
|
|
|
14
14
|
describe('Button', () => {
|
|
15
|
-
const
|
|
15
|
+
const originalWarn = console.warn;
|
|
16
|
+
let mockedWarn;
|
|
17
|
+
|
|
18
|
+
const defaultProps = {
|
|
16
19
|
onClick: jest.fn(),
|
|
17
20
|
children: 'Send money',
|
|
18
21
|
};
|
|
19
22
|
|
|
20
|
-
const origWarn = console.warn;
|
|
21
|
-
let mockedWarn;
|
|
22
|
-
|
|
23
23
|
beforeAll(() => {
|
|
24
|
-
mockedWarn = jest.fn()
|
|
24
|
+
mockedWarn = jest.fn().mockImplementation((args) => {
|
|
25
|
+
if (typeof args !== 'string' || !args.startsWith('Button has deprecated the')) {
|
|
26
|
+
originalWarn(args);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
25
29
|
console.warn = mockedWarn;
|
|
26
30
|
});
|
|
27
31
|
|
|
28
|
-
|
|
29
|
-
cleanup();
|
|
30
|
-
jest.clearAllMocks();
|
|
31
|
-
});
|
|
32
|
+
beforeEach(jest.clearAllMocks);
|
|
32
33
|
|
|
33
34
|
afterAll(() => {
|
|
34
|
-
console.warn =
|
|
35
|
+
console.warn = originalWarn;
|
|
35
36
|
});
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
render(<Button {...props} />);
|
|
40
|
-
});
|
|
38
|
+
const setup = (overrides = {}) => render(<Button {...defaultProps} {...overrides} />);
|
|
41
39
|
|
|
40
|
+
describe('by default', () => {
|
|
42
41
|
it('renders the text', () => {
|
|
43
|
-
|
|
42
|
+
render(<Button {...defaultProps} />);
|
|
43
|
+
expect(screen.getByText(defaultProps.children)).toBeInTheDocument();
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
it('set `ref` to be true on Button', () => {
|
|
47
47
|
const reference = createRef();
|
|
48
|
-
const props = {
|
|
49
|
-
ref: reference,
|
|
50
|
-
};
|
|
51
48
|
|
|
52
49
|
expect(reference.current).toBeFalsy();
|
|
53
|
-
|
|
54
|
-
render(<Button {...props}>Click me!</Button>);
|
|
55
|
-
|
|
50
|
+
render(<Button ref={reference}>Click me!</Button>);
|
|
56
51
|
expect(reference.current).toBeTruthy();
|
|
57
52
|
});
|
|
58
53
|
|
|
59
54
|
it('is not disabled', () => {
|
|
55
|
+
render(<Button {...defaultProps} />);
|
|
60
56
|
expect(screen.getByRole('button')).toBeEnabled();
|
|
61
57
|
});
|
|
62
58
|
|
|
63
59
|
it('renders a medium button of type accent and priority primary', () => {
|
|
64
|
-
expect(render(<Button {...
|
|
60
|
+
expect(render(<Button {...defaultProps} />).container).toMatchSnapshot();
|
|
65
61
|
});
|
|
66
62
|
|
|
67
63
|
it('renders an anchor tag with button styles of type accent and priority primary', () => {
|
|
68
|
-
expect(render(<Button {...
|
|
64
|
+
expect(render(<Button {...defaultProps} as="a" href="#" />).container).toMatchSnapshot();
|
|
69
65
|
});
|
|
70
66
|
});
|
|
71
67
|
|
|
72
68
|
describe('button attributes', () => {
|
|
73
69
|
it('disables the button if disabled', () => {
|
|
74
|
-
render(<Button {...
|
|
70
|
+
render(<Button {...defaultProps} disabled />);
|
|
75
71
|
expect(screen.getByRole('button')).toBeDisabled();
|
|
76
72
|
});
|
|
77
73
|
|
|
78
74
|
it('sets the htmlType if set', () => {
|
|
79
|
-
render(<Button {...
|
|
75
|
+
render(<Button {...defaultProps} htmlType="submit" />);
|
|
80
76
|
expect(screen.getByRole('button')).toHaveAttribute('type', 'submit');
|
|
81
77
|
});
|
|
82
78
|
|
|
83
79
|
it('passes through custom classes if set', () => {
|
|
84
|
-
render(<Button {...
|
|
80
|
+
render(<Button {...defaultProps} className="catsarethebest" />);
|
|
85
81
|
expect(screen.getByRole('button')).toHaveClass('catsarethebest');
|
|
86
82
|
});
|
|
87
83
|
|
|
88
84
|
it('passes through aria-label if set', () => {
|
|
89
|
-
render(<Button {...
|
|
85
|
+
render(<Button {...defaultProps} aria-label="unique label" />);
|
|
90
86
|
const loadingButton = screen.getByLabelText('unique label');
|
|
91
87
|
expect(loadingButton).toBeInTheDocument();
|
|
92
88
|
});
|
|
@@ -95,14 +91,14 @@ describe('Button', () => {
|
|
|
95
91
|
describe('onClick', () => {
|
|
96
92
|
it('calls onClick when clicked', async () => {
|
|
97
93
|
const onClick = jest.fn();
|
|
98
|
-
render(<Button {...
|
|
94
|
+
render(<Button {...defaultProps} onClick={onClick} />);
|
|
99
95
|
await userEvent.click(screen.getByRole('button'));
|
|
100
96
|
expect(onClick).toHaveBeenCalledTimes(1);
|
|
101
97
|
});
|
|
102
98
|
|
|
103
99
|
it('does not call onClick when clicked if disabled', async () => {
|
|
104
100
|
const onClick = jest.fn();
|
|
105
|
-
render(<Button {...
|
|
101
|
+
render(<Button {...defaultProps} disabled onClick={onClick} />);
|
|
106
102
|
await userEvent.click(screen.getByRole('button'));
|
|
107
103
|
expect(onClick).toHaveBeenCalledTimes(0);
|
|
108
104
|
});
|
|
@@ -110,29 +106,29 @@ describe('Button', () => {
|
|
|
110
106
|
|
|
111
107
|
describe('sizes', () => {
|
|
112
108
|
it('renders small buttons', () => {
|
|
113
|
-
expect(render(<Button {...
|
|
109
|
+
expect(render(<Button {...defaultProps} size={SMALL} />).container).toMatchSnapshot();
|
|
114
110
|
});
|
|
115
111
|
|
|
116
112
|
it('renders medium buttons', () => {
|
|
117
|
-
expect(render(<Button {...
|
|
113
|
+
expect(render(<Button {...defaultProps} size={MEDIUM} />).container).toMatchSnapshot();
|
|
118
114
|
});
|
|
119
115
|
|
|
120
116
|
it('renders large buttons', () => {
|
|
121
|
-
expect(render(<Button {...
|
|
117
|
+
expect(render(<Button {...defaultProps} size={LARGE} />).container).toMatchSnapshot();
|
|
122
118
|
});
|
|
123
119
|
});
|
|
124
120
|
|
|
125
121
|
describe('types', () => {
|
|
126
122
|
it('renders accent buttons', () => {
|
|
127
|
-
expect(render(<Button {...
|
|
123
|
+
expect(render(<Button {...defaultProps} type={ACCENT} />).container).toMatchSnapshot();
|
|
128
124
|
});
|
|
129
125
|
|
|
130
126
|
it('renders positive buttons', () => {
|
|
131
|
-
expect(render(<Button {...
|
|
127
|
+
expect(render(<Button {...defaultProps} type={POSITIVE} />).container).toMatchSnapshot();
|
|
132
128
|
});
|
|
133
129
|
|
|
134
130
|
it('renders negative buttons', () => {
|
|
135
|
-
expect(render(<Button {...
|
|
131
|
+
expect(render(<Button {...defaultProps} type={NEGATIVE} />).container).toMatchSnapshot();
|
|
136
132
|
});
|
|
137
133
|
});
|
|
138
134
|
|
|
@@ -140,7 +136,7 @@ describe('Button', () => {
|
|
|
140
136
|
it('renders primary buttons', () => {
|
|
141
137
|
[ACCENT, POSITIVE, NEGATIVE].forEach((type) =>
|
|
142
138
|
expect(
|
|
143
|
-
render(<Button {...
|
|
139
|
+
render(<Button {...defaultProps} priority={PRIMARY} type={type} />).container,
|
|
144
140
|
).toMatchSnapshot(),
|
|
145
141
|
);
|
|
146
142
|
});
|
|
@@ -148,21 +144,21 @@ describe('Button', () => {
|
|
|
148
144
|
it('renders secondary buttons', () => {
|
|
149
145
|
[ACCENT, POSITIVE, NEGATIVE].forEach((type) =>
|
|
150
146
|
expect(
|
|
151
|
-
render(<Button {...
|
|
147
|
+
render(<Button {...defaultProps} priority={SECONDARY} type={type} />).container,
|
|
152
148
|
).toMatchSnapshot(),
|
|
153
149
|
);
|
|
154
150
|
});
|
|
155
151
|
|
|
156
152
|
it('renders tertiary buttons', () => {
|
|
157
153
|
expect(
|
|
158
|
-
render(<Button {...
|
|
154
|
+
render(<Button {...defaultProps} priority={TERTIARY} type={ACCENT} />).container,
|
|
159
155
|
).toMatchSnapshot();
|
|
160
156
|
});
|
|
161
157
|
|
|
162
158
|
it('defaults tertiary buttons to secondary for positive buttons', () => {
|
|
163
159
|
[POSITIVE, NEGATIVE].forEach((type) =>
|
|
164
160
|
expect(
|
|
165
|
-
render(<Button {...
|
|
161
|
+
render(<Button {...defaultProps} priority={TERTIARY} type={type} />).container,
|
|
166
162
|
).toMatchSnapshot(),
|
|
167
163
|
);
|
|
168
164
|
});
|
|
@@ -170,40 +166,40 @@ describe('Button', () => {
|
|
|
170
166
|
|
|
171
167
|
describe('alternative states', () => {
|
|
172
168
|
it('renders as loading if loading is true', () => {
|
|
173
|
-
const { container } = render(<Button {...
|
|
169
|
+
const { container } = render(<Button {...defaultProps} loading />);
|
|
174
170
|
expect(container.querySelector('.btn-loader')).toBeInTheDocument();
|
|
175
171
|
expect(screen.getByRole('button', { name: 'loading' })).toBeInTheDocument();
|
|
176
172
|
});
|
|
177
173
|
|
|
178
174
|
it('loading button has aria-label of loading', () => {
|
|
179
|
-
render(<Button {...
|
|
175
|
+
render(<Button {...defaultProps} loading />);
|
|
180
176
|
const loadingButton = screen.getByLabelText('loading');
|
|
181
177
|
expect(loadingButton).toBeInTheDocument();
|
|
182
178
|
});
|
|
183
179
|
|
|
184
180
|
it('renders as block if block is true', () => {
|
|
185
|
-
expect(render(<Button {...
|
|
181
|
+
expect(render(<Button {...defaultProps} block />).container).toMatchSnapshot();
|
|
186
182
|
});
|
|
187
183
|
});
|
|
188
184
|
|
|
189
185
|
describe('deprecated types', () => {
|
|
190
186
|
it('renders primary as accent buttons and logs a warning', () => {
|
|
191
|
-
expect(render(<Button {...
|
|
187
|
+
expect(render(<Button {...defaultProps} type={PRIMARY} />).container).toMatchSnapshot();
|
|
192
188
|
expect(mockedWarn).toHaveBeenCalledTimes(1);
|
|
193
189
|
});
|
|
194
190
|
|
|
195
191
|
it('renders pay as positive buttons and logs a warning', () => {
|
|
196
|
-
expect(render(<Button {...
|
|
192
|
+
expect(render(<Button {...defaultProps} type={PAY} />).container).toMatchSnapshot();
|
|
197
193
|
expect(mockedWarn).toHaveBeenCalledTimes(1);
|
|
198
194
|
});
|
|
199
195
|
|
|
200
196
|
it('renders danger as negative buttons with priority secondary and logs a warning', () => {
|
|
201
|
-
expect(render(<Button {...
|
|
197
|
+
expect(render(<Button {...defaultProps} type={DANGER} />).container).toMatchSnapshot();
|
|
202
198
|
expect(mockedWarn).toHaveBeenCalledTimes(1);
|
|
203
199
|
});
|
|
204
200
|
|
|
205
201
|
it('renders link as accent buttons with priority tertiary and logs a warning', () => {
|
|
206
|
-
expect(render(<Button {...
|
|
202
|
+
expect(render(<Button {...defaultProps} type={LINK} />).container).toMatchSnapshot();
|
|
207
203
|
});
|
|
208
204
|
});
|
|
209
205
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { userEvent, within } from '@storybook/test';
|
|
2
|
+
import { userEvent, within, fn } from '@storybook/test';
|
|
3
3
|
|
|
4
4
|
import { ControlType, Priority } from '../common';
|
|
5
5
|
import { storyConfig } from '../test-utils';
|
|
@@ -11,6 +11,10 @@ export default {
|
|
|
11
11
|
title: 'Actions/Button',
|
|
12
12
|
args: {
|
|
13
13
|
children: 'Button text',
|
|
14
|
+
loading: false,
|
|
15
|
+
onClick: fn(),
|
|
16
|
+
onBlur: fn(),
|
|
17
|
+
onFocus: fn(),
|
|
14
18
|
},
|
|
15
19
|
argTypes: {
|
|
16
20
|
as: {
|
|
@@ -46,39 +50,38 @@ export const Focused = storyConfig<Story>(
|
|
|
46
50
|
|
|
47
51
|
export const Variants = storyConfig<Story>(
|
|
48
52
|
{
|
|
49
|
-
args: {
|
|
50
|
-
className: 'm-r-2',
|
|
51
|
-
},
|
|
52
53
|
render: (args) => {
|
|
53
54
|
return (
|
|
54
55
|
<>
|
|
55
56
|
<div className="m-b-2">
|
|
56
57
|
<div className="title-4 m-b-1">Accent</div>
|
|
57
|
-
<
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
<div className="d-flex flex-wrap" style={{ gap: 'var(--size-16)' }}>
|
|
59
|
+
<Button {...args} priority={Priority.PRIMARY} type={ControlType.ACCENT} />
|
|
60
|
+
<Button {...args} priority={Priority.SECONDARY} type={ControlType.ACCENT} />
|
|
61
|
+
<Button {...args} priority={Priority.TERTIARY} type={ControlType.ACCENT} />
|
|
62
|
+
</div>
|
|
60
63
|
</div>
|
|
61
64
|
<div className="m-b-2">
|
|
62
65
|
<div className="title-4 m-b-1">Positive</div>
|
|
63
|
-
<
|
|
64
|
-
|
|
66
|
+
<div className="d-flex flex-wrap" style={{ gap: 'var(--size-16)' }}>
|
|
67
|
+
<Button {...args} priority={Priority.PRIMARY} type={ControlType.POSITIVE} />
|
|
68
|
+
<Button {...args} priority={Priority.SECONDARY} type={ControlType.POSITIVE} />
|
|
69
|
+
</div>
|
|
65
70
|
</div>
|
|
66
71
|
<div className="m-b-2">
|
|
67
72
|
<div className="title-4 m-b-1">Negative</div>
|
|
68
|
-
<
|
|
69
|
-
|
|
73
|
+
<div className="d-flex flex-wrap" style={{ gap: 'var(--size-16)' }}>
|
|
74
|
+
<Button {...args} priority={Priority.PRIMARY} type={ControlType.NEGATIVE} />
|
|
75
|
+
<Button {...args} priority={Priority.SECONDARY} type={ControlType.NEGATIVE} />
|
|
76
|
+
</div>
|
|
70
77
|
</div>
|
|
71
78
|
<div className="m-b-2">
|
|
72
79
|
<div className="title-4 m-b-1">Disabled</div>
|
|
73
|
-
<
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
<div className="title-4 m-b-1">Loading</div>
|
|
79
|
-
<Button {...args} priority={Priority.PRIMARY} loading />
|
|
80
|
-
<Button {...args} priority={Priority.SECONDARY} loading />
|
|
81
|
-
<Button {...args} priority={Priority.TERTIARY} loading />
|
|
80
|
+
<div className="d-flex flex-wrap" style={{ gap: 'var(--size-16)' }}>
|
|
81
|
+
<Button {...args} priority={Priority.PRIMARY} disabled />
|
|
82
|
+
<Button {...args} priority={Priority.SECONDARY} disabled />
|
|
83
|
+
<Button {...args} priority={Priority.TERTIARY} disabled />
|
|
84
|
+
</div>
|
|
82
85
|
</div>
|
|
83
86
|
</>
|
|
84
87
|
);
|
|
@@ -87,6 +90,26 @@ export const Variants = storyConfig<Story>(
|
|
|
87
90
|
{ variants: ['default', 'dark', 'rtl'] },
|
|
88
91
|
);
|
|
89
92
|
|
|
93
|
+
export const Loading = storyConfig<Story>(
|
|
94
|
+
{
|
|
95
|
+
render: (args) => {
|
|
96
|
+
return (
|
|
97
|
+
<div className="d-flex flex-wrap" style={{ gap: 'var(--size-16)' }}>
|
|
98
|
+
<Button {...args} loading priority={Priority.PRIMARY} />
|
|
99
|
+
<Button {...args} loading priority={Priority.SECONDARY} />
|
|
100
|
+
<Button {...args} loading priority={Priority.TERTIARY} />
|
|
101
|
+
<Button {...args} loading priority={Priority.PRIMARY} type={ControlType.NEGATIVE} />
|
|
102
|
+
<Button {...args} loading priority={Priority.SECONDARY} type={ControlType.NEGATIVE} />
|
|
103
|
+
</div>
|
|
104
|
+
);
|
|
105
|
+
},
|
|
106
|
+
args: {
|
|
107
|
+
loading: true,
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
{ variants: ['default', 'dark', 'rtl'] },
|
|
111
|
+
);
|
|
112
|
+
|
|
90
113
|
export const SocialMedia = storyConfig<Story>(
|
|
91
114
|
{
|
|
92
115
|
render: () => {
|
package/src/button/Button.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { clsx } from 'clsx';
|
|
2
|
-
import {
|
|
2
|
+
import { ElementType, forwardRef, MouseEvent } from 'react';
|
|
3
3
|
import { useIntl } from 'react-intl';
|
|
4
4
|
|
|
5
5
|
import {
|
|
@@ -65,6 +65,7 @@ const Button = forwardRef<ButtonReferenceType, Props>(
|
|
|
65
65
|
priority = Priority.PRIMARY,
|
|
66
66
|
size = Size.MEDIUM,
|
|
67
67
|
type = ControlType.ACCENT,
|
|
68
|
+
onClick,
|
|
68
69
|
...rest
|
|
69
70
|
}: Props,
|
|
70
71
|
reference,
|
|
@@ -85,9 +86,7 @@ const Button = forwardRef<ButtonReferenceType, Props>(
|
|
|
85
86
|
{
|
|
86
87
|
'btn-loading': loading,
|
|
87
88
|
'btn-block np-btn-block': block,
|
|
88
|
-
|
|
89
|
-
{
|
|
90
|
-
disabled: disabled || loading,
|
|
89
|
+
disabled,
|
|
91
90
|
},
|
|
92
91
|
// @ts-expect-error fix when refactor `typeClassMap` to TypeScript
|
|
93
92
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
@@ -109,19 +108,36 @@ const Button = forwardRef<ButtonReferenceType, Props>(
|
|
|
109
108
|
const { htmlType = 'button', ...restProps } = rest as ButtonProps;
|
|
110
109
|
props = {
|
|
111
110
|
...restProps,
|
|
112
|
-
disabled: disabled
|
|
111
|
+
disabled: disabled && !loading,
|
|
112
|
+
'aria-disabled': loading,
|
|
113
113
|
type: htmlType,
|
|
114
114
|
};
|
|
115
115
|
} else {
|
|
116
116
|
props = { ...rest } as AnchorProps;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Ensures that the button cannot be activated in loading or disabled mode,
|
|
121
|
+
* when `aria-disabled` might be used over the `disabled` HTML attribute
|
|
122
|
+
*/
|
|
123
|
+
const handleClick =
|
|
124
|
+
(handler: Props['onClick']) =>
|
|
125
|
+
(event: MouseEvent<HTMLButtonElement> & MouseEvent<HTMLAnchorElement>) => {
|
|
126
|
+
if (disabled || loading) {
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
} else if (typeof handler === 'function') {
|
|
129
|
+
handler(event);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
119
133
|
return (
|
|
120
134
|
<Element
|
|
121
135
|
ref={reference}
|
|
122
136
|
className={classes}
|
|
137
|
+
onClick={handleClick(onClick)}
|
|
123
138
|
{...props}
|
|
124
139
|
aria-live={loading ? 'polite' : 'off'}
|
|
140
|
+
aria-busy={loading}
|
|
125
141
|
aria-label={loading ? intl.formatMessage(messages.loadingAriaLabel) : rest['aria-label']}
|
|
126
142
|
>
|
|
127
143
|
{children}
|