Skip to content

Commit e4779e9

Browse files
authored
Refactor/button group (#114)
* refactor(component): refactoring Daisy Button props * fix(component): fixed support for custom classes
1 parent 15ac70c commit e4779e9

File tree

6 files changed

+47
-11
lines changed

6 files changed

+47
-11
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { component$, HTMLAttributes, Slot } from '@builder.io/qwik';
22
import { ButtonGroup as HeadlessButtonGroup } from '@qwik-ui/headless';
3+
import { clsq } from '@qwik-ui/shared';
34

45
export type ButtonGroupProps = HTMLAttributes<HTMLElement>;
56

67
export const ButtonGroup = component$(
78
(props: ButtonGroupProps) => {
9+
const { class: cls, ...rest } = props;
810
return (
9-
<HeadlessButtonGroup {...props} class="btn-group" >
11+
<HeadlessButtonGroup class={clsq('btn-group', cls)} {...rest}>
1012
<Slot />
1113
</HeadlessButtonGroup>
1214
);

packages/headless/src/components/button-group/button-group.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ export type ButtonGroupProps = HTMLAttributes<HTMLElement>;
55
export const ButtonGroup = component$(
66
(props: ButtonGroupProps) => {
77
return (
8-
<div {...props}>
8+
<span {...props}>
99
<Slot />
10-
</div>
10+
</span>
1111
);
1212
}
1313
);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.custom-btn-group {
2+
background-color: #dedede;
3+
padding: 1rem;
4+
border-radius: 2rem;
5+
margin: 1rem 0;
6+
display: inline-block;
7+
}

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { component$ } from '@builder.io/qwik';
1+
import { component$, useStyles$ } from '@builder.io/qwik';
22
import { Button, ButtonGroup } from '@qwik-ui/theme-daisy';
3+
import styles from './button-group.css?inline';
34

45
export default component$(() => {
6+
useStyles$(styles);
57
return (
68
<>
79
<h2>This is the documentation for the ButtonGroup</h2>
@@ -13,12 +15,26 @@ export default component$(() => {
1315
<Button>BUTTON 3</Button>
1416
</ButtonGroup>
1517

18+
<hr/>
19+
<h1>With custom class</h1>
20+
<ButtonGroup class="custom-btn-group">
21+
<Button variant="accent">BUTTON 1</Button>
22+
<Button variant="accent">BUTTON 2</Button>
23+
<Button variant="accent">BUTTON 3</Button>
24+
</ButtonGroup>
1625
<hr/>
1726
<h1>With custom styles</h1>
18-
<ButtonGroup style="border: 0.2rem solid black; padding: 1rem;">
19-
<Button>BUTTON 1</Button>
20-
<Button>BUTTON 2</Button>
21-
<Button>BUTTON 3</Button>
27+
<ButtonGroup style="background-color: lightgray; padding: 1rem; display: inline-block; margin: 1rem 0;">
28+
<Button variant="secondary">BUTTON 1</Button>
29+
<Button variant="secondary">BUTTON 2</Button>
30+
<Button variant="secondary">BUTTON 3</Button>
31+
</ButtonGroup>
32+
33+
<h1>With button events</h1>
34+
<ButtonGroup>
35+
<Button variant="info" onClick$={() => window.alert('1') }>BUTTON 1</Button>
36+
<Button variant="info" onClick$={() => window.alert('2') }>BUTTON 2</Button>
37+
<Button variant="info" onClick$={() => window.alert('3') }>BUTTON 3</Button>
2238
</ButtonGroup>
2339
</>
2440
);
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
.custom-btn-group {
22
display: inline-flex;
3+
gap: 2rem;
4+
background-color: #dedede;
35
padding: 1rem;
4-
gap: 3rem;
6+
border-radius: 2rem;
7+
margin: 1rem 0;
58
}

packages/website/src/routes/docs/headless/button-group/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,20 @@ export default component$(() => {
1717
</ButtonGroup>
1818

1919
<hr/>
20-
<h1>With custom styles</h1>
21-
<ButtonGroup class="custom-btn-group" style="border: 2px solid black">
20+
<h1>With custom class</h1>
21+
<ButtonGroup class="custom-btn-group" >
2222
<Button>BUTTON 1</Button>
2323
<Button>BUTTON 2</Button>
2424
<Button>BUTTON 3</Button>
2525
</ButtonGroup>
26+
27+
<hr/>
28+
<h1>With custom styles</h1>
29+
<ButtonGroup style="border: 2px solid black; display: inline-flex; gap: 2rem; padding: 1rem">
30+
<Button style="color: red">BUTTON 1</Button>
31+
<Button>BUTTON 2</Button>
32+
<Button>BUTTON 3</Button>
33+
</ButtonGroup>
2634
</>
2735
);
2836
});

0 commit comments

Comments
 (0)