-
Notifications
You must be signed in to change notification settings - Fork 0
Implement checkbox #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
df93ecc
feat(checkbox): initial implementation
eTallang ea1517c
fix(checkbox): incorrect hover style when in error state
eTallang 6803b61
chore(checkbox): remove web component implementation
eTallang 4b90e57
chore(tabs): reorder props
eTallang fe8232a
fix(checkbox): invalid import
eTallang 0ec336b
Merge branch 'main' into implement-checkbox
eTallang a98154c
chore: updated changelog
eTallang 0001d0a
chore(checkbox): improve docs
eTallang 228f37e
docs(changelog): add alert-component
eTallang 08d9fb6
feat(checkbox): add cx-checkbox-list class
eTallang 2ced32c
docs(checkbox): add comment about indeterminate needing to be toggled…
eTallang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
### 0.0.7 - 19.12.2024 | ||
# 0.0.8 - 19.12.2024 | ||
- Lagt til checkbox-komponent | ||
- Lagt til alert-komponent | ||
|
||
# 0.0.7 - 19.12.2024 | ||
- Importert alle ikoner fra figma på nytt for å fikse padding i ikon-problem | ||
- Lagt til 3 nye ikoner (check-circle-filled, person-card og chat-add) | ||
- Lagt til støtte for accent-color i ikoner |
This file contains hidden or 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 hidden or 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 { | ||
eTallang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--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 hidden or 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; | ||
|
||
eTallang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.