@apolitical/component-library 6.3.4 → 6.4.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.
@@ -1,5 +1,5 @@
1
- import { FieldOnChange, IFieldFunctions } from '../../../form/components/form/form.types';
1
+ import { IFieldFunctions } from '../../../form/components/form/form.types';
2
2
  export declare const getValueLength: (value: string | number | boolean | null | undefined) => number;
3
- export declare const getCharacterLimitProps: (limit: number, onChange?: FieldOnChange | null) => {
3
+ export declare const getCharacterLimitProps: (limit: number, functions: IFieldFunctions) => {
4
4
  [key: string]: number | IFieldFunctions;
5
5
  };
@@ -1,3 +1,3 @@
1
1
  import { IFieldWrapper } from '../../form.types';
2
- declare const FieldWrapper: ({ id, intlPath, className, error, functions, limit, showRequiredLabels, type, validation, value, submitOnEnter, ...props }: IFieldWrapper) => import("react/jsx-runtime").JSX.Element;
2
+ declare const FieldWrapper: (fieldWrapperProps: IFieldWrapper) => import("react/jsx-runtime").JSX.Element;
3
3
  export default FieldWrapper;
@@ -27,6 +27,12 @@ export declare const Checkbox: ({ className, disabled, element, functions: allFu
27
27
  topbar?: boolean | undefined;
28
28
  submitSection?: boolean | undefined;
29
29
  } | undefined;
30
+ multipleInputs?: {
31
+ showCount?: boolean | undefined;
32
+ label?: string | undefined;
33
+ maxInputs: number;
34
+ hasButton?: false | import("../../../../../..").ButtonPropsType | undefined;
35
+ } | undefined;
30
36
  name?: string | undefined;
31
37
  options?: import("../../../form.types").IFieldOption[] | undefined;
32
38
  placeholder?: string | undefined;
@@ -35,6 +41,9 @@ export declare const Checkbox: ({ className, disabled, element, functions: allFu
35
41
  } | undefined;
36
42
  required?: boolean | undefined;
37
43
  submitOnEnter?: boolean | undefined;
44
+ styling?: {
45
+ displayOptionsAsPills?: boolean | undefined;
46
+ } | undefined;
38
47
  validation?: import("../../../form.types").IFieldValidation[] | undefined;
39
48
  onClick: (e: React.MouseEvent<HTMLElement>) => void;
40
49
  className: string;
@@ -2,5 +2,6 @@ export * from './input';
2
2
  export * from './input-autocomplete';
3
3
  export * from './checkbox';
4
4
  export * from './dropdown-menu';
5
+ export * from './multiple-inputs';
5
6
  export * from './multiple-options';
6
7
  export * from './password';
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { IField, InputTypes, InputValues } from '../../../form.types';
3
- export declare const Input: ({ className, element, id, inputRef: ref, functions, name, placeholder, type, value, autoFocus, ...props }: IField) => React.DOMElement<{
3
+ export declare const Input: ({ className, element, id, inputRef: ref, functions, name, placeholder, type, value, autoFocus, label, ...props }: IField) => React.DOMElement<{
4
4
  onChange: (e: React.FormEvent<HTMLInputElement>) => void;
5
5
  onMultiSelectSubmit?: ((arg1: import("../../../form.types").FormValues) => void) | undefined;
6
6
  onBlur?: (() => void) | undefined;
@@ -35,13 +35,18 @@ export declare const Input: ({ className, element, id, inputRef: ref, functions,
35
35
  } | undefined;
36
36
  initialValue?: import("../../../form.types").FormValues;
37
37
  intlPath?: string | false | undefined;
38
- label?: React.ReactNode;
39
38
  limit?: number | undefined;
40
39
  multiSelect?: boolean | undefined;
41
40
  multiSelectOptions?: {
42
41
  topbar?: boolean | undefined;
43
42
  submitSection?: boolean | undefined;
44
43
  } | undefined;
44
+ multipleInputs?: {
45
+ showCount?: boolean | undefined;
46
+ label?: string | undefined;
47
+ maxInputs: number;
48
+ hasButton?: false | import("../../../../../..").ButtonPropsType | undefined;
49
+ } | undefined;
45
50
  options?: import("../../../form.types").IFieldOption[] | undefined;
46
51
  props?: {
47
52
  [key: string]: string | number | boolean | object | React.RefObject<any> | (() => void);
@@ -49,6 +54,9 @@ export declare const Input: ({ className, element, id, inputRef: ref, functions,
49
54
  required?: boolean | undefined;
50
55
  shownValue?: InputValues | undefined;
51
56
  submitOnEnter?: boolean | undefined;
57
+ styling?: {
58
+ displayOptionsAsPills?: boolean | undefined;
59
+ } | undefined;
52
60
  validation?: import("../../../form.types").IFieldValidation[] | undefined;
53
61
  ref: React.RefObject<HTMLInputElement>;
54
62
  }, HTMLInputElement>;
@@ -0,0 +1 @@
1
+ export { default as MultipleInputs } from './multiple-inputs';
@@ -0,0 +1,3 @@
1
+ import type { IFieldWrapper } from '../../../form.types';
2
+ export declare const MultipleInputs: ({ id, label: legend, limit, value, placeholder, functions, error: allFormErrors, multipleInputs, validation, fieldData, type, ...props }: IFieldWrapper) => import("react/jsx-runtime").JSX.Element;
3
+ export default MultipleInputs;
@@ -1,3 +1,3 @@
1
1
  import { IField } from '../../../form.types';
2
- export declare const MultipleOptions: ({ className, functions, intlPath, id: groupId, label, multiSelect, name, options, required, type, value, accessibilityOptions, ...props }: IField) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const MultipleOptions: ({ className, functions, intlPath, id: groupId, label, multiSelect, name, options, required, type, value, accessibilityOptions, styling: { displayOptionsAsPills }, ...props }: IField) => import("react/jsx-runtime").JSX.Element;
3
3
  export default MultipleOptions;
@@ -0,0 +1,2 @@
1
+ import type { InputValues } from './form.types';
2
+ export declare const showError: (type: string, value: InputValues) => boolean;
@@ -5,10 +5,12 @@ import { IntlShape } from 'react-intl';
5
5
  export type InputValues = string | number | boolean | null;
6
6
  export type MultipleInputValues = InputValues[];
7
7
  export type FormValues = InputValues | MultipleInputValues | undefined;
8
- export type InputTypes = 'text' | 'textarea' | 'email' | 'url' | 'checkbox' | 'select' | 'radio' | 'password' | 'autocomplete' | 'number';
8
+ export type InputTypes = 'text' | 'textarea' | 'email' | 'url' | 'checkbox' | 'checkboxes' | 'select' | 'radio' | 'password' | 'autocomplete' | 'number' | 'multiple-inputs';
9
9
  export interface ILabel {
10
10
  /** The element to be used, defaulting to `label` */
11
11
  element?: string;
12
+ /** Optional class for the label */
13
+ className?: string;
12
14
  /** The ID of the input to be labelled */
13
15
  htmlFor?: string;
14
16
  }
@@ -41,13 +43,14 @@ export interface IFormPayload {
41
43
  /** Function to call when something fails */
42
44
  onFailure?: (arg: IFormValues, arg2?: FormValues) => void;
43
45
  }
46
+ interface IFormErrors {
47
+ [key: string]: (() => void) | FormValues;
48
+ }
44
49
  export interface IFormReducerAction extends IReducerAction<IFormPayload> {
45
50
  }
46
51
  export interface IFormReducerState {
47
52
  'custom-validation'?: string | boolean;
48
- errors?: {
49
- [key: string]: (() => void) | FormValues;
50
- };
53
+ errors?: IFormErrors;
51
54
  formSubmitted: boolean;
52
55
  isSubmitting: boolean;
53
56
  values?: IFormValues;
@@ -132,7 +135,7 @@ export interface IField {
132
135
  /** The internationalisation path for the field */
133
136
  intlPath?: string | false;
134
137
  /** The label for the field */
135
- label?: string | React.ReactNode;
138
+ label?: string | React.ReactNode | false;
136
139
  /** An optional character limit, for textareas */
137
140
  limit?: number;
138
141
  /** Whether the field can have multiple values, for checkboxes */
@@ -144,6 +147,17 @@ export interface IField {
144
147
  /** Whether to display the submit button in the dropdown - this allows the user to submit the dropdown only */
145
148
  submitSection?: boolean;
146
149
  };
150
+ /** Props for the inputs rendered in a `multiple` field */
151
+ multipleInputs?: {
152
+ /** Whether or not to show the number of filled in inputs in the legend */
153
+ showCount?: boolean;
154
+ /** The template text for each label */
155
+ label?: string;
156
+ /** How many inputs can be added in total */
157
+ maxInputs: number;
158
+ /** Whether to add options with a button */
159
+ hasButton?: false | ButtonPropsType;
160
+ };
147
161
  /** The name of the field */
148
162
  name?: string;
149
163
  /** The options for the field, for checkboxes and dropdowns */
@@ -160,8 +174,12 @@ export interface IField {
160
174
  shownValue?: InputValues;
161
175
  /** Whether hitting enter on the field should submit the form */
162
176
  submitOnEnter?: boolean;
177
+ styling?: {
178
+ /** Whether to display options for the multiselect as pills */
179
+ displayOptionsAsPills?: boolean;
180
+ };
163
181
  /** The type of the input */
164
- type?: InputTypes | 'checkboxes';
182
+ type?: InputTypes;
165
183
  /** The validation for the field */
166
184
  validation?: IFieldValidation[];
167
185
  /** The value of the field */
@@ -239,9 +257,16 @@ export interface IFormProps {
239
257
  }
240
258
  export interface IFieldWrapper extends IField {
241
259
  /** The error to show */
242
- error: string;
260
+ error: string | IFormErrors | undefined;
243
261
  /** Whether the field wrapper should show required labels */
244
262
  showRequiredLabels?: boolean;
245
263
  /** The value of the field */
246
264
  value?: FormValues;
265
+ /** The setter to amend the fields to validate; this is needed for multiple inputs, to give each input its own error handling */
266
+ fieldData?: {
267
+ fields: IField[];
268
+ setFields: React.Dispatch<React.SetStateAction<IField[]>>;
269
+ dispatch: React.Dispatch<IFormReducerAction>;
270
+ };
247
271
  }
272
+ export {};
package/helpers/intl.d.ts CHANGED
@@ -233,6 +233,9 @@ export declare const checkIntlPathExists: (path: string, language?: {
233
233
  form_submitting: string;
234
234
  form_submitted: string;
235
235
  form_success: string;
236
+ form_multipleInputs_label: string;
237
+ form_multipleInputs_filledInCount: string;
238
+ form_multipleInputs_filledInCount_aria: string;
236
239
  inviteForm_email_placeholder: string;
237
240
  inviteForm_title: string;
238
241
  inviteForm_label: string;