Skip to content

Commit 45c945c

Browse files
committed
🐛 Fix custom icon showing up in wrong place for Svelte component
1 parent 484d1e2 commit 45c945c

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

src/components/Toast/Toast.svelte

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@
2424
}
2525
</script>
2626

27-
<Alert {...$$restProps} className={classes} {...additionalProps}>
28-
{#if $$slots.icon}
29-
<slot name="icon" />
30-
{/if}
31-
<slot />
32-
</Alert>
27+
{#if $$slots.icon}
28+
<Alert {...$$restProps} className={classes} {...additionalProps}>
29+
<slot slot="icon" name="icon" />
30+
<slot />
31+
</Alert>
32+
{:else}
33+
<Alert {...$$restProps} className={classes} {...additionalProps}>
34+
<slot />
35+
</Alert>
36+
{/if}
37+

src/pages/toast.astro

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const sections = getSections({
129129
</section.component>
130130
</ComponentWrapper>
131131

132-
<ComponentWrapper title="Programmatically setting copy, theme & pos">
132+
<ComponentWrapper title="Programmatically setting copy & pos">
133133
<Button theme="secondary" id={`programmatic-btn-${index}`}>
134134
Programmatically setting copy
135135
</Button>
@@ -138,11 +138,11 @@ const sections = getSections({
138138
Original content
139139
</section.component>
140140

141-
<Button theme="secondary" id={`themed-btn-${index}`}>
141+
<Button theme="secondary" id={`pos-btn-${index}`}>
142142
Show Toast in top-left corner
143143
</Button>
144144

145-
<section.component title="Original title" id={`themed-toast-${index}`}>
145+
<section.component title="Original title" id={`pos-toast-${index}`}>
146146
Original content
147147
</section.component>
148148
</ComponentWrapper>
@@ -208,14 +208,12 @@ const sections = getSections({
208208
})
209209
});
210210

211-
// Programmatically setting theme
211+
// Programmatically setting position
212212
[0, 1, 2].forEach(x => {
213-
on(`#themed-btn-${x}`, () => {
213+
on(`#pos-btn-${x}`, () => {
214214
toast({
215-
element: `#themed-toast-${x}`,
215+
element: `#pos-toast-${x}`,
216216
title: 'Title set through JS',
217-
content: 'Theme set to "success"',
218-
theme: 'success',
219217
position: 'top-left'
220218
})
221219
})

src/utils/toast.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ type Toast = {
66
timeout?: number
77
title?: AlertProps['title']
88
content?: string
9-
theme?: AlertProps['theme']
109
position?: ToastProps['position']
1110
}
1211

@@ -23,17 +22,12 @@ export const toast = (config: Toast | string) => {
2322
timeout,
2423
title,
2524
content,
26-
theme,
2725
position
2826
} = (typeof config === 'string' ? {} : config) as Toast
2927

3028
const htmlElement = document.querySelector(element) as HTMLElement
3129

3230
if (htmlElement) {
33-
if (theme) {
34-
htmlElement.dataset.theme = theme
35-
}
36-
3731
if (position) {
3832
htmlElement.dataset.position = position
3933
}

0 commit comments

Comments
 (0)