Skip to content

Commit

Permalink
fix: cyclic imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitskvmdam committed Oct 29, 2021
1 parent e4627ca commit 91255ab
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 124 deletions.
5 changes: 3 additions & 2 deletions src/alert/alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
ThemeCSSStyles,
useTheme,
themeTernaryOperator as tto,
createStyle
createStyle,
getColorForComponent
} from '../styles'
import {
DefaultSuccessIcon,
Expand All @@ -19,7 +20,7 @@ import {
DefaultCloseIcon
} from '../constants/default-icons'

import { attachSignatureToComponent, getColorForComponent } from '../utils'
import { attachSignatureToComponent } from '../utils'
import { ALERT } from '../constants/component-ids'
import { IconButton, IconButtonCommonProps } from '../icon-button'
import { Typography } from '../typography'
Expand Down
8 changes: 3 additions & 5 deletions src/card-content/card-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import cx from 'clsx'
import {
createStyledComponent,
getThemeCSSObject,
ThemeCSSStyles
} from '../styles'
import {
attachSignatureToComponent,
ThemeCSSStyles,
getNeutralBasicColorForComponent
} from '../utils'
} from '../styles'
import { attachSignatureToComponent } from '../utils'
import { CARD_CONTENT } from '../constants/component-ids'

export interface CardContentProps
Expand Down
8 changes: 3 additions & 5 deletions src/card/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import {
createStyledComponent,
getThemeCSSObject,
ThemeCSSStyles,
themeTernaryOperator as tto
} from '../styles'
import {
attachSignatureToComponent,
themeTernaryOperator as tto,
getNeutralBasicColorForComponent
} from '../utils'
} from '../styles'
import { attachSignatureToComponent } from '../utils'
import { CARD } from '../constants/component-ids'

import { CSSObject } from 'styled-components'
Expand Down
5 changes: 3 additions & 2 deletions src/divider/divider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import cx from 'clsx'
import {
createStyledComponent,
getThemeCSSObject,
ThemeCSSStyles
ThemeCSSStyles,
getColorForComponent
} from '../styles'
import { attachSignatureToComponent, getColorForComponent } from '../utils'
import { attachSignatureToComponent } from '../utils'
import { DIVIDER } from '../constants/component-ids'

export interface DividerBaseProps
Expand Down
5 changes: 3 additions & 2 deletions src/inline-alert/inline-alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import {
createStyledComponent,
getThemeCSSObject,
themeTernaryOperator as tto,
Theme
Theme,
getColorForComponent
} from '../styles'

import { Alert, AlertProps } from '../alert'
import { Collapsible, CollapsibleProps } from '../collapsible'

import { attachSignatureToComponent, getColorForComponent } from '../utils'
import { attachSignatureToComponent } from '../utils'
import { INLINE_ALERT } from '../constants/component-ids'
import { getHoverProperties } from '../button-base/utils'

Expand Down
5 changes: 3 additions & 2 deletions src/input-base/input-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import {
themeTernaryOperator as tto,
createStyledComponent,
ThemeCSSStyles,
getThemeCSSObject
getThemeCSSObject,
getColorForComponent
} from '../styles'
import { attachSignatureToComponent, getColorForComponent } from '../utils'
import { attachSignatureToComponent } from '../utils'
import { INPUT_BASE } from '../constants/component-ids'

export interface InputBaseProps
Expand Down
5 changes: 3 additions & 2 deletions src/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import {
isValidColorHex,
ReactElement,
ThemeCSSStyles,
themeTernaryOperator as tto
themeTernaryOperator as tto,
getColorForComponent
} from '../styles'
import { attachSignatureToComponent, getColorForComponent } from '../utils'
import { attachSignatureToComponent } from '../utils'
import { INPUT } from '../constants/component-ids'

export type InputProps = InputBaseProps & {
Expand Down
5 changes: 3 additions & 2 deletions src/label/label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import cx from 'clsx'
import {
createStyledComponent,
getThemeCSSObject,
ThemeCSSStyles
ThemeCSSStyles,
getColorForComponent
} from '../styles'
import { attachSignatureToComponent, getColorForComponent } from '../utils'
import { attachSignatureToComponent } from '../utils'
import { LABEL } from '../constants/component-ids'

export interface LabelProps
Expand Down
8 changes: 3 additions & 5 deletions src/list-heading/list-heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import cx from 'clsx'
import {
createStyledComponent,
getThemeCSSObject,
ThemeCSSStyles
} from '../styles'
import {
attachSignatureToComponent,
ThemeCSSStyles,
getNeutralBasicColorForComponent
} from '../utils'
} from '../styles'
import { attachSignatureToComponent } from '../utils'
import { LIST_HEADING } from '../constants/component-ids'

export interface ListHeadingProps
Expand Down
8 changes: 3 additions & 5 deletions src/list-item/list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import cx from 'clsx'
import {
createStyledComponent,
getThemeCSSObject,
ThemeCSSStyles
} from '../styles'
import {
attachSignatureToComponent,
ThemeCSSStyles,
getNeutralBasicColorForComponent
} from '../utils'
} from '../styles'
import { attachSignatureToComponent } from '../utils'
import { LIST_ITEM } from '../constants/component-ids'
import { CSSObject } from 'styled-components'

Expand Down
5 changes: 3 additions & 2 deletions src/loading/spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import {
createStyledComponent,
createStyle,
ThemeCSSStyles,
getThemeCSSObject
getThemeCSSObject,
getColorForComponent
} from '../styles'
import { attachSignatureToComponent, getColorForComponent } from '../utils'
import { attachSignatureToComponent } from '../utils'
import { SPINNER } from '../constants/component-ids'

export interface SpinnerProps
Expand Down
5 changes: 3 additions & 2 deletions src/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {
getThemeCSSObject,
createStyle,
hex2rgba,
themeTernaryOperator as tto
themeTernaryOperator as tto,
getColorForComponent
} from '../styles'
import { attachSignatureToComponent, getColorForComponent } from '../utils'
import { attachSignatureToComponent } from '../utils'
import { MODAL } from '../constants/component-ids'

export interface ModalProps extends Omit<ReactModalProps, 'as'> {
Expand Down
4 changes: 3 additions & 1 deletion src/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import ReactSelect, {
} from 'react-select'
import cx from 'clsx'
import type { StylesProps } from 'react-select/dist/declarations/src/styles'
import { attachSignatureToComponent, getColorForComponent } from '../utils'

import { getColorForComponent } from '../styles'
import { attachSignatureToComponent } from '../utils'
import { SELECT } from '../constants/component-ids'

import {
Expand Down
8 changes: 3 additions & 5 deletions src/stepper/stepper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import {
ReactElement,
ThemeCSSStyles,
ThemePalette,
themeTernaryOperator as tto
themeTernaryOperator as tto,
getNeutralBasicColorForComponent
} from '../styles'
import DefaultWarningIcon from '../icons/System/alert-line'
import DefaultCompleteIcon from '../icons/System/check-fill'
import DefaultErrorIcon from '../icons/System/close-fill'
import {
attachSignatureToComponent,
getNeutralBasicColorForComponent
} from '../utils'
import { attachSignatureToComponent } from '../utils'
import { STEPPER } from '../constants/component-ids'

import { Box } from '../box'
Expand Down
3 changes: 2 additions & 1 deletion src/styles/theme/create/palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
darkGrey as darkGreyColor,
grey as greyColor,
orange,
themeTernaryOperator as tto,
hex2rgba,
createColor,
getContrastRatio,
Expand All @@ -24,6 +23,8 @@ import type {
ThemePaletteColor,
} from './create'

import { themeTernaryOperator as tto } from '../utils'

type CreateIndividualPaletteOptions = {
contrastThreshold: number
themeType: ThemeType
Expand Down
8 changes: 3 additions & 5 deletions src/table-cell/table-cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import {
createStyledComponent,
ThemeCSSStyles,
getThemeCSSObject,
themeTernaryOperator as tto
} from '../styles'
import {
attachSignatureToComponent,
themeTernaryOperator as tto,
getNeutralBasicColorForComponent
} from '../utils'
} from '../styles'
import { attachSignatureToComponent } from '../utils'
import { TABLE_CELL } from '../constants/component-ids'

import TableContext from '../table/table-context'
Expand Down
5 changes: 3 additions & 2 deletions src/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import cx from 'clsx'
import {
createStyledComponent,
ThemeCSSStyles,
getThemeCSSObject
getThemeCSSObject,
getColorForComponent
} from '../styles'
import { attachSignatureToComponent, getColorForComponent } from '../utils'
import { attachSignatureToComponent } from '../utils'
import { TABLE } from '../constants/component-ids'

import TableContext from './table-context'
Expand Down
4 changes: 2 additions & 2 deletions src/tooltip/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {
isValidColorHex,
ReactElement,
ThemeCSSStyles,
themeTernaryOperator as tto
themeTernaryOperator as tto,
getColorForComponent
} from '../styles'
import {
attachSignatureToComponent,
getColorForComponent,
setRef,
useForkRef,
useMouseOver
Expand Down
5 changes: 3 additions & 2 deletions src/typography/typography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {
isThemeFontVariant,
ThemeTypographyVariant,
ThemeCSSStyles,
getThemeCSSObject
getThemeCSSObject,
getColorForComponent
} from '../styles'
import { attachSignatureToComponent, getColorForComponent } from '../utils'
import { attachSignatureToComponent } from '../utils'
import { TYPOGRAPHY } from '../constants/component-ids'

export interface TypographyBaseProps
Expand Down
70 changes: 0 additions & 70 deletions src/utils/get.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import { nanoid } from 'nanoid'
import {
BasicColor,
getColorNameAndKey,
getThemeColorUsingKey,
Theme,
themeTernaryOperator as tto,
} from '../styles'

import { isChromatinElement } from './validate'

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
Expand All @@ -33,65 +25,3 @@ export const getElementUsingEvent = (event: Event): EventTarget => {

return event.target ?? document.body
}

export const getColorForComponent = (options: {
theme: Theme
color?: string
key?: string
isReturnDefaultColor?: boolean
isSwitchDefaultColor?: boolean
defaultKey?: {
grey?: keyof BasicColor
darkGrey?: keyof BasicColor
}
}): string | undefined => {
const {
key,
theme,
color,
isReturnDefaultColor = true,
isSwitchDefaultColor = false,
defaultKey = {},
} = options

if (!color) {
if (!isReturnDefaultColor) return

const {
themeType,
palette: { darkGrey, grey },
} = theme

const { grey: _gK = 10, darkGrey: _dgK = 10 } = defaultKey

if (isSwitchDefaultColor) {
return tto(themeType, grey[_gK], darkGrey[_dgK])
}
return tto(themeType, darkGrey[_dgK], grey[_dgK])
}

const colorTuple = getColorNameAndKey(color, { theme, defaultKey: key })

if (colorTuple) {
return getThemeColorUsingKey(colorTuple, theme)
}

return color
}

export const getNeutralBasicColorForComponent = (options: {
theme: Theme
isOpposite?: boolean
}): BasicColor => {
const { theme, isOpposite = false } = options
const {
themeType,
palette: { darkGrey, grey },
} = theme

if (isOpposite) {
return tto(themeType, darkGrey, grey)
}

return tto(themeType, grey, darkGrey)
}

0 comments on commit 91255ab

Please sign in to comment.