react-quick-reactions
Version:
A popup emoji-reaction component for React.
147 lines (135 loc) • 4.06 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReactionElement = exports.SelectionContainer = exports.Header = exports.CloseButton = exports.OuterDiv = exports.PopupPositioningWrapper = exports.Overlay = void 0;
const react_1 = require("@emotion/react");
const styled_1 = __importDefault(require("@emotion/styled"));
const styleUtils_1 = require("./styleUtils");
exports.Overlay = styled_1.default.div `
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: 500;
`;
// Separating the placement calculation from the rest of OuterDiv allows me to use transform for animations.
exports.PopupPositioningWrapper = styled_1.default.div `
position: absolute;
z-index: 501;
${({ triggerTransformValues, placement, arrayLength, hideHeader, wide }) => triggerTransformValues &&
(0, react_1.css) `
transform: translate(
${(0, styleUtils_1.calculatePopupTranslate)(triggerTransformValues,
// This solution assumes the height and width are calculated based on the standards I defined,
// not on actual height/width, which could be changed by the user.
wide ? (0, styleUtils_1.calcWidth)(arrayLength) : 150, (0, styleUtils_1.calcHeight)(arrayLength, hideHeader, wide), placement)}
);
`}
`;
exports.OuterDiv = styled_1.default.div `
width: ${({ wide, arrayLength = 8 }) => wide ? (0, styleUtils_1.calcWidth)(arrayLength) + "px" : "150px"};
height: ${({ hideHeader, wide, arrayLength }) => (0, styleUtils_1.calcHeight)(arrayLength, hideHeader, wide)}px;
border-radius: 4px;
border: 1px solid #c6d6eb;
background: white;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 2px 6px rgba(0, 0, 0, 0.06),
0 3px 8px rgba(0, 0, 0, 0.09);
overflow: hidden;
visibility: ${({ visible }) => (visible ? "visible" : "hidden")};
opacity: ${({ visible }) => (visible ? "1" : "0")};
transition: opacity 0.15s;
animation: ${({ visible, animation }) => visible && `${animation} 0.1s ease-in 1`};
@keyframes drop {
from {
height: ${({ hideHeader, wide, arrayLength }) => (0, styleUtils_1.calcHeight)(arrayLength, hideHeader, wide) - 20}px;
}
to {
height: ${({ hideHeader, wide, arrayLength }) => (0, styleUtils_1.calcHeight)(arrayLength, hideHeader, wide) + 10}px;
}
}
@keyframes fade {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes flip {
0% {
perspective: 500px;
transform: rotateX(70deg);
}
100% {
perspective: 500px;
transform: rotateX(-35deg);
}
}
@keyframes zoom {
from {
transform: scale(0, 0);
}
to {
transform: scale(1, 1);
}
}
`;
exports.CloseButton = styled_1.default.span `
position: absolute;
top: 4px;
right: ${({ wide }) => (wide ? 4 : 8)}px;
font-size: 0.8rem;
cursor: pointer;
font-weight: bold;
fill: lightgrey;
:hover {
> svg {
fill: #969696;
}
}
:active {
> svg {
fill: #434343;
}
}
`;
exports.Header = styled_1.default.div `
border-bottom: 1px solid lightGrey;
width: calc(100% - 16px);
left: 8px;
position: relative;
color: black;
`;
exports.SelectionContainer = styled_1.default.div `
display: flex;
justify-content: center;
flex-wrap: wrap;
user-select: none;
`;
exports.ReactionElement = styled_1.default.span `
cursor: pointer;
border-radius: 4px;
width: 30px;
height: 30px;
border: 2px solid transparent;
transition: border 0.1s;
font-size: 1.1rem;
display: flex;
justify-content: center;
align-items: center;
:hover {
font-size: 1.2rem;
animation: EmojiBounce 0.1s ease-in 1;
}
@keyframes EmojiBounce {
from {
font-size: 1.2rem;
}
to {
font-size: 1.4rem;
}
}
`;