From 4bd566c8485725260f39b1e06f3424a7416f20ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Benitte?= Date: Fri, 12 Jul 2019 08:50:26 +0900 Subject: [PATCH] fix(axes): treat renderTick as a React component --- packages/axes/src/components/Axis.js | 4 +- packages/bar/stories/bar.stories.js | 60 ++++++++++++---------------- 2 files changed, 28 insertions(+), 36 deletions(-) diff --git a/packages/axes/src/components/Axis.js b/packages/axes/src/components/Axis.js index 7a986060f..6cb01b0a5 100644 --- a/packages/axes/src/components/Axis.js +++ b/packages/axes/src/components/Axis.js @@ -113,7 +113,7 @@ const Axis = ({ return ( {ticks.map((tick, tickIndex) => - renderTick({ + React.createElement(renderTick, { tickIndex, format: formatValue, rotate: tickRotation, @@ -156,7 +156,7 @@ const Axis = ({ {interpolatedStyles => ( {interpolatedStyles.map(({ style, data: tick }, tickIndex) => - renderTick({ + React.createElement(renderTick, { tickIndex, format: formatValue, textBaseline, diff --git a/packages/bar/stories/bar.stories.js b/packages/bar/stories/bar.stories.js index 8d3525fff..3c1ecabbe 100644 --- a/packages/bar/stories/bar.stories.js +++ b/packages/bar/stories/bar.stories.js @@ -4,6 +4,7 @@ import { action } from '@storybook/addon-actions' import { generateCountriesData, sets } from '@nivo/generators' import range from 'lodash/range' import random from 'lodash/random' +import { useTheme } from '@nivo/core' import { Bar } from '../src' const keys = ['hot dogs', 'burgers', 'sandwich', 'kebab', 'fries', 'donut'] @@ -201,47 +202,38 @@ stories.add('custom tooltip', () => ( /> )) +const CustomTick = tick => { + const theme = useTheme() + + return ( + + + + + + {tick.value} + + + ) +} + stories.add( 'custom axis ticks', () => ( ( - - - - - - {tick.value} - - - ), + renderTick: CustomTick, }} /> ),