Skip to content

Commit

Permalink
Merge pull request #182 from MeasureAuthoringTool/MAT-5828_timeField_2
Browse files Browse the repository at this point in the history
MAT-5828 time field
  • Loading branch information
sb-cecilialiu authored Jul 10, 2023
2 parents f7f3583 + db091c6 commit c4e9dd2
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 748 deletions.
101 changes: 101 additions & 0 deletions react/components/TimeField/TimeField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import React from "react";
import { TimePicker } from "@mui/x-date-pickers";
import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider";
import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
import InputLabel from "../InputLabel";
import { kebabCase } from "lodash";
import PropTypes from "prop-types";

export const timeFieldStyle = {
width: "134px",
borderRadius: "3px",
height: 40,
border: "1px solid #B0B0B0",
marginTop: "8px",
"& .MuiOutlinedInput-notchedOutline": {
borderRadius: "3px",
"& legend": {
width: 0,
},
},
"& .MuiOutlinedInput-root": {
"&&": {
borderRadius: "3px",
},
},
"& .MuiInputBase-input": {
color: "#333333",
fontFamily: "Rubik",
fontSize: 14,
borderRadius: "3px",
padding: "9px",
Width: "170px",
"&::placeholder": {
opacity: 1,
color: "#717171",
fontFamily: "Rubik",
fontSize: 14,
},
},
};

const TimeField = ({
label,
value,
handleTimeChange,
disabled,
required,
error,
}) => {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<InputLabel
data-testid={`${kebabCase(label)}`}
style={{ marginBottom: 0, height: 16 }}
sx={[
{
backgroundColor: "transparent",
textTransform: "none",
height: 17,
left: 0,
right: 0,
top: 0,
fontFamily: "Rubik",
fontStyle: "normal",
fontWeight: 500,
fontSize: 14,
color: "#333333",
},
]}
required={required}
disabled={disabled}
error={error}
>
{`${label}`}
</InputLabel>
<TimePicker
sx={timeFieldStyle}
disableOpenPicker
disabled={disabled}
value={value ? value : null}
onChange={handleTimeChange}
slotProps={{
textField: {
id: "time",
},
}}
/>
</LocalizationProvider>
);
};

TimeField.propTypes = {
label: PropTypes.string.isRequired,
value: PropTypes.object,
handleTimeChange: PropTypes.func.isRequired,
disabled: PropTypes.bool,
required: PropTypes.bool,
error: PropTypes.string,
};

export default TimeField;
26 changes: 26 additions & 0 deletions react/components/TimeField/TimeField.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { useState } from "react";
import TimeField from "./TimeField";
import { withKnobs } from "@storybook/addon-knobs";

export default {
title: "TimeField",
component: TimeField,
decorators: [withKnobs],
};
export const TimeFieldComponent = (args) => {
const [value, setValue] = useState("");
const handleTimeChange = (newValue, v) => {
console.log("Time changed: newValue = ", newValue);
setValue(newValue);
};
return (
<div className="qpp-u-padding--16">
<TimeField
disabled={false}
label="Result Time"
handleTimeChange={handleTimeChange}
value={value}
/>
</div>
);
};
Loading

0 comments on commit c4e9dd2

Please sign in to comment.