|
| 1 | +import React from "react"; |
| 2 | +import { TimePicker } from "@mui/x-date-pickers"; |
| 3 | +import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider"; |
| 4 | +import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs"; |
| 5 | +import InputLabel from "../InputLabel"; |
| 6 | +import { kebabCase } from "lodash"; |
| 7 | +import PropTypes from "prop-types"; |
| 8 | + |
| 9 | +export const timeFieldStyle = { |
| 10 | + width: "134px", |
| 11 | + borderRadius: "3px", |
| 12 | + height: 40, |
| 13 | + border: "1px solid #B0B0B0", |
| 14 | + marginTop: "8px", |
| 15 | + "& .MuiOutlinedInput-notchedOutline": { |
| 16 | + borderRadius: "3px", |
| 17 | + "& legend": { |
| 18 | + width: 0, |
| 19 | + }, |
| 20 | + }, |
| 21 | + "& .MuiOutlinedInput-root": { |
| 22 | + "&&": { |
| 23 | + borderRadius: "3px", |
| 24 | + }, |
| 25 | + }, |
| 26 | + "& .MuiInputBase-input": { |
| 27 | + color: "#333333", |
| 28 | + fontFamily: "Rubik", |
| 29 | + fontSize: 14, |
| 30 | + borderRadius: "3px", |
| 31 | + padding: "9px", |
| 32 | + Width: "170px", |
| 33 | + "&::placeholder": { |
| 34 | + opacity: 1, |
| 35 | + color: "#717171", |
| 36 | + fontFamily: "Rubik", |
| 37 | + fontSize: 14, |
| 38 | + }, |
| 39 | + }, |
| 40 | +}; |
| 41 | + |
| 42 | +const TimeField = ({ |
| 43 | + label, |
| 44 | + value, |
| 45 | + handleTimeChange, |
| 46 | + disabled, |
| 47 | + required, |
| 48 | + error, |
| 49 | +}) => { |
| 50 | + return ( |
| 51 | + <LocalizationProvider dateAdapter={AdapterDayjs}> |
| 52 | + <InputLabel |
| 53 | + data-testid={`${kebabCase(label)}`} |
| 54 | + style={{ marginBottom: 0, height: 16 }} |
| 55 | + sx={[ |
| 56 | + { |
| 57 | + backgroundColor: "transparent", |
| 58 | + textTransform: "none", |
| 59 | + height: 17, |
| 60 | + left: 0, |
| 61 | + right: 0, |
| 62 | + top: 0, |
| 63 | + fontFamily: "Rubik", |
| 64 | + fontStyle: "normal", |
| 65 | + fontWeight: 500, |
| 66 | + fontSize: 14, |
| 67 | + color: "#333333", |
| 68 | + }, |
| 69 | + ]} |
| 70 | + required={required} |
| 71 | + disabled={disabled} |
| 72 | + error={error} |
| 73 | + > |
| 74 | + {`${label}`} |
| 75 | + </InputLabel> |
| 76 | + <TimePicker |
| 77 | + sx={timeFieldStyle} |
| 78 | + disableOpenPicker |
| 79 | + disabled={disabled} |
| 80 | + value={value ? value : null} |
| 81 | + onChange={handleTimeChange} |
| 82 | + slotProps={{ |
| 83 | + textField: { |
| 84 | + id: "time", |
| 85 | + }, |
| 86 | + }} |
| 87 | + /> |
| 88 | + </LocalizationProvider> |
| 89 | + ); |
| 90 | +}; |
| 91 | + |
| 92 | +TimeField.propTypes = { |
| 93 | + label: PropTypes.string.isRequired, |
| 94 | + value: PropTypes.object, |
| 95 | + handleTimeChange: PropTypes.func.isRequired, |
| 96 | + disabled: PropTypes.bool, |
| 97 | + required: PropTypes.bool, |
| 98 | + error: PropTypes.string, |
| 99 | +}; |
| 100 | + |
| 101 | +export default TimeField; |
0 commit comments