Skip to content

Commit

Permalink
Fixes the Shell type
Browse files Browse the repository at this point in the history
  • Loading branch information
AkimaLunar committed Nov 6, 2023
1 parent 26db213 commit 8780d7a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
5 changes: 3 additions & 2 deletions utilities/docs/gatsby-browser.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import * as React from 'react';
import type { WrapRootElementBrowserArgs, WrapPageElementBrowserArgs } from 'gatsby'

import { Shell } from './src/components/shell';
import { SSRSetup } from './src/components/ssr-setup';
import { Theme } from './src/components/theme';

export const wrapRootElement = ({ element }) => {
export const wrapRootElement = ({ element }: WrapRootElementBrowserArgs) => {
return (
<SSRSetup>
<Theme>{element}</Theme>
</SSRSetup>
);
};

export const wrapPageElement = ({ element, props }) => (
export const wrapPageElement = ({ element, props }: WrapPageElementBrowserArgs) => (
<Shell {...props}>{element}</Shell>
);
5 changes: 3 additions & 2 deletions utilities/docs/gatsby-ssr.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { SSRProvider } from '@fluentui/react-utilities';
import { createDOMRenderer, RendererProvider } from '@griffel/react';
import * as React from 'react';
import type { WrapRootElementNodeArgs, WrapPageElementNodeArgs } from 'gatsby'

import { Shell } from './src/components/shell';
import { Theme } from './src/components/theme';

const renderer = createDOMRenderer();

export const wrapRootElement = ({ element }) => (
export const wrapRootElement = ({ element }: WrapRootElementNodeArgs) => (
<RendererProvider renderer={renderer}>
<SSRProvider>
<Theme>{element}</Theme>
</SSRProvider>
</RendererProvider>
);

export const wrapPageElement = ({ element, props }) => (
export const wrapPageElement = ({ element, props }: WrapPageElementNodeArgs) => (
<Shell {...props}>{element}</Shell>
);
1 change: 1 addition & 0 deletions utilities/docs/src/components/shell/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { Shell } from './shell';
export type { ShellProps } from './shell.types';
15 changes: 9 additions & 6 deletions utilities/docs/src/components/shell/shell.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Text } from '@fluentui/react-text';
import { Shell as ArbutusShell } from '@microsoft/arbutus.shell';
import { useCSSVars } from '@microsoft/arbutus.use-css-vars';
import { useTheme } from '@microsoft/arbutus.theming';
import type { PageProps } from 'gatsby';
import { withPrefix } from 'gatsby';
import type { FC } from 'react';
import * as React from 'react';
import { BLUEPRINTS_DOCS_PREFIX, BLUEPRINTS_DOCS_THEME } from '../theme';

import { makeNavigate } from '../../utilities';
import { BLUEPRINTS_DOCS_PREFIX, BLUEPRINTS_DOCS_THEME } from '../theme';
import { FluentLogo } from '../fluent-logo';
import { Footer } from '../footer';
import { Header } from '../header';
import { makeNavigate } from '../../utilities';
import { Navigation } from '../navigation';
import { ShellProps } from './shell.types';
import { useLogoStyles } from './shell.styles';
import { FluentLogo } from '../fluent-logo';
import { Text } from '@fluentui/react-text';

const navigateHome = makeNavigate({ isExternal: false, to: '/' });

Expand All @@ -30,7 +30,10 @@ const Logo: FC = () => {
);
};

export const Shell: FC<PageProps> = ({ children, location }) => {
export const Shell: FC<ShellProps> = ({
children,
location,
}) => {
const isHome = location.pathname === withPrefix('/');
const isComponentPreview = location.pathname.includes('/preview/');
const isComponentSandbox = location.pathname.includes('/sandbox/');
Expand Down
11 changes: 11 additions & 0 deletions utilities/docs/src/components/shell/shell.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { PageProps } from 'gatsby';
import type { ReactNode } from 'react';

/**
* @description ShellProps is a type that extends the PageProps type from Gatsby and adds a children property. Shell is
* used in Gatsby browser and SSR configs to wrap the page component. `wrapPageElement` is used in Gatsby browser and
* SSR configs to add the Shell to the page component. It passes PageProps to the Shell component, but unlike Gatsby
* pages, Shell does indeed have children, so we are removing the children property 9set to `undefined` from PageProps
* and adding it to ShellProps.
*/
export type ShellProps = Omit<PageProps, 'children'> & { children: ReactNode };

0 comments on commit 8780d7a

Please sign in to comment.