@marianmeres/stuic 2.33.2 → 2.34.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.
@@ -33,8 +33,11 @@
33
33
  classInputBoxWrap?: string;
34
34
  classInputBoxWrapInvalid?: string;
35
35
  classDescBox?: string;
36
+ classDescBoxToggle?: string;
36
37
  classBelowBox?: string;
37
38
  classValidationBox?: string;
39
+ descriptionCollapsible?: boolean;
40
+ descriptionDefaultExpanded?: boolean;
38
41
  style?: string;
39
42
  }
40
43
  let {
@@ -64,14 +67,20 @@
64
67
  classInputBoxWrap,
65
68
  classInputBoxWrapInvalid,
66
69
  classDescBox,
70
+ classDescBoxToggle,
67
71
  classBelowBox,
68
72
  classValidationBox,
73
+ descriptionCollapsible = true,
74
+ descriptionDefaultExpanded = false,
69
75
  style,
70
76
  }: Props = $props();
71
77
 
72
78
  let invalid = $derived(validation && !validation?.valid);
73
79
 
74
80
  let width = $state<number>(0);
81
+ let descExpanded = $state(descriptionDefaultExpanded);
82
+ let descContentEl: HTMLDivElement | undefined;
83
+ let descNeedsCollapse = $state(false);
75
84
 
76
85
  $effect(() => {
77
86
  // a non-zero breakpoint has priority
@@ -80,6 +89,14 @@
80
89
  }
81
90
  });
82
91
 
92
+ $effect(() => {
93
+ // only measure when collapsed (line-clamp applied) to detect if truncation is needed
94
+ // width dependency ensures re-measurement on resize
95
+ if (descContentEl && descriptionCollapsible && !descExpanded && width) {
96
+ descNeedsCollapse = descContentEl.scrollHeight > descContentEl.clientHeight;
97
+ }
98
+ });
99
+
83
100
  let _classCommon = $derived(
84
101
  [invalid && "invalid", disabled && "disabled", required && "required", size]
85
102
  .filter(Boolean)
@@ -214,7 +231,30 @@
214
231
  classDescBox
215
232
  )}
216
233
  >
217
- {@render snippetOrThc({ id, value: description })}
234
+ {#if descriptionCollapsible}
235
+ <div class="flex items-start">
236
+ <div
237
+ bind:this={descContentEl}
238
+ class={twMerge("flex-1", !descExpanded && "line-clamp-1")}
239
+ >
240
+ {@render snippetOrThc({ id, value: description })}
241
+ </div>
242
+ {#if descNeedsCollapse}
243
+ <button
244
+ type="button"
245
+ class={twMerge(
246
+ "opacity-70 hover:opacity-100 cursor-pointer px-2 py-1 -my-1 -mr-2",
247
+ classDescBoxToggle
248
+ )}
249
+ onclick={() => (descExpanded = !descExpanded)}
250
+ >
251
+ {descExpanded ? "↑" : "↓"}
252
+ </button>
253
+ {/if}
254
+ </div>
255
+ {:else}
256
+ {@render snippetOrThc({ id, value: description })}
257
+ {/if}
218
258
  </div>
219
259
  {/if}
220
260
 
@@ -28,8 +28,11 @@ interface Props {
28
28
  classInputBoxWrap?: string;
29
29
  classInputBoxWrapInvalid?: string;
30
30
  classDescBox?: string;
31
+ classDescBoxToggle?: string;
31
32
  classBelowBox?: string;
32
33
  classValidationBox?: string;
34
+ descriptionCollapsible?: boolean;
35
+ descriptionDefaultExpanded?: boolean;
33
36
  style?: string;
34
37
  }
35
38
  declare const InputWrap: import("svelte").Component<Props, {}, "">;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/stuic",
3
- "version": "2.33.2",
3
+ "version": "2.34.0",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",