-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.component.tsx
40 lines (36 loc) · 1.24 KB
/
button.component.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
import { JSX, Show, type Component } from 'solid-js';
import { ButtonProps } from './button.types';
import { Icon, IconifyIcon } from '@iconify-icon/solid';
import { attributes, classNames } from '@src/main';
export const Button: Component<ButtonProps> = (props) => {
const { variant = 'contained', color = 'primary', rounded, loading } = props;
const disabled = loading ? true : props.disabled;
return (
<button
type="button"
{...attributes(props)}
title={props.title}
spx-variant={variant}
spx-color={color}
spx-rounded={rounded}
disabled={disabled}
onClick={props.onClick}
{...classNames('spx-button', props.class)}
>
{/* Loader */}
<Show when={loading}>
<Show when={props.loader}>{props.loader}</Show>
<Show when={!props.loader}>
<Icon icon="svg-spinners:ring-resize" />
</Show>
</Show>
{/* Icon */}
<Show when={typeof props.icon === 'string' && !loading}>
<Icon icon={props.icon as IconifyIcon} />
</Show>
<Show when={typeof props.icon === 'object'}>{props.icon as JSX.Element}</Show>
{/* Content */}
{props.children && <span class="spx-button-content">{props.children}</span>}
</button>
);
};