Skip to content

Commit

Permalink
feat(buttons): variants
Browse files Browse the repository at this point in the history
  • Loading branch information
Neox63 committed Jun 26, 2024
1 parent 109428f commit 88c95e7
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 51 deletions.
42 changes: 24 additions & 18 deletions components/Molecules/Button/Button.stories.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
import Button from './Button.twig';
import Compact from './Classic.twig';

export default {
title: 'Design System/Molecules/Button'
};

export const base = {
render: (args) => Button(args),
const types = ['primary', 'secondary', 'tertiary', 'destructive'];
const icons = ['copy', 'eye', 'edit', 'close'];

export const classic = {
render: (args) => Compact(args),
args: {
text: 'Button',
level: 'primary',
href: '#',
target: '_self',
type: 'button',
tag: 'button'
customText: 'Button',
variant: 'primary',
icon_left: 'none',
icon_right: 'none'
},

argTypes: {
text: { control: 'text' },
level: {
control: 'select',
options: ['primary', 'secondary', 'link', 'small']
variant: {
options: types,
control: { type: 'radio' }
},
icon_left: {
options: ['none', ...icons],
control: { type: 'radio' }
},
icon_right: {
options: ['none', ...icons],
control: { type: 'radio' }
},
href: { control: 'text' },
target: { control: 'select', options: ['_self', '_blank'] },
type: { control: 'select', options: ['button', 'submit', 'reset'] },
tag: { control: 'select', options: ['button', 'a'] }
href: {
control: { type: 'text' }
}
}
};
29 changes: 12 additions & 17 deletions components/Molecules/Button/Button.twig
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
{% set tag = tag|default('a') %}
{% set classes = 'Button' %}
{% set classes = classes|default('') %}
{% if variant %}{% set classes = classes ~ ' Button--' ~ variant %}{% endif %}
{% set tag = 'button' %}
{% if href %}{% set tag = 'a' %}{% endif %}

{% if level is defined %}
{% set classes = classes ~ ' Button--' ~ level %}
{% endif %}

{% if class is defined %}
{% set classes = classes ~ ' ' ~ class %}
{% endif %}

<{{ tag }}
class="{{ classes }}"
{% if href is defined %}href="{{ href }}"{% endif %}
{% if target is defined %}target="{{ target }}"{% endif %}
{% if type is defined and type == 'submit' %}type="submit"{% endif %}
>
{{ text }}
<{{ tag }} class='Button {{ classes }}' {% if disabled %}disabled{% endif %} {% if href %}href='{{ href }}'{% else %}type='{{ type|default('button') }}'{% endif %}>
{% if icon_left %}
<span class='icon icon-left'>{{ source("/icons/"~ icon_left ~".svg") }}</span>
{% endif %}
{{ text|striptags('<span>')|raw }}
{% if icon_right %}
<span class='icon icon-right'>{{ source("/icons/"~ icon_right ~".svg") }}</span>
{% endif %}
</{{ tag }}>
34 changes: 34 additions & 0 deletions components/Molecules/Button/Classic.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% set iconLeft = icon_left == 'none' ? '' : icon_left %}
{% set iconRight = icon_right == 'none' ? '' : icon_right %}

<div class="mb-8">
<div class='h4-desktop mb-5'>XL</div>
<div class='flex gap-4'>
{% include './Button.twig' with {disabled: false, classes: 'Button--xl', variant: variant, text: customText, icon_left: iconLeft, icon_right: iconRight} %}
{% include './Button.twig' with {disabled: true, classes: 'Button--xl', variant: variant, text: customText, icon_left: iconLeft, icon_right: iconRight} %}
</div>
</div>

<div class="mb-8">
<div class='h4-desktop mb-5'>Large</div>
<div class='flex gap-4'>
{% include './Button.twig' with {disabled: false, classes: 'Button--large', variant: variant, text: customText, icon_left: iconLeft, icon_right: iconRight} %}
{% include './Button.twig' with {disabled: true, classes: 'Button--large', variant: variant, text: customText, icon_left: iconLeft, icon_right: iconRight} %}
</div>
</div>

<div class="mb-8">
<div class='h4-desktop my-5'>Medium</div>
<div class='flex gap-4'>
{% include './Button.twig' with {disabled: false, classes: 'Button--medium', variant: variant, text: customText, icon_left: iconLeft, icon_right: iconRight} %}
{% include './Button.twig' with {disabled: true, classes: 'Button--medium', text:customText, icon_left: iconLeft, icon_right: iconRight} %}
</div>
</div>

<div class="mb-8">
<div class='h4-desktop my-5'>Small</div>
<div class='flex gap-4'>
{% include './Button.twig' with {disabled: false, classes: 'Button--small', variant: variant, text: customText, icon_left: iconLeft, icon_right: iconRight} %}
{% include './Button.twig' with {disabled: true, classes: 'Button--small', variant: variant, text: customText, icon_left: iconLeft, icon_right: iconRight} %}
</div>
</div>
120 changes: 110 additions & 10 deletions components/Molecules/Button/button.css
Original file line number Diff line number Diff line change
@@ -1,25 +1,125 @@
.Button {
@apply font-medium;
display: inline-flex;
padding: rem-convert(12px) rem-convert(24px);
align-items: center;
justify-content: center;
border-radius: rem-convert(8px);
background: var(--black);
color: var(--white);
text-align: center;
text-transform: uppercase;
kerning: 5%;
font-size: var(--font-size-button-large);
font-family: var(--font-family-button-large);
font-weight: var(--font-weight-button-large);
line-height: var(--line-height-button-large);

cursor: pointer;
text-decoration: none;

& > span.icon {
@apply w-5 h-5;
&-left {
padding-right: rem-convert(6px);
}
&-right {
padding-left: rem-convert(6px);
}
}

&--xl {
width: 100%;
}

&--large,
&--xl {
padding: 16px 24px;
}

&--medium {
padding: 8px 16px;
}

&--small {
padding: 8px;
font-size: var(--font-size-button-small);
font-family: var(--font-family-button-small);
font-weight: var(--font-weight-button-small);
line-height: var(--line-height-button-small);
}

&--primary {
@apply bg-vermillon-light hover:bg-vermillon-light text-gray-200 rounded-lg shadow-lg p-3;
background: var(--black);
color: var(--white);

&:hover {
background: var(--grey-dark);
}

&:disabled {
background: var(--grey-lighter);
color: var(--white);
}

&:focus-visible {
outline: 2px solid var(--vermillon-medium);
}
}

&--secondary {
@apply bg-transparent hover:bg-vermillon-light border-vermillon-light border-2 text-gray-200 rounded-lg shadow-lg p-3;
background: var(--white);
color: var(--black);
border: 1px solid var(--black);

&:hover {
border-color: var(--grey-dark);
color: var(--grey-dark);
}

&:disabled {
border-color: var(--grey-lighter);
color: var(--grey-lighter);
}

&:focus-visible {
outline: 2px solid var(--vermillon-medium);
}
}

&--link {
@apply text-vermillon-light;
&--tertiary {
background: none;
color: var(--black);

&:hover {
color: var(--grey-dark);
}

&:disabled {
background: var(--white);
color: var(--grey-lighter);
}

&:focus-visible {
outline: none;
background: var(--vermillon-lightest);
}
}

&--small {
&-primary {
@apply bg-vermillon-light hover:bg-vermillon-light p-4 flex items-center justify-center text-gray-200 rounded-full;
&--destructive {
background: var(--error);
color: var(--white);

&:hover {
background: var(--error-dark);
}

&:disabled {
background: var(--error-lightest);
color: var(--white);
}

&-secondary {
@apply flex items-center justify-center w-10 h-10 p-4 font-medium rounded-full bg-grey-medium hover:bg-charcoal-medium hover:text-grey-medium text-charcoal-medium;
&:focus-visible {
outline: 2px solid var(--error-darkest);
}
}
}
13 changes: 7 additions & 6 deletions components/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,14 @@
--font-family-paragraph-6: 'Roboto Condensed';
--font-family-paragraph-7: 'Roboto Condensed';

--font-size-button-large: var(--font-size-sm);
--font-size-button-medium: var(--font-size-xs);
--font-size-button-small: var(--font-size-2xs);
--font-size-button-large: rem-convert(14px);
--font-size-button-small: rem-convert(12px);

--font-weight-button-large: 500;
--font-weight-button-medium: 500;
--font-weight-button-small: 400;
--line-height-button-large: rem-convert(19px);
--line-height-button-small: rem-convert(16px);

--font-weight-button-large: 600;
--font-weight-button-small: 600;

--font-family-button-large: 'Poppins';
--font-family-button-medium: 'Poppins';
Expand Down

0 comments on commit 88c95e7

Please sign in to comment.