cleaned up styles a bit
This commit is contained in:
1 parent
3acbaf576d
commit
451b3638bf
28 files changed
+864
-705
No files matched your search
@@ -1,7 +1,21 @@
|
||||
import { ButtonHTMLAttributes, FC } from "react";
|
||||
import { useButtonStyles } from "./styles";
|
||||
import { FC, ReactNode } from "react";
|
||||
import MuiButton from "@mui/material/Button";
|
||||
|
||||
export const Button: FC<ButtonHTMLAttributes<HTMLButtonElement>> = props => {
|
||||
const { classes } = useButtonStyles({});
|
||||
return <button {...props} className={`${classes.input} ${props.className ?? ''}`} />
|
||||
}
|
||||
export const Button: FC<{
|
||||
className?: string;
|
||||
title?: string;
|
||||
disabled?: boolean;
|
||||
children?: ReactNode;
|
||||
onClick?: () => void;
|
||||
}> = (props) => {
|
||||
return (
|
||||
<MuiButton
|
||||
className={props.className}
|
||||
title={props.title}
|
||||
disabled={props.disabled}
|
||||
onClick={props.onClick}
|
||||
variant="outlined"
|
||||
children={props.children}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -2,7 +2,8 @@ import "./InputAutoComplete.css";
|
||||
import Autocomplete from "@mui/material/Autocomplete";
|
||||
import TextField from "@mui/material/TextField";
|
||||
import Chip from "@mui/material/Chip";
|
||||
import { Badge, Popper } from "@mui/material";
|
||||
import Badge from "@mui/material/Badge";
|
||||
import Popper from "@mui/material/Popper";
|
||||
import { SearchItem } from "./extras";
|
||||
import { ReactNode } from "react";
|
||||
import { prettyName } from "utils/formatting";
|
||||
|
||||
@@ -2,7 +2,8 @@ import Checkbox from "@mui/material/Checkbox";
|
||||
import FormGroup from "@mui/material/FormGroup";
|
||||
import FormControlLabel from "@mui/material/FormControlLabel";
|
||||
import { ReactNode } from "react";
|
||||
import { FormHelperText, InputAdornment } from "@mui/material";
|
||||
import FormHelperText from "@mui/material/FormHelperText";
|
||||
import InputAdornment from "@mui/material/InputAdornment";
|
||||
|
||||
export interface Props {
|
||||
label: string;
|
||||
|
||||
@@ -3,7 +3,6 @@ import { useState, useEffect, FC } from "react";
|
||||
import TextField from "@mui/material/TextField";
|
||||
import EditIcon from "@mui/icons-material/Edit";
|
||||
import CloseIcon from "@mui/icons-material/Close";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import { AutomationTime, AutomationTimeObject } from "types/automations/common";
|
||||
import {
|
||||
convertAutomationTimeToTimeObject,
|
||||
@@ -12,6 +11,7 @@ import {
|
||||
import { convertAutomationTimeToTimeString } from "utils/time";
|
||||
import { prettyName } from "utils/formatting";
|
||||
import InputLabel from "@mui/material/InputLabel";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
|
||||
// constants
|
||||
const fields: Array<keyof AutomationTimeObject> = [
|
||||
@@ -140,9 +140,10 @@ export const InputTime: FC<Props> = (props) => {
|
||||
onChange={(e) => updateOne(name)(e.target.value)}
|
||||
/>
|
||||
))}
|
||||
<IconButton onClick={() => setDisabled(!disabled)}>
|
||||
{disabled ? <EditIcon /> : <CloseIcon />}
|
||||
</IconButton>
|
||||
<ButtonIcon
|
||||
onClick={() => setDisabled(!disabled)}
|
||||
icon={disabled ? <EditIcon /> : <CloseIcon />}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
.input-number .MuiButtonBase-root.icon-button[type="button"].icon-button {
|
||||
border-style: none;
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
import "./InputNumber.css";
|
||||
import Close from "@mui/icons-material/Close";
|
||||
import TextField from "@mui/material/TextField";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import InputAdornment from "@mui/material/InputAdornment";
|
||||
import Edit from "@mui/icons-material/Edit";
|
||||
import { ReactNode } from "react";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
|
||||
export interface Props {
|
||||
label: string | JSX.Element;
|
||||
@@ -57,7 +58,7 @@ export default function InputNumber({
|
||||
value={value}
|
||||
onChange={(e) => onChange(Number(e.target.value ?? 0))}
|
||||
disabled={disabled}
|
||||
className={className}
|
||||
className={["input-number", className ?? ""].join(" ")}
|
||||
placeholder={placeholder}
|
||||
required={required}
|
||||
fullWidth
|
||||
@@ -67,9 +68,10 @@ export default function InputNumber({
|
||||
endAdornment
|
||||
) : (
|
||||
<InputAdornment position="end">
|
||||
<IconButton onClick={() => onChange(disabled ? 0 : undefined)}>
|
||||
{disabled ? <Edit /> : <Close />}
|
||||
</IconButton>
|
||||
<ButtonIcon
|
||||
onClick={() => onChange(disabled ? 0 : undefined)}
|
||||
icon={disabled ? <Edit /> : <Close />}
|
||||
/>
|
||||
</InputAdornment>
|
||||
),
|
||||
inputProps: {
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
display: flex;
|
||||
gap: 0;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.input-time>.input-time--inner>.icon-button {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.input-time>.input-time--inner>.MuiFormControl-root {
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
import "./InputTime.css";
|
||||
import { useState, useEffect, FC } from "react";
|
||||
import TextField from '@mui/material/TextField';
|
||||
import EditIcon from '@mui/icons-material/Edit';
|
||||
import TextField from "@mui/material/TextField";
|
||||
import EditIcon from "@mui/icons-material/Edit";
|
||||
import CloseIcon from "@mui/icons-material/Close";
|
||||
import IconButton from "@mui/material/IconButton"
|
||||
import { AutomationTime, AutomationTimeObject } from "types/automations/common";
|
||||
import { convertAutomationTimeToTimeObject, convertObjectToAutomationTimeString, convertAutomationTimeToTimeString } from 'utils/time';
|
||||
import {
|
||||
convertAutomationTimeToTimeObject,
|
||||
convertObjectToAutomationTimeString,
|
||||
convertAutomationTimeToTimeString,
|
||||
} from "utils/time";
|
||||
import { prettyName } from "utils/formatting";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
|
||||
// constants
|
||||
const fields: Array<keyof AutomationTimeObject> = [
|
||||
'hours',
|
||||
'minutes',
|
||||
'seconds',
|
||||
'milliseconds'
|
||||
]
|
||||
"hours",
|
||||
"minutes",
|
||||
"seconds",
|
||||
"milliseconds",
|
||||
];
|
||||
export interface Props {
|
||||
label: string;
|
||||
value?: AutomationTime;
|
||||
@@ -22,73 +26,73 @@ export interface Props {
|
||||
className?: string;
|
||||
}
|
||||
export const InputTime: FC<Props> = (props) => {
|
||||
|
||||
|
||||
// state
|
||||
const [disabled, setDisabled] = useState(!props.value)
|
||||
const [displayValue, setDisplayValue] = useState(convertAutomationTimeToTimeObject(props.value))
|
||||
const [disabled, setDisabled] = useState(!props.value);
|
||||
const [displayValue, setDisplayValue] = useState(
|
||||
convertAutomationTimeToTimeObject(props.value)
|
||||
);
|
||||
|
||||
// process display input
|
||||
const updateOne = (k: keyof AutomationTimeObject) => (v: string) => {
|
||||
if (Number(v) < 0) {
|
||||
setDisplayValue({
|
||||
...displayValue,
|
||||
[k]: 0
|
||||
})
|
||||
[k]: 0,
|
||||
});
|
||||
} else if (k === "hours") {
|
||||
setDisplayValue({
|
||||
...displayValue,
|
||||
[k]: Number(v)
|
||||
})
|
||||
[k]: Number(v),
|
||||
});
|
||||
} else if (k === "minutes") {
|
||||
let minutes = Number(v);
|
||||
let { hours = 0 } = displayValue
|
||||
let { hours = 0 } = displayValue;
|
||||
if (minutes > 59) {
|
||||
const additonalHours = Math.floor(minutes / 60)
|
||||
hours += additonalHours
|
||||
minutes = minutes - additonalHours * 60
|
||||
const additonalHours = Math.floor(minutes / 60);
|
||||
hours += additonalHours;
|
||||
minutes = minutes - additonalHours * 60;
|
||||
}
|
||||
setDisplayValue({
|
||||
...displayValue,
|
||||
minutes,
|
||||
hours,
|
||||
})
|
||||
});
|
||||
} else if (k === "seconds") {
|
||||
let seconds = Number(v);
|
||||
let { hours = 0, minutes = 0 } = displayValue
|
||||
let { hours = 0, minutes = 0 } = displayValue;
|
||||
if (seconds > 59) {
|
||||
const additonalHours = Math.floor(seconds / (60 * 60))
|
||||
hours += additonalHours
|
||||
seconds = seconds - additonalHours * 60
|
||||
const additonalHours = Math.floor(seconds / (60 * 60));
|
||||
hours += additonalHours;
|
||||
seconds = seconds - additonalHours * 60;
|
||||
}
|
||||
if (seconds > 59) {
|
||||
const additionalMinutes = Math.floor(seconds / 60)
|
||||
minutes += additionalMinutes
|
||||
seconds = seconds - additionalMinutes * 60
|
||||
const additionalMinutes = Math.floor(seconds / 60);
|
||||
minutes += additionalMinutes;
|
||||
seconds = seconds - additionalMinutes * 60;
|
||||
}
|
||||
setDisplayValue({
|
||||
...displayValue,
|
||||
minutes,
|
||||
hours,
|
||||
seconds,
|
||||
})
|
||||
});
|
||||
} else if (k === "milliseconds") {
|
||||
let milliseconds = Number(v);
|
||||
let { hours = 0, minutes = 0, seconds = 0 } = displayValue
|
||||
let { hours = 0, minutes = 0, seconds = 0 } = displayValue;
|
||||
if (milliseconds > 1000) {
|
||||
const additonalHours = Math.floor(milliseconds / (60 * 60 * 1000))
|
||||
hours += additonalHours
|
||||
milliseconds = milliseconds - additonalHours * 60 * 60 * 1000
|
||||
const additonalHours = Math.floor(milliseconds / (60 * 60 * 1000));
|
||||
hours += additonalHours;
|
||||
milliseconds = milliseconds - additonalHours * 60 * 60 * 1000;
|
||||
}
|
||||
if (milliseconds > 1000) {
|
||||
const additionalMinutes = Math.floor(milliseconds / (60 * 1000))
|
||||
minutes += additionalMinutes
|
||||
milliseconds = milliseconds - additionalMinutes * 60 * 1000
|
||||
const additionalMinutes = Math.floor(milliseconds / (60 * 1000));
|
||||
minutes += additionalMinutes;
|
||||
milliseconds = milliseconds - additionalMinutes * 60 * 1000;
|
||||
}
|
||||
if (milliseconds > 1000) {
|
||||
const additionalSeconds = Math.floor(milliseconds / 1000)
|
||||
seconds += additionalSeconds
|
||||
milliseconds = milliseconds - additionalSeconds * 1000
|
||||
const additionalSeconds = Math.floor(milliseconds / 1000);
|
||||
seconds += additionalSeconds;
|
||||
milliseconds = milliseconds - additionalSeconds * 1000;
|
||||
}
|
||||
setDisplayValue({
|
||||
...displayValue,
|
||||
@@ -96,50 +100,51 @@ export const InputTime: FC<Props> = (props) => {
|
||||
hours,
|
||||
seconds,
|
||||
milliseconds,
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// effect
|
||||
useEffect(() => {
|
||||
if (disabled && !props.value) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
if (disabled) {
|
||||
props.onChange(undefined)
|
||||
props.onChange(undefined);
|
||||
} else {
|
||||
const pVal = convertAutomationTimeToTimeString(props.value);
|
||||
const cVal = convertObjectToAutomationTimeString(displayValue);
|
||||
if (pVal !== cVal) {
|
||||
props.onChange(displayValue)
|
||||
props.onChange(displayValue);
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line
|
||||
}, [disabled, displayValue])
|
||||
}, [disabled, displayValue]);
|
||||
|
||||
|
||||
return <div className={["input-time", props.className ?? ""].join(" ")}>
|
||||
{/* <InputLabel >{props.label}</InputLabel> */}
|
||||
<div className="input-time--inner">
|
||||
{fields.map(name =>
|
||||
<TextField
|
||||
key={name}
|
||||
variant="filled"
|
||||
label={prettyName(name)}
|
||||
defaultValue="00"
|
||||
InputProps={{
|
||||
disabled,
|
||||
type: "number",
|
||||
title: prettyName(name),
|
||||
}}
|
||||
value={displayValue[name] ?? 0}
|
||||
onChange={e => updateOne(name)(e.target.value)}
|
||||
return (
|
||||
<div className={["input-time", props.className ?? ""].join(" ")}>
|
||||
{/* <InputLabel >{props.label}</InputLabel> */}
|
||||
<div className="input-time--inner">
|
||||
{fields.map((name) => (
|
||||
<TextField
|
||||
key={name}
|
||||
variant="filled"
|
||||
label={prettyName(name)}
|
||||
defaultValue="00"
|
||||
InputProps={{
|
||||
disabled,
|
||||
type: "number",
|
||||
title: prettyName(name),
|
||||
}}
|
||||
value={displayValue[name] ?? 0}
|
||||
onChange={(e) => updateOne(name)(e.target.value)}
|
||||
/>
|
||||
))}
|
||||
<ButtonIcon
|
||||
onClick={() => setDisabled(!disabled)}
|
||||
icon={disabled ? <EditIcon /> : <CloseIcon />}
|
||||
/>
|
||||
)}
|
||||
<IconButton onClick={() => setDisabled(!disabled)}>
|
||||
{disabled ? <EditIcon /> : <CloseIcon />}
|
||||
</IconButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
.input-yaml .MuiInputAdornment-positionEnd {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 55%;
|
||||
right: 0.5em;
|
||||
top: 3.5em;
|
||||
}
|
||||
|
||||
.input-yaml .input-yaml--placeholder {
|
||||
@@ -34,4 +34,8 @@
|
||||
left: 2em;
|
||||
top: 2.5em;
|
||||
color: var(--primary-accent);
|
||||
}
|
||||
|
||||
.input-yaml .MuiButtonBase-root.icon-button[type="button"].icon-button {
|
||||
border-style: none;
|
||||
}
|
||||
@@ -5,8 +5,10 @@ import { useEffect, useState, ReactNode } from "react";
|
||||
import CodeMirror from "@uiw/react-codemirror";
|
||||
import FormControl from "@mui/material/FormControl";
|
||||
import InputLabel from "@mui/material/InputLabel";
|
||||
import { FormHelperText, IconButton, InputAdornment } from "@mui/material";
|
||||
import FormHelperText from "@mui/material/FormHelperText";
|
||||
import InputAdornment from "@mui/material/InputAdornment";
|
||||
import { Save } from "@mui/icons-material";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
|
||||
export interface Props<T extends {}> {
|
||||
label: string;
|
||||
@@ -94,15 +96,16 @@ export default function InputYaml<T extends {}>({
|
||||
{!!text ? "" : placeholder}
|
||||
</span>
|
||||
<InputAdornment position="end">
|
||||
<IconButton
|
||||
<ButtonIcon
|
||||
disabled={!hasChanged}
|
||||
onClick={() => onSave()}
|
||||
title={!!error ? "Invalid YAML" : hasChanged ? "Save" : ""}
|
||||
>
|
||||
<Save
|
||||
color={hasChanged ? (!!error ? "error" : "success") : "disabled"}
|
||||
/>
|
||||
</IconButton>
|
||||
icon={
|
||||
<Save
|
||||
color={hasChanged ? (!!error ? "error" : "success") : "disabled"}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
{endAdornment}
|
||||
</InputAdornment>
|
||||
<FormHelperText variant="filled" error={!!error}>
|
||||
|
||||
Reference in new issue
Block a user