UNPKG

@readr-media/react-feedback

Version:

## Installation `yarn install`

147 lines (125 loc) 8.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = CommentItem; var _react = _interopRequireWildcard(require("react")); var _styledComponents = _interopRequireDefault(require("styled-components")); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } var CommentSvg = function CommentSvg(props) { return /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", { ...props, children: /*#__PURE__*/(0, _jsxRuntime.jsx)("path", { d: "M0.828125 10.8281C1.16667 10.4896 1.55729 10.3203 2 10.3203C2.44271 10.3203 2.83333 10.4896 3.17188 10.8281C3.51042 11.1667 3.67969 11.5573 3.67969 12C3.67969 12.4427 3.51042 12.8333 3.17188 13.1719C2.83333 13.5104 2.44271 13.6797 2 13.6797C1.55729 13.6797 1.16667 13.5104 0.828125 13.1719C0.489583 12.8333 0.320312 12.4427 0.320312 12C0.320312 11.5573 0.489583 11.1667 0.828125 10.8281ZM0.828125 5.82812C1.16667 5.48958 1.55729 5.32031 2 5.32031C2.44271 5.32031 2.83333 5.48958 3.17188 5.82812C3.51042 6.16667 3.67969 6.55729 3.67969 7C3.67969 7.44271 3.51042 7.83333 3.17188 8.17188C2.83333 8.51042 2.44271 8.67969 2 8.67969C1.55729 8.67969 1.16667 8.51042 0.828125 8.17188C0.489583 7.83333 0.320312 7.44271 0.320312 7C0.320312 6.55729 0.489583 6.16667 0.828125 5.82812ZM3.17188 3.17188C2.83333 3.51042 2.44271 3.67969 2 3.67969C1.55729 3.67969 1.16667 3.51042 0.828125 3.17188C0.489583 2.83333 0.320312 2.44271 0.320312 2C0.320312 1.55729 0.489583 1.16667 0.828125 0.828125C1.16667 0.489583 1.55729 0.320312 2 0.320312C2.44271 0.320312 2.83333 0.489583 3.17188 0.828125C3.51042 1.16667 3.67969 1.55729 3.67969 2C3.67969 2.44271 3.51042 2.83333 3.17188 3.17188Z", fill: "#000928", fillOpacity: "0.3" }) }); }; CommentSvg.defaultProps = { width: "4", height: "14", viewBox: "0 0 4 14", fill: "none", xmlns: "http://www.w3.org/2000/svg" }; var CommentStrongSvg = function CommentStrongSvg(props) { return /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", { ...props, children: /*#__PURE__*/(0, _jsxRuntime.jsx)("path", { d: "M0.828125 10.8281C1.16667 10.4896 1.55729 10.3203 2 10.3203C2.44271 10.3203 2.83333 10.4896 3.17188 10.8281C3.51042 11.1667 3.67969 11.5573 3.67969 12C3.67969 12.4427 3.51042 12.8333 3.17188 13.1719C2.83333 13.5104 2.44271 13.6797 2 13.6797C1.55729 13.6797 1.16667 13.5104 0.828125 13.1719C0.489583 12.8333 0.320312 12.4427 0.320312 12C0.320312 11.5573 0.489583 11.1667 0.828125 10.8281ZM0.828125 5.82812C1.16667 5.48958 1.55729 5.32031 2 5.32031C2.44271 5.32031 2.83333 5.48958 3.17188 5.82812C3.51042 6.16667 3.67969 6.55729 3.67969 7C3.67969 7.44271 3.51042 7.83333 3.17188 8.17188C2.83333 8.51042 2.44271 8.67969 2 8.67969C1.55729 8.67969 1.16667 8.51042 0.828125 8.17188C0.489583 7.83333 0.320312 7.44271 0.320312 7C0.320312 6.55729 0.489583 6.16667 0.828125 5.82812ZM3.17188 3.17188C2.83333 3.51042 2.44271 3.67969 2 3.67969C1.55729 3.67969 1.16667 3.51042 0.828125 3.17188C0.489583 2.83333 0.320312 2.44271 0.320312 2C0.320312 1.55729 0.489583 1.16667 0.828125 0.828125C1.16667 0.489583 1.55729 0.320312 2 0.320312C2.44271 0.320312 2.83333 0.489583 3.17188 0.828125C3.51042 1.16667 3.67969 1.55729 3.67969 2C3.67969 2.44271 3.51042 2.83333 3.17188 3.17188Z", fill: "#000928" }) }); }; CommentStrongSvg.defaultProps = { width: "4", height: "14", viewBox: "0 0 4 14", fill: "none", xmlns: "http://www.w3.org/2000/svg" }; const Control = _styledComponents.default.button.withConfig({ displayName: "comment-item__Control", componentId: "sc-1crhqqc-0" })(["width:20px;height:20px;display:flex;justify-content:center;align-items:center;padding:0;border:0;background-color:transparent;cursor:pointer;.normal{display:none;}.strong{display:none;}@media (max-width:1200px){.normal{display:block;}}"]); const Wrapper = _styledComponents.default.div.withConfig({ displayName: "comment-item__Wrapper", componentId: "sc-1crhqqc-1" })(["box-sizing:border-box;background-color:#fff;border:none;border-radius:6px;padding:16px 24px;font:inherit;outline:inherit;width:100%;text-align:left;&:hover{@media (min-width:1201px){.normal{display:block;}}}&:active{.normal{display:none;}.strong{display:block;}}"]); const Header = _styledComponents.default.div.withConfig({ displayName: "comment-item__Header", componentId: "sc-1crhqqc-2" })(["display:flex;justify-content:space-between;"]); const Time = _styledComponents.default.time.withConfig({ displayName: "comment-item__Time", componentId: "sc-1crhqqc-3" })(["font-size:14px;line-height:21px;color:rgba(0,9,40,30%);"]); const ContentWrapper = _styledComponents.default.div.withConfig({ displayName: "comment-item__ContentWrapper", componentId: "sc-1crhqqc-4" })(["overflow:hidden;max-height:216px;@media (max-width:768px){max-height:96px;}&.expanded{max-height:unset;}"]); const Content = _styledComponents.default.div.withConfig({ displayName: "comment-item__Content", componentId: "sc-1crhqqc-5" })(["white-space:pre-line;color:rgba(0,9,40,87%);font-size:18px;line-height:36px;@media (max-width:768px){font-size:16px;line-height:32px;}"]); const ContentExpander = _styledComponents.default.button.withConfig({ displayName: "comment-item__ContentExpander", componentId: "sc-1crhqqc-6" })(["background-color:transparent;color:rgba(0,9,40,30%);font-size:18px;line-height:36px;border:0;padding:0;cursor:pointer;"]); /** * @typedef {import('../../../typedef').Comment} Comment * * @param {Object} props * @param {Comment} props.comment * @param {boolean} [props.shouldShowControl] * @return {JSX.Element} */ function CommentItem({ comment, shouldShowControl }) { const [contentExpanded, setContentExpanded] = (0, _react.useState)(false); const contentRef = (0, _react.useRef)(); // wrapper is loaded after content const onWrapperLoaded = (0, _react.useCallback)(node => { if (node && contentRef.current) { const wrapperHeight = node.clientHeight; const contentHeight = contentRef.current.clientHeight; if (contentHeight > wrapperHeight) { setContentExpanded(false); } else { setContentExpanded(true); } } }, []); return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Wrapper, { className: "comment-wrapper", children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(Header, { className: "comment-header", children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Time, { children: comment.date }), shouldShowControl && /*#__PURE__*/(0, _jsxRuntime.jsxs)(Control, { className: "comment-control", children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(CommentStrongSvg, { className: "strong" }), /*#__PURE__*/(0, _jsxRuntime.jsx)(CommentSvg, { className: "normal" })] })] }), /*#__PURE__*/(0, _jsxRuntime.jsx)(ContentWrapper, { className: `comment-content-wrapper ${contentExpanded ? 'expanded' : ''}`, ref: onWrapperLoaded, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Content, { className: "comment-content", ref: contentRef, children: comment.content }) }), !contentExpanded && /*#__PURE__*/(0, _jsxRuntime.jsx)(ContentExpander, { className: "content-expander", onMouseUp: () => setContentExpanded(true), type: "button", children: "\u5C55\u958B\u5168\u90E8" })] }); }