metacubexd/src/components/Button.tsx

29 lines
671 B
TypeScript
Raw Normal View History

import { JSX, ParentComponent, Show, splitProps } from 'solid-js'
import { twMerge } from 'tailwind-merge'
export const Button: ParentComponent<
2023-09-06 22:20:45 +08:00
JSX.ButtonHTMLAttributes<HTMLButtonElement> & {
loading?: boolean
disabled?: boolean
}
> = (props) => {
2023-09-06 22:20:45 +08:00
const [local, others] = splitProps(props, ['class', 'loading', 'disabled'])
return (
<button
2023-09-06 22:20:45 +08:00
class={twMerge(
'btn',
local.disabled && 'btn-disabled',
local.loading ? 'btn-disabled' : local.class,
)}
{...others}
>
<Show when={local.loading}>
<span class="loading loading-spinner" />
</Show>
{props.children}
</button>
)
}