Skip to content

Commit 9c8f96b

Browse files
authored
Clean up transition related prop names. (#1912)
* feat: use svelte-reactivity-window * Clean up transition related prop names. Some use transitionType and some use transition. Use the following patterns: - transition for the function or "none" string, which reads well and is clear. - transitionParams for the params specifically tied to the transition. * fix: transitionType to transition and params to transitionParams for all the usage * fix: transitionType to transition and params to transitionParams for all the usage * docs: v2-migration-guide * fix: coderabbitai fix
1 parent bb0d16a commit 9c8f96b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+167
-110
lines changed

src/lib/accordion/Accordion.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { createSingleSelectionContext } from "$lib/utils/singleselection.svelte";
88
import { untrack } from "svelte";
99
10-
let { children, flush, multiple = false, class: className, transitionType, respectReducedMotion = true, classes, ...restProps }: AccordionProps = $props();
10+
let { children, flush, multiple = false, class: className, transition, respectReducedMotion = true, classes, ...restProps }: AccordionProps = $props();
1111
1212
const theme = $derived(getTheme("accordion"));
1313
@@ -16,8 +16,8 @@
1616
get flush() {
1717
return flush;
1818
},
19-
get transitionType() {
20-
return transitionType;
19+
get transition() {
20+
return transition;
2121
},
2222
get respectReducedMotion() {
2323
return respectReducedMotion;
@@ -51,7 +51,7 @@
5151
@prop flush
5252
@prop multiple = false
5353
@prop class: className
54-
@prop transitionType
54+
@prop transition
5555
@prop respectReducedMotion = true
5656
@prop classes
5757
@prop ...restProps

src/lib/accordion/AccordionItem.svelte

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { prefersReducedMotion } from "svelte/motion";
99
import { accordionItem } from "./theme";
1010
11-
let { children, header, arrowup, arrowdown, open = $bindable(false), transitionType = slide, transitionParams, class: className, classes }: AccordionItemProps = $props();
11+
let { children, header, arrowup, arrowdown, open = $bindable(false), transition = slide, transitionParams, class: className, classes }: AccordionItemProps = $props();
1212
1313
// Get context - it will be undefined if used outside Accordion
1414
const ctx = getAccordionContext();
@@ -22,9 +22,9 @@
2222
inactive: classes?.inactive || ctx?.classes?.inactive
2323
});
2424
25-
const ctxTransitionType = $derived(ctx?.transitionType ?? transitionType);
26-
// Check if transitionType is explicitly set to undefined in props
27-
const useTransition = $derived(transitionType === "none" ? false : ctxTransitionType === "none" ? false : true);
25+
const ctxTransitionType = $derived(ctx?.transition ?? transition);
26+
// Check if transition is explicitly set to undefined in props
27+
const useTransition = $derived(transition === "none" ? false : ctxTransitionType === "none" ? false : true);
2828
2929
// Get respectReducedMotion from context (defaults to true)
3030
const ctxRespectReducedMotion = $derived(ctx?.respectReducedMotion ?? true);
@@ -81,8 +81,8 @@
8181
</h2>
8282

8383
{#if useTransition}
84-
{#if open && transitionType !== "none"}
85-
<div data-part="content-wrapper" class={contentWrapperCls} transition:transitionType={effectiveTransitionParams as ParamsType}>
84+
{#if open && transition !== "none"}
85+
<div data-part="content-wrapper" class={contentWrapperCls} transition:transition={effectiveTransitionParams as ParamsType}>
8686
<div data-part="content" class={content({ class: clsx(theme?.content, finalClasses.content) })}>
8787
{@render children()}
8888
</div>
@@ -107,7 +107,7 @@
107107
@prop arrowup
108108
@prop arrowdown
109109
@prop open = $bindable(false)
110-
@prop transitionType = slide
110+
@prop transition = slide
111111
@prop transitionParams
112112
@prop class: className
113113
@prop classes

src/lib/alert/Alert.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
class: className,
2020
dismissable,
2121
transition = fade,
22-
params,
22+
transitionParams,
2323
listContent,
2424
borderAccent,
2525
closeButtonProps,
@@ -46,7 +46,7 @@
4646
const isBrowser = typeof window !== "undefined";
4747
4848
// Respect reduced motion preference by setting duration to 0
49-
const effectiveParams = $derived(isBrowser && prefersReducedMotion.current ? { ...params, duration: 0 } : params);
49+
const effectiveParams = $derived(isBrowser && prefersReducedMotion.current ? { ...transitionParams, duration: 0 } : transitionParams);
5050
5151
let ref: HTMLDivElement | undefined = $state(undefined);
5252
@@ -111,7 +111,7 @@
111111
@prop class: className
112112
@prop dismissable
113113
@prop transition = fade
114-
@prop params
114+
@prop transitionParams
115115
@prop listContent
116116
@prop borderAccent
117117
@prop closeButtonProps

src/lib/badge/Badge.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
target,
2323
rounded,
2424
transition = fade,
25-
params,
25+
transitionParams,
2626
closeButtonProps,
2727
...restProps
2828
}: BadgeProps = $props();
@@ -49,7 +49,7 @@
4949
const isBrowser = typeof window !== "undefined";
5050
5151
// Respect reduced motion preference by setting duration to 0
52-
const effectiveParams = $derived(isBrowser && prefersReducedMotion.current ? { ...params, duration: 0 } : params);
52+
const effectiveParams = $derived(isBrowser && prefersReducedMotion.current ? { ...transitionParams, duration: 0 } : transitionParams);
5353
5454
let ref: HTMLDivElement | undefined = $state(undefined);
5555
@@ -103,7 +103,7 @@
103103
@prop target
104104
@prop rounded
105105
@prop transition = fade
106-
@prop params
106+
@prop transitionParams
107107
@prop closeButtonProps
108108
@prop ...restProps
109109
-->

src/lib/banner/Banner.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class: className,
1919
classes,
2020
transition = fade,
21-
params,
21+
transitionParams,
2222
onclose,
2323
closeButtonProps,
2424
...restProps
@@ -35,7 +35,7 @@
3535
const isBrowser = typeof window !== "undefined";
3636
3737
// Respect reduced motion preference by setting duration to 0
38-
const effectiveParams = $derived(isBrowser && prefersReducedMotion.current ? { ...params, duration: 0 } : params);
38+
const effectiveParams = $derived(isBrowser && prefersReducedMotion.current ? { ...transitionParams, duration: 0 } : transitionParams);
3939
4040
let ref: HTMLDivElement | undefined = $state(undefined);
4141
function close(event: MouseEvent) {
@@ -86,7 +86,7 @@
8686
@prop class: className
8787
@prop classes
8888
@prop transition = fade
89-
@prop params
89+
@prop transitionParams
9090
@prop onclose
9191
@prop closeButtonProps
9292
@prop ...restProps

src/lib/drawer/Drawer.svelte

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script lang="ts">
2+
import { innerWidth, innerHeight } from "svelte/reactivity/window";
23
import type { DrawerProps } from "$lib";
34
import Dialog from "$lib/dialog/Dialog.svelte";
45
import { getTheme } from "$lib/theme-provider/themeUtils";
@@ -71,12 +72,14 @@
7172
7273
// set the values for transition start position
7374
const dlg = ev.currentTarget;
74-
const { innerWidth = 0, innerHeight = 0 } = dlg.ownerDocument.defaultView ?? {};
75-
7675
const rect = dlg.getBoundingClientRect();
7776
78-
x = placement === "left" ? rect.left : placement === "right" ? rect.right - innerWidth : undefined;
79-
y = placement === "top" ? rect.top : placement === "bottom" ? rect.bottom - innerHeight : undefined;
77+
const vw = innerWidth.current ?? 0;
78+
const vh = innerHeight.current ?? 0;
79+
80+
x = placement === "left" ? rect.left : placement === "right" ? rect.right - vw : undefined;
81+
82+
y = placement === "top" ? rect.top : placement === "bottom" ? rect.bottom - vh : undefined;
8083
8184
await tick(); // let transition start
8285

src/lib/forms/select/MultiSelect.svelte

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,14 @@
236236
{#if children}
237237
{@render children({ item, clear: () => clearThisOption(item) })}
238238
{:else}
239-
<Badge color="gray" large={size === "lg"} dismissable params={{ duration: 100 }} onclose={() => clearThisOption(item)} class={["mx-0.5 px-2 py-0", disabled && "pointer-events-none"]}>
239+
<Badge
240+
color="gray"
241+
large={size === "lg"}
242+
dismissable
243+
transitionParams={{ duration: 100 }}
244+
onclose={() => clearThisOption(item)}
245+
class={["mx-0.5 px-2 py-0", disabled && "pointer-events-none"]}
246+
>
240247
{item.name}
241248
</Badge>
242249
{/if}

src/lib/sidebar/Sidebar.svelte

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script lang="ts">
2+
import { innerWidth } from "svelte/reactivity/window";
23
import type { Attachment } from "svelte/attachments";
34
import type { SidebarContextType, SidebarProps } from "$lib/types";
45
import { getTheme } from "$lib/theme-provider/themeUtils";
@@ -21,7 +22,7 @@
2122
activateClickOutside = true,
2223
backdrop = true,
2324
transition = fly,
24-
params,
25+
transitionParams,
2526
ariaLabel,
2627
activeUrl = "",
2728
class: className,
@@ -42,8 +43,7 @@
4243
"2xl": 1536
4344
};
4445
45-
let innerWidth: number = $state(-1);
46-
let isLargeScreen = $derived(disableBreakpoints ? false : alwaysOpen || innerWidth >= breakpointValues[breakpoint]);
46+
let isLargeScreen = $derived(disableBreakpoints ? false : alwaysOpen || (innerWidth.current ?? 0) >= breakpointValues[breakpoint]);
4747
4848
// Create reactive context for activeUrl using getter
4949
const activeUrlContext = {
@@ -79,9 +79,9 @@
7979
8080
const isBrowser = typeof window !== "undefined";
8181
82-
let transitionParams = $derived(
83-
isBrowser && prefersReducedMotion.current ? { ...(params ? params : { x: -320, duration: 200, easing: sineIn }), duration: 0 } : params ? params : { x: -320, duration: 200, easing: sineIn }
84-
);
82+
const defaultTransitionParams = { x: -320, duration: 200, easing: sineIn };
83+
84+
let finalTransitionParams = $derived(isBrowser && prefersReducedMotion.current ? { ...(transitionParams ?? defaultTransitionParams), duration: 0 } : (transitionParams ?? defaultTransitionParams));
8585
8686
setSidebarContext(sidebarCtx);
8787
@@ -134,8 +134,6 @@
134134
};
135135
</script>
136136

137-
<svelte:window bind:innerWidth />
138-
139137
{#if !disableBreakpoints}
140138
{#if isOpen || isLargeScreen}
141139
{#if isOpen && !alwaysOpen}
@@ -151,7 +149,7 @@
151149
{/if}
152150
<aside
153151
{@attach trapFocusAttachment}
154-
transition:transition={!alwaysOpen ? transitionParams : undefined}
152+
transition:transition={!alwaysOpen ? finalTransitionParams : undefined}
155153
{...restProps}
156154
data-scope="sidebar"
157155
data-part="base"
@@ -187,7 +185,7 @@
187185
@prop activateClickOutside = true
188186
@prop backdrop = true
189187
@prop transition = fly
190-
@prop params
188+
@prop transitionParams
191189
@prop ariaLabel
192190
@prop activeUrl = ""
193191
@prop class: className

src/lib/sidebar/SidebarDropdownWrapper.svelte

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,20 @@
88
import { slide } from "svelte/transition";
99
import { sidebarDropdownWrapper } from "./theme";
1010
11-
let { children, arrowup, arrowdown, icon, isOpen = $bindable(), label, transition = slide, params, class: className, classes, onclick, ...restProps }: SidebarDropdownWrapperProps = $props();
11+
let {
12+
children,
13+
arrowup,
14+
arrowdown,
15+
icon,
16+
isOpen = $bindable(),
17+
label,
18+
transition = slide,
19+
transitionParams,
20+
class: className,
21+
classes,
22+
onclick,
23+
...restProps
24+
}: SidebarDropdownWrapperProps = $props();
1225
1326
const styling = $derived(classes);
1427
@@ -18,7 +31,7 @@
1831
1932
const isBrowser = typeof window !== "undefined";
2033
21-
const effectiveParams = $derived(isBrowser && prefersReducedMotion.current ? { ...(params as ParamsType), duration: 0 } : (params as ParamsType));
34+
const effectiveParams = $derived(isBrowser && prefersReducedMotion.current ? { ...(transitionParams as ParamsType), duration: 0 } : (transitionParams as ParamsType));
2235
2336
let ctx = getSidebarContext() || { isSingle: false };
2437
@@ -88,7 +101,7 @@
88101
@prop isOpen = $bindable()
89102
@prop label
90103
@prop transition = slide
91-
@prop params
104+
@prop transitionParams
92105
@prop class: className
93106
@prop classes
94107
@prop onclick

src/lib/toast/Toast.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
color = "primary",
1717
position,
1818
align = true,
19-
params,
19+
transitionParams,
2020
transition = fly,
2121
class: className,
2222
classes,
@@ -34,7 +34,7 @@
3434
const isBrowser = typeof window !== "undefined";
3535
3636
// Respect reduced motion preference by setting duration to 0
37-
const effectiveParams = $derived(isBrowser && prefersReducedMotion.current ? { ...params, duration: 0 } : params);
37+
const effectiveParams = $derived(isBrowser && prefersReducedMotion.current ? { ...transitionParams, duration: 0 } : transitionParams);
3838
3939
let ref: HTMLDivElement | undefined = $state(undefined);
4040
@@ -88,7 +88,7 @@
8888
@prop color = "primary"
8989
@prop position
9090
@prop align = true
91-
@prop params
91+
@prop transitionParams
9292
@prop transition = fly
9393
@prop class: className
9494
@prop classes

0 commit comments

Comments
 (0)