Skip to content

Commit

Permalink
fix code configs (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Sep 17, 2023
1 parent 3db3a9f commit 0b2c9db
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
5 changes: 5 additions & 0 deletions packages/ui/app/src/docs-context/DocsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { FernRegistry } from "@fern-fern/registry-browser";
import * as FernRegistryApiRead from "@fern-fern/registry-browser/api/resources/api/resources/v1/resources/read";
import * as FernRegistryDocsRead from "@fern-fern/registry-browser/api/resources/docs/resources/v1/resources/read";
import { type ResolvedUrlPath } from "@fern-ui/app-utils";
import { Theme } from "@fern-ui/theme";
import React from "react";

export const DocsContext = React.createContext<() => DocsContextValue>(() => {
Expand Down Expand Up @@ -66,6 +67,10 @@ export interface DocsContextValue {

nextPath: ResolvedUrlPath | undefined;
previousPath: ResolvedUrlPath | undefined;

// theme
theme: Theme | undefined;
setTheme: (theme: Theme) => void;
}

export interface Anchor {
Expand Down
7 changes: 7 additions & 0 deletions packages/ui/app/src/docs-context/DocsContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "@fern-ui/app-utils";
import { assertNever } from "@fern-ui/core-utils";
import { useEventCallback } from "@fern-ui/react-commons";
import { useTheme } from "@fern-ui/theme";
import { useRouter } from "next/router";
import { PropsWithChildren, useCallback, useEffect, useMemo, useState } from "react";
import { DocsContext, DocsContextValue, type DocsInfo, type NavigateToPathOpts } from "./DocsContext";
Expand Down Expand Up @@ -199,6 +200,8 @@ export const DocsContextProvider: React.FC<DocsContextProvider.Props> = ({
scrollToPathListeners.invokeListeners(slug);
});

const { theme, setTheme } = useTheme(docsDefinition.config.colorsV3.type);

const contextValue = useCallback(
(): DocsContextValue => ({
resolveApi,
Expand All @@ -219,6 +222,8 @@ export const DocsContextProvider: React.FC<DocsContextProvider.Props> = ({
nextPath,
previousPath,
selectedSlug,
theme,
setTheme,
}),
[
docsDefinition,
Expand All @@ -239,6 +244,8 @@ export const DocsContextProvider: React.FC<DocsContextProvider.Props> = ({
resolvedUrlPath,
scrollToPathListeners.registerListener,
selectedSlug,
theme,
setTheme,
]
);

Expand Down
5 changes: 1 addition & 4 deletions packages/ui/app/src/docs/Docs.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PLATFORM } from "@fern-ui/core-utils";
import { useKeyboardCommand } from "@fern-ui/react-commons";
import { useTheme } from "@fern-ui/theme";
import { memo, useMemo } from "react";
import { useDocsContext } from "../docs-context/useDocsContext";
import { useMobileSidebarContext } from "../mobile-sidebar-context/useMobileSidebarContext";
Expand All @@ -14,7 +13,7 @@ import { Header } from "./Header";

export const Docs: React.FC = memo(function UnmemoizedDocs() {
const docsContext = useDocsContext();
const { docsDefinition } = docsContext;
const { docsDefinition, theme } = docsContext;
const searchContext = useSearchContext();
const { isSearchDialogOpen, openSearchDialog, closeSearchDialog } = searchContext;
const searchService = useSearchService();
Expand All @@ -26,8 +25,6 @@ export const Docs: React.FC = memo(function UnmemoizedDocs() {

const { colorsV3 } = docsDefinition.config;

const { theme } = useTheme(colorsV3.type);

const backgroundType = useMemo(() => {
if (theme == null) {
return null;
Expand Down
4 changes: 1 addition & 3 deletions packages/ui/app/src/docs/HeaderLogoSection.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { useTheme } from "@fern-ui/theme";
import { DEFAULT_LOGO_HEIGHT } from "../config";
import { useDocsContext } from "../docs-context/useDocsContext";
import { VersionDropdown } from "./VersionDropdown";

export declare namespace HeaderLogoSection {}

export const HeaderLogoSection: React.FC = () => {
const { resolveFile, docsDefinition, docsInfo, setActiveVersionSlug, navigateToPath } = useDocsContext();
const { theme } = useTheme(docsDefinition.config.colorsV3.type);
const { resolveFile, docsDefinition, docsInfo, setActiveVersionSlug, navigateToPath, theme } = useDocsContext();
const { logo, logoV2, logoHeight, logoHref } = docsDefinition.config;

if (theme == null) {
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/app/src/mdx/base-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CopyToClipboardButton } from "../commons/CopyToClipboardButton";
import { useDocsContext } from "../docs-context/useDocsContext";

export const CodeBlockInternalCore: React.FC<HTMLAttributes<HTMLElement>> = ({ children }) => {
const { theme } = useDocsContext();
if (children == null || typeof children !== "object") {
return null;
}
Expand All @@ -23,7 +24,7 @@ export const CodeBlockInternalCore: React.FC<HTMLAttributes<HTMLElement>> = ({ c
)}
>
<SyntaxHighlighter
style={prism.oneLight}
style={theme === "dark" ? prism.vscDarkPlus : prism.oneLight}
customStyle={{
width: "100%",
overflowX: "auto",
Expand Down

1 comment on commit 0b2c9db

@vercel
Copy link

@vercel vercel bot commented on 0b2c9db Sep 17, 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:

fern-dev – ./packages/ui/fe-bundle

fern-dev-buildwithfern.vercel.app
devtest.buildwithfern.com
fern-dev-git-main-buildwithfern.vercel.app
app-dev.buildwithfern.com

Please sign in to comment.