Skip to content

Commit

Permalink
feat(sbb-stepper): add size 's'
Browse files Browse the repository at this point in the history
  • Loading branch information
TomMenga committed Aug 23, 2024
1 parent 83d7719 commit 2a86acc
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/elements/stepper/step-label/step-label.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
}
}

:host([data-size='s']) {
--sbb-step-label-prefix-size: var(--sbb-size-element-xxxs);
}

:host([disabled]) {
--sbb-step-label-color: var(--sbb-color-granite);
--sbb-step-label-prefix-border-style: dashed;
Expand Down Expand Up @@ -102,6 +106,10 @@
display: flex;
gap: var(--sbb-spacing-fixed-4x);
color: var(--sbb-step-label-color);

:host([data-size='s']) & {
@include sbb.text-m--bold;
}
}

.sbb-step-label__prefix {
Expand Down
15 changes: 15 additions & 0 deletions src/elements/stepper/stepper/stepper.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,25 @@ const horizontalFrom: InputType = {
options: ['unset', 'zero', 'micro', 'small', 'medium', 'large', 'wide', 'ultra'],
};

const size: InputType = {
control: {
type: 'inline-radio',
},
options: ['s', 'm'],
};

const defaultArgTypes: ArgTypes = {
linear,
orientation,
'horizontal-from': horizontalFrom,
size,
};

const defaultArgs: Args = {
linear: false,
orientation: 'horizontal',
'horizontal-from': 'unset',
size: size.options![1],
};

const codeStyle: Args = {
Expand Down Expand Up @@ -356,6 +365,12 @@ export const Vertical: StoryObj = {
args: { ...defaultArgs, orientation: orientation.options![1] },
};

export const SizeS: StoryObj = {
render: Template,
argTypes: defaultArgTypes,
args: { ...defaultArgs, size: size.options![0] },
};

export const HorizontalFromSmall: StoryObj = {
render: Template,
argTypes: defaultArgTypes,
Expand Down
15 changes: 15 additions & 0 deletions src/elements/stepper/stepper/stepper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export class SbbStepperElement extends SbbHydrationMixin(LitElement) {
@property({ reflect: true })
public orientation: SbbOrientation = 'horizontal';

/** Size variant, either l or m. */
@property({ reflect: true }) public size: 's' | 'm' = 'm';

/** The currently selected step. */
@property({ attribute: false })
public set selected(step: SbbStepElement) {
Expand Down Expand Up @@ -200,6 +203,7 @@ export class SbbStepperElement extends SbbHydrationMixin(LitElement) {
label.configure(i + 1, array.length, this._loaded);
});
this._select(this.selected || this._enabledSteps[0]);
this._proxySize();
}

private _updateLabels(): void {
Expand Down Expand Up @@ -271,6 +275,17 @@ export class SbbStepperElement extends SbbHydrationMixin(LitElement) {
if (changedProperties.has('linear') && this._loaded) {
this._configureLinearMode();
}

if (changedProperties.has('size')) {
this._proxySize();
this._setMarkerSize();
}
}

private _proxySize(): void {
this.steps.forEach((step) => {
step.label?.setAttribute('data-size', this.size);
});
}

private _handleKeyDown(evt: KeyboardEvent): void {
Expand Down
9 changes: 9 additions & 0 deletions src/elements/stepper/stepper/stepper.visual.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ describe(`sbb-stepper`, () => {
orientation?: string,
longLabel?: boolean,
horizontalFrom?: string,
size: 's' | 'm' = 'm',
): TemplateResult => html`
<sbb-stepper
selected-index="0"
?linear=${linear}
orientation=${orientation || nothing}
horizontal-from=${horizontalFrom || nothing}
size=${size}
>
<sbb-step-label icon-name="pen-small">Step 1</sbb-step-label>
<sbb-step>
Expand Down Expand Up @@ -87,6 +89,13 @@ describe(`sbb-stepper`, () => {
await setup.withFixture(template(false, orientation, true));
}),
);

it(
`orientation=${orientation} size=s`,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(template(false, orientation, true, undefined, 's'));
}),
);
}
});
});

0 comments on commit 2a86acc

Please sign in to comment.