Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated PR: staging to main #368

Merged
merged 13 commits into from
Jun 12, 2024
17,508 changes: 12,158 additions & 5,350 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@storybook/react": "^8.0.10",
"commander": "^12.0.0",
"contentstack": "^3.19.2",
"fuse.js": "^7.0.0",
"lodash": "^4.17.21",
"marked": "^12.0.2",
"next": "14.2.3",
Expand Down
12 changes: 10 additions & 2 deletions src/app/component/[component]/design-docs/client.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
'use client';

import { css } from '@emotion/css';
import { ContentstackRichText } from '@/components/content-stack';
import { CSNode } from '@/components/content-stack/types';
import { ErrorBoundary } from 'next/dist/client/components/error-boundary';

interface DesignDocsContentProps {
content?: CSNode;
}

export const DesignDocsContent = ({ content }: DesignDocsContentProps) => {
return <ContentstackRichText content={content} />;
return (
<div
className={css`
max-width: 700px;
`}
>
<ContentstackRichText content={content} />
</div>
);
};
8 changes: 1 addition & 7 deletions src/app/component/[component]/design-docs/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { css } from '@emotion/css';

import { fetchComponent } from '@/utils/ContentStack/getContentstackResources';
import { DesignDocsContent } from './client';

Expand All @@ -13,11 +11,7 @@ export default async function Page({
});

return (
<div
className={css`
max-width: 700px; // TODO: Make this responsive
`}
>
<div>
<DesignDocsContent content={component?.designguidelines} />
</div>
);
Expand Down
64 changes: 33 additions & 31 deletions src/app/component/[component]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
"use client";
'use client';

import { css } from "@emotion/css";
import { useRouter, usePathname } from "next/navigation";
import React from "react";
import { css } from '@emotion/css';
import { useRouter, usePathname } from 'next/navigation';
import React from 'react';

import IconButton from "@leafygreen-ui/icon-button";
import { CodeSandbox, Figma, Github } from "@/components/glyphs";
import { useDarkMode } from "@leafygreen-ui/leafygreen-provider";
import { Tabs, Tab } from "@leafygreen-ui/tabs";
import { color, spacing } from "@leafygreen-ui/tokens";
import { H2 } from "@leafygreen-ui/typography";
import IconButton from '@leafygreen-ui/icon-button';
import { CodeSandbox, Figma, Github } from '@/components/glyphs';
import { useDarkMode } from '@leafygreen-ui/leafygreen-provider';
import { Tabs, Tab } from '@leafygreen-ui/tabs';
import { color, spacing } from '@leafygreen-ui/tokens';
import { H2 } from '@leafygreen-ui/typography';

import useComponentFields from "@/hooks/useComponentFields";
import { getGithubLink } from "@/utils";
import { useComponentFields } from '@/hooks';
import { getGithubLink } from '@/utils';

const liveExamplePath = "live-example";
const designDocsPath = "design-docs";
const codeDocsPath = "code-docs";
const liveExamplePath = 'live-example';
const designDocsPath = 'design-docs';
const codeDocsPath = 'code-docs';

export default function ComponentLayout({
children,
Expand All @@ -25,13 +25,13 @@ export default function ComponentLayout({
}) {
const router = useRouter();
const pathname = usePathname();
const currentComponent = pathname.split("/")[2];
const currentComponent = pathname.split('/')[2];
const { theme } = useDarkMode();

const component = useComponentFields({ componentName: currentComponent });

const getSelected = () => {
const suffix = pathname.split("/")[3];
const suffix = pathname.split('/')[3];
if (suffix === liveExamplePath) {
return 0;
}
Expand Down Expand Up @@ -61,7 +61,7 @@ export default function ComponentLayout({
href: component?.codesandbox_url?.href,
icon: <CodeSandbox />,
},
]
];

return (
<div
Expand All @@ -75,7 +75,7 @@ export default function ComponentLayout({
margin-bottom: ${spacing[600]}px;
`}
>
{currentComponent.split("-").join(" ")}
{currentComponent.split('-').join(' ')}
</H2>
<Tabs
selected={getSelected()}
Expand All @@ -94,18 +94,20 @@ export default function ComponentLayout({
height: 100%;
`}
>
{externalLinks.map(({ 'aria-label': ariaLabel, href, icon }, index) => (
<IconButton
key={ariaLabel + index}
aria-label={ariaLabel}
size="large"
href={href}
target="_blank"
rel="noopener noreferrer"
>
{icon}
</IconButton>
))}
{externalLinks.map(
({ 'aria-label': ariaLabel, href, icon }, index) => (
<IconButton
key={ariaLabel + index}
aria-label={ariaLabel}
size="large"
href={href}
target="_blank"
rel="noopener noreferrer"
>
{icon}
</IconButton>
),
)}
</div>
}
>
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { css } from '@emotion/css';
import { RootStyleRegistry } from '@/components/global';
import { useMediaQuery } from '@/hooks/useMediaQuery';
import { useMediaQuery } from '@/hooks';
import LeafyGreenProvider, {
useDarkMode,
} from '@leafygreen-ui/leafygreen-provider';
Expand Down
31 changes: 12 additions & 19 deletions src/app/private/page.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
"use client";
'use client';

import { useEffect, useState } from "react";
import { useRouter } from "next/navigation";
import Button from "@leafygreen-ui/button";
import { BasicEmptyState } from "@leafygreen-ui/empty-state";
import { useEffect, useState } from 'react';
import { useRouter } from 'next/navigation';
import Button from '@leafygreen-ui/button';
import { BasicEmptyState } from '@leafygreen-ui/empty-state';
// @ts-expect-error
import ArrowLeftIcon from "@leafygreen-ui/icon/dist/ArrowLeft";
import ArrowLeftIcon from '@leafygreen-ui/icon/dist/ArrowLeft';
// @ts-expect-error
import LogInIcon from "@leafygreen-ui/icon/dist/LogIn";
import { getSession, login, Session } from "@/auth";
import { ComingSoon, Security } from "@/components/glyphs";
import LogInIcon from '@leafygreen-ui/icon/dist/LogIn';
import { getSession, login, Session } from '@/auth';
import { ComingSoon, Security } from '@/components/glyphs';
import { useSession } from '@/hooks';

export default function Private() {
const router = useRouter();
const [session, setSession] = useState<Session | undefined>();

useEffect(() => {
getSession().then((response) => {
if (response !== null) {
setSession(response);
}
});
}, []);
const session = useSession();

return session?.user ? (
<BasicEmptyState
title="Coming Soon"
description="Check back for updates soon"
primaryButton={
<Button leftGlyph={<ArrowLeftIcon />} onClick={() => router.push("/")}>
<Button leftGlyph={<ArrowLeftIcon />} onClick={() => router.push('/')}>
Return to home
</Button>
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {
Footer,
UserMenu,
SideNavigation,
Search,
} from '@/components/global';
import { useMediaQuery } from '@/hooks/useMediaQuery';
import { useMediaQuery } from '@/hooks';
import { SIDE_NAV_WIDTH } from '@/constants';
import { ContentStackContextProvider } from '@/contexts/ContentStackContext';
import { ComponentFields, ContentPageGroup } from '@/utils/ContentStack/types';
Expand Down Expand Up @@ -54,7 +55,6 @@ export default function Template({ children }: { children: React.ReactNode }) {
return (
<div
className={css`
position: relative;
min-height: 100vh;
height: 100%;
width: 100%;
Expand All @@ -78,8 +78,8 @@ export default function Template({ children }: { children: React.ReactNode }) {
right: 0;
`}
>
<DarkModeToggle />
<UserMenu />
<DarkModeToggle />
</div>

<div
Expand Down
92 changes: 92 additions & 0 deletions src/components/global/Search.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import React, { useEffect, useState, useCallback } from 'react';
import Link from 'next/link';
import { css } from '@emotion/css';
import Fuse, { IFuseOptions } from 'fuse.js';
import debounce from 'lodash/debounce';
// @ts-expect-error
import LockIcon from '@leafygreen-ui/icon/dist/Lock';
import { SearchInput, SearchResult } from '@leafygreen-ui/search-input';
import { spacing } from '@leafygreen-ui/tokens';
import { useSession } from '@/hooks';
import { components } from '@/utils/components';

const fuseOptions = {
includeScore: true,
keys: ['name', 'subComponents', 'group'],
};

const useFuseSearch = (data: any[], options: IFuseOptions<any>) => {
const fuse = new Fuse(data, options);
return (term: string) =>
term ? fuse.search(term).map(result => result.item) : data;
};

export function Search() {
const session = useSession();
const [searchTerm, setSearchTerm] = useState('');
const [results, setResults] = useState(components);

const search = useFuseSearch(components, fuseOptions);

const debouncedSearch = debounce((term: string) => {
setResults(search(term));
}, 300);

const handleSearchChange = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
const term = e.target.value;
setSearchTerm(term);

debouncedSearch(term);
},
[debouncedSearch],
);

useEffect(() => {
if (!searchTerm) {
setResults(components);
}
}, [searchTerm]);

return (
<SearchInput
aria-label="Search Components"
size="small"
value={searchTerm}
onChange={handleSearchChange}
className={css`
margin: ${spacing[400]}px ${spacing[600]}px;
`}
>
{results.map(item => (
<SearchResult
key={item.name}
description={
<div
className={css`
text-transform: capitalize;
`}
>
{item.group.split('-').join(' ')}
</div>
}
href={item.navPath ?? '/'}
// @ts-expect-error Polymorphic
as={Link}
>
<div
className={css`
display: flex;
align-items: center;

gap: ${spacing[200]}px;
`}
>
{item.name}
{item.isPrivate && !session?.user && <LockIcon size="small" />}
</div>
</SearchResult>
))}
</SearchInput>
);
}
Loading
Loading