Newer
Older
import React, { ReactNode } from 'react'
import CardActionArea, {
CardActionAreaProps,
} from '@material-ui/core/CardActionArea'
import CardContent from '@material-ui/core/CardContent'
import { withStyles } from '@material-ui/core/styles'
import { FluidType } from 'enum/fluid.enum'
import { getPicto } from 'utils/utils'
import Icon from 'cozy-ui/react/Icon'
import Grid from '@material-ui/core/Grid'
const CardBase = withStyles({
root: {
background: 'linear-gradient(180deg, #323339 0%, #25262B 100%)',
border: '1px solid',
boxSizing: 'border-box',
boxShadow: '0px 4px 16px',
borderRadius: '4px',
display: 'inline',
margin: '0',
},
})(CardActionArea)
const CardElec = withStyles({
root: {
},
})(CardBase)
const CardWater = withStyles({
root: {
},
})(CardBase)
const CardGas = withStyles({
root: {
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
},
})(CardBase)
const CardContentBase = withStyles({
root: {
color: 'white',
},
})(CardContent)
interface StyledIconCardProps extends CardActionAreaProps {
fluidType: FluidType
}
const GenerateContentCard = (
fluidType: FluidType,
children: ReactNode
): React.ReactFragment => {
const icon = getPicto(fluidType)
return (
<CardContentBase>
<Grid
container
spacing={8}
direction="column"
alignItems="center"
justify="center"
>
<Grid item>
<Icon icon={icon} size={64} />
</Grid>
<Grid item>{children}</Grid>
</Grid>
</CardContentBase>
)
}
const StyledIconCard: React.ComponentType<StyledIconCardProps> = ({
fluidType,
...props
}: StyledIconCardProps) => {
switch (fluidType) {
case FluidType.ELECTRICITY:
return (
<CardElec {...props}>
{GenerateContentCard(fluidType, props.children)}
</CardElec>
)
case FluidType.WATER:
return (
<CardWater {...props}>
{GenerateContentCard(fluidType, props.children)}
</CardWater>
)
case FluidType.GAS:
return (
<CardGas {...props}>
{GenerateContentCard(fluidType, props.children)}
</CardGas>
)
default:
return (
<CardBase {...props}>
<CardContentBase>
<Grid container spacing={8} alignItems="center" justify="center">
<Grid item>{props.children}</Grid>
</Grid>
</CardContentBase>
</CardBase>
)
}
}
export default StyledIconCard