-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin' into link
- Loading branch information
Showing
11 changed files
with
261 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Canvas, Meta, Source, Subtitle, Title } from "@storybook/blocks"; | ||
|
||
import * as stories from "./checkbox.stories"; | ||
|
||
<Meta of={stories} /> | ||
|
||
<Title /> | ||
<Subtitle>The checkbox component is implemented using only CSS.</Subtitle> | ||
|
||
### Default | ||
<Canvas of={stories.Default} /> | ||
|
||
### Checkbox list | ||
If you need a vertical list of checkboxes, you can use the CSS class `.cx-checkbox-list`. | ||
<Canvas of={stories.CheckboxList} /> | ||
|
||
### Indeterminate | ||
A checkbox is displayed as indeterminate if it is put in an indeterminate state. It can also be triggered by applying the CSS class `.cx-checkbox--indeterminate`. | ||
The indeterminate state is not something that is automatically applied to an native checkbox element, and requires use of JavaScript to be toggled. | ||
<Canvas of={stories.Indeterminate} /> | ||
|
||
### Error | ||
A checkbox receives error styling when the input is considered invalid. It can also be triggered by applying the CSS class `.cx-checkbox--invalid`. | ||
<Canvas of={stories.ErrorState} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
label.cx-checkbox { | ||
display: inline-flex; | ||
gap: var(--cx-spacing-2); | ||
align-items: center; | ||
cursor: pointer; | ||
|
||
font-size: 1rem; | ||
font-weight: 400; | ||
color: var(--cx-color-text-primary); | ||
line-height: 1rem; | ||
} | ||
|
||
label.cx-checkbox:is(:hover, :has(:focus-visible)) .cx-checkbox__checkmark { | ||
--cx-gradient-highlight: var(--cx-color-blue); | ||
--cx-gradient-background: var(--cx-color-grey-700); | ||
--border-color: transparent; | ||
} | ||
|
||
label.cx-checkbox:has(:focus-visible) .cx-checkbox__checkmark { | ||
outline: 2px auto var(--cx-color-border-accent-1); | ||
outline-offset: 2px; | ||
} | ||
|
||
label.cx-checkbox:active .cx-checkbox__checkmark { | ||
scale: 0.97; | ||
} | ||
|
||
label.cx-checkbox:has(input:checked) .cx-checkbox__checkmark { | ||
--cx-gradient-highlight: var(--cx-color-background-accent-5); | ||
--cx-gradient-background: var(--cx-color-background-accent-5); | ||
--border-color: transparent; | ||
|
||
&::before, | ||
&::after { | ||
scale: 1; | ||
} | ||
|
||
&::after { | ||
transition-delay: 150ms; | ||
} | ||
} | ||
|
||
label.cx-checkbox:has(input:user-invalid), | ||
label.cx-checkbox.cx-checkbox--invalid { | ||
.cx-checkbox__checkmark { | ||
--border-color: var(--cx-color-signal-danger); | ||
--border-thickness: 2px; | ||
} | ||
|
||
&:hover .cx-checkbox__checkmark { | ||
--border-color: transparent; | ||
} | ||
} | ||
|
||
label.cx-checkbox:has(input:indeterminate), | ||
label.cx-checkbox.cx-checkbox--indeterminate { | ||
.cx-checkbox__checkmark { | ||
--cx-gradient-highlight: var(--cx-color-background-accent-5); | ||
--cx-gradient-background: var(--cx-color-background-accent-5); | ||
--border-color: transparent; | ||
scale: 1; | ||
|
||
&::before, | ||
&::after { | ||
scale: 1; | ||
top: 11px; | ||
rotate: 0deg; | ||
} | ||
|
||
&::before { | ||
left: 6px; | ||
} | ||
|
||
&::after { | ||
left: 7px; | ||
} | ||
} | ||
} | ||
|
||
.cx-checkbox__checkmark { | ||
--border-color: var(--cx-color-border-primary); | ||
--border-thickness: 1px; | ||
|
||
position: relative; | ||
width: var(--cx-spacing-6); | ||
height: var(--cx-spacing-6); | ||
border-radius: var(--cx-spacing-1); | ||
box-shadow: inset 0 0 0 var(--border-thickness) var(--border-color); | ||
background-image: linear-gradient(62deg, var(--cx-gradient-highlight) 5%, var(--cx-gradient-background) 91%); | ||
transition: --cx-gradient-highlight 300ms ease, --cx-gradient-background 300ms ease, box-shadow 300ms ease; | ||
|
||
&::before, | ||
&::after { | ||
content: ""; | ||
position: absolute; | ||
height: 2px; | ||
border-radius: 99px; | ||
background-color: var(--cx-color-text-static-dark); | ||
transition-duration: 200ms; | ||
transition-timing-function: var(--ease-4); | ||
transition-property: scale, rotate, left, top; | ||
transform-origin: left center; | ||
scale: 0 1; | ||
} | ||
|
||
&::before { | ||
width: 6px; | ||
rotate: 45deg; | ||
top: 11px; | ||
left: 7px; | ||
transition-delay: 100ms; | ||
} | ||
|
||
&::after { | ||
width: 11px; | ||
rotate: -45deg; | ||
top: 15px; | ||
left: 10px; | ||
} | ||
} | ||
|
||
label.cx-checkbox input[type="checkbox"] { | ||
clip: rect(0 0 0 0); | ||
clip-path: inset(50%); | ||
height: 1px; | ||
overflow: hidden; | ||
position: absolute; | ||
white-space: nowrap; | ||
width: 1px; | ||
} | ||
|
||
.cx-checkbox-list { | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--cx-spacing-2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import type { Meta, StoryObj } from '@storybook/web-components'; | ||
import { html } from 'lit'; | ||
|
||
export default { | ||
title: 'Components/Checkbox', | ||
} satisfies Meta; | ||
|
||
export const Default: StoryObj = { | ||
render: () => html` | ||
<label class="cx-checkbox"> | ||
<input type="checkbox" /> | ||
<div class="cx-checkbox__checkmark"></div> | ||
Check me | ||
</label> | ||
`, | ||
}; | ||
|
||
export const CheckboxList: StoryObj = { | ||
render: () => html` | ||
<fieldset class="cx-checkbox-list"> | ||
<label class="cx-checkbox"> | ||
<input type="checkbox" /> | ||
<div class="cx-checkbox__checkmark"></div> | ||
Checkbox no 1 | ||
</label> | ||
<label class="cx-checkbox"> | ||
<input type="checkbox" /> | ||
<div class="cx-checkbox__checkmark"></div> | ||
Checkbox no 2 | ||
</label> | ||
<label class="cx-checkbox"> | ||
<input type="checkbox" /> | ||
<div class="cx-checkbox__checkmark"></div> | ||
Checkbox no 3 | ||
</label> | ||
</fieldset> | ||
`, | ||
}; | ||
|
||
export const Indeterminate: StoryObj = { | ||
render: () => html` | ||
<label class="cx-checkbox cx-checkbox--indeterminate"> | ||
<input type="checkbox" /> | ||
<div class="cx-checkbox__checkmark"></div> | ||
Check me | ||
</label> | ||
`, | ||
}; | ||
|
||
export const ErrorState: StoryObj = { | ||
render: () => html` | ||
<label class="cx-checkbox cx-checkbox--invalid"> | ||
<input type="checkbox" /> | ||
<div class="cx-checkbox__checkmark"></div> | ||
Check me | ||
</label> | ||
`, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters