flowbite-svelte 1.18.0 → 1.18.1

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.
@@ -107,8 +107,9 @@
107
107
  rangeFrom = day;
108
108
  rangeTo = undefined;
109
109
  } else if (day < rangeFrom) {
110
+ const oldRangeFrom = rangeFrom;
110
111
  rangeFrom = day;
111
- rangeTo = rangeFrom;
112
+ rangeTo = oldRangeFrom;
112
113
  } else {
113
114
  rangeTo = day;
114
115
  }
@@ -5,28 +5,46 @@
5
5
  import { buttonToggleGroup } from "./theme";
6
6
  import { getTheme } from "../../theme/themeUtils";
7
7
 
8
- let { multiSelect = false, name = "toggle-group", value = multiSelect ? [] : null, color, size = "md", roundedSize = "md", onSelect = (val: any) => {}, children, ctxIconClass, ctxBtnClass, class: className, ...restProps }: ButtonToggleGroupProps = $props();
8
+ let { multiSelect = false, name = "toggle-group", value = multiSelect ? [] : null, color, size = "md", roundedSize = "md", onSelect = () => {}, children, ctxIconClass, ctxBtnClass, class: className, ...restProps }: ButtonToggleGroupProps = $props();
9
9
 
10
10
  const theme = getTheme("buttonToggleGroup");
11
11
 
12
12
  const base = $derived(buttonToggleGroup({ roundedSize, class: clsx(theme, className) }));
13
13
  type SelectedValue = string | null | string[];
14
14
 
15
- let selectedValues = $state<SelectedValue>(multiSelect ? [] : null);
15
+ // Normalize incoming prop `value` to internal SelectedValue
16
+ // Clones arrays to prevent external mutations affecting internal state
17
+ function getInitialValue(): SelectedValue {
18
+ if (multiSelect) {
19
+ // Multi-select mode expects array
20
+ if (Array.isArray(value)) {
21
+ return [...value]; // Clone to prevent aliasing
22
+ } else if (value === null || value === undefined) {
23
+ return [];
24
+ } else {
25
+ // Single string passed but multiSelect is true - wrap in array
26
+ return [value as string];
27
+ }
28
+ } else {
29
+ // Single-select mode expects string or null
30
+ if (Array.isArray(value)) {
31
+ // Array passed but multiSelect is false - take first item
32
+ return value[0] ?? null;
33
+ } else {
34
+ return value;
35
+ }
36
+ }
37
+ }
38
+
39
+ let selectedValues = $state<SelectedValue>(getInitialValue());
16
40
 
17
41
  interface ButtonToggleContext {
18
42
  toggleSelected: (toggleValue: string) => void;
19
43
  isSelected: (toggleValue: string) => boolean;
20
44
  }
21
45
 
22
- $effect(() => {
23
- value = selectedValues;
24
- onSelect(selectedValues);
25
- });
26
-
27
46
  function toggleSelected(toggleValue: string) {
28
47
  if (multiSelect) {
29
- // Handle multi-select mode
30
48
  const currentSelected = [...(selectedValues as string[])];
31
49
  const index = currentSelected.indexOf(toggleValue);
32
50
 
@@ -37,9 +55,9 @@
37
55
  selectedValues = currentSelected;
38
56
  }
39
57
  } else {
40
- // Handle single-select mode
41
58
  selectedValues = toggleValue === selectedValues ? null : toggleValue;
42
59
  }
60
+ onSelect(selectedValues); // ✅ ADD THIS LINE - call onSelect here
43
61
  }
44
62
 
45
63
  function isSelected(toggleValue: string): boolean {
package/dist/types.d.ts CHANGED
@@ -276,7 +276,7 @@ export type ButtonToggleGroupProps = HTMLAttributes<HTMLDivElement> & {
276
276
  color?: ButtonToggleVariants["color"];
277
277
  size?: ButtonToggleVariants["size"];
278
278
  roundedSize?: ButtonToggleVariants["roundedSize"];
279
- onSelect?: (val: any) => void;
279
+ onSelect?: (val: string | null | string[]) => void;
280
280
  children: Snippet;
281
281
  ctxIconClass?: ClassValue;
282
282
  ctxBtnClass?: ClassValue;
@@ -15,10 +15,12 @@
15
15
  innerDivClass: "content"
16
16
  }
17
17
  );
18
- const styling = $derived({
19
- div: divClass,
20
- content: innerDivClass
21
- });
18
+ const styling = $derived(
19
+ classes ?? {
20
+ div: divClass,
21
+ content: innerDivClass
22
+ }
23
+ );
22
24
 
23
25
  const theme = getTheme("hr");
24
26
  const bg = classes?.bg ?? "bg-gray-200 dark:bg-gray-700";
@@ -31,7 +33,7 @@
31
33
  </script>
32
34
 
33
35
  {#if children}
34
- <div {...mergedDivProps} class={div({ class: clsx(theme?.div, divClass) })}>
36
+ <div {...mergedDivProps} class={div({ class: clsx(theme?.div, styling.div) })}>
35
37
  <hr {...mergedHrProps} class={base({ class: clsx(theme?.base, className, bg) })} />
36
38
  <div class={content({ class: clsx(theme?.content, styling.content) })}>
37
39
  {@render children()}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flowbite-svelte",
3
- "version": "1.18.0",
3
+ "version": "1.18.1",
4
4
  "description": "Flowbite components for Svelte",
5
5
  "main": "dist/index.js",
6
6
  "author": {