Skip to content

Commit 0e253ed

Browse files
qwikerxxmimiex
andauthored
fix: button disabled issue (#244)
Co-authored-by: bhenique <benjamin.henique@gmail.com>
1 parent 59f9889 commit 0e253ed

File tree

3 files changed

+73
-17
lines changed

3 files changed

+73
-17
lines changed

apps/web/src/components/ComponentDocPage/ComponentDocPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const ComponentDocPage = component$<Item>(({ name }) => {
5656

5757
return (
5858
<>
59-
{previewItems.value ? (
59+
{previewItems.value.length ? (
6060
<DocumentPageContent ref={previewElements}>
6161
<section class="flex flex-col" q:slot="top">
6262
<Heading tag="h1" class="mb-2 text-3xl font-extrabold capitalize">
@@ -91,6 +91,7 @@ export const ComponentDocPage = component$<Item>(({ name }) => {
9191
) : (
9292
<Heading tag="h2" class="text-center">
9393
Component {name} does not exist
94+
<blockquote>${JSON.stringify(examples)}</blockquote>
9495
</Heading>
9596
)}
9697
</>

packages/lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "flowbite-qwik",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Official Qwik components built for Flowbite and Tailwind CSS",
55
"keywords": [
66
"design-system",

packages/lib/src/components/Button/Button.tsx

Lines changed: 70 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, component$, PropsOf, Slot, useComputed$ } from '@builder.io/qwik'
1+
import { Component, component$, PropsOf, Signal, Slot, useComputed$ } from '@builder.io/qwik'
22
import { ButtonGradient, ButtonMonochromeGradient, ButtonSize, ButtonVariant } from '~/components/Button/button-types'
33
import { useButtonClasses } from '~/components/Button/composables/use-button-classes'
44
import { useButtonSpinner } from '~/components/Button/composables/use-button-spinner'
@@ -61,6 +61,73 @@ export const Button = component$<ButtonProps>(
6161
full: useComputed$(() => full),
6262
})
6363

64+
const isLinkTag = ['a', Link].includes(tag)
65+
const LinkComponent = isLinkTag ? tag : 'a'
66+
const staticComponent = isLinkTag ? 'button' : tag
67+
const ButtonComponent = href ? LinkComponent : staticComponent
68+
69+
return (
70+
<>
71+
{ButtonComponent === 'button' ? (
72+
<button class={bindClasses.value} disabled={!href ? disabled : undefined} {...attrs}>
73+
<ButtonInnerComponent
74+
spanClasses={spanClasses}
75+
color={color}
76+
gradient={gradient}
77+
size={size}
78+
outline={outline}
79+
loading={loading}
80+
loadingPosition={loadingPosition}
81+
prefix={Prefix}
82+
suffix={Suffix}
83+
>
84+
<Slot />
85+
</ButtonInnerComponent>
86+
</button>
87+
) : (
88+
<ButtonComponent
89+
class={bindClasses.value}
90+
href={href}
91+
target={href ? attrs.target : undefined}
92+
//@ts-expect-error does not exist on other elements
93+
disabled={undefined}
94+
{...attrs}
95+
>
96+
<ButtonInnerComponent
97+
spanClasses={spanClasses}
98+
color={color}
99+
gradient={gradient}
100+
size={size}
101+
outline={outline}
102+
loading={loading}
103+
loadingPosition={loadingPosition}
104+
prefix={Prefix}
105+
suffix={Suffix}
106+
>
107+
<Slot />
108+
</ButtonInnerComponent>
109+
</ButtonComponent>
110+
)}
111+
</>
112+
)
113+
},
114+
)
115+
116+
type ButtonInnerProps = ButtonProps & {
117+
spanClasses: Signal<string>
118+
}
119+
const ButtonInnerComponent = component$<ButtonInnerProps>(
120+
({
121+
spanClasses,
122+
color = 'default',
123+
gradient,
124+
size = 'md',
125+
outline = false,
126+
loading = false,
127+
loadingPosition = 'prefix',
128+
prefix: Prefix,
129+
suffix: Suffix,
130+
}) => {
64131
const isOutlineGradient = useComputed$(() => outline && gradient)
65132

66133
const loadingPrefix = useComputed$(() => loading && loadingPosition === 'prefix')
@@ -73,20 +140,8 @@ export const Button = component$<ButtonProps>(
73140
outline,
74141
})
75142

76-
const isLinkTag = ['a', Link].includes(tag)
77-
const LinkComponent = isLinkTag ? tag : 'a'
78-
const staticComponent = isLinkTag ? 'button' : tag
79-
const ButtonComponent = href ? LinkComponent : staticComponent
80-
81143
return (
82-
<ButtonComponent
83-
class={bindClasses.value}
84-
href={href}
85-
target={href ? attrs.target : undefined}
86-
//@ts-expect-error does not exist on other elements
87-
disabled={!href && ButtonComponent === 'button' ? disabled : undefined}
88-
{...attrs}
89-
>
144+
<>
90145
{!isOutlineGradient.value && (Prefix || loadingPrefix.value) && (
91146
<span class="mr-2">{loadingPrefix.value ? <Spinner color={spinnerColor.value} size={spinnerSize.value} /> : Prefix && <Prefix />}</span>
92147
)}
@@ -106,7 +161,7 @@ export const Button = component$<ButtonProps>(
106161
{!isOutlineGradient.value && (Suffix || loadingSuffix.value) && (
107162
<span class="ml-2">{loadingSuffix.value ? <Spinner color={spinnerColor.value} size={spinnerSize.value} /> : Suffix && <Suffix />}</span>
108163
)}
109-
</ButtonComponent>
164+
</>
110165
)
111166
},
112167
)

0 commit comments

Comments
 (0)