-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5235 from hashicorp/f-ui-faceted-search
UI: Faceted Search
- Loading branch information
Showing
32 changed files
with
1,669 additions
and
21 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,9 @@ | ||
// Breakpoints are meant to match Bulma's breakpoints and any additional custom breakpoints | ||
// https://github.com/jgthms/bulma/blob/6ad2e3df0589e5d6ff7a9c03ee1c78a546bedeaf/sass/utilities/initial-variables.sass#L48-L59 | ||
// https://github.com/jgthms/bulma/blob/6ad2e3df0589e5d6ff7a9c03ee1c78a546bedeaf/sass/utilities/mixins.sass#L71-L130 | ||
export default { | ||
mobile: '(max-width: 768px)', | ||
tablet: '(min-width: 769px)', | ||
desktop: '(min-width: 1088px)', | ||
gutterless: '(max-width: 960px)', | ||
}; |
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,45 @@ | ||
import Component from '@ember/component'; | ||
import { computed } from '@ember/object'; | ||
|
||
export default Component.extend({ | ||
options1: computed(() => [ | ||
{ key: 'option-1', label: 'Option One' }, | ||
{ key: 'option-2', label: 'Option Two' }, | ||
{ key: 'option-3', label: 'Option Three' }, | ||
{ key: 'option-4', label: 'Option Four' }, | ||
{ key: 'option-5', label: 'Option Five' }, | ||
]), | ||
|
||
selection1: computed(() => ['option-2', 'option-4', 'option-5']), | ||
|
||
optionsMany: computed(() => | ||
Array(100) | ||
.fill(null) | ||
.map((_, i) => ({ label: `Option ${i}`, key: `option-${i}` })) | ||
), | ||
selectionMany: computed(() => []), | ||
|
||
optionsDatacenter: computed(() => [ | ||
{ key: 'pdx-1', label: 'pdx-1' }, | ||
{ key: 'jfk-1', label: 'jfk-1' }, | ||
{ key: 'jfk-2', label: 'jfk-2' }, | ||
{ key: 'muc-1', label: 'muc-1' }, | ||
]), | ||
selectionDatacenter: computed(() => ['jfk-1', 'jfk-2']), | ||
|
||
optionsType: computed(() => [ | ||
{ key: 'batch', label: 'Batch' }, | ||
{ key: 'service', label: 'Service' }, | ||
{ key: 'system', label: 'System' }, | ||
{ key: 'periodic', label: 'Periodic' }, | ||
{ key: 'parameterized', label: 'Parameterized' }, | ||
]), | ||
selectionType: computed(() => ['system', 'service']), | ||
|
||
optionsStatus: computed(() => [ | ||
{ key: 'pending', label: 'Pending' }, | ||
{ key: 'running', label: 'Running' }, | ||
{ key: 'dead', label: 'Dead' }, | ||
]), | ||
selectionStatus: computed(() => []), | ||
}); |
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,98 @@ | ||
import Component from '@ember/component'; | ||
import { computed } from '@ember/object'; | ||
import { run } from '@ember/runloop'; | ||
|
||
const TAB = 9; | ||
const ESC = 27; | ||
const SPACE = 32; | ||
const ARROW_UP = 38; | ||
const ARROW_DOWN = 40; | ||
|
||
export default Component.extend({ | ||
classNames: ['dropdown'], | ||
|
||
options: computed(() => []), | ||
selection: computed(() => []), | ||
|
||
onSelect() {}, | ||
|
||
isOpen: false, | ||
dropdown: null, | ||
|
||
capture(dropdown) { | ||
// It's not a good idea to grab a dropdown reference like this, but it's necessary | ||
// in order to invoke dropdown.actions.close in traverseList as well as | ||
// dropdown.actions.reposition when the label or selection length changes. | ||
this.set('dropdown', dropdown); | ||
}, | ||
|
||
didReceiveAttrs() { | ||
const dropdown = this.get('dropdown'); | ||
if (this.get('isOpen') && dropdown) { | ||
run.scheduleOnce('afterRender', () => { | ||
dropdown.actions.reposition(); | ||
}); | ||
} | ||
}, | ||
|
||
actions: { | ||
toggle({ key }) { | ||
const newSelection = this.get('selection').slice(); | ||
if (newSelection.includes(key)) { | ||
newSelection.removeObject(key); | ||
} else { | ||
newSelection.addObject(key); | ||
} | ||
this.get('onSelect')(newSelection); | ||
}, | ||
|
||
openOnArrowDown(dropdown, e) { | ||
this.capture(dropdown); | ||
|
||
if (!this.get('isOpen') && e.keyCode === ARROW_DOWN) { | ||
dropdown.actions.open(e); | ||
e.preventDefault(); | ||
} else if (this.get('isOpen') && (e.keyCode === TAB || e.keyCode === ARROW_DOWN)) { | ||
const optionsId = this.element.querySelector('.dropdown-trigger').getAttribute('aria-owns'); | ||
const firstElement = document.querySelector(`#${optionsId} .dropdown-option`); | ||
|
||
if (firstElement) { | ||
firstElement.focus(); | ||
e.preventDefault(); | ||
} | ||
} | ||
}, | ||
|
||
traverseList(option, e) { | ||
if (e.keyCode === ESC) { | ||
// Close the dropdown | ||
const dropdown = this.get('dropdown'); | ||
if (dropdown) { | ||
dropdown.actions.close(e); | ||
// Return focus to the trigger so tab works as expected | ||
const trigger = this.element.querySelector('.dropdown-trigger'); | ||
if (trigger) trigger.focus(); | ||
e.preventDefault(); | ||
this.set('dropdown', null); | ||
} | ||
} else if (e.keyCode === ARROW_UP) { | ||
// previous item | ||
const prev = e.target.previousElementSibling; | ||
if (prev) { | ||
prev.focus(); | ||
e.preventDefault(); | ||
} | ||
} else if (e.keyCode === ARROW_DOWN) { | ||
// next item | ||
const next = e.target.nextElementSibling; | ||
if (next) { | ||
next.focus(); | ||
e.preventDefault(); | ||
} | ||
} else if (e.keyCode === SPACE) { | ||
this.send('toggle', option); | ||
e.preventDefault(); | ||
} | ||
}, | ||
}, | ||
}); |
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
Oops, something went wrong.