From e04342110ac0613703d8f9df4d5d386e99257403 Mon Sep 17 00:00:00 2001 From: Christian Andolf Date: Mon, 14 Apr 2025 10:56:17 +0200 Subject: [PATCH] feat(SW-1509): simplified date of birth component to work with new select added animated labels to new select --- .../Form/Date/date.module.css | 30 +---- .../TempDesignSystem/Form/Date/index.tsx | 122 ++++++------------ .../lib/components/Select/Select.tsx | 14 +- .../lib/components/Select/select.module.css | 32 ++++- 4 files changed, 80 insertions(+), 118 deletions(-) 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..368e3fe33 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" @@ -125,87 +125,45 @@ 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))} + isInvalid={fieldState.invalid} + isRequired + enableFiltering + defaultSelectedKey={day} + /> +
+
+ setValue(DateName.year, Number(key))} + isRequired + enableFiltering + defaultSelectedKey={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 (