diff --git a/apps/scandic-web/components/TempDesignSystem/Form/Country/country.module.css b/apps/scandic-web/components/TempDesignSystem/Form/Country/country.module.css deleted file mode 100644 index ff8d4edf1..000000000 --- a/apps/scandic-web/components/TempDesignSystem/Form/Country/country.module.css +++ /dev/null @@ -1,80 +0,0 @@ -.container { - position: relative; -} - -.comboBoxContainer { - position: relative; - height: 60px; -} - -.label { - position: absolute; - left: var(--Spacing-x2); - top: var(--Spacing-x-one-and-half); - pointer-events: none; -} - -.input { - background-color: var(--Main-Grey-White); - border-color: var(--Scandic-Beige-40); - border-radius: var(--Corner-radius-Medium); - border-style: solid; - border-width: 1px; - padding: var(--Spacing-x4) var(--Spacing-x2) var(--Spacing-x1); - width: 100%; - height: 100%; - - &[aria-invalid="true"], - &[data-invalid="true"] { - border-color: var(--Scandic-Red-60); - } -} - -.input, -.listBoxItem { - color: var(--Main-Grey-100); -} - -.button { - background: none; - border: none; - cursor: pointer; - grid-area: chevron; - height: 100%; - justify-self: flex-end; - padding-left: var(--Spacing-x2); - padding-right: var(--Spacing-x2); - position: absolute; - right: 0; - bottom: 0; - outline: none; -} - -.popover { - background-color: var(--Main-Grey-White); - border-color: var(--Scandic-Beige-40); - border-style: solid; - border-width: 1px; - border-radius: var(--Corner-radius-Medium); - left: 0px; - max-height: 400px; - overflow: auto; - padding: var(--Spacing-x2); - top: calc(60px + var(--Spacing-x1)); - width: 100%; -} - -.listBoxItem { - padding: var(--Spacing-x1) var(--Spacing-x1) var(--Spacing-x1) - var(--Spacing-x2); -} - -.listBoxItem[data-focused="true"], -.listBoxItem[data-focus-visible="true"], -.listBoxItem[data-selected="true"], -.listBoxItem:hover { - background-color: var(--Scandic-Blue-00); - border-radius: var(--Corner-radius-Medium); - cursor: pointer; - outline: none; -} diff --git a/apps/scandic-web/components/TempDesignSystem/Form/Country/index.tsx b/apps/scandic-web/components/TempDesignSystem/Form/Country/index.tsx index ad979fa78..2ed0e1669 100644 --- a/apps/scandic-web/components/TempDesignSystem/Form/Country/index.tsx +++ b/apps/scandic-web/components/TempDesignSystem/Form/Country/index.tsx @@ -1,33 +1,19 @@ "use client" -import { useState } from "react" -import { - Button, - ComboBox, - Input, - type Key, - ListBox, - ListBoxItem, - Popover, -} from "react-aria-components" + +import { useMemo, useState } from "react" +import { useFilter } from "react-aria-components" import { useController, useFormContext } from "react-hook-form" import { useIntl } from "react-intl" +import { Select } from "@scandic-hotels/design-system/Select" + import { countries } from "@/constants/countries" -import Label from "@/components/TempDesignSystem/Form/Label" -import SelectChevron from "@/components/TempDesignSystem/Form/SelectChevron" -import Body from "@/components/TempDesignSystem/Text/Body" import useLang from "@/hooks/useLang" import ErrorMessage from "../ErrorMessage" -import styles from "./country.module.css" - -import type { - CountryPortalContainer, - CountryPortalContainerArgs, - CountryProps, -} from "./country" +import type { CountryProps } from "./country" export default function CountrySelect({ className = "", @@ -38,104 +24,45 @@ export default function CountrySelect({ }: CountryProps) { const lang = useLang() const intl = useIntl() - const [rootDiv, setRootDiv] = useState(undefined) - function setRef(node: CountryPortalContainerArgs) { - if (node) { - setRootDiv(node) - } - } - const { control, setValue } = useFormContext() - const { field, formState } = useController({ + const { startsWith } = useFilter({ sensitivity: "base" }) + const [filterValue, setFilterValue] = useState("") + const { control } = useFormContext() + const { field, formState, fieldState } = useController({ control, name, rules: registerOptions, }) - function handleChange(country: Key | null) { - setValue(name, country ?? "") - } - - const selectCountryLabel = intl.formatMessage({ - defaultMessage: "Select a country", - }) - const collator = new Intl.Collator(lang) + const items = useMemo(() => { + const collator = new Intl.Collator(lang) + return countries + .map((country) => ({ + value: country.code, + label: + intl.formatDisplayName(country.code, { type: "region" }) || + country.name, + })) + .filter((item) => startsWith(item.label, filterValue)) + .sort((a, b) => collator.compare(a.label, b.label)) + }, [filterValue, intl, lang, startsWith]) return ( -
- + - - -
- - - - {countries - .map((country) => ({ - ...country, - localizedDisplayName: - intl.formatDisplayName(country.code, { type: "region" }) || - country.name, - })) - .sort((a, b) => - collator.compare(a.localizedDisplayName, b.localizedDisplayName) - ) - .map((country, idx) => { - return ( - - - {country.localizedDisplayName} - - - ) - })} - - - + isReadOnly={readOnly} + onInputChange={setFilterValue} + /> + ) } diff --git a/apps/scandic-web/components/TempDesignSystem/Form/Date/index.tsx b/apps/scandic-web/components/TempDesignSystem/Form/Date/index.tsx index 1f35d4ab6..a2664a896 100644 --- a/apps/scandic-web/components/TempDesignSystem/Form/Date/index.tsx +++ b/apps/scandic-web/components/TempDesignSystem/Form/Date/index.tsx @@ -22,7 +22,7 @@ export default function DateSelect({ name, registerOptions = {} }: DateProps) { const lang = useLang() const { control, setValue, formState, watch } = useFormContext() - const { field } = useController({ + const { field, fieldState } = useController({ control, name, rules: registerOptions, @@ -127,6 +127,8 @@ export default function DateSelect({ name, registerOptions = {} }: DateProps) { onSelectionChange={(key) => setValue(DateName.day, Number(key))} isRequired enableFiltering + isInvalid={fieldState.invalid} + onBlur={field.onBlur} defaultSelectedKey={dateValue?.day} /> @@ -140,6 +142,8 @@ export default function DateSelect({ name, registerOptions = {} }: DateProps) { onSelectionChange={(key) => setValue(DateName.month, Number(key))} isRequired enableFiltering + isInvalid={fieldState.invalid} + onBlur={field.onBlur} defaultSelectedKey={dateValue?.month} /> @@ -153,6 +157,8 @@ export default function DateSelect({ name, registerOptions = {} }: DateProps) { onSelectionChange={(key) => setValue(DateName.year, Number(key))} isRequired enableFiltering + isInvalid={fieldState.invalid} + onBlur={field.onBlur} defaultSelectedKey={dateValue?.year} /> diff --git a/apps/scandic-web/components/TempDesignSystem/Form/ErrorMessage/error.module.css b/apps/scandic-web/components/TempDesignSystem/Form/ErrorMessage/error.module.css index 215e530ff..450a345c2 100644 --- a/apps/scandic-web/components/TempDesignSystem/Form/ErrorMessage/error.module.css +++ b/apps/scandic-web/components/TempDesignSystem/Form/ErrorMessage/error.module.css @@ -1,6 +1,6 @@ .message { align-items: center; - color: var(--Scandic-Red-60); + color: var(--Text-Interactive-Error); display: flex; gap: var(--Spacing-x-half); margin: var(--Spacing-x1) 0 0; diff --git a/apps/scandic-web/components/TempDesignSystem/Form/ErrorMessage/index.tsx b/apps/scandic-web/components/TempDesignSystem/Form/ErrorMessage/index.tsx index 0e4f2b155..09b7a72ca 100644 --- a/apps/scandic-web/components/TempDesignSystem/Form/ErrorMessage/index.tsx +++ b/apps/scandic-web/components/TempDesignSystem/Form/ErrorMessage/index.tsx @@ -1,5 +1,7 @@ import { ErrorMessage as RHFErrorMessage } from "@hookform/error-message" +import { useIntl } from "react-intl" +import { getErrorMessage } from "../Input/errors" import Error from "./Error" import type { ErrorMessageProps } from "./errorMessage" @@ -8,11 +10,12 @@ export default function ErrorMessage({ errors, name, }: ErrorMessageProps) { + const intl = useIntl() return ( {message}} + render={({ message }) => {getErrorMessage(intl, message)}} /> ) } diff --git a/apps/scandic-web/components/TempDesignSystem/Form/Input/index.tsx b/apps/scandic-web/components/TempDesignSystem/Form/Input/index.tsx index c0a04d30a..bb6c47fc5 100644 --- a/apps/scandic-web/components/TempDesignSystem/Form/Input/index.tsx +++ b/apps/scandic-web/components/TempDesignSystem/Form/Input/index.tsx @@ -83,7 +83,7 @@ const Input = forwardRef(function Input( ) : null} {fieldState.error && !hideError ? ( - + {getErrorMessage(intl, fieldState.error.message)} ) : null} diff --git a/apps/scandic-web/components/TempDesignSystem/Form/Input/input.module.css b/apps/scandic-web/components/TempDesignSystem/Form/Input/input.module.css index 797ee9ae9..db208169e 100644 --- a/apps/scandic-web/components/TempDesignSystem/Form/Input/input.module.css +++ b/apps/scandic-web/components/TempDesignSystem/Form/Input/input.module.css @@ -6,7 +6,7 @@ .error { align-items: center; - color: var(--Scandic-Red-60); + color: var(--Text-Interactive-Error); display: flex; gap: var(--Spacing-x-half); margin: var(--Spacing-x1) 0 0; diff --git a/apps/scandic-web/constants/countries.ts b/apps/scandic-web/constants/countries.ts index f9a0e72d9..687a7e688 100644 --- a/apps/scandic-web/constants/countries.ts +++ b/apps/scandic-web/constants/countries.ts @@ -120,7 +120,6 @@ export const countriesMap = { "Korea, Republic of": "KR", Kuwait: "KW", Kyrgyzstan: "KG", - 'Lao People"S Democratic Republic': "LA", Laos: "LA", Latvia: "LV", Lebanon: "LB", @@ -241,7 +240,6 @@ export const countriesMap = { Uzbekistan: "UZ", Vanuatu: "VU", Venezuela: "VE", - "Viet Nam": "VN", Vietnam: "VN", "Virgin Islands, British": "VG", "Virgin Islands, U.S.": "VI", diff --git a/packages/design-system/lib/components/Select/SelectFilter.tsx b/packages/design-system/lib/components/Select/SelectFilter.tsx index 42a6e5514..b3ba534e7 100644 --- a/packages/design-system/lib/components/Select/SelectFilter.tsx +++ b/packages/design-system/lib/components/Select/SelectFilter.tsx @@ -24,7 +24,9 @@ export function SelectFilter({ icon, itemIcon, defaultSelectedKey, - onSelectionChange, + onSelectionChange = () => undefined, + onFocus = () => undefined, + onBlur = () => undefined, ...props }: SelectFilterProps) { const [focus, setFocus] = useState(false) @@ -39,12 +41,16 @@ export function SelectFilter({ isDisabled={isDisabled} onSelectionChange={(val) => { setValue(val) - if (onSelectionChange) { - onSelectionChange(val) - } + onSelectionChange(val) + }} + onFocus={(e) => { + setFocus(true) + onFocus(e) + }} + onBlur={(e) => { + setFocus(false) + onBlur(e) }} - onFocus={() => setFocus(true)} - onBlur={() => setFocus(false)} defaultSelectedKey={defaultSelectedKey} {...props} >