Skip to content

Commit 15ac70c

Browse files
authored
refactor(component): refactoring Daisy Button props (#113)
1 parent 1b835d3 commit 15ac70c

File tree

4 files changed

+119
-81
lines changed

4 files changed

+119
-81
lines changed

packages/daisy/src/components/button/button.tsx

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,66 @@
11
import { component$, QwikIntrinsicElements, Slot } from '@builder.io/qwik';
22
import { Button as HeadlessButton } from '@qwik-ui/headless';
33
import { clsq } from '@qwik-ui/shared';
4+
import { daisyConfig } from './daisy.config';
45

56
export type HTMLButtonProps = QwikIntrinsicElements['button'];
67

78
export type DaisyButtonProps = {
9+
variant?: DaisyButtonVariants
10+
size?: DaisyButtonSizes
11+
active?: boolean;
812
noAnimation?: boolean;
13+
circle?: boolean;
914
glass?: boolean;
1015
loading?: boolean;
11-
circle?: boolean;
12-
square?: boolean;
13-
active?: boolean;
14-
disabled?: boolean;
1516
outline?: boolean;
16-
size?: 'xs' | 'sm' | 'md' | 'lg' | 'block' | 'wide';
17-
} & DaisyButtonModifiers;
18-
19-
export type DaisyButtonModifiers = {
20-
primary?: boolean;
21-
secondary?: boolean;
22-
accent?: boolean;
23-
info?: boolean;
24-
success?: boolean;
25-
warning?: boolean;
26-
error?: boolean;
27-
ghost?: boolean;
28-
link?: boolean;
17+
square?: boolean;
2918
}
3019

20+
export type DaisyButtonVariants = 'primary' | 'secondary' | 'accent' | 'info' | 'success' | 'warning' | 'error' | 'ghost' | 'link' | 'disabled';
21+
export type DaisyButtonSizes = 'xs' | 'sm' | 'md' | 'lg' | 'block' | 'wide';
3122
export type ButtonProps = HTMLButtonProps & DaisyButtonProps ;
3223

3324
export const Button = component$(
3425
(props: ButtonProps) => {
3526
const {
36-
class: cls,
37-
primary, secondary, accent, info, success, warning, error, ghost, link, outline, active, disabled, glass, loading, noAnimation,
27+
size = 'md',
28+
variant = 'primary',
3829
circle,
30+
active,
31+
class: cls,
32+
disabled,
33+
glass,
34+
loading,
35+
noAnimation,
36+
outline,
3937
square,
40-
size = 'md',
41-
...rest } = props;
38+
...rest
39+
} = props;
40+
41+
const {
42+
variants,
43+
sizes,
44+
options
45+
} = daisyConfig
4246

4347
return (
4448
<HeadlessButton
4549
{...rest}
4650
class={
4751
clsq(
4852
'btn',
53+
variants[variant],
54+
sizes[size],
4955
{
50-
// modifiers
51-
'btn-primary': primary,
52-
'btn-secondary': secondary,
53-
'btn-accent': accent,
54-
'btn-info': info,
55-
'btn-success': success,
56-
'btn-warning': warning,
57-
'btn-error': error,
58-
'btn-ghost': ghost,
59-
'btn-link': link,
60-
'btn-active': active,
61-
// daisy props
62-
'btn-outline': outline,
63-
'btn-disabled': disabled,
64-
'glass': glass,
65-
'loading': loading,
66-
'no-animation': noAnimation,
67-
'btn-circle': circle,
68-
'btn-square': square,
69-
// size
70-
'btn-xs': size === 'xs',
71-
'btn-sm': size === 'sm',
72-
'btn-md': size === 'md',
73-
'btn-lg': size === 'lg',
56+
[options.active]: active,
57+
[options.outline]: outline,
58+
[options.disabled]: disabled,
59+
[options.glass]: glass,
60+
[options.loading]: loading,
61+
[options.noAnimation]: noAnimation,
62+
[options.circle]: circle,
63+
[options.square]: square,
7464
},
7565
cls
7666
)}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export const daisyConfig = {
2+
variants: {
3+
accent: 'btn-accent',
4+
error: 'btn-error',
5+
ghost: 'btn-ghost',
6+
info: 'btn-info',
7+
link: 'btn-link',
8+
primary: 'btn-primary',
9+
secondary: 'btn-secondary',
10+
success: 'btn-success',
11+
warning: 'btn-warning',
12+
disabled: 'btn-disabled',
13+
},
14+
sizes: {
15+
xs: 'btn-xs',
16+
sm: 'btn-sm',
17+
md: 'btn-md',
18+
lg: 'btn-lg',
19+
block: 'btn-block',
20+
wide: 'btn-wide',
21+
},
22+
options: {
23+
active: 'btn-active',
24+
outline: 'btn-outline',
25+
disabled: 'btn-disabled',
26+
glass: 'glass',
27+
loading: 'loading',
28+
noAnimation: 'no-animation',
29+
circle: 'btn-circle',
30+
square: 'btn-square',
31+
}
32+
}

packages/website/src/routes/docs/daisy/button/index.tsx

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,73 +18,87 @@ export default component$(() => {
1818
<h2>Basic Example</h2>
1919
<div class="panel">
2020
<Button>default</Button>
21-
<Button primary>primary</Button>
22-
<Button secondary>secondary</Button>
23-
<Button accent>accent</Button>
24-
<Button info>info</Button>
25-
<Button success>success</Button>
26-
<Button warning>warning</Button>
27-
<Button error>error</Button>
28-
<Button ghost>ghost</Button>
29-
<Button link>link</Button>
30-
<Button primary active>primary active</Button>
31-
<Button accent active>accent active</Button>
32-
<Button disabled>disabled</Button>
33-
<Button disabled={true}>disabled</Button>
21+
<Button variant="primary">primary</Button>
22+
<Button variant="secondary">secondary</Button>
23+
<Button variant="accent">accent</Button>
24+
<Button variant="info">info</Button>
25+
<Button variant="success">success</Button>
26+
<Button variant="warning">warning</Button>
27+
<Button variant="error">error</Button>
28+
<Button variant="ghost">ghost</Button>
29+
<Button variant="link">link</Button>
30+
<Button variant="primary" disabled>primary disabled</Button>
31+
<Button variant="secondary" disabled>secondary disabled</Button>
3432
</div>
3533

34+
<h2>Active Example</h2>
35+
<div className="panel">
36+
<Button active>default</Button>
37+
<Button variant="primary" active>primary</Button>
38+
<Button variant="secondary" active>secondary</Button>
39+
<Button variant="accent" active>accent</Button>
40+
<Button variant="info" active>info</Button>
41+
<Button variant="success" active>success</Button>
42+
<Button variant="warning" active>warning</Button>
43+
<Button variant="error" active>error</Button>
44+
<Button variant="ghost" active>ghost</Button>
45+
<Button variant="link" active>link</Button>
46+
<Button variant="primary" active disabled>primary | active | disabled</Button>
47+
<Button variant="secondary" active disabled>secondary | active | disabled</Button>
48+
</div>
49+
50+
3651
<h2>Outline Example</h2>
3752
<div class="panel">
38-
<Button outline primary>primary</Button>
39-
<Button outline secondary>secondary</Button>
40-
<Button outline accent>accent</Button>
41-
<Button outline info>info</Button>
42-
<Button outline success>success</Button>
43-
<Button outline warning>warning</Button>
44-
<Button outline error>error</Button>
45-
<Button outline ghost>ghost</Button>
46-
<Button outline link>link</Button>
47-
<Button outline active>active</Button>
48-
<Button outline disabled>disabled</Button>
53+
<Button outline variant="primary">primary</Button>
54+
<Button outline variant="secondary">secondary</Button>
55+
<Button outline variant="accent">accent</Button>
56+
<Button outline variant="info">info</Button>
57+
<Button outline variant="success">success</Button>
58+
<Button outline variant="warning">warning</Button>
59+
<Button outline variant="error">error</Button>
60+
<Button outline variant="ghost">ghost</Button>
61+
<Button outline variant="link">link</Button>
62+
<Button outline variant="disabled">disabled</Button>
4963
</div>
5064

5165
<h2>size</h2>
5266
<div class="panel">
53-
<Button primary size="xs">xs</Button>
54-
<Button primary size="sm">sm</Button>
55-
<Button primary size="md">md</Button>
56-
<Button primary size="lg">lg</Button>
67+
<Button variant="primary" size="xs">xs</Button>
68+
<Button variant="secondary" size="sm">sm</Button>
69+
<Button variant="accent" size="md">md</Button>
70+
<Button variant="warning" size="lg">lg</Button>
5771
</div>
5872

5973
<h2>loading</h2>
6074
<div class="panel">
61-
<Button primary loading>loading</Button>
75+
<Button variant="primary" loading>loading</Button>
6276
<Button loading square></Button>
6377
</div>
6478

6579
<h2>no click animation</h2>
6680
<div class="panel">
67-
<Button primary noAnimation>click me</Button>
68-
<Button secondary noAnimation>click me</Button>
81+
<Button variant="primary" noAnimation>click me</Button>
82+
<Button variant="secondary" noAnimation>click me</Button>
6983
</div>
7084

7185
<h2>Square and Circle</h2>
7286
<div class="panel">
73-
<Button secondary square>A</Button>
74-
<Button accent circle>B</Button>
87+
<Button variant="secondary" square>A</Button>
88+
<Button variant="accent" circle>B</Button>
7589
</div>
7690

7791
<h2>Custom class</h2>
7892

7993
<div class="panel">
80-
<Button type="button" primary class="px-32 border-4 border-black">
94+
<Button type="button" variant="primary" class="px-32 border-4 border-black">
8195
CUSTOM CLASS
8296
</Button>
8397
</div>
8498

8599
<div>
86100
<h2>Qwik Events</h2>
87-
<Button primary onClick$={$(() => window.alert('hello'))}>SHOW ALERT</Button>
101+
<Button variant="primary" onClick$={$(() => window.alert('hello'))}>SHOW ALERT</Button>
88102
</div>
89103
</div>
90104
</>

packages/website/src/routes/docs/headless/button/index.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
.customCls {
22
background-color: lightcoral;
33
color: black;
4-
padding: 10px
4+
padding: 0.5rem 2rem;
5+
margin: 0.5rem;
6+
border-radius: 2rem;
57
}
68

79
.customCls:hover {

0 commit comments

Comments
 (0)