Skip to content

Commit

Permalink
feat: useTheme hook
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jun 10, 2020
1 parent d1b8f97 commit 182907d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions ui/blocks/src/Playground/Playground.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { FC, Children, useContext } from 'react';
import Octicon, { Plus, Dash, Sync } from '@primer/octicons-react';
import { useThemeUI } from 'theme-ui';
import {
BackgroundType,
DirectionType,
PanelContainer,
PanelContainerProps,
IconButton,
Zoom,
useTheme,
} from '@component-controls/components';
import { BlockDataContext } from '../context';

Expand Down Expand Up @@ -46,7 +46,7 @@ export const Playground: FC<PlaygroundProps> = ({
description,
scale: userScale = 1,
}) => {
const { theme } = useThemeUI();
const theme = useTheme();

const [scale, setScale] = React.useState(userScale);
const [background, setBackground] = React.useState<BackgroundType>('light');
Expand Down
5 changes: 3 additions & 2 deletions ui/components/src/ActionBar/ActionBar.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/** @jsx jsx */
import { FC } from 'react';
import { transparentize } from 'polished';
import { Theme, Box, Flex, Button, jsx, useThemeUI } from 'theme-ui';
import { Theme, Box, Flex, Button, jsx } from 'theme-ui';
import { getSortedActions, ActionItems } from './utils';
import { useTheme } from '../ThemeContext';

export interface ActionBarProps {
/**
Expand Down Expand Up @@ -45,7 +46,7 @@ const ActionColors = ({
*
*/
export const ActionBar: FC<ActionBarProps> = ({ actions = [] }) => {
const { theme } = useThemeUI();
const theme = useTheme();
const sortedItems = getSortedActions(actions);
const items = sortedItems.map(
({ title, onClick, disabled, 'aria-label': ariaLabel, group }, index) => {
Expand Down
5 changes: 3 additions & 2 deletions ui/components/src/PanelContainer/PanelContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { FC, MouseEvent, useCallback } from 'react';
import { Button, ButtonProps, useThemeUI } from 'theme-ui';
import { Button, ButtonProps } from 'theme-ui';
import { Collapsible } from '../Collapsible';
import { Tab, Tabs, TabList, TabPanel } from '../Tabs';
import { getSortedPanels, ActionItems, ActionItem } from '../ActionBar';
import { ActionContainer, ActionContainerProps } from '../ActionContainer';
import { useTheme } from '../ThemeContext';

export const IconButton = (props: ButtonProps) => (
<Button style={{ paddingTop: '3px', paddingBottom: '3px' }} {...props} />
Expand Down Expand Up @@ -53,7 +54,7 @@ export const PanelContainer: FC<PanelContainerProps> = ({
undefined,
);

const { theme } = useThemeUI();
const theme = useTheme();

const panels: ActionItems = getSortedPanels(actions);

Expand Down
6 changes: 3 additions & 3 deletions ui/components/src/Table/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable react/jsx-key */
/** @jsx jsx */
import { FC, Fragment, ReactNode, useEffect } from 'react';
import { Box, BoxProps, Flex, useThemeUI, jsx } from 'theme-ui';
import { Box, BoxProps, Flex, jsx } from 'theme-ui';
import { get } from '@theme-ui/css';
import memoize from 'fast-memoize';
import {
Expand Down Expand Up @@ -34,7 +34,7 @@ import { GlobalFilter } from './TableFilter';
import { useExpanderColumn } from './TableGrouping';
import { useRowSelectionColumn } from './TableRowSelection';
import { useTableLayout } from './useTableLayout';

import { useTheme } from '../ThemeContext';
const defaultColumn = memoize(() => ({
subRows: undefined,
accessor: '',
Expand Down Expand Up @@ -195,7 +195,7 @@ export const Table: FC<TableProps> = ({
onSelectRowsChange(selectedRowIds as SelectedRowIds);
}
}, [selectedRowIds, onSelectRowsChange]);
const { theme } = useThemeUI();
const theme = useTheme();
return (
<Box
as="table"
Expand Down
5 changes: 3 additions & 2 deletions ui/components/src/Table/TableGrouping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {
UseExpandedRowProps,
UseTableRowProps,
} from 'react-table';
import { Flex, Text, useThemeUI } from 'theme-ui';
import { Flex, Text } from 'theme-ui';
import { get } from '@theme-ui/css';
import Octicon, { ChevronRight, ChevronDown } from '@primer/octicons-react';
import { useTheme } from '../ThemeContext';

type GroupByState = TableState & Partial<UseGroupByState<{}>>;
const useControlledState = (state: GroupByState) => {
Expand Down Expand Up @@ -49,7 +50,7 @@ export const useExpanderColumn = (itemsLabel: string) => (
groupByVal: any;
};
}) => {
const { theme } = useThemeUI();
const theme = useTheme();
if (row.canExpand) {
return (
<td colSpan={row.cells.length}>
Expand Down

0 comments on commit 182907d

Please sign in to comment.