react-garden
Version:
React + TypeScript + ThreeJS app using Material UI on NextJS, Apollo Client, GraphQL + WordPress REST APIs, for ThreeD web development.. a part of the threed.ai code family.
134 lines (121 loc) • 3.44 kB
JavaScript
// ** React Imports
import { forwardRef, useState } from 'react'
// ** MUI Imports
import Card from '@mui/material/Card'
import TextField from '@mui/material/TextField'
import CardHeader from '@mui/material/CardHeader'
import CardContent from '@mui/material/CardContent'
import InputAdornment from '@mui/material/InputAdornment'
// ** Third Party Imports
import format from 'date-fns/format'
import DatePicker from 'react-datepicker'
// ** Icons Imports
import BellOutline from 'mdi-material-ui/BellOutline'
import ChevronDown from 'mdi-material-ui/ChevronDown'
// ** Component Import
import ReactApexcharts from '~/@core/components/react-apexcharts'
const ApexBarChart = () => {
// ** States
const [endDate, setEndDate] = useState(null)
const [startDate, setStartDate] = useState(new Date())
const options = {
chart: {
parentHeightOffset: 0,
toolbar: {
show: false
}
},
plotOptions: {
bar: {
borderRadius: 8,
barHeight: '30%',
horizontal: true,
startingShape: 'rounded'
}
},
grid: {
xaxis: {
lines: {
show: false
}
},
padding: {
top: -10
}
},
colors: ['#00cfe8'],
dataLabels: {
enabled: false
},
xaxis: {
categories: ['MON, 11', 'THU, 14', 'FRI, 15', 'MON, 18', 'WED, 20', 'FRI, 21', 'MON, 23']
}
}
const series = [
{
data: [700, 350, 480, 600, 210, 550, 150]
}
]
const CustomInput = forwardRef((props, ref) => {
const startDate = format(props.start, 'MM/dd/yyyy')
const endDate = props.end !== null ? ` - ${format(props.end, 'MM/dd/yyyy')}` : null
const value = `${startDate}${endDate !== null ? endDate : ''}`
return (
<TextField
{...props}
size='small'
value={value}
inputRef={ref}
InputProps={{
startAdornment: (
<InputAdornment position='start'>
<BellOutline />
</InputAdornment>
),
endAdornment: (
<InputAdornment position='end'>
<ChevronDown />
</InputAdornment>
)
}}
/>
)
})
const handleOnChange = dates => {
const [start, end] = dates
setStartDate(start)
setEndDate(end)
}
return (
<Card>
<CardHeader
title='Data Science'
subheader='$74,382.72'
titleTypographyProps={{ variant: 'h6' }}
subheaderTypographyProps={{ variant: 'caption' }}
sx={{
flexDirection: ['column', 'row'],
alignItems: ['flex-start', 'center'],
'& .MuiCardHeader-action': { mb: 0 },
'& .MuiCardHeader-content': { mb: [2, 0] }
}}
action={
<DatePicker
selectsRange
endDate={endDate}
id='apexchart-bar'
selected={startDate}
startDate={startDate}
onChange={handleOnChange}
placeholderText='Click to select a date'
customInput={<CustomInput start={startDate} end={endDate} />}
/>
}
/>
<CardContent>
<ReactApexcharts options={options} series={series} type='bar' height={400} />
</CardContent>
</Card>
)
}
export default ApexBarChart