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(sbb-checkbox): add size xs #2933

Merged
merged 9 commits into from
Jul 16, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ const size: InputType = {
control: {
type: 'inline-radio',
},
options: ['m', 's'],
options: ['m', 's', 'xs'],
table: {
category: 'Checkbox group',
},
Expand Down Expand Up @@ -359,6 +359,12 @@ export const horizontalSizeM: StoryObj = {
args: { ...checkboxArgs, size: 'm' },
};

export const horizontalSizeXS: StoryObj = {
render: DefaultTemplate,
argTypes: checkboxArgTypes,
args: { ...checkboxArgs, size: 'xs' },
};

export const horizontalDisabled: StoryObj = {
render: DefaultTemplate,
argTypes: checkboxArgTypes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ describe('sbb-checkbox-group', () => {
}),
);

it(
`${orientation} size=xs ${visualDiffDefault.name}`,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(checkboxesTemplate({ ...args, size: 'xs' }));
}),
);

it(
`${orientation} disabled ${visualDiffDefault.name}`,
visualDiffDefault.with(async (setup) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ snapshots["sbb-checkbox-panel renders unchecked Shadow DOM"] =
<span class="sbb-checkbox">
<span class="sbb-checkbox__inner">
<span class="sbb-checkbox__aligner">
<sbb-visual-checkbox>
<sbb-visual-checkbox size="m">
</sbb-visual-checkbox>
</span>
<span class="sbb-checkbox__label">
Expand Down Expand Up @@ -75,7 +75,10 @@ snapshots["sbb-checkbox-panel renders checked Shadow DOM"] =
<span class="sbb-checkbox">
<span class="sbb-checkbox__inner">
<span class="sbb-checkbox__aligner">
<sbb-visual-checkbox checked="">
<sbb-visual-checkbox
checked=""
size="m"
>
</sbb-visual-checkbox>
</span>
<span class="sbb-checkbox__label">
Expand Down Expand Up @@ -121,7 +124,10 @@ snapshots["sbb-checkbox-panel renders indeterminate Shadow DOM"] =
<span class="sbb-checkbox">
<span class="sbb-checkbox__inner">
<span class="sbb-checkbox__aligner">
<sbb-visual-checkbox indeterminate="">
<sbb-visual-checkbox
indeterminate=""
size="m"
>
</sbb-visual-checkbox>
</span>
<span class="sbb-checkbox__label">
Expand Down Expand Up @@ -167,7 +173,10 @@ snapshots["sbb-checkbox-panel renders unchecked disabled Shadow DOM"] =
<span class="sbb-checkbox">
<span class="sbb-checkbox__inner">
<span class="sbb-checkbox__aligner">
<sbb-visual-checkbox disabled="">
<sbb-visual-checkbox
disabled=""
size="m"
>
</sbb-visual-checkbox>
</span>
<span class="sbb-checkbox__label">
Expand Down
19 changes: 17 additions & 2 deletions src/elements/checkbox/checkbox-panel/checkbox-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
type PropertyValues,
type TemplateResult,
} from 'lit';
import { customElement } from 'lit/decorators.js';
import { customElement, property } from 'lit/decorators.js';

import { slotState } from '../../core/decorators.js';
import { EventEmitter } from '../../core/eventing.js';
Expand All @@ -15,7 +15,12 @@ import type {
SbbDisabledStateChange,
SbbStateChange,
} from '../../core/interfaces/types.js';
import { panelCommonStyle, SbbPanelMixin, SbbUpdateSchedulerMixin } from '../../core/mixins.js';
import {
panelCommonStyle,
SbbPanelMixin,
type SbbPanelSize,
SbbUpdateSchedulerMixin,
} from '../../core/mixins.js';
import { checkboxCommonStyle, SbbCheckboxCommonElementMixin } from '../common.js';

import '../../screen-reader-only.js';
Expand Down Expand Up @@ -51,6 +56,16 @@ export class SbbCheckboxPanelElement extends SbbPanelMixin(
panelConnected: 'panelConnected',
} as const;

/** Size variant. */
@property({ reflect: true })
public set size(value: SbbPanelSize) {
this._size = value;
}
public get size(): SbbPanelSize {
return this.group?.size ? (this.group.size === 'xs' ? 's' : this.group.size) : this._size;
}
private _size: SbbPanelSize = 'm';

/**
* @internal
* Internal event that emits whenever the state of the checkbox
Expand Down
10 changes: 9 additions & 1 deletion src/elements/checkbox/checkbox-panel/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ The component's label can be displayed in bold using the `sbb-text--bold` class
</sbb-checkbox-panel>
```

The component has two `size`, named `s` and `m` (default).
If the component is used within a group, the size is inherited from it;
since the `sbb-checkbox-group` has also `xs` size, this case will fall back to `s`.

```html
<sbb-checkbox-panel size="s"> Size </sbb-checkbox-panel>
```

## Events

Consumers can listen to the native `change` event on the `sbb-checkbox-panel` component to intercept the input's change;
Expand Down Expand Up @@ -78,7 +86,7 @@ If you don't want the label to appear next to the checkbox, you can use `aria-la
| `indeterminate` | `indeterminate` | public | `boolean` | `false` | Whether the checkbox is indeterminate. |
| `name` | `name` | public | `string` | | Name of the form element. Will be read from name attribute. |
| `required` | `required` | public | `boolean` | `false` | Whether the component is required. |
| `size` | `size` | public | `SbbCheckboxSize` | `'m'` | Label size variant, either m or s. |
| `size` | `size` | public | `SbbPanelSize` | `'m'` | Size variant. |
| `value` | `value` | public | `string \| null` | `null` | Value of the form element. |

## Events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ snapshots["sbb-checkbox should render unchecked Shadow DOM"] =
<span class="sbb-checkbox">
<span class="sbb-checkbox__inner">
<span class="sbb-checkbox__aligner">
<sbb-visual-checkbox>
<sbb-visual-checkbox size="m">
</sbb-visual-checkbox>
</span>
<span class="sbb-checkbox__label">
Expand Down Expand Up @@ -53,7 +53,10 @@ snapshots["sbb-checkbox should render checked Shadow DOM"] =
<span class="sbb-checkbox">
<span class="sbb-checkbox__inner">
<span class="sbb-checkbox__aligner">
<sbb-visual-checkbox checked="">
<sbb-visual-checkbox
checked=""
size="m"
>
</sbb-visual-checkbox>
</span>
<span class="sbb-checkbox__label">
Expand Down Expand Up @@ -88,7 +91,10 @@ snapshots["sbb-checkbox should render indeterminate Shadow DOM"] =
<span class="sbb-checkbox">
<span class="sbb-checkbox__inner">
<span class="sbb-checkbox__aligner">
<sbb-visual-checkbox indeterminate="">
<sbb-visual-checkbox
indeterminate=""
size="m"
>
</sbb-visual-checkbox>
</span>
<span class="sbb-checkbox__label">
Expand Down Expand Up @@ -123,7 +129,10 @@ snapshots["sbb-checkbox should render unchecked disabled Shadow DOM"] =
<span class="sbb-checkbox">
<span class="sbb-checkbox__inner">
<span class="sbb-checkbox__aligner">
<sbb-visual-checkbox disabled="">
<sbb-visual-checkbox
disabled=""
size="m"
>
</sbb-visual-checkbox>
</span>
<span class="sbb-checkbox__label">
Expand Down
7 changes: 6 additions & 1 deletion src/elements/checkbox/checkbox/checkbox.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const size: InputType = {
control: {
type: 'inline-radio',
},
options: ['m', 's'],
options: ['m', 's', 'xs'],
};

const checked: InputType = {
Expand Down Expand Up @@ -173,6 +173,11 @@ export const sizeM: StoryObj = {
argTypes: defaultArgTypes,
args: { ...defaultArgs, size: size.options![0] },
};
export const sizeXS: StoryObj = {
render: Template,
argTypes: defaultArgTypes,
args: { ...defaultArgs, size: size.options![2] },
};
export const longLabel: StoryObj = {
render: Template,
argTypes: defaultArgTypes,
Expand Down
17 changes: 16 additions & 1 deletion src/elements/checkbox/checkbox/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { customElement, property } from 'lit/decorators.js';
import { slotState } from '../../core/decorators.js';
import type { SbbIconPlacement } from '../../core/interfaces.js';
import { SbbIconNameMixin } from '../../icon.js';
import { SbbCheckboxCommonElementMixin, checkboxCommonStyle } from '../common.js';
import {
SbbCheckboxCommonElementMixin,
checkboxCommonStyle,
type SbbCheckboxSize,
} from '../common.js';

import checkboxStyle from './checkbox.scss?lit&inline';

Expand All @@ -30,6 +34,16 @@ export class SbbCheckboxElement extends SbbCheckboxCommonElementMixin(
didChange: 'didChange',
} as const;

/** Size variant. */
@property({ reflect: true })
public set size(value: SbbCheckboxSize) {
this._size = value;
}
public get size(): SbbCheckboxSize {
return this.group?.size ?? this._size;
}
private _size: SbbCheckboxSize = 'm';

/** The label position relative to the labelIcon. Defaults to end */
@property({ attribute: 'icon-placement', reflect: true })
public iconPlacement: SbbIconPlacement = 'end';
Expand All @@ -44,6 +58,7 @@ export class SbbCheckboxElement extends SbbCheckboxCommonElementMixin(
?checked=${this.checked}
?indeterminate=${this.indeterminate}
?disabled=${this.disabled || this.formDisabled}
size=${this.size}
></sbb-visual-checkbox>
</span>
<span class="sbb-checkbox__label">
Expand Down
7 changes: 7 additions & 0 deletions src/elements/checkbox/checkbox/checkbox.visual.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ describe('sbb-checkbox', () => {
}),
);

it(
`${state} size=xs`,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(template({ ...defaultArgs, size: 'xs' }));
}),
);

for (const iconPlacement of ['start', 'end']) {
it(
`${state} iconPlacement=${iconPlacement}`,
Expand Down
8 changes: 5 additions & 3 deletions src/elements/checkbox/checkbox/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ The component can be displayed in `disabled` or `required` state by using the se

## Style

The component has two `size`, named `s` and `m` (default).
The component has three `size`, named `xs`, `s` and `m` (default).

```html
<sbb-checkbox value="size" size="m">Size</sbb-checkbox>
<sbb-checkbox value="size" size="xs">Size</sbb-checkbox>

<sbb-checkbox value="size" size="s">Size</sbb-checkbox>
```

The component's label can be displayed in bold using the `sbb-text--bold` class on a wrapper tag:
Expand Down Expand Up @@ -90,7 +92,7 @@ If you don't want the label to appear next to the checkbox, you can use `aria-la
| `indeterminate` | `indeterminate` | public | `boolean` | `false` | Whether the checkbox is indeterminate. |
| `name` | `name` | public | `string` | | Name of the form element. Will be read from name attribute. |
| `required` | `required` | public | `boolean` | `false` | Whether the component is required. |
| `size` | `size` | public | `SbbCheckboxSize` | `'m'` | Label size variant, either m or s. |
| `size` | `size` | public | `SbbCheckboxSize` | `'m'` | Size variant. |
| `value` | `value` | public | `string \| null` | `null` | Value of the form element. |

## Events
Expand Down
4 changes: 4 additions & 0 deletions src/elements/checkbox/common/checkbox-common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
:host([size='s']) & {
@include sbb.text-s--regular;
}

:host([size='xs']) & {
@include sbb.text-xs--regular;
}
}

.sbb-checkbox__inner {
Expand Down
15 changes: 1 addition & 14 deletions src/elements/checkbox/common/checkbox-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ import {
} from '../../core/mixins.js';
import type { SbbCheckboxGroupElement } from '../checkbox-group.js';

export type SbbCheckboxSize = 's' | 'm';
export type SbbCheckboxSize = 'xs' | 's' | 'm';

export declare class SbbCheckboxCommonElementMixinType
extends SbbFormAssociatedCheckboxMixinType
implements Partial<SbbDisabledMixinType>, Partial<SbbRequiredMixinType>
{
public indeterminate: boolean;

public set size(value: SbbCheckboxSize);
public get size(): SbbCheckboxSize;

public get group(): SbbCheckboxGroupElement | null;
}

Expand All @@ -35,16 +32,6 @@ export const SbbCheckboxCommonElementMixin = <T extends Constructor<LitElement>>
/** Whether the checkbox is indeterminate. */
@property({ type: Boolean }) public indeterminate = false;

/** Label size variant, either m or s. */
@property({ reflect: true })
public set size(value: SbbCheckboxSize) {
this._size = value;
}
public get size(): SbbCheckboxSize {
return this.group?.size ?? this._size;
}
private _size: SbbCheckboxSize = 'm';

/** Reference to the connected checkbox group. */
public get group(): SbbCheckboxGroupElement | null {
return this._group;
Expand Down
2 changes: 2 additions & 0 deletions src/elements/core/mixins/panel-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export declare class SbbPanelMixinType {
public expansionState?: string;
}

export type SbbPanelSize = 's' | 'm';

/**
* Mixin for common panel behaviors
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import {
import { customElement, property } from 'lit/decorators.js';

import { slotState } from '../../core/decorators.js';
import { panelCommonStyle, SbbPanelMixin, SbbUpdateSchedulerMixin } from '../../core/mixins.js';
import {
panelCommonStyle,
SbbPanelMixin,
type SbbPanelSize,
SbbUpdateSchedulerMixin,
} from '../../core/mixins.js';
import { radioButtonCommonStyle, SbbRadioButtonCommonElementMixin } from '../common.js';

import '../../screen-reader-only.js';

export type SbbRadioButtonPanelSize = 's' | 'm';

/**
/**
* It displays a radio button enhanced with the panel design.
Expand All @@ -42,13 +45,13 @@ export class SbbRadioButtonPanelElement extends SbbPanelMixin(
* Size variant.
*/
@property({ reflect: true })
public set size(value: SbbRadioButtonPanelSize) {
public set size(value: SbbPanelSize) {
this._size = value;
}
public get size(): SbbRadioButtonPanelSize {
public get size(): SbbPanelSize {
return this.group?.size ? (this.group.size === 'xs' ? 's' : this.group.size) : this._size;
}
private _size: SbbRadioButtonPanelSize = 'm';
private _size: SbbPanelSize = 'm';

protected override async willUpdate(changedProperties: PropertyValues<this>): Promise<void> {
super.willUpdate(changedProperties);
Expand Down
2 changes: 1 addition & 1 deletion src/elements/radio-button/radio-button-panel/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ The component's label can be displayed in bold using the `sbb-text--bold` class
| `disabled` | `disabled` | public | `boolean` | `false` | Whether the radio button is disabled. |
| `group` | - | public | `SbbRadioButtonGroupElement \| null` | `null` | Reference to the connected radio button group. |
| `required` | `required` | public | `boolean` | `false` | Whether the radio button is required. |
| `size` | `size` | public | `SbbRadioButtonPanelSize` | `'m'` | Size variant. |
| `size` | `size` | public | `SbbPanelSize` | `'m'` | Size variant. |
| `value` | `value` | public | `string \| undefined` | | Value of radio button. |

## Methods
Expand Down
Loading
Loading