-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
828270e
commit 76b22c4
Showing
37 changed files
with
215 additions
and
162 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,68 @@ | ||
/** | ||
* DisclosureButton class. | ||
*/ | ||
class DisclosureButton { | ||
/** | ||
* Constructor. | ||
* | ||
* @param {DomNode} label | ||
* @param {Object} options | ||
*/ | ||
constructor( label, options ) { | ||
this.label = label; | ||
this.container = this.label.parentNode; | ||
this.config = { | ||
...{ | ||
controlSelector: '.disclosure-button', | ||
buttonVariant: false, | ||
visuallyHiddenLabel: false, | ||
}, | ||
...options | ||
}; | ||
this.initDisclosure(); | ||
this.handleClick = this.handleClick.bind( this ); | ||
this.addEventListeners(); | ||
} | ||
|
||
/** | ||
* Initialize content within the disclosure. | ||
*/ | ||
initDisclosure() { | ||
const ctrl = document.createElement( 'button' ); | ||
const className = ( this.config.buttonVariant ) ? | ||
`button ${this.config.buttonVariant} disclosure-button` : | ||
'button disclosure-button'; | ||
const label = this.config.visuallyHiddenLabel ? | ||
`<span class="screen-reader-text">${this.label.textContent}</span>` : | ||
this.label.textContent; | ||
ctrl.setAttribute( 'class', className ); | ||
ctrl.setAttribute( 'aria-expanded', 'false' ); | ||
ctrl.setAttribute( 'type', 'button' ); | ||
ctrl.innerHTML = ` | ||
${label} | ||
<svg class="icon icon--chevron-down" viewBox="0 0 20 20" aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg"><path id="chevron-down" d="m10 15a1 1 0 0 1 -.71-.29l-5-5a1 1 0 0 1 1.42-1.42l4.29 4.3 4.29-4.3a1 1 0 0 1 1.42 1.42l-5 5a1 1 0 0 1 -.71.29z" fill="currentColor"/></svg> | ||
`; | ||
this.container.insertBefore( ctrl, this.label.nextElementSibling ); | ||
this.container.removeChild( this.label ); | ||
} | ||
|
||
/** | ||
* | ||
* @param {Event} event | ||
*/ | ||
handleClick( event ) { | ||
if ( ! event.target.closest( this.config.controlSelector ) ) return; | ||
const ctrl = event.target.closest( this.config.controlSelector ); | ||
const expanded = 'true' === ctrl.getAttribute( 'aria-expanded' ) || false; | ||
ctrl.setAttribute( 'aria-expanded', !expanded ); | ||
} | ||
|
||
/** | ||
* Add click event listeners. | ||
*/ | ||
addEventListeners() { | ||
this.container.addEventListener( 'click', this.handleClick, false ); | ||
} | ||
} | ||
|
||
export default DisclosureButton; |
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import Accordion from './Accordion/index.js'; | ||
import Card from './Card/index.js'; | ||
import DeselectAll from './DeselectAll/index.js'; | ||
import DisclosureButton from './DisclosureButton/index.js'; | ||
import FilterList from './FilterList/index.js'; | ||
import Icon from './Icon/index.js'; | ||
import Menu from './Menu/index.js'; | ||
import MenuButton from './MenuButton/index.js'; | ||
import NestedCheckbox from './NestedCheckbox/index.js'; | ||
import Notification from './Notification/index.js'; | ||
|
||
export default { Accordion, Card, DeselectAll, FilterList, Icon, Menu, MenuButton, NestedCheckbox, Notification }; | ||
export default { Accordion, Card, DeselectAll, DisclosureButton, FilterList, Icon, Menu, MenuButton, NestedCheckbox, Notification }; |
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 |
---|---|---|
@@ -1,76 +1,15 @@ | ||
.disclosure-button { | ||
align-items: center; | ||
background: $blue-50; | ||
border: solid rem(2) transparent; | ||
border-radius: 50%; | ||
color: $blue-500; | ||
display: inline-block; | ||
display: inline-flex; | ||
flex-direction: column; | ||
font-size: rem(16); | ||
height: rem(34); | ||
justify-content: center; | ||
margin: 0; | ||
padding: rem(6) 0; | ||
text-underline-offset: rem(8); | ||
width: rem(34); | ||
|
||
svg { | ||
margin-bottom: 0; | ||
transition: transform 0.5s; | ||
|
||
@media (prefers-reduced-motion: reduce) { | ||
transition: none; | ||
} | ||
} | ||
|
||
&:hover { | ||
background: $blue-150; | ||
} | ||
|
||
&:active { | ||
background: $blue-100; | ||
color: $blue-500; | ||
} | ||
|
||
&:focus { | ||
border-color: $blue-500; | ||
box-shadow: | ||
0 0 0 rem(2) $off-white, | ||
0 0 0 rem(4) $blue-500; | ||
outline: 0; | ||
} | ||
|
||
&[aria-expanded="true"] { | ||
svg { | ||
transform: rotate(-180deg); | ||
} | ||
} | ||
} | ||
|
||
.has-dark-mint-500-background-color .disclosure-button, | ||
.accordion--filter-list .disclosure-button { | ||
background: $blue-700; | ||
color: $off-white; | ||
|
||
&:hover { | ||
background: $true-black; | ||
} | ||
|
||
&:active { | ||
background: $blue-500; | ||
color: $off-white; | ||
} | ||
|
||
&:focus { | ||
border-color: $off-white; | ||
box-shadow: | ||
0 0 0 rem(2) $black, | ||
0 0 0 rem(4) $off-white; | ||
} | ||
} | ||
|
||
.disclosure-button:active:focus { | ||
border-color: transparent; | ||
box-shadow: none; | ||
} |
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 |
---|---|---|
|
@@ -18,3 +18,7 @@ | |
height: 2.5em; | ||
width: 2.5em; | ||
} | ||
|
||
.screen-reader-text + svg { | ||
margin-left: 0; | ||
} |
Oops, something went wrong.