Skip to content

Commit

Permalink
docs: use selected theme in code demos (#3169)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Sebald <[email protected]>
  • Loading branch information
sarahgm and sebald authored Jul 20, 2023
1 parent d36d4ef commit f0484d2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/app/_components/ThemeSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const useThemeSwitch = () => useContext(Context);
export interface MarigoldThemeSwitchProps {
children?: ReactNode;
themes: { [name: string]: Theme };
initial?: string;
initial: string;
}

export const MarigoldThemeSwitch = ({
Expand Down
10 changes: 7 additions & 3 deletions docs/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import './globals.css';
import '@marigold/theme-b2b/index.css';
import '@marigold/theme-core/index.css';

import { MarigoldProvider } from '@/ui';
import { theme } from '@/theme';
import { theme, b2bTheme, coreTheme } from '@/theme';
import { fontSans } from '@/theme/fonts';

import { Analytics } from './_components/Analytics';
import { Navigation } from './_components/Navigation';
import { SiteHeader } from './_components/SiteHeader';
import { MarigoldThemeSwitch } from './_components/ThemeSwitch';
import { b2bTheme, coreTheme } from '@/theme';

// Metadata
// ---------------
export const metadata = {
title: 'Marigold Documentation',
description: "Documentation of Reservix' Design System",
};

// Themes
// ---------------
const themes = {
b2b: b2bTheme,
core: coreTheme,
Expand All @@ -27,7 +31,7 @@ const Layout = ({ children }: { children: React.ReactNode }) => {
return (
<html lang="en">
<body className={`${fontSans.className} min-h-screen`}>
<MarigoldThemeSwitch themes={themes}>
<MarigoldThemeSwitch themes={themes} initial="b2b">
<MarigoldProvider theme={theme}>
<div className="flex min-h-screen flex-col">
<SiteHeader />
Expand Down
2 changes: 2 additions & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"@marigold/components": "workspace:*",
"@marigold/eslint-config": "workspace:*",
"@marigold/icons": "workspace:*",
"@marigold/theme-b2b": "workspace:*",
"@marigold/theme-core": "workspace:*",
"@marigold/theme-preset": "workspace:*",
"@tailwindcss/typography": "0.5.9",
"@vercel/analytics": "1.0.1",
Expand Down
1 change: 1 addition & 0 deletions docs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"baseUrl": ".",
"paths": {
"@/*": ["./*"],
"@marigold/*/index.css": ["../themes/*/dist/index.css"],
"@marigold/*": ["../packages/*/src", "../themes/*/src"],
"contentlayer/generated": ["./.contentlayer/generated"]
},
Expand Down
13 changes: 11 additions & 2 deletions docs/ui/ComponentDemo.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { ReactNode } from 'react';
import { type Theme } from '@marigold/system';

import { registry } from '../registry';
import { MarigoldProvider } from './marigold';

import { useThemeSwitch } from '@/app/_components/ThemeSwitch';
export interface ComponentDemoProps {
name: keyof typeof registry;
source: string;
Expand All @@ -13,15 +17,20 @@ export const ComponentDemo = ({
children,
}: ComponentDemoProps) => {
const Demo = registry[name].demo;
const { current, themes } = useThemeSwitch();

return (
<div className="bg-cyan-800 p-10 text-cyan-100">
<pre>
<code className="language-tsx">{source}</code>
</pre>
<hr />
<div>
<Demo />
<div data-theme={current}>
<MarigoldProvider theme={(current && themes[current]) as Theme}>
<div className="px-4 py-6">
<Demo />
</div>
</MarigoldProvider>
</div>
</div>
);
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 comments on commit f0484d2

@vercel
Copy link

@vercel vercel bot commented on f0484d2 Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

marigold-docs – ./

marigold-docs.vercel.app
marigold-docs-git-main-marigold.vercel.app
marigold-docs-marigold.vercel.app

@vercel
Copy link

@vercel vercel bot commented on f0484d2 Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

marigold-storybook – ./

marigold-storybook-git-main-marigold.vercel.app
marigold-storybook-marigold.vercel.app
marigold-latest.vercel.app

Please sign in to comment.