Skip to content

Commit

Permalink
feat(drawer): exit animation applied for drawer component (#335)
Browse files Browse the repository at this point in the history
* feat(drawer): exit animation applied for drawer component

This also fixes the snapshot tests for drawer component.

* docs(drawer): re-use trigger method in story
  • Loading branch information
muratcorlu authored Dec 8, 2022
1 parent cf7c787 commit ce67b45
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 49 deletions.
31 changes: 31 additions & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
import { setCustomElementsManifest } from '@storybook/web-components';
import { makeDecorator } from "@storybook/addons";
import { html } from 'lit';
import isChromatic from 'chromatic/isChromatic';

import customElements from '../dist/custom-elements.json';

setCustomElementsManifest(customElements);

const withNoAnimationOnChromaticLayout = makeDecorator({
name: 'withNoAnimationOnChromaticLayout',
parameterName: 'noAnimationOnChromaticLayout',
skipIfNoParametersOrOptions: true,
wrapper: (getStory, context) => {
const story = getStory(context);
const decoratedStory = html`
${isChromatic() ? html`<style>
.custom-wrapper {
--bl-drawer-animation-duration: 0;
}
</style>` : html``}
<div class="custom-wrapper">
${ story }
</div>
`;

// return the modified story
return decoratedStory;
}
});

export const decorators = [
withNoAnimationOnChromaticLayout
]

export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
viewMode: 'docs',
Expand Down
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"@web/test-runner-playwright": "^0.8.6",
"@web/test-runner-puppeteer": "^0.10.5",
"@webcomponents/webcomponentsjs": "^2.5.0",
"chromatic": "^6.11.4",
"del": "^6.1.0",
"del-cli": "^5.0.0",
"esbuild": "^0.14.50",
Expand Down
29 changes: 15 additions & 14 deletions src/components/drawer/bl-drawer.css
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
@keyframes slide-from-right{
@keyframes slide-from-right {
0% {
transform: translateX(+100%);
transform: translateX(100%);
}

100% {
transform: translateX(0);
}
}

.drawer{
.drawer {
position: fixed;
top:0;
top: 0;
right: 0;
width: 424px;
height: 100%;
height: 100vh;
background: var(--bl-color-primary-background);
box-shadow: var(--bl-size-xs) 0 var(--bl-size-2xl) rgba(0 0 0 / 50%);
animation: 0.25s slide-from-right;

/* FIXME: Use z-index variable */
transform: translateX(100%);
transition: transform var(--bl-drawer-animation-duration, .25s);
z-index: 999;
}

iframe{
:host([open]) .drawer {
transform: translateX(0);
animation: slide-from-right var(--bl-drawer-animation-duration, .25s);
}

iframe {
height: 100%;
width: 100%;
border: none;
}

.container{
.container {
display: flex;
flex-direction: column;
width: 100%;
Expand All @@ -46,7 +50,7 @@ header {

header .header-buttons {
display: flex;
gap:24px;
gap: 24px;
margin-left: auto;
}

Expand Down Expand Up @@ -75,6 +79,3 @@ section {
width: calc(100vw - 24px);
}
}



51 changes: 25 additions & 26 deletions src/components/drawer/bl-drawer.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { Meta, Canvas, ArgsTable, Story, Preview, Source } from '@storybook/addo
component="bl-drawer"
parameters={{
layout: 'fullscreen',
chromatic: { viewports: [1000]},
noAnimationOnChromaticLayout: true,
chromatic: {
viewports: [768, 320],
},
}}
argTypes={{
open: {
Expand All @@ -29,46 +32,42 @@ import { Meta, Canvas, ArgsTable, Story, Preview, Source } from '@storybook/addo
}}
/>

export const openDialog = async (event,args) => {
const insideCanvas = !event.target || event.target.parentNode.parentNode.getAttribute("id") === "root";
let selector= insideCanvas ? `#root #${args.id}`: `#docs-root #${args.id}`;
const drawer = document.querySelector(selector);
drawer.open = true;
await new Promise(resolve => setTimeout(resolve,1000));
export const openDialog = async (event, args) => {
document.getElementById(args.id).open=true
}

export const DummyContent = () => html`
<div style="font: var(--bl-font-body-text-2)">
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</div>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
`

export const DrawerTemplate = (args) => html`
<bl-drawer id=${ifDefined(args.id)}
caption=${ifDefined(args.caption)}
embed-url=${ifDefined(args.embedUrl)}
external-link=${ifDefined(args.externalLink)}>
${ifDefined(args.content)}
<div style="font: var(--bl-font-body-text-2)">
${ifDefined(args.content)}
</div>
</bl-drawer>
`

export const StoryTemplate = (args) => html`
${DrawerTemplate(args)}
<bl-button @click="${(event)=>openDialog(event,args)}">${ifDefined(args.buttonText)}</bl-button>
<bl-button @click="${(event)=>openDialog(event, args)}">${ifDefined(args.buttonText)}</bl-button>
`

# Drawer
Expand Down
14 changes: 9 additions & 5 deletions src/components/drawer/bl-drawer.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {assert, elementUpdated, expect, fixture, html, oneEvent} from '@open-wc/testing';
import {assert, aTimeout, elementUpdated, expect, fixture, html, oneEvent} from '@open-wc/testing';
import BlDrawer from "./bl-drawer";
import type typeOfBlDrawer from './bl-drawer';

Expand Down Expand Up @@ -112,10 +112,14 @@ describe('bl-drawer',() => {
expect(el.open).to.equal(true);
closeBtn?.click();

setTimeout(()=>{
expect(el.open).to.equal(false);
expect(el.offsetWidth).to.equal(0);
});
await elementUpdated(el);

expect(el.open).to.equal(false);
expect(el.offsetWidth).to.equal(0);

await aTimeout(1100);

expect(el?.shadowRoot?.querySelector('bl-button')).to.be.null;
});
});
describe('event tests',()=>{
Expand Down
20 changes: 16 additions & 4 deletions src/components/drawer/bl-drawer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {customElement, property} from "lit/decorators.js";
import {customElement, property, state} from "lit/decorators.js";
import {CSSResultGroup, html, LitElement, TemplateResult} from "lit";
import {event, EventDispatcher} from "../../utilities/event";
import '../button/bl-button';
Expand Down Expand Up @@ -65,16 +65,30 @@ export default class BlDrawer extends LitElement{
}
}

private domExistenceSchedule: number;

private toggleDialogHandler() {
if (this.open) {
if (this.domExistenceSchedule) {
clearTimeout(this.domExistenceSchedule);
}

this.domExistence = true;
// FIXME: Allow events without payload
this.onOpen('');
} else {
// Give some time for exit animation
this.domExistenceSchedule = window.setTimeout(() => {
this.domExistence = false;
}, 1000);

// FIXME: Allow events without payload
this.onClose('');
}
}

@state() private domExistence = false;

private closeDrawer() {
this.open = false;
}
Expand Down Expand Up @@ -118,10 +132,8 @@ export default class BlDrawer extends LitElement{
</div>`;
}



render(): TemplateResult{
if(this.open){
if(this.domExistence){
return html`<div class="drawer">
${this.renderContainer()}
</div>`;
Expand Down

0 comments on commit ce67b45

Please sign in to comment.