-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iot2050-conf-webui: Add support for SM1238 Energy Meter 480VAC module
Signed-off-by: Baocheng Su <[email protected]>
- Loading branch information
1 parent
6e4c80a
commit f653f7d
Showing
5 changed files
with
1,095 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
recipes-app/iot2050-conf-webui/files/src/components/ConfigEntry/SliderConfig.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* eslint-disable react/prop-types */ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import InputAdornment from '@mui/material/InputAdornment'; | ||
import { styled } from '@mui/material/styles'; | ||
import Typography from '@mui/material/Typography'; | ||
import Grid from '@mui/material/Grid'; | ||
import Slider from '@mui/material/Slider'; | ||
import MuiInput from '@mui/material/Input'; | ||
|
||
const Input = styled(MuiInput)` | ||
width: 100px; | ||
`; | ||
|
||
const doNothing = (id) => {}; | ||
|
||
export default function SliderConfig ({ id, data, unit, updateConfig, disabled = false, postChange = doNothing }) { | ||
const onChangeSlider = (event, newValue) => { | ||
data.value = newValue; | ||
postChange(id); | ||
updateConfig(); | ||
}; | ||
|
||
const onChangeInput = (event) => { | ||
data.value = event.target.value === '' ? 0 : Number(event.target.value); | ||
postChange(id); | ||
updateConfig(); | ||
}; | ||
|
||
const onBlurInput = () => { | ||
if (data.value < data.min) { | ||
data.value = data.min; | ||
} else if (data.value > data.max) { | ||
data.value = data.max; | ||
} | ||
postChange(id); | ||
updateConfig(); | ||
}; | ||
|
||
return ( | ||
<Box sx={{ width: 300 }}> | ||
<Typography id={id + '-slider'} gutterBottom> | ||
{data.label} | ||
</Typography> | ||
<Grid container spacing={2} alignItems="center"> | ||
<Grid item xs> | ||
<Slider | ||
step={1} | ||
disabled={disabled} | ||
min={data.min} | ||
max={data.max} | ||
value={typeof data.value === 'number' ? data.value : 0} | ||
onChange={onChangeSlider} | ||
aria-labelledby="line-vol-tol-slider" | ||
/> | ||
</Grid> | ||
<Grid item> | ||
<Input | ||
endAdornment={<InputAdornment position="end">{unit}</InputAdornment>} | ||
disabled={disabled} | ||
value={data.value} | ||
size="small" | ||
onChange={onChangeInput} | ||
onBlur={onBlurInput} | ||
inputProps={{ | ||
min: data.min, | ||
max: data.max, | ||
type: 'number', | ||
'aria-labelledby': 'line-vol-tol-slider' | ||
}} | ||
/> | ||
</Grid> | ||
</Grid> | ||
</Box> | ||
); | ||
} |
Oops, something went wrong.