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.
Files changed (31) hide show
  1. package/build/components/button/Button.js +21 -11
  2. package/build/components/button/Button.js.map +1 -1
  3. package/build/components/form/Form.d.ts +4 -2
  4. package/build/components/form/Form.js +36 -27
  5. package/build/components/form/Form.js.map +1 -1
  6. package/build/components/form/FormContext.d.ts +1 -14
  7. package/build/components/form/FormContext.js.map +1 -1
  8. package/build/components/form/FormValidationContext.d.ts +27 -0
  9. package/build/components/form/FormValidationContext.js +15 -0
  10. package/build/components/form/FormValidationContext.js.map +1 -0
  11. package/build/components/form/FormValidationSummary.d.ts +3 -3
  12. package/build/components/form/FormValidationSummary.js +3 -3
  13. package/build/components/form/FormValidationSummary.js.map +1 -1
  14. package/build/components/form/withFormContext.d.ts +1 -1
  15. package/build/components/form/withFormContext.js.map +1 -1
  16. package/build/components/form/withFormValidationContext.d.ts +3 -0
  17. package/build/components/form/withFormValidationContext.js +25 -0
  18. package/build/components/form/withFormValidationContext.js.map +1 -0
  19. package/build/components/submit/Submit.d.ts +3 -2
  20. package/build/components/submit/Submit.js +5 -5
  21. package/build/components/submit/Submit.js.map +1 -1
  22. package/build/dist/report.html +1 -1
  23. package/package.json +1 -1
  24. package/src/lib/components/button/Button.tsx +16 -13
  25. package/src/lib/components/form/Form.tsx +48 -32
  26. package/src/lib/components/form/FormContext.ts +4 -18
  27. package/src/lib/components/form/FormValidationContext.ts +40 -0
  28. package/src/lib/components/form/FormValidationSummary.tsx +12 -7
  29. package/src/lib/components/form/withFormContext.tsx +14 -11
  30. package/src/lib/components/form/withFormValidationContext.tsx +29 -0
  31. package/src/lib/components/submit/Submit.tsx +9 -7
@@ -1,11 +1,14 @@
1
1
  import * as React from 'react';
2
2
  import guid from '../utils/Guid';
3
- import { withFormContext } from './withFormContext';
4
- import { FormContextProps, FormComponentContextState } from './FormContext';
3
+ import {
4
+ FormValidationContextProps,
5
+ FormComponentContextState,
6
+ } from './FormValidationContext';
5
7
  import { Button } from './../button/Button';
6
8
  import classNames from 'classnames';
7
9
 
8
10
  import * as ArrowIcon from 'material-design-icons/maps/svg/production/ic_my_location_24px.svg';
11
+ import { withFormValidationContext } from './withFormValidationContext';
9
12
 
10
13
  export interface FormValidationSummaryComponentProps {
11
14
  componentsWithErrors: FormComponentContextState[];
@@ -20,7 +23,7 @@ export type FormValidationSummaryProps = {
20
23
  Component?:
21
24
  | React.ComponentType<FormValidationSummaryComponentProps>
22
25
  | React.FC<FormValidationSummaryComponentProps>;
23
- } & FormContextProps;
26
+ } & FormValidationContextProps;
24
27
 
25
28
  export interface FormValidationSummaryState {}
26
29
 
@@ -86,9 +89,9 @@ export class FormValidationSummaryRaw extends React.PureComponent<
86
89
  public componentId = guid();
87
90
 
88
91
  public render() {
89
- const componentsWithErrors = this.props.formContext
90
- ? Object.keys(this.props.formContext.components)
91
- .map((key) => this.props.formContext.components[key])
92
+ const componentsWithErrors = this.props.formValidationContext
93
+ ? Object.keys(this.props.formValidationContext.components)
94
+ .map((key) => this.props.formValidationContext.components[key])
92
95
  .filter((component) => {
93
96
  if (!component.validation.isValid && !component.validation.name) {
94
97
  console.warn(
@@ -119,4 +122,6 @@ export class FormValidationSummaryRaw extends React.PureComponent<
119
122
  }
120
123
 
121
124
  export const FormValidationSummary =
122
- withFormContext<FormValidationSummaryProps>(FormValidationSummaryRaw);
125
+ withFormValidationContext<FormValidationSummaryProps>(
126
+ FormValidationSummaryRaw
127
+ );
@@ -2,19 +2,22 @@ import * as React from 'react';
2
2
  import { FormContextConsumer, FormContextProps } from './FormContext';
3
3
 
4
4
  export function withFormContext<P extends FormContextProps>(
5
- Component: React.ComponentClass<P>
5
+ Component: React.ComponentClass<P> | React.ForwardRefExoticComponent<P>
6
6
  ): React.ForwardRefExoticComponent<
7
- React.RefAttributes<InstanceType<typeof Component>> &
7
+ React.RefAttributes<
8
+ React.ComponentClass<P> | React.ForwardRefExoticComponent<P>
9
+ > &
8
10
  React.PropsWithoutRef<React.PropsWithChildren<P>>
9
11
  > {
10
- const WithFormContext = React.forwardRef<InstanceType<typeof Component>, P>(
11
- (props, ref) => {
12
- return (
13
- <FormContextConsumer>
14
- {value => <Component ref={ref} {...props} formContext={value} />}
15
- </FormContextConsumer>
16
- );
17
- }
18
- );
12
+ const WithFormContext = React.forwardRef<
13
+ React.ComponentClass<P> | React.ForwardRefExoticComponent<P>,
14
+ P
15
+ >((props, ref) => {
16
+ return (
17
+ <FormContextConsumer>
18
+ {(value) => <Component ref={ref} {...props} formContext={value} />}
19
+ </FormContextConsumer>
20
+ );
21
+ });
19
22
  return WithFormContext;
20
23
  }
@@ -0,0 +1,29 @@
1
+ import * as React from 'react';
2
+ import {
3
+ FormValidationContextConsumer,
4
+ FormValidationContextProps,
5
+ } from './FormValidationContext';
6
+
7
+ export function withFormValidationContext<P extends FormValidationContextProps>(
8
+ Component: React.ComponentClass<P>
9
+ ): React.ForwardRefExoticComponent<
10
+ React.RefAttributes<InstanceType<typeof Component>> &
11
+ React.PropsWithoutRef<React.PropsWithChildren<P>>
12
+ > {
13
+ const WithFormValidationContext = React.forwardRef<
14
+ InstanceType<typeof Component>,
15
+ P
16
+ >((props, ref) => {
17
+ return (
18
+ <FormValidationContextConsumer>
19
+ {(value) => {
20
+ console.log('value', value);
21
+ return (
22
+ <Component ref={ref} {...props} formValidationContext={value} />
23
+ );
24
+ }}
25
+ </FormValidationContextConsumer>
26
+ );
27
+ });
28
+ return WithFormValidationContext;
29
+ }
@@ -7,10 +7,11 @@ import {
7
7
  defaultBaseTranslations,
8
8
  } from '../base/input/BaseInput';
9
9
  import { Button, ButtonProps } from '../button/Button';
10
- import { withFormContext } from '../form/withFormContext';
11
10
  import { FormValidationSummaryRaw } from './../form/FormValidationSummary';
12
11
  import SubmitValidationSummary from './subComponents/SubmitValidationSummary';
13
12
  import { withThemeContext } from '../themeProvider/withThemeContext';
13
+ import { withFormValidationContext } from '../form/withFormValidationContext';
14
+ import { FormValidationContextProps } from '../form/FormValidationContext';
14
15
 
15
16
  // Misc
16
17
  export const defaultSubmitTranslations = {
@@ -27,7 +28,7 @@ export type SubmitProps = BaseInputProps<never, SubmitTranslations> &
27
28
  validateForm?: boolean;
28
29
  disabledTitle?: string;
29
30
  showValidationSummaryTooltip?: boolean;
30
- };
31
+ } & FormValidationContextProps;
31
32
 
32
33
  export interface SubmitState extends BaseInputState {}
33
34
 
@@ -70,7 +71,8 @@ export class SubmitRaw extends BaseInput<
70
71
  this.props.tooltip
71
72
  ? this.props.tooltip
72
73
  : this.props.showValidationSummaryTooltip &&
73
- !this.props.formContext.isFormValid && (
74
+ this.props.formValidationContext &&
75
+ !this.props.formValidationContext.isFormValid && (
74
76
  <FormValidationSummaryRaw
75
77
  title={translations.hangOn}
76
78
  footer={translations.needsFixing}
@@ -78,7 +80,7 @@ export class SubmitRaw extends BaseInput<
78
80
  headerClassName="submitValidationSummary__header"
79
81
  footerClassName="submitValidationSummary__footer"
80
82
  Component={SubmitValidationSummary}
81
- formContext={this.props.formContext}
83
+ formValidationContext={this.props.formValidationContext}
82
84
  />
83
85
  )
84
86
  }
@@ -103,8 +105,8 @@ export class SubmitRaw extends BaseInput<
103
105
  const disabled = this.getDisabled();
104
106
  return disabled
105
107
  ? disabled
106
- : this.props.validateForm && this.props.formContext
107
- ? !this.props.formContext.isFormValid
108
+ : this.props.validateForm && this.props.formValidationContext
109
+ ? !this.props.formValidationContext.isFormValid
108
110
  : false;
109
111
  }
110
112
  }
@@ -112,6 +114,6 @@ export class SubmitRaw extends BaseInput<
112
114
  export const Submit = withThemeContext<
113
115
  SubmitProps,
114
116
  InstanceType<typeof SubmitRaw>
115
- >(withFormContext<SubmitProps>(SubmitRaw), 'submit');
117
+ >(withFormValidationContext<SubmitProps>(SubmitRaw), 'submit');
116
118
 
117
119
  export default Submit;