diff --git a/src/assets/styles/top-navbar.scss b/src/assets/styles/top-navbar.scss new file mode 100644 index 000000000..67ca409c1 --- /dev/null +++ b/src/assets/styles/top-navbar.scss @@ -0,0 +1,334 @@ +@import './variables.scss'; + +$top-navbar-tablet-max: 859px; +$top-navbar-mobile-max: 600px; +$spotter-code-launcher-clearance: 80px; + +.top-navbar-mode { + --tn-pad: 24px; + --tn-gap: 12px; + --tn-bar-h: 52px; + --tn-control-h: 32px; + --tn-nav-w: 250px; + --tn-picker-w: 200px; + --tn-search-w: 320px; + --tn-search-min: 150px; + --tn-dropdown-shadow: 0 8px 24px rgba(0, 0, 0, 0.14); + + main { + flex-direction: column; + height: 100lvh !important; + } + + .leftNavContainer { + flex: 0 0 auto; + width: 100%; + height: auto; + } + + .resizable-container { + width: 100%; + height: auto; + } + + .resizable { + width: 100% !important; + height: auto; + } + + .react-resizable-handle { + display: none; + } + + .menuMain { + width: 100%; + } + + .secondary-header { + position: absolute; + top: 0; + left: calc(var(--tn-pad) + var(--tn-nav-w) + var(--tn-gap)); + z-index: 40; + width: auto; + height: var(--tn-bar-h); + background: transparent; + border: 0; + box-shadow: none; + } + + .secondary-header__inner { + padding: 0; + justify-content: flex-start; + } + + .secondary-header__tabs, + .secondary-header__mobile-version, + .secondary-header__nav-toggle { + display: none; + } + + .secondary-header__mobile-left { + display: flex; + } + + .secondary-header__mobile { + display: block; + } + + .secondary-header__mobile-trigger { + width: var(--tn-picker-w); + max-width: var(--tn-picker-w); + height: var(--tn-control-h); + padding: 0 10px 0 12px; + justify-content: space-between; + font-family: $font-family-doc; + font-size: $font-size-normal; + color: var(--primary-color); + background: var(--body-background-color); + border: 1px solid var(--border-color); + border-radius: 6px; + transition: border-color 0.15s ease; + + &:hover { + color: var(--primary-color); + background: var(--body-background-color); + border-color: var(--secondary-color); + } + } + + .secondary-header__mobile-label { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + font-size: $font-size-normal; + font-weight: 400; + } + + .secondary-header__mobile-dropdown { + min-width: var(--tn-picker-w); + background: var(--left-nav-color); + border: 1px solid var(--border-color); + box-shadow: var(--tn-dropdown-shadow); + } + + .secondary-header__mobile-item { + font-family: $font-family-doc; + font-size: $font-size-normal; + color: var(--primary-color); + + &:hover { + color: var(--var-note-color); + background: var(--side-nav-active-bg); + } + + &.active { + color: var(--var-note-color) !important; + background: var(--side-nav-active-bg); + } + } + + .aside { + display: flex; + flex-direction: row; + align-items: center; + gap: var(--tn-gap); + left: 0; + width: 100%; + height: var(--tn-bar-h); + padding: 0 var(--tn-pad); + overflow: visible; + font-family: $font-family-doc; + background: var(--left-nav-color); + border-right: 0; + border-bottom: 1px solid var(--border-color); + } + + .aside .backButtonWrapper { + display: none; + } + + .aside > nav { + order: 1; + position: relative; + display: flex; + align-items: center; + flex: 0 0 var(--tn-nav-w); + min-width: 0; + max-width: var(--tn-nav-w); + height: 100%; + margin: 0 calc(var(--tn-picker-w) + var(--tn-gap)) 0 0; + } + + .aside nav > .heading { + position: relative; + display: block; + width: 100%; + max-width: 100%; + height: var(--tn-control-h); + margin: 0; + padding: 0 30px 0 12px; + font-family: $font-family-doc; + font-size: $font-size-normal; + font-weight: 400; + line-height: calc(var(--tn-control-h) - 2px); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + color: var(--primary-color); + background: var(--body-background-color); + border: 1px solid var(--border-color); + border-radius: 6px; + cursor: pointer; + user-select: none; + transition: border-color 0.15s ease; + + &:hover { + border-color: var(--secondary-color); + } + } + + .aside nav > .heading:empty::before { + content: 'Documentation'; + } + + .aside nav > .heading::after { + content: ''; + position: absolute; + right: 12px; + top: calc(50% - 4px); + width: 6px; + height: 6px; + border-right: 1.5px solid currentColor; + border-bottom: 1.5px solid currentColor; + transform: rotate(45deg); + } + + .aside nav > .navWrapper { + display: none; + position: absolute; + top: calc(100% + 6px); + left: 0; + z-index: 30; + width: min(320px, calc(100vw - 2 * var(--tn-pad))); + max-height: 70vh; + margin: 0; + padding: 12px 16px 16px; + overflow-y: auto; + background: var(--left-nav-color); + border: 1px solid var(--border-color); + border-radius: 8px; + box-shadow: var(--tn-dropdown-shadow); + } + + .aside > nav::after { + content: ''; + position: absolute; + top: 100%; + left: 0; + width: 100%; + height: 6px; + } + + .aside nav:hover > .navWrapper, + .aside nav:focus-within > .navWrapper { + display: block; + } + + .aside .searchInputLeftNav { + order: 2; + flex: 1 1 var(--tn-search-w); + width: auto; + min-width: var(--tn-search-min); + max-width: var(--tn-search-w); + margin: 0 0 0 auto; + padding-right: 0; + + input { + height: var(--tn-control-h); + font-size: $font-size-normal; + line-height: calc(var(--tn-control-h) - 2px); + border-color: var(--border-color); + transition: border-color 0.15s ease; + + &:hover { + border-color: var(--secondary-color); + } + } + } + + .documentBody { + flex: 1 1 auto; + height: auto; + min-height: 0; + } + + .introWrapper { + height: 100%; + } + + .documentWrapperContainer, + .docmapWrapper { + height: 100%; + } + + @media screen and (max-width: $top-navbar-tablet-max) { + --tn-nav-w: 150px; + --tn-picker-w: 150px; + --tn-search-w: 240px; + --tn-search-min: 130px; + } + + @media screen and (max-width: $top-navbar-mobile-max) { + --tn-pad: 12px; + --tn-gap: 8px; + --tn-nav-w: 32px; + --tn-picker-w: 118px; + --tn-search-w: 220px; + --tn-search-min: 110px; + + .aside, + .aside.asideDisplay { + display: flex; + height: var(--tn-bar-h); + overflow: visible; + } + + .secondary-header__mobile-trigger { + padding: 0 8px; + } + + .aside nav > .heading { + padding: 0; + font-size: 0; + + &::after { + right: 12px; + } + } + + .aside .active { + color: var(--var-note-color) !important; + } + } +} + +#wrapper.top-navbar-mode[data-theme='dark'] { + --tn-dropdown-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); + + .aside .searchInputLeftNav input { + background: var(--body-background-color); + border-color: var(--border-color); + } +} + +body:has(#wrapper.top-navbar-mode) #floating-assistant-root { + display: none; +} + +body:has(#wrapper.hide-spotter-code) #floating-assistant-root { + display: none; +} + +#wrapper.hide-spotter-code:not(.top-navbar-mode) .aside > nav { + padding-bottom: $spotter-code-launcher-clearance; +} diff --git a/src/components/DevDocTemplate/index.tsx b/src/components/DevDocTemplate/index.tsx index bfb8357ff..ab5d6cbb7 100644 --- a/src/components/DevDocTemplate/index.tsx +++ b/src/components/DevDocTemplate/index.tsx @@ -13,6 +13,7 @@ import { Analytics } from '@vercel/analytics/react'; import { Seo } from '../Seo'; import { queryStringParser, isPublicSite } from '../../utils/app-utils'; import { useRadianceTheme } from '../../utils/radiance'; +import { EmbedConfig, getEmbedConfig } from '../../utils/embed-config'; import { passThroughHandler, fetchChild, getPageIdFromHref } from '../../utils/doc-utils'; import Header from '../Header'; import SecondaryHeader, { DocCategory, CATEGORY_PAGEIDS, CATEGORY_NAV_ID } from '../SecondaryHeader'; @@ -22,6 +23,7 @@ import Document from '../Document'; import Search from '../Search'; import '../../assets/styles/index.scss'; import '../../assets/styles/radiance-home.css'; +import '../../assets/styles/top-navbar.scss'; import { getAlgoliaIndex } from '../../configs/algolia-search-config'; import RenderPlayGround from './playGround/RESTAPI'; import GraphQLPlayGround from './playGround/GraphQL'; @@ -42,6 +44,7 @@ import { CUSTOM_PAGE_ID, BUILD_ENVS, VERSION_DROPDOWN, + DOC_HOST_EVENTS, } from '../../configs/doc-configs'; import { LEFT_NAV_WIDTH_DESKTOP, @@ -138,6 +141,13 @@ const DevDocTemplate: FC = (props) => { }); const [isDarkMode, setDarkMode] = useState(() => { if (typeof window === 'undefined') return false; + if (!isPublicSite(location.search)) { + const { isDarkMode: hostDarkMode } = getEmbedConfig(); + if (hostDarkMode !== null) return hostDarkMode; + const storedChoice = localStorage.getItem('themeMode'); + if (storedChoice) return storedChoice === 'dark'; + return false; + } // URL param takes highest priority (set by embedding product to pass its theme). const urlParams = new URLSearchParams(window.location.search); const darkModeParam = urlParams.get('isDarkMode'); @@ -146,12 +156,6 @@ const DevDocTemplate: FC = (props) => { localStorage.setItem('themeMode', isDark ? 'dark' : 'light'); return isDark; } - // In-product (embedded) presentation always uses light mode — product UI has no theme toggle. - if (!isPublicSite(location.search)){ - const explicitChoice = localStorage.getItem('themeMode'); - if (explicitChoice) return explicitChoice === 'dark'; - return false; - } /* themeMode is only written when the user explicitly clicks the toggle. If absent, follow OS preference fresh every load. */ const explicitChoice = localStorage.getItem('themeMode'); @@ -220,6 +224,15 @@ const isVersionedIframe = VERSION_DROPDOWN.some( typeof window !== 'undefined' && new URLSearchParams(location.search).get('_iframe') === '1'; + const [embedConfig, setEmbedConfig] = useState(getEmbedConfig); + const isTopNavbar = !isPublicSiteOpen && embedConfig.isTopNavbar; + const hideSpotterCode = !isPublicSiteOpen && embedConfig.hideSpotterCode; + + useEffect(() => { + if (isPublicSiteOpen || embedConfig.isDarkMode === null) return; + setDarkMode(embedConfig.isDarkMode); + }, [embedConfig.isDarkMode, isPublicSiteOpen]); + // The walkthroughs overview is a card-grid landing page (like home) — no // in-page nav to browse, so skip the left sidebar entirely and let the // cards use the full width. tutorials-overview is presented like any other @@ -432,6 +445,13 @@ const isVersionedIframe = VERSION_DROPDOWN.some( // Listen for messages from the iframe useEffect(() => { const handleMessage = (e) => { + if ( + e.data?.type === DOC_HOST_EVENTS.UPDATE_EMBED_CONFIG && + e.data?.data + ) { + setEmbedConfig(e.data.data); + return; + } if (e.data?.params || e.data?.subsection) { console.log('Iframe message:', e.data); @@ -628,7 +648,7 @@ const isVersionedIframe = VERSION_DROPDOWN.some(
{ - return isEmbeddedContext() ? 'embedded-mode' : ''; + const classNames: string[] = []; + if (isEmbeddedContext()) classNames.push('embedded-mode'); + if (isTopNavbar) classNames.push('top-navbar-mode'); + if (hideSpotterCode) classNames.push('hide-spotter-code'); + return classNames.join(' '); }; const getCloudLatestVersion = () => { @@ -890,6 +914,14 @@ if (isVersionedIframe) { setLeftNavOpen={setLeftNavOpen} isVersionedIframe={isVersionedIframe} /> + ) : isTopNavbar ? ( + ) : !isVersionedIframe && !isMaxMobileResolution && ( // In-product presentation has no tabs — show just the nav // toggle so the sidebar stays reachable on narrow viewports. diff --git a/src/components/SecondaryHeader/index.tsx b/src/components/SecondaryHeader/index.tsx index 50a8686fa..501b90606 100644 --- a/src/components/SecondaryHeader/index.tsx +++ b/src/components/SecondaryHeader/index.tsx @@ -194,7 +194,7 @@ const SecondaryHeader = (props: { navigate(`?${params.toString()}`); return; } - navigate(landing); + navigate(`${landing}${location.search || ''}`); }; useEffect(() => { diff --git a/src/configs/doc-configs.js b/src/configs/doc-configs.js index c73702688..4edae0ea4 100644 --- a/src/configs/doc-configs.js +++ b/src/configs/doc-configs.js @@ -31,6 +31,12 @@ module.exports = { DEFAULT_PREVIEW_HOST: 'https://try-everywhere.thoughtspot.cloud/v2', DEFAULT_APP_ROOT: '/everywhere', IS_PUBLIC_SITE_OPEN: 'isPublicSiteOpen', + IS_TOP_NAVBAR_PARAM: 'isTopNavbar', + IS_DARK_MODE_PARAM: 'isDarkMode', + HIDE_SPOTTER_CODE_PARAM: 'hideSpotterCode', + DOC_HOST_EVENTS: { + UPDATE_EMBED_CONFIG: 'updateEmbedConfig', + }, TS_DEMO_LOGIN: '/callosum/v1/session/demo/login', TS_SESSION_TOKEN: '/prism/?op=GetSessionToken', TS_INFO: '/callosum/v1/session/info', diff --git a/src/utils/embed-config.ts b/src/utils/embed-config.ts new file mode 100644 index 000000000..4b59350eb --- /dev/null +++ b/src/utils/embed-config.ts @@ -0,0 +1,65 @@ +import { + HIDE_SPOTTER_CODE_PARAM, + IS_DARK_MODE_PARAM, + IS_TOP_NAVBAR_PARAM, +} from '../configs/doc-configs'; + +export interface EmbedConfig { + isDarkMode: boolean | null; + isTopNavbar: boolean; + hideSpotterCode: boolean; +} + +type EmbedConfigKey = keyof EmbedConfig; + +const parseBoolean = (value: string): boolean => value === 'true'; + +interface EmbedConfigParam { + param: string; + parse: (value: string) => V; + defaultValue: V; +} + +type EmbedConfigSchema = { + [K in EmbedConfigKey]: EmbedConfigParam; +}; + +const EMBED_CONFIG_SCHEMA: EmbedConfigSchema = { + isDarkMode: { + param: IS_DARK_MODE_PARAM, + parse: parseBoolean, + defaultValue: null, + }, + isTopNavbar: { + param: IS_TOP_NAVBAR_PARAM, + parse: parseBoolean, + defaultValue: false, + }, + hideSpotterCode: { + param: HIDE_SPOTTER_CODE_PARAM, + parse: parseBoolean, + defaultValue: false, + }, +}; + +const EMBED_CONFIG_KEYS = Object.keys(EMBED_CONFIG_SCHEMA) as EmbedConfigKey[]; + +const DEFAULT_EMBED_CONFIG: EmbedConfig = EMBED_CONFIG_KEYS.reduce( + (config, key) => ({ + ...config, + [key]: EMBED_CONFIG_SCHEMA[key].defaultValue, + }), + {} as EmbedConfig, +); + +const getEmbedConfigFromUrl = (search: string): EmbedConfig => + EMBED_CONFIG_KEYS.reduce((config, key) => { + const { param, parse } = EMBED_CONFIG_SCHEMA[key]; + const value = new URLSearchParams(search).get(param); + return value === null ? config : { ...config, [key]: parse(value) }; + }, DEFAULT_EMBED_CONFIG); + +export const getEmbedConfig = (): EmbedConfig => + typeof window === 'undefined' + ? DEFAULT_EMBED_CONFIG + : getEmbedConfigFromUrl(window.location.search);