diff --git a/apps/scandic-web/components/TempDesignSystem/Form/Date/date.module.css b/apps/scandic-web/components/TempDesignSystem/Form/Date/date.module.css index ecbdd3ee2..74ae18f96 100644 --- a/apps/scandic-web/components/TempDesignSystem/Form/Date/date.module.css +++ b/apps/scandic-web/components/TempDesignSystem/Form/Date/date.module.css @@ -1,35 +1,15 @@ .container { - display: grid; + display: flex; gap: var(--Spacing-x2); - grid-template-areas: "year month day"; - grid-template-columns: 1fr 1fr 1fr; - width: var(--width); + user-select: none; } -@media (max-width: 350px) { +@media screen and (width < 400px) { .container { - display: flex; flex-direction: column; } } -.day { - grid-area: day; -} - -.month { - grid-area: month; -} - -.year { - grid-area: year; -} - -/* TODO: Handle this in Select component. - - out of scope for now. -*/ -.day.invalid > div > div, -.month.invalid > div > div, -.year.invalid > div > div { - border-color: var(--Scandic-Red-60); +.segment { + flex: 1; } diff --git a/apps/scandic-web/components/TempDesignSystem/Form/Date/index.tsx b/apps/scandic-web/components/TempDesignSystem/Form/Date/index.tsx index 6a7b26fc2..1f35d4ab6 100644 --- a/apps/scandic-web/components/TempDesignSystem/Form/Date/index.tsx +++ b/apps/scandic-web/components/TempDesignSystem/Form/Date/index.tsx @@ -1,13 +1,13 @@ "use client" import { parseDate } from "@internationalized/date" import { useEffect } from "react" -import { DateInput, DatePicker, Group, type Key } from "react-aria-components" import { useController, useFormContext, useWatch } from "react-hook-form" import { useIntl } from "react-intl" +import { Select } from "@scandic-hotels/design-system/Select" + import { dt } from "@/lib/dt" -import Select from "@/components/TempDesignSystem/Select" import useLang from "@/hooks/useLang" import { getLocalizedMonthName } from "@/utils/dateFormatting" import { rangeArray } from "@/utils/rangeArray" @@ -22,13 +22,13 @@ export default function DateSelect({ name, registerOptions = {} }: DateProps) { const lang = useLang() const { control, setValue, formState, watch } = useFormContext() - const { field, fieldState } = useController({ + const { field } = useController({ control, name, rules: registerOptions, }) - const currentDateValue = useWatch({ name }) + const currentDateValue: string = useWatch({ name }) const year = watch(DateName.year) const month = watch(DateName.month) const day = watch(DateName.day) @@ -61,16 +61,6 @@ export default function DateSelect({ name, registerOptions = {} }: DateProps) { label: `${day}`, })) - const dayLabel = intl.formatMessage({ - defaultMessage: "Day", - }) - const monthLabel = intl.formatMessage({ - defaultMessage: "Month", - }) - const yearLabel = intl.formatMessage({ - defaultMessage: "Year", - }) - useEffect(() => { if (formState.isSubmitting) return @@ -125,87 +115,50 @@ export default function DateSelect({ name, registerOptions = {} }: DateProps) { }, [setValue, formState.isSubmitting, dateValue, day, month, year]) return ( - - - - {(segment) => { - switch (segment.type) { - case "day": - return ( -
- - setValue(DateName.month, Number(key)) - } - required - tabIndex={2} - value={segment.isPlaceholder ? undefined : segment.value} - /> -
- ) - case "year": - return ( -
- setValue(DateName.day, Number(key))} + isRequired + enableFiltering + defaultSelectedKey={dateValue?.day} + /> +
+
+ setValue(DateName.year, Number(key))} + isRequired + enableFiltering + defaultSelectedKey={dateValue?.year} + /> +
+ -
+ ) } diff --git a/packages/design-system/lib/components/Select/Select.tsx b/packages/design-system/lib/components/Select/Select.tsx index 0682939b2..fab694d30 100644 --- a/packages/design-system/lib/components/Select/Select.tsx +++ b/packages/design-system/lib/components/Select/Select.tsx @@ -15,6 +15,7 @@ import { SelectFilter } from './SelectFilter' import type { SelectProps, SelectFilterProps } from './types' import styles from './select.module.css' +import { useState } from 'react' export function Select({ name, @@ -25,6 +26,8 @@ export function Select({ itemIcon, ...props }: SelectProps | SelectFilterProps) { + const [isOpen, setIsOpen] = useState(false) + if ('enableFiltering' in props) { return (