-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathButton.tsx
60 lines (57 loc) · 1.57 KB
/
Button.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import {ElementType} from '@solid-aria/types';
import clsx from 'clsx';
import {ButtonProps as ShButtonProps} from 'solid-headless';
import {JSXElement, ParentProps, Show, splitProps} from 'solid-js';
import {CustomComponentProps, styled} from '../../utils';
import {LoadingCircle} from '../Loader';
import * as styles from './Button.css';
import {ButtonSizes} from './Button.css';
export type ButtonProps<T extends ElementType = 'button'> =
CustomComponentProps<
T,
{
leftIcon?: JSXElement;
loading?: boolean;
} & ShButtonProps<T> &
styles.ButtonVariants
>;
export function Button<T extends ElementType = 'button'>(
props: ParentProps<ButtonProps<T>>,
): JSXElement {
const [local, others] = splitProps(props, [
'as',
'class',
'loading',
'pill',
'loading',
'block',
'theme',
'variant',
'size',
'children',
'leftIcon',
]);
const classes = () =>
clsx(
styles.buttonVariant({
pill: local.pill,
block: local.block,
theme: local.theme,
variant: local.variant,
size: local.size || ('sm' as ButtonSizes),
loading: local.loading,
}),
local.class,
);
return (
<styled.button as={local.as ?? 'button'} class={classes()} {...others}>
<Show when={!!local.leftIcon && !local.loading}>
<span class={styles.buttonIcon}>{local.leftIcon}</span>
</Show>
<Show when={local.loading}>
<LoadingCircle class={styles.buttonIcon} size={local.size ?? 'sm'} />
</Show>
{local.children}
</styled.button>
);
}