@hashrytech/quick-components-kit 0.20.0 → 0.20.3

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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # @hashrytech/quick-components-kit
2
2
 
3
+ ## 0.20.3
4
+
5
+ ### Patch Changes
6
+
7
+ - add: adding navigation-state class
8
+
9
+ ## 0.20.2
10
+
11
+ ### Patch Changes
12
+
13
+ - fix: adding step to input and null type to value of text area
14
+
15
+ ## 0.20.1
16
+
17
+ ### Patch Changes
18
+
19
+ - fix: text breaking in toast
20
+
3
21
  ## 0.20.0
4
22
 
5
23
  ### Minor Changes
@@ -33,7 +33,7 @@
33
33
  export type TextInputProps = {
34
34
  id: string;
35
35
  name?: string;
36
- value?: string|number;
36
+ value?: string|number|null;
37
37
  placeholder?: string;
38
38
  labelText?: string;
39
39
  labelPosition?: "top" | "left" | "right" | "bottom";
@@ -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";
@@ -193,7 +193,7 @@
193
193
 
194
194
  {#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
195
 
196
- <input {disabled} {required} {type} {id} name={name ? name: id} {placeholder} {pattern} {onmouseup} bind:value {autocomplete} {inputmode} {min} {max} oninput={handleInput}
196
+ <input {disabled} {required} {type} {id} name={name ? name: id} {placeholder} {pattern} {onmouseup} bind:value {autocomplete} {inputmode} {step} {min} {max} oninput={handleInput}
197
197
  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
198
 
199
199
  {#if rightIcon}<div class="h-full flex flex-col items-center justify-center {size == 'lg' ? 'pr-3' : 'pr-2.5'}">{@render rightIcon()}</div>{/if}
@@ -42,16 +42,16 @@
42
42
  {#if open}
43
43
  <div transition:fly={{ delay: toastOptions.transitionDelay, duration: toastOptions.transitionDuration, y: toastOptions.transitionY, easing: toastOptions.transitionEasing }} class="flex flex-row rounded-lg mt-2 py-0.5 h-full min-h-[4rem] shadow-lg w-full max-w-md ring-1
44
44
  border-none pointer-events-auto text-neutral-700 {toastTypeClasses[toastType]}">
45
- <div class="flex flex-row gap-4 items-center w-full justify-center rounded-sm mx-4">
45
+ <div class="flex flex-row gap-4 items-center w-full justify-center rounded-sm px-4">
46
46
 
47
47
  <div class="flex flex-row items-center justify-center">
48
48
  <span class="{toastIcons[toastType]} {toastTypeIconColours[toastType]} size-8 outline-hidden"></span>
49
49
  </div>
50
50
 
51
- <div class="flex flex-col gap-1 px-2 w-full rounded-sm p-2">
52
- <p class="text-sm font-medium break-all xs:break-word">{@html message}</p>
51
+ <div class="flex flex-col gap-1 rounded-sm py-2 flex-1 min-w-0">
52
+ <p class="text-sm font-medium break-words overflow-wrap-anywhere hyphens-auto">{@html message}</p>
53
53
  {#if subMessage}
54
- <p class="text-xs font-light break-all xs:break-word">{@html subMessage}</p>
54
+ <p class="text-xs font-light break-words whitespace-normal hyphens-auto">{@html subMessage}</p>
55
55
  {/if}
56
56
  </div>
57
57
 
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
+ }
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/hashrytech/quick-components-kit.git"
7
7
  },
8
- "version": "0.20.0",
8
+ "version": "0.20.3",
9
9
  "license": "MIT",
10
10
  "author": "Hashry Tech",
11
11
  "files": [