coles-solid-library 0.2.8 → 0.3.1

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.
@@ -0,0 +1,11 @@
1
+ import { JSX } from "solid-js";
2
+ interface CheckboxProps {
3
+ label?: string | JSX.Element;
4
+ checked?: boolean;
5
+ defaultChecked?: boolean;
6
+ onChange?: (checked: boolean) => void;
7
+ disabled?: boolean;
8
+ ariaLabel?: string;
9
+ }
10
+ export declare function Checkbox(props: CheckboxProps): JSX.Element;
11
+ export {};
@@ -1,4 +1,4 @@
1
- import { ErrorObject, FormGroupData } from "./formHelp/models";
1
+ import { FormGroupData, ValidationDefault } from "./formHelp/models";
2
2
  export { FormArray } from "./formHelp/formArray";
3
3
  export { Validators } from "./formHelp/validators";
4
4
  /**
@@ -24,7 +24,15 @@ export declare class FormGroup<T extends object> {
24
24
  * @returns A cloned copy of the value for the specified control.
25
25
  */
26
26
  get(): T;
27
- get(key: keyof T): T[keyof T];
27
+ get<K extends keyof T>(key: K): T[K];
28
+ /**
29
+ * Gets a specific item from a FormArray at the given index
30
+ *
31
+ * @param key - The key of the form control containing the FormArray
32
+ * @param index - The index to retrieve from the array
33
+ * @returns The item at the specified index, or undefined if not found
34
+ */
35
+ getArrayItem<K extends keyof T>(key: K, index: number): ElementType<T[K]> | undefined;
28
36
  /**
29
37
  * Checks whether a specific validator error exists for a given control.
30
38
  *
@@ -32,15 +40,28 @@ export declare class FormGroup<T extends object> {
32
40
  * @param errKey - The error key to check for.
33
41
  * @returns `true` if the error exists, otherwise `false`.
34
42
  */
35
- hasValidator(key: keyof T, errKey: 'required' | 'minLength' | 'maxLength' | string): boolean;
36
- getErrors(key: keyof T): ErrorObject<T>[keyof T];
43
+ hasValidator<K extends keyof T>(key: K, errKey: 'required' | 'minLength' | 'maxLength' | string): boolean;
44
+ /**
45
+ * Gets all errors for a specific control
46
+ *
47
+ * @param key - The key of the form control
48
+ * @returns An array of errors for the control
49
+ */
50
+ getErrors<K extends keyof T>(key: K): (typeof this.errors)[0] extends () => infer E ? (E extends Record<K, infer U> ? U : never) : never;
37
51
  /**
38
52
  * Determines if a specific control has any validation errors.
39
53
  *
40
54
  * @param key - The key of the form control.
41
55
  * @returns `true` if any error is present, otherwise `false`.
42
56
  */
43
- hasError(key: keyof T): boolean;
57
+ hasError<K extends keyof T>(key: K): boolean;
58
+ /**
59
+ * Sets an error state for a validator on a specific control
60
+ *
61
+ * @param key - The key of the form control
62
+ * @param errKey - The error key to update
63
+ * @param hasError - Whether the error should be set or cleared
64
+ */
44
65
  setError(key: keyof T, errKey: string, hasError: boolean): void;
45
66
  /**
46
67
  * Sets a new value for a specified form control.
@@ -48,7 +69,22 @@ export declare class FormGroup<T extends object> {
48
69
  * @param key - The key of the form control to update.
49
70
  * @param value - The new value to assign to the control.
50
71
  */
51
- set(key: keyof T, value: T[keyof T]): void;
72
+ set<K extends keyof T>(key: K, value: T[K]): void;
73
+ /**
74
+ * Adds an item to a FormArray control
75
+ *
76
+ * @param key - The key of the FormArray control
77
+ * @param controlValidation - The validation for the new item
78
+ * @param value - Optional initial value for the new item
79
+ */
80
+ addToArray<K extends keyof T>(key: K, controlValidation: ValidationDefault<ElementType<T[K]> & object, keyof ElementType<T[K]>>, value?: ElementType<T[K]> & object): void;
81
+ /**
82
+ * Removes an item from a FormArray control
83
+ *
84
+ * @param key - The key of the FormArray control
85
+ * @param index - The index of the item to remove
86
+ */
87
+ removeFromArray<K extends keyof T>(key: K, index: number): void;
52
88
  /**
53
89
  * Validates the form data.
54
90
  *
@@ -57,5 +93,9 @@ export declare class FormGroup<T extends object> {
57
93
  * @param key - (Optional) The key of the control to validate.
58
94
  * @returns `true` if the control(s) pass all validations; otherwise, `false`.
59
95
  */
60
- validate(key?: keyof T): boolean;
96
+ validate<K extends keyof T>(key?: K): boolean;
61
97
  }
98
+ /**
99
+ * Utility type to extract the element type from an array type
100
+ */
101
+ type ElementType<T> = T extends (infer U)[] ? U : never;
@@ -1,4 +1,4 @@
1
- import { ValidationDefault, ArrayValidation } from "./models";
1
+ import { ValidationDefault, ArrayValidation, Error } from "./models";
2
2
  /**
3
3
  * A class that encapsulates an array of form controls along with their validation logic.
4
4
  *
@@ -31,32 +31,89 @@ export declare class FormArray<T extends object> {
31
31
  * @private
32
32
  */
33
33
  private errors;
34
+ /**
35
+ * The current values of the form controls in the array.
36
+ *
37
+ * @private
38
+ */
39
+ private internalValues;
40
+ /**
41
+ * A function to update the current values of the form controls.
42
+ *
43
+ * @private
44
+ */
45
+ private setValues;
34
46
  /**
35
47
  * Creates an instance of FormArray.
36
48
  *
37
49
  * @param arrayValidation - A tuple where the first element is an initial array of control-level validation definitions
38
50
  * and the second element is an array of array-level validators.
51
+ * @param initialValues - Optional initial values for the form controls.
52
+ */
53
+ constructor(arrayValidation: ArrayValidation<T>, initialValues?: T | T[]);
54
+ /**
55
+ * Gets the current values of the form controls in the array.
56
+ *
57
+ * @returns A cloned copy of the values array.
58
+ */
59
+ get(): T[];
60
+ /**
61
+ * Gets the value of a specific control in the array.
62
+ *
63
+ * @param index - The index of the control.
64
+ * @returns A cloned copy of the control value.
39
65
  */
40
- constructor(arrayValidation: ArrayValidation<T>);
66
+ getAt(index: number): T | undefined;
41
67
  /**
42
- * Removes a control's validation at the specified index.
68
+ * Gets a property value from an object at the specified index.
69
+ *
70
+ * @param index - The index of the control.
71
+ * @param key - The property key to retrieve.
72
+ * @returns The property value, or undefined if not found.
73
+ */
74
+ getProperty<K extends keyof T>(index: number, key: K): T[K] | undefined;
75
+ /**
76
+ * Sets the values of all controls in the array.
77
+ *
78
+ * @param values - The new values for the controls.
79
+ */
80
+ set(values: T[]): void;
81
+ /**
82
+ * Sets the value of a control at the specified index.
83
+ *
84
+ * @param index - The index of the control to update.
85
+ * @param value - The new value for the control.
86
+ */
87
+ setAt(index: number, value: T): void;
88
+ /**
89
+ * Sets a property value on an object at the specified index.
90
+ *
91
+ * @param index - The index of the control.
92
+ * @param key - The property key to set.
93
+ * @param value - The new value for the property.
94
+ */
95
+ setProperty<K extends keyof T>(index: number, key: K, value: T[K]): void;
96
+ /**
97
+ * Removes a control at the specified index.
43
98
  *
44
99
  * @param index - The index of the control to remove.
45
100
  */
46
101
  remove(index: number): void;
47
102
  /**
48
- * Replaces a control's validation at the specified index with a new validation.
103
+ * Replaces a control at the specified index with new validation and value.
49
104
  *
50
105
  * @param index - The index of the control to replace.
51
106
  * @param controlValidation - The new validation to apply for the control.
107
+ * @param value - The new value for the control.
52
108
  */
53
- replace(index: number, controlValidation: ValidationDefault<T, keyof T>): void;
109
+ replace(index: number, controlValidation: ValidationDefault<T, keyof T>, value?: T): void;
54
110
  /**
55
- * Adds a new control validation to the array.
111
+ * Adds a new control to the array with validation and optional value.
56
112
  *
57
113
  * @param controlValidation - The validation definition to add.
114
+ * @param value - Optional value for the new control.
58
115
  */
59
- add(controlValidation: ValidationDefault<T, keyof T>): void;
116
+ add(controlValidation: ValidationDefault<T, keyof T>, value?: T): void;
60
117
  /**
61
118
  * Checks if any validation errors exist.
62
119
  *
@@ -73,6 +130,26 @@ export declare class FormArray<T extends object> {
73
130
  * @returns `true` if the specific error is present, otherwise `false`.
74
131
  */
75
132
  hasValidator(index: number, errKey: string): boolean;
133
+ /**
134
+ * Gets all errors for the form array.
135
+ *
136
+ * @returns An array of error arrays for each control.
137
+ */
138
+ getErrors(): Error[][];
139
+ /**
140
+ * Gets errors for a specific control in the array.
141
+ *
142
+ * @param index - The index of the control.
143
+ * @returns An array of errors for the control, or an empty array if not found.
144
+ */
145
+ getErrorsAt(index: number): Error[];
146
+ /**
147
+ * Validates the form array using current values.
148
+ *
149
+ * @param index - Optional index to validate just one control.
150
+ * @returns True if validation passes, false otherwise.
151
+ */
152
+ validateCurrent(index?: number): boolean;
76
153
  /**
77
154
  * Validates the provided form control values.
78
155
  *
@@ -27,5 +27,5 @@ export type ValidatorObject<T> = {
27
27
  [P in keyof T]?: ValidatorResult<T[P]>[];
28
28
  };
29
29
  export type FormGroupData<T extends object> = {
30
- [P in keyof T]: [T[P], ValidatorResult<T[P]>[]] | FormArray<T>;
30
+ [P in keyof T]: [T[P], ValidatorResult<T[P]>[]] | (T[P] extends object ? FormArray<T[P]> : any);
31
31
  };
@@ -1,39 +1,12 @@
1
1
  import { Component } from "solid-js";
2
2
  export interface IconProps {
3
- /** Name of the icon (must match a valid Material Symbol identifier) */
4
3
  name: string;
5
- /**
6
- * Icon size: can be "small", "medium", "large" or a custom number (in pixels)
7
- * - small: 16px, medium: 24px (default), large: 32px
8
- */
9
- size?: "small" | "medium" | "large" | number;
10
- /** Icon color; default is 'currentColor' */
4
+ size?: number | "small" | "medium" | "large";
11
5
  color?: string;
12
- /**
13
- * Icon weight:
14
- * - "thin" maps to weight 300,
15
- * - "regular" (or "bold") maps to weight 400.
16
- */
17
- weight?: "thin" | "regular" | "bold";
18
- /**
19
- * Icon variant determines the base style.
20
- * Supported values: "outlined" | "rounded" | "sharp".
21
- * Defaults to "outlined".
22
- */
23
6
  variant?: "outlined" | "rounded" | "sharp";
24
- /**
25
- * When true, load the filled version of the icon.
26
- * This toggles the file name to include a `-fill` suffix.
27
- */
28
- filled?: boolean;
29
- /**
30
- * Accessibility label for the icon.
31
- * If not provided, the icon will be hidden from screen readers.
32
- */
33
- ariaLabel?: string;
34
7
  onClick?: (e: MouseEvent) => void;
35
8
  onPointerDown?: (e: PointerEvent) => void;
36
9
  }
37
10
  declare const Icon: Component<IconProps>;
38
- export { Icon };
39
11
  export default Icon;
12
+ export { Icon };
@@ -0,0 +1,12 @@
1
+ import { Component, JSX } from "solid-js";
2
+ interface InputProps extends JSX.InputHTMLAttributes<HTMLInputElement> {
3
+ tooltip?: string;
4
+ transparent?: boolean;
5
+ onChange?: (e: Event & {
6
+ currentTarget: HTMLInputElement;
7
+ target: HTMLInputElement;
8
+ }) => void;
9
+ }
10
+ declare const Input: Component<InputProps>;
11
+ export { Input };
12
+ export default Input;
@@ -4,6 +4,8 @@ interface MenuProps extends JSX.HTMLAttributes<HTMLDivElement> {
4
4
  children: JSX.Element;
5
5
  position?: 'left' | 'center' | 'right';
6
6
  show: [Accessor<boolean>, Setter<boolean>];
7
+ areaExclusionRefs?: Accessor<HTMLElement | undefined>[];
8
+ submenu?: boolean;
7
9
  }
8
10
  export declare const Menu: Component<MenuProps>;
9
11
  export {};
@@ -0,0 +1,14 @@
1
+ import { JSX } from "solid-js";
2
+ interface MenuContext {
3
+ registerWithParent: (child: HTMLElement | undefined) => void;
4
+ unregisterWithParent: (child: HTMLElement | undefined) => void;
5
+ }
6
+ declare const MenuContext: import("solid-js").Context<MenuContext | undefined>;
7
+ export declare const useMenuContext: () => MenuContext | undefined;
8
+ interface MenuProviderProps {
9
+ registerWithParent: (child: HTMLElement | undefined) => void;
10
+ unregisterWithParent: (child: HTMLElement | undefined) => void;
11
+ children: JSX.Element;
12
+ }
13
+ export declare const MenuProvider: (props: MenuProviderProps) => JSX.Element;
14
+ export {};
@@ -1,7 +1,7 @@
1
1
  import { Component, JSX } from "solid-js";
2
2
  interface MenuItemProps extends JSX.HTMLAttributes<HTMLLIElement> {
3
3
  children: JSX.Element;
4
- header?: JSX.Element;
4
+ header?: () => JSX.Element;
5
5
  }
6
6
  export declare const MenuDropdown: Component<MenuItemProps>;
7
7
  export {};
@@ -0,0 +1,13 @@
1
+ import { JSX } from "solid-js";
2
+ interface RadioProps {
3
+ value: string | number;
4
+ label?: string | JSX.Element;
5
+ checked?: boolean;
6
+ defaultChecked?: boolean;
7
+ onChange?: (value: string | number) => void;
8
+ disabled?: boolean;
9
+ name?: string;
10
+ ariaLabel?: string;
11
+ }
12
+ export declare function Radio(props: RadioProps): JSX.Element;
13
+ export {};
@@ -0,0 +1,23 @@
1
+ import { JSX } from "solid-js";
2
+ interface RadioGroupProps {
3
+ name?: string;
4
+ label?: string;
5
+ ariaLabel?: string;
6
+ value?: string | number;
7
+ defaultValue?: string | number;
8
+ onChange?: (value: string | number) => void;
9
+ disabled?: boolean;
10
+ children: JSX.Element | JSX.Element[];
11
+ }
12
+ export interface RadioGroupContextType {
13
+ name: string;
14
+ selectedValue: () => string | number | undefined;
15
+ setSelectedValue: (val: string | number) => void;
16
+ register: (el: HTMLInputElement) => void;
17
+ unregister: (el: HTMLInputElement) => void;
18
+ handleKeyDown: (e: KeyboardEvent) => void;
19
+ disabled: boolean;
20
+ }
21
+ export declare const RadioGroupContext: import("solid-js").Context<RadioGroupContextType | undefined>;
22
+ export declare function RadioGroup(props: RadioGroupProps): JSX.Element;
23
+ export {};
@@ -1,13 +1,4 @@
1
1
  import { JSX } from "solid-js";
2
- interface SelectContextValue<T> {
3
- isSelected: (val: T) => boolean;
4
- selectValue: (val: T) => void;
5
- registerOption?: (val: T, label: JSX.Element) => void;
6
- unregisterOption?: (val: T) => void;
7
- selectRef?: (val: HTMLDivElement | undefined) => HTMLDivElement | undefined;
8
- selectStyle?: () => string;
9
- }
10
- export declare const SelectContext: import("solid-js").Context<SelectContextValue<any> | undefined>;
11
2
  interface SelectProps<T = string, K = boolean> {
12
3
  multiple?: K;
13
4
  value?: T;
@@ -15,6 +6,7 @@ interface SelectProps<T = string, K = boolean> {
15
6
  id?: string;
16
7
  defaultValue?: T;
17
8
  onChange?: (value: T) => void;
9
+ onSelect?: (value: T) => void;
18
10
  placeholder?: string;
19
11
  tooltip?: string;
20
12
  renderValue?: (selected: T) => JSX.Element;
@@ -0,0 +1,14 @@
1
+ import { JSX } from "solid-js";
2
+ export interface SelectContextValue<T> {
3
+ isSelected: (val: T) => boolean;
4
+ selectValue: (val: T) => void;
5
+ registerOption?: (val: T, label: JSX.Element) => void;
6
+ unregisterOption?: (val: T) => void;
7
+ selectRef?: (val: HTMLDivElement | undefined) => HTMLDivElement | undefined;
8
+ selectStyle?: () => string;
9
+ }
10
+ export declare const useSelectContext: () => SelectContextValue<any>;
11
+ export declare const SelectContextProvider: (props: {
12
+ value: SelectContextValue<any>;
13
+ children: JSX.Element;
14
+ }) => JSX.Element;
@@ -3,6 +3,7 @@ interface DropRowProps<T> extends Omit<JSX.HTMLAttributes<HTMLTableRowElement>,
3
3
  children: (item: T, index: number) => JSX.Element;
4
4
  isOpen?: boolean;
5
5
  rowNumber?: number;
6
+ isDropHeader?: boolean;
6
7
  }
7
8
  export declare const DropRowBody: Component<DropRowProps<any>>;
8
9
  export {};
@@ -0,0 +1,18 @@
1
+ import { JSX } from "solid-js";
2
+ interface FormArrayTableProps<T = any> {
3
+ children: JSX.Element;
4
+ formArrayPath: string;
5
+ columns: string[];
6
+ initialData?: T[];
7
+ style?: JSX.CSSProperties | string;
8
+ id?: string;
9
+ class?: string;
10
+ otherStyles?: {
11
+ thead?: any;
12
+ tbody?: any;
13
+ tfoot?: any;
14
+ colGroup?: any;
15
+ };
16
+ }
17
+ export declare const FormArrayTable: <T extends object>(props: FormArrayTableProps<T>) => JSX.Element;
18
+ export {};
@@ -5,7 +5,6 @@ interface TableProps<T = any> {
5
5
  data: Accessor<T[]>;
6
6
  setData?: Setter<T[]>;
7
7
  columns: string[];
8
- formName?: string;
9
8
  style?: JSX.CSSProperties | string;
10
9
  id?: string;
11
10
  class?: string;
@@ -1,4 +1,4 @@
1
- import { JSX } from "solid-js";
1
+ import { Accessor, JSX } from "solid-js";
2
2
  export interface StyleContainer<T> {
3
3
  class?: string;
4
4
  style?: JSX.CSSProperties | string;
@@ -52,13 +52,17 @@ export interface ColumnStyle {
52
52
  export interface ColumnGroupStyle {
53
53
  [colName: string]: StyleContainer<JSX.ColgroupHTMLAttributes<HTMLTableColElement>>;
54
54
  }
55
- export interface TableContext<T> {
55
+ export interface TableContext<T = any> {
56
+ refresh: Accessor<boolean>;
56
57
  getDataSource: () => T[];
57
58
  setDataSource: (data: T[]) => any;
58
59
  addHeaderCell: (name: string, index: number, header: JSX.Element) => void;
59
60
  addRowCell: (index: number, name: string, cell: (item: T, index: number) => JSX.Element, isDropDown?: boolean) => void;
61
+ removeRowCell?: (index: number, name: string) => void;
60
62
  addFooterCell: (index: number, name: string, cell: JSX.Element) => void;
63
+ removeFooterCell?: (index: number, name: string) => void;
61
64
  addColumnStyle: (name: string, style: StyleContainer<JSX.ColHTMLAttributes<HTMLTableColElement>>) => void;
65
+ removeColumnStyle?: (name: string) => void;
62
66
  addHeaderStyle: (name: string, index: number, style: StyleContainer<JSX.ThHTMLAttributes<HTMLTableCellElement>>) => void;
63
67
  addCellStyle: (rowIndex: number, colName: string, style: StyleContainer<JSX.TdHTMLAttributes<HTMLTableCellElement>>) => void;
64
68
  addFootCellStyle: (rowIndex: number, colName: string, style: StyleContainer<JSX.TdHTMLAttributes<HTMLTableCellElement>>) => void;
@@ -0,0 +1,24 @@
1
+ import { Accessor, Component, JSX, Setter } from "solid-js";
2
+ type Props = {
3
+ title: string;
4
+ show: [Accessor<boolean>, Setter<boolean>];
5
+ children?: JSX.Element;
6
+ width?: string;
7
+ height?: string;
8
+ translate?: {
9
+ x?: string;
10
+ y?: string;
11
+ };
12
+ styleType?: "primary" | "accent" | "tertiary";
13
+ onClick?: (e: MouseEvent) => void;
14
+ ref?: JSX.HTMLAttributes<HTMLDivElement>["ref"];
15
+ };
16
+ export declare const Modal: Component<Props>;
17
+ declare module "solid-js" {
18
+ namespace JSX {
19
+ interface Directives {
20
+ clickOutside: () => void;
21
+ }
22
+ }
23
+ }
24
+ export {};
@@ -10,7 +10,8 @@ type Props = {
10
10
  y?: string;
11
11
  };
12
12
  styleType?: "primary" | "accent" | "tertiary";
13
- ref?: Accessor<HTMLDivElement | undefined>;
13
+ onClick?: (e: MouseEvent) => void;
14
+ ref?: JSX.HTMLAttributes<HTMLDivElement>["ref"];
14
15
  };
15
16
  export declare const Modal: Component<Props>;
16
17
  declare module "solid-js" {
package/dist/index.d.ts CHANGED
@@ -4,18 +4,22 @@ export * from './components/Carosel/Slide';
4
4
  export * from './components/Chip/Chip';
5
5
  export * from './components/Chipbar/chipbar';
6
6
  export * from './components/ComponentBody/body.component';
7
- export * from './components/Input/Input';
7
+ export * from './components/Input/inputV2';
8
+ export * from './components/Checkbox/checkbox';
8
9
  export * from './components/Select/select.component';
9
10
  export * from './components/Select/option.component';
10
- export * from './components/Snackbar/snackbar';
11
- export * from './components/popup/popup.component';
12
11
  export * from './components/TextArea/TextArea';
12
+ export * from './components/modal/popup.component';
13
13
  export * from './components/expansion/expansion';
14
- export * from './components/Icon/icon';
14
+ export * from './components/Snackbar/snackbar';
15
15
  export * from './components/Container/container';
16
+ export * from './components/Icon/icon';
16
17
  export * from './components/Menu/menu';
17
18
  export * from './components/Menu/menuitem';
18
19
  export * from './components/Menu/menuDropdown';
20
+ export * from './components/Radio/radioGroup';
21
+ export * from './components/Radio/radio';
22
+ export { FormArray } from './components/Form/formHelp/formArray';
19
23
  export { Form } from './components/Form/form';
20
24
  export { FormField } from './components/FormField/formField';
21
25
  export { FormGroup, Validators } from './components/Form/formGroup';