Skip to content

Commit

Permalink
add mobile chatbot button. hide for other langs via css
Browse files Browse the repository at this point in the history
  • Loading branch information
seungpark committed Nov 25, 2024
1 parent eab75ba commit 95249a4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
30 changes: 16 additions & 14 deletions src/components/ActionBar/ActionBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ import {
offlineStyling,
overlineStyling,
buttonStyling,
mobileButtonStyling,
} from './styles';
import { SparkleIcon } from './SparkIcon';

const Chatbot = lazy(() => import('mongodb-chatbot-ui'));
const LazyChatbot = lazy(() => import('./LazyChatbot'));
const ChatbotModal = lazy(() => import('./ChatbotModal'));

export const DEPRECATED_PROJECTS = ['atlas-app-services', 'datalake', 'realm'];
const CHATBOT_TEXT = 'Ask MongoDB AI';

const ActionBar = ({ template, slug, sidenav, ...props }) => {
const url = isBrowser ? window.location.href : null;
Expand All @@ -55,7 +58,7 @@ const ActionBar = ({ template, slug, sidenav, ...props }) => {

const { hideMobile, setHideMobile } = useContext(SidenavContext);

const onClick = () => {
const openChatbot = () => {
reportAnalytics('Chatbot button clicked');
setChatbotClicked((currVal) => !currVal);
};
Expand All @@ -82,21 +85,20 @@ const ActionBar = ({ template, slug, sidenav, ...props }) => {
{!isOfflineDocsBuild && (
<ActionsBox>
{template !== 'openapi' && <DarkModeDropdown />}
{locale === 'en-us' && (
<Button
className={cx(buttonStyling)}
leftGlyph={<Icon glyph="Sparkle" />}
aria-label={'Ask MongoDB AI'}
variant={'primaryOutline'}
onClick={onClick}
>
Ask Mongodb AI
</Button>
)}
<Button
className={cx(buttonStyling)}
leftGlyph={<Icon glyph="Sparkle" />}
aria-label={CHATBOT_TEXT}
variant={'primaryOutline'}
onClick={openChatbot}
>
{CHATBOT_TEXT}
</Button>
<SparkleIcon className={cx(mobileButtonStyling)} glyph={'Sparkle'} onClick={openChatbot} />
{locale === 'en-us' && (
<SuspenseHelper>
<Chatbot serverBaseUrl={CHATBOT_SERVER_BASE_URL} darkMode={darkMode}>
<LazyChatbot chatbotClicked={chatbotClicked} setChatbotClicked={setChatbotClicked} />
<ChatbotModal chatbotClicked={chatbotClicked} setChatbotClicked={setChatbotClicked} />
</Chatbot>
</SuspenseHelper>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect } from 'react';
import { useChatbotContext, ModalView, MongoDbLegalDisclosure, PoweredByAtlasVectorSearch } from 'mongodb-chatbot-ui';
import { css } from '@leafygreen-ui/emotion';

const LazyChatbot = ({ chatbotClicked, setChatbotClicked }) => {
const ChatbotModal = ({ chatbotClicked, setChatbotClicked }) => {
const { openChat } = useChatbotContext();
useEffect(() => {
if (chatbotClicked) {
Expand Down Expand Up @@ -31,4 +31,4 @@ const LazyChatbot = ({ chatbotClicked, setChatbotClicked }) => {
);
};

export default LazyChatbot;
export default ChatbotModal;
22 changes: 20 additions & 2 deletions src/components/ActionBar/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ const flexStyling = css`
const middleAlignment = css`
display: grid;
${centerGridStyling}
@media ${theme.screenSize.upToMedium} {
grid-template-columns: repeat(12, 1fr);
}
`;

const leftInGrid = css`
Expand Down Expand Up @@ -99,7 +103,6 @@ const centerInGrid = css`
}
@media ${theme.screenSize.upToMedium} {
grid-column: 3/-2;
padding-right: ${theme.size.small};
}
`;

Expand Down Expand Up @@ -272,6 +275,12 @@ export const searchIconStyling = css`
${displayNone.onLargerThanMedium};
float: right;
justify-content: right;
@media ${theme.screenSize.upToMedium} {
> div {
justify-content: flex-end;
}
}
`;

export const offlineStyling = css`
Expand All @@ -282,5 +291,14 @@ export const offlineStyling = css`

export const buttonStyling = css`
text-wrap-mode: nowrap;
${displayNone.onMobileAndTablet}
${displayNone.onMobileAndTablet};
&:not(:lang(EN)) {
display: none;
}
`;

export const mobileButtonStyling = css`
cursor: pointer;
${displayNone.onLargerThanTablet};
`;

0 comments on commit 95249a4

Please sign in to comment.