Fix visual regression in datetime attribute (#2787)

This commit is contained in:
Dawid 2022-12-06 12:02:45 +01:00 committed by GitHub
parent 018b93aaa6
commit b98d5d57ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 0 deletions

View file

@ -10,6 +10,8 @@ import { joinDateTime, splitDateTime } from "@saleor/misc";
import React from "react"; import React from "react";
import { useIntl } from "react-intl"; import { useIntl } from "react-intl";
import { useStyles } from "./styles";
type DateTimeFieldProps = Omit<TextFieldProps, "label" | "error"> & { type DateTimeFieldProps = Omit<TextFieldProps, "label" | "error"> & {
onChange: (value: string) => void; onChange: (value: string) => void;
error: ProductErrorWithAttributesFragment | PageErrorWithAttributesFragment; error: ProductErrorWithAttributesFragment | PageErrorWithAttributesFragment;
@ -24,6 +26,7 @@ export const DateTimeField: React.FC<DateTimeFieldProps> = ({
value, value,
}) => { }) => {
const intl = useIntl(); const intl = useIntl();
const classes = useStyles();
const parsedValue = value ? splitDateTime(value) : { date: "", time: "" }; const parsedValue = value ? splitDateTime(value) : { date: "", time: "" };
@ -44,6 +47,11 @@ export const DateTimeField: React.FC<DateTimeFieldProps> = ({
type="date" type="date"
value={parsedValue.date} value={parsedValue.date}
InputLabelProps={{ shrink: true }} InputLabelProps={{ shrink: true }}
InputProps={{
classes: {
root: classes.dateField,
},
}}
/> />
<TextField <TextField
fullWidth fullWidth
@ -60,6 +68,11 @@ export const DateTimeField: React.FC<DateTimeFieldProps> = ({
type="time" type="time"
value={parsedValue.time} value={parsedValue.time}
InputLabelProps={{ shrink: true }} InputLabelProps={{ shrink: true }}
InputProps={{
classes: {
root: classes.timeField,
},
}}
/> />
</> </>
); );

View file

@ -0,0 +1 @@
export * from "./DateTimeField";

View file

@ -0,0 +1,28 @@
import { makeStyles } from "@saleor/macaw-ui";
export const useStyles = makeStyles(
theme => ({
dateField: {
borderRadius: "4px 0 0 4px",
},
timeField: {
borderRadius: "0 4px 4px 0",
"& > fieldset": {
borderLeftWidth: "0 !important",
},
},
[theme.breakpoints.down("md")]: {
dateField: {
borderRadius: "4px 4px 0 0",
},
timeField: {
borderRadius: "0 0 4px 4px",
"& > fieldset": {
borderTopWidth: "0 !important",
borderLeftWidth: "1px !important",
},
},
},
}),
{ name: "DateTimeField" },
);