-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #354 from AllenInstitute/feature/metadata-editing/…
…custom-input-fields Add custom input fields for editing metadata
- Loading branch information
Showing
25 changed files
with
539 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/core/components/DateRangePicker/DateTimePicker.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
.display-block { | ||
display: block; | ||
} | ||
|
||
.dateTimeWrapper { | ||
display: flex; | ||
} | ||
|
||
.date-range-root { | ||
width: 300px; | ||
min-width: 145px; | ||
} | ||
|
||
.date-range-text-field div, .time-picker { | ||
background-color: var(--secondary-background-color); | ||
border: none; | ||
border-radius: var(--small-border-radius); | ||
color: var(--primary-text-color); | ||
} | ||
|
||
.date-range-text-field div::after, .time-picker:focus-visible { | ||
border: 1px solid var(--aqua); | ||
outline: none; | ||
} | ||
|
||
.date-range-text-field > div, .time-picker { | ||
border: 1px solid var(--border-color) | ||
} | ||
|
||
.date-range-text-field i, .time-picker i { | ||
color: var(--primary-text-color); | ||
} | ||
|
||
.read-only-placeholder { | ||
margin-right: 20px; | ||
font-style: italic; | ||
font-size: var(--s-paragraph-size) !important; /* override FluentUI button callout font size*/ | ||
color: var(--primary-text-color); | ||
} | ||
|
||
.time-picker { | ||
height: 34px; | ||
margin: 0 0 5px 5px; | ||
color-scheme: dark; | ||
width: 150px; | ||
padding: 0 5px; | ||
} |
63 changes: 63 additions & 0 deletions
63
packages/core/components/DateRangePicker/DateTimePicker.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { DatePicker } from "@fluentui/react"; | ||
import * as React from "react"; | ||
|
||
import styles from "./DateTimePicker.module.css"; | ||
|
||
interface DateTimePickerProps { | ||
className?: string; | ||
placeholder: string; | ||
defaultDate?: Date; | ||
onSelectDate: (date: Date | null | undefined) => void; | ||
showTimeSelection?: boolean; // Show time input; default false | ||
} | ||
|
||
/** | ||
* DatePicker that can also function as DateTimePicker | ||
* by including showTimeSelection prop | ||
*/ | ||
export default function DateTimePicker(props: DateTimePickerProps) { | ||
const { onSelectDate } = props; | ||
const [date, setDate] = React.useState<Date | undefined>(props?.defaultDate); | ||
const [time, setTime] = React.useState<string | undefined>(""); | ||
|
||
React.useEffect(() => { | ||
if (!date && !time) return; | ||
// Prioritize the date from datePicked, otherwise set to today | ||
const combinedDateTime: Date = date || new Date(); | ||
if (time) { | ||
combinedDateTime.setHours(Number(time.split(":")[0])); | ||
combinedDateTime.setMinutes(Number(time.split(":")[1])); | ||
combinedDateTime.setSeconds(Number(time.split(":")[2])); | ||
} | ||
onSelectDate(combinedDateTime); | ||
}, [date, time, onSelectDate]); | ||
|
||
return ( | ||
<> | ||
<DatePicker | ||
className={props?.className} | ||
styles={{ | ||
root: styles.dateRangeRoot, | ||
readOnlyPlaceholder: styles.readOnlyPlaceholder, | ||
textField: styles.dateRangeTextField, | ||
}} | ||
placeholder={props.placeholder} | ||
onSelectDate={(date) => setDate(date || undefined)} | ||
value={date} | ||
/> | ||
{props?.showTimeSelection && ( | ||
<input | ||
type="time" | ||
className={styles.timePicker} | ||
step="2" | ||
onChange={(ev) => setTime(ev.target.value)} | ||
value={time} | ||
/> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
DateTimePicker.defaultProps = { | ||
showTimeSelection: false, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/core/components/DurationForm/DurationForm.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.input-wrapper { | ||
display: flex; | ||
} | ||
|
||
.input-field { | ||
margin-right: 3px; | ||
max-height: fit-content; | ||
} | ||
|
||
.input-field > input { | ||
padding: 6px; | ||
font-size: var(--s-paragraph-size); | ||
max-width: 70px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import * as React from "react"; | ||
|
||
import NumberField from "../NumberRangePicker/NumberField"; | ||
import annotationFormatterFactory, { AnnotationType } from "../../entity/AnnotationFormatter"; | ||
|
||
import styles from "./DurationForm.module.css"; | ||
|
||
interface DurationFormProps { | ||
className?: string; | ||
onChange: (totalDuration: number) => void; | ||
title?: string; | ||
} | ||
|
||
/** | ||
* This component renders a simple form for entering durations | ||
*/ | ||
export default function DurationForm(props: DurationFormProps) { | ||
const { onChange } = props; | ||
const [days, setDurationDays] = React.useState<string>("0"); | ||
const [hours, setDurationHours] = React.useState<string>("0"); | ||
const [minutes, setDurationMinutes] = React.useState<string>("0"); | ||
const [seconds, setDurationSeconds] = React.useState<string>("0"); | ||
const durationFormatter = annotationFormatterFactory(AnnotationType.DURATION); | ||
|
||
React.useEffect(() => { | ||
const durationString = `${Number(days) || 0}D ${Number(hours) || 0}H ${ | ||
Number(minutes) || 0 | ||
}M ${Number(seconds) || 0}S`; | ||
const totalDurationInMs = Number(durationFormatter.valueOf(durationString)); | ||
onChange(totalDurationInMs); | ||
}, [days, hours, minutes, seconds, durationFormatter, onChange]); | ||
|
||
return ( | ||
<div> | ||
<h3 className={styles.title}>{props?.title}</h3> | ||
<div className={styles.inputWrapper}> | ||
<NumberField | ||
aria-label="Days" | ||
className={styles.inputField} | ||
id="durationDays" | ||
label="Days" | ||
onChange={(event) => setDurationDays(event?.target?.value || "")} | ||
defaultValue={days} | ||
min={0} | ||
/> | ||
<NumberField | ||
aria-label="Hours" | ||
className={styles.inputField} | ||
id="durationHours" | ||
label="Hrs" | ||
onChange={(event) => setDurationHours(event?.target?.value || "")} | ||
defaultValue={hours} | ||
min={0} | ||
max={23} | ||
/> | ||
<NumberField | ||
aria-label="Minutes" | ||
className={styles.inputField} | ||
id="durationMinutes" | ||
label="Mins" | ||
onChange={(event) => setDurationMinutes(event?.target?.value || "")} | ||
defaultValue={minutes} | ||
min={0} | ||
max={59} | ||
/> | ||
<NumberField | ||
aria-label="Seconds" | ||
className={styles.inputField} | ||
id="durationSeconds" | ||
label="Secs" | ||
onChange={(event) => setDurationSeconds(event?.target?.value || "")} | ||
defaultValue={seconds} | ||
min={0} | ||
max={59} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.