Skip to content

Commit

Permalink
feat(bar): use @nivo/colors for inherited colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte authored and Raphaël Benitte committed Apr 17, 2019
1 parent 1347fd8 commit c7cf5ce
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 31 deletions.
15 changes: 7 additions & 8 deletions packages/bar/src/enhance.js
Expand Up @@ -14,11 +14,10 @@ import {
withTheme,
withDimensions,
withMotion,
getInheritedColorGenerator,
getAccessorFor,
getLabelGenerator,
} from '@nivo/core'
import { getOrdinalColorScale } from '@nivo/colors'
import { getOrdinalColorScale, getInheritedColorGenerator } from '@nivo/colors'
import { BarDefaultProps } from './props'

export default Component =>
Expand All @@ -33,17 +32,17 @@ export default Component =>
withPropsOnChange(['indexBy'], ({ indexBy }) => ({
getIndex: getAccessorFor(indexBy),
})),
withPropsOnChange(['labelTextColor'], ({ labelTextColor }) => ({
getLabelTextColor: getInheritedColorGenerator(labelTextColor, 'axis.ticks.text.fill'),
withPropsOnChange(['labelTextColor', 'theme'], ({ labelTextColor, theme }) => ({
getLabelTextColor: getInheritedColorGenerator(labelTextColor, theme),
})),
withPropsOnChange(['labelLinkColor'], ({ labelLinkColor }) => ({
getLabelLinkColor: getInheritedColorGenerator(labelLinkColor, 'axis.ticks.line.stroke'),
withPropsOnChange(['labelLinkColor', 'theme'], ({ labelLinkColor, theme }) => ({
getLabelLinkColor: getInheritedColorGenerator(labelLinkColor, theme),
})),
withPropsOnChange(['label', 'labelFormat'], ({ label, labelFormat }) => ({
getLabel: getLabelGenerator(label, labelFormat),
})),
withPropsOnChange(['borderColor'], ({ borderColor }) => ({
getBorderColor: getInheritedColorGenerator(borderColor),
withPropsOnChange(['borderColor', 'theme'], ({ borderColor, theme }) => ({
getBorderColor: getInheritedColorGenerator(borderColor, theme),
})),
withPropsOnChange(['tooltipLabel'], ({ tooltipLabel }) => {
let getTooltipLabel = d => `${d.id} - ${d.indexValue}`
Expand Down
15 changes: 9 additions & 6 deletions packages/bar/src/props.js
Expand Up @@ -8,7 +8,11 @@
*/
import PropTypes from 'prop-types'
import { noop, defsPropTypes } from '@nivo/core'
import { ordinalColorsPropType, colorPropertyAccessorPropType } from '@nivo/colors'
import {
ordinalColorsPropType,
colorPropertyAccessorPropType,
inheritedColorPropType,
} from '@nivo/colors'
import { axisPropType } from '@nivo/axes'
import { LegendPropShape } from '@nivo/legends'
import BarItem from './BarItem'
Expand Down Expand Up @@ -51,9 +55,9 @@ export const BarPropTypes = {
getLabel: PropTypes.func.isRequired, // computed
labelSkipWidth: PropTypes.number.isRequired,
labelSkipHeight: PropTypes.number.isRequired,
labelTextColor: PropTypes.oneOfType([PropTypes.string, PropTypes.func]).isRequired,
labelTextColor: inheritedColorPropType.isRequired,
getLabelTextColor: PropTypes.func.isRequired, // computed
labelLinkColor: PropTypes.oneOfType([PropTypes.string, PropTypes.func]).isRequired,
labelLinkColor: inheritedColorPropType.isRequired,
getLabelLinkColor: PropTypes.func.isRequired, // computed

colors: ordinalColorsPropType.isRequired,
Expand All @@ -62,7 +66,7 @@ export const BarPropTypes = {
getColor: PropTypes.func.isRequired, // computed
...defsPropTypes,
borderWidth: PropTypes.number.isRequired,
borderColor: PropTypes.any.isRequired,
borderColor: inheritedColorPropType.isRequired,
getBorderColor: PropTypes.func.isRequired,

isInteractive: PropTypes.bool,
Expand All @@ -81,7 +85,6 @@ export const BarPropTypes = {
})
).isRequired,

// canvas specific
pixelRatio: PropTypes.number.isRequired,
}

Expand Down Expand Up @@ -119,7 +122,7 @@ export const BarDefaultProps = {
fill: [],
borderRadius: 0,
borderWidth: 0,
borderColor: 'inherit',
borderColor: { from: 'color' },

isInteractive: true,
onClick: noop,
Expand Down
4 changes: 1 addition & 3 deletions website/src/data/components/bar/mapper.js
Expand Up @@ -8,7 +8,7 @@
*/
import React from 'react'
import styled from 'styled-components'
import { settingsMapper, mapAxis, mapInheritedColor } from '../../../lib/settings'
import { settingsMapper, mapAxis } from '../../../lib/settings'

const TooltipWrapper = styled.div`
display: grid;
Expand Down Expand Up @@ -43,8 +43,6 @@ export default settingsMapper(
axisRight: mapAxis('right'),
axisBottom: mapAxis('bottom'),
axisLeft: mapAxis('left'),
borderColor: mapInheritedColor,
labelTextColor: mapInheritedColor,
tooltip: (value, values) => {
if (!values['custom tooltip example']) return null

Expand Down
14 changes: 4 additions & 10 deletions website/src/data/components/bar/props.js
Expand Up @@ -317,14 +317,11 @@ const props = [
how to compute border color,
[see dedicated documentation](self:/guides/colors).
`,
type: 'string | Function',
type: 'string | object | Function',
required: false,
defaultValue: defaults.borderColor,
controlType: 'color',
controlType: 'inheritedColor',
group: 'Style',
controlOptions: {
withCustomColor: true,
},
},
...defsProperties(['Bar']),
{
Expand Down Expand Up @@ -416,14 +413,11 @@ const props = [
key: 'labelTextColor',
scopes: '*',
help: 'Defines how to compute label text color.',
type: 'string | Function',
type: 'string | object | Function',
required: false,
defaultValue: defaults.labelTextColor,
controlType: 'color',
controlType: 'inheritedColor',
group: 'Labels',
controlOptions: {
withCustomColor: true,
},
},
{
key: 'enableGridX',
Expand Down
8 changes: 4 additions & 4 deletions website/src/pages/bar/index.js
Expand Up @@ -60,8 +60,8 @@ const initialProperties = {
borderRadius: 0,
borderWidth: 0,
borderColor: {
type: 'inherit:darker',
gamma: 1.6,
from: 'color',
modifiers: [['darker', 1.6]],
},

axisTop: {
Expand Down Expand Up @@ -106,8 +106,8 @@ const initialProperties = {
labelSkipWidth: 12,
labelSkipHeight: 12,
labelTextColor: {
type: 'inherit:darker',
gamma: 1.6,
from: 'color',
modifiers: [['darker', 1.6]],
},

animate: true,
Expand Down

0 comments on commit c7cf5ce

Please sign in to comment.