added support for more condition editors
This commit is contained in:
1 parent
b71cd3ad0a
commit
2953ac45dd
10 files changed
+253
-25
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { useState } from "react";
|
||||
import { AutomationTime } from "types/automations/common";
|
||||
|
||||
import InputTime from "./InputTime";
|
||||
|
||||
export default {
|
||||
title: 'Inputs/InputTime',
|
||||
component: InputTime,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
} as ComponentMeta<typeof InputTime>;
|
||||
|
||||
|
||||
const Template: ComponentStory<typeof InputTime> = args => {
|
||||
|
||||
const [value, setValue] = useState<AutomationTime>({
|
||||
|
||||
})
|
||||
return <div className="page">
|
||||
<InputTime {...args} value={value} onChange={setValue} />
|
||||
</div>
|
||||
}
|
||||
|
||||
export const SimpleText = Template.bind({})
|
||||
SimpleText.args = {
|
||||
label: "Time Stamp",
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { PropsWithChildren, useState } from "react";
|
||||
import { AutomationTime } from "types/automations/common";
|
||||
import { milisecondsToObject } from "utils/time";
|
||||
import InputWrapper from "./InputWrapper";
|
||||
import { useInputTimeStyles } from "./styles";
|
||||
|
||||
export interface Props {
|
||||
textBoxFor?: string;
|
||||
label: string;
|
||||
value?: AutomationTime;
|
||||
onChange: (v?: AutomationTime) => void;
|
||||
onEnter?: () => void;
|
||||
}
|
||||
export default function InputTime({
|
||||
label,
|
||||
textBoxFor,
|
||||
value = {},
|
||||
onChange,
|
||||
onEnter = () => { },
|
||||
children,
|
||||
}: PropsWithChildren<Props>) {
|
||||
let cleanValue = '';
|
||||
if (value) {
|
||||
const {
|
||||
hours,
|
||||
minutes,
|
||||
seconds,
|
||||
milliseconds,
|
||||
} = value;
|
||||
cleanValue = [hours, minutes, seconds].map(x => String(x).padStart(2, '0')).join(':') + `.${String(milliseconds).padStart(3, '0')}`;
|
||||
}
|
||||
const { classes } = useInputTimeStyles({});
|
||||
const [isFocused, setIsFocused] = useState(false)
|
||||
return <InputWrapper className={classes.wrapper} label={label} labelSize={(value === '') && !isFocused ? 'normal' : 'small'}>
|
||||
<input
|
||||
className={classes.input}
|
||||
type="time"
|
||||
step={0.001}
|
||||
value={cleanValue}
|
||||
onKeyDown={e => {
|
||||
if (e.key === 'Enter') {
|
||||
onEnter();
|
||||
}
|
||||
}}
|
||||
onChange={e => {
|
||||
e.preventDefault();
|
||||
onChange(milisecondsToObject(e.target.valueAsNumber))
|
||||
}}
|
||||
onBlur={e => {
|
||||
setIsFocused(false)
|
||||
}}
|
||||
/>
|
||||
<button onClick={() => onChange()} className={classes.cancel}>X</button>
|
||||
{children}
|
||||
</InputWrapper>
|
||||
}
|
||||
@@ -6,10 +6,11 @@ export interface Props {
|
||||
label: string;
|
||||
labelSize?: 'normal' | 'small';
|
||||
noMargin?: boolean;
|
||||
className?: string;
|
||||
}
|
||||
const InputWrapper: FC<Props> = ({ label, children, labelSize = 'normal', noMargin = false }) => {
|
||||
const InputWrapper: FC<Props> = ({ label, children, labelSize = 'normal', noMargin = false, className = "" }) => {
|
||||
const { classes } = useInputWrapperStyles({ labelSize, noMargin })
|
||||
return <div className={classes.wrapper}>
|
||||
return <div className={[classes.wrapper, className].join(" ")}>
|
||||
<label className={classes.label}>{label}</label>
|
||||
{children}
|
||||
</div>
|
||||
|
||||
@@ -62,6 +62,32 @@ export const useInputTextStyles = createAppUseStyles<{}>(theme => ({
|
||||
...commonInputStyle(theme),
|
||||
}));
|
||||
|
||||
|
||||
export const useInputTimeStyles = createAppUseStyles<{}>(theme => ({
|
||||
input: {
|
||||
...commonInputStyle(theme).input,
|
||||
flex: 1,
|
||||
},
|
||||
wrapper: {
|
||||
flexDirection: 'row !important',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
},
|
||||
cancel: {
|
||||
cursor: 'pointer',
|
||||
maxWidth: "2em",
|
||||
maxHeight: "2em",
|
||||
fontSize: '1em',
|
||||
padding: "0.25em 0.5em",
|
||||
borderRadius: '20px',
|
||||
background: theme.primary,
|
||||
color: theme.primaryAccent,
|
||||
borderColor: theme.primaryAccent,
|
||||
borderStyle: "solid",
|
||||
borderWidth: '1.5px',
|
||||
},
|
||||
}));
|
||||
|
||||
export const useInputNumberStyles = createAppUseStyles<{}>(theme => {
|
||||
const styles = commonInputStyle(theme);
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user