Skip to content

Commit 1d3eaaf

Browse files
committed
✨ Add Toast component for Svelte & React
1 parent fec229d commit 1d3eaaf

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,5 @@ import { Accordion } from 'webcoreui/react'
149149
- [Spinner](https://github.com/Frontendland/webcoreui/tree/main/src/components/Spinner)
150150
- [Switch](https://github.com/Frontendland/webcoreui/tree/main/src/components/Switch)
151151
- [Tabs](https://github.com/Frontendland/webcoreui/tree/main/src/components/Tabs)
152+
- [Toast](https://github.com/Frontendland/webcoreui/tree/main/src/components/Toast)
152153
- [Tooltip](https://github.com/Frontendland/webcoreui/blob/main/src/pages/tooltip.astro)

src/components/Toast/Toast.svelte

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts">
22
import type { ToastProps } from './toast'
3+
import Alert from '../Alert/Alert.svelte'
34
import './toast.scss'
45
56
export let className: ToastProps['className'] = ''
@@ -8,4 +9,11 @@
89
'w-toast',
910
className
1011
].filter(Boolean).join(' ')
11-
</script>
12+
</script>
13+
14+
<Alert {...$$restProps} className={classes}>
15+
{#if $$slots.icon}
16+
<slot name="icon" />
17+
{/if}
18+
<slot />
19+
</Alert>

src/components/Toast/Toast.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
11
import React from 'react'
22
import type { ToastProps } from './toast'
3+
import Alert from '../Alert/Alert.tsx'
34

45
import './toast.scss'
56

7+
type ReactToastProps = {
8+
children: React.ReactNode
9+
icon?: string
10+
} & ToastProps
11+
612
const Toast = ({
7-
className
8-
}: ToastProps) => {
13+
icon,
14+
className,
15+
children,
16+
...rest
17+
}: ReactToastProps) => {
918
const classes = [
1019
'w-toast',
1120
className
1221
].filter(Boolean).join(' ')
1322

14-
return <div>Toast</div>
23+
return (
24+
<Alert {...rest} className={classes} icon={icon}>
25+
{children}
26+
</Alert>
27+
28+
)
1529
}
1630

17-
export default Toast
31+
export default Toast

0 commit comments

Comments
 (0)