Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) Enhance User Experience with MUI Datepicker #75

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,16 @@
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.0",
"@mui/material": "^5.15.12",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a whole new design system library lik MUI for one feature is not recommended, as it'll increase the bundle size.

also using multiple design systems can lead to inconsistent look on the overall UI. The project already has 'carbondesignsystem' installed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @IamSAL . I fully understand your point! I don't think there's much of a solution that differs from this one, because the dote picker needs the style that's only in these packages. any suggestions?

Thanks,

"@mui/styled-engine-sc": "^6.0.0-alpha.17",
"@mui/x-date-pickers": "^6.19.6",
"dayjs": "^1.11.10",
"i18next": "^21.10.0",
"i18next-parser": "^6.6.0",
"react-hook-form": "^7.34.2",
"styled-components": "^6.1.8",
"turbo": "^1.12.4",
"uuid": "^9.0.1"
},
Expand Down
45 changes: 19 additions & 26 deletions src/group-form-entry-workflow/SessionDetailsForm.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import {
Layer,
Tile,
TextInput,
TextArea,
DatePicker,
DatePickerInput,
} from "@carbon/react";
import { Layer, Tile, TextInput, TextArea } from "@carbon/react";
import React, { useContext } from "react";
import { DatePicker, LocalizationProvider } from "@mui/x-date-pickers";
import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
import dayjs from "dayjs";
import { useConfig } from "@openmrs/esm-framework";
import { useParams } from "react-router-dom";
import styles from "./styles.scss";
Expand Down Expand Up @@ -80,25 +76,22 @@ const SessionDetailsForm = () => {
name="sessionDate"
control={control}
rules={{ required: true }}
defaultValue={dayjs()}
render={({ field }) => (
<DatePicker
datePickerType="single"
size="md"
maxDate={new Date()}
{...field}
>
<DatePickerInput
id="session-date"
labelText={t("sessionDate", "Session Date")}
placeholder="mm/dd/yyyy"
size="md"
invalid={errors.sessionDate}
invalidText={t(
"requiredField",
"This field is required"
)}
/>
</DatePicker>
<LocalizationProvider dateAdapter={AdapterDayjs}>
<div className={`cds--form-item ${styles.sessionDate}`}>
<label className="cds--label">
{t("sessionDate", "Session Date")}
</label>
<DatePicker
name="sessionDate"
views={["day", "month", "year"]}
maxDate={dayjs()}
className="cds--date-picker__input"
{...field}
/>
</div>
</LocalizationProvider>
)}
/>
<TextArea
Expand Down
8 changes: 7 additions & 1 deletion src/group-form-entry-workflow/SessionMetaWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import GroupFormWorkflowContext from "../context/GroupFormWorkflowContext";
import { FormProvider, useForm, useFormContext } from "react-hook-form";
import CancelModal from "../CancelModal";
import SessionDetailsForm from "./SessionDetailsForm";
import dayjs from "dayjs";

const NewGroupWorkflowButtons = () => {
const { t } = useTranslation();
Expand Down Expand Up @@ -78,7 +79,12 @@ const SessionMetaWorkspace = () => {

const onSubmit = (data) => {
const { sessionDate, ...rest } = data;
setSessionMeta({ ...rest, sessionDate: sessionDate[0] });
setSessionMeta({
...rest,
sessionDate: sessionDate.isSame(dayjs(), "day")
? sessionDate
: sessionDate.startOf("day"),
});
};

if (workflowState !== "NEW_GROUP_SESSION") return null;
Expand Down
16 changes: 16 additions & 0 deletions src/group-form-entry-workflow/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,19 @@
@include type.type-style("helper-text-02");
color: colors.$red-60;
}

.sessionDate input {
background-color: var(--cds-field);
font-family: var(--cds-code-02-font-family, "IBM Plex Mono");
font-size: var(--cds-code-02-font-size, .875rem);
height: 2.5rem;
letter-spacing: var(--cds-code-02-letter-spacing, .32px);
line-height: var(--cds-code-02-line-height, 1.42857);
padding: 0 1rem;
}

.sessionDate fieldset {
border: 0;
border-bottom: 1px solid var(--cds-border-strong);
border-radius: 0;
}
Loading