react-base-guide
Version:
react ui components
97 lines (92 loc) • 3.84 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const styled_components_1 = __importStar(require("styled-components"));
const add_custom_style_1 = require("../../utils/add-custom-style");
const Down = (0, styled_components_1.keyframes) `
0% { transform: translateY(0); opacity: 0; }
100% { transform: translateY(4px); opacity: 0.9; }
`;
const Up = (0, styled_components_1.keyframes) `
0% { transform: translateY(0); opacity: 0; }
100% { transform: translateY(-4px); opacity: 0.9; }
`;
const Wrapper = styled_components_1.default.div `
position: relative;
box-sizing: border-box;
pointer-events: ${p => p.disabled ? "none" : "all"};
${p => (0, add_custom_style_1.addCustomStyle)(p.$styled, "inline-block")}
.hint-area {
display: none;
}
&:hover {
.hint-area {
display: flex;
@media(max-width: ${p => p.theme.screen.tablet}) {
display: ${p => p.mobileHidden ? "none" : "flex"};
}
}
}
`;
const HintArea = styled_components_1.default.div `
position: absolute;
box-sizing: border-box;
min-width: ${p => p.hintWidth || "200px"};
max-width: ${p => p.hintWidth || "200px"};
right: ${p => p.right ? "0" : "auto"};
bottom: ${p => p.up ? "100%" : "auto"};
padding: 8px 12px;
border-radius: ${p => p.theme.radius.element};
box-shadow: ${p => p.theme.shadow.absolute};
margin: 4px 0;
z-index: ${p => p.theme.zIndex.dropdown};
animation: ${p => p.up ? Up : Down} 0.3s forwards;
background: ${p => p.theme.palette.background.contrast};
color: ${p => p.theme.palette.text.contrast};
font-size: 12px;
line-height: 1.5;
&::after {
content: "";
position: absolute;
pointer-events: none;
top: ${p => p.up ? "auto" : "-8px"};
bottom: ${p => p.up ? "-8px" : "auto"};
left: ${p => p.right ? "auto" : "8px"};
right: ${p => p.right ? "8px" : "auto"};
border: 8px solid transparent;
border-bottom: ${p => p.up ? "0px" : "10px"} solid ${p => p.theme.palette.background.contrast};
border-top: ${p => p.up ? "10px" : "0px"} solid ${p => p.theme.palette.background.contrast};
}
`;
const Hint = (props) => {
const { children, hint } = props;
if (!hint) {
return children;
}
return ((0, jsx_runtime_1.jsxs)(Wrapper, Object.assign({ className: props.className, disabled: props.disabled, mobileHidden: props.mobileHidden, "$styled": props.styled }, { children: [children, (0, jsx_runtime_1.jsx)(HintArea, Object.assign({ className: "hint-area", hintWidth: props.hintWidth, up: props.up, right: props.right }, { children: hint }))] })));
};
exports.default = Hint;
//# sourceMappingURL=index.js.map