Skip to content

Commit

Permalink
feat(sbb-time-input): add size 's' (#3018)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomMenga authored Aug 28, 2024
1 parent 6000abc commit 375bdad
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
6 changes: 6 additions & 0 deletions src/elements/core/styles/core.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

// Time Input
--sbb-time-input-max-width: #{functions.px-to-rem-build(58)};
--sbb-time-input-s-max-width: #{functions.px-to-rem-build(51)};

// Overlay
--sbb-overlay-default-z-index: 1000;
Expand All @@ -41,6 +42,7 @@

// Time Input
--sbb-time-input-max-width: #{functions.px-to-rem-build(65)};
--sbb-time-input-s-max-width: #{functions.px-to-rem-build(58)};
}
}
}
Expand Down Expand Up @@ -123,4 +125,8 @@ sbb-title + p {

input[data-sbb-time-input] {
max-width: var(--sbb-time-input-max-width);

sbb-form-field[size='s'] & {
max-width: var(--sbb-time-input-s-max-width);
}
}
7 changes: 5 additions & 2 deletions src/elements/time-input/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ which accepts the id of the native input, or directly its reference.

## In `sbb-form-field`

If the `sbb-time-input` is used within a `sbb-form-field` with a native input, they are automatically linked.
If the `sbb-time-input` is used within a `sbb-form-field`:

- It links to the native input automatically.
- It adapts to the form-field `size`.

```html
<sbb-form-field width="collapse">
<sbb-form-field width="collapse" size="s">
<input value="13:30" />
<sbb-time-input></sbb-time-input>
</sbb-form-field>
Expand Down
28 changes: 14 additions & 14 deletions src/elements/time-input/time-input.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const value: InputType = {
type: 'text',
},
table: {
category: 'Native input attribute',
category: 'Native input',
},
};

Expand All @@ -81,7 +81,7 @@ const readonly: InputType = {
type: 'boolean',
},
table: {
category: 'Native input attribute',
category: 'Native input',
},
};

Expand All @@ -90,7 +90,7 @@ const disabled: InputType = {
type: 'boolean',
},
table: {
category: 'Native input attribute',
category: 'Native input',
},
};

Expand All @@ -99,17 +99,17 @@ const required: InputType = {
type: 'boolean',
},
table: {
category: 'Native input attribute',
category: 'Native input',
},
};

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

Expand All @@ -118,7 +118,7 @@ const negative: InputType = {
type: 'boolean',
},
table: {
category: 'Form-field attribute',
category: 'Form-field',
},
};

Expand All @@ -127,7 +127,7 @@ const label: InputType = {
type: 'text',
},
table: {
category: 'Form-field attribute',
category: 'Form-field',
},
};

Expand All @@ -136,7 +136,7 @@ const optional: InputType = {
type: 'boolean',
},
table: {
category: 'Form-field attribute',
category: 'Form-field',
},
};

Expand All @@ -145,7 +145,7 @@ const borderless: InputType = {
type: 'boolean',
},
table: {
category: 'Form-field attribute',
category: 'Form-field',
},
};

Expand All @@ -154,7 +154,7 @@ const iconStart: InputType = {
type: 'text',
},
table: {
category: 'Form-field attribute',
category: 'Form-field',
},
};

Expand All @@ -163,7 +163,7 @@ const iconEnd: InputType = {
type: 'text',
},
table: {
category: 'Form-field attribute',
category: 'Form-field',
},
};

Expand Down Expand Up @@ -196,7 +196,7 @@ const basicArgs: Args = {
const formFieldBasicArgs = {
...basicArgs,
label: 'Label',
size: size.options![0],
size: size.options![1],
optional: false,
borderless: false,
iconStart: undefined,
Expand All @@ -206,7 +206,7 @@ const formFieldBasicArgs = {
const formFieldBasicArgsWithIcons = {
...basicArgs,
label: 'Label',
size: size.options![0],
size: size.options![1],
optional: false,
borderless: false,
iconStart: 'clock-small',
Expand Down
32 changes: 23 additions & 9 deletions src/elements/time-input/time-input.visual.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,25 @@ describe(`sbb-time-input`, () => {
withError: [false, true],
};

const sizeCases = {
size: ['s', 'm', 'l'],
noIcons: [false, true],
};

type ParamsType = { [K in keyof typeof cases]: (typeof cases)[K][number] } & {
[K in keyof typeof sizeCases]: (typeof sizeCases)[K][number];
} & {
readonly?: boolean;
borderless?: boolean;
disabled?: boolean;
noIcons?: boolean;
};
const template = (args: Partial<ParamsType>): TemplateResult => html`
<sbb-form-field ?borderless=${args.borderless} ?negative=${args.negative} width="collapse">
<sbb-form-field
?borderless=${args.borderless}
?negative=${args.negative}
size=${args.size || nothing}
width="collapse"
>
<label>Label</label>
${!args.noIcons ? html`<sbb-icon slot="prefix" name="clock-small"></sbb-icon>` : nothing}
<sbb-time-input></sbb-time-input>
Expand Down Expand Up @@ -62,6 +73,16 @@ describe(`sbb-time-input`, () => {
);
});

// Size and icons cases
describeEach(sizeCases, (params) => {
it(
state.name,
state.with(async (setup) => {
await setup.withFixture(template(params));
}),
);
});

it(
`disabled_${state.name}`,
state.with(async (setup) => {
Expand All @@ -82,13 +103,6 @@ describe(`sbb-time-input`, () => {
await setup.withFixture(template({ borderless: true }));
}),
);

it(
`no icon_${state.name}`,
state.with(async (setup) => {
await setup.withFixture(template({ noIcons: true }));
}),
);
}
});
});

0 comments on commit 375bdad

Please sign in to comment.