Merged in chore/sw-3145-move-deprecated-select (pull request #2518)

chore(SW-3145): Move DeprecatedSelect to design-system

* Move DeprecatedSelect to design-system


Approved-by: Linus Flood
This commit is contained in:
Anton Gunnarsson
2025-07-04 06:34:18 +00:00
parent 923206ee4c
commit 9e1cc66f95
15 changed files with 97 additions and 77 deletions

View File

@@ -2,7 +2,7 @@
import { useIntl } from "react-intl" import { useIntl } from "react-intl"
import DeprecatedSelect from "@/components/TempDesignSystem/DeprecatedSelect" import DeprecatedSelect from "@scandic-hotels/design-system/DeprecatedSelect"
import styles from "./filter.module.css" import styles from "./filter.module.css"

View File

@@ -3,11 +3,11 @@ import { useReducer } from "react"
import { useIntl } from "react-intl" import { useIntl } from "react-intl"
import { type MembershipLevel } from "@scandic-hotels/common/constants/membershipLevels" import { type MembershipLevel } from "@scandic-hotels/common/constants/membershipLevels"
import DeprecatedSelect from "@scandic-hotels/design-system/DeprecatedSelect"
import { membershipLevels } from "@/constants/membershipLevels" import { membershipLevels } from "@/constants/membershipLevels"
import MembershipLevelIcon from "@/components/Levels/Icon" import MembershipLevelIcon from "@/components/Levels/Icon"
import DeprecatedSelect from "@/components/TempDesignSystem/DeprecatedSelect"
import LargeTable from "./LargeTable" import LargeTable from "./LargeTable"
import LevelSummary from "./LevelSummary" import LevelSummary from "./LevelSummary"

View File

@@ -2,9 +2,9 @@
import { useIntl } from "react-intl" import { useIntl } from "react-intl"
import { useDestinationDataStore } from "@/stores/destination-data" import DeprecatedSelect from "@scandic-hotels/design-system/DeprecatedSelect"
import DeprecatedSelect from "@/components/TempDesignSystem/DeprecatedSelect" import { useDestinationDataStore } from "@/stores/destination-data"
import type { SortOption } from "@scandic-hotels/trpc/enums/destinationFilterAndSort" import type { SortOption } from "@scandic-hotels/trpc/enums/destinationFilterAndSort"

View File

@@ -4,11 +4,10 @@ import { useFormContext } from "react-hook-form"
import { useIntl } from "react-intl" import { useIntl } from "react-intl"
import Caption from "@scandic-hotels/design-system/Caption" import Caption from "@scandic-hotels/design-system/Caption"
import DeprecatedSelect from "@scandic-hotels/design-system/DeprecatedSelect"
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
import { ChildBedMapEnum } from "@scandic-hotels/trpc/enums/childBedMapEnum" import { ChildBedMapEnum } from "@scandic-hotels/trpc/enums/childBedMapEnum"
import DeprecatedSelect from "@/components/TempDesignSystem/DeprecatedSelect"
import styles from "./child-selector.module.css" import styles from "./child-selector.module.css"
import type { import type {

View File

@@ -13,6 +13,7 @@ import {
} from "react-aria-components" } from "react-aria-components"
import { useIntl } from "react-intl" import { useIntl } from "react-intl"
import DeprecatedSelect from "@scandic-hotels/design-system/DeprecatedSelect"
import { Divider } from "@scandic-hotels/design-system/Divider" import { Divider } from "@scandic-hotels/design-system/Divider"
import Footnote from "@scandic-hotels/design-system/Footnote" import Footnote from "@scandic-hotels/design-system/Footnote"
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
@@ -21,7 +22,6 @@ import Subtitle from "@scandic-hotels/design-system/Subtitle"
import { useHotelFilterStore } from "@/stores/hotel-filters" import { useHotelFilterStore } from "@/stores/hotel-filters"
import Button from "@/components/TempDesignSystem/Button" import Button from "@/components/TempDesignSystem/Button"
import DeprecatedSelect from "@/components/TempDesignSystem/DeprecatedSelect"
import useInitializeFiltersFromUrl from "@/hooks/useInitializeFiltersFromUrl" import useInitializeFiltersFromUrl from "@/hooks/useInitializeFiltersFromUrl"
import { DEFAULT_SORT } from "../../HotelSorter" import { DEFAULT_SORT } from "../../HotelSorter"

View File

@@ -4,7 +4,8 @@ import { usePathname, useSearchParams } from "next/navigation"
import { useCallback } from "react" import { useCallback } from "react"
import { useIntl } from "react-intl" import { useIntl } from "react-intl"
import DeprecatedSelect from "@/components/TempDesignSystem/DeprecatedSelect" import DeprecatedSelect from "@scandic-hotels/design-system/DeprecatedSelect"
import { trackEvent } from "@/utils/tracking/base" import { trackEvent } from "@/utils/tracking/base"
import { import {

View File

@@ -1,20 +0,0 @@
import type { ReactElement } from "react"
import type { Key } from "react-aria-components"
export interface SelectProps
extends Omit<React.SelectHTMLAttributes<HTMLSelectElement>, "onSelect"> {
defaultSelectedKey?: Key
items: { label: string; value: Key }[]
label: string
name: string
onSelect: (key: Key) => void
value?: string | number
maxHeight?: number
showRadioButton?: boolean
discreet?: boolean
isNestedInModal?: boolean
optionsIcon?: ReactElement<any>
}
export type SelectPortalContainer = HTMLDivElement | undefined
export type SelectPortalContainerArgs = HTMLDivElement | null

View File

@@ -1,7 +1,7 @@
"use client" "use client"
import { useController, useFormContext } from "react-hook-form" import { useController, useFormContext } from "react-hook-form"
import DeprecatedSelect from "@/components/TempDesignSystem/DeprecatedSelect" import DeprecatedSelect from "@scandic-hotels/design-system/DeprecatedSelect"
import type { SelectProps } from "./select" import type { SelectProps } from "./select"

View File

@@ -1,12 +1,28 @@
import type { ReactElement } from "react"
import type { Key } from "react-aria-components"
import type { RegisterOptions } from "react-hook-form" import type { RegisterOptions } from "react-hook-form"
import type { SelectProps as ReactAriaSelectProps } from "@/components/TempDesignSystem/DeprecatedSelect/select" interface ReactAriaSelectProps
extends Omit<
React.SelectHTMLAttributes<HTMLSelectElement>,
"onSelect" | "value"
> {
defaultSelectedKey?: Key
items: { label: string; value: Key }[]
label: string
name: string
maxHeight?: number
showRadioButton?: boolean
discreet?: boolean
isNestedInModal?: boolean
optionsIcon?: ReactElement<any>
}
export interface SelectProps export interface SelectProps
extends Omit< extends Omit<
React.SelectHTMLAttributes<HTMLSelectElement>, React.SelectHTMLAttributes<HTMLSelectElement>,
"name" | "onSelect" | "placeholder" "name" | "onSelect" | "placeholder"
>, >,
Omit<ReactAriaSelectProps, "onSelect" | "ref" | "value"> { Omit<ReactAriaSelectProps, "ref" | "value"> {
registerOptions?: RegisterOptions registerOptions?: RegisterOptions
} }

View File

@@ -1,16 +0,0 @@
import { type IconProps } from "@scandic-hotels/design-system/Icons"
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
import styles from "./chevron.module.css"
export default function SelectChevron(props: IconProps) {
return (
<span aria-hidden="true" className={styles.chevron}>
<MaterialIcon
icon="keyboard_arrow_down"
color={props.color ?? "Icon/Default"}
size={20}
/>
</span>
)
}

View File

@@ -2,6 +2,6 @@
display: flex; display: flex;
} }
div[data-rac][data-open="true"] .chevron { div[data-rac][data-open='true'] .chevron {
transform: rotate(180deg); transform: rotate(180deg);
} }

View File

@@ -0,0 +1,15 @@
import { IconProps } from '../../Icons'
import { MaterialIcon } from '../../Icons/MaterialIcon'
import styles from './chevron.module.css'
export default function SelectChevron(props: IconProps) {
return (
<span aria-hidden="true" className={styles.chevron}>
<MaterialIcon
icon="keyboard_arrow_down"
color={props.color ?? 'Icon/Default'}
size={20}
/>
</span>
)
}

View File

@@ -1,5 +1,5 @@
"use client" 'use client'
import { useState } from "react" import { ReactElement, useState } from 'react'
import { import {
Button, Button,
type Key, type Key,
@@ -8,26 +8,39 @@ import {
Popover, Popover,
Select as ReactAriaSelect, Select as ReactAriaSelect,
SelectValue, SelectValue,
} from "react-aria-components" } from 'react-aria-components'
import Body from "@scandic-hotels/design-system/Body" import SelectChevron from './SelectChevron'
import { Label } from "@scandic-hotels/design-system/Label"
import useSetOverflowVisibleOnRA from "@/hooks/useSetOverflowVisibleOnRA" import styles from './select.module.css'
import Body from '../Body'
import { Label } from '../Label'
import SelectChevron from "../Form/SelectChevron" interface SelectProps
extends Omit<React.SelectHTMLAttributes<HTMLSelectElement>, 'onSelect'> {
defaultSelectedKey?: Key
items: { label: string; value: Key }[]
label: string
name: string
onSelect: (key: Key) => void
value?: string | number
maxHeight?: number
showRadioButton?: boolean
discreet?: boolean
isNestedInModal?: boolean
// eslint-disable-next-line @typescript-eslint/no-explicit-any
optionsIcon?: ReactElement<any>
}
import styles from "./select.module.css" type SelectPortalContainer = HTMLDivElement | undefined
type SelectPortalContainerArgs = HTMLDivElement | null
import type {
SelectPortalContainer,
SelectPortalContainerArgs,
SelectProps,
} from "./select"
/**
* @deprecated Do not use.
*/
export default function Select({ export default function Select({
className = "", className = '',
"aria-label": ariaLabel, 'aria-label': ariaLabel,
defaultSelectedKey, defaultSelectedKey,
items, items,
label, label,
@@ -59,16 +72,16 @@ export default function Select({
let chevronProps = {} let chevronProps = {}
if (discreet) { if (discreet) {
chevronProps = { color: "baseButtonTextOnFillNormal" } chevronProps = { color: 'baseButtonTextOnFillNormal' }
} else if (disabled) { } else if (disabled) {
chevronProps = { color: "disabled" } chevronProps = { color: 'disabled' }
} }
return ( return (
<div className={`${styles.container} ${className}`} ref={setRef}> <div className={`${styles.container} ${className}`} ref={setRef}>
<ReactAriaSelect <ReactAriaSelect
aria-label={ariaLabel} aria-label={ariaLabel}
className={`${styles.select} ${discreet ? styles.discreet : ""} select-container`} className={`${styles.select} ${discreet ? styles.discreet : ''} select-container`}
defaultSelectedKey={defaultSelectedKey} defaultSelectedKey={defaultSelectedKey}
name={name} name={name}
onSelectionChange={handleOnSelect} onSelectionChange={handleOnSelect}
@@ -86,14 +99,13 @@ export default function Select({
<> <>
<Label <Label
required={required} required={required}
size={discreet ? "discreet" : "regular"} size={discreet ? 'discreet' : 'regular'}
> >
{label} {label}
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */}
{discreet && `:`} {discreet && `:`}
</Label> </Label>
{selectedText && ( {selectedText && (
<Body className={optionsIcon ? styles.iconLabel : ""}> <Body className={optionsIcon ? styles.iconLabel : ''}>
{optionsIcon ? optionsIcon : null} {optionsIcon ? optionsIcon : null}
{selectedText} {selectedText}
</Body> </Body>
@@ -138,3 +150,15 @@ export default function Select({
</div> </div>
) )
} }
function useSetOverflowVisibleOnRA(isNestedInModal?: boolean) {
function setOverflowVisible(isOpen: boolean) {
if (isOpen) {
document.body.style.overflow = 'visible'
} else if (!isNestedInModal) {
document.body.style.overflow = ''
}
}
return setOverflowVisible
}

View File

@@ -10,16 +10,16 @@
gap: var(--Spacing-x-half); gap: var(--Spacing-x-half);
} }
.select[data-focused="true"] { .select[data-focused='true'] {
border: 1px solid var(--Border-Interactive-Focus); border: 1px solid var(--Border-Interactive-Focus);
outline: none; outline: none;
} }
.select[data-focused="true"].discreet { .select[data-focused='true'].discreet {
border: 1px solid transparent; border: 1px solid transparent;
outline: none; outline: none;
} }
.select[data-focus-visible="true"].discreet { .select[data-focus-visible='true'].discreet {
border: 1px solid var(--Border-Interactive-Focus); border: 1px solid var(--Border-Interactive-Focus);
} }
@@ -97,8 +97,8 @@
padding: var(--Spacing-x1); padding: var(--Spacing-x1);
} }
.listBoxItem[data-focused="true"], .listBoxItem[data-focused='true'],
.listBoxItem[data-selected="true"] { .listBoxItem[data-selected='true'] {
background: var(--UI-Input-Controls-Surface-Hover); background: var(--UI-Input-Controls-Surface-Hover);
border-radius: var(--Corner-radius-md); border-radius: var(--Corner-radius-md);
outline: none; outline: none;
@@ -111,7 +111,7 @@
.listBoxItem.showRadioButton:before { .listBoxItem.showRadioButton:before {
flex-shrink: 0; flex-shrink: 0;
content: ""; content: '';
margin-right: var(--Spacing-x-one-and-half); margin-right: var(--Spacing-x-one-and-half);
background-color: white; background-color: white;
width: 24px; width: 24px;
@@ -120,6 +120,6 @@
box-shadow: inset 0 0 0 2px var(--Base-Border-Normal); box-shadow: inset 0 0 0 2px var(--Base-Border-Normal);
} }
.listBoxItem[data-selected="true"].showRadioButton:before { .listBoxItem[data-selected='true'].showRadioButton:before {
box-shadow: inset 0 0 0 8px var(--Surface-UI-Fill-Active); box-shadow: inset 0 0 0 8px var(--Surface-UI-Fill-Active);
} }

View File

@@ -11,6 +11,7 @@
"./ChipButton": "./dist/components/ChipButton/index.js", "./ChipButton": "./dist/components/ChipButton/index.js",
"./ChipLink": "./dist/components/ChipLink/index.js", "./ChipLink": "./dist/components/ChipLink/index.js",
"./Chips": "./dist/components/Chips/index.js", "./Chips": "./dist/components/Chips/index.js",
"./DeprecatedSelect": "./dist/components/DeprecatedSelect/index.js",
"./Divider": "./dist/components/Divider/index.js", "./Divider": "./dist/components/Divider/index.js",
"./Footnote": "./dist/components/Footnote/index.js", "./Footnote": "./dist/components/Footnote/index.js",
"./Form/Checkbox": "./dist/components/Form/Checkbox/index.js", "./Form/Checkbox": "./dist/components/Form/Checkbox/index.js",