(react) add button sizes

Add two sizes for the Button component: small and medium. They
are present on the new delivered sketches concerning pagination
but dont exists yet.
This commit is contained in:
Nathan Vasse
2023-02-16 14:41:40 +01:00
committed by NathanVss
parent f3e3b568fc
commit 05242ffbcd
8 changed files with 63 additions and 15 deletions

View File

@@ -4,17 +4,31 @@
border: none;
cursor: pointer;
transition: background-color var(--c--theme--transitions--duration) var(--c--theme--transitions--ease-out);
padding: 0 var(--c--theme--spacings--s);
height: var(--c--components--button--height);
border-radius: var(--c--components--button--border-radius);
font-size: var(--c--components--button--font-size);
font-weight: var(--c--components--button--font-weight);
&--medium {
height: var(--c--components--button--medium-height);
font-size: var(--c--components--button--medium-font-size);
padding: 0 var(--c--theme--spacings--s);
&.c__button--icon-only {
width: var(--c--components--button--medium-height);
}
}
&--small {
height: var(--c--components--button--small-height);
font-size: var(--c--components--button--small-font-size);
padding: 0 0.75rem;
&.c__button--icon-only {
width: var(--c--components--button--small-height);
}
}
&--icon-only {
padding: 0;
width: var(--c--components--button--height);
justify-content: center;
}
@@ -41,6 +55,10 @@
&:active, &.c__button--active {
background-color: var(--c--theme--colors--primary-500);
}
&[disabled] {
background-color: var(--c--theme--colors--greyscale-200);
}
}
&--secondary {
@@ -54,6 +72,10 @@
&:active, &.c__button--active {
background-color: var(--c--theme--colors--secondary-500);
}
&[disabled] {
background-color: var(--c--theme--colors--greyscale-200);
}
}
&--tertiary {
@@ -62,12 +84,17 @@
&:hover {
color: var(--c--theme--colors--greyscale-900);
background-color: var(--c--theme--colors--greyscale-100);
}
&:active, &.c__button--active {
color: var(--c--theme--colors--greyscale-800);
background-color: var(--c--theme--colors--greyscale-200);
}
&[disabled] {
background-color: transparent;
}
}
&--danger {
@@ -81,11 +108,14 @@
&:active {
background-color: var(--c--theme--colors--danger-500);
}
&[disabled] {
background-color: var(--c--theme--colors--greyscale-200);
}
}
&[disabled] {
cursor: not-allowed;
background-color: var(--c--theme--colors--greyscale-200);
color: var(--c--theme--colors--greyscale-400);
}
}

View File

@@ -1,7 +1,7 @@
import { act, render, screen, waitFor } from "@testing-library/react";
import React from "react";
import { buildTheme, loadTokens } from "tests/Theme";
import userEvent from "@testing-library/user-event";
import { buildTheme, loadTokens } from "tests/Theme";
import { Button } from "./index";
describe("<Button/>", () => {

View File

@@ -5,6 +5,11 @@ import { Button } from "./index";
export default {
title: "Components/Button",
component: Button,
argTypes: {
disabled: {
control: "boolean",
},
},
} as ComponentMeta<typeof Button>;
const Template: ComponentStory<typeof Button> = (args) => <Button {...args} />;
@@ -40,6 +45,13 @@ Danger.args = {
color: "danger",
};
export const Small = Template.bind({});
Small.args = {
children: "Primary",
color: "primary",
size: "small",
};
export const IconLeft = Template.bind({});
IconLeft.args = {
children: "Icon",

View File

@@ -2,6 +2,7 @@ import React, { ButtonHTMLAttributes, ReactNode } from "react";
interface Props extends ButtonHTMLAttributes<HTMLButtonElement> {
color?: "primary" | "secondary" | "tertiary" | "danger";
size?: "medium" | "small";
icon?: ReactNode;
iconPosition?: "left" | "right";
active?: boolean;
@@ -10,12 +11,13 @@ interface Props extends ButtonHTMLAttributes<HTMLButtonElement> {
export const Button = ({
children,
color = "primary",
size = "medium",
iconPosition = "left",
icon,
active,
...props
}: Props) => {
const classes = ["c__button", "c__button--" + color];
const classes = ["c__button", "c__button--" + color, "c__button--" + size];
if (icon && children) {
classes.push("c__button--with-icon--" + iconPosition);
}

View File

@@ -3,8 +3,10 @@ import { DefaultTokens } from "@openfun/cunningham-tokens";
export const tokens = (defaults: DefaultTokens) => {
return {
"border-radius": "2px",
height: "48px",
"font-size": defaults.theme.font.sizes.l,
"medium-height": "48px",
"small-height": "32px",
"medium-font-size": defaults.theme.font.sizes.l,
"small-font-size": defaults.theme.font.sizes.m,
"font-weight": defaults.theme.font.weights.medium,
};
};