Skip to content

Commit

Permalink
feat(Components): added theme
Browse files Browse the repository at this point in the history
  • Loading branch information
gizeasy committed Apr 28, 2021
1 parent 105ae5a commit 420b47d
Show file tree
Hide file tree
Showing 32 changed files with 2,139 additions and 147 deletions.
4 changes: 3 additions & 1 deletion src/Area/Area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Area as G2plotArea, AreaOptions as G2plotAreaProps } from '@antv/g2plot
import { useForkRef } from '@consta/uikit/useForkRef'

import { useChart } from '@/__private__/hooks/useChart'
import { useChartTheme } from '@/__private__/hooks/useChartTheme'
import { getChart } from '@/__private__/utils/getChart'
import { ChartProps } from '@/__private__/utils/types/ChartProps'

Expand All @@ -20,7 +21,8 @@ export const Area: Area = React.forwardRef((props, ref) => {
className,
...rest
} = props
const { chart, container } = useChart(G2plotArea, rest)
const theme = useChartTheme()
const { chart, container } = useChart(G2plotArea, { ...rest, theme })

useEffect(() => {
getChart(chartRef, chart.current)
Expand Down
1 change: 1 addition & 0 deletions src/Area/__stories__/Column.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const Default = () => {
width: 800,
height: '100%',
}}
renderer="svg"
{...options}
/>
)
Expand Down
4 changes: 3 additions & 1 deletion src/Bar/Bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Bar as G2plotBar, BarOptions as G2plotBarProps } from '@antv/g2plot'
import { useForkRef } from '@consta/uikit/useForkRef'

import { useChart } from '@/__private__/hooks/useChart'
import { useChartTheme } from '@/__private__/hooks/useChartTheme'
import { getChart } from '@/__private__/utils/getChart'
import { ChartProps } from '@/__private__/utils/types/ChartProps'

Expand All @@ -20,7 +21,8 @@ export const Bar: Bar = React.forwardRef((props, ref) => {
className,
...rest
} = props
const { chart, container } = useChart(G2plotBar, rest)
const theme = useChartTheme()
const { chart, container } = useChart(G2plotBar, { ...rest, theme })

useEffect(() => {
getChart(chartRef, chart.current)
Expand Down
1 change: 1 addition & 0 deletions src/Bar/__stories__/Bar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const Default = () => {
width: 800,
height: '100%',
}}
renderer="svg"
{...options}
/>
)
Expand Down
4 changes: 3 additions & 1 deletion src/Bullet/Bullet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Bullet as G2plotBullet, BulletOptions as G2plotBulletProps } from '@ant
import { useForkRef } from '@consta/uikit/useForkRef'

import { useChart } from '@/__private__/hooks/useChart'
import { useChartTheme } from '@/__private__/hooks/useChartTheme'
import { getChart } from '@/__private__/utils/getChart'
import { ChartProps } from '@/__private__/utils/types/ChartProps'

Expand All @@ -21,7 +22,8 @@ export const Bullet: Bullet = React.forwardRef((props, ref) => {
...rest
} = props

const { chart, container } = useChart(G2plotBullet, rest)
const theme = useChartTheme()
const { chart, container } = useChart(G2plotBullet, { ...rest, theme })

useEffect(() => {
getChart(chartRef, chart.current)
Expand Down
1 change: 1 addition & 0 deletions src/Bullet/__stories__/Bullet.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const Default = () => {
width: 800,
height: '100%',
}}
renderer="svg"
{...options}
/>
)
Expand Down
4 changes: 3 additions & 1 deletion src/Column/Column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Column as G2plotColumn, ColumnOptions as G2plotColumnProps } from '@ant
import { useForkRef } from '@consta/uikit/useForkRef'

import { useChart } from '@/__private__/hooks/useChart'
import { useChartTheme } from '@/__private__/hooks/useChartTheme'
import { getChart } from '@/__private__/utils/getChart'
import { ChartProps } from '@/__private__/utils/types/ChartProps'

Expand All @@ -20,7 +21,8 @@ export const Column: Column = React.forwardRef((props, ref) => {
className,
...rest
} = props
const { chart, container } = useChart(G2plotColumn, rest)
const theme = useChartTheme()
const { chart, container } = useChart(G2plotColumn, { ...rest, theme })

useEffect(() => {
getChart(chartRef, chart.current)
Expand Down
1 change: 1 addition & 0 deletions src/Column/__stories__/Column.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const Default = () => {
width: 800,
height: '100%',
}}
renderer="svg"
{...options}
/>
)
Expand Down
4 changes: 3 additions & 1 deletion src/Gauge/Gauge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Gauge as G2plotGauge, GaugeOptions as G2plotGaugeProps } from '@antv/g2
import { useForkRef } from '@consta/uikit/useForkRef'

import { useChart } from '@/__private__/hooks/useChart'
import { useChartTheme } from '@/__private__/hooks/useChartTheme'
import { getChart } from '@/__private__/utils/getChart'
import { ChartProps } from '@/__private__/utils/types/ChartProps'

Expand All @@ -21,7 +22,8 @@ export const Gauge: Gauge = React.forwardRef((props, ref) => {
...rest
} = props

const { chart, container } = useChart(G2plotGauge, rest)
const theme = useChartTheme()
const { chart, container } = useChart(G2plotGauge, { ...rest, theme })

useEffect(() => {
getChart(chartRef, chart.current)
Expand Down
5 changes: 3 additions & 2 deletions src/Gauge/__stories__/Gauge.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const Default = () => {
const options: GaugeProps = {
percent: 0.7,
range: {
ticks: [0, 1 / 3, 2 / 3, 1],
color: ['#F4664A', '#FAAD14', '#30BF78'],
// ticks: [0, 1 / 3, 2 / 3, 1],
// color: ['#F4664A', '#FAAD14', '#30BF78'],
},
indicator: {
pointer: {
Expand Down Expand Up @@ -40,6 +40,7 @@ const Default = () => {
width: 300,
height: '100%',
}}
renderer="svg"
{...options}
/>
)
Expand Down
4 changes: 3 additions & 1 deletion src/Histogram/Histogram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { useForkRef } from '@consta/uikit/useForkRef'

import { useChart } from '@/__private__/hooks/useChart'
import { useChartTheme } from '@/__private__/hooks/useChartTheme'
import { getChart } from '@/__private__/utils/getChart'
import { ChartProps } from '@/__private__/utils/types/ChartProps'

Expand All @@ -23,7 +24,8 @@ export const Histogram: Histogram = React.forwardRef((props, ref) => {
className,
...rest
} = props
const { chart, container } = useChart(G2plotHistogram, rest)
const theme = useChartTheme()
const { chart, container } = useChart(G2plotHistogram, { ...rest, theme })

useEffect(() => {
getChart(chartRef, chart.current)
Expand Down
1 change: 1 addition & 0 deletions src/Histogram/__stories__/Histogram.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const Default = () => {
width: 800,
height: '100%',
}}
renderer="svg"
{...options}
/>
)
Expand Down
18 changes: 12 additions & 6 deletions src/Line/Line.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import React, { useEffect, useImperativeHandle } from 'react'

import { Line as G2plotLine, LineOptions as G2plotLineProps } from '@antv/g2plot'
import { Line as G2plotLine } from '@antv/g2plot'
import { useForkRef } from '@consta/uikit/useForkRef'
import { useThemeVars } from '@consta/uikit/useThemeVars'

import { useChart } from '@/__private__/hooks/useChart'
import { getChartTheme } from '@/__private__/hooks/useChartTheme'
import { getChart } from '@/__private__/utils/getChart'
import { ChartProps } from '@/__private__/utils/types/ChartProps'

export type LineProps = ChartProps<G2plotLineProps>
import { withDefaultProps } from './helpers'
import { Line as Component } from './types'

type Line = (props: LineProps) => React.ReactElement | null
export * from './types'

export const Line: Line = React.forwardRef((props, ref) => {
export const Line: Component = React.forwardRef((props, ref) => {
const {
chartRef,
style = {
Expand All @@ -20,7 +22,11 @@ export const Line: Line = React.forwardRef((props, ref) => {
className,
...rest
} = props
const { chart, container } = useChart(G2plotLine, rest)
const themeVars = useThemeVars()
const theme = getChartTheme(themeVars)
const chartProps = withDefaultProps(rest)

const { chart, container } = useChart(G2plotLine, { ...chartProps, theme })

useEffect(() => {
getChart(chartRef, chart.current)
Expand Down
Loading

0 comments on commit 420b47d

Please sign in to comment.