Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions components/composition/Enter/Enter.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,38 @@
}

dmd-enter {
animation-duration: var(--dmd-transition-duration-enter);
animation-fill-mode: forwards;
animation-iteration-count: 1;
animation-name: var(--dmd-transition-enter-animation);
animation-timing-function: var(--dmd-transition-timing-enter);
display: block;
opacity: 0;

&[delay] {
animation-delay: var(--dmd-transition-enter-delay);
&[type='fade'] {
animation-name: fade;
}

&[type='fade-in-up'] {
animation-name: fade-in-up;
}

&[type='boing'] {
animation-name: boing;
animation-timing-function: var(--dmd-transition-timing-boing);
}

&[type] {
animation-duration: var(--dmd-transition-duration-enter);
animation-fill-mode: forwards;
animation-iteration-count: 1;
animation-timing-function: var(--dmd-transition-timing-enter);
}

&[delay] {
animation-delay: attr(delay s, 0s);
}

&[enter-on-scroll]:not([enter-on-scroll='false']) {
animation-range: entry 0% entry 25%;
animation-timeline: view();
}

&[fill] {
display: grid;
}
Expand Down
5 changes: 2 additions & 3 deletions components/composition/Enter/Enter.stories.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { StoryObj } from '@storybook/web-components';
import { html } from 'lit';

import './Enter';

export default {
component: 'dmd-enter',
argTypes: {
Expand Down Expand Up @@ -49,8 +47,9 @@ export const OnScroll: StoryObj = {
enter-on-scroll="${args.enterOnScroll}"
delay="${args.delay}"
>
<div style="background-color: #eee; height: 400px;"></div>
<div style="background-color: #eee; height: 100px;"></div>
</dmd-enter>
<div style="height: 120vh;">Scroll down</div>
`,
};

Expand Down
51 changes: 0 additions & 51 deletions components/composition/Enter/Enter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { LitElement, html } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';

import { JSXCustomElement } from '../../../types/jsx-custom-element';

export interface EnterAttributes {
Expand All @@ -13,54 +10,6 @@ export interface EnterAttributes {
fill?: string | boolean;
}

@customElement('dmd-enter')
export class Enter extends LitElement {
observer?: IntersectionObserver;
@state() inView: boolean = false;
@property({ reflect: true }) type?: 'fade' | 'fade-in-up' | 'boing';
@property({ reflect: true, attribute: 'enter-on-scroll' })
enterOnScroll?: string | boolean;
@property({ reflect: true }) delay?: string | number;
@property({ reflect: true }) fill?: string | boolean;

connectedCallback(): void {
super.connectedCallback();
if (this.enterOnScroll) {
this.observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
this.inView = true;
this.observer?.unobserve(this);
}
});
},
{ threshold: 0 },
);
this.observer.observe(this);
}
}

disconnectedCallback(): void {
super.disconnectedCallback();
this.observer?.disconnect();
}

render() {
const type = this.inView || !this.enterOnScroll ? this.type : '';

return html`
<style>
:host {
--dmd-transition-enter-delay: ${this.delay}s;
--dmd-transition-enter-animation: ${type};
}
</style>
<slot></slot>
`;
}
}

declare global {
interface HTMLElementTagNameMap {
'dmd-enter': EnterAttributes;
Expand Down
6 changes: 6 additions & 0 deletions stylelint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@ module.exports = {
ignoreAtRules: ['starting-style'],
},
],
'property-no-unknown': [
true,
{
ignoreProperties: ['animation-timeline', 'animation-range'],
},
],
},
};
Loading