Skip to content

Commit

Permalink
fix(rules): reload button style issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kunish committed Sep 23, 2023
1 parent 29ebee3 commit 04c8d25
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 45 deletions.
47 changes: 18 additions & 29 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { JSX, ParentComponent, Show, splitProps } from 'solid-js'
import { twMerge } from 'tailwind-merge'

interface ButtonBaseProps extends JSX.ButtonHTMLAttributes<HTMLButtonElement> {
loading?: boolean
disabled?: boolean
}

interface ButtonWithIconProps extends ButtonBaseProps {
icon: JSX.Element
children?: JSX.Element
}

interface ButtonWithoutIconProps extends ButtonBaseProps {
icon?: JSX.Element
children: JSX.Element
}

export const Button: ParentComponent<
JSX.ButtonHTMLAttributes<HTMLButtonElement> & {
loading?: boolean
disabled?: boolean
icon?: JSX.Element
}
ButtonWithIconProps | ButtonWithoutIconProps
> = (props) => {
const [local, others] = splitProps(props, [
'class',
'loading',
'disabled',
'icon',
])
const [local, others] = splitProps(props, ['class', 'loading', 'icon'])

return (
<button
Expand All @@ -22,29 +28,12 @@ export const Button: ParentComponent<
local.loading ? 'btn-disabled' : local.class,
)}
{...others}
onClick={(e) => {
if (props.disabled) {
e.preventDefault()
e.stopPropagation()

return
}

if (typeof props.onClick === 'function') {
props.onClick(e)
}
}}
>
<Show when={local.loading}>
<div class="loading loading-spinner" />
</Show>

<span
class="truncate"
classList={{
'flex-1': !local.icon,
}}
>
<span class="truncate" classList={{ 'flex-1': !local.icon }}>
{props.icon || props.children}
</span>
</button>
Expand Down
34 changes: 18 additions & 16 deletions src/pages/Rules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default () => {
return (
<div class="flex h-full flex-col gap-2">
<div class="flex items-center gap-2">
<div class="tabs tabs-boxed gap-2">
<div class="tabs-boxed tabs gap-2">
<For each={tabs()}>
{(tab) => (
<button
Expand All @@ -81,13 +81,14 @@ export default () => {
class="btn btn-circle btn-sm"
disabled={allProviderIsUpdating()}
onClick={(e) => onUpdateAllProviderClick(e)}
>
<IconReload
class={twMerge(
allProviderIsUpdating() && 'animate-spin text-success',
)}
/>
</Button>
icon={
<IconReload
class={twMerge(
allProviderIsUpdating() && 'animate-spin text-success',
)}
/>
}
/>
</Show>
</div>

Expand Down Expand Up @@ -133,14 +134,15 @@ export default () => {
class="btn-circle btn-sm absolute right-2 top-2 mr-2 h-4"
disabled={updatingMap()[ruleProvider.name]}
onClick={(e) => onUpdateProviderClick(e, ruleProvider.name)}
>
<IconReload
class={twMerge(
updatingMap()[ruleProvider.name] &&
'animate-spin text-success',
)}
/>
</Button>
icon={
<IconReload
class={twMerge(
updatingMap()[ruleProvider.name] &&
'animate-spin text-success',
)}
/>
}
/>
</div>
)}
</For>
Expand Down

0 comments on commit 04c8d25

Please sign in to comment.