@hashrytech/quick-components-kit 0.20.1 → 0.20.4
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/CHANGELOG.md +18 -0
- package/dist/components/text-area/TextArea.svelte +1 -1
- package/dist/components/text-area/TextArea.svelte.d.ts +1 -1
- package/dist/components/text-input/TextInput.svelte +5 -3
- package/dist/components/text-input/TextInput.svelte.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/modules/navigation-state.d.ts +28 -0
- package/dist/modules/navigation-state.js +84 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @hashrytech/quick-components-kit
|
|
2
2
|
|
|
3
|
+
## 0.20.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- add: new showErrorText property
|
|
8
|
+
|
|
9
|
+
## 0.20.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- add: adding navigation-state class
|
|
14
|
+
|
|
15
|
+
## 0.20.2
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- fix: adding step to input and null type to value of text area
|
|
20
|
+
|
|
3
21
|
## 0.20.1
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -30,7 +30,7 @@ export type InputMode = "none" | "text" | "decimal" | "numeric" | "tel" | "searc
|
|
|
30
30
|
export type TextInputProps = {
|
|
31
31
|
id: string;
|
|
32
32
|
name?: string;
|
|
33
|
-
value?: string | number;
|
|
33
|
+
value?: string | number | null;
|
|
34
34
|
placeholder?: string;
|
|
35
35
|
labelText?: string;
|
|
36
36
|
labelPosition?: "top" | "left" | "right" | "bottom";
|
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
disabled?: boolean;
|
|
43
43
|
required?: boolean;
|
|
44
44
|
pattern?: string;
|
|
45
|
-
error?: string;
|
|
45
|
+
error?: string;
|
|
46
|
+
showErrorText?: boolean;
|
|
46
47
|
labelClass?: ClassNameValue;
|
|
47
48
|
firstDivClass?: ClassNameValue;
|
|
48
49
|
secondDivClass?: ClassNameValue;
|
|
@@ -83,6 +84,7 @@
|
|
|
83
84
|
required=false,
|
|
84
85
|
pattern,
|
|
85
86
|
error,
|
|
87
|
+
showErrorText=true,
|
|
86
88
|
firstDivClass,
|
|
87
89
|
secondDivClass,
|
|
88
90
|
thirdDivClass,
|
|
@@ -193,7 +195,7 @@
|
|
|
193
195
|
|
|
194
196
|
{#if leftIcon}<div class="h-full flex flex-col items-center justify-center {size == 'lg' ? 'pl-3' : 'pl-2.5'}">{@render leftIcon()}</div>{/if}
|
|
195
197
|
|
|
196
|
-
<input {disabled} {required} {type} {id} name={name ? name: id} {placeholder} {pattern} {onmouseup} bind:value {autocomplete} {inputmode} {min} {max} oninput={handleInput}
|
|
198
|
+
<input {disabled} {required} {type} {id} name={name ? name: id} {placeholder} {pattern} {onmouseup} bind:value {autocomplete} {inputmode} {step} {min} {max} oninput={handleInput}
|
|
197
199
|
class={twMerge("border-0 focus:border-0 focus:ring-0 active:border-0 outline-none p-0 bg-transparent placeholder:text-neutral-600/50 h-full w-full rounded-primary", sizeStyle[size], restProps.class)} />
|
|
198
200
|
|
|
199
201
|
{#if rightIcon}<div class="h-full flex flex-col items-center justify-center {size == 'lg' ? 'pr-3' : 'pr-2.5'}">{@render rightIcon()}</div>{/if}
|
|
@@ -201,7 +203,7 @@
|
|
|
201
203
|
|
|
202
204
|
</div>
|
|
203
205
|
|
|
204
|
-
{#if error}
|
|
206
|
+
{#if error && showErrorText}
|
|
205
207
|
<p class="text-sm text-red-500 mt-0.5 bg-red-100/30 px-2 rounded-primary">{error}</p>
|
|
206
208
|
{/if}
|
|
207
209
|
|
package/dist/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export * from './modules/fetch-client.js';
|
|
|
24
24
|
export * from './modules/api-proxy.js';
|
|
25
25
|
export * from './modules/crypto.js';
|
|
26
26
|
export * from './modules/problem-details.js';
|
|
27
|
+
export * from './modules/navigation-state.js';
|
|
27
28
|
export * from './functions/object-to-form-data.js';
|
|
28
29
|
export * from './functions/compare-objects.js';
|
|
29
30
|
export * from './functions/click-outside.js';
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,7 @@ export * from './modules/fetch-client.js';
|
|
|
27
27
|
export * from './modules/api-proxy.js';
|
|
28
28
|
export * from './modules/crypto.js';
|
|
29
29
|
export * from './modules/problem-details.js';
|
|
30
|
+
export * from './modules/navigation-state.js';
|
|
30
31
|
// Functions
|
|
31
32
|
export * from './functions/object-to-form-data.js';
|
|
32
33
|
export * from './functions/compare-objects.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type NavigationStateOptions = {
|
|
2
|
+
init?: string[][] | Record<string, string> | string | URLSearchParams;
|
|
3
|
+
onNavigateFns?: Array<(queryString?: string) => void | Promise<void>>;
|
|
4
|
+
defaultParams?: Record<string, string | number | boolean>;
|
|
5
|
+
};
|
|
6
|
+
export declare class NavigationState extends URLSearchParams {
|
|
7
|
+
static readonly SEARCH_PARAM: string;
|
|
8
|
+
static readonly LIMIT_PARAM: string;
|
|
9
|
+
static readonly OFFSET_PARAM: string;
|
|
10
|
+
private listeners;
|
|
11
|
+
private defaultParams?;
|
|
12
|
+
private onNavigateFns?;
|
|
13
|
+
constructor(opts?: NavigationStateOptions);
|
|
14
|
+
private emit;
|
|
15
|
+
onNavigate: (fn: (queryString?: string) => void) => () => boolean;
|
|
16
|
+
navigate: () => Promise<void>;
|
|
17
|
+
/** Make a copy (so we can return new instances for Svelte reactivity) */
|
|
18
|
+
clone: () => NavigationState;
|
|
19
|
+
/** Clear the specified keys (or everything if no keys passed) */
|
|
20
|
+
clear: (keyList?: string[]) => void;
|
|
21
|
+
setDefaultParam: (key: string, value: string) => void;
|
|
22
|
+
setDefaultParams: (params: Record<string, string | number | boolean>) => void;
|
|
23
|
+
clearPagination: () => void;
|
|
24
|
+
paginate: (values: Record<string, string>) => Promise<void>;
|
|
25
|
+
search: (term: string | number | null) => Promise<void>;
|
|
26
|
+
filter: (key: string, value: string | number | boolean | null | undefined | Array<string | number | boolean>) => Promise<void>;
|
|
27
|
+
removeFilter: (key: string, value?: string | number | boolean | null | undefined | Array<string | number | boolean>) => Promise<void>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export class NavigationState extends URLSearchParams {
|
|
2
|
+
static SEARCH_PARAM = "q";
|
|
3
|
+
static LIMIT_PARAM = "limit";
|
|
4
|
+
static OFFSET_PARAM = "offset";
|
|
5
|
+
listeners = new Set();
|
|
6
|
+
defaultParams;
|
|
7
|
+
onNavigateFns;
|
|
8
|
+
constructor(opts = {}) {
|
|
9
|
+
super(opts.init);
|
|
10
|
+
this.defaultParams = opts.defaultParams ?? {};
|
|
11
|
+
this.onNavigateFns = opts.onNavigateFns ?? [];
|
|
12
|
+
if (opts.onNavigateFns) {
|
|
13
|
+
opts.onNavigateFns.forEach(fn => this.onNavigate(fn));
|
|
14
|
+
}
|
|
15
|
+
this.setDefaultParams(this.defaultParams);
|
|
16
|
+
}
|
|
17
|
+
/* NOTE we use arrow functions because we want to preserve 'this' context when using it as svelte 5 bindings or to pass as functions to components */
|
|
18
|
+
emit = () => {
|
|
19
|
+
//console.log("Nav Listeners: ", this.listeners.size);
|
|
20
|
+
for (const fn of this.listeners)
|
|
21
|
+
fn(this.toString());
|
|
22
|
+
};
|
|
23
|
+
onNavigate = (fn) => {
|
|
24
|
+
this.listeners.add(fn);
|
|
25
|
+
return () => this.listeners.delete(fn); // unsubscribe
|
|
26
|
+
};
|
|
27
|
+
navigate = async () => {
|
|
28
|
+
this.emit();
|
|
29
|
+
};
|
|
30
|
+
/** Make a copy (so we can return new instances for Svelte reactivity) */
|
|
31
|
+
clone = () => {
|
|
32
|
+
return new NavigationState({ init: this, onNavigateFns: this.onNavigateFns, defaultParams: this.defaultParams });
|
|
33
|
+
};
|
|
34
|
+
/** Clear the specified keys (or everything if no keys passed) */
|
|
35
|
+
clear = (keyList) => {
|
|
36
|
+
const all_keys = keyList && keyList.length > 0 ? keyList : Array.from(this.keys());
|
|
37
|
+
for (const akey in all_keys) {
|
|
38
|
+
const isDefaultkey = this.defaultParams && akey in this.defaultParams;
|
|
39
|
+
if (!isDefaultkey)
|
|
40
|
+
this.delete(akey);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
setDefaultParam = (key, value) => {
|
|
44
|
+
this.set(key, value);
|
|
45
|
+
};
|
|
46
|
+
setDefaultParams = (params) => {
|
|
47
|
+
for (const key in params) {
|
|
48
|
+
this.set(key, String(params[key]));
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
clearPagination = () => {
|
|
52
|
+
this.delete(NavigationState.LIMIT_PARAM);
|
|
53
|
+
this.delete(NavigationState.OFFSET_PARAM);
|
|
54
|
+
};
|
|
55
|
+
/* The below emit events after performing their actions */
|
|
56
|
+
paginate = async (values) => {
|
|
57
|
+
this.clearPagination();
|
|
58
|
+
for (const key in values) {
|
|
59
|
+
this.set(key, values[key]);
|
|
60
|
+
}
|
|
61
|
+
this.emit();
|
|
62
|
+
};
|
|
63
|
+
search = async (term) => {
|
|
64
|
+
this.clearPagination();
|
|
65
|
+
this.delete(NavigationState.SEARCH_PARAM);
|
|
66
|
+
if (term)
|
|
67
|
+
this.set(NavigationState.SEARCH_PARAM, String(term));
|
|
68
|
+
this.emit();
|
|
69
|
+
};
|
|
70
|
+
filter = async (key, value) => {
|
|
71
|
+
this.clearPagination();
|
|
72
|
+
this.set(key, String(value));
|
|
73
|
+
this.emit();
|
|
74
|
+
};
|
|
75
|
+
removeFilter = async (key, value) => {
|
|
76
|
+
this.clearPagination();
|
|
77
|
+
this.getAll(key).forEach((v) => {
|
|
78
|
+
if (v === String(value)) {
|
|
79
|
+
this.delete(key);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
this.emit();
|
|
83
|
+
};
|
|
84
|
+
}
|