guestbell-forms 3.0.85 → 3.0.86
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/components/button/Button.js +21 -11
- package/build/components/button/Button.js.map +1 -1
- package/build/components/form/Form.d.ts +4 -2
- package/build/components/form/Form.js +36 -27
- package/build/components/form/Form.js.map +1 -1
- package/build/components/form/FormContext.d.ts +1 -14
- package/build/components/form/FormContext.js.map +1 -1
- package/build/components/form/FormValidationContext.d.ts +27 -0
- package/build/components/form/FormValidationContext.js +15 -0
- package/build/components/form/FormValidationContext.js.map +1 -0
- package/build/components/form/FormValidationSummary.d.ts +3 -3
- package/build/components/form/FormValidationSummary.js +3 -3
- package/build/components/form/FormValidationSummary.js.map +1 -1
- package/build/components/form/withFormContext.d.ts +1 -1
- package/build/components/form/withFormContext.js.map +1 -1
- package/build/components/form/withFormValidationContext.d.ts +3 -0
- package/build/components/form/withFormValidationContext.js +25 -0
- package/build/components/form/withFormValidationContext.js.map +1 -0
- package/build/components/submit/Submit.d.ts +3 -2
- package/build/components/submit/Submit.js +5 -5
- package/build/components/submit/Submit.js.map +1 -1
- package/build/dist/report.html +1 -1
- package/package.json +1 -1
- package/src/lib/components/button/Button.tsx +16 -13
- package/src/lib/components/form/Form.tsx +48 -32
- package/src/lib/components/form/FormContext.ts +4 -18
- package/src/lib/components/form/FormValidationContext.ts +40 -0
- package/src/lib/components/form/FormValidationSummary.tsx +12 -7
- package/src/lib/components/form/withFormContext.tsx +14 -11
- package/src/lib/components/form/withFormValidationContext.tsx +29 -0
- package/src/lib/components/submit/Submit.tsx +9 -7
@@ -8,6 +8,7 @@ var React = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _withThemeContext = require("../themeProvider/withThemeContext");
|
9
9
|
var _reactInk = _interopRequireDefault(require("react-ink"));
|
10
10
|
var _classnames = _interopRequireDefault(require("classnames"));
|
11
|
+
const _excluded = ["disabled"]; // Libs
|
11
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
12
13
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
13
14
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
@@ -16,19 +17,28 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
16
17
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
17
18
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
18
19
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
19
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
20
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
21
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
22
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
20
23
|
// Misc
|
21
24
|
|
22
|
-
const DefaultButtonComponent = /*#__PURE__*/React.forwardRef((props, ref) =>
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
}
|
25
|
+
const DefaultButtonComponent = /*#__PURE__*/React.forwardRef((props, ref) => {
|
26
|
+
const _ref = props.buttonProps ?? {},
|
27
|
+
{
|
28
|
+
disabled
|
29
|
+
} = _ref,
|
30
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
31
|
+
return /*#__PURE__*/React.createElement("button", _extends({
|
32
|
+
ref: ref
|
33
|
+
// tslint:disable-next-line:no-any
|
34
|
+
}, rest, props.id && {
|
35
|
+
id: props.id
|
36
|
+
}, {
|
37
|
+
className: props.className,
|
38
|
+
onClick: props.onClick,
|
39
|
+
style: props.style
|
40
|
+
}), props.children);
|
41
|
+
});
|
32
42
|
class Button extends React.PureComponent {
|
33
43
|
constructor(props) {
|
34
44
|
super(props);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Button.js","names":["React","_interopRequireWildcard","require","_withThemeContext","_reactInk","_interopRequireDefault","_classnames","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","ownKeys","object","enumerableOnly","keys","getOwnPropertySymbols","symbols","filter","sym","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","value","_toPropertyKey","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","TypeError","Number","_extends","assign","bind","DefaultButtonComponent","forwardRef","props","ref","createElement","buttonProps","id","className","onClick","style","children","Button","PureComponent","constructor","preventMultipleClickTimer","handleClick","state","disabledAfterClick","render","_this$props$buttonPro","disabled","disableAfterClick","btnClassName","classNames","getButtonClassName","circular","small","noShadow","blank","unobtrusive","outlined","dropdown","icon","hero","text","button","Component","tabIndex","noRipples","Ink","tooltip","disableTooltip","_document","Tippy","content","placement","animation","arrow","duration","delay","distance","interactive","appendTo","document","body","tooltipProps","componentWillUnmount","clearTimeout","e","preventsDefault","preventDefault","disableAfterClickMs","setState","setTimeout","type","exports","defaultProps","role","_default","withThemeContext"],"sources":["../../../src/lib/components/button/Button.tsx"],"sourcesContent":["// Libs\r\nimport * as React from 'react';\r\nimport type { TippyProps } from '@tippy.js/react';\r\nimport { withThemeContext } from '../themeProvider/withThemeContext';\r\nimport { ThemeContextProps } from '../themeProvider/ThemeContext';\r\nimport Ink from 'react-ink';\r\nimport classNames from 'classnames';\r\n\r\n// Misc\r\n\r\nexport type ButtonTypes =\r\n | 'primary'\r\n | 'success'\r\n | 'error'\r\n | 'warning'\r\n | 'info'\r\n | 'gray'\r\n | 'white'\r\n | 'black'\r\n | 'none';\r\n\r\nexport type ButtonComponentProps = {\r\n id?: string;\r\n onClick: (e: React.MouseEvent<HTMLElement>) => void;\r\n className: string;\r\n buttonProps: React.ButtonHTMLAttributes<HTMLButtonElement>;\r\n children: React.ReactNode;\r\n style: React.CSSProperties;\r\n};\r\n\r\nexport type ButtonProps = React.PropsWithChildren<\r\n {\r\n id?: string;\r\n onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;\r\n style?: React.CSSProperties;\r\n className?: string;\r\n disabled?: boolean;\r\n type?: ButtonTypes;\r\n circular?: boolean;\r\n noRipples?: boolean;\r\n small?: boolean;\r\n icon?: boolean;\r\n outlined?: boolean;\r\n disableAfterClickMs?: number;\r\n disableAfterClick?: boolean;\r\n buttonProps?: React.ButtonHTMLAttributes<HTMLButtonElement>;\r\n text?: boolean;\r\n hero?: boolean;\r\n noShadow?: boolean;\r\n blank?: boolean;\r\n unobtrusive?: boolean;\r\n dropdown?: boolean;\r\n Component?: React.FC<ButtonComponentProps>;\r\n tooltip?: JSX.Element | string;\r\n disableTooltip?: boolean;\r\n tooltipProps?: TippyProps;\r\n preventsDefault?: boolean;\r\n } & ThemeContextProps\r\n>;\r\n\r\nexport interface ButtonState {\r\n disabledAfterClick: boolean;\r\n}\r\n\r\nconst DefaultButtonComponent: React.FC<ButtonComponentProps> = React.forwardRef(\r\n (props, ref) => (\r\n <button\r\n ref={ref}\r\n // tslint:disable-next-line:no-any\r\n {...((props.buttonProps ? props.buttonProps : {}) as any)}\r\n {...(props.id && { id: props.id })}\r\n className={props.className}\r\n onClick={props.onClick}\r\n style={props.style}\r\n >\r\n {props.children}\r\n </button>\r\n )\r\n);\r\n\r\nexport class Button extends React.PureComponent<ButtonProps, ButtonState> {\r\n public static defaultProps: ButtonProps = {\r\n disabled: false,\r\n className: '',\r\n onClick: () => null,\r\n circular: false,\r\n noRipples: false,\r\n small: false,\r\n disableAfterClickMs: 100,\r\n disableAfterClick: false,\r\n Component: DefaultButtonComponent,\r\n buttonProps: {\r\n type: 'button',\r\n role: 'button',\r\n tabIndex: 0,\r\n },\r\n type: 'none',\r\n preventsDefault: true,\r\n };\r\n\r\n private preventMultipleClickTimer: number;\r\n\r\n constructor(props: ButtonProps) {\r\n super(props);\r\n this.handleClick = this.handleClick.bind(this);\r\n this.state = {\r\n disabledAfterClick: false,\r\n };\r\n }\r\n\r\n public render() {\r\n const disabled =\r\n this.props.disabled ||\r\n (this.props.disableAfterClick && this.state.disabledAfterClick);\r\n let btnClassName = classNames([\r\n 'guestbell-btn',\r\n this.getButtonClassName(),\r\n this.props.className,\r\n { ['guestbell-btn--disabled']: disabled },\r\n { ['guestbell-btn--circular']: this.props.circular },\r\n { ['guestbell-btn--small']: this.props.small },\r\n { ['guestbell-btn--no-shadow']: this.props.noShadow },\r\n { ['guestbell-btn--blank']: this.props.blank },\r\n { ['guestbell-btn--unobtrusive']: this.props.unobtrusive },\r\n { ['guestbell-btn--outlined']: this.props.outlined },\r\n { ['guestbell-btn--dropdown']: this.props.dropdown },\r\n { ['guestbell-btn--icon']: this.props.icon },\r\n { ['guestbell-btn--hero']: this.props.hero },\r\n { ['guestbell-btn--text']: this.props.text },\r\n ]);\r\n const button = (\r\n <this.props.Component\r\n {...(this.props.id && { id: this.props.id })}\r\n onClick={this.handleClick}\r\n buttonProps={{\r\n ...this.props.buttonProps,\r\n disabled: this.props.disabled,\r\n tabIndex: !disabled ? this.props.buttonProps?.tabIndex : -1,\r\n }}\r\n className={btnClassName}\r\n style={this.props.style}\r\n >\r\n {!this.props.noRipples && !disabled && Ink && <Ink />}\r\n {this.props.children}\r\n </this.props.Component>\r\n );\r\n if (this.props.tooltip && !this.props.disableTooltip) {\r\n const Tippy = require('@tippy.js/react').default;\r\n return (\r\n <Tippy\r\n content={this.props.tooltip}\r\n placement=\"bottom\"\r\n animation=\"scale-subtle\"\r\n arrow={false}\r\n duration={200}\r\n delay={[75, 0]}\r\n distance={8}\r\n interactive={true}\r\n appendTo={document?.body}\r\n {...this.props.tooltipProps}\r\n >\r\n {button}\r\n </Tippy>\r\n );\r\n }\r\n return button;\r\n }\r\n\r\n public componentWillUnmount() {\r\n clearTimeout(this.preventMultipleClickTimer);\r\n }\r\n\r\n private handleClick(e: React.MouseEvent<HTMLButtonElement>) {\r\n if (this.props.preventsDefault) {\r\n e.preventDefault();\r\n }\r\n if (!this.state.disabledAfterClick && !this.props.disabled) {\r\n this.props.onClick && this.props.onClick(e);\r\n if (this.props.disableAfterClickMs !== 0) {\r\n this.setState({ disabledAfterClick: true });\r\n this.preventMultipleClickTimer = setTimeout(() => {\r\n this.setState({ disabledAfterClick: false });\r\n }, this.props.disableAfterClickMs) as unknown as number;\r\n }\r\n }\r\n }\r\n\r\n private getButtonClassName() {\r\n return this.props.type && 'guestbell-btn-' + this.props.type;\r\n }\r\n}\r\nexport default withThemeContext<ButtonProps, InstanceType<typeof Button>>(\r\n Button,\r\n 'button'\r\n);\r\n"],"mappings":";;;;;;AACA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,iBAAA,GAAAD,OAAA;AAEA,IAAAE,SAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,WAAA,GAAAD,sBAAA,CAAAH,OAAA;AAAoC,SAAAG,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAV,wBAAAM,GAAA,EAAAI,WAAA,SAAAA,WAAA,IAAAJ,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAQ,KAAA,GAAAL,wBAAA,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,KAAK,EAAE,KAAK;EACZmC,mBAAmB,EAAE,GAAG;EACxBxC,iBAAiB,EAAE,KAAK;EACxBe,SAAS,EAAEpC,sBAAsB;EACjCK,WAAW,EAAE;IACX2D,IAAI,EAAE,QAAQ;IACdG,IAAI,EAAE,QAAQ;IACd9B,QAAQ,EAAE;EACZ,CAAC;EACD2B,IAAI,EAAE,MAAM;EACZL,eAAe,EAAE;AACnB,CAAC;AAAA,IAAAS,QAAA,GA6FY,IAAAC,kCAAgB,EAC7B1D,MAAM,EACN,QACF,CAAC;AAAAsD,OAAA,CAAA7H,OAAA,GAAAgI,QAAA"}
|
1
|
+
{"version":3,"file":"Button.js","names":["React","_interopRequireWildcard","require","_withThemeContext","_reactInk","_interopRequireDefault","_classnames","_excluded","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","ownKeys","object","enumerableOnly","keys","getOwnPropertySymbols","symbols","filter","sym","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","value","_toPropertyKey","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","TypeError","Number","_extends","assign","bind","_objectWithoutProperties","excluded","_objectWithoutPropertiesLoose","sourceSymbolKeys","indexOf","propertyIsEnumerable","sourceKeys","DefaultButtonComponent","forwardRef","props","ref","_ref","buttonProps","disabled","rest","createElement","id","className","onClick","style","children","Button","PureComponent","constructor","preventMultipleClickTimer","handleClick","state","disabledAfterClick","render","_this$props$buttonPro","disableAfterClick","btnClassName","classNames","getButtonClassName","circular","small","noShadow","blank","unobtrusive","outlined","dropdown","icon","hero","text","button","Component","tabIndex","noRipples","Ink","tooltip","disableTooltip","_document","Tippy","content","placement","animation","arrow","duration","delay","distance","interactive","appendTo","document","body","tooltipProps","componentWillUnmount","clearTimeout","e","preventsDefault","preventDefault","disableAfterClickMs","setState","setTimeout","type","exports","defaultProps","role","_default","withThemeContext"],"sources":["../../../src/lib/components/button/Button.tsx"],"sourcesContent":["// Libs\r\nimport * as React from 'react';\r\nimport type { TippyProps } from '@tippy.js/react';\r\nimport { withThemeContext } from '../themeProvider/withThemeContext';\r\nimport { ThemeContextProps } from '../themeProvider/ThemeContext';\r\nimport Ink from 'react-ink';\r\nimport classNames from 'classnames';\r\n\r\n// Misc\r\n\r\nexport type ButtonTypes =\r\n | 'primary'\r\n | 'success'\r\n | 'error'\r\n | 'warning'\r\n | 'info'\r\n | 'gray'\r\n | 'white'\r\n | 'black'\r\n | 'none';\r\n\r\nexport type ButtonComponentProps = {\r\n id?: string;\r\n onClick: (e: React.MouseEvent<HTMLElement>) => void;\r\n className: string;\r\n buttonProps: React.ButtonHTMLAttributes<HTMLButtonElement>;\r\n children: React.ReactNode;\r\n style: React.CSSProperties;\r\n};\r\n\r\nexport type ButtonProps = React.PropsWithChildren<\r\n {\r\n id?: string;\r\n onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;\r\n style?: React.CSSProperties;\r\n className?: string;\r\n disabled?: boolean;\r\n type?: ButtonTypes;\r\n circular?: boolean;\r\n noRipples?: boolean;\r\n small?: boolean;\r\n icon?: boolean;\r\n outlined?: boolean;\r\n disableAfterClickMs?: number;\r\n disableAfterClick?: boolean;\r\n buttonProps?: React.ButtonHTMLAttributes<HTMLButtonElement>;\r\n text?: boolean;\r\n hero?: boolean;\r\n noShadow?: boolean;\r\n blank?: boolean;\r\n unobtrusive?: boolean;\r\n dropdown?: boolean;\r\n Component?: React.FC<ButtonComponentProps>;\r\n tooltip?: JSX.Element | string;\r\n disableTooltip?: boolean;\r\n tooltipProps?: TippyProps;\r\n preventsDefault?: boolean;\r\n } & ThemeContextProps\r\n>;\r\n\r\nexport interface ButtonState {\r\n disabledAfterClick: boolean;\r\n}\r\n\r\nconst DefaultButtonComponent: React.FC<ButtonComponentProps> = React.forwardRef(\r\n (props, ref) => {\r\n const { disabled, ...rest } = props.buttonProps ?? {};\r\n return (\r\n <button\r\n ref={ref}\r\n // tslint:disable-next-line:no-any\r\n {...(rest as any)}\r\n {...(props.id && { id: props.id })}\r\n className={props.className}\r\n onClick={props.onClick}\r\n style={props.style}\r\n >\r\n {props.children}\r\n </button>\r\n );\r\n }\r\n);\r\n\r\nexport class Button extends React.PureComponent<ButtonProps, ButtonState> {\r\n public static defaultProps: ButtonProps = {\r\n disabled: false,\r\n className: '',\r\n onClick: () => null,\r\n circular: false,\r\n noRipples: false,\r\n small: false,\r\n disableAfterClickMs: 100,\r\n disableAfterClick: false,\r\n Component: DefaultButtonComponent,\r\n buttonProps: {\r\n type: 'button',\r\n role: 'button',\r\n tabIndex: 0,\r\n },\r\n type: 'none',\r\n preventsDefault: true,\r\n };\r\n\r\n private preventMultipleClickTimer: number;\r\n\r\n constructor(props: ButtonProps) {\r\n super(props);\r\n this.handleClick = this.handleClick.bind(this);\r\n this.state = {\r\n disabledAfterClick: false,\r\n };\r\n }\r\n\r\n public render() {\r\n const disabled =\r\n this.props.disabled ||\r\n (this.props.disableAfterClick && this.state.disabledAfterClick);\r\n let btnClassName = classNames([\r\n 'guestbell-btn',\r\n this.getButtonClassName(),\r\n this.props.className,\r\n { ['guestbell-btn--disabled']: disabled },\r\n { ['guestbell-btn--circular']: this.props.circular },\r\n { ['guestbell-btn--small']: this.props.small },\r\n { ['guestbell-btn--no-shadow']: this.props.noShadow },\r\n { ['guestbell-btn--blank']: this.props.blank },\r\n { ['guestbell-btn--unobtrusive']: this.props.unobtrusive },\r\n { ['guestbell-btn--outlined']: this.props.outlined },\r\n { ['guestbell-btn--dropdown']: this.props.dropdown },\r\n { ['guestbell-btn--icon']: this.props.icon },\r\n { ['guestbell-btn--hero']: this.props.hero },\r\n { ['guestbell-btn--text']: this.props.text },\r\n ]);\r\n const button = (\r\n <this.props.Component\r\n {...(this.props.id && { id: this.props.id })}\r\n onClick={this.handleClick}\r\n buttonProps={{\r\n ...this.props.buttonProps,\r\n disabled: this.props.disabled,\r\n tabIndex: !disabled ? this.props.buttonProps?.tabIndex : -1,\r\n }}\r\n className={btnClassName}\r\n style={this.props.style}\r\n >\r\n {!this.props.noRipples && !disabled && Ink && <Ink />}\r\n {this.props.children}\r\n </this.props.Component>\r\n );\r\n if (this.props.tooltip && !this.props.disableTooltip) {\r\n const Tippy = require('@tippy.js/react').default;\r\n return (\r\n <Tippy\r\n content={this.props.tooltip}\r\n placement=\"bottom\"\r\n animation=\"scale-subtle\"\r\n arrow={false}\r\n duration={200}\r\n delay={[75, 0]}\r\n distance={8}\r\n interactive={true}\r\n appendTo={document?.body}\r\n {...this.props.tooltipProps}\r\n >\r\n {button}\r\n </Tippy>\r\n );\r\n }\r\n return button;\r\n }\r\n\r\n public componentWillUnmount() {\r\n clearTimeout(this.preventMultipleClickTimer);\r\n }\r\n\r\n private handleClick(e: React.MouseEvent<HTMLButtonElement>) {\r\n if (this.props.preventsDefault) {\r\n e.preventDefault();\r\n }\r\n if (!this.state.disabledAfterClick && !this.props.disabled) {\r\n this.props.onClick && this.props.onClick(e);\r\n if (this.props.disableAfterClickMs !== 0) {\r\n this.setState({ disabledAfterClick: true });\r\n this.preventMultipleClickTimer = setTimeout(() => {\r\n this.setState({ disabledAfterClick: false });\r\n }, this.props.disableAfterClickMs) as unknown as number;\r\n }\r\n }\r\n }\r\n\r\n private getButtonClassName() {\r\n return this.props.type && 'guestbell-btn-' + this.props.type;\r\n }\r\n}\r\nexport default withThemeContext<ButtonProps, InstanceType<typeof Button>>(\r\n Button,\r\n 'button'\r\n);\r\n"],"mappings":";;;;;;AACA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,iBAAA,GAAAD,OAAA;AAEA,IAAAE,SAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,WAAA,GAAAD,sBAAA,CAAAH,OAAA;AAAoC,MAAAK,SAAA,iBANpC;AAAA,SAAAF,uB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B,KAAK,CAACgE,IAAI,IAAI,gBAAgB,GAAG,IAAI,CAAChE,KAAK,CAACgE,IAAI;EAC9D;AACF;AAACC,OAAA,CAAArD,MAAA,GAAAA,MAAA;AA9GYA,MAAM,CACHsD,YAAY,GAAgB;EACxC9D,QAAQ,EAAE,KAAK;EACfI,SAAS,EAAE,EAAE;EACbC,OAAO,EAAEA,CAAA,KAAM,IAAI;EACnBgB,QAAQ,EAAE,KAAK;EACfa,SAAS,EAAE,KAAK;EAChBZ,KAAK,EAAE,KAAK;EACZmC,mBAAmB,EAAE,GAAG;EACxBxC,iBAAiB,EAAE,KAAK;EACxBe,SAAS,EAAEtC,sBAAsB;EACjCK,WAAW,EAAE;IACX6D,IAAI,EAAE,QAAQ;IACdG,IAAI,EAAE,QAAQ;IACd9B,QAAQ,EAAE;EACZ,CAAC;EACD2B,IAAI,EAAE,MAAM;EACZL,eAAe,EAAE;AACnB,CAAC;AAAA,IAAAS,QAAA,GA6FY,IAAAC,kCAAgB,EAC7BzD,MAAM,EACN,QACF,CAAC;AAAAqD,OAAA,CAAAtI,OAAA,GAAAyI,QAAA"}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
import { FormContextState,
|
2
|
+
import { FormContextState, ComponentsDict } from './FormContext';
|
3
3
|
import { ThemeContextProps } from '../themeProvider/ThemeContext';
|
4
|
+
import { FormComponentContextState, FormValidationContextState } from './FormValidationContext';
|
4
5
|
export type FormProps = React.PropsWithChildren<ThemeContextProps & {
|
5
6
|
id?: string;
|
6
7
|
className?: string;
|
@@ -11,7 +12,8 @@ export type FormProps = React.PropsWithChildren<ThemeContextProps & {
|
|
11
12
|
onValidChanged?: (isValid: boolean, errors?: FormComponentContextState[]) => void;
|
12
13
|
}>;
|
13
14
|
export interface FormState {
|
14
|
-
|
15
|
+
formContext: FormContextState;
|
16
|
+
formValidationContext: FormValidationContextState;
|
15
17
|
}
|
16
18
|
export declare class Form extends React.PureComponent<FormProps, FormState> {
|
17
19
|
static defaultProps: {
|
@@ -7,6 +7,7 @@ exports.default = exports.Form = void 0;
|
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
8
8
|
var _FormContext = require("./FormContext");
|
9
9
|
var _withThemeContext = require("../themeProvider/withThemeContext");
|
10
|
+
var _FormValidationContext = require("./FormValidationContext");
|
10
11
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
11
12
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
12
13
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
@@ -29,59 +30,62 @@ class Form extends React.PureComponent {
|
|
29
30
|
this.disableComponents = this.disableComponents.bind(this);
|
30
31
|
this.enableComponents = this.enableComponents.bind(this);
|
31
32
|
this.state = {
|
32
|
-
|
33
|
+
formContext: {
|
33
34
|
subscribe: this.subscribe,
|
34
35
|
unSubscribe: this.unSubscribe,
|
35
|
-
isFormValid: true,
|
36
36
|
updateCallback: this.updateCallback,
|
37
37
|
disableComponents: this.disableComponents,
|
38
|
-
enableComponents: this.enableComponents
|
38
|
+
enableComponents: this.enableComponents
|
39
|
+
},
|
40
|
+
formValidationContext: {
|
41
|
+
isFormValid: true,
|
39
42
|
components: {}
|
40
43
|
}
|
41
44
|
};
|
42
45
|
}
|
43
46
|
componentDidUpdate(prevProps, prevState, snapshot) {
|
44
|
-
var _this$state$
|
45
|
-
if (((_this$state$
|
46
|
-
var _this$props$onValidCh, _this$props, _this$state$
|
47
|
-
const componentsWithErrors = this.state.
|
47
|
+
var _this$state$formValid, _prevState$formValida;
|
48
|
+
if (((_this$state$formValid = this.state.formValidationContext) === null || _this$state$formValid === void 0 ? void 0 : _this$state$formValid.isFormValid) !== (prevState === null || prevState === void 0 ? void 0 : (_prevState$formValida = prevState.formValidationContext) === null || _prevState$formValida === void 0 ? void 0 : _prevState$formValida.isFormValid)) {
|
49
|
+
var _this$props$onValidCh, _this$props, _this$state$formValid2;
|
50
|
+
const componentsWithErrors = this.state.formContext ? Object.keys(this.state.formValidationContext.components).map(key => this.state.formValidationContext.components[key]).filter(component => {
|
48
51
|
if (!component.validation.isValid && !component.validation.name) {
|
49
52
|
console.warn(component, 'Has validation error. FormValidationSummary is present but the component has no validation name');
|
50
53
|
}
|
51
54
|
return !component.validation.isValid;
|
52
55
|
}) : [];
|
53
|
-
(_this$props$onValidCh = (_this$props = this.props).onValidChanged) === null || _this$props$onValidCh === void 0 ? void 0 : _this$props$onValidCh.call(_this$props, (_this$state$
|
56
|
+
(_this$props$onValidCh = (_this$props = this.props).onValidChanged) === null || _this$props$onValidCh === void 0 ? void 0 : _this$props$onValidCh.call(_this$props, (_this$state$formValid2 = this.state.formValidationContext) === null || _this$state$formValid2 === void 0 ? void 0 : _this$state$formValid2.isFormValid, componentsWithErrors);
|
54
57
|
}
|
55
58
|
}
|
56
59
|
disableComponents() {
|
57
|
-
const components = _objectSpread(_objectSpread({}, this.state.
|
60
|
+
const components = _objectSpread(_objectSpread({}, this.state.formValidationContext.components), this.props.extraComponents);
|
58
61
|
Object.keys(components).forEach(key => {
|
59
62
|
const component = components[key];
|
60
63
|
component && component.componentApi && component.componentApi.disableComponent && component.componentApi.disableComponent();
|
61
64
|
});
|
62
65
|
}
|
63
66
|
enableComponents() {
|
64
|
-
const components = _objectSpread(_objectSpread({}, this.state.
|
67
|
+
const components = _objectSpread(_objectSpread({}, this.state.formValidationContext.components), this.props.extraComponents);
|
65
68
|
Object.keys(components).forEach(key => {
|
66
69
|
const component = components[key];
|
67
70
|
component && component.componentApi && component.componentApi.enableComponent && component.componentApi.enableComponent();
|
68
71
|
});
|
69
72
|
}
|
70
73
|
touchAll() {
|
71
|
-
const components = _objectSpread(_objectSpread({}, this.state.
|
74
|
+
const components = _objectSpread(_objectSpread({}, this.state.formValidationContext.components), this.props.extraComponents);
|
72
75
|
Object.keys(components).forEach(key => {
|
73
76
|
const component = components[key];
|
74
77
|
component && component.componentApi && component.componentApi.touch && component.componentApi.touch();
|
75
78
|
});
|
76
79
|
}
|
77
80
|
unTouchAll() {
|
78
|
-
const components = _objectSpread(_objectSpread({}, this.state.
|
81
|
+
const components = _objectSpread(_objectSpread({}, this.state.formValidationContext.components), this.props.extraComponents);
|
79
82
|
Object.keys(components).forEach(key => {
|
80
83
|
const component = components[key];
|
81
84
|
component && component.componentApi && component.componentApi.unTouch && component.componentApi.unTouch();
|
82
85
|
});
|
83
86
|
}
|
84
87
|
render() {
|
88
|
+
const validationContext = this.mergeContext();
|
85
89
|
return /*#__PURE__*/React.createElement(this.props.component, _extends({}, this.props.id && {
|
86
90
|
id: this.props.id
|
87
91
|
}, {
|
@@ -90,32 +94,35 @@ class Form extends React.PureComponent {
|
|
90
94
|
className: `input__form validation-form ${this.props.className ? this.props.className : ''}`,
|
91
95
|
onSubmit: this.onSubmit
|
92
96
|
}), /*#__PURE__*/React.createElement(_FormContext.FormContextProvider, {
|
93
|
-
value: this.
|
94
|
-
},
|
97
|
+
value: this.state.formContext
|
98
|
+
}, /*#__PURE__*/React.createElement(_FormValidationContext.FormValidationContextProvider, {
|
99
|
+
value: validationContext
|
100
|
+
}, this.props.children)));
|
95
101
|
}
|
96
102
|
mergeContext() {
|
97
103
|
if (!this.props.extraComponents) {
|
98
|
-
return this.state.
|
104
|
+
return this.state.formValidationContext;
|
99
105
|
}
|
100
|
-
const isFormValid = this.state.
|
101
|
-
return _objectSpread(_objectSpread({}, this.state.
|
102
|
-
components: _objectSpread(_objectSpread({}, this.state.
|
106
|
+
const isFormValid = this.state.formValidationContext.isFormValid && this.getIsFormValid(this.props.extraComponents);
|
107
|
+
return _objectSpread(_objectSpread({}, this.state.formValidationContext), {}, {
|
108
|
+
components: _objectSpread(_objectSpread({}, this.state.formValidationContext.components), this.props.extraComponents),
|
103
109
|
isFormValid
|
104
110
|
});
|
105
111
|
}
|
106
112
|
subscribe(componentId, componentState) {
|
107
113
|
if (componentId) {
|
108
114
|
this.setState(previousState => {
|
109
|
-
let components = Object.assign({}, previousState.
|
115
|
+
let components = Object.assign({}, previousState.formValidationContext.components);
|
110
116
|
if (componentState) {
|
111
117
|
components[componentId] = componentState;
|
112
118
|
}
|
113
119
|
let isFormValid = this.getIsFormValid(components);
|
114
120
|
return {
|
115
|
-
|
121
|
+
formValidationContext: _objectSpread(_objectSpread({}, previousState.formValidationContext), {}, {
|
116
122
|
components,
|
117
123
|
isFormValid
|
118
|
-
})
|
124
|
+
}),
|
125
|
+
formContext: previousState.formContext
|
119
126
|
};
|
120
127
|
});
|
121
128
|
}
|
@@ -123,11 +130,12 @@ class Form extends React.PureComponent {
|
|
123
130
|
unSubscribe(componentId) {
|
124
131
|
if (componentId) {
|
125
132
|
this.setState(previousState => {
|
126
|
-
let components = Object.assign({}, previousState.
|
133
|
+
let components = Object.assign({}, previousState.formValidationContext.components);
|
127
134
|
delete components[componentId];
|
128
135
|
let isFormValid = this.getIsFormValid(components);
|
129
136
|
return {
|
130
|
-
|
137
|
+
formContext: previousState.formContext,
|
138
|
+
formValidationContext: _objectSpread(_objectSpread({}, previousState.formValidationContext), {}, {
|
131
139
|
components,
|
132
140
|
isFormValid
|
133
141
|
})
|
@@ -136,7 +144,7 @@ class Form extends React.PureComponent {
|
|
136
144
|
}
|
137
145
|
}
|
138
146
|
getIsFormValid() {
|
139
|
-
let components = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.state.
|
147
|
+
let components = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.state.formValidationContext.components;
|
140
148
|
let initialValid = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
141
149
|
let isFormValid = initialValid;
|
142
150
|
Object.keys(components).forEach(key => {
|
@@ -150,7 +158,7 @@ class Form extends React.PureComponent {
|
|
150
158
|
updateCallback(componentId, componentState) {
|
151
159
|
this.setState(previousState => {
|
152
160
|
var _previousComponent$va, _componentState$error, _previousComponent$va2;
|
153
|
-
let components = Object.assign({}, previousState.
|
161
|
+
let components = Object.assign({}, previousState.formValidationContext.components);
|
154
162
|
const previousComponent = components[componentId];
|
155
163
|
if (previousComponent && previousComponent.validation && previousComponent.validation.isValid === componentState.isValid && ((_previousComponent$va = previousComponent.validation.errors) === null || _previousComponent$va === void 0 ? void 0 : _previousComponent$va.length) === ((_componentState$error = componentState.errors) === null || _componentState$error === void 0 ? void 0 : _componentState$error.length) && (_previousComponent$va2 = previousComponent.validation.errors) !== null && _previousComponent$va2 !== void 0 && _previousComponent$va2.every((error, index) => {
|
156
164
|
var _componentState$error2;
|
@@ -165,10 +173,11 @@ class Form extends React.PureComponent {
|
|
165
173
|
}
|
166
174
|
let isFormValid = this.getIsFormValid(components);
|
167
175
|
return {
|
168
|
-
|
176
|
+
formValidationContext: _objectSpread(_objectSpread({}, this.state.formValidationContext), {}, {
|
169
177
|
components,
|
170
178
|
isFormValid
|
171
|
-
})
|
179
|
+
}),
|
180
|
+
formContext: previousState.formContext
|
172
181
|
};
|
173
182
|
});
|
174
183
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Form.js","names":["React","_interopRequireWildcard","require","_FormContext","_withThemeContext","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","_extends","assign","bind","target","i","arguments","length","source","apply","ownKeys","object","enumerableOnly","keys","getOwnPropertySymbols","symbols","filter","sym","enumerable","push","_objectSpread","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","value","_toPropertyKey","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","TypeError","Number","Form","PureComponent","constructor","props","onSubmit","e","preventDefault","subscribe","unSubscribe","updateCallback","disableComponents","enableComponents","state","contextState","isFormValid","components","componentDidUpdate","prevProps","prevState","snapshot","_this$state$contextSt","_prevState$contextSta","_this$props$onValidCh","_this$props","_this$state$contextSt2","componentsWithErrors","map","component","validation","isValid","name","console","warn","onValidChanged","extraComponents","componentApi","disableComponent","enableComponent","touchAll","touch","unTouchAll","unTouch","render","createElement","id","noValidate","role","className","FormContextProvider","mergeContext","children","getIsFormValid","componentId","componentState","setState","previousState","initialValid","_previousComponent$va","_componentState$error","_previousComponent$va2","previousComponent","errors","every","error","index","_componentState$error2","exports","defaultProps","showExpandAll","_default","withThemeContext"],"sources":["../../../src/lib/components/form/Form.tsx"],"sourcesContent":["// Libs\r\nimport * as React from 'react';\r\n\r\n// Misc\r\nimport {\r\n FormContextState,\r\n FormComponentContextState,\r\n FormContextProvider,\r\n ComponentsDict,\r\n FormComponentValidationContextStateBase,\r\n} from './FormContext';\r\nimport { withThemeContext } from '../themeProvider/withThemeContext';\r\nimport { ThemeContextProps } from '../themeProvider/ThemeContext';\r\n\r\nexport type FormProps = React.PropsWithChildren<\r\n ThemeContextProps & {\r\n id?: string;\r\n className?: string;\r\n noValidate?: boolean;\r\n onSubmit?: () => void;\r\n extraComponents?: ComponentsDict;\r\n component?: keyof JSX.IntrinsicElements;\r\n onValidChanged?: (\r\n isValid: boolean,\r\n errors?: FormComponentContextState[]\r\n ) => void;\r\n }\r\n>;\r\n\r\nexport interface FormState {\r\n contextState: FormContextState;\r\n}\r\n\r\nexport class Form extends React.PureComponent<FormProps, FormState> {\r\n public static defaultProps = {\r\n noValidate: false,\r\n showExpandAll: true,\r\n component: 'form' as keyof JSX.IntrinsicElements,\r\n };\r\n\r\n constructor(props: FormProps) {\r\n super(props);\r\n this.subscribe = this.subscribe.bind(this);\r\n this.unSubscribe = this.unSubscribe.bind(this);\r\n this.updateCallback = this.updateCallback.bind(this);\r\n this.disableComponents = this.disableComponents.bind(this);\r\n this.enableComponents = this.enableComponents.bind(this);\r\n this.state = {\r\n contextState: {\r\n subscribe: this.subscribe,\r\n unSubscribe: this.unSubscribe,\r\n isFormValid: true,\r\n updateCallback: this.updateCallback,\r\n disableComponents: this.disableComponents,\r\n enableComponents: this.enableComponents,\r\n components: {},\r\n },\r\n };\r\n }\r\n\r\n public componentDidUpdate(\r\n prevProps: Readonly<FormProps>,\r\n prevState: Readonly<FormState>,\r\n snapshot?: any\r\n ): void {\r\n if (\r\n this.state.contextState?.isFormValid !==\r\n prevState?.contextState?.isFormValid\r\n ) {\r\n const componentsWithErrors = this.state.contextState\r\n ? Object.keys(this.state.contextState.components)\r\n .map((key) => this.state.contextState.components[key])\r\n .filter((component) => {\r\n if (!component.validation.isValid && !component.validation.name) {\r\n console.warn(\r\n component,\r\n 'Has validation error. FormValidationSummary is present but the component has no validation name'\r\n );\r\n }\r\n return !component.validation.isValid;\r\n })\r\n : [];\r\n this.props.onValidChanged?.(\r\n this.state.contextState?.isFormValid,\r\n componentsWithErrors\r\n );\r\n }\r\n }\r\n\r\n public disableComponents() {\r\n const components = {\r\n ...this.state.contextState.components,\r\n ...this.props.extraComponents,\r\n };\r\n Object.keys(components).forEach((key) => {\r\n const component = components[key];\r\n component &&\r\n component.componentApi &&\r\n component.componentApi.disableComponent &&\r\n component.componentApi.disableComponent();\r\n });\r\n }\r\n\r\n public enableComponents() {\r\n const components = {\r\n ...this.state.contextState.components,\r\n ...this.props.extraComponents,\r\n };\r\n Object.keys(components).forEach((key) => {\r\n const component = components[key];\r\n component &&\r\n component.componentApi &&\r\n component.componentApi.enableComponent &&\r\n component.componentApi.enableComponent();\r\n });\r\n }\r\n\r\n public touchAll() {\r\n const components = {\r\n ...this.state.contextState.components,\r\n ...this.props.extraComponents,\r\n };\r\n Object.keys(components).forEach((key) => {\r\n const component = components[key];\r\n component &&\r\n component.componentApi &&\r\n component.componentApi.touch &&\r\n component.componentApi.touch();\r\n });\r\n }\r\n\r\n public unTouchAll() {\r\n const components = {\r\n ...this.state.contextState.components,\r\n ...this.props.extraComponents,\r\n };\r\n Object.keys(components).forEach((key) => {\r\n const component = components[key];\r\n component &&\r\n component.componentApi &&\r\n component.componentApi.unTouch &&\r\n component.componentApi.unTouch();\r\n });\r\n }\r\n\r\n public render() {\r\n return (\r\n <this.props.component\r\n {...(this.props.id && { id: this.props.id })}\r\n noValidate={true}\r\n role=\"form\"\r\n className={`input__form validation-form ${\r\n this.props.className ? this.props.className : ''\r\n }`}\r\n onSubmit={this.onSubmit}\r\n >\r\n <FormContextProvider value={this.mergeContext()}>\r\n {this.props.children}\r\n </FormContextProvider>\r\n </this.props.component>\r\n );\r\n }\r\n\r\n private mergeContext(): FormContextState {\r\n if (!this.props.extraComponents) {\r\n return this.state.contextState;\r\n }\r\n const isFormValid =\r\n this.state.contextState.isFormValid &&\r\n this.getIsFormValid(this.props.extraComponents);\r\n return {\r\n ...this.state.contextState,\r\n components: {\r\n ...this.state.contextState.components,\r\n ...this.props.extraComponents,\r\n },\r\n isFormValid,\r\n };\r\n }\r\n\r\n private onSubmit = (e: React.FormEvent) => {\r\n e.preventDefault();\r\n this.props.onSubmit && this.props.onSubmit();\r\n };\r\n\r\n private subscribe(\r\n componentId: string,\r\n componentState: FormComponentContextState\r\n ) {\r\n if (componentId) {\r\n this.setState((previousState) => {\r\n let components = Object.assign(\r\n {},\r\n previousState.contextState.components\r\n );\r\n if (componentState) {\r\n components[componentId] = componentState;\r\n }\r\n let isFormValid = this.getIsFormValid(components);\r\n return {\r\n contextState: {\r\n ...previousState.contextState,\r\n components,\r\n isFormValid,\r\n },\r\n };\r\n });\r\n }\r\n }\r\n\r\n private unSubscribe(componentId: string) {\r\n if (componentId) {\r\n this.setState((previousState) => {\r\n let components = Object.assign(\r\n {},\r\n previousState.contextState.components\r\n );\r\n delete components[componentId];\r\n let isFormValid = this.getIsFormValid(components);\r\n return {\r\n contextState: {\r\n ...previousState.contextState,\r\n components,\r\n isFormValid,\r\n },\r\n };\r\n });\r\n }\r\n }\r\n\r\n private getIsFormValid(\r\n components: ComponentsDict = this.state.contextState.components,\r\n initialValid: boolean = true\r\n ): boolean {\r\n let isFormValid = initialValid;\r\n Object.keys(components).forEach((key) => {\r\n const component = components[key];\r\n if (component && component.validation && !component.validation.isValid) {\r\n isFormValid = false;\r\n }\r\n });\r\n return isFormValid;\r\n }\r\n\r\n private updateCallback(\r\n componentId: string,\r\n componentState: FormComponentValidationContextStateBase\r\n ) {\r\n this.setState((previousState) => {\r\n let components = Object.assign({}, previousState.contextState.components);\r\n const previousComponent = components[componentId];\r\n if (\r\n previousComponent &&\r\n previousComponent.validation &&\r\n previousComponent.validation.isValid === componentState.isValid &&\r\n previousComponent.validation.errors?.length ===\r\n componentState.errors?.length &&\r\n previousComponent.validation.errors?.every(\r\n (error, index) => error === componentState.errors?.[index]\r\n )\r\n ) {\r\n return previousState;\r\n }\r\n if (componentState && previousComponent) {\r\n components[componentId] = {\r\n ...previousComponent,\r\n validation: {\r\n ...previousComponent.validation,\r\n ...componentState,\r\n },\r\n };\r\n }\r\n let isFormValid = this.getIsFormValid(components);\r\n return {\r\n contextState: {\r\n ...this.state.contextState,\r\n components,\r\n isFormValid,\r\n },\r\n };\r\n });\r\n }\r\n}\r\n\r\nexport default withThemeContext<FormProps, InstanceType<typeof Form>>(\r\n Form,\r\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,OAAOT,aAAa;MACtB;MACA,IAAIF,cAAc,IAAIO,iBAAiB,EAAE;QACvC7C,UAAU,CAACqC,WAAW,CAAC,GAAAzE,aAAA,CAAAA,aAAA,KAClBiF,iBAAiB;UACpBhC,UAAU,EAAAjD,aAAA,CAAAA,aAAA,KACLiF,iBAAiB,CAAChC,UAAU,GAC5ByB,cAAc;QAClB,EACF;MACH;MACA,IAAIvC,WAAW,GAAG,IAAI,CAACqC,cAAc,CAACpC,UAAU,CAAC;MACjD,OAAO;QACLF,YAAY,EAAAlC,aAAA,CAAAA,aAAA,KACP,IAAI,CAACiC,KAAK,CAACC,YAAY;UAC1BE,UAAU;UACVD;QAAW;MAEf,CAAC;IACH,CAAC,CAAC;EACJ;AACF;AAACoD,OAAA,CAAAlE,IAAA,GAAAA,IAAA;AAzPYA,IAAI,CACDmE,YAAY,GAAG;EAC3BtB,UAAU,EAAE,KAAK;EACjBuB,aAAa,EAAE,IAAI;EACnBzC,SAAS,EAAE;AACb,CAAC;AAAA,IAAA0C,QAAA,GAsPY,IAAAC,kCAAgB,EAC7BtE,IAAI,EACJ,MACF,CAAC;AAAAkE,OAAA,CAAAzH,OAAA,GAAA4H,QAAA"}
|
1
|
+
{"version":3,"file":"Form.js","names":["React","_interopRequireWildcard","require","_FormContext","_withThemeContext","_FormValidationContext","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","_extends","assign","bind","target","i","arguments","length","source","apply","ownKeys","object","enumerableOnly","keys","getOwnPropertySymbols","symbols","filter","sym","enumerable","push","_objectSpread","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","value","_toPropertyKey","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","TypeError","Number","Form","PureComponent","constructor","props","onSubmit","e","preventDefault","subscribe","unSubscribe","updateCallback","disableComponents","enableComponents","state","formContext","formValidationContext","isFormValid","components","componentDidUpdate","prevProps","prevState","snapshot","_this$state$formValid","_prevState$formValida","_this$props$onValidCh","_this$props","_this$state$formValid2","componentsWithErrors","map","component","validation","isValid","name","console","warn","onValidChanged","extraComponents","componentApi","disableComponent","enableComponent","touchAll","touch","unTouchAll","unTouch","render","validationContext","mergeContext","createElement","id","noValidate","role","className","FormContextProvider","FormValidationContextProvider","children","getIsFormValid","componentId","componentState","setState","previousState","initialValid","_previousComponent$va","_componentState$error","_previousComponent$va2","previousComponent","errors","every","error","index","_componentState$error2","exports","defaultProps","showExpandAll","_default","withThemeContext"],"sources":["../../../src/lib/components/form/Form.tsx"],"sourcesContent":["// Libs\r\nimport * as React from 'react';\r\n\r\n// Misc\r\nimport {\r\n FormContextState,\r\n FormContextProvider,\r\n ComponentsDict,\r\n} from './FormContext';\r\nimport { withThemeContext } from '../themeProvider/withThemeContext';\r\nimport { ThemeContextProps } from '../themeProvider/ThemeContext';\r\nimport {\r\n FormComponentContextState,\r\n FormComponentValidationContextStateBase,\r\n FormValidationContextProvider,\r\n FormValidationContextState,\r\n} from './FormValidationContext';\r\n\r\nexport type FormProps = React.PropsWithChildren<\r\n ThemeContextProps & {\r\n id?: string;\r\n className?: string;\r\n noValidate?: boolean;\r\n onSubmit?: () => void;\r\n extraComponents?: ComponentsDict;\r\n component?: keyof JSX.IntrinsicElements;\r\n onValidChanged?: (\r\n isValid: boolean,\r\n errors?: FormComponentContextState[]\r\n ) => void;\r\n }\r\n>;\r\n\r\nexport interface FormState {\r\n formContext: FormContextState;\r\n formValidationContext: FormValidationContextState;\r\n}\r\n\r\nexport class Form extends React.PureComponent<FormProps, FormState> {\r\n public static defaultProps = {\r\n noValidate: false,\r\n showExpandAll: true,\r\n component: 'form' as keyof JSX.IntrinsicElements,\r\n };\r\n\r\n constructor(props: FormProps) {\r\n super(props);\r\n this.subscribe = this.subscribe.bind(this);\r\n this.unSubscribe = this.unSubscribe.bind(this);\r\n this.updateCallback = this.updateCallback.bind(this);\r\n this.disableComponents = this.disableComponents.bind(this);\r\n this.enableComponents = this.enableComponents.bind(this);\r\n this.state = {\r\n formContext: {\r\n subscribe: this.subscribe,\r\n unSubscribe: this.unSubscribe,\r\n updateCallback: this.updateCallback,\r\n disableComponents: this.disableComponents,\r\n enableComponents: this.enableComponents,\r\n },\r\n formValidationContext: {\r\n isFormValid: true,\r\n components: {},\r\n },\r\n };\r\n }\r\n\r\n public componentDidUpdate(\r\n prevProps: Readonly<FormProps>,\r\n prevState: Readonly<FormState>,\r\n snapshot?: any\r\n ): void {\r\n if (\r\n this.state.formValidationContext?.isFormValid !==\r\n prevState?.formValidationContext?.isFormValid\r\n ) {\r\n const componentsWithErrors = this.state.formContext\r\n ? Object.keys(this.state.formValidationContext.components)\r\n .map((key) => this.state.formValidationContext.components[key])\r\n .filter((component) => {\r\n if (!component.validation.isValid && !component.validation.name) {\r\n console.warn(\r\n component,\r\n 'Has validation error. FormValidationSummary is present but the component has no validation name'\r\n );\r\n }\r\n return !component.validation.isValid;\r\n })\r\n : [];\r\n this.props.onValidChanged?.(\r\n this.state.formValidationContext?.isFormValid,\r\n componentsWithErrors\r\n );\r\n }\r\n }\r\n\r\n public disableComponents() {\r\n const components = {\r\n ...this.state.formValidationContext.components,\r\n ...this.props.extraComponents,\r\n };\r\n Object.keys(components).forEach((key) => {\r\n const component = components[key];\r\n component &&\r\n component.componentApi &&\r\n component.componentApi.disableComponent &&\r\n component.componentApi.disableComponent();\r\n });\r\n }\r\n\r\n public enableComponents() {\r\n const components = {\r\n ...this.state.formValidationContext.components,\r\n ...this.props.extraComponents,\r\n };\r\n Object.keys(components).forEach((key) => {\r\n const component = components[key];\r\n component &&\r\n component.componentApi &&\r\n component.componentApi.enableComponent &&\r\n component.componentApi.enableComponent();\r\n });\r\n }\r\n\r\n public touchAll() {\r\n const components = {\r\n ...this.state.formValidationContext.components,\r\n ...this.props.extraComponents,\r\n };\r\n Object.keys(components).forEach((key) => {\r\n const component = components[key];\r\n component &&\r\n component.componentApi &&\r\n component.componentApi.touch &&\r\n component.componentApi.touch();\r\n });\r\n }\r\n\r\n public unTouchAll() {\r\n const components = {\r\n ...this.state.formValidationContext.components,\r\n ...this.props.extraComponents,\r\n };\r\n Object.keys(components).forEach((key) => {\r\n const component = components[key];\r\n component &&\r\n component.componentApi &&\r\n component.componentApi.unTouch &&\r\n component.componentApi.unTouch();\r\n });\r\n }\r\n\r\n public render() {\r\n const validationContext = this.mergeContext();\r\n return (\r\n <this.props.component\r\n {...(this.props.id && { id: this.props.id })}\r\n noValidate={true}\r\n role=\"form\"\r\n className={`input__form validation-form ${\r\n this.props.className ? this.props.className : ''\r\n }`}\r\n onSubmit={this.onSubmit}\r\n >\r\n <FormContextProvider value={this.state.formContext}>\r\n <FormValidationContextProvider value={validationContext}>\r\n {this.props.children}\r\n </FormValidationContextProvider>\r\n </FormContextProvider>\r\n </this.props.component>\r\n );\r\n }\r\n\r\n private mergeContext(): FormValidationContextState {\r\n if (!this.props.extraComponents) {\r\n return this.state.formValidationContext;\r\n }\r\n const isFormValid =\r\n this.state.formValidationContext.isFormValid &&\r\n this.getIsFormValid(this.props.extraComponents);\r\n return {\r\n ...this.state.formValidationContext,\r\n components: {\r\n ...this.state.formValidationContext.components,\r\n ...this.props.extraComponents,\r\n },\r\n isFormValid,\r\n };\r\n }\r\n\r\n private onSubmit = (e: React.FormEvent) => {\r\n e.preventDefault();\r\n this.props.onSubmit && this.props.onSubmit();\r\n };\r\n\r\n private subscribe(\r\n componentId: string,\r\n componentState: FormComponentContextState\r\n ) {\r\n if (componentId) {\r\n this.setState((previousState) => {\r\n let components = Object.assign(\r\n {},\r\n previousState.formValidationContext.components\r\n );\r\n if (componentState) {\r\n components[componentId] = componentState;\r\n }\r\n let isFormValid = this.getIsFormValid(components);\r\n return {\r\n formValidationContext: {\r\n ...previousState.formValidationContext,\r\n components,\r\n isFormValid,\r\n },\r\n formContext: previousState.formContext,\r\n };\r\n });\r\n }\r\n }\r\n\r\n private unSubscribe(componentId: string) {\r\n if (componentId) {\r\n this.setState((previousState) => {\r\n let components = Object.assign(\r\n {},\r\n previousState.formValidationContext.components\r\n );\r\n delete components[componentId];\r\n let isFormValid = this.getIsFormValid(components);\r\n return {\r\n formContext: previousState.formContext,\r\n formValidationContext: {\r\n ...previousState.formValidationContext,\r\n components,\r\n isFormValid,\r\n },\r\n };\r\n });\r\n }\r\n }\r\n\r\n private getIsFormValid(\r\n components: ComponentsDict = this.state.formValidationContext.components,\r\n initialValid: boolean = true\r\n ): boolean {\r\n let isFormValid = initialValid;\r\n Object.keys(components).forEach((key) => {\r\n const component = components[key];\r\n if (component && component.validation && !component.validation.isValid) {\r\n isFormValid = false;\r\n }\r\n });\r\n return isFormValid;\r\n }\r\n\r\n private updateCallback(\r\n componentId: string,\r\n componentState: FormComponentValidationContextStateBase\r\n ) {\r\n this.setState((previousState) => {\r\n let components = Object.assign(\r\n {},\r\n previousState.formValidationContext.components\r\n );\r\n const previousComponent = components[componentId];\r\n if (\r\n previousComponent &&\r\n previousComponent.validation &&\r\n previousComponent.validation.isValid === componentState.isValid &&\r\n previousComponent.validation.errors?.length ===\r\n componentState.errors?.length &&\r\n previousComponent.validation.errors?.every(\r\n (error, index) => error === componentState.errors?.[index]\r\n )\r\n ) {\r\n return previousState;\r\n }\r\n if (componentState && previousComponent) {\r\n components[componentId] = {\r\n ...previousComponent,\r\n validation: {\r\n ...previousComponent.validation,\r\n ...componentState,\r\n },\r\n };\r\n }\r\n let isFormValid = this.getIsFormValid(components);\r\n return {\r\n formValidationContext: {\r\n ...this.state.formValidationContext,\r\n components,\r\n isFormValid,\r\n },\r\n formContext: previousState.formContext,\r\n };\r\n });\r\n }\r\n}\r\n\r\nexport default withThemeContext<FormProps, InstanceType<typeof Form>>(\r\n Form,\r\n 'form'\r\n);\r\n"],"mappings":";;;;;;AACA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAGA,IAAAC,YAAA,GAAAD,OAAA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,cAAAF,sBAAA,eAAnCA,sBAAA,CAAqCG,KAAK,CACxC,CAACC,KAAK,EAAEC,KAAK;QAAA,IAAAC,sBAAA;QAAA,OAAKF,KAAK,OAAAE,sBAAA,GAAKZ,cAAc,CAACQ,MAAM,cAAAI,sBAAA,uBAArBA,sBAAA,CAAwBD,KAAK,CAAC;MAAA,CAC5D,CAAC,EACD;QACA,OAAOT,aAAa;MACtB;MACA,IAAIF,cAAc,IAAIO,iBAAiB,EAAE;QACvC/C,UAAU,CAACuC,WAAW,CAAC,GAAA5E,aAAA,CAAAA,aAAA,KAClBoF,iBAAiB;UACpBlC,UAAU,EAAAlD,aAAA,CAAAA,aAAA,KACLoF,iBAAiB,CAAClC,UAAU,GAC5B2B,cAAc;QAClB,EACF;MACH;MACA,IAAIzC,WAAW,GAAG,IAAI,CAACuC,cAAc,CAACtC,UAAU,CAAC;MACjD,OAAO;QACLF,qBAAqB,EAAAnC,aAAA,CAAAA,aAAA,KAChB,IAAI,CAACiC,KAAK,CAACE,qBAAqB;UACnCE,UAAU;UACVD;QAAW,EACZ;QACDF,WAAW,EAAE6C,aAAa,CAAC7C;MAC7B,CAAC;IACH,CAAC,CAAC;EACJ;AACF;AAACwD,OAAA,CAAArE,IAAA,GAAAA,IAAA;AApQYA,IAAI,CACDsE,YAAY,GAAG;EAC3BtB,UAAU,EAAE,KAAK;EACjBuB,aAAa,EAAE,IAAI;EACnB3C,SAAS,EAAE;AACb,CAAC;AAAA,IAAA4C,QAAA,GAiQY,IAAAC,kCAAgB,EAC7BzE,IAAI,EACJ,MACF,CAAC;AAAAqE,OAAA,CAAA5H,OAAA,GAAA+H,QAAA"}
|
@@ -1,18 +1,7 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
import { ValidationError, ComponentApi } from '../base/input';
|
3
2
|
import { PartialBy } from '../utils/Typescript';
|
3
|
+
import { FormComponentContextState, FormComponentValidationContextStateBase } from './FormValidationContext';
|
4
4
|
export type OmitFormContext<P extends FormContextProps> = PartialBy<P, 'formContext'>;
|
5
|
-
export interface FormComponentValidationContextStateBase {
|
6
|
-
isValid: boolean;
|
7
|
-
errors: ValidationError[];
|
8
|
-
}
|
9
|
-
export interface FormComponentValidationContextState extends FormComponentValidationContextStateBase {
|
10
|
-
name: JSX.Element | string;
|
11
|
-
}
|
12
|
-
export interface FormComponentContextState {
|
13
|
-
validation: FormComponentValidationContextState;
|
14
|
-
componentApi: ComponentApi;
|
15
|
-
}
|
16
5
|
export interface FormContextProps {
|
17
6
|
formContext?: FormContextState;
|
18
7
|
}
|
@@ -22,11 +11,9 @@ export type ComponentsDict = {
|
|
22
11
|
export interface FormContextState {
|
23
12
|
subscribe: (componentId: string, componentState: FormComponentContextState) => void;
|
24
13
|
unSubscribe: (componentId: string) => void;
|
25
|
-
isFormValid: boolean;
|
26
14
|
updateCallback: (componentId: string, newComponentState: FormComponentValidationContextStateBase) => void;
|
27
15
|
disableComponents: () => void;
|
28
16
|
enableComponents: () => void;
|
29
|
-
components: ComponentsDict;
|
30
17
|
}
|
31
18
|
export declare const FormContextProvider: React.Provider<FormContextState>;
|
32
19
|
export declare const FormContextConsumer: React.Consumer<FormContextState>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"FormContext.js","names":["React","_interopRequireWildcard","require","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","FormContext","createContext","undefined","FormContextProvider","Provider","exports","FormContextConsumer","Consumer"],"sources":["../../../src/lib/components/form/FormContext.ts"],"sourcesContent":["import * as React from 'react';\r\nimport {
|
1
|
+
{"version":3,"file":"FormContext.js","names":["React","_interopRequireWildcard","require","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","FormContext","createContext","undefined","FormContextProvider","Provider","exports","FormContextConsumer","Consumer"],"sources":["../../../src/lib/components/form/FormContext.ts"],"sourcesContent":["import * as React from 'react';\r\nimport { PartialBy } from '../utils/Typescript';\r\nimport {\r\n FormComponentContextState,\r\n FormComponentValidationContextStateBase,\r\n} from './FormValidationContext';\r\n\r\nexport type OmitFormContext<P extends FormContextProps> = PartialBy<\r\n P,\r\n 'formContext'\r\n>;\r\n\r\nexport interface FormContextProps {\r\n formContext?: FormContextState;\r\n}\r\n\r\nexport type ComponentsDict = {\r\n [componentId: string]: FormComponentContextState;\r\n};\r\n\r\nexport interface FormContextState {\r\n subscribe: (\r\n componentId: string,\r\n componentState: FormComponentContextState\r\n ) => void;\r\n unSubscribe: (componentId: string) => void;\r\n updateCallback: (\r\n componentId: string,\r\n newComponentState: FormComponentValidationContextStateBase\r\n ) => void;\r\n disableComponents: () => void;\r\n enableComponents: () => void;\r\n}\r\n\r\nconst FormContext = React.createContext<FormContextState | undefined>(\r\n undefined\r\n);\r\nexport const FormContextProvider = FormContext.Provider;\r\nexport const FormContextConsumer = FormContext.Consumer;\r\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAA+B,SAAAC,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAH,wBAAAO,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAAA,CAAAH,MAAA,EAAAK,GAAA,EAAAI,IAAA,YAAAT,MAAA,CAAAK,GAAA,IAAAX,GAAA,CAAAW,GAAA,SAAAL,MAAA,CAAAJ,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAa,GAAA,CAAAhB,GAAA,EAAAM,MAAA,YAAAA,MAAA;AAkC/B,MAAMW,WAAW,gBAAGzB,KAAK,CAAC0B,aAAa,CACrCC,SACF,CAAC;AACM,MAAMC,mBAAmB,GAAGH,WAAW,CAACI,QAAQ;AAACC,OAAA,CAAAF,mBAAA,GAAAA,mBAAA;AACjD,MAAMG,mBAAmB,GAAGN,WAAW,CAACO,QAAQ;AAACF,OAAA,CAAAC,mBAAA,GAAAA,mBAAA"}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { ValidationError, ComponentApi } from '../base/input';
|
3
|
+
import { PartialBy } from '../utils/Typescript';
|
4
|
+
export type OmitFormValidationContext<P extends FormValidationContextProps> = PartialBy<P, 'formValidationContext'>;
|
5
|
+
export interface FormComponentValidationContextStateBase {
|
6
|
+
isValid: boolean;
|
7
|
+
errors: ValidationError[];
|
8
|
+
}
|
9
|
+
export interface FormComponentValidationContextState extends FormComponentValidationContextStateBase {
|
10
|
+
name: JSX.Element | string;
|
11
|
+
}
|
12
|
+
export interface FormComponentContextState {
|
13
|
+
validation: FormComponentValidationContextState;
|
14
|
+
componentApi: ComponentApi;
|
15
|
+
}
|
16
|
+
export interface FormValidationContextProps {
|
17
|
+
formValidationContext?: FormValidationContextState;
|
18
|
+
}
|
19
|
+
export type ComponentsDict = {
|
20
|
+
[componentId: string]: FormComponentContextState;
|
21
|
+
};
|
22
|
+
export interface FormValidationContextState {
|
23
|
+
isFormValid: boolean;
|
24
|
+
components: ComponentsDict;
|
25
|
+
}
|
26
|
+
export declare const FormValidationContextProvider: React.Provider<FormValidationContextState>;
|
27
|
+
export declare const FormValidationContextConsumer: React.Consumer<FormValidationContextState>;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.FormValidationContextProvider = exports.FormValidationContextConsumer = void 0;
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
8
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
9
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
10
|
+
const FormValidationContext = /*#__PURE__*/React.createContext(undefined);
|
11
|
+
const FormValidationContextProvider = FormValidationContext.Provider;
|
12
|
+
exports.FormValidationContextProvider = FormValidationContextProvider;
|
13
|
+
const FormValidationContextConsumer = FormValidationContext.Consumer;
|
14
|
+
exports.FormValidationContextConsumer = FormValidationContextConsumer;
|
15
|
+
//# sourceMappingURL=FormValidationContext.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"FormValidationContext.js","names":["React","_interopRequireWildcard","require","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","FormValidationContext","createContext","undefined","FormValidationContextProvider","Provider","exports","FormValidationContextConsumer","Consumer"],"sources":["../../../src/lib/components/form/FormValidationContext.ts"],"sourcesContent":["import * as React from 'react';\r\nimport { ValidationError, ComponentApi } from '../base/input';\r\nimport { PartialBy } from '../utils/Typescript';\r\n\r\nexport type OmitFormValidationContext<P extends FormValidationContextProps> =\r\n PartialBy<P, 'formValidationContext'>;\r\n\r\nexport interface FormComponentValidationContextStateBase {\r\n isValid: boolean;\r\n errors: ValidationError[];\r\n}\r\n\r\nexport interface FormComponentValidationContextState\r\n extends FormComponentValidationContextStateBase {\r\n name: JSX.Element | string;\r\n}\r\n\r\nexport interface FormComponentContextState {\r\n validation: FormComponentValidationContextState;\r\n componentApi: ComponentApi;\r\n}\r\n\r\nexport interface FormValidationContextProps {\r\n formValidationContext?: FormValidationContextState;\r\n}\r\n\r\nexport type ComponentsDict = {\r\n [componentId: string]: FormComponentContextState;\r\n};\r\n\r\nexport interface FormValidationContextState {\r\n isFormValid: boolean;\r\n components: ComponentsDict;\r\n}\r\n\r\nconst FormValidationContext = React.createContext<\r\n FormValidationContextState | undefined\r\n>(undefined);\r\nexport const FormValidationContextProvider = FormValidationContext.Provider;\r\nexport const FormVal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B,aAAa,CAE/CC,SAAS,CAAC;AACL,MAAMC,6BAA6B,GAAGH,qBAAqB,CAACI,QAAQ;AAACC,OAAA,CAAAF,6BAAA,GAAAA,6BAAA;AACrE,MAAMG,6BAA6B,GAAGN,qBAAqB,CAACO,QAAQ;AAACF,OAAA,CAAAC,6BAAA,GAAAA,6BAAA"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
import {
|
2
|
+
import { FormValidationContextProps, FormComponentContextState } from './FormValidationContext';
|
3
3
|
export interface FormValidationSummaryComponentProps {
|
4
4
|
componentsWithErrors: FormComponentContextState[];
|
5
5
|
}
|
@@ -10,7 +10,7 @@ export type FormValidationSummaryProps = {
|
|
10
10
|
title?: string | JSX.Element;
|
11
11
|
footer?: string | JSX.Element;
|
12
12
|
Component?: React.ComponentType<FormValidationSummaryComponentProps> | React.FC<FormValidationSummaryComponentProps>;
|
13
|
-
} &
|
13
|
+
} & FormValidationContextProps;
|
14
14
|
export interface FormValidationSummaryState {
|
15
15
|
}
|
16
16
|
export declare const DefaultComponent: React.FC<FormValidationSummaryComponentProps>;
|
@@ -33,6 +33,6 @@ export declare const FormValidationSummary: React.ForwardRefExoticComponent<Reac
|
|
33
33
|
title?: string | JSX.Element;
|
34
34
|
footer?: string | JSX.Element;
|
35
35
|
Component?: React.ComponentType<FormValidationSummaryComponentProps> | React.FC<FormValidationSummaryComponentProps>;
|
36
|
-
} &
|
36
|
+
} & FormValidationContextProps & {
|
37
37
|
children?: React.ReactNode;
|
38
38
|
}>;
|
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
exports.FormValidationSummaryRaw = exports.FormValidationSummary = exports.DefaultComponent = void 0;
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
8
8
|
var _Guid = _interopRequireDefault(require("../utils/Guid"));
|
9
|
-
var _withFormContext = require("./withFormContext");
|
10
9
|
var _Button = require("./../button/Button");
|
11
10
|
var _classnames = _interopRequireDefault(require("classnames"));
|
11
|
+
var _withFormValidationContext = require("./withFormValidationContext");
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
13
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
14
14
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
@@ -58,7 +58,7 @@ class FormValidationSummaryRaw extends React.PureComponent {
|
|
58
58
|
this.componentId = (0, _Guid.default)();
|
59
59
|
}
|
60
60
|
render() {
|
61
|
-
const componentsWithErrors = this.props.
|
61
|
+
const componentsWithErrors = this.props.formValidationContext ? Object.keys(this.props.formValidationContext.components).map(key => this.props.formValidationContext.components[key]).filter(component => {
|
62
62
|
if (!component.validation.isValid && !component.validation.name) {
|
63
63
|
console.warn(component, 'Has validation error. FormValidationSummary is present but the component has no validation name');
|
64
64
|
}
|
@@ -87,6 +87,6 @@ FormValidationSummaryRaw.defaultProps = {
|
|
87
87
|
headerClassName: 'formValidationSummary__header',
|
88
88
|
footerClassName: 'formValidationSummary__footer'
|
89
89
|
};
|
90
|
-
const FormValidationSummary = (0,
|
90
|
+
const FormValidationSummary = (0, _withFormValidationContext.withFormValidationContext)(FormValidationSummaryRaw);
|
91
91
|
exports.FormValidationSummary = FormValidationSummary;
|
92
92
|
//# sourceMappingURL=FormValidationSummary.js.map
|