From b248aa06c1b5616bb1dadfa71167ad77f4759f58 Mon Sep 17 00:00:00 2001 From: Arlindo Pereira Date: Fri, 13 Dec 2024 11:30:10 +0100 Subject: [PATCH] Code Review fixes - Remove invalid CSS rule - Change TimePicker signature to return a Time object with hours and minutes, instead of a time string. --- .../DatePicker/DatePicker.module.scss | 6 ------ .../DateTimePicker/DateTimePicker.tsx | 19 +++++++----------- .../TimePicker/TimePicker.stories.tsx | 6 +++--- .../forms/controls/TimePicker/TimePicker.tsx | 20 +++++++++++++------ 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/components/forms/controls/DatePicker/DatePicker.module.scss b/src/components/forms/controls/DatePicker/DatePicker.module.scss index 8daaf74..7cedf3a 100644 --- a/src/components/forms/controls/DatePicker/DatePicker.module.scss +++ b/src/components/forms/controls/DatePicker/DatePicker.module.scss @@ -155,12 +155,6 @@ $navigation-distance: 1rem; border-radius: bk.$border-radius-circle; } -/* stylelint-disable-next-line */ -:global(.react-datepicker__day:not(&--selected):hover) { - background: rgba(bk.$color-blueberry-500, 0.5); // TODO use proper variable - border-radius: 50%; -} - :global(.react-datepicker-popper[data-placement^="bottom"]) { margin-top: 0; } diff --git a/src/components/forms/controls/DateTimePicker/DateTimePicker.tsx b/src/components/forms/controls/DateTimePicker/DateTimePicker.tsx index cce6d9f..4daa251 100644 --- a/src/components/forms/controls/DateTimePicker/DateTimePicker.tsx +++ b/src/components/forms/controls/DateTimePicker/DateTimePicker.tsx @@ -7,7 +7,7 @@ import * as React from 'react'; import { classNames as cx, type ClassNameArgument } from '../../../../util/componentUtil.ts'; import { DatePicker } from '../DatePicker/DatePicker.tsx'; -import { TimePicker } from '../TimePicker/TimePicker.tsx'; +import { TimePicker, type Time } from '../TimePicker/TimePicker.tsx'; import cl from './DateTimePicker.module.scss'; @@ -29,23 +29,18 @@ type GenericProps = { export type DateTimePickerProps = GenericProps; export const DateTimePicker = ({ unstyled = false, className, date, onChange, ...propsRest }: DateTimePickerProps) => { - // time string from date object - const time = `${String(date?.getHours() || 0).padStart(2, '0')}:${String(date?.getMinutes() || 0).padStart(2, '0')}`; + // time from date object + const time = { hours: date?.getHours() || 0, minutes: date?.getMinutes() || 0 }; // manually update upstream date object when time is updated - const onTimeUpdate = (time: string) => { + const onTimeUpdate = (time: Time) => { if (date) { const newDate = new Date(date); - const [newHours, newMinutes] = time.split(':'); - if (newHours) { - newDate.setHours(Number(newHours)); - } - if (newMinutes) { - newDate.setMinutes(Number(newMinutes)); - } + newDate.setHours(time.hours); + newDate.setMinutes(time.minutes); onChange(newDate); } - } + }; return (
; @@ -29,13 +29,13 @@ export default { export const TimePickerStory: Story = { name: 'Time Picker', render: (args) => { - const [time, setTime] = React.useState('09:41'); + const [time, setTime] = React.useState