Skip to content

Commit

Permalink
Merge branch 'fix/improve-forms-input-in-hcm' into feat/2525-update-f…
Browse files Browse the repository at this point in the history
…orm-check-styles
  • Loading branch information
imagoiq committed Apr 8, 2024
2 parents 91f82aa + 9eec980 commit e156454
Show file tree
Hide file tree
Showing 18 changed files with 305 additions and 120 deletions.
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`.
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 @@ -222,10 +222,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 @@ -274,12 +274,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 @@ -224,12 +224,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 @@ -191,9 +191,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

0 comments on commit e156454

Please sign in to comment.