Skip to content

Commit

Permalink
Merge branch 'main' into DOP-4961
Browse files Browse the repository at this point in the history
  • Loading branch information
branberry authored Sep 18, 2024
2 parents 708c600 + ca00191 commit a7af2e9
Show file tree
Hide file tree
Showing 100 changed files with 6,179 additions and 5,457 deletions.
7 changes: 6 additions & 1 deletion gatsby-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { renderToString } from 'react-dom/server';
import { theme } from './src/theme/docsTheme';
import EuclidCircularASemiBold from './src/styles/fonts/EuclidCircularA-Semibold-WebXL.woff';
import redirectBasedOnLang from './src/utils/head-scripts/redirect-based-on-lang';
import { getHtmlLangFormat } from './src/utils/locale';

export const onRenderBody = ({ setHeadComponents }) => {
export const onRenderBody = ({ setHeadComponents, setHtmlAttributes }) => {
const headComponents = [
// GTM Pathway
<script
Expand Down Expand Up @@ -84,6 +85,10 @@ export const onRenderBody = ({ setHeadComponents }) => {
/>
);
}
setHtmlAttributes({
// Help work with translated content locally; Smartling should handle rewriting the lang
lang: process.env.GATSBY_LOCALE ? getHtmlLangFormat(process.env.GATSBY_LOCALE) : 'en',
});
setHeadComponents(headComponents);
};

Expand Down
549 changes: 169 additions & 380 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@
"@leafygreen-ui/code": "^14.3.3",
"@leafygreen-ui/combobox": "^6.0.0",
"@leafygreen-ui/emotion": "^4.0.0",
"@leafygreen-ui/hooks": "^6.0.1",
"@leafygreen-ui/hooks": "^8.1.3",
"@leafygreen-ui/icon": "^12.4.0",
"@leafygreen-ui/icon-button": "^15.0.23",
"@leafygreen-ui/inline-definition": "^4.0.2",
"@leafygreen-ui/leafygreen-provider": "^3.1.12",
"@leafygreen-ui/lib": "^9.5.2",
"@leafygreen-ui/logo": "^4.0.2",
"@leafygreen-ui/logo": "^9.1.1",
"@leafygreen-ui/menu": "^24.1.0",
"@leafygreen-ui/modal": "^10.1.0",
"@leafygreen-ui/pagination": "^1.0.9",
Expand Down
124 changes: 54 additions & 70 deletions src/components/ActionBar/ActionBar.js
Original file line number Diff line number Diff line change
@@ -1,87 +1,71 @@
import React from 'react';
import styled from '@emotion/styled';
import { useDarkMode } from '@leafygreen-ui/leafygreen-provider';
import { palette } from '@leafygreen-ui/palette';
import { theme } from '../../theme/docsTheme';
import ChatbotUi from '../ChatbotUi';
import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import { cx } from '@leafygreen-ui/emotion';
import Icon from '@leafygreen-ui/icon';
import { Overline } from '@leafygreen-ui/typography';
import { isBrowser } from '../../utils/is-browser';
import { getPlaintext } from '../../utils/get-plaintext';
import { getNestedValue } from '../../utils/get-nested-value';
import useSnootyMetadata from '../../utils/use-snooty-metadata';
import { SidenavContext } from '../Sidenav';
import {
FeedbackProvider,
FeedbackForm,
FeedbackButton,
useFeedbackData,
FeedbackContainer,
} from '../Widgets/FeedbackWidget';
import DarkModeDropdown from './DarkModeDropdown';
import SearchInput from './SearchInput';
import { ActionBarSearchContainer, ActionsBox, actionBarStyling, getContainerStyling, overlineStyling } from './styles';

const ActionBarContainer = styled('div')`
display: flex;
justify-content: space-between;
padding-top: ${theme.size.small};
padding-bottom: ${theme.size.small};
padding-right: ${theme.size.large};
width: 100%;
position: sticky;
top: 0;
flex-wrap: wrap;
z-index: ${theme.zIndexes.actionBar};
background-color: ${(props) => (props.darkMode ? palette.black : palette.white)};
border-bottom: 1px solid ${(props) => (props.darkMode ? palette.gray.dark2 : palette.gray.light2)};
const DEPRECATED_PROJECTS = ['atlas-app-services', 'datalake', 'realm'];

@media ${theme.screenSize.mediumAndUp} {
& > div {
flex: 0 1 auto;
}
}
const ActionBar = ({ template, slug, sidenav, ...props }) => {
const url = isBrowser ? window.location.href : null;
const metadata = useSnootyMetadata();
const feedbackData = useFeedbackData({
slug,
url,
title:
getPlaintext(getNestedValue(['slugToTitle', slug === '/' ? 'index' : slug], metadata)) || 'MongoDB Documentation',
});

@media ${theme.screenSize.upToMedium} {
justify-content: space-between;
padding-right: 0;
}
`;
const { fakeColumns, containerClassname, searchContainerClassname } = getContainerStyling(template);

const ActionBarSearchContainer = styled.div`
align-items: center;
display: flex;
width: 80%;
const { hideMobile, setHideMobile } = useContext(SidenavContext);

@media ${theme.screenSize.upToMedium} {
width: 100%;
}
@media ${theme.screenSize.upToSmall} {
& > div {
padding: ${theme.size.default} 32px;
}
}
`;

const ActionsBox = styled('div')`
display: flex;
align-items: center;
column-gap: ${theme.size.default};
@media ${theme.screenSize.upToMedium} {
padding-left: 3rem;
}
@media ${theme.screenSize.upToSmall} {
padding-left: 2rem;
}
`;

// Note: When working on this component further, please check with design on how it should look in the errorpage template (404) as well!
const ActionBar = ({ template, ...props }) => {
const { darkMode } = useDarkMode();
return (
<ActionBarContainer className={props.className} darkMode={darkMode}>
<ActionBarSearchContainer>
<ChatbotUi darkMode={darkMode} />
<div className={cx(props.className, actionBarStyling, containerClassname)}>
{fakeColumns && <div></div>}
<ActionBarSearchContainer className={cx(searchContainerClassname)}>
{sidenav && (
<Overline className={cx(overlineStyling)} onClick={() => setHideMobile((state) => !state)}>
<Icon glyph={hideMobile ? 'ChevronDown' : 'ChevronUp'} />
Docs Menu
</Overline>
)}
<SearchInput slug={slug} />
</ActionBarSearchContainer>
<ActionsBox>
{template !== 'openapi' && <DarkModeDropdown />}
{template !== 'errorpage' && (
<div>
<button>Feedback</button>
</div>
{template !== 'errorpage' && !DEPRECATED_PROJECTS.includes(metadata.project) && (
<FeedbackProvider page={feedbackData}>
<FeedbackContainer>
<FeedbackButton />
<FeedbackForm />
</FeedbackContainer>
</FeedbackProvider>
)}
</ActionsBox>
</ActionBarContainer>
</div>
);
};

ActionBar.propTypes = {};
ActionBar.propTypes = {
template: PropTypes.string.isRequired,
slug: PropTypes.string.isRequired,
sidenav: PropTypes.bool.isRequired,
};

export default ActionBar;
28 changes: 28 additions & 0 deletions src/components/ActionBar/ChatbotControls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { forwardRef, useCallback, useImperativeHandle } from 'react';
import { useChatbotContext } from 'mongodb-chatbot-ui';
import PropTypes from 'prop-types';

// Using a forward ref and imperative handle
// to expose lazy loaded child (chatbot) behaviors to parent (SearchInput)
// https://react.dev/reference/react/useImperativeHandle
const ChatbotControls = forwardRef(function ChatbotControls({ searchValue }, ref) {
const { setInputText, handleSubmit, openChat } = useChatbotContext();

const onClick = useCallback(async () => {
await openChat();
setInputText(searchValue);
handleSubmit(searchValue);
}, [handleSubmit, openChat, searchValue, setInputText]);

useImperativeHandle(ref, () => {
return {
onClick,
};
});
});

export default ChatbotControls;

ChatbotControls.propTypes = {
searchValue: PropTypes.string.isRequired,
};
37 changes: 28 additions & 9 deletions src/components/ActionBar/DarkModeDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,35 @@ import { cx, css } from '@leafygreen-ui/emotion';
import Box from '@leafygreen-ui/box';
import Icon from '@leafygreen-ui/icon';
import IconButton from '@leafygreen-ui/icon-button';
import { useDarkMode } from '@leafygreen-ui/leafygreen-provider';
import { Menu, MenuItem } from '@leafygreen-ui/menu';
import { DarkModeContext } from '../../context/dark-mode-context';
import { theme } from '../../theme/docsTheme';
import IconComputer from '../icons/Computer';
import IconDarkmode from '../icons/DarkMode';

const iconStyling = css`
display: block;
align-content: center;
cursor: pointer;
> div {
position: relative;
}
`;

const menuStyling = css`
width: fit-content;
margin-top: ${theme.size.small};
`;

const DarkModeDropdown = ({ ...props }) => {
const DROPDOWN_ICON_SIZE = 20;
const darkModeSvgStyle = {
width: DROPDOWN_ICON_SIZE,
height: DROPDOWN_ICON_SIZE,
};

const DarkModeDropdown = () => {
// not using dark mode from LG/provider here to account for case of 'system' dark theme
const { setDarkModePref, darkModePref } = useContext(DarkModeContext);
const { darkMode } = useDarkMode();

const [open, setOpen] = useState(false);

Expand All @@ -46,31 +56,40 @@ const DarkModeDropdown = ({ ...props }) => {
// since we are using usePortal=false to mitigate sticky header
<IconButton as={Box} className={cx(iconStyling)} aria-label="Dark Mode Menu" aria-labelledby="Dark Mode Menu">
{darkModePref === 'system' ? (
<IconComputer darkMode={darkMode} />
<IconDarkmode />
) : (
<Icon glyph={darkModePref === 'dark-theme' ? 'Moon' : 'Sun'} />
<Icon size={24} glyph={darkModePref === 'dark-theme' ? 'Moon' : 'Sun'} />
)}
</IconButton>
}
>
<MenuItem
active={darkModePref === 'light-theme'}
onClick={() => select('light-theme')}
glyph={<Icon glyph={'Sun'} />}
glyph={<Icon size={DROPDOWN_ICON_SIZE} glyph={'Sun'} />}
>
Light
</MenuItem>
<MenuItem
active={darkModePref === 'dark-theme'}
onClick={() => select('dark-theme')}
glyph={<Icon glyph={'Moon'} />}
glyph={<Icon size={DROPDOWN_ICON_SIZE} glyph={'Moon'} />}
>
Dark
</MenuItem>
<MenuItem
active={darkModePref === 'system'}
onClick={() => select('system')}
glyph={<IconComputer darkMode={darkMode} />}
glyph={
<IconDarkmode
className={css`
svg {
margin-right: ${theme.size.default};
}
`}
styles={darkModeSvgStyle}
/>
}
>
System
</MenuItem>
Expand Down
Loading

0 comments on commit a7af2e9

Please sign in to comment.