@marianmeres/stuic 2.10.0 → 2.11.0

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.
@@ -21,6 +21,30 @@ export declare function isTooltipSupported(): boolean;
21
21
  * Valid positions for tooltip placement relative to the anchor element.
22
22
  */
23
23
  export type TooltipPosition = "top" | "top-left" | "top-right" | "top-span-left" | "top-span-right" | "bottom" | "bottom-left" | "bottom-right" | "bottom-span-left" | "bottom-span-right" | "left" | "right";
24
+ /**
25
+ * Configuration function for the tooltip action.
26
+ *
27
+ * Returns an object with tooltip options. Using a function allows reactive
28
+ * updates when Svelte state changes.
29
+ *
30
+ * @returns Tooltip configuration object
31
+ * @property enabled - Whether the tooltip is active (default: `true`)
32
+ * @property content - Tooltip text content, falls back to `aria-label` if not provided
33
+ * @property position - Placement relative to anchor element (default: `"top"`)
34
+ * @property debug - Enable console debug logging
35
+ * @property class - Additional CSS classes to merge with default styles
36
+ * @property onShow - Callback fired after tooltip becomes visible
37
+ * @property onHide - Callback fired after tooltip is hidden
38
+ */
39
+ export type TooltipConfig = () => {
40
+ enabled?: boolean;
41
+ content?: string | null;
42
+ position?: TooltipPosition;
43
+ debug?: boolean;
44
+ class?: string;
45
+ onShow?: CallableFunction;
46
+ onHide?: CallableFunction;
47
+ };
24
48
  /**
25
49
  * A Svelte action that displays a tooltip anchored to an element using CSS Anchor Positioning.
26
50
  *
@@ -57,12 +81,4 @@ export type TooltipPosition = "top" | "top-left" | "top-right" | "top-span-left"
57
81
  * - Tooltip persists when hovering over it (useful for interactive content)
58
82
  * - Automatically cleans up DOM elements on unmount
59
83
  */
60
- export declare function tooltip(anchorEl: HTMLElement, fn?: () => {
61
- enabled?: boolean;
62
- content?: string | null;
63
- position?: TooltipPosition;
64
- debug?: boolean;
65
- class?: string;
66
- onShow?: CallableFunction;
67
- onHide?: CallableFunction;
68
- }): void;
84
+ export declare function tooltip(anchorEl: HTMLElement, fn?: TooltipConfig): void;
@@ -22,6 +22,8 @@
22
22
  roleSwitch?: boolean;
23
23
  checked?: boolean;
24
24
  el?: Element;
25
+ /* */
26
+ tooltip?: TooltipConfig;
25
27
  }
26
28
 
27
29
  export interface ButtonPresetClasses {
@@ -88,6 +90,7 @@
88
90
  import { twMerge } from "../../utils/tw-merge.js";
89
91
  //
90
92
  import "./index.css";
93
+ import { tooltip, type TooltipConfig } from "../../actions/index.js";
91
94
 
92
95
  let {
93
96
  variant,
@@ -105,6 +108,8 @@
105
108
  checked = $bindable(false),
106
109
  el = $bindable(),
107
110
  //
111
+ tooltip: tooltipConfig = () => ({ enabled: false }),
112
+ //
108
113
  ...rest
109
114
  }: Props = $props();
110
115
 
@@ -147,11 +152,22 @@
147
152
  </script>
148
153
 
149
154
  {#if href}
150
- <a {href} bind:this={el} class={twMerge(_class, classProp)} {...rest as any}>
155
+ <a
156
+ {href}
157
+ bind:this={el}
158
+ class={twMerge(_class, classProp)}
159
+ use:tooltip={tooltipConfig}
160
+ {...rest as any}
161
+ >
151
162
  {@render children?.({})}
152
163
  </a>
153
164
  {:else}
154
- <button bind:this={el} class={twMerge(_class, classProp)} {...rest}>
165
+ <button
166
+ bind:this={el}
167
+ class={twMerge(_class, classProp)}
168
+ use:tooltip={tooltipConfig}
169
+ {...rest}
170
+ >
155
171
  {@render children?.({ checked })}
156
172
  </button>
157
173
  {/if}
@@ -22,6 +22,7 @@ export interface Props extends Omit<HTMLButtonAttributes, "children"> {
22
22
  roleSwitch?: boolean;
23
23
  checked?: boolean;
24
24
  el?: Element;
25
+ tooltip?: TooltipConfig;
25
26
  }
26
27
  export interface ButtonPresetClasses {
27
28
  size: Record<string, string>;
@@ -33,6 +34,7 @@ export interface ButtonPresetClasses {
33
34
  export declare const BUTTON_STUIC_BASE_CLASSES = "\n\t\tbg-button-bg text-button-text\n\t\tdark:bg-button-bg-dark dark:text-button-text-dark\n\t\tfont-mono text-sm text-center\n\t\tleading-none\n\t\tborder-1\n\t\tborder-button-border dark:border-button-border-dark\n\t\trounded-md\n\t\tinline-flex items-center justify-center gap-x-2\n\t\tpx-3 py-2.5\n\t\tselect-none\n\n\t\thover:brightness-105\n\t\tactive:brightness-95\n\t\tdisabled:hover:brightness-100 disabled:opacity-50\n\n\t\tfocus:brightness-105\n\t\tfocus:border-button-border-focus focus:dark:border-button-border-focus-dark\n\n\t\t focus:outline-4 focus:outline-black/10 focus:dark:outline-white/20\n\t\tfocus-visible:outline-4 focus-visible:outline-black/10 focus-visible:dark:outline-white/20\n\t";
34
35
  export declare const BUTTON_STUIC_PRESET_CLASSES: ButtonPresetClasses;
35
36
  import "./index.css";
37
+ import { type TooltipConfig } from "../../actions/index.js";
36
38
  declare const Button: import("svelte").Component<Props, {}, "checked" | "el">;
37
39
  type Button = ReturnType<typeof Button>;
38
40
  export default Button;
@@ -25,6 +25,8 @@
25
25
  coll: ItemColl
26
26
  ) => Promise<boolean | undefined | void> | boolean | undefined | void;
27
27
  buttonProps?: (index: number, coll: ItemColl) => undefined | Record<string, any>;
28
+ //
29
+ tooltip?: TooltipConfig;
28
30
  }
29
31
  </script>
30
32
 
@@ -38,6 +40,7 @@
38
40
  import Button from "../Button/Button.svelte";
39
41
  //
40
42
  import "./index.css";
43
+ import { tooltip, type TooltipConfig } from "../../actions/index.js";
41
44
 
42
45
  let {
43
46
  options,
@@ -54,6 +57,7 @@
54
57
  style,
55
58
  onButtonClick,
56
59
  buttonProps,
60
+ tooltip: tooltipConfig = () => ({ enabled: false }),
57
61
  }: Props = $props();
58
62
 
59
63
  const coll: ItemColl = $derived.by(() => {
@@ -137,6 +141,7 @@
137
141
  {style}
138
142
  role="radiogroup"
139
143
  aria-labelledby={$coll?.active?.id || ""}
144
+ use:tooltip={tooltipConfig}
140
145
  >
141
146
  {#each coll.items as item, i}
142
147
  <Button
@@ -20,8 +20,10 @@ export interface Props {
20
20
  /** Return false to prevent activation */
21
21
  onButtonClick?: (index: number, coll: ItemColl) => Promise<boolean | undefined | void> | boolean | undefined | void;
22
22
  buttonProps?: (index: number, coll: ItemColl) => undefined | Record<string, any>;
23
+ tooltip?: TooltipConfig;
23
24
  }
24
25
  import "./index.css";
26
+ import { type TooltipConfig } from "../../actions/index.js";
25
27
  declare const ButtonGroupRadio: import("svelte").Component<Props, {}, "value" | "activeIndex">;
26
28
  type ButtonGroupRadio = ReturnType<typeof ButtonGroupRadio>;
27
29
  export default ButtonGroupRadio;
@@ -263,7 +263,7 @@
263
263
  // otherwise normal spinner will be shown
264
264
  let progress = $state<Record<string, number>>({});
265
265
  const onProgress = (id: string, value: number) => (progress[id] = Math.round(value));
266
- $inspect("progress", progress);
266
+ // $inspect("progress", progress);
267
267
 
268
268
  $effect(() => {
269
269
  if (!assets?.length) modal?.close?.();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/stuic",
3
- "version": "2.10.0",
3
+ "version": "2.11.0",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",