Skip to content

Commit 2cee766

Browse files
committed
🏷️ Improve types
1 parent a677653 commit 2cee766

File tree

7 files changed

+32
-17
lines changed

7 files changed

+32
-17
lines changed

src/components/Badge/Badge.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import styles from './badge.module.scss'
77
88
export let theme: SvelteBadgeProps['theme'] = null
9-
export let onClick: SvelteBadgeProps['onClick'] = null
109
export let hover: SvelteBadgeProps['hover'] = false
1110
export let small: SvelteBadgeProps['small'] = false
1211
export let className: SvelteBadgeProps['className'] = ''
12+
export let onClick: SvelteBadgeProps['onClick'] = () => {}
1313
1414
const classes = classNames([
1515
styles.badge,

src/components/Badge/badge.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { MouseEventHandler } from 'svelte/elements'
2+
13
export type BadgeProps = {
24
theme?: 'secondary'
35
| 'outline'
@@ -14,10 +16,10 @@ export type BadgeProps = {
1416
}
1517

1618
export type SvelteBadgeProps = {
17-
onClick?: ((event: MouseEvent) => void) | null
19+
onClick?: MouseEventHandler<HTMLButtonElement>
1820
} & BadgeProps
1921

2022
export type ReactBadgeProps = {
21-
onClick?: (event: React.MouseEvent) => void
23+
onClick?: React.MouseEventHandler<HTMLButtonElement>
2224
children: React.ReactNode
2325
} & BadgeProps

src/components/Button/button.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { MouseEventHandler } from 'svelte/elements'
2+
13
export type ButtonProps = {
24
theme?: 'secondary'
35
| 'outline'
@@ -7,17 +9,24 @@ export type ButtonProps = {
79
| 'warning'
810
| 'alert'
911
| null
12+
| undefined
13+
target?: '_self'
14+
| '_blank'
15+
| '_parent'
16+
| '_top'
17+
| '_unfencedTop'
18+
| null
19+
| undefined
1020
href?: string
11-
target?: '_self' | '_blank' | '_parent' | '_top' | '_unfencedTop' | undefined
1221
className?: string
1322
[key: string]: any
1423
}
1524

1625
export type SvelteButtonProps = {
17-
onClick?: ((event: MouseEvent) => void) | null
26+
onClick?: MouseEventHandler<HTMLButtonElement>
1827
} & ButtonProps
1928

2029
export type ReactButtonProps = {
21-
onClick?: (event: React.MouseEvent) => void
30+
onClick?: React.MouseEventHandler<HTMLButtonElement>
2231
children: React.ReactNode
2332
} & ButtonProps

src/components/Checkbox/checkbox.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { MouseEventHandler } from 'svelte/elements'
2+
13
export type CheckboxProps = {
24
checked?: boolean
35
label?: string
@@ -8,9 +10,9 @@ export type CheckboxProps = {
810
}
911

1012
export type SvelteCheckboxProps = {
11-
onClick?: ((event: MouseEvent) => void) | null
13+
onClick?: MouseEventHandler<HTMLInputElement>
1214
} & CheckboxProps
1315

1416
export type ReactCheckboxProps = {
15-
onClick?: (event: React.MouseEvent) => void
17+
onClick?: React.MouseEventHandler<HTMLInputElement>
1618
} & CheckboxProps

src/components/Switch/switch.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { MouseEventHandler } from 'svelte/elements'
2+
13
export type SwitchProps = {
24
label?: string
35
reverse?: boolean
@@ -11,9 +13,9 @@ export type SwitchProps = {
1113
}
1214

1315
export type SvelteSwitchProps = {
14-
onClick?: ((event: MouseEvent) => void) | null
16+
onClick?: MouseEventHandler<HTMLInputElement>
1517
} & SwitchProps
1618

1719
export type ReactSwitchProps = {
18-
onClick?: (event: React.MouseEvent) => void
20+
onClick?: React.MouseEventHandler<HTMLInputElement>
1921
} & SwitchProps

src/playground/ReactPlayground.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const ReactPlayground = () => {
9292
<Card title="Checkbox">
9393
<Checkbox
9494
label="Accept"
95-
onClick={e => setCheckbox(e.target.checked)}
95+
onClick={e => setCheckbox(e.currentTarget.checked)}
9696
/>
9797

9898
<span className={styles.span}>{`${checkbox}`}</span>
@@ -222,7 +222,7 @@ const ReactPlayground = () => {
222222

223223
<Card title="Switch">
224224
<Switch
225-
onClick={e => setToggle(e.target.checked)}
225+
onClick={e => setToggle(e.currentTarget.checked)}
226226
/>
227227

228228
<span className={styles.span}>{`${toggle}`}</span>

src/playground/SveltePlayground.svelte

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script>
1+
<script lang="ts">
22
import Accordion from '@components/Accordion/Accordion.svelte'
33
import Badge from '@components/Badge/Badge.svelte'
44
import Button from '@components/Button/Button.svelte'
@@ -90,7 +90,7 @@
9090
<Card title="Checkbox">
9191
<Checkbox
9292
label="Accept"
93-
onClick={e => checkbox = e.target.checked}
93+
onClick={e => checkbox = e.currentTarget.checked}
9494
/>
9595

9696
<span class={styles.span}>{checkbox}</span>
@@ -128,12 +128,12 @@
128128
<Input
129129
label="Enter a value"
130130
placeholder="Or change the color below"
131-
onKeyUp={e => input = e.target.value}
131+
onKeyUp={e => input = e.currentTarget.value}
132132
/>
133133

134134
<Input
135135
type="color"
136-
onChange={e => input = e.target.value}
136+
onChange={e => input = e.currentTarget.value}
137137
/>
138138

139139
<span class={styles.span}>{input}</span>
@@ -217,7 +217,7 @@
217217

218218
<Card title="Switch">
219219
<Switch
220-
onClick={e => toggle = e.target.checked}
220+
onClick={e => toggle = e.currentTarget.checked}
221221
/>
222222

223223
<span class={styles.span}>{toggle}</span>

0 commit comments

Comments
 (0)