Skip to content

Commit

Permalink
site: Fix previews theme overrides (#1545)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltaranto authored Jul 30, 2024
1 parent 0d9cb62 commit 83acbea
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 48 deletions.
49 changes: 21 additions & 28 deletions site/src/App/DocNavigation/DocDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useContext } from 'react';
import {
Stack,
BraidProvider,
List,
TextLink,
Secondary,
Expand All @@ -10,29 +9,25 @@ import {
import { PlayroomStateProvider } from 'braid-src/lib/playroom/playroomState';
import { LinkableHeading } from '@braid-design-system/docs-ui';
import { PageTitle } from '../Seo/PageTitle';
import { useThemeSettings } from '../ThemeSetting';
import { DocsContext } from './DocNavigation';
import { DocExample } from './DocExample';

export const DocDetails = () => {
const { theme } = useThemeSettings();
const { docs, docsName } = useContext(DocsContext);

return docs ? (
<>
<PageTitle title={docsName} />
<Stack space="xxlarge">
{'Example' in docs && docs.Example ? (
<BraidProvider styleBody={false} theme={theme}>
<PlayroomStateProvider>
<DocExample
id={`${docsName}_example`}
Example={docs.Example}
background={docs.examplebackground}
showCodeByDefault={docs.category === 'Logic'}
/>
</PlayroomStateProvider>
</BraidProvider>
<PlayroomStateProvider>
<DocExample
id={`${docsName}_example`}
Example={docs.Example}
background={docs.examplebackground}
showCodeByDefault={docs.category === 'Logic'}
/>
</PlayroomStateProvider>
) : null}

{docs.description ? (
Expand Down Expand Up @@ -72,21 +67,19 @@ export const DocDetails = () => {
) : null}
{example.description ?? null}
{example.code || example.Example ? (
<BraidProvider styleBody={false} theme={theme}>
<PlayroomStateProvider>
<DocExample
id={String(index)}
code={example.code}
Example={example.Example}
Container={example.Container}
background={example.background}
showCodeByDefault={
example.showCodeByDefault || example.Example === undefined
}
playroom={example.playroom}
/>
</PlayroomStateProvider>
</BraidProvider>
<PlayroomStateProvider>
<DocExample
id={String(index)}
code={example.code}
Example={example.Example}
Container={example.Container}
background={example.background}
showCodeByDefault={
example.showCodeByDefault || example.Example === undefined
}
playroom={example.playroom}
/>
</PlayroomStateProvider>
) : null}
</Stack>
))}
Expand Down
35 changes: 16 additions & 19 deletions site/src/App/DocNavigation/DocExample.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React, { type ReactNode } from 'react';
import { BraidProvider, Stack } from 'braid-src/lib/components';
import { Stack } from 'braid-src/lib/components';
import { useSourceFromExample } from '../useSourceFromExample/useSourceFromExample';
import type { ComponentExample } from '../../types';
import Code from '../Code/Code';
import { ThemedExample } from '../ThemeSetting';
import docsTheme from 'braid-src/entries/themes/docs';

const DefaultContainer = ({ children }: { children: ReactNode }) => (
<>{children}</>
Expand Down Expand Up @@ -34,22 +33,20 @@ export const DocExample = ({
});

return (
<BraidProvider styleBody={false} theme={docsTheme}>
<Stack space={background === false ? 'medium' : 'xxsmall'}>
{value ? (
<ThemedExample
background={background || undefined}
transparent={background === false}
>
<Container>{value}</Container>
</ThemedExample>
) : null}
{code !== false && codeAsString ? (
<Code collapsedByDefault={!showCodeByDefault} playroom={playroom}>
{codeAsString}
</Code>
) : null}
</Stack>
</BraidProvider>
<Stack space={background === false ? 'medium' : 'xxsmall'}>
{value ? (
<ThemedExample
background={background || undefined}
transparent={background === false}
>
<Container>{value}</Container>
</ThemedExample>
) : null}
{code !== false && codeAsString ? (
<Code collapsedByDefault={!showCodeByDefault} playroom={playroom}>
{codeAsString}
</Code>
) : null}
</Stack>
);
};
6 changes: 5 additions & 1 deletion site/src/App/ThemeSetting/ThemedExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ export function ThemedExample({
<Box opacity={!ready ? 0 : undefined} transition="fast">
<BraidProvider styleBody={false} theme={theme}>
<Box
background={darkCanvas ? 'customDark' : undefined}
background={
darkCanvas
? 'customDark'
: { lightMode: 'customLight', darkMode: 'customDark' }
}
borderRadius="large"
>
<Box
Expand Down

0 comments on commit 83acbea

Please sign in to comment.