Skip to content

Commit

Permalink
Merge pull request #362 from mongodb/brooke/mobile
Browse files Browse the repository at this point in the history
Adds basic mobile responsiveness
  • Loading branch information
bruugey authored May 21, 2024
2 parents 9fb7efc + 86d9409 commit a213d1a
Show file tree
Hide file tree
Showing 14 changed files with 479 additions and 254 deletions.
8 changes: 7 additions & 1 deletion src/app/component/[component]/code-docs/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { css } from '@emotion/css';
import { TableSkeleton } from '@leafygreen-ui/skeleton-loader';
import { spacing } from '@leafygreen-ui/tokens';
import { InstallCard, PropsTable, VersionCard } from '@/components/code-docs';
import { useMediaQuery } from '@/hooks/useMediaQuery';
import { components } from '@/utils';
import {
TSDocResponse,
Expand All @@ -15,6 +16,9 @@ import {
import { getTSDocFromServer, getChangelogFromServer } from './server';

export default function Page({ params }: { params: { component: string } }) {
const [isTablet] = useMediaQuery(['(max-width: 768px)'], {
fallback: [true],
});
const [isLoading, setIsLoading] = useState(true);
const [componentProps, setComponentProps] = useState<Array<PropTableState>>(
[],
Expand Down Expand Up @@ -78,11 +82,13 @@ export default function Page({ params }: { params: { component: string } }) {
<div
className={css`
display: grid;
grid-template-columns: 2fr 1fr;
gap: ${spacing[800]}px;
grid-template-columns: ${isTablet ? '1fr' : '2fr 1fr'};
max-width: 100%;
`}
>
<InstallCard component={params.component} />

<VersionCard
component={params.component}
getChangelog={getChangelogFromServer}
Expand Down
43 changes: 25 additions & 18 deletions src/app/template.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
"use client";
'use client';

import { css } from "@emotion/css";
import React, { useEffect, useState } from "react";

import { useDarkMode } from "@leafygreen-ui/leafygreen-provider";
import { color, spacing } from "@leafygreen-ui/tokens";
import { css, cx } from '@emotion/css';
import React, { useEffect, useState } from 'react';
import { useDarkMode } from '@leafygreen-ui/leafygreen-provider';
import { color, spacing } from '@leafygreen-ui/tokens';

import {
DarkModeToggle,
Footer,
UserMenu,
SideNavigation,
} from "@/components/global";
import { SIDE_NAV_WIDTH } from "@/constants";
import { ContentStackContextProvider } from "@/contexts/ContentStackContext";
import { ComponentFields, ContentPageGroup } from "@/utils/ContentStack/types";
} from '@/components/global';
import { useMediaQuery } from '@/hooks/useMediaQuery';
import { BREAKPOINTS, SIDE_NAV_WIDTH } from '@/constants';
import { ContentStackContextProvider } from '@/contexts/ContentStackContext';
import { ComponentFields, ContentPageGroup } from '@/utils/ContentStack/types';
import {
getComponents,
getContentPageGroups,
} from "@/utils/ContentStack/getContentstackResources";
} from '@/utils/ContentStack/getContentstackResources';

const useGetInitialContentStackContext = () => {
const [components, setComponents] = useState<ComponentFields[]>([]);
Expand Down Expand Up @@ -46,6 +46,9 @@ const useGetInitialContentStackContext = () => {

export default function Template({ children }: { children: React.ReactNode }) {
const { darkMode } = useDarkMode();
const [isMobile] = useMediaQuery(['(max-width: 640px)'], {
fallback: [false],
});
const { components, contentPageGroups } = useGetInitialContentStackContext();

return (
Expand Down Expand Up @@ -80,13 +83,17 @@ export default function Template({ children }: { children: React.ReactNode }) {
</div>

<div
className={css`
margin-left: ${SIDE_NAV_WIDTH}px; // SideNav override
height: 100%;
padding-left: ${spacing[1000]}px;
padding-right: ${spacing[1000]}px;
padding-top: ${spacing[1600]}px;
`}
className={cx(
css`
height: 100%;
margin-left: ${isMobile
? 0
: `${SIDE_NAV_WIDTH}px`}; // SideNav override}))}
padding-left: ${spacing[1000]}px;
padding-right: ${spacing[1000]}px;
padding-top: ${spacing[1600]}px;
`,
)}
>
<ContentStackContextProvider
components={components}
Expand Down
24 changes: 13 additions & 11 deletions src/components/code-docs/InstallCard.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"use-client";
'use-client';

import React, { useState } from "react";
import { css } from "@emotion/css";
import Card from "@leafygreen-ui/card";
import Copyable from "@leafygreen-ui/copyable";
import React, { useState } from 'react';
import { css } from '@emotion/css';
import Card from '@leafygreen-ui/card';
import Copyable from '@leafygreen-ui/copyable';
import {
SegmentedControl,
SegmentedControlOption,
} from "@leafygreen-ui/segmented-control";
import { spacing } from "@leafygreen-ui/tokens";
import { Subtitle } from "@leafygreen-ui/typography";
} from '@leafygreen-ui/segmented-control';
import { spacing } from '@leafygreen-ui/tokens';
import { Subtitle } from '@leafygreen-ui/typography';

export const InstallCard = ({ component }: { component: string }) => {
const [packageManager, setPackageManager] = useState("yarn");
const [packageManager, setPackageManager] = useState('yarn');

return (
<Card>
Expand All @@ -27,7 +27,8 @@ export const InstallCard = ({ component }: { component: string }) => {
<div
className={css`
display: flex;
gap: ${spacing[100]}px;
flex-wrap: wrap;
gap: 8px;
`}
>
<SegmentedControl
Expand All @@ -43,9 +44,10 @@ export const InstallCard = ({ component }: { component: string }) => {
id="install-instructions"
className={css`
margin: unset;
width: unset;
`}
>
{packageManager === "yarn"
{packageManager === 'yarn'
? `yarn add @leafygreen-ui/${component}`
: `npm i @leafygreen-ui/${component}`}
</Copyable>
Expand Down
28 changes: 14 additions & 14 deletions src/components/code-docs/VersionCard.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"use client";
'use client';

import React, { useEffect, useState } from "react";
import { css } from "@emotion/css";
import Button from "@leafygreen-ui/button";
import Card from "@leafygreen-ui/card";
import React, { useEffect, useState } from 'react';
import { css } from '@emotion/css';
import Button from '@leafygreen-ui/button';
import Card from '@leafygreen-ui/card';
// @ts-expect-error
import ActivityFeed from "@leafygreen-ui/icon/dist/ActivityFeed";
import Modal from "@leafygreen-ui/modal";
import { CardSkeleton } from "@leafygreen-ui/skeleton-loader";
import { spacing } from "@leafygreen-ui/tokens";
import { Subtitle } from "@leafygreen-ui/typography";
import { color } from "@leafygreen-ui/tokens";
import ActivityFeed from '@leafygreen-ui/icon/dist/ActivityFeed';
import Modal from '@leafygreen-ui/modal';
import { CardSkeleton } from '@leafygreen-ui/skeleton-loader';
import { spacing } from '@leafygreen-ui/tokens';
import { Subtitle } from '@leafygreen-ui/typography';
import { color } from '@leafygreen-ui/tokens';

export const VersionCard = ({
component,
Expand All @@ -26,14 +26,14 @@ export const VersionCard = ({

useEffect(() => {
getChangelog(component)
.then((response) => {
.then(response => {
setChangelog(response);
})
.finally(() => setIsLoading(false));
}, [component, getChangelog]);

useEffect(() => {
setVersion(changelog?.split("h2")[1]?.replace(/[>/<]+/g, "") ?? null);
setVersion(changelog?.split('h2')[1]?.replace(/[>/<]+/g, '') ?? null);
}, [changelog]);

if (isLoading) {
Expand All @@ -55,7 +55,7 @@ export const VersionCard = ({
leftGlyph={<ActivityFeed />}
onClick={() => setIsModalOpen(true)}
>
View Changelog
View&nbsp;Changelog
</Button>
<Modal open={isModalOpen} setOpen={setIsModalOpen}>
<div
Expand Down
1 change: 0 additions & 1 deletion src/components/content-stack/ContentstackText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const ContentstackText = ({
}: CSRichTextProps) => {
const { theme } = useDarkMode();
const Component = node.bold ? 'b' : 'span';
console.log({ node });

return (
<Component
Expand Down
122 changes: 122 additions & 0 deletions src/components/global/SideNavigation/Drawer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
'use client';

import React, { useEffect, useState } from 'react';
import { css, keyframes } from '@emotion/css';
// @ts-expect-error
import XIcon from '@leafygreen-ui/icon/dist/XWithCircle';
import IconButton from '@leafygreen-ui/icon-button';
import { color, spacing, transitionDuration } from '@leafygreen-ui/tokens';
import { useDarkMode } from '@leafygreen-ui/leafygreen-provider';

const slideIn = keyframes`
from {
transform: translateX(-100%);
}
to {
transform: translateX(0);
}
`;

const slideOut = keyframes`
from {
transform: translateX(0);
}
to {
transform: translateX(-100%);
}
`;

const fadeIn = keyframes`
from {
opacity: 0;
}
to {
opacity: 1;
}
`;

const fadeOut = keyframes`
from {
opacity: 1;
}
to {
opacity: 0.5;
}
`;

export const Drawer = ({
isOpen,
onClose,
children,
}: {
isOpen: boolean;
onClose: () => void;
children: React.ReactNode;
}) => {
const { theme } = useDarkMode();
const [firstMount, setFirstMount] = useState(false);

useEffect(() => {
if (isOpen && !firstMount) {
setFirstMount(true);
}
}, [isOpen, firstMount]);

if (!firstMount) {
return null;
}

return (
<>
<div
onClick={onClose}
className={css`
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.75);
z-index: ${isOpen ? 1 : 0};
opacity: ${isOpen ? 1 : 0};
animation: ${isOpen ? fadeIn : fadeOut}
${transitionDuration.slowest}ms backwards;
`}
/>

<div
className={css`
position: fixed;
top: 0;
left: 0;
width: 60%;
height: 100%;
background-color: ${color[theme].background.secondary.default};
color: white;
overflow: hidden;
animation: ${isOpen ? slideIn : slideOut}
${transitionDuration.slowest}ms forwards;
z-index: 2;
padding-bottom: ${spacing[400]}px;
overflow-y: scroll;
`}
>
<IconButton
aria-label="Close Menu"
size="large"
onClick={onClose}
className={css`
position: absolute;
right: 0;
top: 0;
/* z-index: 5; */
padding: ${spacing[600]}px;
`}
>
<XIcon size="large" />
</IconButton>
{children}
</div>
</>
);
};
Loading

0 comments on commit a213d1a

Please sign in to comment.