22
33import type { Theme } from '@emotion/react'
44import { css } from '@emotion/react'
5- import styled from '@emotion/styled'
65import type { DatumValue } from '@nivo/core'
76import type { Serie } from '@nivo/line'
87import type { ComponentProps } from 'react'
98import { getLegendColor } from '../../helpers/legend'
109import { Checkbox } from '../Checkbox'
1110import { Text } from '../Text'
1211import { getAverage , getCurrent , getMax , getMin , getSelected } from './helpers'
12+ import {
13+ cellValueContainer ,
14+ container ,
15+ longContainer ,
16+ textLegend ,
17+ } from './styles.css'
1318
1419const styles = {
1520 body : ( theme : Theme ) => css `
@@ -47,29 +52,12 @@ type CellProps = {
4752 variant : ComponentProps < typeof Text > [ 'variant' ]
4853}
4954
50- const StyledText = styled ( Text ) `
51- text-align: right;
52- flex: 1;
53- min-width: 72px;
54- align-self: center;
55- `
56-
5755const Cell = ( { value, variant } : CellProps ) => (
58- < StyledText as = "span" sentiment = "neutral" variant = { variant } >
56+ < Text as = "span" className = { textLegend } sentiment = "neutral" variant = { variant } >
5957 { value as string | number }
60- </ StyledText >
58+ </ Text >
6159)
6260
63- const CellValueContainer = styled . div `
64- display: flex;
65- align-items: center;
66- `
67-
68- const LongContainer = styled . div `
69- display: flex;
70- flex: 6;
71- `
72-
7361type Transformer = ( value : DatumValue ) => string
7462
7563const noop : Transformer = value => value . toString ( )
@@ -83,10 +71,6 @@ type CustomLegendProps = {
8371 'data-testid' ?: string
8472}
8573
86- const StyledContainer = styled . div `
87- margin-top: ${ ( { theme } ) => theme . space [ 2 ] } ;
88- `
89-
9074export const CustomLegend = ( {
9175 axisTransformer = noop ,
9276 data,
@@ -95,12 +79,15 @@ export const CustomLegend = ({
9579 className,
9680 'data-testid' : dataTestId ,
9781} : CustomLegendProps ) => (
98- < StyledContainer className = { className } data-testid = { dataTestId } >
82+ < div
83+ className = { `${ className ? `${ className } ` : '' } ${ container } ` }
84+ data-testid = { dataTestId }
85+ >
9986 < div
10087 // oxlint-disable-next-line no-unknown-property
10188 css = { styles . head }
10289 >
103- < LongContainer > Legend</ LongContainer >
90+ < div className = { longContainer } > Legend</ div >
10491 < Cell value = "Minimum" variant = "body" />
10592 < Cell value = "Maximum" variant = "body" />
10693 < Cell value = "Average" variant = "body" />
@@ -122,15 +109,15 @@ export const CustomLegend = ({
122109 // oxlint-disable-next-line no-unknown-property
123110 key = { labelIndexed }
124111 >
125- < LongContainer >
112+ < div className = { longContainer } >
126113 < Checkbox
127114 checked = { selected . includes ( labelIndexed ) }
128115 name = { id }
129116 onChange = { ( ) =>
130117 setSelected ( [ ...getSelected ( id , index , selected ) ] )
131118 }
132119 >
133- < CellValueContainer >
120+ < div className = { cellValueContainer } >
134121 < Text as = "span" sentiment = "neutral" variant = "bodySmall" >
135122 { row ?. [ 'label' ] }
136123 </ Text >
@@ -140,9 +127,9 @@ export const CustomLegend = ({
140127 // oxlint-disable-next-line no-unknown-property
141128 data-testid = { `label-${ id } ` }
142129 />
143- </ CellValueContainer >
130+ </ div >
144131 </ Checkbox >
145- </ LongContainer >
132+ </ div >
146133 < Cell value = { axisTransformer ( getMin ( values ) ) } variant = "bodySmall" />
147134 < Cell value = { axisTransformer ( getMax ( values ) ) } variant = "bodySmall" />
148135 < Cell
@@ -157,5 +144,5 @@ export const CustomLegend = ({
157144 )
158145 } ) }
159146 </ div >
160- </ StyledContainer >
147+ </ div >
161148)
0 commit comments