From 79557bc2ab389bcd3f270967ec0407293f967145 Mon Sep 17 00:00:00 2001 From: Dante Soares Date: Thu, 20 Mar 2025 18:06:35 -0500 Subject: [PATCH 1/5] Added HelpMenu and HelpMenu stories, fixed ladle menu for SidebarNav stories --- src/components/HelpMenu.stories.tsx | 23 ++++ src/components/HelpMenu.tsx | 175 ++++++++++++++++++++++++++ src/components/SidebarNav.stories.tsx | 5 +- 3 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 src/components/HelpMenu.stories.tsx create mode 100644 src/components/HelpMenu.tsx diff --git a/src/components/HelpMenu.stories.tsx b/src/components/HelpMenu.stories.tsx new file mode 100644 index 000000000..4507e79c8 --- /dev/null +++ b/src/components/HelpMenu.stories.tsx @@ -0,0 +1,23 @@ +import { createGlobalStyle } from 'styled-components'; +import { BodyPortalSlotsContext } from './BodyPortalSlotsContext'; +import { useHelpMenu } from './HelpMenu'; +import { NavBar } from './NavBar'; + +const BodyPortalGlobalStyle = createGlobalStyle` + #ladle-root { + position: absolute; + right: 0; + } +`; + +export const Default = () => { + const [HelpMenu, ContactFormIframe] = useHelpMenu( + [{ label: 'Test Callback', callback: () => window.alert('Ran HelpMenu callback function') }] + ); + + return + + + + ; +}; diff --git a/src/components/HelpMenu.tsx b/src/components/HelpMenu.tsx new file mode 100644 index 000000000..eaf236e1d --- /dev/null +++ b/src/components/HelpMenu.tsx @@ -0,0 +1,175 @@ +import React from 'react'; +import { NavBarMenuButton, NavBarMenuItem } from './NavBarMenuButtons'; +import { colors } from '../theme'; +import styled from 'styled-components'; + +export const styledMenu = { + Button: styled(NavBarMenuButton)` + color: ${colors.palette.gray}; + font-size: 1.4rem; + `, + Item: styled(NavBarMenuItem)` + color: ${colors.palette.neutralDarker}; + text-decoration: none; + + :focus-visible { + outline: 0; + background: ${colors.palette.neutralLighter}; + } + :hover { + color: ${colors.palette.neutralDarker}; + text-decoration: none; + } + `, +}; + +const IframeWrapper = styled.div` + background-color: #F5F5F5; + position: absolute; + width: 100%; + top: 4rem; + left: 0; + bottom: 0; + z-index: 20; +`; + +const Iframe = styled.iframe` + border: 0; + width: 100%; + height: calc(100% - 5rem); +`; + +function PutAway({onClick, className}: {onClick: () => void; className?: string}) { + return ( +
+ +
+ ); +} + +const StyledPutAway = styled(PutAway)` + border-top: 0.1rem solid #D5D5D5; + width: 100%; + height: 5.6rem; + display: flex; + align-items: center; + background-color: #F5F5F5; + padding-left: 1.5rem; + position: fixed; + bottom: 0; + left: 0; + z-index: 20; + + @media(min-width: 56em) { + padding: 0 calc(50vw - 43rem); + } + + button { + height: 3rem; + background-color: white; + border: 1px solid #D5D5D5; + box-shadow: 0px 2px 4px 0px #00000033; + width: 9rem; + border-radius: 0.5rem; + } +`; + +const newTabIcon = + new tab + +; + +export const useHelpMenu = (actions: {label: string; callback: () => void}[] = []) => { + const [showIframe, setShowIframe] = React.useState(); + + function HelpMenu({contactFormParams}: {contactFormParams: { key: string; value: string }[]}) { + const contactFormUrl = React.useMemo(() => { + const formUrl = 'https://openstax.org/embedded/contact'; + const params = contactFormParams + .map(({key, value}) => encodeURIComponent(`${key}=${value}`)) + .map((p) => `body=${p}`) + .join('&'); + + return `${formUrl}?${params}`; + }, [contactFormParams]); + + return ( + <> + + {actions.map((action, i) => + {action.label} + + )} + setShowIframe(contactFormUrl)} + > + Report an issue + + + Support center  + {newTabIcon} + + + Accessibility statement  + {newTabIcon} + + { + window.parent.postMessage({type: 'TriggerConsentModalMessage'}, '*'); + }} + > + Cookie settings + + + + ); + } + + function ContactFormIframe() { + React.useEffect( + () => { + const closeIt = ({data}: MessageEvent) => { + if (data === 'CONTACT_FORM_SUBMITTED') { + setShowIframe(undefined); + } + }; + + window.addEventListener('message', closeIt, false); + + return () => window.removeEventListener('message', closeIt, false); + }, + [] + ); + + if (!showIframe) { + return null; + } + + return ( + +