From 8a7e0f89d24f05389e27443e51e995d0702e5cb7 Mon Sep 17 00:00:00 2001
From: masonschafercodes <57614646+masonschafercodes@users.noreply.github.com>
Date: Tue, 31 Jan 2023 12:41:42 -0500
Subject: [PATCH] feat(web/input): time input field (#206)
* feat(web/input): time input
---
web/src/features/dev/debug/input.ts | 6 ++++
web/src/features/dialog/InputDialog.tsx | 4 +--
.../dialog/components/fields/date.tsx | 29 +++++++++++++++----
web/src/interfaces/dialog.ts | 3 +-
4 files changed, 33 insertions(+), 9 deletions(-)
diff --git a/web/src/features/dev/debug/input.ts b/web/src/features/dev/debug/input.ts
index 0a23a70..5b3afae 100644
--- a/web/src/features/dev/debug/input.ts
+++ b/web/src/features/dev/debug/input.ts
@@ -14,6 +14,12 @@ export const debugInput = () => {
placeholder: '420',
description: 'Description that tells you what this input field does',
},
+ {
+ type: 'time',
+ format: '12',
+ label: 'Locker Time',
+ description: 'Description that tells you what this input field does',
+ },
{ type: 'checkbox', label: 'Some checkbox' },
{ type: 'input', label: 'Locker PIN', password: true, icon: 'lock' },
{ type: 'checkbox', label: 'Some other checkbox', checked: true },
diff --git a/web/src/features/dialog/InputDialog.tsx b/web/src/features/dialog/InputDialog.tsx
index 62b8416..d10d544 100644
--- a/web/src/features/dialog/InputDialog.tsx
+++ b/web/src/features/dialog/InputDialog.tsx
@@ -61,7 +61,7 @@ const InputDialog: React.FC = () => {
{
value:
row.type !== 'checkbox'
- ? row.type === 'date' || row.type === 'date-range'
+ ? row.type === 'date' || row.type === 'date-range' || row.type === 'time'
? // Set date to current one if default is set to true
row.default === true
? new Date().getTime()
@@ -146,7 +146,7 @@ const InputDialog: React.FC = () => {
{row.type === 'number' && }
{row.type === 'slider' && }
{row.type === 'color' && }
- {row.type === 'date' || row.type === 'date-range' ? (
+ {row.type === 'date' || row.type === 'date-range' || row.type === 'time' ? (
) : null}
{row.type === 'textarea' && (
diff --git a/web/src/features/dialog/components/fields/date.tsx b/web/src/features/dialog/components/fields/date.tsx
index 0385f01..5152d84 100644
--- a/web/src/features/dialog/components/fields/date.tsx
+++ b/web/src/features/dialog/components/fields/date.tsx
@@ -1,7 +1,7 @@
import { IDateInput } from '../../../../interfaces/dialog';
import { Control, useController } from 'react-hook-form';
import { FormValues } from '../../InputDialog';
-import { DatePicker, DateRangePicker } from '@mantine/dates';
+import { DatePicker, DateRangePicker, TimeInput } from '@mantine/dates';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
interface Props {
@@ -19,7 +19,7 @@ const DateField: React.FC = (props) => {
return (
<>
- {props.row.type === 'date' ? (
+ {props.row.type === 'date' && (
= (props) => {
minDate={props.row.min ? new Date(props.row.min) : undefined}
maxDate={props.row.max ? new Date(props.row.max) : undefined}
/>
- ) : (
- props.row.type === 'date-range' && (
+ )}
+ {props.row.type === 'date-range' && (
= (props) => {
minDate={props.row.min ? new Date(props.row.min) : undefined}
maxDate={props.row.max ? new Date(props.row.max) : undefined}
/>
- )
- )}
+ )}
+
+ {props.row.type === 'time' && (
+ controller.field.onChange(date ? date.getTime() : null)}
+ label={props.row.label}
+ description={props.row.description}
+ placeholder={props.row.placeholder}
+ disabled={props.row.disabled}
+ format={props.row.format || "12"}
+ withAsterisk={props.row.required}
+ clearable={props.row.clearable}
+ icon={props.row.icon && }
+ />
+ )}
>
);
};
diff --git a/web/src/interfaces/dialog.ts b/web/src/interfaces/dialog.ts
index cf649c9..6b8ff9a 100644
--- a/web/src/interfaces/dialog.ts
+++ b/web/src/interfaces/dialog.ts
@@ -70,11 +70,12 @@ export interface IColorInput {
}
export interface IDateInput {
- type: 'date' | 'date-range';
+ type: 'date' | 'date-range' | 'time';
label: string;
default?: string | [string, string] | true;
disabled?: boolean;
description?: string;
+ format?: '12' | '24' | undefined;
required?: boolean;
placeholder?: string;
clearable?: boolean;