Skip to content

Commit

Permalink
feat(theming): move theming to its own package
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed May 11, 2023
1 parent ce598c0 commit ac06db9
Show file tree
Hide file tree
Showing 102 changed files with 732 additions and 128 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ pkgs-test-cover: ##@1 packages run tests for all packages with code coverage

pkgs-build: pkgs-types ##@1 packages build all packages
@# Using exit code 255 in case of error as it'll make xargs stop immediately.
@export SKIP_TYPES=TRUE;find ./packages -type d -maxdepth 1 ! -path ./packages \
@# Skipping type generation as it's already done via `pkgs-types` in one go.
@export SKIP_TYPES=TRUE; find ./packages -type d -maxdepth 1 ! -path ./packages \
| sed 's|^./packages/||' \
| xargs -P 8 -I '{}' sh -c '$(MAKE) pkg-build-{} || exit 255'

Expand Down
1 change: 1 addition & 0 deletions packages/annotations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"dependencies": {
"@nivo/colors": "workspace:*",
"@nivo/core": "workspace:*",
"@nivo/theming": "workspace:*",
"@react-spring/web": "9.4.5 || ^9.7.2",
"@types/prop-types": "^15.7.2",
"lodash": "^4.17.21",
Expand Down
3 changes: 2 additions & 1 deletion packages/annotations/src/AnnotationLink.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useMemo } from 'react'
import { animated } from '@react-spring/web'
import { useAnimatedPath, useTheme } from '@nivo/core'
import { useAnimatedPath } from '@nivo/core'
import { useTheme } from '@nivo/theming'

export const AnnotationLink = ({
points,
Expand Down
3 changes: 2 additions & 1 deletion packages/annotations/src/AnnotationNote.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { createElement } from 'react'
import omit from 'lodash/omit'
import { useSpring, animated } from '@react-spring/web'
import { useTheme, useMotionConfig } from '@nivo/core'
import { useMotionConfig } from '@nivo/core'
import { useTheme } from '@nivo/theming'
import { NoteSvg } from './types'

export const AnnotationNote = <Datum,>({
Expand Down
3 changes: 2 additions & 1 deletion packages/annotations/src/CircleAnnotationOutline.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useSpring, animated } from '@react-spring/web'
import { useMotionConfig, useTheme } from '@nivo/core'
import { useMotionConfig } from '@nivo/core'
import { useTheme } from '@nivo/theming'

export const CircleAnnotationOutline = ({ x, y, size }: { x: number; y: number; size: number }) => {
const theme = useTheme()
Expand Down
3 changes: 2 additions & 1 deletion packages/annotations/src/DotAnnotationOutline.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useSpring, animated } from '@react-spring/web'
import { useMotionConfig, useTheme } from '@nivo/core'
import { useMotionConfig } from '@nivo/core'
import { useTheme } from '@nivo/theming'
import { defaultProps } from './props'

export const DotAnnotationOutline = ({
Expand Down
3 changes: 2 additions & 1 deletion packages/annotations/src/RectAnnotationOutline.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useSpring, animated } from '@react-spring/web'
import { useMotionConfig, useTheme } from '@nivo/core'
import { useMotionConfig } from '@nivo/core'
import { useTheme } from '@nivo/theming'

export const RectAnnotationOutline = ({
x,
Expand Down
4 changes: 2 additions & 2 deletions packages/annotations/src/canvas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CompleteTheme } from '@nivo/core'
import { Theme } from '@nivo/theming'
import { ComputedAnnotation } from './types'
import { isCanvasNote, isCircleAnnotation, isDotAnnotation, isRectAnnotation } from './utils'

Expand All @@ -19,7 +19,7 @@ export const renderAnnotationsToCanvas = <Datum>(
theme,
}: {
annotations: ComputedAnnotation<Datum>[]
theme: CompleteTheme
theme: Theme
}
) => {
if (annotations.length === 0) return
Expand Down
4 changes: 2 additions & 2 deletions packages/annotations/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CompleteTheme } from '@nivo/core'
import { Theme } from '@nivo/theming'
import { ReactElement } from 'react'

// The types below are from lodash but the babel plugin won't let us import it
Expand Down Expand Up @@ -38,7 +38,7 @@ export type NoteCanvasRenderer<Datum> = (
datum: Datum
x: number
y: number
theme: CompleteTheme
theme: Theme
}
) => void

Expand Down
1 change: 1 addition & 0 deletions packages/arcs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"dependencies": {
"@nivo/colors": "workspace:*",
"@nivo/core": "workspace:*",
"@nivo/theming": "workspace:*",
"@react-spring/web": "9.4.5 || ^9.7.2",
"@types/d3-shape": "^2.0.0",
"d3-shape": "^1.3.5"
Expand Down
2 changes: 1 addition & 1 deletion packages/arcs/src/ArcsLayer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createElement } from 'react'
import { useTheme } from '@nivo/core'
import { useTheme } from '@nivo/theming'
import { InheritedColorConfig, useInheritedColor } from '@nivo/colors'
import { DatumWithArcAndColor, ArcGenerator } from './types'
import { useArcsTransition } from './useArcsTransition'
Expand Down
2 changes: 1 addition & 1 deletion packages/arcs/src/arc_labels/ArcLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CSSProperties } from 'react'
import { SpringValue, Interpolation, animated } from '@react-spring/web'
import { useTheme } from '@nivo/core'
import { useTheme } from '@nivo/theming'
import { DatumWithArcAndColor } from '../types'

const staticStyle: CSSProperties = {
Expand Down
3 changes: 2 additions & 1 deletion packages/arcs/src/arc_labels/ArcLabelsLayer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createElement, useMemo } from 'react'
import { PropertyAccessor, usePropertyAccessor, radiansToDegrees, useTheme } from '@nivo/core'
import { PropertyAccessor, usePropertyAccessor, radiansToDegrees } from '@nivo/core'
import { useTheme } from '@nivo/theming'
import { useInheritedColor } from '@nivo/colors'
import { useArcCentersTransition } from '../centers'
import { ArcTransitionMode } from '../arcTransitionMode'
Expand Down
4 changes: 2 additions & 2 deletions packages/arcs/src/arc_labels/canvas.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CompleteTheme } from '@nivo/core'
import { Theme } from '@nivo/theming'
import { DatumWithArcAndColor } from '../types'
import { ArcLabel } from './useArcLabels'

export const drawCanvasArcLabels = <Datum extends DatumWithArcAndColor>(
ctx: CanvasRenderingContext2D,
labels: ArcLabel<Datum>[],
theme: CompleteTheme
theme: Theme
) => {
ctx.textAlign = 'center'
ctx.textBaseline = 'middle'
Expand Down
3 changes: 2 additions & 1 deletion packages/arcs/src/arc_labels/useArcLabels.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback } from 'react'
import { PropertyAccessor, usePropertyAccessor, useTheme } from '@nivo/core'
import { PropertyAccessor, usePropertyAccessor } from '@nivo/core'
import { useTheme } from '@nivo/theming'
import { InheritedColorConfig, useInheritedColor } from '@nivo/colors'
import { DatumWithArcAndColor } from '../types'
import { useArcCenters, ArcCenter } from '../centers'
Expand Down
2 changes: 1 addition & 1 deletion packages/arcs/src/arc_link_labels/ArcLinkLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useTheme } from '@nivo/core'
import { useTheme } from '@nivo/theming'
import { SpringValue, Interpolation, animated } from '@react-spring/web'
import { DatumWithArcAndColor } from '../types'

Expand Down
10 changes: 4 additions & 6 deletions packages/arcs/src/arc_link_labels/canvas.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import {
// @ts-ignore
textPropsByEngine,
CompleteTheme,
} from '@nivo/core'
// @ts-ignore
import { textPropsByEngine } from '@nivo/core'
import { Theme } from '@nivo/theming'
import { DatumWithArcAndColor } from '../types'
import { ArcLinkLabel } from './types'

export const drawCanvasArcLinkLabels = <Datum extends DatumWithArcAndColor>(
ctx: CanvasRenderingContext2D,
labels: ArcLinkLabel<Datum>[],
theme: CompleteTheme,
theme: Theme,
strokeWidth: number
) => {
ctx.textBaseline = 'middle'
Expand Down
3 changes: 2 additions & 1 deletion packages/arcs/src/arc_link_labels/useArcLinkLabels.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback } from 'react'
import { PropertyAccessor, usePropertyAccessor, useTheme } from '@nivo/core'
import { PropertyAccessor, usePropertyAccessor } from '@nivo/core'
import { useTheme } from '@nivo/theming'
import { InheritedColorConfig, useInheritedColor } from '@nivo/colors'
import { DatumWithArcAndColor } from '../types'
import { ArcLinkWithDatum, ArcLinkLabel } from './types'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useMemo } from 'react'
import { SpringValue, useTransition, to } from '@react-spring/web'
import { line } from 'd3-shape'
import { useMotionConfig, useTheme } from '@nivo/core'
import { useMotionConfig } from '@nivo/core'
import { useTheme } from '@nivo/theming'
import { InheritedColorConfig, useInheritedColor } from '@nivo/colors'
import { DatumWithArcAndColor, Point } from '../types'
import { useFilteredDataBySkipAngle } from '../utils'
Expand Down
1 change: 1 addition & 0 deletions packages/axes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"dependencies": {
"@nivo/core": "workspace:*",
"@nivo/scales": "workspace:*",
"@nivo/theming": "workspace:*",
"@react-spring/web": "9.4.5 || ^9.7.2",
"@types/d3-format": "^1.4.1",
"@types/d3-time-format": "^2.3.1",
Expand Down
7 changes: 4 additions & 3 deletions packages/axes/src/canvas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { degreesToRadians, CompleteTheme } from '@nivo/core'
import { degreesToRadians } from '@nivo/core'
import { Theme } from '@nivo/theming'
import { ScaleValue, AnyScale, TicksSpec } from '@nivo/scales'
import { computeCartesianTicks, getFormatter, computeGridLines } from './compute'
import { positions } from './props'
Expand Down Expand Up @@ -40,7 +41,7 @@ export const renderAxisToCanvas = <Value extends ScaleValue>(
legend?: string
legendPosition?: AxisLegendPosition
legendOffset?: number
theme: CompleteTheme
theme: Theme
}
) => {
const { ticks, textAlign, textBaseline } = computeCartesianTicks({
Expand Down Expand Up @@ -189,7 +190,7 @@ export const renderAxesToCanvas = <X extends ScaleValue, Y extends ScaleValue>(
right?: CanvasAxisProps<Y> | null
bottom?: CanvasAxisProps<X> | null
left?: CanvasAxisProps<Y> | null
theme: CompleteTheme
theme: Theme
}
) => {
const axes = { top, right, bottom, left }
Expand Down
3 changes: 2 additions & 1 deletion packages/axes/src/components/Axis.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useMemo, memo, useCallback } from 'react'
import * as React from 'react'
import { useSpring, useTransition, animated } from '@react-spring/web'
import { useTheme, useMotionConfig } from '@nivo/core'
import { useMotionConfig } from '@nivo/core'
import { useTheme } from '@nivo/theming'
import { ScaleValue, AnyScale } from '@nivo/scales'
import { computeCartesianTicks, getFormatter } from '../compute'
import { AxisTick } from './AxisTick'
Expand Down
2 changes: 1 addition & 1 deletion packages/axes/src/components/AxisTick.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMemo, memo } from 'react'
import * as React from 'react'
import { animated } from '@react-spring/web'
import { useTheme } from '@nivo/core'
import { useTheme } from '@nivo/theming'
import { ScaleValue } from '@nivo/scales'
import { AxisTickProps } from '../types'

Expand Down
2 changes: 1 addition & 1 deletion packages/axes/src/components/GridLine.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { memo, SVGAttributes } from 'react'
import { SpringValues, animated } from '@react-spring/web'
import { useTheme } from '@nivo/core'
import { useTheme } from '@nivo/theming'

export const GridLine = memo(
({
Expand Down
1 change: 1 addition & 0 deletions packages/bar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@nivo/core": "workspace:*",
"@nivo/legends": "workspace:*",
"@nivo/scales": "workspace:*",
"@nivo/theming": "workspace:*",
"@nivo/tooltip": "workspace:*",
"@react-spring/web": "9.4.5 || ^9.7.2",
"@types/d3-scale": "^3.2.3",
Expand Down
10 changes: 2 additions & 8 deletions packages/bar/src/BarCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ import {
BarDatum,
ComputedBarDatum,
} from './types'
import {
Container,
Margin,
getRelativeCursor,
isCursorInRect,
useDimensions,
useTheme,
} from '@nivo/core'
import { Container, Margin, getRelativeCursor, isCursorInRect, useDimensions } from '@nivo/core'
import { useTheme } from '@nivo/theming'
import {
ForwardedRef,
createElement,
Expand Down
2 changes: 1 addition & 1 deletion packages/bar/src/BarItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createElement, MouseEvent, useCallback, useMemo } from 'react'
import { animated, to } from '@react-spring/web'
import { useTheme } from '@nivo/core'
import { useTheme } from '@nivo/theming'
import { useTooltip } from '@nivo/tooltip'
import { BarDatum, BarItemProps } from './types'

Expand Down
3 changes: 2 additions & 1 deletion packages/bar/src/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useMemo, useState } from 'react'
import { useInheritedColor, useOrdinalColorScale } from '@nivo/colors'
import { usePropertyAccessor, useTheme, useValueFormatter, Margin } from '@nivo/core'
import { usePropertyAccessor, useValueFormatter, Margin } from '@nivo/core'
import { useTheme } from '@nivo/theming'
import {
DataProps,
BarCommonProps,
Expand Down
4 changes: 2 additions & 2 deletions packages/bar/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
MotionProps,
PropertyAccessor,
SvgDefsAndFill,
Theme,
ValueFormat,
} from '@nivo/core'
import { PartialTheme } from '@nivo/theming'
import { InheritedColorConfig, OrdinalColorScaleConfig } from '@nivo/colors'
import { LegendProps } from '@nivo/legends'
import { AnyScale, ScaleSpec, ScaleBandSpec } from '@nivo/scales'
Expand Down Expand Up @@ -251,7 +251,7 @@ export type BarCommonProps<RawDatum> = {

colorBy: 'id' | 'indexValue'
colors: OrdinalColorScaleConfig<ComputedDatum<RawDatum>>
theme: Theme
theme: PartialTheme

annotations: AnnotationMatcher<ComputedBarDatum<RawDatum>>[]
legends: BarLegendProps[]
Expand Down
1 change: 1 addition & 0 deletions packages/boxplot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@nivo/core": "workspace:*",
"@nivo/legends": "workspace:*",
"@nivo/scales": "workspace:*",
"@nivo/theming": "workspace:*",
"@nivo/tooltip": "workspace:*",
"@react-spring/web": "9.4.5 || ^9.7.2",
"@types/d3-scale": "^3.2.3",
Expand Down
6 changes: 3 additions & 3 deletions packages/boxplot/src/BoxPlotTooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BoxPlotSummaryFormatted, BoxPlotTooltipProps, BoxPlotSummary } from './types'
import { Chip } from '@nivo/tooltip'
import { memo } from 'react'
import { useTheme, CompleteTheme } from '@nivo/core'
import { useTheme, Theme } from '@nivo/theming'

interface BoxPlotSummaryTooltipProps {
label: string
Expand All @@ -23,11 +23,11 @@ export const defaultTranslation = {
Quantiles: 'Quantiles',
}

type ExtendedTheme = CompleteTheme & {
type ExtendedTheme = Theme & {
translation: Translation
}

const hasTranslation = (theme: CompleteTheme | ExtendedTheme): theme is ExtendedTheme => {
const hasTranslation = (theme: Theme | ExtendedTheme): theme is ExtendedTheme => {
return 'translation' in theme
}

Expand Down
3 changes: 2 additions & 1 deletion packages/boxplot/src/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useMemo, useState } from 'react'
import { SpringConfig, useTransition } from '@react-spring/web'
import { useInheritedColor, useOrdinalColorScale } from '@nivo/colors'
import { PropertyAccessor, usePropertyAccessor, useTheme, useValueFormatter } from '@nivo/core'
import { PropertyAccessor, usePropertyAccessor, useValueFormatter } from '@nivo/core'
import { useTheme } from '@nivo/theming'
import {
BoxPlotCommonProps,
BoxPlotDatum,
Expand Down
4 changes: 2 additions & 2 deletions packages/boxplot/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
MotionProps,
PropertyAccessor,
SvgDefsAndFill,
Theme,
ValueFormat,
} from '@nivo/core'
import { PartialTheme } from '@nivo/theming'
import { InheritedColorConfig, OrdinalColorScaleConfig } from '@nivo/colors'
import { LegendProps } from '@nivo/legends'
import {
Expand Down Expand Up @@ -231,7 +231,7 @@ export type BoxPlotCommonProps<RawDatum> = {

colorBy: 'group' | 'subGroup'
colors: OrdinalColorScaleConfig<BoxPlotSummary>
theme: Theme & { translation: BoxPlotDatum }
theme: PartialTheme & { translation: BoxPlotDatum }

annotations: AnnotationMatcher<ComputedBoxPlotSummary>[]
legends: LegendProps[]
Expand Down
1 change: 1 addition & 0 deletions packages/bullet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@nivo/core": "workspace:*",
"@nivo/legends": "workspace:*",
"@nivo/scales": "workspace:*",
"@nivo/theming": "workspace:*",
"@nivo/tooltip": "workspace:*",
"@react-spring/web": "9.4.5 || ^9.7.2"
},
Expand Down
8 changes: 6 additions & 2 deletions packages/bullet/src/BulletItem.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { useMemo } from 'react'
import { useSpring, animated } from '@react-spring/web'
import { Axis } from '@nivo/axes'
// @ts-ignore
import { getColorScale, useMotionConfig, useTheme } from '@nivo/core'
import {
// @ts-ignore
getColorScale,
useMotionConfig,
} from '@nivo/core'
import { useTheme } from '@nivo/theming'
import { useTooltip } from '@nivo/tooltip'
import { stackValues } from './compute'
import { BulletMarkers } from './BulletMarkers'
Expand Down
Loading

0 comments on commit ac06db9

Please sign in to comment.