-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
100 changed files
with
6,179 additions
and
5,457 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.