Skip to content

Commit

Permalink
feat/(form)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordi hermes babalako committed Jun 24, 2024
1 parent 94891f6 commit 3789c4b
Show file tree
Hide file tree
Showing 11 changed files with 324 additions and 3 deletions.
2 changes: 1 addition & 1 deletion assets/icons/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions components/Atoms/Form/Checkbox.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<label class="Checkbox {{ classes|default('') }} {{ error ? 'error' : ''}}">
<input type="checkbox"
name='{{ name }}'
value='{{ value }}'
{% if disabled %}disabled{% endif %}
{% if checked %}checked{% endif %}
>
<div class="flex items-center justify-center checkmark">
<span class="w-[10px] h-[10px] text-white">{{ source("/icons/check.svg") }}</span>
</div>
<span>{{ label }}</span>
</label>
7 changes: 7 additions & 0 deletions components/Atoms/Form/Checkboxs.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div>
{% include './Checkbox.twig' with {label: 'Unchecked',disabled: disabled, error:error} %}
{% include './Checkbox.twig' with {label: 'Checked',disabled: disabled, error:error, checked:true} %}
{% include './Checkbox.twig' with
{label: 'Undefined',disabled: disabled, error:error, classes:'indeterminate'}
%}
</div>
53 changes: 53 additions & 0 deletions components/Atoms/Form/Form.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import Checkbox from './Checkboxs.twig';
import Radio from './Radios.twig';
import Toggle from './Toggles.twig';
import './checkbox.css';
import './toggle.css';

export default {
title: 'Design System/Atoms/Form'
};

const commonProps = {
args: {
error: false,
disabled: false
},
argTypes: {
error: {
control: { type: 'boolean' }
},
disabled: {
control: { type: 'boolean' }
}
}
};

export const checkbox = {
render: (args) => Checkbox(args),

play: ({ canvasElement, ...props }) => {
const checkbox = canvasElement.querySelector(
'.Checkbox.indeterminate input'
);
checkbox.indeterminate = true;
},
...commonProps
};

export const radio = {
render: (args) => Radio(args),
...commonProps
};

export const toggle = {
render: (args) => Toggle(args),
args: {
disabled: false
},
argTypes: {
disabled: {
control: { type: 'boolean' }
}
}
};
13 changes: 13 additions & 0 deletions components/Atoms/Form/Radio.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% set type = type|default('label') %}
<{{ type }} class="Radio {{ classes|default('') }} {{ error|default(0) ? 'error' : ''}}">
<input
type="radio"
name='{{ name }}'
value='{{ value|default('') }}'
{% if id %}id='{{ id }}'{% endif %}
{% if disabled %}disabled{% endif %}
{% if checked %}checked{% endif %}
>
<span class="checkmark"></span>
<span>{{ label }}</span>
</{{ type }}>
5 changes: 5 additions & 0 deletions components/Atoms/Form/Radios.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
{% include './Radio.twig' with {label: 'Radio 1', name: 'radio',disabled: disabled, error:error} %}
{% include './Radio.twig' with {label: 'Radio 2', name: 'radio',disabled: disabled, error:error, checked:true} %}
{% include './Radio.twig' with {label: 'Radio 3', name: 'radio',disabled: disabled, error:error} %}
</div>
18 changes: 18 additions & 0 deletions components/Atoms/Form/Toggle.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<label class="ToggleButton {{ classes|default('') }} {{ error ? 'error' : ''}}">
<input type="checkbox"
name='{{ name }}'
value='{{ value }}'
tabindex="-1"
{% if disabled %}disabled{% endif %}
{% if checked %}checked{% endif %}
>
{% if labelOff %}
<span class="ToggleButton-uncheckedLabel">{{ labelOff }}</span>
{% endif %}
<span class="ToggleButton-wrapper" tabindex="0">
<span></span>
</span>
{% if labelOn %}
<span class="ToggleButton-checkedLabel">{{ labelOn }}</span>
{% endif %}
</label>
4 changes: 4 additions & 0 deletions components/Atoms/Form/Toggles.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% include './Toggle.twig' with {labelOff: 'Off', labelOn: 'On',disabled: disabled, error:error} %}
<div class="mt-5">
{% include './Toggle.twig' with {disabled: disabled, error:error, checked:true} %}
</div>
124 changes: 124 additions & 0 deletions components/Atoms/Form/checkbox.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
.Checkbox, .Radio {
display: flex;
align-items: center;
position: relative;
cursor: pointer;
gap: 0.5rem;
--current-checkbox-color: var(--black);
--current-checkbox-hover: var(--grey-dark);
--current-checkbox-disabled: var(--grey-lighter);
--checkbox-focus: var(--vermillon);
&.error {
--current-checkbox-color: var(--error-dark);
--current-checkbox-hover: var(--error-darkest);
--checkbox-focus: var(--error);
}
input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;

&:focus-visible{
& ~ .checkmark {
outline: var(--checkbox-focus) solid 1px;
outline-offset: 1px;
}
}
}
.checkmark {
width: 16px;
height: 16px;
background: var(--white);
border: 1px solid var(--current-checkbox-color);
border-radius: 2px;
position: relative;
span {
display: none;
}
}
input:disabled ~ .checkmark {
border: 1px solid var(--current-checkbox-disabled);
}

&:hover input:not(:disabled) {
& ~ .checkmark {
border: 1px solid var(--current-checkbox-hover);
}
&:indeterminate ~ .checkmark {
background-color: var(--grey-lightest);
&:after {
background: var(--current-checkbox-hover);
}
}
}
}

.Checkbox {
input {
&:indeterminate {
~ .checkmark {
&:after {
content: "";
position: absolute;
width: 8px;
height: 2px;
left: 3px;
top: 6px;
background: var(--current-checkbox-color);
}
}
&:disabled {
& ~ .checkmark:after {
background: var(--current-checkbox-disabled);
}
}
}
&:checked {
& ~ .checkmark {
background-color: var(--current-checkbox-color);
span {
display: block;
}
}
&:disabled {
& ~ .checkmark {
background-color: var(--current-checkbox-disabled);
}
}
}
}
&:hover input:not(:disabled) {
&:checked ~ .checkmark {
background-color: var(--current-checkbox-hover);
}
}
}

.Radio {
.checkmark {
border-radius: 555rem;
width: 14px;
height: 14px;
}
input {
&:checked {
& ~ .checkmark:after {
content: "";
position: absolute;
border-radius: 555rem;
top:2px;
bottom:2px;
left:2px;
right:2px;
background-color: var(--current-checkbox-color);
}
}
&:disabled {
& ~ .checkmark:after {
background: var(--current-checkbox-disabled);
}
}
}
}
74 changes: 74 additions & 0 deletions components/Atoms/Form/toggle.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
.ToggleButton {
--on-color: var(--black);
--off-color: var(--grey);
--on-color-hover: var(--grey-dark);
--off-color-hover: var(--black);
--color-disabled: var(--grey-lighter);
--checkbox-focus: var(--vermillon)

display: flex;
align-items: center;
cursor: pointer;
gap: 0.5rem;
&-wrapper {
background: var(--off-color);
width: 25px;
height: 14px;
position: relative;
display: inline-flex;
align-items: center;
flex-shrink: 0;
border-color: transparent;
@apply rounded-full transition-colors duration-200 ease-in-out;
span {
width: 10px;
height: 10px;
display: inline-block;
background: var(--white);
@apply translate-x-[0.1rem];
@apply rounded-full transition duration-200 ease-in-out;
}
}
input {
position: absolute;
opacity: 0;
height: 0;
width: 0;
}
input:checked {
& ~ .ToggleButton {
&-wrapper {
background: var(--on-color);
span {
@apply translate-x-[0.8rem];
}
}
}
}
input:focus-visible{
& ~ .ToggleButton-wrapper {
outline: var(--checkbox-focus) solid 1px;
outline-offset: 1px;
}
}
input:disabled {
& ~ .ToggleButton-wrapper {
background: var(--color-disabled);
}
}
&:hover {
.ToggleButton-wrapper {
background: var(--off-color-hover);
}
input:checked {
& ~ .ToggleButton-wrapper {
background: var(--on-color-hover);
}
}
}
}

.ToggleButton-wrapper:focus-visible {
outline: var(--vermillon) solid 1px;
outline-offset: 1px;
}
15 changes: 13 additions & 2 deletions components/variables.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
:root {
--vermillon: #FF7036;
--vermillon-light: #fa533c;
--vermillon-lighter: #ff8f80;
--vermillon-lightest: #ffeaf8;
Expand All @@ -11,15 +12,25 @@
--pearl-light: #f5f5f5;
--pearl-medium: #ebebeb;

--grey-medium: #9b9b9b;
--grey-dark: #787878;
--grey-darker: #424242;
--grey-dark: #545454;
--grey: #808080;
--grey-lighter: #D6D6D6;
--grey-lightest: #F5F5F5;

--black: #282828;
--white: #ffffff;

--red-light: #ed5656;
--red: #d21919;
--background-red: #ffeded;

--error-darkest: #B70101;
--error-dark: #D00000;
--error: #EB0000;
--error-light: #FF6666;
--error-lightest: #FFE1E1;

--green-light: #eafbf5;
--green-dark: #008958;

Expand Down

0 comments on commit 3789c4b

Please sign in to comment.