Skip to content

Instantly share code, notes, and snippets.

View dbismut's full-sized avatar
🏠
Working from home

David Bismut dbismut

🏠
Working from home
View GitHub Profile
// OPTION 1
// Close Icon managed by CTO, alert managed by CTO
TryOn.init({
events: {
close: () => {
window.modal.close(); // closes the popin embedding the CTO experience
}
}
});
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"jest": true,
"node": true
},
"globals": {},
"parser": "/Users/david/repos/useAudioPlayer/node_modules/babel-eslint/lib/index.js",
@dbismut
dbismut / Post.js
Created April 9, 2018 16:55
Part 3 - changing the render to implement the close icon state
render() {
/* ... */
const { closeInverted, dragProgress } = this.state; // change the state
return (
/* same code */
// this will add the invert class
// when this.state.closeInverted is true
<div
@dbismut
dbismut / Post.js
Created April 9, 2018 16:51
Part 3 - Modifying the onScroll method for handling the closeInvert state
state = {
dragProgress: 0,
closeInverted: false,
};
onScroll = () => {
/* same code */
// handling close icon color
const threshold = scrollTop / CLOSE_INVERTED_THRESHOLD;
@dbismut
dbismut / Post.scss
Created April 9, 2018 16:47
Part 3 - Adding the invert class for the close icon
.close.invert {
background: #000;
&::after,
&::before {
background: #fff;
}
}
@dbismut
dbismut / Post.js
Created April 9, 2018 15:24
Part 3 - Last details and animation width
executeEnteringTransition = (node, done) => {
/* same code */
const {
height: heightFrom,
top: topFrom,
scale: scaleFrom,
...mainFrom
} = this.from;
const { height: heightTo, top: topTo, scale: scaleTo, ...mainTo } = this.to;
@dbismut
dbismut / Post.js
Last active April 9, 2018 15:03
Part 3 - Setting scale for the preview node
getPreviewStyleAndPosition = () => {
const { top, width, height } = this.preview.getBoundingClientRect();
const transformMatrix = window.getComputedStyle(this.preview).transform;
// transformMatrix is either 'none', or a string in the form of
// matrix(0.965, 0, 0, 0.965, 0, 0)
const scale =
transformMatrix.indexOf('matrix') === 0
? parseFloat(transformMatrix.split(', ')[3])
@dbismut
dbismut / Preview.js
Last active April 9, 2018 14:55
Part 3 - Starting with Pressure.js
import React, { PureComponent } from 'react';
import Pressure from 'pressure';
const PRESSED_SCALE = 0.95;
// minimum scale applied to the preview node
export default class Preview extends PureComponent {
state = { force: 0 };
timer = null;
@dbismut
dbismut / Post.scss
Last active April 9, 2018 21:09
Part 3 - Classes that will animate the underlay and close icon
.page-post {
&.post-exit,
&.post-enter {
.content,
.close,
.underlay {
opacity: 0;
}
.underlay {
transition-delay: 0;
@dbismut
dbismut / Post.js
Last active April 9, 2018 22:14
Part 3 - Adding the .post-enter-started class
executeEnteringTransition = (node, done) => {
this.postStyler.set({ ...this.from, visibility: 'visible' });
node.classList.add('post-enter-started'); // add this line
/* same code */
complete: () => {
node.classList.remove('post-enter-started'); // add this line
done();
}