flowbite-svelte 1.10.4 → 1.10.5

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.
@@ -9,28 +9,7 @@
9
9
  import { getTheme } from "../theme/themeUtils";
10
10
  import clsx from "clsx";
11
11
 
12
- let {
13
- children,
14
- isOpen = false, // Controls the *overlay* state on small screens
15
- closeSidebar,
16
- isSingle = true,
17
- breakpoint = "md", // e.g., 'md'
18
- alwaysOpen = false, // When true, sidebar is always visible, no hamburger menu
19
- position = "fixed",
20
- activateClickOutside = true,
21
- backdrop = true,
22
- backdropClass,
23
- transition = fly,
24
- params,
25
- divClass,
26
- ariaLabel,
27
- nonActiveClass,
28
- activeClass,
29
- activeUrl = "",
30
- class: className,
31
- disableBreakpoints = false, // Key prop for Drawer integration
32
- ...restProps
33
- }: SidebarProps = $props();
12
+ let { children, isOpen = false, closeSidebar, isSingle = true, breakpoint = "md", alwaysOpen = false, position = "fixed", activateClickOutside = true, backdrop = true, backdropClass, transition = fly, params, divClass, ariaLabel, nonActiveClass, activeClass, activeUrl = "", class: className, disableBreakpoints = false, ...restProps }: SidebarProps = $props();
34
13
 
35
14
  const theme = getTheme("sidebar");
36
15
 
@@ -43,15 +22,8 @@
43
22
  };
44
23
 
45
24
  let innerWidth: number = $state(-1);
46
- // This derived state is now primarily for trapFocus and transition,
47
- // NOT for rendering the main sidebar element in standalone mode.
48
- // It determines if the screen size *would* make it "large" if alwaysOpen were applied.
49
- let isLargeScreen = $derived(innerWidth >= breakpointValues[breakpoint]);
50
-
51
- // Determine if the sidebar should be "open" based on explicit isOpen or large screen AND alwaysOpen
52
- // This state is what should drive the 'hidden' / 'block' classes for the sidebar itself,
53
- // which will be passed to tailwind-variants.
54
- let shouldBeOpen = $derived(isOpen || (alwaysOpen && isLargeScreen));
25
+ // isLargeScreen should only be true if not disabling breakpoints and it meets the criteria
26
+ let isLargeScreen = $derived(disableBreakpoints ? false : alwaysOpen || innerWidth >= breakpointValues[breakpoint]);
55
27
 
56
28
  const activeUrlStore = writable("");
57
29
  setContext("activeUrl", activeUrlStore);
@@ -59,23 +31,8 @@
59
31
  activeUrlStore.set(activeUrl);
60
32
  });
61
33
 
62
- // Pass shouldBeOpen to sidebar utility for `isOpen` variant and other relevant styling.
63
- // Pass alwaysOpen directly to sidebar utility for the `alwaysOpen` variant.
64
- const {
65
- base,
66
- active,
67
- nonactive,
68
- div,
69
- backdrop: backdropCls
70
- } = $derived(
71
- sidebar({
72
- isOpen: shouldBeOpen, // Now dynamically drives the tv `isOpen` variant
73
- breakpoint: alwaysOpen ? undefined : breakpoint, // Apply breakpoint variant ONLY if not alwaysOpen
74
- position,
75
- backdrop: backdrop && !disableBreakpoints, // Backdrop for standalone sidebar
76
- alwaysOpen // Pass alwaysOpen directly
77
- })
78
- );
34
+ if (disableBreakpoints) isOpen = true;
35
+ const { base, active, nonactive, div, backdrop: backdropCls } = $derived(sidebar({ isOpen, breakpoint, position, backdrop, alwaysOpen: alwaysOpen && !disableBreakpoints }));
79
36
 
80
37
  let sidebarCtx: SidebarCtxType = {
81
38
  get closeSidebar() {
@@ -90,11 +47,11 @@
90
47
  isSingle
91
48
  };
92
49
 
93
- // Transition parameters for the fly effect when opening/closing
94
50
  let transitionParams = params ? params : { x: -320, duration: 200, easing: sineIn };
95
51
 
96
52
  setContext("sidebarContext", sidebarCtx);
97
53
 
54
+ // Handler for Escape key
98
55
  const handleEscape = () => {
99
56
  closeSidebar?.();
100
57
  };
@@ -103,17 +60,26 @@
103
60
  <svelte:window bind:innerWidth />
104
61
 
105
62
  {#if !disableBreakpoints}
106
- <aside use:trapFocus={isOpen ? { onEscape: closeSidebar ? handleEscape : undefined } : null} transition:transition={isOpen && !alwaysOpen ? transitionParams : undefined} {...restProps} class={cn(base(), clsx(clsx(className)), (theme as SidebarTheme)?.base)} aria-label={ariaLabel}>
107
- <div class={cn(div(), clsx(divClass), (theme as SidebarTheme)?.base)}>
108
- {@render children()}
109
- </div>
110
- </aside>
111
-
112
- {#if isOpen && !alwaysOpen && backdrop}
113
- <div role="presentation" class={cn(backdropCls(), clsx(backdropClass), (theme as SidebarTheme)?.backdrop)} onclick={activateClickOutside ? closeSidebar : undefined}></div>
63
+ {#if isOpen || isLargeScreen}
64
+ {#if isOpen && !alwaysOpen}
65
+ {#if backdrop && activateClickOutside}
66
+ <div role="presentation" class={cn(backdropCls(), clsx(backdropClass), (theme as SidebarTheme)?.backdrop)} onclick={closeSidebar}></div>
67
+ {:else if backdrop && !activateClickOutside}
68
+ <div role="presentation" class={cn(backdropCls(), clsx(backdropClass), (theme as SidebarTheme)?.backdrop)}></div>
69
+ {:else if !backdrop && activateClickOutside}
70
+ <div role="presentation" class="fixed start-0 top-0 z-50 h-full w-full" onclick={closeSidebar}></div>
71
+ {:else if !backdrop && !activateClickOutside}
72
+ <div role="presentation" class="fixed start-0 top-0 z-50 h-full w-full"></div>
73
+ {/if}
74
+ {/if}
75
+ <aside use:trapFocus={!isLargeScreen && isOpen && !alwaysOpen ? { onEscape: closeSidebar ? handleEscape : undefined } : null} transition:transition={!alwaysOpen ? transitionParams : undefined} {...restProps} class={cn(base(), clsx(clsx(className)), (theme as SidebarTheme)?.base)} aria-label={ariaLabel}>
76
+ <div class={cn(div(), clsx(divClass), (theme as SidebarTheme)?.base)}>
77
+ {@render children()}
78
+ </div>
79
+ </aside>
114
80
  {/if}
115
81
  {:else}
116
- <aside use:trapFocus={isOpen ? { onEscape: closeSidebar ? handleEscape : undefined } : null} transition:transition={isOpen && !alwaysOpen ? transitionParams : undefined} {...restProps} class={cn(base(), clsx(clsx(className)), (theme as SidebarTheme)?.base)} aria-label={ariaLabel}>
82
+ <aside use:trapFocus={isOpen ? { onEscape: closeSidebar ? handleEscape : undefined } : null} {...restProps} class={cn(base(), clsx(clsx(className)), (theme as SidebarTheme)?.base)} aria-label={ariaLabel}>
117
83
  <div class={cn(div(), clsx(divClass), (theme as SidebarTheme)?.base)}>
118
84
  {@render children()}
119
85
  </div>
@@ -13,12 +13,8 @@ export declare const sidebar: import("tailwind-variants").TVReturnType<{
13
13
  };
14
14
  };
15
15
  isOpen: {
16
- true: {
17
- base: string;
18
- };
19
- false: {
20
- base: string;
21
- };
16
+ true: string;
17
+ false: string;
22
18
  };
23
19
  breakpoint: {
24
20
  sm: {
@@ -66,12 +62,8 @@ export declare const sidebar: import("tailwind-variants").TVReturnType<{
66
62
  };
67
63
  };
68
64
  isOpen: {
69
- true: {
70
- base: string;
71
- };
72
- false: {
73
- base: string;
74
- };
65
+ true: string;
66
+ false: string;
75
67
  };
76
68
  breakpoint: {
77
69
  sm: {
@@ -119,12 +111,8 @@ export declare const sidebar: import("tailwind-variants").TVReturnType<{
119
111
  };
120
112
  };
121
113
  isOpen: {
122
- true: {
123
- base: string;
124
- };
125
- false: {
126
- base: string;
127
- };
114
+ true: string;
115
+ false: string;
128
116
  };
129
117
  breakpoint: {
130
118
  sm: {
@@ -1,4 +1,3 @@
1
- // theme.ts
2
1
  import { tv } from "tailwind-variants";
3
2
  export const sidebar = tv({
4
3
  slots: {
@@ -14,10 +13,9 @@ export const sidebar = tv({
14
13
  absolute: { base: "absolute" },
15
14
  static: { base: "static" }
16
15
  },
17
- // Reintroducing isOpen, but this will only apply when isLargeScreen AND alwaysOpen is false
18
16
  isOpen: {
19
- true: { base: "block" }, // When explicitly open (hamburger menu clicked)
20
- false: { base: "hidden" } // When explicitly closed
17
+ true: "block",
18
+ false: "hidden"
21
19
  },
22
20
  breakpoint: {
23
21
  sm: { base: "sm:block" },
@@ -27,58 +25,21 @@ export const sidebar = tv({
27
25
  "2xl": { base: "2xl:block" }
28
26
  },
29
27
  alwaysOpen: {
30
- true: { base: "block" } // This variant will ensure it's always block regardless of breakpoints
28
+ true: { base: "block" } // Always display the sidebar when alwaysOpen is true
31
29
  },
32
30
  backdrop: {
33
31
  true: { backdrop: "bg-gray-900 opacity-75" }
34
32
  }
35
33
  },
36
34
  compoundVariants: [
37
- // Rule for responsive display when NOT alwaysOpen
38
- {
39
- alwaysOpen: false, // Only apply these if the sidebar is NOT always open
40
- breakpoint: "sm",
41
- class: { base: "sm:block" }
42
- },
43
- {
44
- alwaysOpen: false,
45
- breakpoint: "md",
46
- class: { base: "md:block" }
47
- },
48
- {
49
- alwaysOpen: false,
50
- breakpoint: "lg",
51
- class: { base: "lg:block" }
52
- },
53
- {
54
- alwaysOpen: false,
55
- breakpoint: "xl",
56
- class: { base: "xl:block" }
57
- },
58
- {
59
- alwaysOpen: false,
60
- breakpoint: "2xl",
61
- class: { base: "2xl:block" }
62
- },
63
- // Override: When alwaysOpen is true, it should always be visible, ignoring `isOpen` and `breakpoint`
35
+ // When alwaysOpen is true, override the breakpoint display classes
64
36
  {
65
37
  alwaysOpen: true,
66
38
  class: {
67
- base: "!block" // Force block display
68
- }
69
- },
70
- // Another compound variant to hide it below the breakpoint if not alwaysOpen and not explicitly open
71
- {
72
- alwaysOpen: false,
73
- isOpen: false, // If it's not always open AND not explicitly open (via hamburger)
74
- class: {
75
- base: "hidden" // Hide it by default. Breakpoint rules will override this for larger screens.
39
+ base: "!block"
76
40
  }
77
41
  }
78
- ],
79
- defaultVariants: {
80
- isOpen: false // Default to closed on small screens if not specified
81
- }
42
+ ]
82
43
  });
83
44
  export const sidebarButton = tv({
84
45
  base: "inline-flex items-center p-0 mt-0 ms-3 text-sm text-gray-500 rounded-lg hover:bg-gray-100 focus:outline-hidden focus:ring-2 focus:ring-gray-200 dark:text-gray-400 dark:hover:bg-gray-700 dark:focus:ring-gray-600",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flowbite-svelte",
3
- "version": "1.10.4",
3
+ "version": "1.10.5",
4
4
  "description": "Flowbite components for Svelte",
5
5
  "main": "dist/index.js",
6
6
  "author": {