-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(styles): create validation component (#3824)
Co-authored-by: Alizé Debray <[email protected]>
- Loading branch information
1 parent
4b381b6
commit cecf171
Showing
31 changed files
with
598 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@swisspost/design-system-styles': patch | ||
--- | ||
|
||
Updated the styles of the form validation messages to match the new Post design. |
13 changes: 13 additions & 0 deletions
13
packages/documentation/cypress/e2e/components/validation.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
describe('Validation', () => { | ||
describe('Accessibility', () => { | ||
beforeEach(() => { | ||
cy.visit('/iframe.html?id=snapshots--validation'); | ||
cy.get('.snapshot', { timeout: 30000 }).should('be.visible'); | ||
cy.injectAxe(); | ||
}); | ||
|
||
it('Has no detectable a11y violations on load for all variants', () => { | ||
cy.checkA11y('#root-inner'); | ||
}); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/documentation/cypress/snapshots/components/validation.snapshot.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
describe('Validation', () => { | ||
it('default', () => { | ||
cy.visit('/iframe.html?id=snapshots--validation'); | ||
cy.get('.snapshot', { timeout: 30000 }).should('be.visible'); | ||
cy.percySnapshot('Validation', { widths: [1440] }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
packages/documentation/src/stories/components/forms/validation/validation.docs.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { Canvas, Controls, Meta } from '@storybook/blocks'; | ||
import * as ValidationStories from './validation.stories'; | ||
import StylesPackageImport from '@/shared/styles-package-import.mdx'; | ||
|
||
<Meta of={ValidationStories} /> | ||
|
||
<div className="docs-title"> | ||
# Validation | ||
|
||
<nav> | ||
<link-design of={JSON.stringify(ValidationStories)}></link-design> | ||
</nav> | ||
</div> | ||
|
||
<div className="lead"> | ||
The Validation component is a reusable component designed to provide consistent validation | ||
feedback across all components that require input validation. | ||
</div> | ||
|
||
Validation employs the `:invalid` and `:valid` pseudo-classes to provide styling for `<input>`, `<select>`, and `<textarea>` elements. To control when these styles are displayed, the `.was-validated` class must be applied to a parent element (e.g. `<form>`). | ||
|
||
Alternatively, `.is-invalid` and `.is-valid` classes may be used instead of the pseudo-classes for server-side validation, without the `.was-validated` parent class. | ||
|
||
These classes control the display of corresponding feedback messages that should be placed under the component: `<p className="valid-feedback">...</p>` or `<p className="invalid-feedback">...</p>`. | ||
|
||
## Examples | ||
|
||
### Checkbox | ||
|
||
<Canvas sourceState="shown" of={ValidationStories.Checkbox} /> | ||
<div className="hide-col-default"> | ||
<Controls of={ValidationStories.Checkbox} /> | ||
</div> | ||
|
||
### Input | ||
|
||
<Canvas sourceState="shown" of={ValidationStories.Input} /> | ||
<div className="hide-col-default"> | ||
<Controls of={ValidationStories.Input} /> | ||
</div> | ||
|
||
### Radio Button | ||
|
||
<Canvas sourceState="shown" of={ValidationStories.RadioButton} /> | ||
<div className="hide-col-default"> | ||
<Controls of={ValidationStories.RadioButton} /> | ||
</div> | ||
|
||
### Radio Button Inline Group | ||
|
||
<Canvas sourceState="shown" of={ValidationStories.RadioButtonGroup} /> | ||
<div className="hide-col-default"> | ||
<Controls of={ValidationStories.RadioButtonGroup} /> | ||
</div> | ||
|
||
### Select | ||
|
||
<Canvas sourceState="shown" of={ValidationStories.Select} /> | ||
<div className="hide-col-default"> | ||
<Controls of={ValidationStories.Select} /> | ||
</div> | ||
|
||
### Switch | ||
|
||
<Canvas sourceState="shown" of={ValidationStories.Switch} /> | ||
<div className="hide-col-default"> | ||
<Controls of={ValidationStories.Switch} /> | ||
</div> | ||
|
||
### Textarea | ||
|
||
<Canvas sourceState="shown" of={ValidationStories.TextArea} /> | ||
<div className="hide-col-default"> | ||
<Controls of={ValidationStories.TextArea} /> | ||
</div> |
50 changes: 50 additions & 0 deletions
50
...ages/documentation/src/stories/components/forms/validation/validation.snapshot.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { StoryObj, Args, StoryContext } from '@storybook/web-components'; | ||
import meta, { | ||
Checkbox, | ||
Input, | ||
RadioButton, | ||
RadioButtonGroup, | ||
Select, | ||
Switch, | ||
TextArea, | ||
} from './validation.stories'; | ||
import { html, nothing } from 'lit'; | ||
import { schemes } from '@/shared/snapshots/schemes'; | ||
|
||
const { id, ...metaWithoutId } = meta; | ||
|
||
export default { | ||
...metaWithoutId, | ||
title: 'Snapshots', | ||
}; | ||
|
||
type Story = StoryObj; | ||
|
||
const components = [Checkbox, Input, RadioButton, RadioButtonGroup, Select, Switch, TextArea]; | ||
|
||
export const Validation: Story = { | ||
render: (_args: Args, context: StoryContext) => { | ||
return schemes( | ||
scheme => html` | ||
<div class="snapshot"> | ||
${components.map(Component => { | ||
return html` | ||
<div> | ||
${['is-valid', 'is-invalid'].map(validation => { | ||
const render = Component.render || (() => nothing); | ||
const args = { | ||
...context.args, | ||
validationValidation: validation, | ||
scheme: scheme, | ||
componentName: Object.keys(Component.args!)[0], | ||
}; | ||
return html`${render(args, context)}`; | ||
})} | ||
</div> | ||
`; | ||
})} | ||
</div> | ||
`, | ||
); | ||
}, | ||
}; |
Oops, something went wrong.