From 74d3b51b0f7f34418403a57689b231f21efab4c2 Mon Sep 17 00:00:00 2001 From: atanasster Date: Sun, 21 Jun 2020 17:38:11 -0400 Subject: [PATCH] fix: dark mode removed from theme context --- ui/blocks/src/ComponentSource/ComponentSource.tsx | 9 ++------- ui/blocks/src/StoryConfig/BaseStoryConfig.tsx | 6 ++---- ui/blocks/src/StorySource/BaseStorySource.tsx | 5 +---- ui/blocks/src/context/block/BlockContext.tsx | 1 + .../src/SyntaxHighlighter/SyntaxHighlighter.tsx | 7 +++++-- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/ui/blocks/src/ComponentSource/ComponentSource.tsx b/ui/blocks/src/ComponentSource/ComponentSource.tsx index d64b0c4cb..450dbf687 100644 --- a/ui/blocks/src/ComponentSource/ComponentSource.tsx +++ b/ui/blocks/src/ComponentSource/ComponentSource.tsx @@ -1,10 +1,6 @@ import React, { FC } from 'react'; import { ActionItem } from '@component-controls/components'; -import { - ThemeContext, - Source, - SourceProps, -} from '@component-controls/components'; +import { Source, SourceProps } from '@component-controls/components'; import { ComponentsBlockContainer, ComponentsBlockContainerProps, @@ -27,7 +23,6 @@ export const ComponentSource: FC = ({ ...rest }) => { const [showFileSource, setShowFileSource] = React.useState(false); - const { dark } = React.useContext(ThemeContext); return ( {(component, props, sourceProps) => { @@ -66,7 +61,7 @@ export const ComponentSource: FC = ({ allActions.push.apply(allActions, actions); } return ( - + {showFileSource ? component?.source ?? '' : source} ); diff --git a/ui/blocks/src/StoryConfig/BaseStoryConfig.tsx b/ui/blocks/src/StoryConfig/BaseStoryConfig.tsx index 5a506dfed..434ff79be 100644 --- a/ui/blocks/src/StoryConfig/BaseStoryConfig.tsx +++ b/ui/blocks/src/StoryConfig/BaseStoryConfig.tsx @@ -3,10 +3,9 @@ /** @jsx jsx */ /* eslint react/jsx-key: 0 */ import { jsx } from 'theme-ui'; -import { FC, useState, useContext } from 'react'; +import { FC, useState } from 'react'; import { Story, StoriesDoc, PackageInfo } from '@component-controls/core'; import { - ThemeContext, Source, SourceProps, ActionItem, @@ -29,7 +28,6 @@ export const BaseStoryConfig: FC = ({ const [showFileSource, setShowFileSource] = useState(false); const onShowFileSource = () => setShowFileSource(!showFileSource); - const { dark } = useContext(ThemeContext); const allActions: ActionItem[] = []; const repositoryItems = repositoryActions(docPackage); if (repositoryItems) { @@ -57,7 +55,7 @@ export const BaseStoryConfig: FC = ({ restStory.parameters = restParameters; } return Object.keys(restStory).length ? ( - + {JSON.stringify(restStory, null, 2)} ) : null; diff --git a/ui/blocks/src/StorySource/BaseStorySource.tsx b/ui/blocks/src/StorySource/BaseStorySource.tsx index ffd260b3e..0e9a7dd29 100644 --- a/ui/blocks/src/StorySource/BaseStorySource.tsx +++ b/ui/blocks/src/StorySource/BaseStorySource.tsx @@ -1,11 +1,10 @@ /* eslint-disable react/jsx-key */ /** @jsx jsx */ import { jsx } from 'theme-ui'; -import { FC, useState, useContext } from 'react'; +import { FC, useState } from 'react'; import { Styled } from 'theme-ui'; import { Story, StoriesDoc, PackageInfo } from '@component-controls/core'; import { - ThemeContext, Source, SourceProps, ActionItem, @@ -51,7 +50,6 @@ export const BaseStorySource: FC = ({ const onShowFileSource = () => setShowFileSource(!showFileSource); const { controls } = story || {}; - const { dark } = useContext(ThemeContext); const allActions: ActionItem[] = []; const repositoryItems = repositoryActions(docPackage); if (repositoryItems) { @@ -85,7 +83,6 @@ export const BaseStorySource: FC = ({ return ( = ({ options, }) => { let storyId = propsStoryId; + console.log(propsStoryId, propsDocId); const docId = storyId || propsDocId; if (!storyId && docId) { const doc = store.getStoryDoc(docId); diff --git a/ui/components/src/SyntaxHighlighter/SyntaxHighlighter.tsx b/ui/components/src/SyntaxHighlighter/SyntaxHighlighter.tsx index 39f2a55ea..3cec38989 100644 --- a/ui/components/src/SyntaxHighlighter/SyntaxHighlighter.tsx +++ b/ui/components/src/SyntaxHighlighter/SyntaxHighlighter.tsx @@ -2,7 +2,7 @@ /* eslint react/jsx-key: 0 */ import { jsx } from 'theme-ui'; import React, { FC } from 'react'; -import { Styled, Box } from 'theme-ui'; +import { Styled, Box, useColorMode } from 'theme-ui'; import Highlight, { defaultProps, PrismTheme, @@ -63,7 +63,10 @@ export const SyntaxHighlighter: FC = ({ style: propStyle, as = 'span', }) => { - const theme = customTheme ? customTheme : dark ? duotoneDark : duotoneLight; + const [colorMode] = useColorMode(); + const isDark = dark === true || colorMode === `dark`; + const theme = customTheme ? customTheme : isDark ? duotoneDark : duotoneLight; + const renderProps = typeof renderFn === 'function' ? (props: RenderProps) => renderFn(props, { theme })