refactor: move input and label to design system
correct variables according to design system spec various cleanup
This commit is contained in:
@@ -16,13 +16,13 @@ import { FormProvider, useForm } from "react-hook-form"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import { Input } from "@scandic-hotels/design-system/Input"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
|
||||
import { SAS_TRANSFER_POINT_KEY } from "@/app/[lang]/(partner)/(sas)/(protected)/sas-x-scandic/sasUtils"
|
||||
import Image from "@/components/Image"
|
||||
import Modal from "@/components/Modal"
|
||||
import Button from "@/components/TempDesignSystem/Button"
|
||||
import AriaInputWithLabel from "@/components/TempDesignSystem/Form/Input/AriaInputWithLabel"
|
||||
|
||||
import styles from "./transferPoints.module.css"
|
||||
|
||||
@@ -86,7 +86,7 @@ export function TransferPointsFormClient({
|
||||
</I18nProvider>
|
||||
<div className={styles.inputsWrapper}>
|
||||
<TextField type="number" isDisabled={disabled}>
|
||||
<AriaInputWithLabel
|
||||
<Input
|
||||
label={intl.formatMessage({
|
||||
defaultMessage: "EB points to transfer",
|
||||
})}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
.container {
|
||||
align-content: center;
|
||||
background-color: var(--Surface-Primary-Default);
|
||||
border-color: var(--Border-Interactive-Default);
|
||||
border-style: solid;
|
||||
border-width: 1px;
|
||||
border-radius: var(--Corner-radius-md);
|
||||
display: grid;
|
||||
min-width: 0; /* allow shrinkage */
|
||||
height: 60px;
|
||||
padding: var(--Space-x1) var(--Space-x2);
|
||||
transition: border-color 200ms ease;
|
||||
}
|
||||
|
||||
.container:has(.input:focus) {
|
||||
border-color: var(--Border-Interactive-Focus);
|
||||
}
|
||||
|
||||
.container:has(.input:disabled) {
|
||||
background-color: var(--Surface-Primary-Disabled);
|
||||
border: none;
|
||||
color: var(--Text-Interactive-Disabled);
|
||||
}
|
||||
|
||||
.container:has(.input[data-invalid="true"], .input[aria-invalid="true"]) {
|
||||
border-color: var(--Border-Interactive-Error);
|
||||
|
||||
&:focus-within {
|
||||
outline-offset: -2px;
|
||||
outline: 2px solid var(--Border-Interactive-Error);
|
||||
}
|
||||
}
|
||||
|
||||
.input {
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--Text-Default);
|
||||
height: 1px;
|
||||
margin: 0;
|
||||
order: 2;
|
||||
overflow: visible;
|
||||
padding: 0;
|
||||
transition: height 150ms ease;
|
||||
}
|
||||
|
||||
.input:focus,
|
||||
.input:placeholder-shown,
|
||||
.input[value]:not([value=""]) {
|
||||
height: 18px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.input:disabled {
|
||||
color: var(--Text-Interactive-Disabled);
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
export interface AriaInputWithLabelProps
|
||||
extends React.InputHTMLAttributes<HTMLInputElement> {
|
||||
label: string
|
||||
}
|
||||
@@ -6,8 +6,8 @@ import { Controller, useFormContext } from "react-hook-form"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import { Input as InputWithLabel } from "@scandic-hotels/design-system/Input"
|
||||
|
||||
import AriaInputWithLabel from "@/components/TempDesignSystem/Form/Input/AriaInputWithLabel"
|
||||
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
||||
|
||||
import { getErrorMessage } from "./errors"
|
||||
@@ -63,7 +63,7 @@ const Input = forwardRef<HTMLInputElement, InputProps>(function Input(
|
||||
validationBehavior="aria"
|
||||
value={field.value}
|
||||
>
|
||||
<AriaInputWithLabel
|
||||
<InputWithLabel
|
||||
{...field}
|
||||
ref={ref}
|
||||
aria-labelledby={field.name}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
import { labelVariants } from "./variants"
|
||||
|
||||
import type { LabelProps } from "./label"
|
||||
|
||||
export default function Label({
|
||||
children,
|
||||
className,
|
||||
required,
|
||||
size,
|
||||
}: LabelProps) {
|
||||
const classNames = labelVariants({
|
||||
className,
|
||||
size,
|
||||
required,
|
||||
})
|
||||
|
||||
return <span className={classNames}>{children}</span>
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
.label {
|
||||
color: var(--Text-Interactive-Placeholder);
|
||||
font-family: "fira sans";
|
||||
font-weight: 400;
|
||||
letter-spacing: 0.03px;
|
||||
line-height: 120%;
|
||||
text-align: left;
|
||||
transition: font-size 100ms ease;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
span.small {
|
||||
display: block;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
span.regular {
|
||||
font-size: 16px;
|
||||
order: 1;
|
||||
}
|
||||
|
||||
span.discreet {
|
||||
color: var(--Text-Interactive-Default);
|
||||
font-weight: 500;
|
||||
order: unset;
|
||||
}
|
||||
|
||||
span.required:after {
|
||||
content: " *";
|
||||
}
|
||||
|
||||
/* Handle input and textarea fields */
|
||||
input:focus ~ .label,
|
||||
input:placeholder-shown ~ .label,
|
||||
input[value]:not([value=""]) ~ .label,
|
||||
textarea:focus ~ .label textarea:placeholder-shown ~ .label,
|
||||
textarea[value]:not([value=""]) ~ .label {
|
||||
font-size: 12px;
|
||||
margin-bottom: var(--Space-x05);
|
||||
}
|
||||
|
||||
input:disabled ~ .label,
|
||||
textarea:disabled ~ .label,
|
||||
:global(.select-container)[data-disabled] .label {
|
||||
color: var(--Text-Interactive-Disabled);
|
||||
}
|
||||
|
||||
/* Handle select fields */
|
||||
:global(.select-button) .label {
|
||||
order: unset;
|
||||
}
|
||||
|
||||
:global(.select-container)[data-open="true"] .label:not(.discreet),
|
||||
:global(.react-aria-SelectValue):has(:nth-child(2)) .label:not(.discreet) {
|
||||
font-size: 12px;
|
||||
margin-bottom: var(--Space-x05);
|
||||
}
|
||||
@@ -6,9 +6,9 @@ import { Controller, useFormContext } from "react-hook-form"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import { Input } from "@scandic-hotels/design-system/Input"
|
||||
|
||||
import Button from "@/components/TempDesignSystem/Button"
|
||||
import AriaInputWithLabel from "@/components/TempDesignSystem/Form/Input/AriaInputWithLabel"
|
||||
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
||||
import { passwordValidators } from "@/utils/zod/passwordValidator"
|
||||
|
||||
@@ -62,7 +62,7 @@ export default function PasswordInput({
|
||||
}
|
||||
>
|
||||
<div className={styles.inputWrapper}>
|
||||
<AriaInputWithLabel
|
||||
<Input
|
||||
{...field}
|
||||
aria-labelledby={field.name}
|
||||
id={field.name}
|
||||
|
||||
@@ -12,12 +12,12 @@ import {
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import { Input } from "@scandic-hotels/design-system/Input"
|
||||
import { Label } from "@scandic-hotels/design-system/Label"
|
||||
|
||||
import { getDefaultCountryFromLang } from "@/constants/languages"
|
||||
|
||||
import ErrorMessage from "@/components/TempDesignSystem/Form/ErrorMessage"
|
||||
import AriaInputWithLabel from "@/components/TempDesignSystem/Form/Input/AriaInputWithLabel"
|
||||
import Label from "@/components/TempDesignSystem/Form/Label"
|
||||
import Body from "@/components/TempDesignSystem/Text/Body"
|
||||
import useLang from "@/hooks/useLang"
|
||||
|
||||
@@ -114,7 +114,7 @@ export default function Phone({
|
||||
type="tel"
|
||||
value={phoneNumber}
|
||||
>
|
||||
<AriaInputWithLabel
|
||||
<Input
|
||||
{...register(name, registerOptions)}
|
||||
autoComplete="tel-national"
|
||||
label={label}
|
||||
|
||||
@@ -9,8 +9,8 @@ import {
|
||||
import { Controller, useFormContext } from "react-hook-form"
|
||||
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
import { Label } from "@scandic-hotels/design-system/Label"
|
||||
|
||||
import Label from "@/components/TempDesignSystem/Form/Label"
|
||||
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
||||
|
||||
import Body from "../../Text/Body"
|
||||
|
||||
@@ -10,7 +10,8 @@ import {
|
||||
SelectValue,
|
||||
} from "react-aria-components"
|
||||
|
||||
import Label from "@/components/TempDesignSystem/Form/Label"
|
||||
import { Label } from "@scandic-hotels/design-system/Label"
|
||||
|
||||
import Body from "@/components/TempDesignSystem/Text/Body"
|
||||
import useSetOverflowVisibleOnRA from "@/hooks/useSetOverflowVisibleOnRA"
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react'
|
||||
|
||||
import { Input } from './Input'
|
||||
import { TextField } from 'react-aria-components'
|
||||
|
||||
const meta: Meta<typeof Input> = {
|
||||
title: 'Components/Input',
|
||||
component: ({ isInvalid, ...props }) => (
|
||||
<TextField isInvalid={isInvalid}>
|
||||
<Input {...props} />
|
||||
</TextField>
|
||||
),
|
||||
argTypes: {},
|
||||
}
|
||||
|
||||
export default meta
|
||||
|
||||
type Story = StoryObj<typeof Input>
|
||||
|
||||
export const Default: Story = {
|
||||
args: {
|
||||
label: 'Label',
|
||||
name: 'foo',
|
||||
required: false,
|
||||
},
|
||||
}
|
||||
|
||||
export const Filled: Story = {
|
||||
args: {
|
||||
label: 'Label',
|
||||
name: 'foo',
|
||||
value: 'Value',
|
||||
},
|
||||
}
|
||||
|
||||
export const Error: Story = {
|
||||
args: {
|
||||
label: 'Label',
|
||||
name: 'foo',
|
||||
// @ts-expect-error Input does not support this, but wrapping <TextField> does
|
||||
isInvalid: true,
|
||||
},
|
||||
}
|
||||
|
||||
export const Disabled: Story = {
|
||||
args: {
|
||||
label: 'Label',
|
||||
name: 'foo',
|
||||
disabled: true,
|
||||
},
|
||||
}
|
||||
|
||||
export const DisabledFilled: Story = {
|
||||
args: {
|
||||
label: 'Label',
|
||||
name: 'foo',
|
||||
disabled: true,
|
||||
value: 'Value',
|
||||
},
|
||||
}
|
||||
@@ -1,22 +1,22 @@
|
||||
import { cx } from "class-variance-authority"
|
||||
import { cx } from 'class-variance-authority'
|
||||
import {
|
||||
type ForwardedRef,
|
||||
forwardRef,
|
||||
useId,
|
||||
useImperativeHandle,
|
||||
useRef,
|
||||
} from "react"
|
||||
import { Input as AriaInput, Label as AriaLabel } from "react-aria-components"
|
||||
} from 'react'
|
||||
import { Input as AriaInput, Label as AriaLabel } from 'react-aria-components'
|
||||
|
||||
import Label from "@/components/TempDesignSystem/Form/Label"
|
||||
import Body from "@/components/TempDesignSystem/Text/Body"
|
||||
import { Label } from '../Label'
|
||||
|
||||
import styles from "./input.module.css"
|
||||
import styles from './input.module.css'
|
||||
|
||||
import type { AriaInputWithLabelProps } from "./input"
|
||||
import type { InputProps } from './types'
|
||||
import { Typography } from '../Typography'
|
||||
|
||||
const AriaInputWithLabel = forwardRef(function AriaInputWithLabelComponent(
|
||||
{ label, ...props }: AriaInputWithLabelProps,
|
||||
export const Input = forwardRef(function AriaInputWithLabelComponent(
|
||||
{ label, ...props }: InputProps,
|
||||
forwardedRef: ForwardedRef<HTMLInputElement>
|
||||
) {
|
||||
const ref = useRef<HTMLInputElement>(null)
|
||||
@@ -31,17 +31,16 @@ const AriaInputWithLabel = forwardRef(function AriaInputWithLabelComponent(
|
||||
|
||||
return (
|
||||
<AriaLabel className={styles.container}>
|
||||
<Body asChild fontOnly>
|
||||
<Typography variant="Body/Paragraph/mdRegular">
|
||||
<AriaInput
|
||||
{...props}
|
||||
placeholder={props.placeholder}
|
||||
className={cx(styles.input, props.className)}
|
||||
ref={ref}
|
||||
id={inputId}
|
||||
/>
|
||||
</Body>
|
||||
</Typography>
|
||||
<Label required={props.required}>{label}</Label>
|
||||
</AriaLabel>
|
||||
)
|
||||
})
|
||||
|
||||
export default AriaInputWithLabel
|
||||
1
packages/design-system/lib/components/Input/index.ts
Normal file
1
packages/design-system/lib/components/Input/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { Input } from './Input'
|
||||
60
packages/design-system/lib/components/Input/input.module.css
Normal file
60
packages/design-system/lib/components/Input/input.module.css
Normal file
@@ -0,0 +1,60 @@
|
||||
.container {
|
||||
align-content: center;
|
||||
background-color: var(--Surface-Primary-Default);
|
||||
border: 1px solid var(--Border-Interactive-Default);
|
||||
border-radius: var(--Corner-radius-md);
|
||||
display: grid;
|
||||
min-width: 0; /* allow shrinkage */
|
||||
height: 60px;
|
||||
padding: var(--Space-x1) var(--Space-x2);
|
||||
box-sizing: border-box;
|
||||
cursor: text;
|
||||
|
||||
&:has(.input:focus) {
|
||||
outline-offset: -2px;
|
||||
outline: 2px solid var(--Border-Interactive-Focus);
|
||||
}
|
||||
|
||||
&:has(.input:disabled) {
|
||||
background-color: var(--Surface-Primary-Disabled);
|
||||
border: transparent;
|
||||
cursor: unset;
|
||||
}
|
||||
|
||||
&:has(.input[data-invalid='true'], .input[aria-invalid='true']) {
|
||||
border-color: var(--Border-Interactive-Error);
|
||||
|
||||
&:focus-within {
|
||||
outline-offset: -2px;
|
||||
outline: 2px solid var(--Border-Interactive-Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.input {
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--Text-Default);
|
||||
height: 1px;
|
||||
order: 2;
|
||||
padding: 0;
|
||||
transition: height 150ms ease;
|
||||
|
||||
&:focus,
|
||||
&:placeholder-shown,
|
||||
&[value]:not([value='']) {
|
||||
height: 18px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
color: var(--Text-Interactive-Disabled);
|
||||
}
|
||||
}
|
||||
|
||||
@media (hover: hover) {
|
||||
.input:active:not(:disabled) {
|
||||
height: 18px;
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
6
packages/design-system/lib/components/Input/types.ts
Normal file
6
packages/design-system/lib/components/Input/types.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { ComponentProps } from 'react'
|
||||
import { Input } from 'react-aria-components'
|
||||
|
||||
export interface InputProps extends ComponentProps<typeof Input> {
|
||||
label: string
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react'
|
||||
|
||||
import { Label } from './Label'
|
||||
|
||||
const meta: Meta<typeof Label> = {
|
||||
title: 'Components/Label',
|
||||
component: Label,
|
||||
argTypes: {},
|
||||
}
|
||||
|
||||
export default meta
|
||||
|
||||
type Story = StoryObj<typeof Label>
|
||||
|
||||
export const Default: Story = {
|
||||
args: {
|
||||
children: 'Label',
|
||||
required: false,
|
||||
},
|
||||
}
|
||||
|
||||
export const Discreet: Story = {
|
||||
args: {
|
||||
children: 'Label',
|
||||
size: 'discreet',
|
||||
},
|
||||
}
|
||||
|
||||
export const Small: Story = {
|
||||
args: {
|
||||
children: 'Label',
|
||||
size: 'small',
|
||||
},
|
||||
}
|
||||
13
packages/design-system/lib/components/Label/Label.tsx
Normal file
13
packages/design-system/lib/components/Label/Label.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { labelVariants } from './variants'
|
||||
|
||||
import type { LabelProps } from './types'
|
||||
|
||||
export function Label({ children, className, required, size }: LabelProps) {
|
||||
const classNames = labelVariants({
|
||||
className,
|
||||
size,
|
||||
required,
|
||||
})
|
||||
|
||||
return <span className={classNames}>{children}</span>
|
||||
}
|
||||
1
packages/design-system/lib/components/Label/index.ts
Normal file
1
packages/design-system/lib/components/Label/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { Label } from './Label'
|
||||
51
packages/design-system/lib/components/Label/label.module.css
Normal file
51
packages/design-system/lib/components/Label/label.module.css
Normal file
@@ -0,0 +1,51 @@
|
||||
.label {
|
||||
composes: Body-Paragraph-mdRegular from '../Typography/typography.module.css';
|
||||
transition: font-size 100ms ease;
|
||||
text-align: left;
|
||||
color: var(--Text-Interactive-Placeholder);
|
||||
user-select: none;
|
||||
|
||||
&.small {
|
||||
display: block;
|
||||
font-size: 12px;
|
||||
}
|
||||
&.regular {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
.discreet {
|
||||
composes: Body-Supporting-text-caption-smBold from '../Typography/typography.module.css';
|
||||
color: var(--Text-Default);
|
||||
order: unset;
|
||||
}
|
||||
|
||||
.required:after {
|
||||
content: ' *';
|
||||
}
|
||||
|
||||
input:focus,
|
||||
input:placeholder-shown,
|
||||
input[value]:not([value='']),
|
||||
textarea:focus,
|
||||
textarea:placeholder-shown,
|
||||
textarea[value]:not([value='']) {
|
||||
& ~ .label {
|
||||
font-size: 12px;
|
||||
margin-bottom: var(--Space-x05);
|
||||
}
|
||||
}
|
||||
|
||||
input:disabled,
|
||||
textarea:disabled {
|
||||
& ~ .label {
|
||||
color: var(--Text-Interactive-Disabled);
|
||||
}
|
||||
}
|
||||
|
||||
@media (hover: hover) {
|
||||
input:active:not(:disabled) ~ .label {
|
||||
font-size: 12px;
|
||||
margin-bottom: var(--Space-x05);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { VariantProps } from "class-variance-authority"
|
||||
import type { VariantProps } from 'class-variance-authority'
|
||||
|
||||
import type { labelVariants } from "./variants"
|
||||
import type { labelVariants } from './variants'
|
||||
|
||||
export interface LabelProps
|
||||
extends React.PropsWithChildren<React.HTMLAttributes<HTMLSpanElement>>,
|
||||
@@ -1,6 +1,6 @@
|
||||
import { cva } from "class-variance-authority"
|
||||
import { cva } from 'class-variance-authority'
|
||||
|
||||
import styles from "./label.module.css"
|
||||
import styles from './label.module.css'
|
||||
|
||||
export const labelVariants = cva(styles.label, {
|
||||
variants: {
|
||||
@@ -11,11 +11,10 @@ export const labelVariants = cva(styles.label, {
|
||||
},
|
||||
required: {
|
||||
true: styles.required,
|
||||
false: "",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
size: "regular",
|
||||
size: 'regular',
|
||||
required: false,
|
||||
},
|
||||
})
|
||||
@@ -10,6 +10,8 @@
|
||||
"./ChipLink": "./dist/components/ChipLink/index.js",
|
||||
"./Chips": "./dist/components/Chips/index.js",
|
||||
"./Divider": "./dist/components/Divider/index.js",
|
||||
"./Input": "./dist/components/Input/index.js",
|
||||
"./Label": "./dist/components/Label/index.js",
|
||||
"./Select": "./dist/components/Select/index.js",
|
||||
"./Typography": "./dist/components/Typography/index.js",
|
||||
"./RegularRateCard": "./dist/components/RateCard/Regular/index.js",
|
||||
|
||||
Reference in New Issue
Block a user