@openedx/paragon 22.11.1 → 22.12.0
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/README.md +8 -0
- package/dist/Card/CardFallbackDefaultImage.js +1 -0
- package/dist/Card/CardImageCap.js +1 -1
- package/dist/Card/CardImageCap.js.map +1 -1
- 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.js +1 -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/package.json +1 -1
- package/src/Card/CardFallbackDefaultImage.js +1 -0
- package/src/Card/CardImageCap.jsx +1 -1
- package/src/Card/tests/CardImageCap.test.jsx +3 -3
- 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/{index.jsx → index.tsx} +33 -1
- package/src/IconButton/index.tsx +1 -1
- package/src/index.d.ts +22 -22
- package/src/index.js +22 -22
- package/dist/Card/fallback-default.png +0 -0
- package/src/Card/fallback-default.png +0 -0
- /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/Form/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["BootstrapForm","FormControl","FormLabel","FormGroup","FormControlFeedback","FormText","FormControlDecoratorGroup","FormRadio","RadioControl","FormRadioSet","FormRadioSetContext","FormAutosuggest","FormAutosuggestOption","FormCheckbox","CheckboxControl","FormSwitch","SwitchControl","FormCheckboxSet","FormSwitchSet","FormCheckboxSetContext","useCheckboxSetValues","Form","Control","Radio","RadioSet","Autosuggest","AutosuggestOption","Checkbox","CheckboxSet","Switch","SwitchSet","Label","Group","Text","default","FormCheck","FormFile","InputGroup"],"sources":["../../src/Form/index.tsx"],"sourcesContent":["import BootstrapForm, { FormProps } from 'react-bootstrap/Form';\nimport { ComponentWithAsProp } from '../utils/types/bootstrap';\n// TODO: add more typing and remove the @ts-ignore directives here\n// @ts-ignore\nimport FormControl from './FormControl';\nimport FormLabel from './FormLabel';\nimport FormGroup from './FormGroup';\n// @ts-ignore\nimport FormControlFeedback from './FormControlFeedback';\n// @ts-ignore\nimport FormText from './FormText';\n// @ts-ignore\nimport FormControlDecoratorGroup from './FormControlDecoratorGroup';\n// @ts-ignore\nimport FormRadio, { RadioControl } from './FormRadio';\n// @ts-ignore\nimport FormRadioSet from './FormRadioSet';\n// @ts-ignore\nimport FormRadioSetContext from './FormRadioSetContext';\n// @ts-ignore\nimport FormAutosuggest from './FormAutosuggest';\n// @ts-ignore\nimport FormAutosuggestOption from './FormAutosuggestOption';\n// @ts-ignore\nimport FormCheckbox, { CheckboxControl } from './FormCheckbox';\n// @ts-ignore\nimport FormSwitch, { SwitchControl } from './FormSwitch';\n// @ts-ignore\nimport FormCheckboxSet from './FormCheckboxSet';\n// @ts-ignore\nimport FormSwitchSet from './FormSwitchSet';\n// @ts-ignore\nimport FormCheckboxSetContext from './FormCheckboxSetContext';\n// @ts-ignore\nimport useCheckboxSetValues from './useCheckboxSetValues';\n\nconst Form = BootstrapForm as any as ComponentWithAsProp<'form', FormProps> & {\n Control: typeof FormControl;\n Radio: typeof FormRadio;\n RadioSet: typeof FormRadioSet;\n Autosuggest: typeof FormAutosuggest;\n AutosuggestOption: typeof FormAutosuggestOption;\n Checkbox: typeof FormCheckbox;\n CheckboxSet: typeof FormCheckboxSet;\n Row: typeof BootstrapForm.Row;\n Switch: typeof FormSwitch;\n SwitchSet: typeof FormSwitchSet;\n Label: typeof FormLabel;\n Group: typeof FormGroup;\n Text: typeof FormText;\n};\nForm.Control = FormControl;\nForm.Radio = FormRadio;\nForm.RadioSet = FormRadioSet;\nForm.Autosuggest = FormAutosuggest;\nForm.AutosuggestOption = FormAutosuggestOption;\nForm.Checkbox = FormCheckbox;\nForm.CheckboxSet = FormCheckboxSet;\nForm.Switch = FormSwitch;\nForm.SwitchSet = FormSwitchSet;\nForm.Label = FormLabel;\nForm.Group = FormGroup;\nForm.Text = FormText;\n\nexport default Form;\nexport {\n FormControl,\n FormLabel,\n FormRadio,\n FormRadioSet,\n FormRadioSetContext,\n FormCheckbox,\n FormSwitch,\n FormAutosuggest,\n FormAutosuggestOption,\n FormCheckboxSet,\n FormCheckboxSetContext,\n FormGroup,\n FormControlDecoratorGroup,\n FormControlFeedback,\n FormText,\n CheckboxControl,\n RadioControl,\n SwitchControl,\n FormSwitchSet,\n useCheckboxSetValues,\n};\n\nexport { default as FormCheck } from 'react-bootstrap/FormCheck';\nexport { default as FormFile } from 'react-bootstrap/FormFile';\nexport { default as InputGroup } from 'react-bootstrap/InputGroup';\n"],"mappings":"AAAA,OAAOA,aAAa,MAAqB,sBAAsB;AAE/D;AACA;AACA,OAAOC,WAAW,MAAM,eAAe;AACvC,OAAOC,SAAS,MAAM,aAAa;AACnC,OAAOC,SAAS,MAAM,aAAa;AACnC;AACA,OAAOC,mBAAmB,MAAM,uBAAuB;AACvD;AACA,OAAOC,QAAQ,MAAM,YAAY;AACjC;AACA,OAAOC,yBAAyB,MAAM,6BAA6B;AACnE;AACA,OAAOC,SAAS,IAAIC,YAAY,QAAQ,aAAa;AACrD;AACA,OAAOC,YAAY,MAAM,gBAAgB;AACzC;AACA,OAAOC,mBAAmB,MAAM,uBAAuB;AACvD;AACA,OAAOC,eAAe,MAAM,mBAAmB;AAC/C;AACA,OAAOC,qBAAqB,MAAM,yBAAyB;AAC3D;AACA,OAAOC,YAAY,IAAIC,eAAe,QAAQ,gBAAgB;AAC9D;AACA,OAAOC,UAAU,IAAIC,aAAa,QAAQ,cAAc;AACxD;AACA,OAAOC,eAAe,MAAM,mBAAmB;AAC/C;AACA,OAAOC,aAAa,MAAM,iBAAiB;AAC3C;AACA,OAAOC,sBAAsB,MAAM,0BAA0B;AAC7D;AACA,OAAOC,oBAAoB,MAAM,wBAAwB;AAEzD,MAAMC,IAAI,GAAGrB,aAcZ;AACDqB,IAAI,CAACC,OAAO,GAAGrB,WAAW;AAC1BoB,IAAI,CAACE,KAAK,GAAGhB,SAAS;AACtBc,IAAI,CAACG,QAAQ,GAAGf,YAAY;AAC5BY,IAAI,CAACI,WAAW,GAAGd,eAAe;AAClCU,IAAI,CAACK,iBAAiB,GAAGd,qBAAqB;AAC9CS,IAAI,CAACM,QAAQ,GAAGd,YAAY;AAC5BQ,IAAI,CAACO,WAAW,GAAGX,eAAe;AAClCI,IAAI,CAACQ,MAAM,GAAGd,UAAU;AACxBM,IAAI,CAACS,SAAS,GAAGZ,aAAa;AAC9BG,IAAI,CAACU,KAAK,GAAG7B,SAAS;AACtBmB,IAAI,CAACW,KAAK,GAAG7B,SAAS;AACtBkB,IAAI,CAACY,IAAI,GAAG5B,QAAQ;AAEpB,eAAegB,IAAI;AACnB,SACEpB,WAAW,EACXC,SAAS,EACTK,SAAS,EACTE,YAAY,EACZC,mBAAmB,EACnBG,YAAY,EACZE,UAAU,EACVJ,eAAe,EACfC,qBAAqB,EACrBK,eAAe,EACfE,sBAAsB,EACtBhB,SAAS,EACTG,yBAAyB,EACzBF,mBAAmB,EACnBC,QAAQ,EACRS,eAAe,EACfN,YAAY,EACZQ,aAAa,EACbE,aAAa,EACbE,oBAAoB;AAGtB,SAASc,OAAO,IAAIC,SAAS,QAAQ,2BAA2B;AAChE,SAASD,OAAO,IAAIE,QAAQ,QAAQ,0BAA0B;AAC9D,SAASF,OAAO,IAAIG,UAAU,QAAQ,4BAA4B","ignoreList":[]}
|
package/dist/Form/messages.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { defineMessages } from 'react-intl';
|
|
2
|
-
|
|
3
2
|
const messages = defineMessages({
|
|
4
3
|
iconButtonOpened: {
|
|
5
4
|
id: 'pgn.FormAutosuggest.iconButtonOpened',
|
|
6
5
|
defaultMessage: 'Open the options menu',
|
|
7
|
-
description: 'A message shown in case when the autosuggest menu is closed.'
|
|
6
|
+
description: 'A message shown in case when the autosuggest menu is closed.'
|
|
8
7
|
},
|
|
9
8
|
iconButtonClosed: {
|
|
10
9
|
id: 'pgn.FormAutosuggest.iconButtonClosed',
|
|
11
10
|
defaultMessage: 'Close the options menu',
|
|
12
|
-
description: 'A message shown in case when the autosuggest menu is opened.'
|
|
13
|
-
}
|
|
11
|
+
description: 'A message shown in case when the autosuggest menu is opened.'
|
|
12
|
+
}
|
|
14
13
|
});
|
|
15
|
-
|
|
16
14
|
export default messages;
|
|
15
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","names":["defineMessages","messages","iconButtonOpened","id","defaultMessage","description","iconButtonClosed"],"sources":["../../src/Form/messages.ts"],"sourcesContent":["import { defineMessages } from 'react-intl';\n\nconst messages = defineMessages({\n iconButtonOpened: {\n id: 'pgn.FormAutosuggest.iconButtonOpened',\n defaultMessage: 'Open the options menu',\n description: 'A message shown in case when the autosuggest menu is closed.',\n },\n iconButtonClosed: {\n id: 'pgn.FormAutosuggest.iconButtonClosed',\n defaultMessage: 'Close the options menu',\n description: 'A message shown in case when the autosuggest menu is opened.',\n },\n});\n\nexport default messages;\n"],"mappings":"AAAA,SAASA,cAAc,QAAQ,YAAY;AAE3C,MAAMC,QAAQ,GAAGD,cAAc,CAAC;EAC9BE,gBAAgB,EAAE;IAChBC,EAAE,EAAE,sCAAsC;IAC1CC,cAAc,EAAE,uBAAuB;IACvCC,WAAW,EAAE;EACf,CAAC;EACDC,gBAAgB,EAAE;IAChBH,EAAE,EAAE,sCAAsC;IAC1CC,cAAc,EAAE,wBAAwB;IACxCC,WAAW,EAAE;EACf;AACF,CAAC,CAAC;AAEF,eAAeJ,QAAQ","ignoreList":[]}
|
package/dist/IconButton/index.js
CHANGED
|
@@ -93,7 +93,7 @@ IconButton.propTypes = {
|
|
|
93
93
|
size: PropTypes.oneOf(['sm', 'md', 'inline']),
|
|
94
94
|
/** whether to show the `IconButton` in an active state, whose styling is distinct from default state */
|
|
95
95
|
isActive: PropTypes.bool,
|
|
96
|
-
/** Used with
|
|
96
|
+
/** Used with `IconButtonToggle` */
|
|
97
97
|
value: PropTypes.string
|
|
98
98
|
};
|
|
99
99
|
/**
|
|
@@ -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","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,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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":[]}
|
|
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,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AO;MACNkD,EAAE,EAAG,sBAAqBL,gBAAiB,EAAE;MAC7ChC,OAAO,EAAEK,MAAM,GAAG,OAAO,GAAGY;IAAU,GAErCgB,cACM;EACT,gBAEFnD,KAAA,CAAAgC,aAAA,CAAC1B,UAAU;IAAA,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":[]}
|
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const cardSrcFallbackImg = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXwAAACMCAYAAAB/AhJnAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAH6SURBVHgB7dRBEYBADACxwuDf5j0QUXywiYhc7zk7APzd3gNAgvABIoQPECF8gAjhA0QIHyBC+AARwgeIED5AhPABIoQPECF8gAjhA0QIHyBC+AARwgeIED5AhPABIoQPECF8gAjhA0QIHyBC+AARwgeIED5AhPABIoQPECF8gAjhA0QIHyBC+AARwgeIED5AhPABIoQPECF8gAjhA0QIHyBC+AARwgeIED5AhPABIoQPECF8gAjhA0QIHyBC+AARwgeIED5AhPABIoQPECF8gAjhA0QIHyBC+AARwgeIED5AhPABIoQPECF8gAjhA0QIHyBC+AARwgeIED5AhPABIoQPECF8gAjhA0QIHyBC+AARwgeIED5AhPABIoQPECF8gAjhA0QIHyBC+AARwgeIED5AhPABIoQPECF8gAjhA0QIHyBC+AARwgeIED5AhPABIoQPECF8gAjhA0QIHyBC+AARwgeIED5AhPABIoQPECF8gAjhA0QIHyBC+AARwgeIED5AhPABIoQPECF8gAjhA0QIHyBC+AARwgeIED5AhPABIoQPECF8gAjhA0QIHyBC+AARwgeIED5AhPABIoQPECF8gAjhA0QIHyBC+AARwgeIED5AhPABIoQPECF8gAjhA0QIHyBC+AARwgeIED5AhPABIp4BaNpp2Q/3/wfPkGyXOQAAAABJRU5ErkJggg==';
|
|
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import Skeleton from 'react-loading-skeleton';
|
|
5
5
|
import CardContext from './CardContext';
|
|
6
|
-
import cardSrcFallbackImg from './
|
|
6
|
+
import { cardSrcFallbackImg } from './CardFallbackDefaultImage';
|
|
7
7
|
|
|
8
8
|
const SKELETON_HEIGHT_VALUE = 140;
|
|
9
9
|
const LOGO_SKELETON_HEIGHT_VALUE = 41;
|
|
@@ -3,6 +3,7 @@ import renderer from 'react-test-renderer';
|
|
|
3
3
|
import { render, fireEvent, screen } from '@testing-library/react';
|
|
4
4
|
import CardImageCap from '../CardImageCap';
|
|
5
5
|
import CardContext from '../CardContext';
|
|
6
|
+
import { cardSrcFallbackImg } from '../CardFallbackDefaultImage';
|
|
6
7
|
|
|
7
8
|
// eslint-disable-next-line react/prop-types
|
|
8
9
|
function CardImageCapWrapper({ orientation = 'vertical', isLoading, ...props }) {
|
|
@@ -119,13 +120,12 @@ describe('<CardImageCap />', () => {
|
|
|
119
120
|
expect(logoImg.className).toEqual('pgn__card-logo-cap');
|
|
120
121
|
});
|
|
121
122
|
|
|
122
|
-
it('
|
|
123
|
+
it('renders the default image if both src and fallbackSrc fail to load', () => {
|
|
123
124
|
render(<CardImageCapWrapper src="fakeURL" fallbackSrc="fakeURL" srcAlt="Src alt text" />);
|
|
124
125
|
|
|
125
126
|
const srcImg = screen.getByAltText('Src alt text');
|
|
126
127
|
fireEvent.load(srcImg);
|
|
127
128
|
fireEvent.error(srcImg);
|
|
128
|
-
|
|
129
|
-
expect(srcImg.src.endsWith('test-file-stub')).toEqual(true);
|
|
129
|
+
expect(srcImg.src).toEqual(cardSrcFallbackImg);
|
|
130
130
|
});
|
|
131
131
|
});
|
|
@@ -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
|
};
|