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-stepper): add size 's' #3026

Merged
merged 5 commits into from
Aug 28, 2024
Merged
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
21 changes: 20 additions & 1 deletion src/elements/stepper/step-label/step-label.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
--sbb-step-label-prefix-border-style: solid;
--sbb-step-label-prefix-border-color: var(--sbb-color-cloud);
--sbb-step-label-prefix-background-color: var(--sbb-color-white);
--sbb-step-label-gap: var(--sbb-spacing-fixed-4x);

position: relative;
min-width: 0;
Expand Down Expand Up @@ -57,6 +58,20 @@
}
}

:host([data-size='s']) {
--sbb-step-label-gap: var(--sbb-spacing-fixed-3x);
--sbb-step-label-prefix-size: var(--sbb-size-element-xxxs);

&::before {
// The `--sbb-font-size-text-m` is beign used here to align the bubble's inner text to
// the label text which includes the `sbb.text-m--bold` mixin.
inset-block-start: calc(
var(--sbb-font-size-text-m) * (var(--sbb-typo-line-height-body-text) / 2) +
(var(--sbb-border-width-1x) / 2)
);
}
}

:host([disabled]) {
--sbb-step-label-color: var(--sbb-color-granite);
--sbb-step-label-prefix-border-style: dashed;
Expand Down Expand Up @@ -100,8 +115,12 @@
cursor: var(--sbb-step-label-cursor);
position: relative;
display: flex;
gap: var(--sbb-spacing-fixed-4x);
gap: var(--sbb-step-label-gap);
color: var(--sbb-step-label-color);

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

.sbb-step-label__prefix {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ snapshots["sbb-stepper renders DOM"] =
data-disable-animation=""
orientation="horizontal"
selected-index="0"
size="m"
>
<sbb-step-label
aria-controls="sbb-step-0"
data-action=""
data-button=""
data-orientation="horizontal"
data-selected=""
data-size="m"
dir="ltr"
id="sbb-step-label-0"
role="tab"
Expand All @@ -36,6 +38,7 @@ snapshots["sbb-stepper renders DOM"] =
data-action=""
data-button=""
data-orientation="horizontal"
data-size="m"
dir="ltr"
id="sbb-step-label-1"
role="tab"
Expand All @@ -59,6 +62,7 @@ snapshots["sbb-stepper renders DOM"] =
data-button=""
data-disabled=""
data-orientation="horizontal"
data-size="m"
dir="ltr"
disabled=""
id="sbb-step-label-2"
Expand Down
1 change: 1 addition & 0 deletions src/elements/stepper/stepper/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Use an `aria-label` attribute to describe the purpose of the stepper. The `sbb-s
| `orientation` | `orientation` | public | `SbbOrientation` | `'horizontal'` | Steps orientation, either horizontal or vertical. |
| `selected` | - | public | `SbbStepElement \| undefined` | | The currently selected step. |
| `selectedIndex` | `selected-index` | public | `number \| undefined` | | The currently selected step index. |
| `size` | `size` | public | `'s' \| 'm'` | `'m'` | Size variant, either s or m. |
| `steps` | - | public | `SbbStepElement[]` | | The steps of the stepper. |

## Methods
Expand Down
11 changes: 11 additions & 0 deletions src/elements/stepper/stepper/stepper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,15 @@ describe('sbb-stepper', () => {
expect(stepLabelThree).to.have.attribute('data-selected');
expect(stepLabelThree.step).to.have.attribute('data-selected');
});

it('proxy size to step children', async () => {
const stepLabels = Array.from(element.querySelectorAll<SbbStepLabelElement>('sbb-step-label')!);

expect(stepLabels.every((l) => l.getAttribute('data-size') === element.size)).to.be.true;

element.size = 's';
await waitForLitRender(element);

expect(stepLabels.every((l) => l.getAttribute('data-size') === element.size)).to.be.true;
});
});
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 s 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, false, undefined, 's'));
}),
);
}
});
});
Loading