Skip to content

Commit 20134ff

Browse files
committed
♻️ Simplify Button block types
1 parent 349f43d commit 20134ff

File tree

18 files changed

+97
-120
lines changed

18 files changed

+97
-120
lines changed

src/blocks/Button/button.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import type {
22
BadgeProps,
3-
ButtonProps as WebcoreButtonProps,
3+
ButtonProps as WButtonProps,
44
IconProps
55
} from 'webcoreui/astro'
66

7-
export type ButtonProps = {
8-
icon?: IconProps['type'] | string
7+
type BaseProps = {
98
text?: string
9+
icon?: IconProps['type'] | string
10+
}
11+
12+
export type ButtonProps = {
1013
badge?: boolean
11-
className?: string
12-
} & WebcoreButtonProps & BadgeProps
14+
} & BaseProps & WButtonProps & BadgeProps
15+
16+
export type ButtonBlockProps = BaseProps & WButtonProps
17+
export type BadgeBlockProps = BaseProps & BadgeProps

src/blocks/Deployments/Deployments.astro

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
---
22
import {
33
Alert,
4-
Button,
54
Icon,
65
Modal
76
} from 'webcoreui/astro'
87
8+
import Button from '@blocks/Button/Button.astro'
9+
910
import styles from './deployments.module.scss'
1011
---
1112

1213
<Alert title="Deployments">
1314
<Icon type="github" slot="icon" />
1415
<span>Connect your project to GitHub to start running automatic deployments.</span>
1516
<br />
16-
<Button className={styles.connect} id="connect">Connect</Button>
17+
<Button className={styles.connect} id="connect" text="Connect" />
1718
</Alert>
1819

1920
<Modal title="Are you sure?" subTitle="Confirm update" className="modal">
2021
<p>Automatic deployments will be enabled for your project.</p>
21-
<Button className="close-modal">Confirm</Button>
22-
<Button theme="secondary" className="close-modal">Cancel</Button>
22+
<Button className="close-modal" text="Confirm" />
23+
<Button theme="secondary" className="close-modal" text="Cancel" />
2324
</Modal>
2425

2526
<script>

src/blocks/Deployments/Deployments.svelte

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import { closeModal, modal } from 'webcoreui'
44
import {
55
Alert,
6-
Button,
76
Icon,
87
Modal
98
} from 'webcoreui/svelte'
109
10+
import Button from '@blocks/Button/Button.astro'
11+
1112
import styles from './deployments.module.scss'
1213
1314
let modalInstance
@@ -26,11 +27,11 @@
2627
{/snippet}
2728
<span>Connect your project to GitHub to start running automatic deployments.</span>
2829
<br />
29-
<Button className={styles.connect} onClick={connect}>Connect</Button>
30+
<Button className={styles.connect} onClick={connect} text="Connect" />
3031
</Alert>
3132

3233
<Modal title="Are you sure?" subTitle="Confirm update" className="modal">
3334
<p>Automatic deployments will be enabled for your project.</p>
34-
<Button className="close-modal" onClick={close}>Confirm</Button>
35-
<Button theme="secondary" className="close-modal" onClick={close}>Cancel</Button>
35+
<Button className="close-modal" onClick={close} text="Confirm" />
36+
<Button theme="secondary" className="close-modal" onClick={close} text="Cancel" />
3637
</Modal>

src/blocks/Deployments/Deployments.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import React, { useEffect, useState } from 'react'
22
import { closeModal,modal } from 'webcoreui'
33
import {
44
Alert,
5-
Button,
65
Icon,
76
Modal
87
} from 'webcoreui/react'
98

9+
import Button from '@blocks/Button/Button.astro'
10+
1011
import styles from './deployments.module.scss'
1112

1213
type ModalInstance = {
@@ -28,13 +29,13 @@ const Deployments = () => {
2829
<Alert title="Deployments" icon={<Icon type="github" />}>
2930
<span>Connect your project to GitHub to start running automatic deployments.</span>
3031
<br />
31-
<Button className={styles.connect} onClick={connect}>Connect</Button>
32+
<Button className={styles.connect} onClick={connect} text="Connect" />
3233

3334
<Modal title="Are you sure?" subTitle="Confirm update" className="modal">
3435
<p>Automatic deployments will be enabled for your project.</p>
3536
<div className="flex xs">
36-
<Button className="close-modal" onClick={close}>Confirm</Button>
37-
<Button theme="secondary" className="close-modal" onClick={close}>Cancel</Button>
37+
<Button className="close-modal" onClick={close} text="Confirm" />
38+
<Button theme="secondary" className="close-modal" onClick={close} text="Cancel" />
3839
</div>
3940
</Modal>
4041
</Alert>

src/blocks/Empty/empty.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
import type {
2-
ButtonProps,
3-
IconProps
4-
} from 'webcoreui/astro'
1+
import type { IconProps } from 'webcoreui/astro'
2+
3+
import type { ButtonBlockProps } from '@blocks/Button/button'
54

65
export type EmptyProps = {
76
icon?: IconProps['type'] | string
87
iconWithBackground?: boolean
98
title: string
109
text: string
11-
buttons?: ({
12-
text: string
13-
icon?: IconProps['type'] | string
14-
} & ButtonProps)[]
10+
buttons?: ButtonBlockProps[]
1511
className?: string
1612
}

src/blocks/ErrorPage/ErrorPage.astro

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
---
2-
import {
3-
Button,
4-
Icon
5-
} from 'webcoreui/astro'
2+
import Button from '@blocks/Button/Button.astro'
63
74
import type { ErrorPageProps } from './errorPage'
85
import styles from './error-page.module.scss'
@@ -29,19 +26,7 @@ const typeStyle = typeColor
2926
{subTitle && <h2 class={styles['sub-title']}>{subTitle}</h2>}
3027
{!!buttons?.length && (
3128
<div class="flex xs wrap justify-center">
32-
{buttons?.map(button => (
33-
<Button {...button} icon={null}>
34-
{button.icon && (
35-
<Fragment>
36-
{button.icon.startsWith('<svg')
37-
? <Fragment set:html={button.icon} />
38-
: <Icon type={button.icon} />
39-
}
40-
</Fragment>
41-
)}
42-
{button.text}
43-
</Button>
44-
))}
29+
{buttons?.map(button => <Button {...button} />)}
4530
</div>
4631
)}
4732
</section>

src/blocks/ErrorPage/ErrorPage.svelte

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { Button } from 'webcoreui/svelte'
2+
import Button from '@blocks/Button/Button.svelte'
33
44
import type { ErrorPageProps } from './errorPage'
55
import styles from './error-page.module.scss'
@@ -28,12 +28,7 @@
2828
{#if buttons?.length}
2929
<div class="flex xs wrap justify-center">
3030
{#each buttons as button}
31-
<Button {...button} icon={null}>
32-
{#if button.icon}
33-
{@html button.icon}
34-
{/if}
35-
{button.text}
36-
</Button>
31+
<Button {...button} />
3732
{/each}
3833
</div>
3934
{/if}

src/blocks/ErrorPage/ErrorPage.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
2-
import { Button } from 'webcoreui/react'
2+
3+
import Button from '@blocks/Button/Button.tsx'
34

45
import type { ErrorPageProps } from './errorPage'
56
import styles from './error-page.module.scss'
@@ -24,15 +25,7 @@ const ErrorPage = ({
2425
{!!buttons?.length && (
2526
<div className="flex xs wrap justify-center">
2627
{buttons?.map((button, index) => (
27-
<Button
28-
{...button}
29-
key={index}
30-
icon={null}
31-
dangerouslySetInnerHTML={{ __html: button.icon
32-
? `${button.icon} ${button.text}`
33-
: button.text
34-
}}
35-
/>
28+
<Button {...button} key={index} />
3629
))}
3730
</div>
3831
)}

src/blocks/ErrorPage/errorPage.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import type { ButtonProps, IconProps } from 'webcoreui/astro'
1+
import type { ButtonBlockProps } from '@blocks/Button/button'
22

33
export type ErrorPageProps = {
44
type: number
55
typeColor?: string
66
title: string
77
subTitle?: string
8-
buttons?: ({
9-
text: string
10-
icon?: IconProps['type'] | string
11-
} & ButtonProps)[]
8+
buttons?: ButtonBlockProps[]
129
[key: string]: any
1310
}

src/blocks/Hero/hero.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
import type {
2-
BadgeProps,
3-
ButtonProps,
4-
IconProps
5-
} from 'webcoreui/astro'
6-
71
import type { AvatarWithRatingProps } from '@blocks/AvatarWithRating/avatarWithRating'
2+
import type { BadgeBlockProps, ButtonBlockProps } from '@blocks/Button/button'
83

94
export type HeroProps = {
10-
badge?: {
11-
text: string
12-
} & BadgeProps | null
5+
badge?: BadgeBlockProps
136
heading: string
147
subHeading?: string
15-
buttons?: ({
16-
text: string
17-
icon?: IconProps['type'] | string
18-
} & ButtonProps)[]
8+
buttons?: ButtonBlockProps[]
199
avatarWithRating?: AvatarWithRatingProps
2010
image?: {
2111
src: string

0 commit comments

Comments
 (0)