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

feat(styles): implemented radio-button styles using tokens #3803

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/dirty-squids-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/design-system-styles': minor
---

Updated radio-button styles with Design Tokens.
5 changes: 5 additions & 0 deletions .changeset/slimy-singers-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/design-system-documentation': minor
---

Removed unnecessary classes from radio-button markup.
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ Our radios use custom icons to indicate checked states.

The following examples show the different characteristics of the component. These can differ in the type of visualization, the HTML structure, as well as when, how and why they are displayed.

### Sizing

The size can be changed by simply adding a class:

- Small: `.form-check-sm`
- Large: default

<Canvas of={RadioStories.Size} />

### Inline

To render a radio inline, simply add the class `.form-check-inline` to the `.form-check` wrapper element.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Args, StoryContext, StoryObj } from '@storybook/web-components';
import { useArgs } from '@storybook/preview-api';
import { html, nothing, TemplateResult } from 'lit';
import { MetaComponent } from '@root/types';
import { ifDefined } from 'lit/directives/if-defined.js';

const VALIDATION_STATE_MAP: Record<string, undefined | boolean> = {
'null': undefined,
Expand Down Expand Up @@ -74,21 +75,6 @@ const meta: MetaComponent = {
category: 'States',
},
},
size: {
name: 'Size',
description: "Sets the size of the component's appearance.",
control: {
type: 'select',
labels: {
'form-check-sm': 'Small',
'null': 'Large',
},
},
options: ['form-check-sm', 'null'],
table: {
category: 'General',
},
},
disabled: {
name: 'Disabled',
description:
Expand Down Expand Up @@ -124,12 +110,13 @@ function render(args: Args, context: StoryContext) {
const [_, updateArgs] = useArgs();

const id = context.id ?? `${context.viewMode}_${context.name.replace(/\s/g, '-')}_ExampleRadio`;
const classes = ['form-check-input', args.validation].filter(c => c && c !== 'null').join(' ');
const classes = args.validation !== 'null' ? `is-${args.validation}` : undefined;

const groupClasses = ['form-check', args.size].filter(c => c && c !== 'null').join(' ');

const useAriaLabel = args.hiddenLabel;
const label: TemplateResult | null = !useAriaLabel
? html` <label for="${id}" class="form-check-label">${args.label}</label> `
? html` <label for="${id}">${args.label}</label> `
: null;

const contextual: (TemplateResult | null)[] = [
Expand All @@ -140,7 +127,7 @@ function render(args: Args, context: StoryContext) {
const control = html`
<input
id="${id}"
class="${classes}"
class="${ifDefined(classes)}"
type="radio"
?checked="${args.checked}"
.checked="${args.checked}"
Expand Down Expand Up @@ -233,14 +220,6 @@ export function renderInline(args: Args, context: Partial<StoryContext>) {
`;
}

export const Size: Story = {
render,
args: {
size: 'form-check-sm',
checkedRadio: null,
},
};

export const Inline: Story = {
render: renderInline,
parameters: {
Expand Down
71 changes: 71 additions & 0 deletions packages/styles/src/components/_form-check.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
@forward './../variables/options';

@use '../variables/color';
@use '../variables/commons';
@use '../variables/type';
@use '../variables/spacing';
@use '../variables/animation';
@use '../variables/components/form-check';
@use '../mixins/color' as color-mx;
@use '../mixins/icons' as icons-mx;
@use '../mixins/utilities' as utility-mx;
@use '../tokens/helpers';
@use '../functions/tokens';

.form-check {
display: flex;
flex-wrap: wrap;
align-items: flex-start;
width: fit-content;
border-radius: tokens.get('focus-border-radius', helpers.$post-focus);

&-inline {
display: inline-flex;
vertical-align: top;

&:not(:last-of-type) {
margin-right: form-check.$form-check-inline-margin-right;
}
}

> input,
> label {
transition: color #{animation.$transition-base-timing};

@include utility-mx.high-contrast-mode {
transition: none;
}
}

> input {
&:not([disabled]),
&:not([disabled]) ~ .form-check-label {
cursor: pointer;
}

@include utility-mx.focus-style-none();
display: inline-flex;
flex: 0 auto;
appearance: none;
background: transparent;

@include utility-mx.high-contrast-mode {
border-color: FieldText;
}

&::after {
content: '';
display: block;
}

// Shared disabled styles
&[disabled] {
&[type='checkbox'],
&[type='radio'] {
@include utility-mx.high-contrast-mode {
border-color: GrayText !important;
}
}
}
}
}
1 change: 1 addition & 0 deletions packages/styles/src/components/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@use 'datatable';
@use 'dialog';
@use 'form-check';
@use 'radio-button';
@use 'forms';
@use 'grid';
@use 'icon-button';
Expand Down
Loading