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

fix(styles): Make styling more coherent for forms elements with High contrast mode and focus/hover state #2774

Merged
merged 29 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ba5450d
fix(styles): Update form validation feedback color and indicators in HCM
imagoiq Mar 6, 2024
182db6a
Lint
imagoiq Mar 6, 2024
26f9e1b
fix(styles): Make styling more coherent for forms elements with High …
imagoiq Mar 11, 2024
fa310ed
Fix using border instead of background to highlight selected state
imagoiq Mar 14, 2024
a67aaf6
Remove commented code
imagoiq Mar 14, 2024
37d27a0
Merge branch 'main' into fix/improve-forms-input-in-hcm
imagoiq Mar 19, 2024
e11a974
Merge branch 'main' into fix/improve-forms-input-in-hcm
imagoiq Mar 21, 2024
d5347d2
Merge branch 'main' into fix/improve-forms-input-in-hcm
imagoiq Mar 21, 2024
9f47f0f
Fixes for card-control
imagoiq Mar 21, 2024
9eac28a
Merge branch 'main' into fix/improve-forms-input-in-hcm
imagoiq Mar 21, 2024
00e55ec
Merge branch 'main' into fix/improve-forms-input-in-hcm
imagoiq Apr 2, 2024
125ba22
Merge branch 'main' into fix/improve-forms-input-in-hcm
imagoiq Apr 3, 2024
bd503f7
Add missing hover state for form-range on hover
imagoiq Apr 4, 2024
e15eeb7
Prototype for simpler version + support for input text and select
imagoiq Apr 4, 2024
01a622c
Remove unneeded prototype for focus-style and remove box-shadow on fo…
imagoiq Apr 8, 2024
995f34e
Add wrapper and styles for input, select and slider
imagoiq Apr 8, 2024
7c96433
Add changelog
imagoiq Apr 8, 2024
f140df2
Improve text input and select on chrome and reinstate hover style for…
imagoiq Apr 8, 2024
71daa2b
Reinstate hover style for checkbox, radio, textarea, switch
imagoiq Apr 8, 2024
fb563db
Consistency on disabled style
imagoiq Apr 8, 2024
9eec980
Fix code smell
imagoiq Apr 8, 2024
d655614
Reinstate selectedItem color
imagoiq Apr 10, 2024
0ee7ed2
Fix issues for checkbox on Firefox
imagoiq Apr 10, 2024
7741117
Extract border-radius from focus-style mixin
imagoiq Apr 10, 2024
15198c9
Merge branch 'main' into fix/improve-forms-input-in-hcm
imagoiq Apr 10, 2024
673040d
Use focus-dark variable
imagoiq Apr 10, 2024
777e6cf
Merge branch 'main' into fix/improve-forms-input-in-hcm
imagoiq Apr 11, 2024
84eac5c
Merge branch 'refs/heads/main' into fix/improve-forms-input-in-hcm
imagoiq Apr 15, 2024
bf998b2
Fix focus form-range focus
imagoiq Apr 15, 2024
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
5 changes: 5 additions & 0 deletions .changeset/shy-peas-count-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/design-system-styles': minor
---

Introduced new focus style for text input and select, and added new wrapper element `.focus-control-wrapper`, `.form-range-wrapper`, `.form-select-wrapper`.
5 changes: 5 additions & 0 deletions .changeset/shy-peas-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/design-system-styles': patch
---

Made styling more coherent for forms elements with High contrast mode and focus/hover state.
4 changes: 3 additions & 1 deletion packages/documentation/.storybook/styles/preview.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@

// General styles for content
a {
@include utilities.focus-style();
@include utilities.focus-style() {
border-radius: post.$border-radius;
}
}

// Style buttons related to the current page next to the tile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ $tile-rg-size: var(--post-docs-tile-rg-size, calc($tile-size / 1.2));

:host{
a {
@include utilities.focus-style();
@include utilities.focus-style() {
border-radius: post.$border-radius;
}
}

.tile {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="form-floating">
<div class="form-control-wrapper form-floating">
<input
#d="ngbDatepicker"
class="form-control"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="position-relative">
<div class="form-control-wrapper position-relative">
<input
#d="ngbDatepicker"
navigation="arrows"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="position-relative">
<div class="form-control-wrapper position-relative">
<input
#d="ngbDatepicker"
aria-label="Datepicker"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,14 @@ function render(args: Args, context: StoryContext) {
`;
if (args.floatingLabel) {
return html`
<div class="form-floating">${[control, label, ...contextual].filter(el => el !== null)}</div>
<div class="form-control-wrapper form-floating">
${[control, label, ...contextual].filter(el => el !== null)}
</div>
`;
} else {
return html` ${[label, control, ...contextual].filter(el => el !== null)} `;
return html`<div class="form-control-wrapper">
${[label, control, ...contextual].filter(el => el !== null)}
</div>`;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,14 @@ const Template: Story = {

if (args.floatingLabel) {
return html`
<div class="form-floating">
<div class="form-select-wrapper form-floating">
${[control, label, ...contextuals].filter(el => el !== null)}
</div>
`;
} else {
return html` ${[label, control, ...contextuals].filter(el => el !== null)} `;
return html`<div class="form-select-wrapper">
${[label, control, ...contextuals].filter(el => el !== null)}
</div>`;
}
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,18 @@ function render(args: Args, context: StoryContext) {
if (args.showValue === 'input') {
return html`
<div class="row align-items-end">
<div class="col">${[label, control, ...contextual].filter(el => el !== null)}</div>
<div class="col">
<div class="form-range-wrapper">
${[label, control, ...contextual].filter(el => el !== null)}
</div>
</div>
<div class="col-auto">${valueElement}</div>
</div>
`;
} else {
return html` ${[label, control, valueElement, ...contextual].filter(el => el !== null)} `;
return html`<div class="form-range-wrapper">
${[label, control, valueElement, ...contextual].filter(el => el !== null)}
</div>`;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,14 @@ ${args.textInside ?? nothing}</textarea
`;
if (args.floatingLabel) {
return html`
<div class="form-floating">${[control, label, ...contextual].filter(el => el !== null)}</div>
<div class="form-control-wrapper form-floating">
${[control, label, ...contextual].filter(el => el !== null)}
</div>
`;
} else return html` ${[label, control, ...contextual].filter(el => el !== null)} `;
} else
return html`<div class="form-control-wrapper">
${[label, control, ...contextual].filter(el => el !== null)}
</div>`;
}

export const Default: Story = {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="form-floating mb-3">
<div class="form-control-wrapper form-floating mb-3">
<input
id="typeahead-basic"
placeholder=" "
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="form-floating mb-3">
<div class="form-control-wrapper form-floating mb-3">
<input
id="typeahead-basic"
placeholder=" "
Expand Down
108 changes: 67 additions & 41 deletions packages/documentation/src/stories/patterns/forms/forms.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,27 @@ type Story = StoryObj;

export const BasicInput: Story = {
render: () => html`
<label class="form-label" for="firstname">Firstname</label>
<input type="text" id="firstname" class="form-control" />
<div class="form-control-wrapper"></div>
<label class="form-label" for="firstname">Firstname</label>
<input type="text" id="firstname" class="form-control" />
</div>
`,
};

export const RowSimple: Story = {
render: () => html`
<div class="row row-cols-1 row-cols-md-2">
<div class="col">
<label class="form-label" for="firstname">Firstname</label>
<input type="text" id="firstname" class="form-control" />
<div class="form-control-wrapper">
<label class="form-label" for="firstname">Firstname</label>
<input type="text" id="firstname" class="form-control" />
</div>
</div>
<div class="col">
<label class="form-label" for="lastname">Lastname</label>
<input type="text" id="lastname" class="form-control" />
<div class="form-control-wrapper">
<label class="form-label" for="lastname">Lastname</label>
<input type="text" id="lastname" class="form-control" />
</div>
</div>
</div>
`,
Expand All @@ -40,12 +46,16 @@ export const ColSimple: Story = {
render: () => html`
<div class="row">
<div class="col-8">
<label class="form-label" for="city">City</label>
<input type="text" id="city" class="form-control" />
<div class="form-control-wrapper">
<label class="form-label" for="city">City</label>
<input type="text" id="city" class="form-control" />
</div>
</div>
<div class="col-4">
<label class="form-label" for="state">State</label>
<input type="text" id="state" class="form-control" />
<div class="form-control-wrapper">
<label class="form-label" for="state">State</label>
<input type="text" id="state" class="form-control" />
</div>
</div>
</div>
`,
Expand All @@ -55,12 +65,16 @@ export const CustomWidth: Story = {
render: () => html`
<div class="row">
<div class="col-auto">
<label class="form-label" for="zip">Zip</label>
<input type="number" id="zip" class="form-control" style="max-width: 11ch" />
<div class="form-control-wrapper">
<label class="form-label" for="zip">Zip</label>
<input type="number" id="zip" class="form-control" style="max-width: 11ch" />
</div>
</div>
<div class="col">
<label class="form-label" for="city">City</label>
<input type="text" id="city" class="form-control" />
<div class="form-control-wrapper">
<label class="form-label" for="city">City</label>
<input type="text" id="city" class="form-control" />
</div>
</div>
</div>
`,
Expand All @@ -69,25 +83,33 @@ export const CustomWidth: Story = {
export const VerticalSpacing: Story = {
render: () => html`
<div class="mb-regular">
<label for="firstname">Firstname</label>
<input type="text" id="firstname" class="form-control" />
<div class="form-control-wrapper">
<label for="firstname">Firstname</label>
<input type="text" id="firstname" class="form-control" />
</div>
</div>
<div class="mb-regular">
<label for="lastname">Lastname</label>
<input type="text" id="lastname" class="form-control" />
<div class="form-control-wrapper">
<label for="lastname">Lastname</label>
<input type="text" id="lastname" class="form-control" />
</div>
</div>
`,
};

export const Buttons: Story = {
render: () => html`
<div class="mb-regular">
<label for="firstname">Firstname</label>
<input type="text" id="firstname" class="form-control" />
<div class="form-control-wrapper">
<label for="firstname">Firstname</label>
<input type="text" id="firstname" class="form-control" />
</div>
</div>
<div class="d-flex flex-row-reverse gap-mini">
<button class="btn btn-primary">Send</button>
<button class="btn btn-secondary">Cancel</button>
<div class="form-control-wrapper">
<button class="btn btn-primary">Send</button>
<button class="btn btn-secondary">Cancel</button>
</div>
</div>
`,
};
Expand All @@ -96,13 +118,13 @@ export const FloatingLabels: Story = {
render: () => html`
<div class="row">
<div class="col">
<div class="form-floating">
<div class="form-control-wrapper form-floating">
<input type="text" id="firstname" class="form-control" placeholder=" " />
<label class="form-label" for="firstname">Firstname</label>
</div>
</div>
<div class="col">
<div class="form-floating">
<div class="form-control-wrapper form-floating">
<input type="text" id="lastname" class="form-control" placeholder=" " />
<label class="form-label" for="lastname">Lastname</label>
</div>
Expand All @@ -117,7 +139,7 @@ export const Validation: Story = {
<!-- Form Control -->
<div class="row mb-regular">
<div class="col">
<div class="form-floating">
<div class="form-control-wrapper form-floating">
<input
id="formControlInvalid"
type="text"
Expand All @@ -130,7 +152,7 @@ export const Validation: Story = {
</div>
</div>
<div class="col">
<div class="form-floating">
<div class="form-control-wrapper form-floating">
<input
id="FormControlValid"
type="text"
Expand All @@ -147,14 +169,14 @@ export const Validation: Story = {
<!-- Form Select -->
<div class="row mb-regular">
<div class="col">
<div class="form-floating">
<div class="form-select-wrapper form-floating">
<select id="FormSelectInvalid" class="form-select is-invalid" required></select>
<label class="form-label" for="FormSelectInvalid">Invalid Select</label>
<p class="invalid-feedback">Error message</p>
</div>
</div>
<div class="col">
<div class="form-floating">
<div class="form-select-wrapper form-floating">
<select id="FormSelectValid" class="form-select is-valid">
<option disabled>Select one..</option>
<option value="1">Value 1</option>
Expand All @@ -169,7 +191,7 @@ export const Validation: Story = {
<!-- Form Select Multiple-->
<div class="row mb-regular">
<div class="col">
<div class="form-floating">
<div class="form-select-wrapper form-floating">
<select
id="FormSelectMultipleInvalid"
class="form-select is-invalid"
Expand All @@ -183,7 +205,7 @@ export const Validation: Story = {
</div>
</div>
<div class="col">
<div class="form-floating">
<div class="form-select-wrapper form-floating">
<select id="FormSelectMultipleValid" class="form-select is-valid" multiple>
<option value="1">Value 1</option>
<option value="2">Value 2</option>
Expand All @@ -197,14 +219,14 @@ export const Validation: Story = {
<!-- Form File -->
<div class="row mb-regular">
<div class="col">
<div class="form-floating">
<div class="form-control-wrapper form-floating">
<input id="FormFileInvalid" type="file" class="form-control is-invalid" required />
<label class="form-label" for="FormFileInvalid">Invalid File</label>
<p class="invalid-feedback">Error message</p>
</div>
</div>
<div class="col">
<div class="form-floating">
<div class="form-control-wrapper form-floating">
<input id="FormFileValid" type="file" class="form-control is-valid" />
<label class="form-label" for="FormFileValid">Valid File</label>
<p class="valid-feedback">Success message (optional)</p>
Expand All @@ -215,7 +237,7 @@ export const Validation: Story = {
<!-- Form Textarea -->
<div class="row mb-regular">
<div class="col">
<div class="form-floating">
<div class="form-control-wrapper form-floating">
<textarea
id="FormTextareaInvalid"
type="text"
Expand All @@ -228,7 +250,7 @@ export const Validation: Story = {
</div>
</div>
<div class="col">
<div class="form-floating">
<div class="form-control-wrapper form-floating">
<textarea
id="FormTextareaValid"
type="text"
Expand Down Expand Up @@ -287,14 +309,18 @@ Value</textarea
<!-- Form Range -->
<div class="row mb-regular">
<div class="col">
<label class="form-label" for="FormRangeInvalid">Invalid Range</label>
<input class="form-range is-invalid" id="FormRangeInvalid" type="range" />
<p class="invalid-feedback">Error message</p>
<div class="form-range-wrapper">
<label class="form-label" for="FormRangeInvalid">Invalid Range</label>
<input class="form-range is-invalid" id="FormRangeInvalid" type="range" />
<p class="invalid-feedback">Error message</p>
</div>
</div>
<div class="col">
<label class="form-label" for="FormRangeValid">Valid Range</label>
<input class="form-range is-valid" id="FormRangeValid" type="range" />
<p class="valid-feedback">Success message (optional)</p>
<div class="form-range-wrapper">
<label class="form-label" for="FormRangeValid">Valid Range</label>
<input class="form-range is-valid" id="FormRangeValid" type="range" />
<p class="valid-feedback">Success message (optional)</p>
</div>
</div>
</div>

Expand Down Expand Up @@ -332,7 +358,7 @@ Value</textarea

export const Hints: Story = {
render: () => html`
<div class="form-floating">
<div class="form-control-wrapper form-floating">
<input
type="text"
id="firstname"
Expand Down
Loading
Loading