@openedx/paragon 22.11.0 → 22.11.2
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/dist/Form/FormGroup.d.ts +41 -0
- package/dist/Form/FormGroup.js +3 -11
- package/dist/Form/FormGroup.js.map +1 -1
- package/dist/Form/FormGroupContext.d.ts +24 -0
- package/dist/Form/FormGroupContext.js +2 -17
- package/dist/Form/FormGroupContext.js.map +1 -1
- package/dist/Form/FormLabel.d.ts +20 -0
- package/dist/Form/FormLabel.js +2 -10
- package/dist/Form/FormLabel.js.map +1 -1
- package/dist/Form/constants.d.ts +13 -0
- package/dist/Form/constants.js +5 -8
- package/dist/Form/constants.js.map +1 -0
- package/dist/Form/fieldUtils.d.ts +9 -0
- package/dist/Form/fieldUtils.js +27 -29
- package/dist/Form/fieldUtils.js.map +1 -0
- package/dist/Form/index.d.ts +39 -0
- package/dist/Form/index.js +18 -1
- package/dist/Form/index.js.map +1 -1
- package/dist/Form/messages.d.ts +13 -0
- package/dist/Form/messages.js +4 -5
- package/dist/Form/messages.js.map +1 -0
- package/dist/IconButton/index.d.ts +3 -0
- package/dist/IconButton/index.js +4 -1
- package/dist/IconButton/index.js.map +1 -1
- package/dist/index.d.ts +22 -22
- package/dist/index.js +22 -22
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/newId.d.ts +2 -0
- package/dist/utils/newId.js +3 -3
- package/dist/utils/newId.js.map +1 -0
- package/dist/utils/propTypes/utils.js +1 -1
- package/package.json +1 -1
- package/src/Collapsible/README.md +2 -2
- package/src/DataTable/README.md +2 -2
- package/src/Dropdown/README.md +1 -1
- package/src/Dropzone/README.md +1 -1
- package/src/Form/{FormGroup.jsx → FormGroup.tsx} +24 -14
- package/src/Form/{FormGroupContext.jsx → FormGroupContext.tsx} +29 -27
- package/src/Form/{FormLabel.jsx → FormLabel.tsx} +8 -11
- package/src/Form/{constants.js → constants.ts} +4 -7
- package/src/Form/{fieldUtils.js → fieldUtils.ts} +14 -11
- package/src/Form/form-control.mdx +4 -6
- package/src/Form/{index.jsx → index.tsx} +33 -1
- package/src/IconButton/index.tsx +5 -0
- package/src/InputSelect/README.md +2 -3
- package/src/InputText/README.md +4 -6
- package/src/ListBox/README.md +1 -1
- package/src/Modal/standard-modal.mdx +1 -1
- package/src/TextArea/README.md +2 -3
- package/src/index.d.ts +22 -22
- package/src/index.js +22 -22
- package/src/utils/propTypes/utils.js +1 -1
- /package/src/Form/{messages.js → messages.ts} +0 -0
- /package/src/utils/{index.js → index.ts} +0 -0
- /package/src/utils/{newId.js → newId.ts} +0 -0
package/dist/IconButton/index.js
CHANGED
|
@@ -57,6 +57,7 @@ IconButton.defaultProps = {
|
|
|
57
57
|
size: 'md',
|
|
58
58
|
onClick: () => {},
|
|
59
59
|
isActive: false,
|
|
60
|
+
value: undefined,
|
|
60
61
|
children: undefined
|
|
61
62
|
};
|
|
62
63
|
IconButton.propTypes = {
|
|
@@ -91,7 +92,9 @@ IconButton.propTypes = {
|
|
|
91
92
|
/** size of button to render */
|
|
92
93
|
size: PropTypes.oneOf(['sm', 'md', 'inline']),
|
|
93
94
|
/** whether to show the `IconButton` in an active state, whose styling is distinct from default state */
|
|
94
|
-
isActive: PropTypes.bool
|
|
95
|
+
isActive: PropTypes.bool,
|
|
96
|
+
/** Used with `IconButtonToggle` */
|
|
97
|
+
value: PropTypes.string
|
|
95
98
|
};
|
|
96
99
|
/**
|
|
97
100
|
* An icon button wrapped in overlaytrigger to display a tooltip.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["React","PropTypes","classNames","FontAwesomeIcon","OverlayTrigger","Tooltip","IconButton","forwardRef","_ref","ref","className","alt","invertColors","icon","src","iconClassNames","onClick","size","variant","iconAs","isActive","children","attrs","invert","activeStyle","process","env","NODE_ENV","console","msg","warn","IconComponent","createElement","type","defaultProps","undefined","propTypes","string","elementType","isRequired","bool","shape","prefix","iconName","array","func","oneOf","IconButtonWithTooltip","_ref2","tooltipPlacement","tooltipContent","props","placement","overlay","id","node"],"sources":["../../src/IconButton/index.tsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport classNames from 'classnames';\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome';\nimport { type Placement } from 'react-bootstrap/Overlay';\n\nimport { OverlayTrigger } from '../Overlay';\nimport Tooltip from '../Tooltip';\nimport Icon from '../Icon';\n\ninterface Props extends React.HTMLAttributes<HTMLButtonElement> {\n iconAs?: typeof Icon | typeof FontAwesomeIcon,\n /** Additional CSS class[es] to apply to this button */\n className?: string;\n /** Alt text for your icon. For best practice, avoid using alt text to describe\n * the image in the `IconButton`. Instead, we recommend describing the function\n * of the button. */\n alt: string;\n /** Changes icon styles for dark background */\n invertColors?: boolean;\n /** An icon component to render. Example import of a Paragon icon component:\n * `import { Check } from '@openedx/paragon/icons';`\n * */\n // Note: React.ComponentType is what we want here. React.ElementType would allow some element type strings like \"div\",\n // but we only want to allow components like 'Add' (a specific icon component function/class)\n src?: React.ComponentType;\n /** Extra class names that will be added to the icon */\n iconClassNames?: string;\n /** Click handler for the button */\n onClick?: React.MouseEventHandler<HTMLButtonElement>;\n /** whether to show the `IconButton` in an active state, whose styling is distinct from default state */\n isActive?: boolean;\n /** @deprecated Using FontAwesome icons is deprecated. Instead, pass iconAs={Icon} src={...} */\n icon?: { prefix?: string; iconName?: string, icon?: any[] },\n /** Type of button (uses Bootstrap options) */\n variant?: 'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'light' | 'dark' | 'black' | 'brand';\n /** size of button to render */\n size?: 'sm' | 'md' | 'inline';\n /** no children */\n children?: never;\n}\n\nconst IconButton = React.forwardRef<HTMLButtonElement, Props>(({\n className,\n alt,\n invertColors,\n icon,\n src,\n iconClassNames,\n onClick,\n size,\n variant,\n iconAs,\n isActive,\n children, // unused, just here because we don't want it to be part of 'attrs'\n ...attrs\n}, ref) => {\n const invert = invertColors ? 'inverse-' : '';\n const activeStyle = isActive ? `${variant}-` : '';\n if (!iconAs && process.env.NODE_ENV === 'development' && console) {\n const msg = '[Deprecated] IconButton: you have not provided a value for iconAs prop and '\n + 'are using a default one - FontAwesomeIcon, the default value is going to be changed soon '\n + 'as Paragon is moving away from FontAwesome, please use Paragon\\'s icons instead.';\n // eslint-disable-next-line no-console\n console.warn(msg);\n }\n const IconComponent = iconAs || FontAwesomeIcon;\n return (\n <button\n aria-label={alt}\n className={classNames(\n 'btn-icon',\n `btn-icon-${invert}${variant}`,\n `btn-icon-${size}`,\n {\n [`btn-icon-${invert}${activeStyle}active`]: isActive,\n },\n className,\n )}\n onClick={onClick}\n type=\"button\"\n ref={ref}\n {...attrs}\n >\n <span className=\"btn-icon__icon-container\">\n <IconComponent\n className={classNames('btn-icon__icon', iconClassNames)}\n icon={icon as any}\n src={src}\n />\n </span>\n </button>\n );\n});\n\nIconButton.defaultProps = {\n iconAs: undefined,\n src: undefined,\n icon: undefined,\n iconClassNames: undefined,\n className: undefined,\n invertColors: false,\n variant: 'primary',\n size: 'md',\n onClick: () => {},\n isActive: false,\n children: undefined,\n};\n\nIconButton.propTypes = {\n /** A custom class name. */\n className: PropTypes.string,\n /** Component that renders the icon, currently defaults to `FontAwesomeIcon`,\n * but is going to be deprecated soon, please use Paragon's icons instead. */\n iconAs: PropTypes.elementType as any,\n /** An icon component to render. Example import of a Paragon icon component:\n * `import { Check } from '@openedx/paragon/icons';`\n * */\n src: PropTypes.elementType as any,\n /** Alt text for your icon. For best practice, avoid using alt text to describe\n * the image in the `IconButton`. Instead, we recommend describing the function\n * of the button. */\n alt: PropTypes.string.isRequired,\n /** Changes icon styles for dark background */\n invertColors: PropTypes.bool,\n /** Accepts a React fontawesome icon. */\n icon: PropTypes.shape({\n prefix: PropTypes.string,\n iconName: PropTypes.string,\n // eslint-disable-next-line react/forbid-prop-types\n icon: PropTypes.array,\n }) as any,\n /** Extra class names that will be added to the icon */\n iconClassNames: PropTypes.string,\n /** Click handler for the button */\n onClick: PropTypes.func,\n /** Type of button (uses Bootstrap options) */\n variant: PropTypes.oneOf(['primary', 'secondary', 'success', 'warning', 'danger', 'light', 'dark', 'black', 'brand']),\n /** size of button to render */\n size: PropTypes.oneOf(['sm', 'md', 'inline']),\n /** whether to show the `IconButton` in an active state, whose styling is distinct from default state */\n isActive: PropTypes.bool,\n};\n\ninterface PropsWithTooltip extends Props {\n /** choose from https://popper.js.org/docs/v2/constructors/#options */\n tooltipPlacement: Placement,\n /** any content to pass to tooltip content area */\n tooltipContent: React.ReactNode,\n}\n\n/**\n * An icon button wrapped in overlaytrigger to display a tooltip.\n */\nfunction IconButtonWithTooltip({\n tooltipPlacement, tooltipContent, ...props\n}: PropsWithTooltip) {\n const invert = props.invertColors ? 'inverse-' : '';\n return (\n <OverlayTrigger\n placement={tooltipPlacement}\n overlay={(\n <Tooltip\n id={`iconbutton-tooltip-${tooltipPlacement}`}\n variant={invert ? 'light' : undefined}\n >\n {tooltipContent}\n </Tooltip>\n )}\n >\n <IconButton {...props} />\n </OverlayTrigger>\n );\n}\n\nIconButtonWithTooltip.defaultProps = {\n ...IconButton.defaultProps,\n tooltipPlacement: 'top',\n};\n\nIconButtonWithTooltip.propTypes = {\n /** tooltip placement can be top, left, right etc, per https://popper.js.org/docs/v2/constructors/#options */\n tooltipPlacement: PropTypes.string,\n /** any valid JSX or text to be rendered as tooltip contents */\n tooltipContent: PropTypes.node.isRequired,\n /** Type of button (uses Bootstrap options) */\n variant: PropTypes.oneOf(['primary', 'secondary', 'success', 'warning', 'danger', 'light', 'dark', 'black', 'brand']),\n /** Changes icon styles for dark background */\n invertColors: PropTypes.bool,\n};\n\n(IconButton as any).IconButtonWithTooltip = IconButtonWithTooltip;\n\nexport default IconButton as typeof IconButton & {\n IconButtonWithTooltip: typeof IconButtonWithTooltip,\n};\nexport { IconButtonWithTooltip };\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,SAAS,M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B,CAAC;AAEAlC,UAAU,CAASyC,qBAAqB,GAAGA,qBAAqB;AAEjE,eAAezC,UAAU;AAGzB,SAASyC,qBAAqB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","PropTypes","classNames","FontAwesomeIcon","OverlayTrigger","Tooltip","IconButton","forwardRef","_ref","ref","className","alt","invertColors","icon","src","iconClassNames","onClick","size","variant","iconAs","isActive","children","attrs","invert","activeStyle","process","env","NODE_ENV","console","msg","warn","IconComponent","createElement","type","defaultProps","undefined","value","propTypes","string","elementType","isRequired","bool","shape","prefix","iconName","array","func","oneOf","IconButtonWithTooltip","_ref2","tooltipPlacement","tooltipContent","props","placement","overlay","id","node"],"sources":["../../src/IconButton/index.tsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport classNames from 'classnames';\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome';\nimport { type Placement } from 'react-bootstrap/Overlay';\n\nimport { OverlayTrigger } from '../Overlay';\nimport Tooltip from '../Tooltip';\nimport Icon from '../Icon';\n\ninterface Props extends React.HTMLAttributes<HTMLButtonElement> {\n iconAs?: typeof Icon | typeof FontAwesomeIcon,\n /** Additional CSS class[es] to apply to this button */\n className?: string;\n /** Alt text for your icon. For best practice, avoid using alt text to describe\n * the image in the `IconButton`. Instead, we recommend describing the function\n * of the button. */\n alt: string;\n /** Changes icon styles for dark background */\n invertColors?: boolean;\n /** An icon component to render. Example import of a Paragon icon component:\n * `import { Check } from '@openedx/paragon/icons';`\n * */\n // Note: React.ComponentType is what we want here. React.ElementType would allow some element type strings like \"div\",\n // but we only want to allow components like 'Add' (a specific icon component function/class)\n src?: React.ComponentType;\n /** Extra class names that will be added to the icon */\n iconClassNames?: string;\n /** Click handler for the button */\n onClick?: React.MouseEventHandler<HTMLButtonElement>;\n /** whether to show the `IconButton` in an active state, whose styling is distinct from default state */\n isActive?: boolean;\n /** @deprecated Using FontAwesome icons is deprecated. Instead, pass iconAs={Icon} src={...} */\n icon?: { prefix?: string; iconName?: string, icon?: any[] },\n /** Type of button (uses Bootstrap options) */\n variant?: 'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'light' | 'dark' | 'black' | 'brand';\n /** size of button to render */\n size?: 'sm' | 'md' | 'inline';\n /** Used with `IconButtonToggle` */\n value?: string;\n /** no children */\n children?: never;\n}\n\nconst IconButton = React.forwardRef<HTMLButtonElement, Props>(({\n className,\n alt,\n invertColors,\n icon,\n src,\n iconClassNames,\n onClick,\n size,\n variant,\n iconAs,\n isActive,\n children, // unused, just here because we don't want it to be part of 'attrs'\n ...attrs\n}, ref) => {\n const invert = invertColors ? 'inverse-' : '';\n const activeStyle = isActive ? `${variant}-` : '';\n if (!iconAs && process.env.NODE_ENV === 'development' && console) {\n const msg = '[Deprecated] IconButton: you have not provided a value for iconAs prop and '\n + 'are using a default one - FontAwesomeIcon, the default value is going to be changed soon '\n + 'as Paragon is moving away from FontAwesome, please use Paragon\\'s icons instead.';\n // eslint-disable-next-line no-console\n console.warn(msg);\n }\n const IconComponent = iconAs || FontAwesomeIcon;\n return (\n <button\n aria-label={alt}\n className={classNames(\n 'btn-icon',\n `btn-icon-${invert}${variant}`,\n `btn-icon-${size}`,\n {\n [`btn-icon-${invert}${activeStyle}active`]: isActive,\n },\n className,\n )}\n onClick={onClick}\n type=\"button\"\n ref={ref}\n {...attrs}\n >\n <span className=\"btn-icon__icon-container\">\n <IconComponent\n className={classNames('btn-icon__icon', iconClassNames)}\n icon={icon as any}\n src={src}\n />\n </span>\n </button>\n );\n});\n\nIconButton.defaultProps = {\n iconAs: undefined,\n src: undefined,\n icon: undefined,\n iconClassNames: undefined,\n className: undefined,\n invertColors: false,\n variant: 'primary',\n size: 'md',\n onClick: () => {},\n isActive: false,\n value: undefined,\n children: undefined,\n};\n\nIconButton.propTypes = {\n /** A custom class name. */\n className: PropTypes.string,\n /** Component that renders the icon, currently defaults to `FontAwesomeIcon`,\n * but is going to be deprecated soon, please use Paragon's icons instead. */\n iconAs: PropTypes.elementType as any,\n /** An icon component to render. Example import of a Paragon icon component:\n * `import { Check } from '@openedx/paragon/icons';`\n * */\n src: PropTypes.elementType as any,\n /** Alt text for your icon. For best practice, avoid using alt text to describe\n * the image in the `IconButton`. Instead, we recommend describing the function\n * of the button. */\n alt: PropTypes.string.isRequired,\n /** Changes icon styles for dark background */\n invertColors: PropTypes.bool,\n /** Accepts a React fontawesome icon. */\n icon: PropTypes.shape({\n prefix: PropTypes.string,\n iconName: PropTypes.string,\n // eslint-disable-next-line react/forbid-prop-types\n icon: PropTypes.array,\n }) as any,\n /** Extra class names that will be added to the icon */\n iconClassNames: PropTypes.string,\n /** Click handler for the button */\n onClick: PropTypes.func,\n /** Type of button (uses Bootstrap options) */\n variant: PropTypes.oneOf(['primary', 'secondary', 'success', 'warning', 'danger', 'light', 'dark', 'black', 'brand']),\n /** size of button to render */\n size: PropTypes.oneOf(['sm', 'md', 'inline']),\n /** whether to show the `IconButton` in an active state, whose styling is distinct from default state */\n isActive: PropTypes.bool,\n /** Used with `IconButtonToggle` */\n value: PropTypes.string,\n};\n\ninterface PropsWithTooltip extends Props {\n /** choose from https://popper.js.org/docs/v2/constructors/#options */\n tooltipPlacement: Placement,\n /** any content to pass to tooltip content area */\n tooltipContent: React.ReactNode,\n}\n\n/**\n * An icon button wrapped in overlaytrigger to display a tooltip.\n */\nfunction IconButtonWithTooltip({\n tooltipPlacement, tooltipContent, ...props\n}: PropsWithTooltip) {\n const invert = props.invertColors ? 'inverse-' : '';\n return (\n <OverlayTrigger\n placement={tooltipPlacement}\n overlay={(\n <Tooltip\n id={`iconbutton-tooltip-${tooltipPlacement}`}\n variant={invert ? 'light' : undefined}\n >\n {tooltipContent}\n </Tooltip>\n )}\n >\n <IconButton {...props} />\n </OverlayTrigger>\n );\n}\n\nIconButtonWithTooltip.defaultProps = {\n ...IconButton.defaultProps,\n tooltipPlacement: 'top',\n};\n\nIconButtonWithTooltip.propTypes = {\n /** tooltip placement can be top, left, right etc, per https://popper.js.org/docs/v2/constructors/#options */\n tooltipPlacement: PropTypes.string,\n /** any valid JSX or text to be rendered as tooltip contents */\n tooltipContent: PropTypes.node.isRequired,\n /** Type of button (uses Bootstrap options) */\n variant: PropTypes.oneOf(['primary', 'secondary', 'success', 'warning', 'danger', 'light', 'dark', 'black', 'brand']),\n /** Changes icon styles for dark background */\n invertColors: PropTypes.bool,\n};\n\n(IconButton as any).IconButtonWithTooltip = IconButtonWithTooltip;\n\nexport default IconButton as typeof IconButton & {\n IconButtonWithTooltip: typeof IconButtonWithTooltip,\n};\nexport { IconButtonWithTooltip };\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,SAAS,MAAM,YAAY;AAClC,OAAOC,UAAU,MAAM,YAAY;AACnC,SAASC,eAAe,QAAQ,gCAAgC;AAGhE,SAASC,cAAc,QAAQ,YAAY;AAC3C,OAAOC,OAAO,MAAM,YAAY;AAqChC,MAAMC,UAAU,gBAAGN,KAAK,CAACO,UAAU,CAA2B,CAAAC,IAAA,EAc3DC,GAAG,KAAK;EAAA,IAdoD;IAC7DC,SAAS;IACTC,GAAG;IACHC,YAAY;IACZC,IAAI;IACJC,GAAG;IACHC,cAAc;IACdC,OAAO;IACPC,IAAI;IACJC,OAAO;IACPC,MAAM;IACNC,QAAQ;IACRC,QAAQ;IAAE;IACV,GAAGC;EACL,CAAC,GAAAd,IAAA;EACC,MAAMe,MAAM,GAAGX,YAAY,GAAG,UAAU,GAAG,EAAE;EAC7C,MAAMY,WAAW,GAAGJ,QAAQ,GAAI,GAAEF,OAAQ,GAAE,GAAG,EAAE;EACjD,IAAI,CAACC,MAAM,IAAIM,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,aAAa,IAAIC,OAAO,EAAE;IAChE,MAAMC,GAAG,GAAG,6EAA6E,GACrF,2FAA2F,GAC3F,kFAAkF;IACtF;IACAD,OAAO,CAACE,IAAI,CAACD,GAAG,CAAC;EACnB;EACA,MAAME,aAAa,GAAGZ,MAAM,I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GAAK8C;EAAK,CAAG,CACV,CAAC;AAErB;AAEAJ,qBAAqB,CAACd,YAAY,GAAG;EACnC,GAAG5B,UAAU,CAAC4B,YAAY;EAC1BgB,gBAAgB,EAAE;AACpB,CAAC;AAEDF,qBAAqB,CAACX,SAAS,GAAG;EAChC;EACAa,gBAAgB,EAAEjD,SAAS,CAACqC,MAAM;EAClC;EACAa,cAAc,EAAElD,SAAS,CAACuD,IAAI,CAAChB,UAAU;EACzC;EACAtB,OAAO,EAAEjB,SAAS,CAAC8C,KAAK,CAAC,CAAC,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;EACrH;EACAnC,YAAY,EAAEX,SAAS,CAACwC;AAC1B,CAAC;AAEAnC,UAAU,CAAS0C,qBAAqB,GAAGA,qBAAqB;AAEjE,eAAe1C,UAAU;AAGzB,SAAS0C,qBAAqB","ignoreList":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,28 @@ export { default as Button, ButtonGroup, ButtonToolbar } from './Button';
|
|
|
9
9
|
export { default as Chip, CHIP_PGN_CLASS } from './Chip';
|
|
10
10
|
export { default as ChipCarousel } from './ChipCarousel';
|
|
11
11
|
export { default as Container, ContainerSize } from './Container';
|
|
12
|
+
export {
|
|
13
|
+
default as Form,
|
|
14
|
+
RadioControl,
|
|
15
|
+
CheckboxControl,
|
|
16
|
+
SwitchControl,
|
|
17
|
+
FormSwitchSet,
|
|
18
|
+
FormControl,
|
|
19
|
+
FormControlDecoratorGroup,
|
|
20
|
+
FormControlFeedback,
|
|
21
|
+
FormCheck,
|
|
22
|
+
FormFile,
|
|
23
|
+
FormRadio,
|
|
24
|
+
FormRadioSet,
|
|
25
|
+
FormRadioSetContext,
|
|
26
|
+
FormGroup,
|
|
27
|
+
FormLabel,
|
|
28
|
+
useCheckboxSetValues,
|
|
29
|
+
FormText,
|
|
30
|
+
FormAutosuggest,
|
|
31
|
+
FormAutosuggestOption,
|
|
32
|
+
InputGroup,
|
|
33
|
+
} from './Form';
|
|
12
34
|
export { default as Hyperlink, HYPER_LINK_EXTERNAL_LINK_ALT_TEXT, HYPER_LINK_EXTERNAL_LINK_TITLE } from './Hyperlink';
|
|
13
35
|
export { default as Icon } from './Icon';
|
|
14
36
|
export { default as IconButton, IconButtonWithTooltip } from './IconButton';
|
|
@@ -61,28 +83,6 @@ export const
|
|
|
61
83
|
export const Fade: any; // from './Fade';
|
|
62
84
|
/** @deprecated */
|
|
63
85
|
export const Fieldset: any; // from './Fieldset';
|
|
64
|
-
export const
|
|
65
|
-
Form: any,
|
|
66
|
-
RadioControl: any,
|
|
67
|
-
CheckboxControl: any,
|
|
68
|
-
SwitchControl: any,
|
|
69
|
-
FormSwitchSet: any,
|
|
70
|
-
FormControl: any,
|
|
71
|
-
FormControlDecoratorGroup: any,
|
|
72
|
-
FormControlFeedback: any,
|
|
73
|
-
FormCheck: any,
|
|
74
|
-
FormFile: any,
|
|
75
|
-
FormRadio: any,
|
|
76
|
-
FormRadioSet: any,
|
|
77
|
-
FormRadioSetContext: any,
|
|
78
|
-
FormGroup: any,
|
|
79
|
-
FormLabel: any,
|
|
80
|
-
useCheckboxSetValues: any,
|
|
81
|
-
FormText: any,
|
|
82
|
-
FormAutosuggest: any,
|
|
83
|
-
FormAutosuggestOption: any,
|
|
84
|
-
InputGroup: any;
|
|
85
|
-
// from './Form';
|
|
86
86
|
export const IconButtonToggle: any; // from './IconButtonToggle';
|
|
87
87
|
/** @deprecated Replaced by `Form.Control`. */
|
|
88
88
|
export const Input: any; // from './Input';
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,28 @@ export { default as Button, ButtonGroup, ButtonToolbar } from './Button';
|
|
|
9
9
|
export { default as Chip, CHIP_PGN_CLASS } from './Chip';
|
|
10
10
|
export { default as ChipCarousel } from './ChipCarousel';
|
|
11
11
|
export { default as Container } from './Container';
|
|
12
|
+
export {
|
|
13
|
+
default as Form,
|
|
14
|
+
RadioControl,
|
|
15
|
+
CheckboxControl,
|
|
16
|
+
SwitchControl,
|
|
17
|
+
FormSwitchSet,
|
|
18
|
+
FormControl,
|
|
19
|
+
FormControlDecoratorGroup,
|
|
20
|
+
FormControlFeedback,
|
|
21
|
+
FormCheck,
|
|
22
|
+
FormFile,
|
|
23
|
+
FormRadio,
|
|
24
|
+
FormRadioSet,
|
|
25
|
+
FormRadioSetContext,
|
|
26
|
+
FormGroup,
|
|
27
|
+
FormLabel,
|
|
28
|
+
useCheckboxSetValues,
|
|
29
|
+
FormText,
|
|
30
|
+
FormAutosuggest,
|
|
31
|
+
FormAutosuggestOption,
|
|
32
|
+
InputGroup,
|
|
33
|
+
} from './Form';
|
|
12
34
|
export { default as Hyperlink, HYPER_LINK_EXTERNAL_LINK_ALT_TEXT, HYPER_LINK_EXTERNAL_LINK_TITLE } from './Hyperlink';
|
|
13
35
|
export { default as Icon } from './Icon';
|
|
14
36
|
export { default as IconButton, IconButtonWithTooltip } from './IconButton';
|
|
@@ -61,28 +83,6 @@ export {
|
|
|
61
83
|
export { default as Fade } from './Fade';
|
|
62
84
|
/** @deprecated */
|
|
63
85
|
export { default as Fieldset } from './Fieldset';
|
|
64
|
-
export {
|
|
65
|
-
default as Form,
|
|
66
|
-
RadioControl,
|
|
67
|
-
CheckboxControl,
|
|
68
|
-
SwitchControl,
|
|
69
|
-
FormSwitchSet,
|
|
70
|
-
FormControl,
|
|
71
|
-
FormControlDecoratorGroup,
|
|
72
|
-
FormControlFeedback,
|
|
73
|
-
FormCheck,
|
|
74
|
-
FormFile,
|
|
75
|
-
FormRadio,
|
|
76
|
-
FormRadioSet,
|
|
77
|
-
FormRadioSetContext,
|
|
78
|
-
FormGroup,
|
|
79
|
-
FormLabel,
|
|
80
|
-
useCheckboxSetValues,
|
|
81
|
-
FormText,
|
|
82
|
-
FormAutosuggest,
|
|
83
|
-
FormAutosuggestOption,
|
|
84
|
-
InputGroup,
|
|
85
|
-
} from './Form';
|
|
86
86
|
export { default as IconButtonToggle } from './IconButtonToggle';
|
|
87
87
|
/** @deprecated Replaced by `Form.Control`. */
|
|
88
88
|
export { default as Input } from './Input';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as newId } from './newId';
|
package/dist/utils/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["default","newId"],"sources":["../../src/utils/index.ts"],"sourcesContent":["// eslint-disable-next-line import/prefer-default-export\nexport { default as newId } from './newId';\n"],"mappings":"AAAA;AACA,SAASA,OAAO,IAAIC,KAAK,QAAQ,SAAS","ignoreList":[]}
|
package/dist/utils/newId.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
let lastId = 0;
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const newId = function () {
|
|
3
|
+
let prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'id';
|
|
4
4
|
lastId += 1;
|
|
5
5
|
return `${prefix}${lastId}`;
|
|
6
6
|
};
|
|
7
|
-
|
|
8
7
|
export default newId;
|
|
8
|
+
//# sourceMappingURL=newId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"newId.js","names":["lastId","newId","prefix","arguments","length","undefined"],"sources":["../../src/utils/newId.ts"],"sourcesContent":["let lastId = 0;\n\nconst newId = (prefix = 'id') => {\n lastId += 1;\n return `${prefix}${lastId}`;\n};\n\nexport default newId;\n"],"mappings":"AAAA,IAAIA,MAAM,GAAG,CAAC;AAEd,MAAMC,KAAK,GAAG,SAAAA,CAAA,EAAmB;EAAA,IAAlBC,MAAM,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI;EAC1BH,MAAM,IAAI,CAAC;EACX,OAAQ,GAAEE,MAAO,GAAEF,MAAO,EAAC;AAC7B,CAAC;AAED,eAAeC,KAAK","ignoreList":[]}
|
|
@@ -36,7 +36,7 @@ export const isEveryPropDefined = (props, otherPropNames) => otherPropNames
|
|
|
36
36
|
* Returns a PropType entry with the given propType that is required if otherPropName
|
|
37
37
|
* is truthy.
|
|
38
38
|
* @param {func} propType - target PropType
|
|
39
|
-
* @param {string} otherPropName - string name for prop that, if true, marks the
|
|
39
|
+
* @param {string | string[]} otherPropName - string name for prop that, if true, marks the
|
|
40
40
|
* associated prop as required
|
|
41
41
|
* @return {func} - PropType based on propType that is required if otherPropName is
|
|
42
42
|
* set to true.
|
package/package.json
CHANGED
|
@@ -185,13 +185,13 @@ See the developer console for logging.
|
|
|
185
185
|
### Controlled usage
|
|
186
186
|
|
|
187
187
|
```jsx live
|
|
188
|
-
|
|
188
|
+
() => {
|
|
189
189
|
const [collapseIsOpen, setCollapseOpen] = React.useState(true);
|
|
190
190
|
|
|
191
191
|
return (
|
|
192
192
|
<Collapsible.Advanced
|
|
193
193
|
open={collapseIsOpen}
|
|
194
|
-
onToggle={isOpen => setCollapseOpen(
|
|
194
|
+
onToggle={isOpen => setCollapseOpen(isOpen)}
|
|
195
195
|
className="collapsible-card"
|
|
196
196
|
>
|
|
197
197
|
<Collapsible.Trigger className="collapsible-trigger">
|
package/src/DataTable/README.md
CHANGED
|
@@ -253,7 +253,7 @@ To enable proper selection behavior with backend pagination (i.e., when ``isSele
|
|
|
253
253
|
</Component>
|
|
254
254
|
);
|
|
255
255
|
|
|
256
|
-
const ClearAction = ({ as: Component, tableInstance
|
|
256
|
+
const ClearAction = ({ as: Component, tableInstance }) => (
|
|
257
257
|
<Component
|
|
258
258
|
variant="danger"
|
|
259
259
|
onClick={() => {
|
|
@@ -845,7 +845,7 @@ a responsive grid of cards.
|
|
|
845
845
|
</Component>
|
|
846
846
|
);
|
|
847
847
|
|
|
848
|
-
const ClearAction = ({ as: Component, tableInstance
|
|
848
|
+
const ClearAction = ({ as: Component, tableInstance }) => (
|
|
849
849
|
<Component
|
|
850
850
|
variant="danger"
|
|
851
851
|
onClick={() => {
|
package/src/Dropdown/README.md
CHANGED
|
@@ -145,7 +145,7 @@ You can use `Dropdown.Toggle` with [IconButton](/components/iconbutton) componen
|
|
|
145
145
|
```jsx live
|
|
146
146
|
<Dropdown.Deprecated>
|
|
147
147
|
<Dropdown.Deprecated.Button>
|
|
148
|
-
<Icon className="fa fa-user pr-3"
|
|
148
|
+
<Icon className="fa fa-user pr-3" />
|
|
149
149
|
Search Engines
|
|
150
150
|
</Dropdown.Deprecated.Button>
|
|
151
151
|
<Dropdown.Deprecated.Menu>
|
package/src/Dropzone/README.md
CHANGED
|
@@ -240,7 +240,7 @@ This example validates that only `400x479` images can be uploaded.
|
|
|
240
240
|
async function imageDimensionValidator(file) {
|
|
241
241
|
const image = new window.Image();
|
|
242
242
|
try {
|
|
243
|
-
url = URL.createObjectURL(file);
|
|
243
|
+
const url = URL.createObjectURL(file);
|
|
244
244
|
image.src = url;
|
|
245
245
|
await image.decode();
|
|
246
246
|
if (image.width !== 400 || image.height !== 479) {
|
|
@@ -2,18 +2,37 @@ import React from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import { FormGroupContextProvider } from './FormGroupContext';
|
|
5
|
+
import { FORM_CONTROL_SIZES } from './constants';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
interface Props<As extends React.ElementType> {
|
|
8
|
+
/** Specifies contents of the component. */
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
/** Specifies class name to append to the base element. */
|
|
11
|
+
className?: string;
|
|
12
|
+
/** Specifies base element for the component. */
|
|
13
|
+
as?: As;
|
|
14
|
+
/** Specifies id to use in the group, it will be used as `htmlFor` in `FormLabel` and as `id` in input components.
|
|
15
|
+
* Will be autogenerated if none is supplied. */
|
|
16
|
+
controlId?: string;
|
|
17
|
+
/** Specifies whether to display components in invalid state, this affects styling. */
|
|
18
|
+
isInvalid?: boolean;
|
|
19
|
+
/** Specifies whether to display components in valid state, this affects styling. */
|
|
20
|
+
isValid?: boolean;
|
|
21
|
+
/** Specifies size for the component. */
|
|
22
|
+
size?: typeof FORM_CONTROL_SIZES.SMALL | typeof FORM_CONTROL_SIZES.LARGE;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function FormGroup<As extends React.ElementType = 'div'>({
|
|
7
26
|
children,
|
|
8
27
|
controlId,
|
|
9
|
-
isInvalid,
|
|
10
|
-
isValid,
|
|
28
|
+
isInvalid = false,
|
|
29
|
+
isValid = false,
|
|
11
30
|
size,
|
|
12
31
|
as,
|
|
13
32
|
...props
|
|
14
|
-
}) {
|
|
33
|
+
}: Props<As> & React.ComponentPropsWithoutRef<As>) {
|
|
15
34
|
return React.createElement(
|
|
16
|
-
as,
|
|
35
|
+
as ?? 'div',
|
|
17
36
|
{
|
|
18
37
|
...props,
|
|
19
38
|
className: classNames('pgn__form-group', props.className),
|
|
@@ -50,13 +69,4 @@ FormGroup.propTypes = {
|
|
|
50
69
|
size: PropTypes.oneOf(SIZE_CHOICES),
|
|
51
70
|
};
|
|
52
71
|
|
|
53
|
-
FormGroup.defaultProps = {
|
|
54
|
-
as: 'div',
|
|
55
|
-
className: undefined,
|
|
56
|
-
controlId: undefined,
|
|
57
|
-
isInvalid: false,
|
|
58
|
-
isValid: false,
|
|
59
|
-
size: undefined,
|
|
60
|
-
};
|
|
61
|
-
|
|
62
72
|
export default FormGroup;
|
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
import React, {
|
|
2
2
|
useState, useEffect, useMemo, useCallback,
|
|
3
3
|
} from 'react';
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
4
|
import classNames from 'classnames';
|
|
6
5
|
import { newId } from '../utils';
|
|
7
6
|
import { useIdList, omitUndefinedProperties } from './fieldUtils';
|
|
8
7
|
import { FORM_CONTROL_SIZES } from './constants';
|
|
9
8
|
|
|
10
|
-
const identityFn = props => props;
|
|
9
|
+
const identityFn = (props: Record<string, any>) => props;
|
|
11
10
|
const noop = () => {};
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
interface FormGroupContextData {
|
|
13
|
+
getControlProps: (props: Record<string, any>) => Record<string, any>;
|
|
14
|
+
getLabelProps: (props: React.ComponentPropsWithoutRef<'label'>) => React.ComponentPropsWithoutRef<'label'>;
|
|
15
|
+
getDescriptorProps: (props: Record<string, any>) => Record<string, any>;
|
|
16
|
+
useSetIsControlGroupEffect: (isControlGroup: boolean) => void;
|
|
17
|
+
isControlGroup?: boolean;
|
|
18
|
+
controlId?: string;
|
|
19
|
+
isInvalid?: boolean;
|
|
20
|
+
isValid?: boolean;
|
|
21
|
+
size?: string;
|
|
22
|
+
hasFormGroupProvider?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const FormGroupContext = React.createContext<FormGroupContextData>({
|
|
14
26
|
getControlProps: identityFn,
|
|
15
27
|
useSetIsControlGroupEffect: noop,
|
|
16
28
|
getLabelProps: identityFn,
|
|
@@ -20,13 +32,15 @@ const FormGroupContext = React.createContext({
|
|
|
20
32
|
|
|
21
33
|
const useFormGroupContext = () => React.useContext(FormGroupContext);
|
|
22
34
|
|
|
23
|
-
|
|
35
|
+
function useStateEffect<ValueType extends any>(
|
|
36
|
+
initialState: ValueType,
|
|
37
|
+
): [value: ValueType, setter: (v: ValueType) => void] {
|
|
24
38
|
const [state, setState] = useState(initialState);
|
|
25
|
-
const useSetStateEffect = (newState) => {
|
|
39
|
+
const useSetStateEffect = (newState: ValueType) => {
|
|
26
40
|
useEffect(() => setState(newState), [newState]);
|
|
27
41
|
};
|
|
28
42
|
return [state, useSetStateEffect];
|
|
29
|
-
}
|
|
43
|
+
}
|
|
30
44
|
|
|
31
45
|
function FormGroupContextProvider({
|
|
32
46
|
children,
|
|
@@ -34,6 +48,12 @@ function FormGroupContextProvider({
|
|
|
34
48
|
isInvalid,
|
|
35
49
|
isValid,
|
|
36
50
|
size,
|
|
51
|
+
}: {
|
|
52
|
+
children: React.ReactNode;
|
|
53
|
+
controlId?: string;
|
|
54
|
+
isInvalid?: boolean;
|
|
55
|
+
isValid?: boolean;
|
|
56
|
+
size?: typeof FORM_CONTROL_SIZES.SMALL | typeof FORM_CONTROL_SIZES.LARGE;
|
|
37
57
|
}) {
|
|
38
58
|
const controlId = useMemo(() => explicitControlId || newId('form-field'), [explicitControlId]);
|
|
39
59
|
const [describedByIds, registerDescriptorId] = useIdList(controlId);
|
|
@@ -62,7 +82,7 @@ function FormGroupContextProvider({
|
|
|
62
82
|
controlId,
|
|
63
83
|
]);
|
|
64
84
|
|
|
65
|
-
const getLabelProps = (labelProps) => {
|
|
85
|
+
const getLabelProps = (labelProps: React.ComponentPropsWithoutRef<'label'>) => {
|
|
66
86
|
const id = registerLabelerId(labelProps?.id);
|
|
67
87
|
if (isControlGroup) {
|
|
68
88
|
return { ...labelProps, id };
|
|
@@ -70,12 +90,12 @@ function FormGroupContextProvider({
|
|
|
70
90
|
return { ...labelProps, htmlFor: controlId };
|
|
71
91
|
};
|
|
72
92
|
|
|
73
|
-
const getDescriptorProps = (descriptorProps) => {
|
|
93
|
+
const getDescriptorProps = (descriptorProps: Record<string, any>) => {
|
|
74
94
|
const id = registerDescriptorId(descriptorProps?.id);
|
|
75
95
|
return { ...descriptorProps, id };
|
|
76
96
|
};
|
|
77
97
|
|
|
78
|
-
const contextValue = {
|
|
98
|
+
const contextValue: FormGroupContextData = {
|
|
79
99
|
getControlProps,
|
|
80
100
|
getLabelProps,
|
|
81
101
|
getDescriptorProps,
|
|
@@ -95,24 +115,6 @@ function FormGroupContextProvider({
|
|
|
95
115
|
);
|
|
96
116
|
}
|
|
97
117
|
|
|
98
|
-
FormGroupContextProvider.propTypes = {
|
|
99
|
-
children: PropTypes.node.isRequired,
|
|
100
|
-
controlId: PropTypes.string,
|
|
101
|
-
isInvalid: PropTypes.bool,
|
|
102
|
-
isValid: PropTypes.bool,
|
|
103
|
-
size: PropTypes.oneOf([
|
|
104
|
-
FORM_CONTROL_SIZES.SMALL,
|
|
105
|
-
FORM_CONTROL_SIZES.LARGE,
|
|
106
|
-
]),
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
FormGroupContextProvider.defaultProps = {
|
|
110
|
-
controlId: undefined,
|
|
111
|
-
isInvalid: undefined,
|
|
112
|
-
isValid: undefined,
|
|
113
|
-
size: undefined,
|
|
114
|
-
};
|
|
115
|
-
|
|
116
118
|
export {
|
|
117
119
|
FormGroupContext,
|
|
118
120
|
FormGroupContextProvider,
|
|
@@ -4,7 +4,14 @@ import classNames from 'classnames';
|
|
|
4
4
|
import { useFormGroupContext } from './FormGroupContext';
|
|
5
5
|
import { FORM_CONTROL_SIZES } from './constants';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
interface Props {
|
|
8
|
+
/** Specifies contents of the component. */
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
/** Specifies whether the component should be displayed with inline styling. */
|
|
11
|
+
isInline?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function FormLabel({ children, isInline = false, ...props }: Props & React.ComponentPropsWithoutRef<'label'>) {
|
|
8
15
|
const { size, isControlGroup, getLabelProps } = useFormGroupContext();
|
|
9
16
|
const className = classNames(
|
|
10
17
|
'pgn__form-label',
|
|
@@ -20,8 +27,6 @@ function FormLabel({ children, isInline, ...props }) {
|
|
|
20
27
|
return React.createElement(componentType, labelProps, children);
|
|
21
28
|
}
|
|
22
29
|
|
|
23
|
-
const SIZE_CHOICES = ['sm', 'lg'];
|
|
24
|
-
|
|
25
30
|
FormLabel.propTypes = {
|
|
26
31
|
/** Specifies class name to append to the base element. */
|
|
27
32
|
className: PropTypes.string,
|
|
@@ -29,14 +34,6 @@ FormLabel.propTypes = {
|
|
|
29
34
|
children: PropTypes.node.isRequired,
|
|
30
35
|
/** Specifies whether the component should be displayed with inline styling. */
|
|
31
36
|
isInline: PropTypes.bool,
|
|
32
|
-
/** Specifies size of the component. */
|
|
33
|
-
size: PropTypes.oneOf(SIZE_CHOICES),
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
FormLabel.defaultProps = {
|
|
37
|
-
isInline: false,
|
|
38
|
-
size: undefined,
|
|
39
|
-
className: undefined,
|
|
40
37
|
};
|
|
41
38
|
|
|
42
39
|
export default FormLabel;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
const FORM_CONTROL_SIZES = {
|
|
1
|
+
export const FORM_CONTROL_SIZES = {
|
|
3
2
|
SMALL: 'sm',
|
|
4
3
|
LARGE: 'lg',
|
|
5
|
-
};
|
|
4
|
+
} as const;
|
|
6
5
|
|
|
7
|
-
const FORM_TEXT_TYPES = {
|
|
6
|
+
export const FORM_TEXT_TYPES = {
|
|
8
7
|
DEFAULT: 'default',
|
|
9
8
|
VALID: 'valid',
|
|
10
9
|
INVALID: 'invalid',
|
|
@@ -12,6 +11,4 @@ const FORM_TEXT_TYPES = {
|
|
|
12
11
|
CRITERIA_EMPTY: 'criteria-empty',
|
|
13
12
|
CRITERIA_VALID: 'criteria-valid',
|
|
14
13
|
CRITERIA_INVALID: 'criteria-invalid',
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export { FORM_CONTROL_SIZES, FORM_TEXT_TYPES };
|
|
14
|
+
} as const;
|
|
@@ -8,10 +8,10 @@ const omitUndefinedProperties = (obj = {}) => Object.entries(obj)
|
|
|
8
8
|
acc[key] = value;
|
|
9
9
|
}
|
|
10
10
|
return acc;
|
|
11
|
-
}, {});
|
|
11
|
+
}, {} as Record<string, any>);
|
|
12
12
|
|
|
13
|
-
const callAllHandlers = (...handlers) => {
|
|
14
|
-
const unifiedEventHandler = (event) => {
|
|
13
|
+
const callAllHandlers = <EventType extends Object>(...handlers: ((event: EventType) => void)[]) => {
|
|
14
|
+
const unifiedEventHandler = (event: EventType) => {
|
|
15
15
|
handlers
|
|
16
16
|
.filter(handler => typeof handler === 'function')
|
|
17
17
|
.forEach(handler => handler(event));
|
|
@@ -19,16 +19,19 @@ const callAllHandlers = (...handlers) => {
|
|
|
19
19
|
return unifiedEventHandler;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
const useHasValue = ({ defaultValue, value }) => {
|
|
22
|
+
const useHasValue = <ValueType>({ defaultValue, value }: { defaultValue?: ValueType, value?: ValueType }) => {
|
|
23
23
|
const [hasUncontrolledValue, setHasUncontrolledValue] = useState(!!defaultValue || defaultValue === 0);
|
|
24
24
|
const hasValue = !!value || value === 0 || hasUncontrolledValue;
|
|
25
|
-
const handleInputEvent = (e) => setHasUncontrolledValue(e.target.value);
|
|
25
|
+
const handleInputEvent = (e: React.ChangeEvent<HTMLInputElement>) => setHasUncontrolledValue(!!e.target.value);
|
|
26
26
|
return [hasValue, handleInputEvent];
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
const useIdList = (
|
|
29
|
+
const useIdList = (
|
|
30
|
+
uniqueIdPrefix: string,
|
|
31
|
+
initialList?: string[],
|
|
32
|
+
): [idList: string[], useRegisteredId: (id: string | undefined) => string | undefined] => {
|
|
30
33
|
const [idList, setIdList] = useState(initialList || []);
|
|
31
|
-
const addId = (idToAdd) => {
|
|
34
|
+
const addId = (idToAdd: string) => {
|
|
32
35
|
setIdList(oldIdList => [...oldIdList, idToAdd]);
|
|
33
36
|
return idToAdd;
|
|
34
37
|
};
|
|
@@ -36,17 +39,17 @@ const useIdList = (uniqueIdPrefix, initialList) => {
|
|
|
36
39
|
const idToAdd = newId(`${uniqueIdPrefix}-`);
|
|
37
40
|
return addId(idToAdd);
|
|
38
41
|
};
|
|
39
|
-
const removeId = (idToRemove) => {
|
|
42
|
+
const removeId = (idToRemove: string | undefined) => {
|
|
40
43
|
setIdList(oldIdList => oldIdList.filter(id => id !== idToRemove));
|
|
41
44
|
};
|
|
42
45
|
|
|
43
|
-
const useRegisteredId = (explicitlyRegisteredId) => {
|
|
46
|
+
const useRegisteredId = (explicitlyRegisteredId: string | undefined) => {
|
|
44
47
|
const [registeredId, setRegisteredId] = useState(explicitlyRegisteredId);
|
|
45
48
|
useEffect(() => {
|
|
46
49
|
if (explicitlyRegisteredId) {
|
|
47
50
|
addId(explicitlyRegisteredId);
|
|
48
51
|
} else if (!registeredId) {
|
|
49
|
-
setRegisteredId(getNewId(
|
|
52
|
+
setRegisteredId(getNewId());
|
|
50
53
|
}
|
|
51
54
|
return () => removeId(registeredId);
|
|
52
55
|
}, [registeredId, explicitlyRegisteredId]);
|
|
@@ -56,7 +59,7 @@ const useIdList = (uniqueIdPrefix, initialList) => {
|
|
|
56
59
|
return [idList, useRegisteredId];
|
|
57
60
|
};
|
|
58
61
|
|
|
59
|
-
const mergeAttributeValues = (...values) => {
|
|
62
|
+
const mergeAttributeValues = (...values: (string | undefined)[]) => {
|
|
60
63
|
const mergedValues = classNames(values);
|
|
61
64
|
return mergedValues || undefined;
|
|
62
65
|
};
|
|
@@ -49,7 +49,9 @@ or [select attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element
|
|
|
49
49
|
() => {
|
|
50
50
|
{/* start example state */}
|
|
51
51
|
const [type, setType] = useState('default');
|
|
52
|
+
const [value, setValue] = useState('');
|
|
52
53
|
{/* end example state */}
|
|
54
|
+
const handleChange = (e) => setValue(e.target.value);
|
|
53
55
|
|
|
54
56
|
const inputs = {
|
|
55
57
|
default: (
|
|
@@ -144,8 +146,6 @@ or [select attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element
|
|
|
144
146
|
</Form.Group>
|
|
145
147
|
</>),
|
|
146
148
|
};
|
|
147
|
-
const [value, setValue] = useState('');
|
|
148
|
-
const handleChange = (e) => setValue(e.target.value);
|
|
149
149
|
return (
|
|
150
150
|
<>
|
|
151
151
|
{/* start example form block */}
|
|
@@ -172,7 +172,9 @@ See [react-imask](https://imask.js.org) for documentation on available props.
|
|
|
172
172
|
() => {
|
|
173
173
|
{/* start example state */}
|
|
174
174
|
const [maskType, setMaskType] = useState('phone');
|
|
175
|
+
const [value, setValue] = useState('');
|
|
175
176
|
{/* end example state */}
|
|
177
|
+
const handleChange = (e) => setValue(e.target.value);
|
|
176
178
|
|
|
177
179
|
const inputsWithMask = {
|
|
178
180
|
phone: (
|
|
@@ -255,10 +257,6 @@ See [react-imask](https://imask.js.org) for documentation on available props.
|
|
|
255
257
|
),
|
|
256
258
|
};
|
|
257
259
|
|
|
258
|
-
const [value, setValue] = useState('');
|
|
259
|
-
|
|
260
|
-
const handleChange = (e) => setValue(e.target.value);
|
|
261
|
-
|
|
262
260
|
return (
|
|
263
261
|
<>
|
|
264
262
|
{/* start example form block */}
|