@open-xamu-co/ui-common-types 4.0.0-next.6 → 4.0.0-next.8

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-xamu-co/ui-common-types",
3
- "version": "4.0.0-next.6",
3
+ "version": "4.0.0-next.8",
4
4
  "description": "Xamu shared types",
5
5
  "author": "@xamu-co",
6
6
  "main": "src/index.ts",
@@ -31,7 +31,7 @@
31
31
  "build:legacy": "rimraf dist && tsc --outDir dist --declaration --emitDeclarationOnly"
32
32
  },
33
33
  "dependencies": {
34
- "@open-xamu-co/ui-common-enums": "^4.0.0-next.2",
34
+ "@open-xamu-co/ui-common-enums": "^4.0.0-next.3",
35
35
  "@fortawesome/fontawesome-common-types": "^6.4.0",
36
36
  "sweetalert2": "^11.11.1"
37
37
  },
package/src/form/class.ts CHANGED
@@ -7,11 +7,12 @@ import type {
7
7
  import type {
8
8
  iFormInput,
9
9
  iFormInputDefault,
10
+ iFormOption,
10
11
  iFormValue,
11
12
  tFormAutocomplete,
12
13
  tFormIcon,
14
+ tOptionsLoaderFn,
13
15
  } from "./types";
14
- import type { iSelectOption } from "../values.js";
15
16
 
16
17
  export declare abstract class tFormInputDefault<
17
18
  T extends eFormTypeBase | eFormTypeSimple | eFormTypeComplex = eFormTypeSimple,
@@ -44,12 +45,13 @@ export declare abstract class tFormInput<
44
45
  // public readonly
45
46
  public readonly name: string;
46
47
  public readonly title?: string;
47
- public readonly multiple: boolean;
48
- public readonly min: number;
49
- public readonly max: number;
50
- public readonly meta?: Record<string, any>;
48
+ public readonly optionsFilter?: tOptionsLoaderFn;
51
49
  // public
52
- public options: iSelectOption[];
50
+ public multiple: boolean;
51
+ public min: number;
52
+ public max: number;
53
+ public meta?: Record<string, any>;
54
+ public options: iFormOption[];
53
55
  public values: V[];
54
56
  public defaults?: [
55
57
  iFormInputDefault<eFormTypeBase | eFormTypeSimple | eFormTypeComplex>,
package/src/form/types.ts CHANGED
@@ -34,7 +34,17 @@ export interface iFormResults<T = Record<string, unknown>> {
34
34
  invalidInputs: iInvalidInput[];
35
35
  }
36
36
 
37
- export type tTextInputType = "text" | "email" | "password" | "search" | "url" | "number" | "tel";
37
+ export type tTextInputType =
38
+ | "text"
39
+ | "email"
40
+ | "password"
41
+ | "search"
42
+ | "url"
43
+ | "number"
44
+ | "tel"
45
+ | "date"
46
+ | "datetime-local"
47
+ | "time";
38
48
 
39
49
  export type tFormAutocomplete =
40
50
  | "off"
@@ -113,15 +123,29 @@ export interface iFormInputDefault<
113
123
  autocomplete?: tFormAutocomplete;
114
124
  }
115
125
 
126
+ export type tOptionsLoaderFn =
127
+ | ((v?: string | number, signal?: AbortSignal) => iFormOption[])
128
+ | ((v?: string | number, signal?: AbortSignal) => Promise<iFormOption[]>);
129
+
130
+ /** If a function is given, it should be responsible of determining if v is a value or an alias (search) */
131
+ export type iFormInputOptions = (string | number | iFormOption)[] | tOptionsLoaderFn;
132
+
116
133
  /**
117
134
  * Complex input, sub input support
135
+ * Used as input for the classes
118
136
  */
119
137
  export interface iFormInput<
120
138
  V extends iFormValue | iFormValue[],
121
139
  T extends eFormTypeBase | eFormTypeSimple | eFormTypeComplex,
122
140
  > extends iFormInputDefault<T> {
123
141
  name: string;
124
- options?: (string | number | iFormOption)[];
142
+ /**
143
+ * Options for select, checkbox, radio inputs
144
+ * The usage of a function requires a compatible component (SelectFilter)
145
+ *
146
+ * @values array of options or function that returns options
147
+ */
148
+ options?: iFormInputOptions;
125
149
  /**
126
150
  * An array of values to simplify validation
127
151
  *
@@ -189,6 +213,13 @@ export interface iFetchResponse<R = any> {
189
213
  [x: string]: any;
190
214
  }
191
215
 
216
+ /**
217
+ * Takes the parsed inputs values and perform a request (content creation, update, etc).
218
+ *
219
+ * @param values Values of the input
220
+ * @param fetcher Request function
221
+ * @returns Response with data and errors if any
222
+ */
192
223
  export type tResponseFn<T, V extends Record<string, any> = Record<string, any>> = (
193
224
  values: V
194
225
  ) => Promise<iFetchResponse<T>>;
package/src/locale.ts CHANGED
@@ -180,6 +180,12 @@ export type tLocaleForm = {
180
180
  form_cellphone: string;
181
181
  /** @example "ID number" */
182
182
  form_id_number: string;
183
+ /** @example "Date" */
184
+ form_date: string;
185
+ /** @example "Date & time" */
186
+ form_datetime: string;
187
+ /** @example "Time" */
188
+ form_time: string;
183
189
  /** @example "Complete the field" */
184
190
  form_complete_the_field: string;
185
191
  /** @example "Location" */