Skip to content

Commit fec229d

Browse files
committed
✨ Add Toast component to Astro
1 parent ce9999a commit fec229d

File tree

14 files changed

+413
-6
lines changed

14 files changed

+413
-6
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131
"components",
3232
"icons",
3333
"scss",
34+
"utils",
3435
"astro.d.ts",
3536
"astro.js",
3637
"svelte.d.ts",
3738
"svelte.js",
3839
"react.d.ts",
3940
"react.js",
41+
"index.js",
4042
"README.md",
4143
"LICENSE"
4244
],

scripts/build.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import fs from 'fs'
2-
import buildImports from './buildImports.js'
2+
import { buildImports, buildUtilImports } from './buildImports.js'
33
import buildTypes from './buildTypes.js'
44

55
const folders = {
66
'src/icons': 'dist/icons',
77
'src/components': 'dist/components',
8-
'src/scss': 'dist/scss'
8+
'src/scss': 'dist/scss',
9+
'src/utils': 'dist/utils'
910
}
1011

1112
const files = {
@@ -44,4 +45,6 @@ fs.writeFileSync('dist/astro.d.ts', buildTypes('astro'))
4445
fs.writeFileSync('dist/svelte.d.ts', buildTypes('svelte'))
4546
fs.writeFileSync('dist/react.d.ts', buildTypes('react'))
4647

48+
fs.writeFileSync('dist/index.js', buildUtilImports())
49+
4750
console.log('✅ Package built')

scripts/buildImports.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'fs'
22

3-
const buildImports = extension => {
3+
export const buildImports = extension => {
44
const components = fs.readdirSync('src/components')
55

66
return components.map(component => {
@@ -10,4 +10,8 @@ const buildImports = extension => {
1010
+ components.map(component => `export const ${component} = ${component}Component`).join('\n')
1111
}
1212

13-
export default buildImports
13+
export const buildUtilImports = () => {
14+
const utils = fs.readdirSync('src/utils')
15+
16+
return utils.map(util => `export * from './utils/${util}'`).join('\n')
17+
}

src/components/Alert/alert.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@
4848
.alert-body {
4949
font-size: 16px;
5050
color: #BBB;
51+
line-height: 1.5;
5152
}
5253
}

src/components/Button/button.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export type ButtonProps = {
99
| null
1010
bold?: boolean
1111
href?: string
12-
target?: string
13-
disabled?: boolean
1412
onClick?: () => any
13+
[key: string]: any
1514
}

src/components/Toast/Toast.astro

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
import type { ToastProps } from './toast'
3+
import Alert from '../Alert/Alert.astro'
4+
5+
import './toast.scss'
6+
7+
interface Props extends ToastProps {}
8+
9+
const {
10+
className
11+
} = Astro.props
12+
13+
const classes = [
14+
'w-toast',
15+
className
16+
].filter(Boolean).join(' ')
17+
---
18+
19+
{Astro.slots.has('icon') ? (
20+
<Alert {...Astro.props} className={classes}>
21+
<slot slot="icon" name="icon" />
22+
<slot />
23+
</Alert>
24+
) : (
25+
<Alert {...Astro.props} className={classes}>
26+
<slot />
27+
</Alert>
28+
)}

src/components/Toast/Toast.svelte

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script lang="ts">
2+
import type { ToastProps } from './toast'
3+
import './toast.scss'
4+
5+
export let className: ToastProps['className'] = ''
6+
7+
const classes = [
8+
'w-toast',
9+
className
10+
].filter(Boolean).join(' ')
11+
</script>

src/components/Toast/Toast.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react'
2+
import type { ToastProps } from './toast'
3+
4+
import './toast.scss'
5+
6+
const Toast = ({
7+
className
8+
}: ToastProps) => {
9+
const classes = [
10+
'w-toast',
11+
className
12+
].filter(Boolean).join(' ')
13+
14+
return <div>Toast</div>
15+
}
16+
17+
export default Toast

src/components/Toast/toast.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@import '../../scss/config.scss';
2+
3+
.w-toast {
4+
@include Transition(transform);
5+
background: #000;
6+
position: fixed;
7+
right: 20px;
8+
bottom: 20px;
9+
transform: translateY(calc(100% + 25px));
10+
11+
&.show {
12+
transform: translateY(0);
13+
}
14+
}

src/components/Toast/toast.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { AlertProps } from '../Alert/alert'
2+
3+
export type ToastProps = {
4+
[key: string]: any
5+
} & AlertProps

src/pages/index.astro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ const tabItems = [{
126126
<CardWrapper title="Tabs" href="/tabs">
127127
<Tabs items={tabItems} theme="boxed" />
128128
</CardWrapper>
129+
<CardWrapper title="Toast" href="/toast">
130+
<Alert theme="success">Post saved</Alert>
131+
</CardWrapper>
129132
<CardWrapper title="Tooltip" href="/tooltip">
130133
<p>Tooltip<sup>?</sup></p>
131134
</CardWrapper>

0 commit comments

Comments
 (0)