Skip to content

Commit

Permalink
Merge pull request #601 from sveltejs/gh-574
Browse files Browse the repository at this point in the history
apply t0 styles to nodes if css transition has delay
  • Loading branch information
Rich-Harris authored May 28, 2017
2 parents 1db0d46 + b831d6c commit 31d8ef6
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ coverage.lcov
test/sourcemaps/samples/*/output.js
test/sourcemaps/samples/*/output.js.map
_actual.*
src/generators/dom/shared.ts
35 changes: 0 additions & 35 deletions src/generators/dom/shared.ts

This file was deleted.

11 changes: 10 additions & 1 deletion src/shared/transitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@ export function wrapTransition ( node, fn, params, intro, outgroup ) {
var obj = fn( node, params );
var duration = obj.duration || 300;
var ease = obj.easing || linear;
var cssText;

// TODO share <style> tag between all transitions?
if ( obj.css ) {
var style = document.createElement( 'style' );
}

if ( intro && obj.tick ) obj.tick( 0 );
if ( intro ) {
if ( obj.css && obj.delay ) {
cssText = node.style.cssText;
node.style.cssText += obj.css( 0 );
}

if ( obj.tick ) obj.tick( 0 );
}

return {
t: intro ? 0 : 1,
Expand Down Expand Up @@ -70,6 +78,7 @@ export function wrapTransition ( node, fn, params, intro, outgroup ) {
program.end = program.start + program.duration;

if ( obj.css ) {
if ( obj.delay ) node.style.cssText = cssText;
generateKeyframes( program.a, program.b, program.delta, program.duration, ease, obj.css, node, style );
}

Expand Down
12 changes: 12 additions & 0 deletions test/runtime/samples/transition-css-delay/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
test ( assert, component, target, window, raf ) {
component.set({ visible: true });
const div = target.querySelector( 'div' );
assert.strictEqual( div.style.opacity, '0' );

raf.tick( 50 );
assert.strictEqual( div.style.opacity, '' );

component.destroy();
}
};
19 changes: 19 additions & 0 deletions test/runtime/samples/transition-css-delay/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{#if visible}}
<div transition:foo>delayed</div>
{{/if}}

<script>
export default {
transitions: {
foo: function ( node, params ) {
return {
delay: 50,
duration: 100,
css: t => {
return `opacity: ${t}`;
}
};
}
}
};
</script>

0 comments on commit 31d8ef6

Please sign in to comment.