Skip to content
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

fix(Radio+Checkbox): use input component #2607

Merged
merged 33 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ccb46c8
fix(Radio): use input component
eirikbacker Oct 11, 2024
1ac4871
Merge branch 'next' into fix/radio-use-input
eirikbacker Oct 16, 2024
551f356
fix: move stack to base.css, use fieldset with aria-readonly
eirikbacker Oct 18, 2024
c12d083
chore: merge in next
eirikbacker Oct 18, 2024
b5f04c1
fix(Checkbox): use input
eirikbacker Oct 18, 2024
8be76de
fix(Checkbox): remove unused code
eirikbacker Oct 18, 2024
1c8d454
fix: undo stack and update input stories
eirikbacker Oct 21, 2024
10044d6
fix: reset card.css
eirikbacker Oct 21, 2024
47a407c
fix: move readonly state
eirikbacker Oct 21, 2024
b42fdc0
fix: radio readonly label cursor
eirikbacker Oct 21, 2024
934af71
fix: cleanup
eirikbacker Oct 21, 2024
0362927
fix: cleanup
eirikbacker Oct 21, 2024
bb9ae47
fix: cleanup
eirikbacker Oct 21, 2024
1ac7b21
fix(Fieldset): readonly based on children
eirikbacker Oct 21, 2024
7e52c9b
fix(Field): toggle disabled label cursor
eirikbacker Oct 21, 2024
4c268ce
fix(Field): readonly label
eirikbacker Oct 21, 2024
ee28840
chore: cleanup
eirikbacker Oct 22, 2024
0a7878b
chore: merge in next
eirikbacker Oct 23, 2024
fe6946b
fix: make label or aria-label required
eirikbacker Oct 23, 2024
93ba836
chore: fix types
eirikbacker Oct 23, 2024
b696164
fix: switch test
eirikbacker Oct 23, 2024
a755af3
Merge branch 'next' into fix/radio-use-input
eirikbacker Oct 23, 2024
99377e3
chore: update theme
eirikbacker Oct 23, 2024
86c4a6d
Merge branch 'next' into fix/radio-use-input
eirikbacker Oct 23, 2024
1fa7d62
fix(Field): no gap if toggle input is only child
eirikbacker Oct 23, 2024
f556a57
Merge branch 'next' into fix/radio-use-input
eirikbacker Oct 23, 2024
250fbae
Merge branch 'next' into fix/radio-use-input
eirikbacker Oct 24, 2024
65d9340
Create shiny-dryers-count.md
eirikbacker Oct 24, 2024
93ad0d8
chore: move css import
eirikbacker Oct 24, 2024
c5489b6
Update shiny-dryers-count.md
eirikbacker Oct 24, 2024
605624c
chore: merge in next
eirikbacker Oct 24, 2024
bc51578
chore: merge in next
eirikbacker Oct 24, 2024
773f24c
chore: lint
eirikbacker Oct 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 15 additions & 25 deletions apps/theme/components/Previews/Components/Components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import { useState } from 'react';
import classes from './Components.module.css';

export const Components = () => {
const [radioValue, setRadioValue] = useState('vanilje');
const [currentPage, setCurrentPage] = useState(1);
const pagination = usePagination({
currentPage,
Expand All @@ -47,21 +46,15 @@ export const Components = () => {
return (
<div className={classes.components}>
<div className={cl(classes.card, classes.checkbox)}>
<Checkbox.Group error='' legend='Handleliste' size='sm'>
<Checkbox value='epost'>En kilo poteter</Checkbox>
<Checkbox value='telefon'>To liter Farris</Checkbox>
<Checkbox value='sms' defaultChecked>
Blomkål
</Checkbox>
<Checkbox value='sms' defaultChecked>
Pizza
</Checkbox>
<Checkbox value='sms' defaultChecked>
Tre liter lettmelk
</Checkbox>
<Checkbox value='sms'>2kg smågodt</Checkbox>
<Checkbox value='sms'>10 poser med Smash</Checkbox>
</Checkbox.Group>
<Fieldset legend='Handleliste' size='sm'>
<Checkbox label='En kilo poteter' value='epost' />
<Checkbox label='To liter Farris' value='telefon' />
<Checkbox label='Blomkål' value='sms' defaultChecked />
<Checkbox label='Pizza' value='sms' defaultChecked />
<Checkbox label='Tre liter lettmelk' value='sms' defaultChecked />
<Checkbox label='2kg smågodt' value='sms' />
<Checkbox label='10 poser med Smash' value='sms' />
</Fieldset>
</div>
<div className={cl(classes.card, classes.user)}>
<Heading className={cl(classes.cardTitle, classes.userTitle)} size='xs'>
Expand Down Expand Up @@ -205,19 +198,16 @@ export const Components = () => {
</div>
</div>
<div className={cl(classes.card, classes.radio)}>
<Radio.Group
error=''
<Fieldset
legend='Hvilken iskremsmak er best?'
description='Velg din favorittsmak'
size='sm'
value={radioValue}
onChange={(e: string) => setRadioValue(e)}
>
<Radio value='vanilje'>Vanilje</Radio>
<Radio value='jordbær'>Jordbær</Radio>
<Radio value='sjokolade'>Sjokolade</Radio>
<Radio value='spiser-ikke-is'>Jeg spiser ikke iskrem</Radio>
</Radio.Group>
<Radio label='Vanile' value='vanilje' />
<Radio label='Jordbær' value='jordbær' defaultChecked />
<Radio label='Sjokolade' value='sjokolade' />
<Radio label='Jeg spiser ikke iskrem' value='spiser-ikke-is' />
</Fieldset>
</div>
<div className={cl(classes.card, classes.tag)}>
<Heading size='xs' className={classes.tagHeading}>
Expand Down
221 changes: 0 additions & 221 deletions packages/css/checkbox.css

This file was deleted.

66 changes: 63 additions & 3 deletions packages/css/field.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,67 @@
.ds-field {
display: contents;
align-items: start;
display: flex;
flex-direction: column;
gap: var(--ds-spacing-2);

& > * + * {
margin-top: var(--ds-spacing-2);
@composes ds-body-text--md from './base/base.css';

&[data-size='sm'] {
@composes ds-body-text--sm from './base/base.css';
}

&[data-size='lg'] {
@composes ds-body-text--lg from './base/base.css';
}

& [data-field='description'] {
color: var(--ds-color-neutral-text-subtle); /* TODO: Change to opacity or color-mix(currentColor, trasparent) to ensure contrast when parent element color changes? */
}

/**
* States
*/
&:has([aria-disabled='true'], :disabled) > * {
cursor: not-allowed;
opacity: var(--ds-disabled-opacity);
}

&:has([aria-readonly='true'], [readonly]) label {
--dsc-label--readonly: ; /* Activate lock icon for label when readonly */
}

/**
* Toggle inputs
*/
&:has(input:is([type='radio'], [type='checkbox'])) {
border-radius: var(--ds-border-radius-md);
display: grid;
grid-template-columns: auto 1fr;
eirikbacker marked this conversation as resolved.
Show resolved Hide resolved
row-gap: 0;
width: fit-content; /* Rather do display: grid + width: fit-content than display: inline-grid to encourage stacked radios */

& > * {
grid-column: 2; /* Only allow input in column 1 */
}

& label {
--dsc-label--readonly: initial; /* Never show lock icon on toggle inputs */
font-weight: var(--ds-font-weight-regular);
}

& input {
grid-column: 1; /* Always place input in column 1 */
grid-row: 1; /* Always place input in row 1 */
outline: none;
box-shadow: none;
}

&:not(:has([readonly], [aria-disabled='true'], :disabled)) label {
cursor: pointer;
}

&:has(:focus-visible) {
@composes ds-focus--visible from './base/base.css';
}
}
}
Loading
Loading