import React from 'react' import styled from 'styled-components' import { BarSvgProps, BarCanvasProps } from '@nivo/bar' import { settingsMapper, UnmappedSettings, AxisWithToggle } from '../../../lib/settings' import { mapAxis, UnmappedValueFormat, mapFormat, mapLegends } from '../../../lib/property-mappers' export type MappedBarSvgProps = Omit, 'data' | 'width' | 'height'> export type UnmappedBarSvgProps = UnmappedSettings< MappedBarSvgProps, { valueFormat: UnmappedValueFormat axisTop: AxisWithToggle axisRight: AxisWithToggle axisBottom: AxisWithToggle axisLeft: AxisWithToggle 'custom tooltip example': boolean } > export type MappedBarCanvasProps = Omit, 'data' | 'width' | 'height'> export type UnmappedBarCanvasProps = UnmappedSettings< MappedBarCanvasProps, { valueFormat: UnmappedValueFormat axisTop: AxisWithToggle axisRight: AxisWithToggle axisBottom: AxisWithToggle axisLeft: AxisWithToggle 'custom tooltip example': boolean } > const TooltipWrapper = styled.div` display: grid; grid-template-columns: 1fr 1fr; grid-column-gap: 12px; background: #333; padding: 12px 16px; font-size: 12px; border-radius: 2px; ` const TooltipKey = styled.span` font-weight: 600; ` const TooltipValue = styled.span`` const CustomTooltip = ({ color, ...bar }: any) => { return ( id {bar.id} value {bar.value} formattedValue {bar.formattedValue} index {bar.index} indexValue {bar.indexValue} color {color} ) } export const barSvgMapper = settingsMapper( { valueFormat: mapFormat, axisTop: mapAxis, axisRight: mapAxis, axisBottom: mapAxis, axisLeft: mapAxis, legends: mapLegends, tooltip: (_value: any, values: any) => { if (!values['custom tooltip example']) return undefined return CustomTooltip }, }, { exclude: ['custom tooltip example'], } ) export const barCanvasMapper = barSvgMapper as ReturnType< typeof settingsMapper >