boron-15
Version:
A collection of dialog animations for React 15+
147 lines (135 loc) • 4.27 kB
JavaScript
var React = require('react');
var modalFactory = require('./modalFactory');
var insertKeyframesRule = require('domkit/insertKeyframesRule');
var appendVendorPrefix = require('domkit/appendVendorPrefix');
var animation = {
show: {
animationDuration: '0.8s',
animationTimingFunction: 'cubic-bezier(0.6,0,0.4,1)'
},
hide: {
animationDuration: '0.4s',
animationTimingFunction: 'ease-out'
},
showContentAnimation: insertKeyframesRule({
'0%': {
opacity: 0,
},
'40%':{
opacity: 0
},
'100%': {
opacity: 1,
}
}),
hideContentAnimation: insertKeyframesRule({
'0%': {
opacity: 1
},
'100%': {
opacity: 0,
}
}),
showBackdropAnimation: insertKeyframesRule({
'0%': {
opacity: 0
},
'100%': {
opacity: 0.9
},
}),
hideBackdropAnimation: insertKeyframesRule({
'0%': {
opacity: 0.9
},
'100%': {
opacity: 0
}
})
};
var showAnimation = animation.show;
var hideAnimation = animation.hide;
var showContentAnimation = animation.showContentAnimation;
var hideContentAnimation = animation.hideContentAnimation;
var showBackdropAnimation = animation.showBackdropAnimation;
var hideBackdropAnimation = animation.hideBackdropAnimation;
module.exports = modalFactory({
getRef: function(willHidden) {
return 'content';
},
getSharp: function(willHidden) {
var strokeDashLength = 1680;
var showSharpAnimation = insertKeyframesRule({
'0%': {
'stroke-dashoffset': strokeDashLength
},
'100%': {
'stroke-dashoffset': 0
},
});
var sharpStyle = {
position: 'absolute',
width: 'calc(100%)',
height: 'calc(100%)',
zIndex: '-1'
};
var rectStyle = appendVendorPrefix({
animationDuration: willHidden? '0.4s' :'0.8s',
animationFillMode: 'forwards',
animationName: willHidden? hideContentAnimation: showSharpAnimation,
stroke: '#ffffff',
strokeWidth: '2px',
strokeDasharray: strokeDashLength
});
return React.createElement("div", {style: sharpStyle},
React.createElement("svg", {
xmlns: "http://www.w3.org/2000/svg",
width: "100%",
height: "100%",
viewBox: "0 0 496 136",
preserveAspectRatio: "none"},
React.createElement("rect", {style: rectStyle,
x: "2",
y: "2",
fill: "none",
width: "492",
height: "132"})
)
)
},
getModalStyle: function(willHidden) {
return appendVendorPrefix({
zIndex: 1050,
position: "fixed",
width: "500px",
transform: "translate3d(-50%, -50%, 0)",
top: "50%",
left: "50%"
})
},
getBackdropStyle: function(willHidden) {
return appendVendorPrefix({
position: "fixed",
top: 0,
right: 0,
bottom: 0,
left: 0,
zIndex: 1040,
backgroundColor: "#373A47",
animationFillMode: 'forwards',
animationDuration: '0.4s',
animationName: willHidden ? hideBackdropAnimation : showBackdropAnimation,
animationTimingFunction: (willHidden ? hideAnimation : showAnimation).animationTimingFunction
});
},
getContentStyle: function(willHidden) {
return appendVendorPrefix({
margin: 0,
backgroundColor: "white",
animationDuration: (willHidden ? hideAnimation : showAnimation).animationDuration,
animationFillMode: 'forwards',
animationName: willHidden ? hideContentAnimation : showContentAnimation,
animationTimingFunction: (willHidden ? hideAnimation : showAnimation).animationTimingFunction
})
}
});