Skip to content

Commit f8aa3af

Browse files
Merge pull request #59 from code0-tech/issue-30/more-button-styles
Issue 30/more button styles
2 parents 539c937 + d851ec1 commit f8aa3af

File tree

5 files changed

+58
-20
lines changed

5 files changed

+58
-20
lines changed

src/components/button/Button.stories.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,29 @@ const meta = {
1616
type: "boolean",
1717
default: false
1818
},
19-
variant: {table: {disable: true}}
19+
variant: {
20+
options: ['none', 'normal', 'filled', 'outlined'],
21+
control: {type: 'radio'},
22+
},
23+
color: {table: {disable: true}}
2024
}
2125
}
2226

23-
type ButtonStory = StoryObj<{ icon: boolean, disabled: boolean }>;
27+
type ButtonStory = StoryObj<{ icon: boolean, disabled: boolean, variant: string }>;
2428
type ButtonGroupStory = StoryObj<typeof ButtonGroup>;
2529

2630
export default meta
2731

2832
export const Buttons: ButtonStory = {
2933
render: (args) => {
3034

31-
const {icon, disabled} = args
35+
const {icon, disabled, variant} = args
3236

3337
return <>
3438
{
3539
["primary", "secondary", "info", "success", "warning", "error"].map(value => {
3640
// @ts-ignore
37-
return <Button disabled={disabled} variant={value}>
41+
return <Button disabled={disabled} variant={variant} color={value}>
3842
{icon ? <Button.Icon><IconAbc/></Button.Icon> : null}
3943
{value}
4044
</Button>
@@ -44,7 +48,8 @@ export const Buttons: ButtonStory = {
4448
},
4549
args: {
4650
icon: true,
47-
disabled: false
51+
disabled: false,
52+
variant: "normal"
4853
}
4954
}
5055

@@ -55,7 +60,7 @@ export const ButtonGroups: ButtonGroupStory = {
5560
{
5661
["primary", "secondary", "info", "success", "warning", "error"].map((value, index) => {
5762
// @ts-ignore
58-
return <Button variant={value}>
63+
return <Button color={value}>
5964
{(index % 2) == 0 ? <Button.Icon><IconAbc/></Button.Icon> : null}
6065
{value}
6166
</Button>
@@ -66,7 +71,7 @@ export const ButtonGroups: ButtonGroupStory = {
6671
{
6772
["primary", "primary", "primary", "primary"].map((value, index) => {
6873
// @ts-ignore
69-
return <Button variant={value}>
74+
return <Button color={value}>
7075
{(index % 2) == 0 ? <Button.Icon><IconAbc/></Button.Icon> : null}
7176
{value}
7277
</Button>
@@ -78,14 +83,13 @@ export const ButtonGroups: ButtonGroupStory = {
7883
{
7984
["secondary", "secondary", "secondary", "secondary"].map((value, index) => {
8085
// @ts-ignore
81-
return <Button disabled={(index % 2) == 0} variant={value}>
86+
return <Button disabled={(index % 2) == 0} color={value}>
8287
{(index % 2) == 0 ? <Button.Icon><IconAbc/></Button.Icon> : null}
8388
{value}
8489
</Button>
8590
})
8691
}
8792
</ButtonGroup>
88-
8993
</>
9094
}
9195
}

src/components/button/Button.style.scss

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
@import "../../styles/helpers";
22

33
.button {
4-
@include box(true);
5-
64
padding: .5rem;
75
cursor: pointer;
86
display: flex;
@@ -34,10 +32,44 @@
3432
}
3533
}
3634

35+
@function getMixedColor($color) {
36+
@return mix($bodyBg, if($color == $primary, $white, $color), if($color == $primary, 90%, 80%));
37+
}
38+
3739
@each $name, $color in $variants {
3840
.button--#{$name} {
3941
@include box(true, $color);
4042

43+
&.button--filled {
44+
border-color: transparent;
45+
46+
&:active {
47+
@include border();
48+
}
49+
}
50+
51+
&.button--outlined {
52+
background: transparent;
53+
border-color: getMixedColor($color);
54+
&:hover, &.button--none:hover {
55+
background: getMixedColor($color);
56+
}
57+
&:active, &.button--none:active {
58+
@include border();
59+
}
60+
}
61+
62+
&.button--none {
63+
background: transparent;
64+
border-color: transparent;
65+
&:hover {
66+
background: getMixedColor($color);
67+
}
68+
&:active {
69+
@include border();
70+
}
71+
}
72+
4173
.button__icon {
4274
color: color($color);
4375
}

src/components/button/Button.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import {getChild, getContent} from "../../utils/utils";
99
export interface ButtonType extends DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement> {
1010
children: ReactNode | ReactNode[]
1111
//defaults to primary
12-
variant?: "primary" | "secondary" | "info" | "success" | "warning" | "error",
12+
color?: "primary" | "secondary" | "info" | "success" | "warning" | "error",
13+
//default to normal
14+
variant?: "none" | "normal" | "outlined" | "filled",
1315
//defaults to false
1416
active?: boolean
1517
//defaults to false
@@ -22,13 +24,13 @@ export interface ButtonIconType {
2224

2325
const Button: React.FC<ButtonType> = (props) => {
2426

25-
const {children, variant = "primary", active = false, disabled = false, ...args} = props
27+
const {children, variant = "normal", color = "primary", active = false, disabled = false, ...args} = props
2628
const icon = getChild(children, ButtonIcon)
2729
const content = getContent(children, ButtonIcon)
2830

29-
30-
return <a {...args} className={`button button--${variant} ${active ? "button--active" : ""} ${disabled ? "button--disabled" : ""}`}
31-
aria-disabled={disabled ? "true" : "false"}>
31+
return <a {...args}
32+
className={`button button--${color} ${active ? "button--active" : ""} ${disabled ? "button--disabled" : ""} button--${variant}`}
33+
aria-disabled={disabled ? "true" : "false"}>
3234
{icon}
3335
{content ? <span className={"button__content"}>{content}</span> : null}
3436
</a>

src/components/card/Card.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ export const Test = () => {
3939
</ListGroup>
4040
<CardFooter>
4141
<ButtonGroup>
42-
<Button variant={"secondary"}>
42+
<Button color={"secondary"}>
4343
Button
4444
</Button>
45-
<Button variant={"secondary"}>
45+
<Button color={"secondary"}>
4646
Button
4747
</Button>
4848
</ButtonGroup>

src/components/dropdown/Dropdown.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ export const Dropdowns = () => {
5353
{
5454
["secondary", "secondary", "secondary", "secondary"].map((value, index) => {
5555
// @ts-ignore
56-
return (index % 2 == 0) ? <Button disabled={(index % 2) == 0} variant={value}>
56+
return (index % 2 == 0) ? <Button disabled={(index % 2) == 0} color={value}>
5757
{(index % 2) == 0 ? <Button.Icon><IconAbc/></Button.Icon> : null}
5858
{value}
5959
</Button> : <Dropdown position={"bottom"} align={"start"}>
6060
<Dropdown.Trigger>
61-
<Button disabled={(index % 2) == 0} variant={"secondary"}>
61+
<Button disabled={(index % 2) == 0} color={"secondary"}>
6262
{(index % 2) == 0 ? <Button.Icon><IconAbc/></Button.Icon> : null}
6363
{value}
6464
</Button>

0 commit comments

Comments
 (0)