Skip to content

Commit

Permalink
refactor: move styles to external css files (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
daenub authored Dec 6, 2023
1 parent e1baf77 commit 3f16620
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 231 deletions.
83 changes: 4 additions & 79 deletions src/components/checkbox/Checkbox.js
Original file line number Diff line number Diff line change
@@ -1,89 +1,14 @@
import { html, css, LitElement } from "lit"
import { html, LitElement } from "lit"
import { Icon } from "../icon/icon.js"
import { defineElement } from "../../lib/defineElement.js"

import styles from "./checkbox.css"

/**
* @tagname leu-checkbox
*/
export class LeuCheckbox extends LitElement {
static styles = css`
:host {
--checkbox-color: var(--leu-color-black-40);
--checkbox-color-disabled: var(--leu-color-black-20);
--checkbox-color-focus: var(--leu-color-func-cyan);
--checkbox-label-color: var(--leu-color-black-100);
--checkbox-label-color-disabled: var(--checkbox-color-disabled);
--checkbox-tick-color: var(--leu-color-black-0);
--checkbox-font-regular: var(--leu-font-regular);
position: relative;
display: inline-flex;
align-items: flex-start;
gap: 0.5rem;
font-family: var(--checkbox-font-regular);
}
.checkbox {
--_length: 1.5rem;
appearance: none;
cursor: pointer;
width: var(--_length);
height: var(--_length);
margin: 0;
border: 2px solid var(--checkbox-color);
border-radius: 2px;
flex: 1 0 var(--_length);
display: grid;
place-items: center;
}
.checkbox:checked {
background-color: var(--checkbox-color);
}
.checkbox:is(:hover, :checked, :focus) {
--checkbox-color: var(--checkbox-color-focus);
}
.checkbox:focus-visible {
outline: 2px solid var(--checkbox-color-focus);
outline-offset: 2px;
}
.checkbox:disabled {
--checkbox-color: var(--checkbox-color-disabled);
cursor: not-allowed;
}
.label {
cursor: pointer;
color: var(--checkbox-label-color);
font-size: 1rem;
line-height: 1.5;
}
.checkbox:disabled + .label {
--checkbox-label-color: var(--checkbox-label-color-disabled);
cursor: not-allowed;
}
.icon {
position: absolute;
top: 0;
left: 0;
color: var(--checkbox-tick-color);
pointer-events: none;
}
`
static styles = styles

static shadowRootOptions = {
...LitElement.shadowRootOptions,
Expand Down
36 changes: 4 additions & 32 deletions src/components/checkbox/CheckboxGroup.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,14 @@
import { html, css, LitElement } from "lit"
import { html, LitElement } from "lit"
import { classMap } from "lit/directives/class-map.js"
import { defineElement } from "../../lib/defineElement.js"

import styles from "./checkbox-group.css"

/**
* @tagname leu-checkbox-group
*/
export class LeuCheckboxGroup extends LitElement {
static styles = css`
:host {
--group-font-regular: var(--leu-font-regular);
--group-font-black: var(--leu-font-black);
font-family: var(--group-font-regular);
}
.fieldset {
display: flex;
align-items: flex-start;
flex-wrap: wrap;
gap: 0.5rem 1rem;
border: none;
padding: 0;
}
.fieldset--vertical {
flex-direction: column;
gap: 1rem;
}
.legend {
font-family: var(--group-font-black);
font-size: 1.125rem;
line-height: 1.5;
margin-bottom: 0.5rem;
}
`
static styles = styles

static properties = {
orientation: { type: String, reflect: true },
Expand Down
29 changes: 29 additions & 0 deletions src/components/checkbox/checkbox-group.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
:host {
--group-font-regular: var(--leu-font-regular);
--group-font-black: var(--leu-font-black);

font-family: var(--group-font-regular);
}

.fieldset {
display: flex;
align-items: flex-start;
flex-wrap: wrap;
gap: 0.5rem 1rem;

border: none;
padding: 0;
}

.fieldset--vertical {
flex-direction: column;
gap: 1rem;
}

.legend {
font-family: var(--group-font-black);
font-size: 1.125rem;
line-height: 1.5;

margin-bottom: 0.5rem;
}
76 changes: 76 additions & 0 deletions src/components/checkbox/checkbox.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
:host {
--checkbox-color: var(--leu-color-black-40);
--checkbox-color-disabled: var(--leu-color-black-20);
--checkbox-color-focus: var(--leu-color-func-cyan);

--checkbox-label-color: var(--leu-color-black-100);
--checkbox-label-color-disabled: var(--checkbox-color-disabled);

--checkbox-tick-color: var(--leu-color-black-0);

--checkbox-font-regular: var(--leu-font-regular);

position: relative;

display: inline-flex;
align-items: flex-start;
gap: 0.5rem;

font-family: var(--checkbox-font-regular);
}

.checkbox {
--_length: 1.5rem;
appearance: none;
cursor: pointer;

width: var(--_length);
height: var(--_length);
margin: 0;

border: 2px solid var(--checkbox-color);
border-radius: 2px;

flex: 1 0 var(--_length);

display: grid;
place-items: center;
}

.checkbox:checked {
background-color: var(--checkbox-color);
}

.checkbox:is(:hover, :checked, :focus) {
--checkbox-color: var(--checkbox-color-focus);
}

.checkbox:focus-visible {
outline: 2px solid var(--checkbox-color-focus);
outline-offset: 2px;
}

.checkbox:disabled {
--checkbox-color: var(--checkbox-color-disabled);
cursor: not-allowed;
}

.label {
cursor: pointer;
color: var(--checkbox-label-color);
font-size: 1rem;
line-height: 1.5;
}

.checkbox:disabled + .label {
--checkbox-label-color: var(--checkbox-label-color-disabled);
cursor: not-allowed;
}

.icon {
position: absolute;
top: 0;
left: 0;
color: var(--checkbox-tick-color);
pointer-events: none;
}
36 changes: 4 additions & 32 deletions src/components/radio/RadioGroup.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,14 @@
import { html, css, LitElement } from "lit"
import { html, LitElement } from "lit"
import { classMap } from "lit/directives/class-map.js"
import { defineElement } from "../../lib/defineElement.js"

import styles from "./radio-group.css"

/**
* @tagname leu-radio-group
*/
export class LeuRadioGroup extends LitElement {
static styles = css`
:host {
--group-font-regular: var(--leu-font-regular);
--group-font-black: var(--leu-font-black);
font-family: var(--group-font-regular);
}
.fieldset {
display: flex;
align-items: flex-start;
flex-wrap: wrap;
gap: 0.5rem 1rem;
border: none;
padding: 0;
}
.fieldset--vertical {
flex-direction: column;
gap: 1rem;
}
.legend {
font-family: var(--group-font-black);
font-size: 1.125rem;
line-height: 1.5;
margin-bottom: 0.5rem;
}
`
static styles = styles

static properties = {
orientation: { type: String, reflect: true },
Expand Down
29 changes: 29 additions & 0 deletions src/components/radio/radio-group.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
:host {
--group-font-regular: var(--leu-font-regular);
--group-font-black: var(--leu-font-black);

font-family: var(--group-font-regular);
}

.fieldset {
display: flex;
align-items: flex-start;
flex-wrap: wrap;
gap: 0.5rem 1rem;

border: none;
padding: 0;
}

.fieldset--vertical {
flex-direction: column;
gap: 1rem;
}

.legend {
font-family: var(--group-font-black);
font-size: 1.125rem;
line-height: 1.5;

margin-bottom: 0.5rem;
}
Loading

0 comments on commit 3f16620

Please sign in to comment.