-
Notifications
You must be signed in to change notification settings - Fork 14
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(Switch): enable support for form-associated #1368
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b828008
feat(Switch): enable support for form-associated
dgonzalezr 77d3bcd
fix(Switch): handle form association when `required` is enabled
dgonzalezr c783e05
fix(Checkbox): enable focus when form validation message is shown
dgonzalezr b9bb52a
fix: clear form associated value on form reset callback
dgonzalezr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ const meta: Meta = { | |
'background-on-hover': { control: 'boolean' }, | ||
checked: { control: 'boolean' }, | ||
disabled: { control: 'boolean' }, | ||
'form-validation-message': { control: 'text' }, | ||
'full-width': { control: 'boolean' }, | ||
'inner-label': { control: 'inline-radio', options: [...SWITCH_INNER_LABEL] }, | ||
'justify-content': { control: 'select', options: [...SWITCH_JUSTIFY_CONTENT] }, | ||
|
@@ -35,6 +36,7 @@ const meta: Meta = { | |
'background-on-hover': false, | ||
checked: false, | ||
disabled: false, | ||
'form-validation-message': undefined, | ||
'full-width': false, | ||
'inner-label': 'default', | ||
'justify-content': 'start', | ||
|
@@ -55,6 +57,7 @@ const Template = (args: Args) => html` | |
?background-on-hover=${args['background-on-hover']} | ||
?checked=${args.checked} | ||
?disabled=${args.disabled} | ||
form-validation-message=${ifDefined(args['form-validation-message'])} | ||
?full-width=${args['full-width']} | ||
inner-label=${ifDefined(args['inner-label'])} | ||
justify-content=${ifDefined(args['justify-content'])} | ||
|
@@ -124,3 +127,76 @@ export const FullWidth: Story = { | |
'reverse-order': true, | ||
}, | ||
}; | ||
|
||
export const WithForm: Story = { | ||
render: (args: Args) => { | ||
const handleFormSubmit = (ev: Event) => { | ||
ev.preventDefault(); | ||
const form = ev.target as HTMLFormElement; | ||
const formData = new FormData(form); | ||
const formValues = Object.fromEntries(formData.entries()); | ||
|
||
const codeElement = document.getElementById('form-data'); | ||
if (!codeElement) return; | ||
|
||
codeElement.textContent = JSON.stringify(formValues, null, 2); | ||
}; | ||
|
||
return html` | ||
<link rel="stylesheet" href="https://unpkg.com/@highlightjs/[email protected]/styles/night-owl.min.css" /> | ||
<div class="grid auto-cols-auto grid-cols-1 gap-y-l sm:grid-cols-2 sm:gap-x-l"> | ||
<bq-card style="--bq-card--background: transparent"> | ||
<h4 class="m-be-m">Account settings</h4> | ||
<form class="flex flex-col gap-y-m" @submit=${handleFormSubmit}> | ||
${Template({ | ||
...args, | ||
text: 'Show app list in the menu', | ||
name: 'showAppList', | ||
required: true, | ||
'form-validation-message': 'Please enable showing the app list in the menu', | ||
})} | ||
${Template({ ...args, text: 'Show recently added apps', name: 'showRecentlyApps', checked: true })} | ||
${Template({ ...args, text: 'Show most used apps', name: 'showUsedApps' })} | ||
${Template({ ...args, text: 'Show app notifications', name: 'showAppNotifications', checked: true })} | ||
<div class="flex justify-end gap-x-s"> | ||
<bq-button appearance="secondary" type="reset">Cancel</bq-button> | ||
<bq-button type="submit">Save</bq-button> | ||
</div> | ||
</form> | ||
</bq-card> | ||
<bq-card class="[&::part(wrapper)]:h-full"> | ||
<h4 class="m-be-m">Form Data</h4> | ||
<div class="language-javascript overflow-x-scroll whitespace-pre rounded-s"> | ||
// Handle form submit<br /> | ||
const form = ev.target as HTMLFormElement;<br /> | ||
const formData = new FormData(form);<br /> | ||
const formValues = Object.fromEntries(formData.entries()); | ||
</div> | ||
<pre> | ||
<code id="form-data" class="rounded-s"> | ||
{ // submit the form to see the data here } | ||
</code> | ||
</pre> | ||
</bq-card> | ||
</div> | ||
|
||
<script type="module"> | ||
import hljs from 'https://unpkg.com/@highlightjs/[email protected]/es/highlight.min.js'; | ||
import javascript from 'https://unpkg.com/@highlightjs/[email protected]/es/languages/javascript.min.js'; | ||
|
||
hljs.registerLanguage('javascript', javascript); | ||
hljs.highlightAll(); | ||
|
||
document.querySelectorAll('div.language-javascript').forEach((block) => { | ||
hljs.highlightElement(block); | ||
}); | ||
</script> | ||
`; | ||
}, | ||
args: { | ||
'background-on-hover': true, | ||
'full-width': true, | ||
'justify-content': 'space-between', | ||
'reverse-order': true, | ||
}, | ||
}; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.