Skip to content

Commit 1b835d3

Browse files
authored
feat: add MaterialButtonProps (#112)
1 parent 4935b8a commit 1b835d3

File tree

4 files changed

+102
-19
lines changed

4 files changed

+102
-19
lines changed
Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,45 @@
11
import { component$, QwikIntrinsicElements, Slot } from '@builder.io/qwik';
22
import { Button as HeadlessButton } from '@qwik-ui/headless';
3+
import { clsq } from '@qwik-ui/shared';
34

4-
export type ButtonProps = QwikIntrinsicElements['button'];
5-
6-
export const Button = component$(
7-
(props: ButtonProps) => {
8-
return (
9-
<HeadlessButton class="waves-effect waves-light btn-large" {...props}>
10-
<Slot />
11-
</HeadlessButton>
12-
);
13-
}
14-
);
5+
export type HTMLButtonProps = QwikIntrinsicElements['button'];
6+
7+
export type MaterialButtonProps = {
8+
disabled?: boolean;
9+
floating?: boolean;
10+
flat?: boolean;
11+
size?: 'small' | 'medium' | 'large';
12+
};
13+
14+
export type ButtonProps = HTMLButtonProps & MaterialButtonProps;
15+
16+
export const Button = component$((props: ButtonProps) => {
17+
const {
18+
class: cls,
19+
disabled,
20+
floating,
21+
flat,
22+
size = 'medium',
23+
...rest
24+
} = props;
25+
26+
return (
27+
<HeadlessButton
28+
{...rest}
29+
class={clsq(
30+
{
31+
disabled: disabled,
32+
'btn-floating': floating,
33+
'btn-flat': flat,
34+
// size
35+
'btn-small': size === 'small',
36+
btn: size === 'medium',
37+
'btn-large': size === 'large',
38+
},
39+
cls
40+
)}
41+
>
42+
<Slot />
43+
</HeadlessButton>
44+
);
45+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { component$, Slot, useStyles$ } from '@builder.io/qwik';
22
import material from '../styles/materialize.scss?inline';
3+
import materialIcons from '../styles/material-icons.css?inline';
34

45
export const MaterialProvider = component$(() => {
56
useStyles$(material);
7+
useStyles$(materialIcons);
68
return <Slot />;
79
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* fallback */
2+
@font-face {
3+
font-family: 'Material Icons';
4+
font-style: normal;
5+
font-weight: 400;
6+
src: url(https://fonts.gstatic.com/s/materialicons/v139/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2) format('woff2');
7+
}
8+
9+
.material-icons {
10+
font-family: 'Material Icons';
11+
font-weight: normal;
12+
font-style: normal;
13+
font-size: 24px;
14+
line-height: 1;
15+
letter-spacing: normal;
16+
text-transform: none;
17+
display: inline-block;
18+
white-space: nowrap;
19+
word-wrap: normal;
20+
direction: ltr;
21+
-webkit-font-feature-settings: 'liga';
22+
-webkit-font-smoothing: antialiased;
23+
}

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

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,46 @@
1-
import { component$, $ } from '@builder.io/qwik';
1+
import { component$, $, useStylesScoped$ } from '@builder.io/qwik';
22
import { Button } from '@qwik-ui/material';
33
import { MaterialContext } from '../../../../../src/components/material';
44

5-
65
export default component$(() => {
6+
useStylesScoped$(`
7+
.panel {
8+
display: flex;
9+
gap: 8px;
10+
flex-wrap: wrap;
11+
}`);
12+
713
return (
814
<>
915
<h2>This is the documentation for the Button</h2>
16+
1017
<div class="flex flex-col gap-8 mt-4">
11-
<div>
12-
<h2>Basic Example</h2>
13-
<MaterialContext>
14-
<Button onClick$={$(() => alert('Material'))}>SIMPLE BUTTON</Button>
15-
</MaterialContext>
16-
</div>
18+
<h2>Raised</h2>
19+
<MaterialContext>
20+
<Button>Raised</Button>
21+
</MaterialContext>
22+
<h2>Disabled</h2>
23+
<MaterialContext>
24+
<Button disabled>Disabled</Button>
25+
</MaterialContext>
26+
<h2>Floating</h2>
27+
<MaterialContext>
28+
<Button floating size='large'>
29+
<i class="material-icons">add</i>
30+
</Button>
31+
</MaterialContext>
32+
<h2>Flat</h2>
33+
<MaterialContext>
34+
<Button flat>Flat</Button>
35+
</MaterialContext>
36+
<h2>Size: default medium</h2>
37+
<MaterialContext>
38+
<div class="panel">
39+
<Button size={'small'}>Small</Button>
40+
<Button size={'medium'}>Medium</Button>
41+
<Button size={'large'}>Large</Button>
42+
</div>
43+
</MaterialContext>
1744
</div>
1845
</>
1946
);

0 commit comments

Comments
 (0)