coles-solid-library 0.1.1 → 0.2.2

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,13 +1,10 @@
1
1
  import { Component, JSX } from "solid-js";
2
- export interface MenuButton {
3
- name: string;
4
- condition?: () => boolean;
5
- action: () => void;
6
- }
2
+ import { ThemeVariables } from "../..";
3
+ type ButtonTypes = Exclude<ThemeVariables, "header" | "subheader">;
7
4
  interface Props extends JSX.ButtonHTMLAttributes<HTMLButtonElement> {
8
- onClick?: (e: MouseEvent) => unknown;
9
5
  transparent?: boolean;
10
- styleType?: "primary" | "accent" | "tertiary";
6
+ theme?: ButtonTypes;
7
+ borderTheme?: ButtonTypes | "none";
11
8
  }
12
9
  declare const Button: Component<Props>;
13
10
  export { Button };
@@ -5,7 +5,6 @@ interface Props {
5
5
  value: string;
6
6
  remove?: () => any;
7
7
  onClick?: (e: MouseEvent) => any;
8
- styleType?: "primary" | "accent" | "tertiary";
9
8
  }
10
9
  declare const Chip: Component<Props>;
11
10
  export { Chip };
@@ -0,0 +1,9 @@
1
+ import { Component, JSX } from "solid-js";
2
+ export type ThemeVariables = "primary" | "primaryVariant" | "secondary" | "secondaryVariant" | "background" | "surface" | "surfaceVariant" | "container" | "error" | "header" | "subheader";
3
+ export type BorderThemeVariables = "borderPrimary" | "borderSecondary" | "borderError" | "borderSurface" | "borderSurfaceVariant" | "borderContainer" | "borderBackground" | "none";
4
+ interface ContainerProps extends JSX.HTMLAttributes<HTMLDivElement> {
5
+ theme: ThemeVariables;
6
+ children: JSX.Element | JSX.Element[] | undefined;
7
+ }
8
+ export declare const Container: Component<ContainerProps>;
9
+ export {};
@@ -1,35 +1,61 @@
1
- interface ValidatorResult<T> {
2
- revalidate: (val: T) => boolean;
3
- errKey: string;
4
- }
5
- export type ValidatorObject<T> = {
6
- [P in keyof T]?: ValidatorResult<T[P]>[];
7
- };
8
- type FormGroupData<T extends object> = {
9
- [P in keyof T]: [T[P], ValidatorResult<T[P]>[]];
10
- };
1
+ import { ErrorObject, FormGroupData } from "./formHelp/models";
2
+ export { FormArray } from "./formHelp/formArray";
3
+ export { Validators } from "./formHelp/validators";
4
+ /**
5
+ * Represents a group of form controls and manages their state, validation, and errors.
6
+ *
7
+ * @template T - The shape of the form's data, where each property corresponds to a form control.
8
+ */
11
9
  export declare class FormGroup<T extends object> {
12
10
  data: FormGroupData<T>;
13
11
  private internalDataSignal;
14
12
  private validators;
15
13
  private errors;
14
+ private keys;
16
15
  constructor(data: FormGroupData<T>);
16
+ /**
17
+ * Gets the current form data or the value of a specific control.
18
+ *
19
+ * @overload
20
+ * @returns A cloned copy of the entire form data.
21
+ *
22
+ * @overload
23
+ * @param key - The key of the control to retrieve.
24
+ * @returns A cloned copy of the value for the specified control.
25
+ */
17
26
  get(): T;
18
27
  get(key: keyof T): T[keyof T];
19
- hasValidator(key: keyof T, errKey: string): boolean;
28
+ /**
29
+ * Checks whether a specific validator error exists for a given control.
30
+ *
31
+ * @param key - The key of the form control.
32
+ * @param errKey - The error key to check for.
33
+ * @returns `true` if the error exists, otherwise `false`.
34
+ */
35
+ hasValidator(key: keyof T, errKey: 'required' | 'minLength' | 'maxLength' | string): boolean;
36
+ getErrors(key: keyof T): ErrorObject<T>[keyof T];
37
+ /**
38
+ * Determines if a specific control has any validation errors.
39
+ *
40
+ * @param key - The key of the form control.
41
+ * @returns `true` if any error is present, otherwise `false`.
42
+ */
20
43
  hasError(key: keyof T): boolean;
44
+ setError(key: keyof T, errKey: string, hasError: boolean): void;
45
+ /**
46
+ * Sets a new value for a specified form control.
47
+ *
48
+ * @param key - The key of the form control to update.
49
+ * @param value - The new value to assign to the control.
50
+ */
21
51
  set(key: keyof T, value: T[keyof T]): void;
52
+ /**
53
+ * Validates the form data.
54
+ *
55
+ * If a key is provided, only that control is validated. If no key is provided, the entire form is validated.
56
+ *
57
+ * @param key - (Optional) The key of the control to validate.
58
+ * @returns `true` if the control(s) pass all validations; otherwise, `false`.
59
+ */
22
60
  validate(key?: keyof T): boolean;
23
61
  }
24
- export declare class Validators {
25
- private static required;
26
- static get Required(): ValidatorResult<unknown>;
27
- private static email;
28
- static get Email(): ValidatorResult<string>;
29
- static minLength(length: number): ValidatorResult<string | any[]>;
30
- static maxLength(length: number): ValidatorResult<string | any[]>;
31
- static pattern(errKey: string, pattern: RegExp): ValidatorResult<string>;
32
- static custom<T>(errKey: string, validator: (value: T) => boolean): ValidatorResult<T>;
33
- private static createValidatorResult;
34
- }
35
- export {};
@@ -0,0 +1,85 @@
1
+ import { ValidationDefault, ArrayValidation } from "./models";
2
+ /**
3
+ * A class that encapsulates an array of form controls along with their validation logic.
4
+ *
5
+ * @template T - An object type representing the shape of a single form control's value.
6
+ */
7
+ export declare class FormArray<T extends object> {
8
+ /**
9
+ * An array of array-level validators. Each validator validates the entire array of form control values.
10
+ * Each element is a ValidatorResult function that returns a validation result for the entire array.
11
+ *
12
+ * @private
13
+ */
14
+ private internalArrayValidation;
15
+ /**
16
+ * An array of control-level validators. Each element is a tuple where the first value is not used
17
+ * in this class and the second value is an array of validators that validate a single control value.
18
+ *
19
+ * @private
20
+ */
21
+ private internalValidation;
22
+ /**
23
+ * A function to update the current state of control-level validations.
24
+ *
25
+ * @private
26
+ */
27
+ private setValidation;
28
+ /**
29
+ * An array of error arrays. Each inner array holds the errors corresponding to a single form control.
30
+ *
31
+ * @private
32
+ */
33
+ private errors;
34
+ /**
35
+ * Creates an instance of FormArray.
36
+ *
37
+ * @param arrayValidation - A tuple where the first element is an initial array of control-level validation definitions
38
+ * and the second element is an array of array-level validators.
39
+ */
40
+ constructor(arrayValidation: ArrayValidation<T>);
41
+ /**
42
+ * Removes a control's validation at the specified index.
43
+ *
44
+ * @param index - The index of the control to remove.
45
+ */
46
+ remove(index: number): void;
47
+ /**
48
+ * Replaces a control's validation at the specified index with a new validation.
49
+ *
50
+ * @param index - The index of the control to replace.
51
+ * @param controlValidation - The new validation to apply for the control.
52
+ */
53
+ replace(index: number, controlValidation: ValidationDefault<T, keyof T>): void;
54
+ /**
55
+ * Adds a new control validation to the array.
56
+ *
57
+ * @param controlValidation - The validation definition to add.
58
+ */
59
+ add(controlValidation: ValidationDefault<T, keyof T>): void;
60
+ /**
61
+ * Checks if any validation errors exist.
62
+ *
63
+ * @param index - (Optional) The index of the control to check for errors.
64
+ * If not provided, it checks the entire form array.
65
+ * @returns `true` if any errors are found, otherwise `false`.
66
+ */
67
+ hasError(index?: number): boolean;
68
+ /**
69
+ * Checks if a specific validator error exists for a control at the given index.
70
+ *
71
+ * @param index - The index of the control.
72
+ * @param errKey - The key identifying the specific error to check for.
73
+ * @returns `true` if the specific error is present, otherwise `false`.
74
+ */
75
+ hasValidator(index: number, errKey: string): boolean;
76
+ /**
77
+ * Validates the provided form control values.
78
+ *
79
+ * @param values - The array of form control values.
80
+ * @param index - (Optional) The index of a single control to validate.
81
+ * If not provided, the method validates all controls in the form array.
82
+ * @returns `true` if all validations pass, otherwise `false`.
83
+ */
84
+ validate(values: T[], index?: number): boolean;
85
+ }
@@ -0,0 +1,31 @@
1
+ import { JSX } from "solid-js";
2
+ import { FormArray } from "./formArray";
3
+ export interface ValidatorResult<T> {
4
+ revalidate: (val: T) => boolean;
5
+ errKey: string;
6
+ }
7
+ export interface Error {
8
+ key: string;
9
+ hasError: boolean;
10
+ display?: JSX.Element;
11
+ }
12
+ export type ValidationDefault<T, P extends keyof T> = [T[P], ValidatorResult<T[P]>[]];
13
+ export type ErrorObject<T> = {
14
+ [P in keyof T]: Error[];
15
+ };
16
+ export type ArrayValidation<T> = [(ValidationDefault<T, keyof T>)[], ValidatorResult<T[]>[]];
17
+ export interface ValidatorResult<T> {
18
+ revalidate: (val: T) => boolean;
19
+ errKey: string;
20
+ hide?: (val: T) => boolean;
21
+ }
22
+ export interface Error {
23
+ key: string;
24
+ hasError: boolean;
25
+ }
26
+ export type ValidatorObject<T> = {
27
+ [P in keyof T]?: ValidatorResult<T[P]>[];
28
+ };
29
+ export type FormGroupData<T extends object> = {
30
+ [P in keyof T]: [T[P], ValidatorResult<T[P]>[]] | FormArray<T>;
31
+ };
@@ -0,0 +1,81 @@
1
+ import { ValidatorResult } from "./models";
2
+ /**
3
+ * A collection of static validator functions that return a ValidatorResult.
4
+ * These validators can be used to validate common conditions such as required fields,
5
+ * email format, minimum/maximum length, custom patterns, and more.
6
+ */
7
+ export declare class Validators {
8
+ /**
9
+ * Validates that a value is present (i.e. not null or undefined).
10
+ * For strings, it checks that the trimmed string is not empty.
11
+ * For arrays, it verifies that the array is not empty.
12
+ *
13
+ * @template T - The type of the value to validate.
14
+ * @returns A ValidatorResult that includes the error key and a revalidation function.
15
+ *
16
+ * @private
17
+ */
18
+ private static required;
19
+ /**
20
+ * A getter that returns the required validator.
21
+ *
22
+ * @returns A ValidatorResult for validating required fields.
23
+ */
24
+ static get Required(): ValidatorResult<unknown>;
25
+ /**
26
+ * Validates that a string is in a valid email format.
27
+ *
28
+ * @returns A ValidatorResult that includes the error key and a revalidation function for email validation.
29
+ *
30
+ * @private
31
+ */
32
+ private static email;
33
+ /**
34
+ * A getter that returns the email validator.
35
+ *
36
+ * @returns A ValidatorResult for validating email format.
37
+ */
38
+ static get Email(): ValidatorResult<string>;
39
+ /**
40
+ * Creates a validator that checks if a value meets the minimum length requirement.
41
+ *
42
+ * @param length - The minimum length required.
43
+ * @returns A ValidatorResult that includes the error key and a revalidation function for minimum length.
44
+ */
45
+ static minLength(length: number): ValidatorResult<string | any[]>;
46
+ /**
47
+ * Creates a validator that checks if a value does not exceed the maximum length.
48
+ *
49
+ * @param length - The maximum allowed length.
50
+ * @returns A ValidatorResult that includes the error key and a revalidation function for maximum length.
51
+ */
52
+ static maxLength(length: number): ValidatorResult<string | any[]>;
53
+ /**
54
+ * Creates a validator that checks if a string matches the provided regular expression pattern.
55
+ *
56
+ * @param errKey - The error key to associate with this validator.
57
+ * @param pattern - The regular expression pattern to test the value against.
58
+ * @returns A ValidatorResult that includes the provided error key and a revalidation function.
59
+ */
60
+ static pattern(errKey: string, pattern: RegExp): ValidatorResult<string>;
61
+ /**
62
+ * Creates a custom validator with a provided validation function.
63
+ *
64
+ * @template T - The type of the value to validate.
65
+ * @param errKey - The error key to associate with this validator.
66
+ * @param validator - A function that receives a value of type T and returns a boolean indicating validity.
67
+ * @returns A ValidatorResult that includes the error key and a revalidation function.
68
+ */
69
+ static custom<T>(errKey: string, validator: (value: T) => boolean, hide?: (val: T) => boolean): ValidatorResult<T>;
70
+ /**
71
+ * A helper function that creates a ValidatorResult object.
72
+ *
73
+ * @template T - The type of the value to validate.
74
+ * @param errKey - The error key associated with the validator.
75
+ * @param revalidate - A function that revalidates a given value and returns true if valid, false otherwise.
76
+ * @returns A ValidatorResult containing the error key and revalidation function.
77
+ *
78
+ * @private
79
+ */
80
+ private static createValidatorResult;
81
+ }
@@ -0,0 +1,7 @@
1
+ import { Component, JSX } from "solid-js";
2
+ interface Props {
3
+ errorName: string;
4
+ children?: JSX.Element;
5
+ }
6
+ export declare const ColeError: Component<Props>;
7
+ export {};
@@ -1,7 +1,7 @@
1
1
  import { Component, JSX } from "solid-js";
2
2
  interface Props extends JSX.FieldsetHTMLAttributes<HTMLFieldSetElement> {
3
3
  children: JSX.Element;
4
- styleType?: "primary" | "accent" | "tertiary";
4
+ styleType?: "primary";
5
5
  name: string;
6
6
  formName?: string;
7
7
  class?: string;
@@ -1,4 +1,5 @@
1
1
  import { Accessor, JSX, Component, Setter } from "solid-js";
2
+ import { Error } from "../Form/formHelp/models";
2
3
  interface formFieldContext<T = string> {
3
4
  getName: Accessor<string>;
4
5
  setName: Setter<string>;
@@ -11,6 +12,14 @@ interface formFieldContext<T = string> {
11
12
  getFieldType: Accessor<string>;
12
13
  setFieldType: Setter<string>;
13
14
  formName?: string;
15
+ getErrors: Accessor<{
16
+ err: Error[];
17
+ }>;
18
+ setErrors: Setter<{
19
+ err: Error[];
20
+ }>;
21
+ getFormFieldRef: Accessor<HTMLFieldSetElement | undefined>;
22
+ setFormFieldRef: Setter<HTMLFieldSetElement | undefined>;
14
23
  }
15
24
  interface ProviderProps {
16
25
  children: JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { Component, JSX } from "solid-js";
2
+ interface HeaderProps extends JSX.HTMLAttributes<HTMLDivElement> {
3
+ children: JSX.Element | JSX.Element[] | undefined;
4
+ }
5
+ export declare const HeaderBar: Component<HeaderProps>;
6
+ export declare const SubHeaderBar: Component<HeaderProps>;
7
+ export {};
@@ -0,0 +1,9 @@
1
+ import { Accessor, Component, JSX, Setter } from "solid-js";
2
+ interface MenuProps extends JSX.HTMLAttributes<HTMLDivElement> {
3
+ anchorElement: Accessor<HTMLElement | undefined>;
4
+ children: JSX.Element;
5
+ position?: 'left' | 'center' | 'right';
6
+ show: [Accessor<boolean>, Setter<boolean>];
7
+ }
8
+ export declare const Menu: Component<MenuProps>;
9
+ export {};
@@ -0,0 +1,6 @@
1
+ import { Component, JSX } from "solid-js";
2
+ interface MenuItemProps extends JSX.HTMLAttributes<HTMLLIElement> {
3
+ children: JSX.Element;
4
+ }
5
+ export declare const MenuItem: Component<MenuItemProps>;
6
+ export {};
@@ -21,7 +21,6 @@ interface SelectProps<T = string, K = boolean> {
21
21
  class?: string;
22
22
  dropdownClass?: string;
23
23
  children: JSX.Element;
24
- style?: "primary" | "accent" | "tertiary";
25
24
  }
26
25
  export declare function Select<T, K extends boolean = false>(props: SelectProps<(K extends true ? T[] : T), K>): JSX.Element;
27
26
  export {};
@@ -0,0 +1,24 @@
1
+ import { Component } from "solid-js";
2
+ interface TabBarProps {
3
+ tabs: string[];
4
+ activeTab: number;
5
+ class?: string;
6
+ indicatorClass?: string;
7
+ noRail?: boolean;
8
+ onTabChange?: (label: string, index: number) => void;
9
+ tabPosition?: "start" | "center" | "end" | "stretch";
10
+ colors?: {
11
+ text?: string;
12
+ activeText?: string;
13
+ background?: string;
14
+ indicator?: string;
15
+ };
16
+ size?: {
17
+ height?: string;
18
+ fontSize?: string;
19
+ indicatorHeight?: string;
20
+ };
21
+ animationTiming?: string;
22
+ }
23
+ export declare const TabBar: Component<TabBarProps>;
24
+ export {};
@@ -4,7 +4,8 @@ interface BaseCellProps<T> extends Omit<JSX.TdHTMLAttributes<HTMLTableCellElemen
4
4
  class?: string;
5
5
  header?: boolean;
6
6
  footer?: boolean;
7
+ rowNumber?: number;
7
8
  children: JSX.Element | ((item: T, index: number) => JSX.Element);
8
9
  }
9
- export declare const Cell: <T>(props: BaseCellProps<T>) => JSX.Element;
10
+ export declare const Cell: <T = any>(props: BaseCellProps<T>) => JSX.Element;
10
11
  export {};
@@ -3,6 +3,7 @@ interface HeaderProps extends JSX.ThHTMLAttributes<HTMLTableCellElement> {
3
3
  children: JSX.Element;
4
4
  style?: JSX.CSSProperties;
5
5
  class?: string;
6
+ rowNumber?: number;
6
7
  }
7
8
  export declare const Header: <T>(props: HeaderProps) => JSX.Element;
8
9
  export {};
@@ -1,8 +1,8 @@
1
- import { JSX, Setter } from "solid-js";
1
+ import { Accessor, JSX, Setter } from "solid-js";
2
2
  import { StyleContainer } from "./tableProvider";
3
- interface TableProps<T> {
3
+ interface TableProps<T = any> {
4
4
  children: JSX.Element;
5
- data: T[];
5
+ data: Accessor<T[]>;
6
6
  setData?: Setter<T[]>;
7
7
  columns: string[];
8
8
  formName?: string;
@@ -49,7 +49,7 @@ export interface ColumnGroupStyle {
49
49
  }
50
50
  export interface TableContext<T> {
51
51
  getDataSource: () => T[];
52
- setDataSource: (data: T[]) => void;
52
+ setDataSource: (data: T[]) => any;
53
53
  addHeaderCell: (name: string, index: number, header: JSX.Element) => void;
54
54
  addRowCell: (index: number, name: string, cell: (item: T, index: number) => JSX.Element) => void;
55
55
  addFooterCell: (index: number, name: string, cell: JSX.Element) => void;
@@ -69,7 +69,6 @@ export declare const TableProvider: <T>(props: TableProviderProps<T>) => JSX.Ele
69
69
  interface ColumnProps {
70
70
  children: JSX.Element;
71
71
  name: string;
72
- rowNumber?: number;
73
72
  }
74
73
  export declare const ColumnProvider: (props: ColumnProps) => JSX.Element;
75
74
  export declare const useColumnContext: () => {
@@ -78,6 +77,5 @@ export declare const useColumnContext: () => {
78
77
  };
79
78
  export interface ColumnInfo {
80
79
  name: string;
81
- rowNumber: number;
82
80
  }
83
81
  export {};
@@ -6,7 +6,6 @@ type Props = {
6
6
  };
7
7
  extraLogic?: () => void;
8
8
  startOpen?: boolean;
9
- styleType?: "primary" | "accent" | "tertiary";
10
9
  [key: string]: any;
11
10
  arrowSize?: {
12
11
  width: string;
@@ -10,20 +10,8 @@ type Props = {
10
10
  y?: string;
11
11
  };
12
12
  styleType?: "primary" | "accent" | "tertiary";
13
- setClose?: Setter<boolean>;
14
13
  ref?: Accessor<HTMLDivElement | undefined>;
15
14
  };
16
- /**
17
- *
18
- * @param title {string} {string} - The title of the modal.
19
- * @param width {string} {string} - The css width of the modal.
20
- * @param maxWidth {string} {string} - The optional css max-width of the modal.
21
- * @param height {string} {string} - The css height of the modal.
22
- * @param maxHeight {string} {string} - The optional css max-height of the modal.
23
- * @param translate {x{x: string, y: string} - Override the default x and y coordinates of the modal.
24
- * @param backgroundClick [Accessor <bool>, Setter <bool>] - A signal and setter for enabling the background click.
25
- * @returns - A Modal component.
26
- */
27
15
  export declare const Modal: Component<Props>;
28
16
  declare module "solid-js" {
29
17
  namespace JSX {
package/dist/index.d.ts CHANGED
@@ -10,7 +10,6 @@ export * from './components/Select/select.component';
10
10
  export * from './components/Select/option.component';
11
11
  export * from './components/Snackbar/snackbar';
12
12
  export * from './components/popup/popup.component';
13
- export * from './components/Tabs/tabs';
14
13
  export * from './components/TextArea/TextArea';
15
14
  export * from './components/expansion/expansion';
16
15
  export * from './components/popup/popup.component';
@@ -24,3 +23,8 @@ export { Column } from './components/TableV2/column';
24
23
  export { Cell } from './components/TableV2/cell';
25
24
  export { Header } from './components/TableV2/header';
26
25
  export { type StyleContainer } from './components/TableV2/tableProvider';
26
+ export { TabBar } from './components/TabV2/tabs';
27
+ export * from './components/Container/container';
28
+ export * from './components/Menu/menu';
29
+ export * from './components/Menu/menuitem';
30
+ export { ColeError as FieldError } from './components/FormField/coleError';