Skip to content

Commit

Permalink
feat(ld-accordion): implement accordion component
Browse files Browse the repository at this point in the history
Resolves #127
  • Loading branch information
borisdiakur committed Mar 28, 2022
1 parent 916d465 commit 709ed6b
Show file tree
Hide file tree
Showing 37 changed files with 2,707 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ module.exports = function (eleventyConfig) {
if (link.startsWith('./')) {
const splitted = env.page.url.split('/')
splitted.splice(splitted.length - 1, 0, link.substr(2))
return base + splitted.join('/')
return base + splitted.join('/').replace(/\/$/, '')
}
if (link.startsWith('../')) {
const splitted = env.page.url.split('/')
splitted.splice(splitted.length - 2, 1, link.substr(3))
return base + splitted.join('/')
return base + splitted.join('/').replace(/\/$/, '')
}
return link
},
Expand Down
208 changes: 208 additions & 0 deletions screenshot/builds/master.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,214 @@
"appNamespace": "liquid",
"timestamp": 1636634469855,
"screenshots": [
{
"id": "85cea231",
"image": "8412edfe77a00dbd21ac8733de7cd674.png",
"userAgent": "default",
"desc": "ld-accordion active",
"testPath": "./src/liquid/components/ld-accordion/test/ld-accordion.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "530617cc",
"image": "fdaad58965e44e3207b581a995f23a8f.png",
"userAgent": "default",
"desc": "ld-accordion auto-scroll auto-scrolls, after expansion of inner panel",
"testPath": "./src/liquid/components/ld-accordion/test/ld-accordion.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "a7a92ded",
"image": "ed3e04ea46b8f1765886cffca3c20ece.png",
"userAgent": "default",
"desc": "ld-accordion auto-scroll auto-scrolls, after expansion of outer panel",
"testPath": "./src/liquid/components/ld-accordion/test/ld-accordion.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "2c314b53",
"image": "93096990d6d56c8984397c43c940cc40.png",
"userAgent": "default",
"desc": "ld-accordion dark",
"testPath": "./src/liquid/components/ld-accordion/test/ld-accordion.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "8ffb6073",
"image": "3e393f417b244ad45348ae038de3bfba.png",
"userAgent": "default",
"desc": "ld-accordion default",
"testPath": "./src/liquid/components/ld-accordion/test/ld-accordion.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "0dfcabc5",
"image": "797c63c997908b064bfbfdd428eedd70.png",
"userAgent": "default",
"desc": "ld-accordion detached",
"testPath": "./src/liquid/components/ld-accordion/test/ld-accordion.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "40ae5b92",
"image": "b276ce7160fc59d2f44e712284f6518a.png",
"userAgent": "default",
"desc": "ld-accordion focus",
"testPath": "./src/liquid/components/ld-accordion/test/ld-accordion.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "90a92378",
"image": "6a3d2f5d69997b08e4d57d12d910d312.png",
"userAgent": "default",
"desc": "ld-accordion hover",
"testPath": "./src/liquid/components/ld-accordion/test/ld-accordion.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "3421a2a3",
"image": "f045d4123934fdc08c5ebccf9959bc1d.png",
"userAgent": "default",
"desc": "ld-accordion nested",
"testPath": "./src/liquid/components/ld-accordion/test/ld-accordion.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "14103e65",
"image": "f20d59ceee7f3e319fa24fe27301d1bd.png",
"userAgent": "default",
"desc": "ld-accordion on brand color",
"testPath": "./src/liquid/components/ld-accordion/test/ld-accordion.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "9ecfc80b",
"image": "0c07b0d8b057c72861b4a6930daaee3e.png",
"userAgent": "default",
"desc": "ld-accordion on brand color active",
"testPath": "./src/liquid/components/ld-accordion/test/ld-accordion.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "74d4ca32",
"image": "2d7d26ffb7488aa821a0148c7d3f48a6.png",
"userAgent": "default",
"desc": "ld-accordion on brand color focus",
"testPath": "./src/liquid/components/ld-accordion/test/ld-accordion.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "ec6c8b95",
"image": "19796773fd85180c49ea3c1844edc5ed.png",
"userAgent": "default",
"desc": "ld-accordion on brand color hover",
"testPath": "./src/liquid/components/ld-accordion/test/ld-accordion.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "75c6a116",
"image": "316e34c0736fb9e823f537ed66ab05de.png",
"userAgent": "default",
"desc": "ld-accordion rounded",
"testPath": "./src/liquid/components/ld-accordion/test/ld-accordion.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "3684a2d1",
"image": "1031d132d455336837fb0a102533678e.png",
"userAgent": "default",
"desc": "ld-accordion split focus label",
"testPath": "./src/liquid/components/ld-accordion/test/ld-accordion.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "54b9bb4c",
"image": "577a4b8a58d60a43c4240b1108effaaf.png",
"userAgent": "default",
"desc": "ld-accordion split focus trigger",
"testPath": "./src/liquid/components/ld-accordion/test/ld-accordion.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "d4180b1a",
"image": "8c7d88309af50761a7f679a70b1daab7.png",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
:host {
/* Not using 0s here because we rely on the transition end event. */
--ld-accordion-panel-transition-duration: 0.001s;

position: relative;
display: block;
box-sizing: border-box;
max-height: var(--ld-accordion-panel-max-height, auto);
overflow: hidden;
background-color: var(--ld-accordion-bg-col);
border-radius: var(--ld-accordion-border-radius);
border-top-left-radius: inherit;
border-top-right-radius: inherit;
will-change: max-height;

&(.ld-accordion-panel--initialized) {
/* stylelint-disable-next-line plugin/no-low-performance-animation-properties */
transition: max-height var(--ld-accordion-panel-transition-duration) ease;

@media (prefers-reduced-motion: no-preference) {
--ld-accordion-panel-transition-duration: 0.2s;
}
}

&(.ld-accordion-panel--expanded) {
&::before {
content: '';
height: var(--ld-sp-1);
background-color: var(--ld-accordion-panel-border-top-color);
position: absolute;
top: 0;
left: 0;
right: 0;
}

.ld-accordion-panel__content {
opacity: 1;
visibility: inherit;
transition: opacity var(--ld-accordion-panel-transition-duration) linear;
}
}
}

.ld-accordion-panel__content {
opacity: 0;
visibility: hidden;
transition: opacity var(--ld-accordion-panel-transition-duration) linear,
visibility 0s var(--ld-accordion-panel-transition-duration) linear;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import '../../../components' // type definitions for type checks and intelliSense
import { Component, Element, h, Host, Method, State } from '@stencil/core'
import { getClassNames } from '../../../utils/getClassNames'
import { closest } from '../../../utils/closest'

/**
* @virtualProp ref - reference to component
* @virtualProp {string | number} key - for tracking the node's identity when working with lists
*/
@Component({
tag: 'ld-accordion-panel',
styleUrl: 'ld-accordion-panel.css',
shadow: true,
})
export class LdAccordionPanel {
@Element() el: HTMLElement

// Container to be observed for size changes.
// Note that we can not observe size changes on the element itself,
// As with the max-height prop applied to it changes to the content
// will not trigger a resize event. Hence, we use a container element.
private contentRef: HTMLDivElement

@State() expanded: boolean
@State() initialized = false
@State() transitionEnabled = false
@State() maxHeight: number
@State() resizeObserver: ResizeObserver
@State() innerPanelExpanding = false

/**
* @internal
* Updates expanded state.
*/
@Method()
async applyMaxHeight(additionalHeightFromInnerPanel = 0) {
if (additionalHeightFromInnerPanel) {
this.innerPanelExpanding = true
}

// Apply max height on outer panel inside nested accordion.
if (this.expanded) {
const closestPanel = closest('ld-accordion-panel', this.el.parentElement)
closestPanel?.applyMaxHeight(this.el.scrollHeight)
}

this.maxHeight = this.expanded
? this.el.scrollHeight + additionalHeightFromInnerPanel
: 0
}

/**
* @internal
* Updates expanded state.
*/
@Method()
async setExpanded(expanded: boolean) {
this.expanded = expanded

this.applyMaxHeight()
}

private onTransitionEnd = (ev: TransitionEvent) => {
if (ev.target === this.el) {
this.innerPanelExpanding = false
}
}

componentDidLoad() {
setTimeout(() => {
this.resizeObserver = new ResizeObserver(() => {
// When a panel is expanding inside a nested accordion, the nested panel
// takes over the responsibility for updating the max-height on the outer
// panel. In other words: We disable the observer callback function in
// order to instantly update the max-height for a better performance.
if (!this.innerPanelExpanding) {
this.applyMaxHeight()
}
})
this.resizeObserver.observe(this.contentRef)
this.initialized = true
})
}

disconnectedCallback() {
this.resizeObserver.unobserve(this.contentRef)
}

render() {
const cl = getClassNames([
'ld-accordion-panel',
this.expanded && 'ld-accordion-panel--expanded',
this.initialized && 'ld-accordion-panel--initialized',
])

return (
<Host
style={{ '--ld-accordion-panel-max-height': this.maxHeight + 'px' }}
class={cl}
onTransitionEnd={this.onTransitionEnd}
>
<div
ref={(ref) => (this.contentRef = ref)}
class="ld-accordion-panel__content"
>
<slot></slot>
</div>
</Host>
)
}
}
Loading

0 comments on commit 709ed6b

Please sign in to comment.