From 71655121ce5dced043ddba627f900489421d78ac Mon Sep 17 00:00:00 2001 From: panagiotis vourtsis Date: Wed, 23 Sep 2020 10:17:44 +0300 Subject: [PATCH 1/4] fix: remove useTheme from components that was imported only for css functions --- src/components/Breadcrumb/Breadcrumb.tsx | 6 +- .../BreadcrumbCollapsed.tsx | 8 +-- .../BreadcrumbItem/BreadcrumbItem.tsx | 4 +- .../Breadcrumb/Separator/Separator.tsx | 4 +- .../Breadcrumb.stories.storyshot | 46 ++------------- src/components/Button/Button.tsx | 10 ++-- .../__snapshots__/Button.stories.storyshot | 52 +++-------------- src/components/CheckBox/CheckBox.style.ts | 10 ++-- src/components/CheckBox/CheckBox.tsx | 10 ++-- .../__snapshots__/CheckBox.stories.storyshot | 16 +---- src/components/DatePicker/DatePicker.style.ts | 8 +-- src/components/DatePicker/DatePicker.tsx | 4 +- .../OverlayComponent/OverlayComponent.tsx | 2 +- src/components/Icon/Icon.tsx | 5 +- .../Icon/__snapshots__/Icon.stories.storyshot | 24 +------- .../IconButton.stories.storyshot | 58 +++---------------- src/components/Label/Label.style.ts | 4 +- src/components/Label/Label.tsx | 5 +- .../Menu/__snapshots__/Menu.stories.storyshot | 14 +---- .../Pagination.stories.storyshot | 42 ++------------ src/components/Radio/Radio.style.ts | 13 ++--- src/components/Select/Select.tsx | 2 +- .../__snapshots__/Select.stories.storyshot | 34 +++-------- src/components/Table/Table.style.ts | 4 +- src/components/Table/Table.tsx | 4 +- src/components/TextField/TextField.style.ts | 22 +++---- src/components/TextField/TextField.tsx | 15 ++--- .../__snapshots__/TextField.stories.storyshot | 48 ++------------- src/components/storyUtils/Stack/Stack.tsx | 2 +- src/theme/functions.ts | 18 +++--- 30 files changed, 109 insertions(+), 385 deletions(-) diff --git a/src/components/Breadcrumb/Breadcrumb.tsx b/src/components/Breadcrumb/Breadcrumb.tsx index c53d51ae8..6b4830d4c 100644 --- a/src/components/Breadcrumb/Breadcrumb.tsx +++ b/src/components/Breadcrumb/Breadcrumb.tsx @@ -5,7 +5,6 @@ import isEmpty from 'lodash/isEmpty'; import uniqueId from 'lodash/uniqueId'; import * as React from 'react'; import { Link } from 'react-router-dom'; -import useTheme from '../../hooks/useTheme'; import { breadcrumbLinkStyles, breadcrumbStyles } from './Breadcrumb.style'; import BreadcrumbCollapsed from './BreadcrumbCollapsed/BreadcrumbCollapsed'; import BreadcrumbItem from './BreadcrumbItem/BreadcrumbItem'; @@ -22,9 +21,8 @@ const MAX_ITEMS_TO_SHOW_BEFORE_COLLAPSE = 1; const Breadcrumb: React.FC = props => { const { children, data = [] } = props; - const theme = useTheme(); const passDataToRouterLink = ({ to, label }: BreadcrumbItemData) => ( - + {label} ); @@ -78,7 +76,7 @@ const Breadcrumb: React.FC = props => { ); return ( -
    +
      {dataItems.map(getBreadcrumbItem)}
    ); diff --git a/src/components/Breadcrumb/BreadcrumbCollapsed/BreadcrumbCollapsed.tsx b/src/components/Breadcrumb/BreadcrumbCollapsed/BreadcrumbCollapsed.tsx index 31cd22eef..07af45332 100644 --- a/src/components/Breadcrumb/BreadcrumbCollapsed/BreadcrumbCollapsed.tsx +++ b/src/components/Breadcrumb/BreadcrumbCollapsed/BreadcrumbCollapsed.tsx @@ -2,7 +2,6 @@ import { jsx } from '@emotion/core'; import uniqueId from 'lodash/uniqueId'; import * as React from 'react'; -import useTheme from '../../../hooks/useTheme'; import Separator from '../../Breadcrumb/Separator/Separator'; import Icon from '../../Icon'; import { optionsStyle } from '../../Menu/Menu.style'; @@ -23,19 +22,18 @@ type Props = { const BreadcrumbCollapsed: React.FC = props => { const [open, setOpen] = React.useState(false); const { collapsedItems } = props; - const theme = useTheme(); const expandHandler = () => { setOpen(prevState => !prevState); }; const listItems = collapsedItems.map(item => ( -
  1. +
  2. {item}
  3. )); const collapsedItemsList = ( -
      +
        {listItems}
      ); @@ -50,7 +48,7 @@ const BreadcrumbCollapsed: React.FC = props => { cssStyles={ClickAwayListenerStyle} >
      - + diff --git a/src/components/Breadcrumb/BreadcrumbItem/BreadcrumbItem.tsx b/src/components/Breadcrumb/BreadcrumbItem/BreadcrumbItem.tsx index d19a1ff52..5db06edda 100644 --- a/src/components/Breadcrumb/BreadcrumbItem/BreadcrumbItem.tsx +++ b/src/components/Breadcrumb/BreadcrumbItem/BreadcrumbItem.tsx @@ -3,7 +3,6 @@ import { jsx } from '@emotion/core'; import React from 'react'; import Separator from 'components/Breadcrumb/Separator/Separator'; import { breadcrumbItemStyles } from './BreadcrumbItem.style'; -import useTheme from 'hooks/useTheme'; import BreadcrumbAdvancedItem from './BreadcrumbAdvancedItem'; type Props = { @@ -27,7 +26,6 @@ const BreadcrumbItem: React.FC = props => { onChangeHandler, lastItemLabel, } = props; - const theme = useTheme(); const renderComponentBasedOnOptions = options ? ( = props => { return (
    • -
      +
      {renderComponentBasedOnOptions}
      diff --git a/src/components/Breadcrumb/Separator/Separator.tsx b/src/components/Breadcrumb/Separator/Separator.tsx index 5d1f49c0e..a84fbd100 100644 --- a/src/components/Breadcrumb/Separator/Separator.tsx +++ b/src/components/Breadcrumb/Separator/Separator.tsx @@ -1,7 +1,6 @@ /** @jsx jsx */ import { jsx } from '@emotion/core'; import * as React from 'react'; -import useTheme from '../../../hooks/useTheme'; import Icon from '../../Icon'; import { separatorStyles } from './Separator.style'; @@ -12,11 +11,10 @@ type Props = { const Separator: React.FC = props => { const { isLastItem = false } = props; - const theme = useTheme(); if (isLastItem) return null; return ( - + ); diff --git a/src/components/Breadcrumb/__snapshots__/Breadcrumb.stories.storyshot b/src/components/Breadcrumb/__snapshots__/Breadcrumb.stories.storyshot index 59d0daa67..1c12b03d1 100644 --- a/src/components/Breadcrumb/__snapshots__/Breadcrumb.stories.storyshot +++ b/src/components/Breadcrumb/__snapshots__/Breadcrumb.stories.storyshot @@ -33,13 +33,7 @@ exports[`Storyshots Design System/Breadcrumb Advanced Breadcrumbs with options p
      = props => { onClick, onBlur, } = props; - const theme = useTheme(); return (
      (theme: Theme): SerializedStyles => css` +export const wrapperStyle = ({ disabled }: Props) => (theme: Theme) => css` opacity: ${disabled ? 0.3 : 1}; justify-content: center; align-items: center; @@ -23,9 +23,7 @@ export const checkboxWrapperStyle = () => (theme: Theme) => css` } `; -export const checkboxStyle = ({ intermediate, checked }: Props) => ( - theme: Theme -): SerializedStyles => css` +export const checkboxStyle = ({ intermediate, checked }: Props) => (theme: Theme) => css` background: ${checked ? intermediate ? theme.palette.flat.darkGray[400] @@ -83,7 +81,7 @@ export const checkboxStyle = ({ intermediate, checked }: Props) => ( } `; -export const labelStyle = () => (theme: Theme): SerializedStyles => css` +export const labelStyle = () => (theme: Theme) => css` padding-left: ${rem(4)}; font-size: ${theme.typography.fontSizes['15']}; font-weight: ${theme.typography.weights.regular}; diff --git a/src/components/CheckBox/CheckBox.tsx b/src/components/CheckBox/CheckBox.tsx index 334322146..5062fc41c 100644 --- a/src/components/CheckBox/CheckBox.tsx +++ b/src/components/CheckBox/CheckBox.tsx @@ -2,7 +2,6 @@ import { jsx } from '@emotion/core'; import * as React from 'react'; import { ChangeEvent } from 'react'; -import useTheme from '../../hooks/useTheme'; import { generateUniqueID } from '../../utils/helpers'; import { checkboxStyle, checkboxWrapperStyle, labelStyle, wrapperStyle } from './CheckBox.style'; @@ -27,7 +26,6 @@ const CheckBox: React.FC = ({ intermediate = false, }) => { const [isChecked, setIsChecked] = React.useState(checked); - const theme = useTheme(); const id = generateUniqueID(); const handleInputChange = (event: ChangeEvent) => { @@ -43,10 +41,10 @@ const CheckBox: React.FC = ({ }; return ( - - + + = ({ /> - {label && {label}} + {label && {label}} ); }; diff --git a/src/components/CheckBox/__snapshots__/CheckBox.stories.storyshot b/src/components/CheckBox/__snapshots__/CheckBox.stories.storyshot index 2b68b8d51..04e5f461f 100644 --- a/src/components/CheckBox/__snapshots__/CheckBox.stories.storyshot +++ b/src/components/CheckBox/__snapshots__/CheckBox.stories.storyshot @@ -33,13 +33,7 @@ exports[`Storyshots Design System/CheckBox CheckBox with Label 1`] = `
      ( - theme: Theme -): SerializedStyles => css` +export const optionStyle = ({ selected }: { selected?: boolean }) => (theme: Theme) => css` white-space: nowrap; padding: ${theme.spacing.md}; font-weight: ${selected ? 'bold' : 'initial'}; @@ -14,7 +12,7 @@ export const optionStyle = ({ selected }: { selected?: boolean }) => ( export const datePickerStyles = ({ isRangePicker }: { isRangePicker?: boolean }) => ( theme: Theme -): SerializedStyles => css` +) => css` .DayPickerInput-Overlay { box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05); border: 1px solid #dfdfdf; diff --git a/src/components/DatePicker/DatePicker.tsx b/src/components/DatePicker/DatePicker.tsx index d701fb6a8..814e5e514 100644 --- a/src/components/DatePicker/DatePicker.tsx +++ b/src/components/DatePicker/DatePicker.tsx @@ -2,7 +2,6 @@ import { jsx } from '@emotion/core'; import React, { useState, useCallback, useRef, useEffect } from 'react'; import { datePickerStyles } from './DatePicker.style'; -import useTheme from 'hooks/useTheme'; import DayPickerInput from 'react-day-picker/DayPickerInput'; import 'react-day-picker/lib/style.css'; import dayjs from 'dayjs'; @@ -75,7 +74,6 @@ const DatePicker: React.FC = ({ }, inputLabel = 'Date', }) => { - const theme = useTheme(); const dayPickerInputRef = useRef(null); const dayPickerRef = useRef(null); const daysInitialState = { from: undefined, to: undefined }; @@ -165,7 +163,7 @@ const DatePicker: React.FC = ({ }; return ( -
      +
      { diff --git a/src/components/DatePicker/OverlayComponent/OverlayComponent.tsx b/src/components/DatePicker/OverlayComponent/OverlayComponent.tsx index adb4a7777..34ae6e96c 100644 --- a/src/components/DatePicker/OverlayComponent/OverlayComponent.tsx +++ b/src/components/DatePicker/OverlayComponent/OverlayComponent.tsx @@ -42,7 +42,7 @@ const OverlayComponent: React.FC = ({ {extraOptions.map(option => (
      setSelectedOption(option.value)} > {option.label} diff --git a/src/components/Icon/Icon.tsx b/src/components/Icon/Icon.tsx index c25d9b1fd..70384f83f 100644 --- a/src/components/Icon/Icon.tsx +++ b/src/components/Icon/Icon.tsx @@ -1,7 +1,6 @@ /** @jsx jsx */ import { jsx } from '@emotion/core'; import * as React from 'react'; -import useTheme from '../../hooks/useTheme'; import { AcceptedColorComponentTypes } from '../../utils/themeFunctions'; import iconSelector from './assets/iconSelector'; import { iconContainerStyle, iconStyle } from './Icon.style'; @@ -17,13 +16,11 @@ export type Props = { }; const Icon: React.FC = ({ name, color = 'primary', size = 16 }) => { - const theme = useTheme(); - const Icon = iconSelector[name]; return ( - + ); }; diff --git a/src/components/Icon/__snapshots__/Icon.stories.storyshot b/src/components/Icon/__snapshots__/Icon.stories.storyshot index cb0fbee8b..21cc5bdbc 100644 --- a/src/components/Icon/__snapshots__/Icon.stories.storyshot +++ b/src/components/Icon/__snapshots__/Icon.stories.storyshot @@ -33,13 +33,7 @@ exports[`Storyshots Design System/Icon Icon with color 1`] = `
      ( theme: Theme -): SerializedStyles => css` +) => css` transition: transform 0.25s, opacity 0.25s ease-in-out; transform-origin: 0 0; width: 100%; diff --git a/src/components/Label/Label.tsx b/src/components/Label/Label.tsx index 3f102731b..c8d526400 100644 --- a/src/components/Label/Label.tsx +++ b/src/components/Label/Label.tsx @@ -1,7 +1,6 @@ /** @jsx jsx */ import { jsx } from '@emotion/core'; import * as React from 'react'; -import useTheme from '../../hooks/useTheme'; import { labelStyle } from './Label.style'; export type Props = { @@ -23,10 +22,8 @@ const Label: React.FC = ({ required = false, animateToTop = false, }) => { - const theme = useTheme(); - return ( -