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-autocomplete): introduce size s #3020

Merged
merged 6 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
44 changes: 44 additions & 0 deletions src/elements/autocomplete/autocomplete.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ const borderless: InputType = {
},
};

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

const floatingLabel: InputType = {
control: {
type: 'boolean',
Expand Down Expand Up @@ -119,6 +129,7 @@ const defaultArgTypes: ArgTypes = {

// Form field args
borderless,
size,
floatingLabel,
};

Expand All @@ -142,6 +153,7 @@ const defaultArgs: Args = {

// Form field args
borderless: false,
size: size.options![0],
floatingLabel: false,
};

Expand Down Expand Up @@ -238,6 +250,7 @@ const Template = (args: Args): TemplateResult => html`
?negative=${args.negative}
?borderless=${args.borderless}
?floating-label=${args.floatingLabel}
size=${args.size}
data-testid="form-field"
>
<label>Label</label>
Expand All @@ -262,6 +275,7 @@ const OptionGroupTemplate = (args: Args): TemplateResult => html`
?negative=${args.negative}
?borderless=${args.borderless}
?floating-label=${args.floatingLabel}
size=${args.size}
data-testid="form-field"
>
<label>Label</label>
Expand Down Expand Up @@ -289,6 +303,7 @@ const MixedTemplate = (args: Args): TemplateResult => html`
?negative=${args.negative}
?borderless=${args.borderless}
?floating-label=${args.floatingLabel}
size=${args.size}
data-testid="form-field"
>
<label>Label</label>
Expand Down Expand Up @@ -329,6 +344,7 @@ const RequiredTemplate = (args: Args): TemplateResult => {
?negative=${args.negative}
?borderless=${args.borderless}
?floating-label=${args.floatingLabel}
size=${args.size}
data-testid="form-field"
id="sbb-form-field"
>
Expand Down Expand Up @@ -378,6 +394,13 @@ export const BasicNegative: StoryObj = {
play: isChromatic() ? playStory : undefined,
};

export const BasicSizeS: StoryObj = {
render: Template,
argTypes: defaultArgTypes,
args: { ...defaultArgs, size: size.options![1] },
play: isChromatic() ? playStory : undefined,
};

export const BasicOpenAbove: StoryObj = {
render: Template,
argTypes: defaultArgTypes,
Expand All @@ -400,13 +423,27 @@ export const BorderlessNegative: StoryObj = {
play: isChromatic() ? playStory : undefined,
};

export const BorderlessSizeS: StoryObj = {
render: Template,
argTypes: defaultArgTypes,
args: { ...defaultArgs, borderless: true, size: size.options![1] },
play: isChromatic() ? playStory : undefined,
};

export const FloatingLabel: StoryObj = {
render: Template,
argTypes: defaultArgTypes,
args: { ...defaultArgs, floatingLabel: true },
play: isChromatic() ? playStory : undefined,
};

export const FloatingLabelSizeS: StoryObj = {
render: Template,
argTypes: defaultArgTypes,
args: { ...defaultArgs, floatingLabel: true, size: size.options![1] },
play: isChromatic() ? playStory : undefined,
};

export const WithError: StoryObj = {
render: RequiredTemplate,
argTypes: withGroupsArgTypes,
Expand Down Expand Up @@ -481,6 +518,13 @@ export const MixedSingleOptionWithOptionGroupNegative: StoryObj = {
play: isChromatic() ? playStory : undefined,
};

export const MixedSingleOptionWithOptionGroupSizeS: StoryObj = {
render: MixedTemplate,
argTypes: withGroupsArgTypes,
args: { ...withGroupsDefaultArgs, size: size.options![1] },
play: isChromatic() ? playStory : undefined,
};

const meta: Meta = {
decorators: [withActions as Decorator],
parameters: {
Expand Down
42 changes: 33 additions & 9 deletions src/elements/autocomplete/autocomplete.visual.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ describe('sbb-autocomplete', () => {
preserveIconSpace: true,
disableOption: false,
borderless: false,
size: 'm',
value: undefined as undefined | string,
withGroup: false,
disableGroup: false,
withMixedOptionAndGroup: false,
Expand Down Expand Up @@ -86,15 +88,15 @@ describe('sbb-autocomplete', () => {
disableOption: boolean,
disableGroup: boolean,
): TemplateResult => html`
<sbb-option value="Option 1">
<sbb-option value="Option 1" selected>
<sbb-icon slot="icon" name="clock-small" style="color: var(--sbb-color-sky)"></sbb-icon>
Option Value
</sbb-option>
${createOptionsGroup(withIcon, disableOption, disableGroup)}
`;

const template = (args: typeof defaultArgs): TemplateResult => html`
<sbb-form-field ?negative=${args.negative} ?borderless=${args.borderless}>
<sbb-form-field ?negative=${args.negative} ?borderless=${args.borderless} size=${args.size}>
<label>Label</label>
<input placeholder="Placeholder" ?disabled=${args.disabled} ?readonly=${args.readonly} />
<sbb-autocomplete ?preserve-icon-space=${args.preserveIconSpace}>
Expand Down Expand Up @@ -152,13 +154,15 @@ describe('sbb-autocomplete', () => {
backgroundColor: negative ? 'var(--sbb-color-black)' : undefined,
};

for (const visualDiffState of [visualDiffDefault, visualDiffFocus]) {
it(
`state=${visualDiffState.name} negative=${negative}`,
visualDiffState.with(async (setup) => {
await setup.withFixture(template({ ...defaultArgs, negative }), style);
}),
);
for (const size of ['m', 's']) {
for (const visualDiffState of [visualDiffDefault, visualDiffFocus]) {
it(
`state=${visualDiffState.name} negative=${negative} size=${size}`,
visualDiffState.with(async (setup) => {
await setup.withFixture(template({ ...defaultArgs, negative, size }), style);
}),
);
}
}

it(
Expand Down Expand Up @@ -271,6 +275,26 @@ describe('sbb-autocomplete', () => {
setup.withPostSetupAction(() => openAutocomplete(setup));
}),
);

it(
`negative=${negative} withGroup=true withMixedOptionAndGroup=true size=s`,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(
template({
...defaultArgs,
negative,
withGroup: true,
withMixedOptionAndGroup: true,
size: 's',
}),
{
minHeight: '800px',
backgroundColor: negative ? 'var(--sbb-color-black)' : undefined,
},
);
setup.withPostSetupAction(() => openAutocomplete(setup));
}),
);
}
});
});
12 changes: 12 additions & 0 deletions src/elements/autocomplete/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ The displayed `sbb-option` can be collected into groups using `sbb-optgroup` ele
</sbb-form-field>
```

### Size

The component has no `size` property but, when slotted in a `sbb-form-field`, it adapts to the parent `size`.

```html
<sbb-form-field size="s">
<label>Label</label>
<input placeholder="Trigger element" />
<sbb-autocomplete> ... </sbb-autocomplete>
</sbb-form-field>
```

## Events

The `sbb-option` emits the `optionSelected` event when selected via user interaction.
Expand Down
Loading