UNPKG

@navinc/base-react-components

Version:
245 lines (242 loc) 11.6 kB
"use strict"; 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; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var _a, _b; Object.defineProperty(exports, "__esModule", { value: true }); exports.UserFeedback = exports.AdditionalFeedbackContainer = exports.ThankYouMessage = exports.UserFeedbackContainer = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); /* eslint-disable @typescript-eslint/no-use-before-define */ const react_1 = require("react"); const prop_types_1 = __importDefault(require("prop-types")); const styled_components_1 = __importStar(require("styled-components")); const js_cookie_1 = __importDefault(require("js-cookie")); const utils_1 = require("@navinc/utils"); const button_js_1 = __importDefault(require("./button.js")); const copy_js_1 = __importDefault(require("./copy.js")); const icon_button_1 = __importDefault(require("./icon-button")); const is_rebrand_js_1 = __importDefault(require("./is-rebrand.js")); const { CLIENT_COOKIE_DOMAIN } = (_b = (_a = utils_1.global === null || utils_1.global === void 0 ? void 0 : utils_1.global.process) === null || _a === void 0 ? void 0 : _a.env) !== null && _b !== void 0 ? _b : ''; const slideInFromSide = (0, styled_components_1.keyframes) ` 0% { transform: translateX(50%); opacity: 0; } 100% { transform: translateX(0); opacity: 1; } `; const slideInFromBottom = (0, styled_components_1.keyframes) ` 0% { transform: translateY(50%); opacity: 0; } 100% { transform: translateX(0); opacity: 1; } `; const slideOutAnimation = (0, styled_components_1.keyframes) ` 0% { opacity: 1; transform: translateY(0); } 10% { transform: translateY(calc(100% - 4px)); opacity: 1; border-top: 4px solid ${({ theme }) => ((0, is_rebrand_js_1.default)(theme) ? theme.navNeutral300 : theme.border)}; } 50% { opacity: 1; border-top: 4px solid ${({ theme }) => ((0, is_rebrand_js_1.default)(theme) ? theme.navStatusPositive : theme.seaturtleGreen200)}; } 60% { opacity: 1; border-top: 4px solid ${({ theme }) => ((0, is_rebrand_js_1.default)(theme) ? theme.navStatusPositive : theme.seaturtleGreen200)}; } 80% { transform: translateY(calc(100% - 4px)) translateX(0); opacity: 1; } 100% { transform: translateY(calc(100% - 4px)) translateX(100%); opacity: 0; } `; const slideOut = (0, styled_components_1.css) ` opacity: 0; transform: translateY(100%); animation: ${slideOutAnimation} 2s ease-in-out; `; exports.UserFeedbackContainer = styled_components_1.default.div.withConfig({ displayName: "brc-sc-UserFeedbackContainer", componentId: "brc-sc-17zo9fs" }) ` position: relative; display: flex; height: 52px; max-height: 52px; min-width: 240px; margin-left: auto; opacity: 1; overflow: hidden; transition: opacity 0.2s linear 15s, height 0.2s linear 15s, max-height 0.2s linear; ${({ isTouched }) => isTouched && ` height: 0; opacity: 0; & > ${UserFeedbackPrompt} { opacity: 0; } `} ${({ shouldHideImmediately }) => shouldHideImmediately && ` max-height: 0; `} `; const UserFeedbackPrompt = styled_components_1.default.div.withConfig({ displayName: "brc-sc-UserFeedbackPrompt", componentId: "brc-sc-1vpzbz6" }) ` display: flex; width: 100%; align-items: center; justify-content: flex-end; margin-top: 16px; opacity: 1; transition: opacity 0.2s linear; `; exports.ThankYouMessage = styled_components_1.default.div.withConfig({ displayName: "brc-sc-ThankYouMessage", componentId: "brc-sc-1y175pz" }) ` position: absolute; top: 16px; right: 0; padding-left: 8px; overflow: hidden; animation: ${slideInFromSide} 0.4s ease-in-out; &::after { position: absolute; content: ''; top: 0; left: 0; width: 2px; height: 100%; border-radius: 2px; background: ${({ theme }) => ((0, is_rebrand_js_1.default)(theme) ? theme.navPrimary400 : theme.bubbleBlue400)}; z-index: 5; } `; const StyledIconButton = (0, styled_components_1.default)(icon_button_1.default).withConfig({ displayName: "brc-sc-StyledIconButton", componentId: "brc-sc-1seszv6" }) ` height: 16px; color: ${({ theme }) => ((0, is_rebrand_js_1.default)(theme) ? theme.navNeutral400 : theme.neutral400)}; transition: color 0.2s linear; cursor: pointer; &:hover, &:hover:not([disabled]), &:hover:active, &:focus, &:focus:active, &:active { color: ${({ theme }) => ((0, is_rebrand_js_1.default)(theme) ? theme.navStatusPositive500 : theme.mermaidGreen500)}; box-shadow: none; } `; const MoreFeedbackLink = (0, styled_components_1.default)(copy_js_1.default).attrs(() => ({ size: 'xs', as: 'a', })).withConfig({ displayName: "brc-sc-MoreFeedbackLink", componentId: "brc-sc-8rczjo" }) ` color: ${({ theme }) => theme.navPrimary}; align-content: center; cursor: pointer; `; exports.AdditionalFeedbackContainer = styled_components_1.default.div.withConfig({ displayName: "brc-sc-AdditionalFeedbackContainer", componentId: "brc-sc-1voa3re" }) ` position: fixed; bottom: 0; left: 0; width: 100%; border-top: 4px solid ${({ theme }) => ((0, is_rebrand_js_1.default)(theme) ? theme.navNeutral300 : theme.border)}; background-color: ${({ theme }) => ((0, is_rebrand_js_1.default)(theme) ? theme.navNeutralLight : theme.white)}; opacity: 1; transform: translateY(0); z-index: 60; animation: ${slideInFromBottom} 0.4s ease-in-out; ${({ shouldHide }) => shouldHide && slideOut} `; const Form = styled_components_1.default.div.withConfig({ displayName: "brc-sc-Form", componentId: "brc-sc-rbo5yy" }) ` display: flex; flex-wrap: wrap; justify-content: flex-end; max-width: ${({ theme }) => theme.contentWidth}px; margin: 0 auto; padding: 16px; ${copy_js_1.default} { width: 100%; max-width: 100%; text-align: center; } ${button_js_1.default} { margin-left: 16px; } `; const Textarea = styled_components_1.default.textarea.withConfig({ displayName: "brc-sc-Textarea", componentId: "brc-sc-1y1effq" }) ` width: 100%; margin: 8px 0 16px; border: 1px solid ${({ theme }) => ((0, is_rebrand_js_1.default)(theme) ? theme.navNeutral300 : theme.border)}; border-radius: 4px; `; const UserFeedback = ({ trackingLabel = '', className, initialPrompt = 'Was this useful?', thumbsUpThankYouText = `We're glad this helps.`, thumbsDownThankYouText = `We're sorry this isn't helpful.`, thumbsUpAdditionalFeedbackPrompt = 'Tell us more', thumbsDownAdditionalFeedbackPrompt = 'Tell us how we can improve', additionalFeedbackQuestion = 'What can we do to improve your experience?', }) => { const [isTouched, setIsTouched] = (0, react_1.useState)(false); const [showAdditionalDialogue, setShowAdditionalDialogue] = (0, react_1.useState)(false); const [userReaction, setUserReaction] = (0, react_1.useState)(''); const [userFeedback, setUserFeedback] = (0, react_1.useState)(''); const trackClick = (newUserReaction) => () => { setIsTouched(true); setUserReaction(newUserReaction); js_cookie_1.default.set(trackingLabel, true, { domain: CLIENT_COOKIE_DOMAIN, path: '/', expires: 30, }); }; const handleShowMoreFeedback = () => { setShowAdditionalDialogue(true); }; const handleHideMoreFeedback = () => setShowAdditionalDialogue(false); const handleSubmitMoreFeedback = (event) => { event.preventDefault(); setShowAdditionalDialogue(false); }; const handleTextChange = ({ target }) => setUserFeedback(target.value); if (!isTouched && !showAdditionalDialogue && js_cookie_1.default.get(trackingLabel)) return null; return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(exports.UserFeedbackContainer, Object.assign({ isTouched: isTouched, shouldHideImmediately: !!userFeedback, className: className, "data-id": `user-feedback-${trackingLabel}` }, { children: [(0, jsx_runtime_1.jsxs)(UserFeedbackPrompt, { children: [(0, jsx_runtime_1.jsx)(copy_js_1.default, Object.assign({ size: "sm", light: true }, { children: initialPrompt })), (0, jsx_runtime_1.jsx)(StyledIconButton, { onClick: trackClick('Thumbs Up'), name: "feedback/thumbs-up", "data-testid": "user-feedback:button-positive", size: "16" }), (0, jsx_runtime_1.jsx)(StyledIconButton, { onClick: trackClick('Thumbs Down'), name: "feedback/thumbs-down", "data-testid": "user-feedback:button-negative", size: "16" })] }), isTouched && ((0, jsx_runtime_1.jsxs)(exports.ThankYouMessage, { children: [(0, jsx_runtime_1.jsx)(copy_js_1.default, Object.assign({ size: "xs" }, { children: userReaction === 'Thumbs Up' ? thumbsUpThankYouText : thumbsDownThankYouText })), (0, jsx_runtime_1.jsx)(MoreFeedbackLink, Object.assign({ onClick: handleShowMoreFeedback, "data-testid": "user-feedback:tell-us-more-link" }, { children: userReaction === 'Thumbs Up' ? thumbsUpAdditionalFeedbackPrompt : thumbsDownAdditionalFeedbackPrompt }))] }))] })), (showAdditionalDialogue || userFeedback) && ((0, jsx_runtime_1.jsx)(exports.AdditionalFeedbackContainer, Object.assign({ shouldHide: !showAdditionalDialogue }, { children: (0, jsx_runtime_1.jsxs)(Form, { children: [(0, jsx_runtime_1.jsx)(copy_js_1.default, Object.assign({ bold: true }, { children: additionalFeedbackQuestion })), (0, jsx_runtime_1.jsx)(Textarea, { onChange: handleTextChange, "data-testid": "user-feedback:text-area" }), (0, jsx_runtime_1.jsx)(button_js_1.default, Object.assign({ onClick: handleHideMoreFeedback, variation: "outline", "data-testid": "user-feedback:cancel" }, { children: "Cancel" })), (0, jsx_runtime_1.jsx)(button_js_1.default, Object.assign({ onClick: handleSubmitMoreFeedback, disabled: !userFeedback, "data-testid": "user-feedback:submit" }, { children: "Submit" }))] }) })))] })); }; exports.UserFeedback = UserFeedback; exports.UserFeedback.propTypes = { trackingLabel: prop_types_1.default.string, initialPrompt: prop_types_1.default.string, thumbsUpThankYouText: prop_types_1.default.string, thumbsDownThankYouText: prop_types_1.default.string, thumbsUpAdditionalFeedbackPrompt: prop_types_1.default.string, thumbsDownAdditionalFeedbackPrompt: prop_types_1.default.string, additionalFeedbackQuestion: prop_types_1.default.string, }; exports.default = (0, styled_components_1.default)(exports.UserFeedback).withConfig({ componentId: "brc-sc-l5cm5b" }) ``; //# sourceMappingURL=user-feedback.js.map