-
Notifications
You must be signed in to change notification settings - Fork 59
feat(docs): add an inline search field for component in list doc page #3377
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
base: ouds/main
Are you sure you want to change the base?
Changes from 6 commits
41a7bbe
cefc8ab
29556e0
c0518a8
f982752
52e4d24
65a7a8a
d410303
46b80d4
cda0a68
68b8389
43332f8
867db65
ce67984
1b31ce9
95efe9d
5a65748
964130f
558f4f3
ab7228e
45c3fc2
b122851
3adcefe
e2bcaa7
73b8cb0
ff7e87c
d72e58b
0453e1e
c007c07
4aa0d2c
67a0798
8818e1a
9833ac7
4d81394
a69636a
f4d9881
afed057
20418fe
3b8a985
c55f547
4831735
4e6b946
b9ec773
e072017
ff901be
4bfd22b
ba02835
2a0b3cf
2ff54f2
c97d904
2378c88
d83fe0b
ae07016
70b80ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| --- | ||
| import { getVersionedDocsPath } from '@libs/path' | ||
| --- | ||
|
|
||
| <ouds-component-finder> | ||
| <form class="needs-validation" novalidate onsubmit="return false"> | ||
| <div class="text-input mb-gridgap"> | ||
| <div class="text-input-container"> | ||
| <svg aria-hidden="true"> | ||
| <use xlink:href={getVersionedDocsPath('assets/img/ouds-web-sprite.svg#search')}></use> | ||
| </svg> | ||
| <label for="oudsComponentFinderInput" | ||
| >Find component <span class="visually-hidden">and update the component list below</span></label | ||
| > | ||
| <input | ||
| type="search" | ||
| class="text-input-field" | ||
| id="oudsComponentFinderInput" | ||
| pattern="[a-zA-Z \\-]+" | ||
| placeholder=" " | ||
| data-feedback-id="componentSearchFeedback" | ||
| /> | ||
| </div> | ||
| <p id="usernameFeedback" class="error-text">Alphabetical characters only.</p> | ||
| </div> | ||
| </form> | ||
| <ul | ||
| class="list-unstyled row gy-large row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-xl-4 row-cols-2xl-5" | ||
| data-component-list | ||
| > | ||
| <slot /> | ||
| </ul> | ||
| </ouds-component-finder> | ||
|
|
||
| <script> | ||
| class OudsComponentFinder extends HTMLElement { | ||
| connectedCallback() { | ||
| const searchInput = document.getElementById('oudsComponentFinderInput') as HTMLInputElement | ||
| if (!searchInput) return | ||
| searchInput.addEventListener('input', () => { | ||
| setTimeout(() => { | ||
| this.querySelectorAll('ul[data-component-list] > *').forEach((elt) => elt.classList.remove('d-none')) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be in the if below ? to keep the already existing list instead of giving the whole list again ?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to reset the list when the input is emptied |
||
| if (searchInput.value && searchInput.checkValidity()) { | ||
| this.querySelectorAll( | ||
| `ul[data-component-list] > :not([data-name*="${searchInput.value.toLowerCase()}"])` | ||
| ).forEach((elt) => elt.classList.add('d-none')) | ||
| } | ||
| }, 0) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| customElements.define('ouds-component-finder', OudsComponentFinder) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we need the web component here, the js should work just fine even without it right ?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not per se, but it permits to constrain the JS to here. Also a thing proposed by Astro |
||
| </script> | ||
Uh oh!
There was an error while loading. Please reload this page.