-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* First draft accordion component * Further changes to the new accordion * Fix incorrectly nested CSS * Update CHANGELOG.md * Export Accordion from all.mjs * Remove double marker on accordions in Safari * Lint * Add TODO * Update Jest ignore paths * Add details component * Small CSS tweaks
- Loading branch information
Showing
32 changed files
with
1,028 additions
and
66 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@use "accordion"; |
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,35 @@ | ||
export class Accordion { | ||
polyfillRequired = null; | ||
|
||
constructor($module) { | ||
this.$module = $module; | ||
this.$firstDetailsElement = | ||
$module && $module.querySelector(".tna-accordion__details[name]"); | ||
this.$detailsElements = | ||
$module && | ||
this.$firstDetailsElement && | ||
document.querySelectorAll( | ||
`.tna-accordion__details[name="${this.$firstDetailsElement.getAttribute("name")}"]`, | ||
); | ||
if (!this.$module || !this.$detailsElements) { | ||
return; | ||
} | ||
|
||
Array.from(this.$detailsElements).forEach(($detailsElement) => { | ||
$detailsElement.addEventListener("toggle", (e) => { | ||
const $thisDetailsElement = e.target; | ||
if ($thisDetailsElement.hasAttribute("open")) { | ||
Array.from(this.$detailsElements) | ||
.filter( | ||
($eachDetailsElement) => | ||
$eachDetailsElement !== $thisDetailsElement && | ||
$eachDetailsElement.hasAttribute("open"), | ||
) | ||
.forEach(($eachDetailsElement) => | ||
$eachDetailsElement.removeAttribute("open"), | ||
); | ||
} | ||
}); | ||
}); | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
src/nationalarchives/components/accordion/accordion.scss
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,116 @@ | ||
@use "sass:math"; | ||
@use "../../tools/colour"; | ||
@use "../../tools/spacing"; | ||
@use "../../tools/typography"; | ||
|
||
.tna-accordion { | ||
@include spacing.space-above; | ||
|
||
@include colour.colour-border("keyline", 1px, solid, top); | ||
// @include colour.thick-keyline-dark(top); | ||
// @include colour.thick-keyline-accent(top); | ||
|
||
&__details { | ||
@include colour.colour-border("keyline", 1px, solid, bottom); | ||
|
||
position: relative; | ||
z-index: 1; | ||
} | ||
|
||
&__details:has(&__summary:focus) { | ||
z-index: 2; | ||
} | ||
|
||
&__summary { | ||
padding: spacing.space(0.5) spacing.space(2.5) spacing.space(0.5) | ||
spacing.space(1); | ||
|
||
position: relative; | ||
|
||
@include typography.main-font-weight-bold; | ||
list-style: none; | ||
|
||
border-radius: 0.1px; | ||
|
||
cursor: pointer; | ||
|
||
&::-webkit-details-marker { | ||
display: none; | ||
} | ||
|
||
&::before { | ||
content: ""; | ||
|
||
width: 0; | ||
height: 0; | ||
|
||
position: absolute; | ||
top: calc(50% - 0.5rem); | ||
right: 0.75rem; | ||
|
||
border-width: #{math.div(math.sqrt(3), 2)}rem 0.5rem 0 0.5rem; | ||
border-color: colour.colour-var("font-light") transparent transparent | ||
transparent; | ||
border-style: solid; | ||
} | ||
|
||
&:hover { | ||
@include typography.interacted-text-decoration; | ||
@include colour.colour-background("background-tint"); | ||
|
||
&::before { | ||
border-top-color: colour.colour-var("font-dark"); | ||
} | ||
} | ||
} | ||
|
||
&__content { | ||
padding: spacing.space(1); | ||
|
||
&:has(.tna-table-wrapper):has(.tna-table) { | ||
padding-right: 0; | ||
padding-left: 0; | ||
|
||
.tna-table { | ||
&__caption { | ||
padding-top: 0; | ||
padding-bottom: spacing.space(1); | ||
|
||
font-size: inherit; | ||
line-height: inherit; | ||
text-align: left; | ||
caption-side: top; | ||
} | ||
} | ||
|
||
.tna-table-wrapper { | ||
padding-right: 0; | ||
padding-left: 0; | ||
|
||
left: 0; | ||
|
||
.tna-table { | ||
width: calc(100% - #{spacing.space(2)}); | ||
margin-right: spacing.space(1); | ||
margin-left: spacing.space(1); | ||
} | ||
} | ||
} | ||
} | ||
|
||
&__details[open] &__summary { | ||
&::before { | ||
top: calc(50% - #{math.div(math.sqrt(3), 4)}rem); | ||
|
||
border-width: 0 0.5rem #{math.div(math.sqrt(3), 2)}rem 0.5rem; | ||
border-color: transparent transparent colour.colour-var("font-light") | ||
transparent; | ||
} | ||
|
||
&:hover { | ||
&::before { | ||
border-bottom-color: colour.colour-var("font-dark"); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.