chop-logic-components 0.11.0 → 0.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.
Files changed (24) hide show
  1. package/dist/components/containers/form/FormContext.d.ts +2 -0
  2. package/dist/components/containers/form/controller.d.ts +15 -0
  3. package/dist/components/containers/form/helpers.d.ts +4 -13
  4. package/dist/components/inputs/numeric/NumericInput.d.ts +2 -0
  5. package/dist/components/inputs/numeric/helpers.d.ts +13 -2
  6. package/dist/components/inputs/text/TextInput.d.ts +8 -1
  7. package/dist/components/inputs/text/__docs__/TextInput.stories.d.ts +3 -1
  8. package/dist/components/inputs/text/helpers.d.ts +12 -1
  9. package/dist/components/misc/icon/Icon.d.ts +2 -0
  10. package/dist/components/misc/icon/elements/Hide.d.ts +4 -0
  11. package/dist/components/misc/icon/elements/Show.d.ts +4 -0
  12. package/dist/components/misc/input-inner-button/InputInnerButton.d.ts +10 -0
  13. package/dist/components/misc/input-inner-button/InputInnerButton.styled.d.ts +2 -0
  14. package/dist/hooks/use-element-ids/__tests__/use-element-ids.test.d.ts +1 -0
  15. package/dist/index.cjs.js +186 -186
  16. package/dist/index.cjs.js.map +1 -1
  17. package/dist/index.es.js +5484 -5397
  18. package/dist/index.es.js.map +1 -1
  19. package/package.json +10 -10
  20. package/dist/components/misc/clear-input-button/ClearInputButton.d.ts +0 -8
  21. package/dist/components/misc/clear-input-button/ClearInputButton.styled.d.ts +0 -2
  22. /package/dist/components/{misc/clear-input-button/__tests__/ClearInputButton.test.d.ts → containers/form/__tests__/helpers.test.d.ts} +0 -0
  23. /package/dist/{hooks/use-element-id/__tests__/use-element-ids.test.d.ts → components/misc/input-inner-button/__tests__/InputInnerButton.test.d.ts} +0 -0
  24. /package/dist/hooks/{use-element-id → use-element-ids}/index.d.ts +0 -0
@@ -3,10 +3,12 @@ import { default as React } from 'react';
3
3
  export type ChopLogicFormData = {
4
4
  [key: string]: unknown;
5
5
  };
6
+ export type ChopLogicFormValidationState = [string, boolean][];
6
7
  export type ChopLogicFormInput = HTMLInputElement | HTMLSelectElement;
7
8
  export type ChopLogicFormInputParams = {
8
9
  name: string;
9
10
  value: unknown;
11
+ valid?: boolean;
10
12
  };
11
13
  export type ChopLogicFormContextProps = {
12
14
  onChangeFormInput?: (params: ChopLogicFormInputParams) => void;
@@ -0,0 +1,15 @@
1
+ import { FormEvent } from 'react';
2
+ import { ChopLogicFormData, ChopLogicFormInputParams } from './FormContext';
3
+
4
+ export declare function useChopLogicFormController({ initialValues, onReset, onSubmit, onClickSubmit, }: {
5
+ initialValues?: ChopLogicFormData;
6
+ onReset?: React.FormEventHandler<HTMLFormElement>;
7
+ onSubmit?: React.FormEventHandler<HTMLFormElement>;
8
+ onClickSubmit?: (data: ChopLogicFormData) => void;
9
+ }): {
10
+ handleInputChange: (params: ChopLogicFormInputParams) => void;
11
+ handleSubmit: (event: FormEvent<HTMLFormElement>) => void;
12
+ handleReset: (event: FormEvent<HTMLFormElement>) => void;
13
+ resetSignal: number;
14
+ valid: boolean;
15
+ };
@@ -1,14 +1,5 @@
1
- import { FormEvent } from 'react';
2
- import { ChopLogicFormData, ChopLogicFormInputParams } from './FormContext';
1
+ import { ChopLogicFormData, ChopLogicFormInputParams, ChopLogicFormValidationState } from './FormContext';
3
2
 
4
- export declare function useChopLogicFormController({ initialValues, onReset, onSubmit, onClickSubmit, }: {
5
- initialValues?: ChopLogicFormData;
6
- onReset?: React.FormEventHandler<HTMLFormElement>;
7
- onSubmit?: React.FormEventHandler<HTMLFormElement>;
8
- onClickSubmit?: (data: ChopLogicFormData) => void;
9
- }): {
10
- handleInputChange: (params: ChopLogicFormInputParams) => void;
11
- handleSubmit: (event: FormEvent<HTMLFormElement>) => void;
12
- handleReset: (event: FormEvent<HTMLFormElement>) => void;
13
- resetSignal: number;
14
- };
3
+ export declare function getInitialValidationState(data?: ChopLogicFormData): ChopLogicFormValidationState;
4
+ export declare function updateValidationState(state: ChopLogicFormValidationState, params: ChopLogicFormInputParams): ChopLogicFormValidationState;
5
+ export declare function isFormDataValid(state: ChopLogicFormValidationState): boolean;
@@ -1,10 +1,12 @@
1
1
  import { default as React } from 'react';
2
2
 
3
+ export type NumericValidationFunction = (input?: number) => boolean;
3
4
  export type ChopLogicNumericInputProps = React.InputHTMLAttributes<HTMLInputElement> & {
4
5
  name: string;
5
6
  label: string;
6
7
  valid?: boolean;
7
8
  errorMessage?: string;
9
+ validator?: NumericValidationFunction;
8
10
  };
9
11
  declare const ChopLogicNumericInput: React.FC<ChopLogicNumericInputProps>;
10
12
  export default ChopLogicNumericInput;
@@ -1,20 +1,31 @@
1
1
  import { ChangeEventHandler } from 'react';
2
2
  import { ChopLogicFormData } from '../../../../../../../../../src/components/containers/form/FormContext';
3
+ import { NumericValidationFunction } from './NumericInput';
3
4
 
4
5
  export declare function getNumericInputInitialValue({ name, initialValues, defaultValue, }: {
5
6
  name: string;
6
7
  initialValues?: ChopLogicFormData;
7
8
  defaultValue?: string | number | readonly string[];
8
9
  }): number;
9
- export declare function useChopLogicNumericInputController({ name, defaultValue, onChange, min, max, }: {
10
+ export declare function validateNumericInputValue({ value, required, validator, maxValue, minValue, }: {
11
+ value?: number;
12
+ required?: boolean;
13
+ validator?: NumericValidationFunction;
14
+ maxValue?: number;
15
+ minValue?: number;
16
+ }): boolean;
17
+ export declare function useChopLogicNumericInputController({ name, defaultValue, onChange, min, max, required, validator, }: {
10
18
  name: string;
11
19
  defaultValue?: string | number | readonly string[];
12
20
  onChange?: ChangeEventHandler<HTMLInputElement>;
13
21
  min?: string | number;
14
22
  max?: string | number;
23
+ required: boolean;
24
+ validator?: NumericValidationFunction;
15
25
  }): {
16
26
  handleChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
17
- value: string | number;
27
+ value: number;
28
+ valid: boolean;
18
29
  minValue: number;
19
30
  maxValue: number;
20
31
  };
@@ -1,12 +1,19 @@
1
1
  import { default as React } from 'react';
2
2
 
3
+ export type RegExpWithFlags = {
4
+ regexp: string;
5
+ flags?: string;
6
+ };
7
+ export type TextValidationFunction = (input: string) => boolean;
3
8
  export type ChopLogicTextInputProps = React.InputHTMLAttributes<HTMLInputElement> & {
4
9
  name: string;
5
10
  label: string;
6
11
  valid?: boolean;
7
12
  errorMessage?: string;
8
- hasClearButton?: boolean;
13
+ clearable?: boolean;
9
14
  onClear?: () => void;
15
+ type?: 'text' | 'email' | 'password';
16
+ validator?: RegExpWithFlags | TextValidationFunction;
10
17
  };
11
18
  declare const ChopLogicTextInput: React.FC<ChopLogicTextInputProps>;
12
19
  export default ChopLogicTextInput;
@@ -4,4 +4,6 @@ import { default as TextInputExample } from './TextInputExample';
4
4
  declare const meta: Meta<typeof TextInputExample>;
5
5
  export default meta;
6
6
  type Story = StoryObj<typeof TextInputExample>;
7
- export declare const Default: Story;
7
+ export declare const DefaultTextInput: Story;
8
+ export declare const PasswordInput: Story;
9
+ export declare const EmailInput: Story;
@@ -1,17 +1,28 @@
1
1
  import { ChangeEventHandler } from 'react';
2
2
  import { ChopLogicFormData } from '../../../../../../../../../src/components/containers/form/FormContext';
3
+ import { RegExpWithFlags, TextValidationFunction } from './TextInput';
3
4
 
5
+ export declare function validateTextInputValue({ value, required, validator, }: {
6
+ value: string;
7
+ required: boolean;
8
+ validator?: RegExpWithFlags | TextValidationFunction;
9
+ }): boolean;
4
10
  export declare function getTextInputInitialValue({ name, initialValues, defaultValue, }: {
5
11
  name: string;
6
12
  initialValues?: ChopLogicFormData;
7
13
  defaultValue?: string | number | readonly string[];
8
14
  }): string;
9
- export declare function useChopLogicTextInputController({ name, defaultValue, onChange, }: {
15
+ export declare function useChopLogicTextInputController({ name, defaultValue, onChange, required, validator, }: {
10
16
  name: string;
17
+ required: boolean;
18
+ validator?: RegExpWithFlags | TextValidationFunction;
11
19
  defaultValue?: string | number | readonly string[];
12
20
  onChange?: ChangeEventHandler<HTMLInputElement>;
13
21
  }): {
14
22
  value: string;
23
+ valid: boolean;
24
+ passwordShown: boolean;
15
25
  handleChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
16
26
  handleClear: () => void;
27
+ togglePassword: () => void;
17
28
  };
@@ -16,10 +16,12 @@ export declare enum CLIcon {
16
16
  Error = "error",
17
17
  Forward = "forward",
18
18
  Help = "help",
19
+ Hide = "hide",
19
20
  Info = "info",
20
21
  Paste = "paste",
21
22
  Question = "question",
22
23
  Save = "save",
24
+ Show = "show",
23
25
  Upload = "upload",
24
26
  Warning = "warning",
25
27
  Remove = "remove"
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+
3
+ declare function HideIcon(props: React.SVGProps<SVGSVGElement>): import("react/jsx-runtime").JSX.Element;
4
+ export default HideIcon;
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+
3
+ declare function ShowIcon(props: React.SVGProps<SVGSVGElement>): import("react/jsx-runtime").JSX.Element;
4
+ export default ShowIcon;
@@ -0,0 +1,10 @@
1
+ import { default as React } from 'react';
2
+ import { CLIcon } from '../../../../../../../../../src/components/misc/icon/Icon';
3
+
4
+ type ClearInputButtonProps = {
5
+ onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
6
+ label: string;
7
+ icon: CLIcon;
8
+ };
9
+ declare const InputInnerButton: React.FC<ClearInputButtonProps>;
10
+ export default InputInnerButton;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const StyledInputInnerButton: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components').FastOmit<import('react').DetailedHTMLProps<import('react').ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, never>> & string;