Skip to content

Commit

Permalink
fix: dark mode removed from theme context
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jun 21, 2020
1 parent 8b9e463 commit 74d3b51
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 17 deletions.
9 changes: 2 additions & 7 deletions ui/blocks/src/ComponentSource/ComponentSource.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -27,7 +23,6 @@ export const ComponentSource: FC<ComponentSourceProps> = ({
...rest
}) => {
const [showFileSource, setShowFileSource] = React.useState<boolean>(false);
const { dark } = React.useContext(ThemeContext);
return (
<ComponentsBlockContainer visibility="info" {...rest}>
{(component, props, sourceProps) => {
Expand Down Expand Up @@ -66,7 +61,7 @@ export const ComponentSource: FC<ComponentSourceProps> = ({
allActions.push.apply(allActions, actions);
}
return (
<Source dark={dark} {...sourceProps} actions={allActions}>
<Source {...sourceProps} actions={allActions}>
{showFileSource ? component?.source ?? '' : source}
</Source>
);
Expand Down
6 changes: 2 additions & 4 deletions ui/blocks/src/StoryConfig/BaseStoryConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,7 +28,6 @@ export const BaseStoryConfig: FC<BaseStoryConfigProps> = ({
const [showFileSource, setShowFileSource] = useState<boolean>(false);
const onShowFileSource = () => setShowFileSource(!showFileSource);

const { dark } = useContext(ThemeContext);
const allActions: ActionItem[] = [];
const repositoryItems = repositoryActions(docPackage);
if (repositoryItems) {
Expand Down Expand Up @@ -57,7 +55,7 @@ export const BaseStoryConfig: FC<BaseStoryConfigProps> = ({
restStory.parameters = restParameters;
}
return Object.keys(restStory).length ? (
<Source dark={dark} language="json" {...sourceProps} actions={allActions}>
<Source language="json" {...sourceProps} actions={allActions}>
{JSON.stringify(restStory, null, 2)}
</Source>
) : null;
Expand Down
5 changes: 1 addition & 4 deletions ui/blocks/src/StorySource/BaseStorySource.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -51,7 +50,6 @@ export const BaseStorySource: FC<BaseStorySourceProps> = ({
const onShowFileSource = () => setShowFileSource(!showFileSource);

const { controls } = story || {};
const { dark } = useContext(ThemeContext);
const allActions: ActionItem[] = [];
const repositoryItems = repositoryActions(docPackage);
if (repositoryItems) {
Expand Down Expand Up @@ -85,7 +83,6 @@ export const BaseStorySource: FC<BaseStorySourceProps> = ({
return (
<Source
actions={allActions}
dark={dark}
{...sourceProps}
renderFn={(
{ className, style, tokens, getLineProps, getTokenProps }: any,
Expand Down
1 change: 1 addition & 0 deletions ui/blocks/src/context/block/BlockContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const BlockContextProvider: React.FC<BlockContextInputProps> = ({
options,
}) => {
let storyId = propsStoryId;
console.log(propsStoryId, propsDocId);
const docId = storyId || propsDocId;
if (!storyId && docId) {
const doc = store.getStoryDoc(docId);
Expand Down
7 changes: 5 additions & 2 deletions ui/components/src/SyntaxHighlighter/SyntaxHighlighter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -63,7 +63,10 @@ export const SyntaxHighlighter: FC<SyntaxHighlighterProps> = ({
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 })
Expand Down

0 comments on commit 74d3b51

Please sign in to comment.