@hashrytech/quick-components-kit 0.13.1 → 0.13.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,17 @@
1
1
  # @hashrytech/quick-components-kit
2
2
 
3
+ ## 0.13.3
4
+
5
+ ### Patch Changes
6
+
7
+ - patch: updating disabled state for button
8
+
9
+ ## 0.13.2
10
+
11
+ ### Patch Changes
12
+
13
+ - patch: Adding an object level fetch to the ApiClient class
14
+
3
15
  ## 0.13.1
4
16
 
5
17
  ### Patch Changes
@@ -3,8 +3,10 @@
3
3
  import type { ClassNameValue } from 'tailwind-merge';
4
4
 
5
5
  export type ButtonProps = {
6
+ disabled?: boolean;
6
7
  children?: Snippet;
7
8
  icon?: Snippet;
9
+ loadingIcon?: Snippet;
8
10
  onclick?: (event: MouseEvent) => void;
9
11
  class?: ClassNameValue;
10
12
  };
@@ -14,13 +16,15 @@
14
16
  <script lang="ts">
15
17
  import {twMerge} from 'tailwind-merge';
16
18
 
17
- let {children, icon, onclick, ...props}: ButtonProps = $props();
19
+ let { disabled=$bindable(), children, icon, loadingIcon, onclick, ...props }: ButtonProps = $props();
18
20
 
19
21
  </script>
20
22
 
21
- <button class={twMerge("flex flex-row items-center gap-2 px-4 py-2 bg-button-primary hover:bg-button-primary-hover rounded-primary w-fit cursor-pointer text-white focus:outline-focus-primary", props.class)}
23
+ <button {disabled} class={twMerge("flex flex-row items-center gap-2 px-4 py-2 bg-button-primary hover:bg-button-primary-hover rounded-primary w-fit cursor-pointer text-white focus:outline-focus-primary",
24
+ "disabled:bg-button-primary/60 disabled:cursor-default", props.class)}
22
25
  {onclick}>
23
26
  {#if icon}<span class="w-10">{@render icon()}</span>{/if}
27
+ {#if loadingIcon}<span class="w-10">{@render loadingIcon()}</span>{/if}
24
28
  {@render children?.()}
25
29
  </button>
26
30
 
@@ -1,11 +1,13 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import type { ClassNameValue } from 'tailwind-merge';
3
3
  export type ButtonProps = {
4
+ disabled?: boolean;
4
5
  children?: Snippet;
5
6
  icon?: Snippet;
7
+ loadingIcon?: Snippet;
6
8
  onclick?: (event: MouseEvent) => void;
7
9
  class?: ClassNameValue;
8
10
  };
9
- declare const Button: import("svelte").Component<ButtonProps, {}, "">;
11
+ declare const Button: import("svelte").Component<ButtonProps, {}, "disabled">;
10
12
  type Button = ReturnType<typeof Button>;
11
13
  export default Button;
@@ -20,24 +20,6 @@
20
20
 
21
21
  </script>
22
22
 
23
- <!--
24
- <button class={twMerge("p-2 rounded focus:outline-none focus:ring-2 focus:ring-focus-primary cursor-pointer w-fit", props.class)} aria-label={ariaLabel} {onclick}>
25
- <div class="space-y-2">
26
- {#each Array(numberOfLines) as _}
27
- <span class={twMerge("block w-7 h-0.5 bg-button-primary", linesClasses)}></span>
28
- {/each}
29
- </div>
30
- </button>
31
-
32
- <button class={twMerge("p-2 rounded focus:outline-none focus:ring-2 focus:ring-focus-primary cursor-pointer w-fit", props.class)} aria-label={ariaLabel} {onclick}>
33
- <div class="relative w-7 h-7">
34
- <span class={twMerge("absolute left-0 top-1.5 w-full h-0.5 bg-button-primary transition-all duration-300", open ? "rotate-45 top-3.5" : "")}></span>
35
- <span class={twMerge("absolute left-0 top-3.5 w-full h-0.5 bg-button-primary transition-all duration-300", open ? "opacity-0" : "opacity-100")}></span>
36
- <span class={twMerge("absolute left-0 bottom-1 w-full h-0.5 bg-button-primary transition-all duration-300", open ? "-rotate-45 top-3.5" : "")}></span>
37
- </div>
38
- </button>
39
- -->
40
-
41
23
  <button aria-label={ariaLabel} class={twMerge("px-1 py-0.5 rounded focus:outline-none focus:ring-2 focus:ring-focus-primary cursor-pointer w-fit", props.class)} {onclick}>
42
24
  <div class={twMerge("flex flex-col items-center justify-center size-7 transition-all gap-2", linesParentClasses)}>
43
25
  <!-- Top bar -->
@@ -19,12 +19,12 @@
19
19
  </script>
20
20
 
21
21
  <script lang="ts">
22
- let { links, preload=true, reload=false, divClasses, ...props }: TabNavigationProps = $props();
22
+ let { links=$bindable(), preload=true, reload=false, divClasses, ...props }: TabNavigationProps = $props();
23
23
  </script>
24
24
 
25
25
  <div class={twMerge("flex flex-row flex-wrap gap-4 justify-start xxxs:justify-center items-start py-2 px-4 mt-8 font-semibold", divClasses)}>
26
26
  {#each links as link}
27
- <a class={twMerge("px-4 py-1 hover:border-primary-secondary-500 hover:border-b-2 text-gray-900 bg-transparent hover:bg-transparent rounded-none", link.active ? "border-primary-600 border-b-2": "", props.class)}
27
+ <a class={twMerge("px-4 py-1 hover:border-secondary-500 hover:border-b-2 text-gray-900 bg-transparent hover:bg-transparent rounded-none", link.active ? "border-primary-600 border-b-2": "", props.class)}
28
28
  data-sveltekit-reload={reload} data-sveltekit-preload-data={preload ? 'hover' : false}
29
29
  href={link.href}>
30
30
  {link.text}
@@ -11,6 +11,6 @@ export type TabNavigationProps = {
11
11
  divClasses?: ClassNameValue;
12
12
  class?: ClassNameValue;
13
13
  };
14
- declare const TabNavigation: import("svelte").Component<TabNavigationProps, {}, "">;
14
+ declare const TabNavigation: import("svelte").Component<TabNavigationProps, {}, "links">;
15
15
  type TabNavigation = ReturnType<typeof TabNavigation>;
16
16
  export default TabNavigation;
@@ -81,6 +81,7 @@ export declare class ApiClient {
81
81
  private defaultHeaders;
82
82
  private clientAuthToken;
83
83
  private getAccessTokenFromStore;
84
+ private fetchInstance?;
84
85
  private requestInterceptors;
85
86
  private responseInterceptors;
86
87
  private errorHandlers;
@@ -98,6 +99,12 @@ export declare class ApiClient {
98
99
  * @param token - The access token string, or undefined to clear it.
99
100
  */
100
101
  setAuthToken(token: string | undefined): void;
102
+ /**
103
+ * Sets a custom fetch implementation globally for all requests made by this client.
104
+ * Useful for passing enhanced `fetch` from SvelteKit's load functions.
105
+ * @param fetchFn - The fetch function to use.
106
+ */
107
+ setFetchInstance(fetchFn: typeof fetch): void;
101
108
  /**
102
109
  * Adds a request interceptor. Interceptors can modify the `Request` object before it's sent.
103
110
  * @param interceptor - A function that takes a `Request` object and returns a `Request` or a Promise resolving to a `Request`.
@@ -34,6 +34,7 @@ export class ApiClient {
34
34
  // otherwise relies on getAccessTokenFromStore or SvelteKit's `handleFetch`.
35
35
  clientAuthToken;
36
36
  getAccessTokenFromStore;
37
+ fetchInstance;
37
38
  requestInterceptors = [];
38
39
  responseInterceptors = [];
39
40
  errorHandlers = [];
@@ -55,6 +56,14 @@ export class ApiClient {
55
56
  setAuthToken(token) {
56
57
  this.clientAuthToken = token;
57
58
  }
59
+ /**
60
+ * Sets a custom fetch implementation globally for all requests made by this client.
61
+ * Useful for passing enhanced `fetch` from SvelteKit's load functions.
62
+ * @param fetchFn - The fetch function to use.
63
+ */
64
+ setFetchInstance(fetchFn) {
65
+ this.fetchInstance = fetchFn;
66
+ }
58
67
  /**
59
68
  * Adds a request interceptor. Interceptors can modify the `Request` object before it's sent.
60
69
  * @param interceptor - A function that takes a `Request` object and returns a `Request` or a Promise resolving to a `Request`.
@@ -220,7 +229,7 @@ export class ApiClient {
220
229
  * @template T - Expected type of the response data.
221
230
  */
222
231
  async request(endpoint, method, body, options = {}) {
223
- const currentFetch = options.fetchInstance || fetch;
232
+ const currentFetch = options.fetchInstance || this.fetchInstance || fetch; // Use provided fetch first then the class instance fetch or the global fetch if not specified.
224
233
  try {
225
234
  const request = await this.processRequest(endpoint, method, body, options);
226
235
  const response = await currentFetch(request);
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.13.1",
8
+ "version": "0.13.3",
9
9
  "license": "MIT",
10
10
  "author": "Hashry Tech",
11
11
  "files": [