Merged in monorepo-step-1 (pull request #1080)
Migrate to a monorepo setup - step 1 * Move web to subfolder /apps/scandic-web * Yarn + transitive deps - Move to yarn - design-system package removed for now since yarn doesn't support the parameter for token (ie project currently broken) - Add missing transitive dependencies as Yarn otherwise prevents these imports - VS Code doesn't pick up TS path aliases unless you open /apps/scandic-web instead of root (will be fixed with monorepo) * Pin framer-motion to temporarily fix typing issue https://github.com/adobe/react-spectrum/issues/7494 * Pin zod to avoid typ error There seems to have been a breaking change in the types returned by zod where error is now returned as undefined instead of missing in the type. We should just handle this but to avoid merge conflicts just pin the dependency for now. * Pin react-intl version Pin version of react-intl to avoid tiny type issue where formatMessage does not accept a generic any more. This will be fixed in a future commit, but to avoid merge conflicts just pin for now. * Pin typescript version Temporarily pin version as newer versions as stricter and results in a type error. Will be fixed in future commit after merge. * Setup workspaces * Add design-system as a monorepo package * Remove unused env var DESIGN_SYSTEM_ACCESS_TOKEN * Fix husky for monorepo setup * Update netlify.toml * Add lint script to root package.json * Add stub readme * Fix react-intl formatMessage types * Test netlify.toml in root * Remove root toml * Update netlify.toml publish path * Remove package-lock.json * Update build for branch/preview builds Approved-by: Linus Flood
This commit is contained in:
committed by
Linus Flood
parent
667cab6fb6
commit
80100e7631
@@ -0,0 +1,7 @@
|
||||
import Card from "./_Card"
|
||||
|
||||
import type { RadioProps } from "./_Card/card"
|
||||
|
||||
export default function RadioCard(props: RadioProps) {
|
||||
return <Card {...props} type="radio" />
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
.label {
|
||||
background-color: var(--Base-Surface-Primary-light-Normal);
|
||||
border: 1px solid var(--Base-Border-Subtle);
|
||||
border-radius: var(--Corner-radius-Large);
|
||||
cursor: pointer;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto;
|
||||
padding: var(--Spacing-x-one-and-half) var(--Spacing-x2);
|
||||
transition: all 200ms ease;
|
||||
width: min(100%, 600px);
|
||||
grid-column-gap: var(--Spacing-x2);
|
||||
}
|
||||
|
||||
.label:hover {
|
||||
background-color: var(--Base-Surface-Secondary-light-Hover);
|
||||
}
|
||||
|
||||
.label:has(:checked) {
|
||||
background-color: var(--Primary-Light-Surface-Normal);
|
||||
border-color: var(--Base-Border-Hover);
|
||||
}
|
||||
|
||||
.icon {
|
||||
align-self: center;
|
||||
grid-column: 2/3;
|
||||
grid-row: 1/3;
|
||||
justify-self: flex-end;
|
||||
transition: fill 200ms ease;
|
||||
}
|
||||
|
||||
.label:hover .icon,
|
||||
.label:hover .icon *,
|
||||
.label:has(:checked) .icon,
|
||||
.label:has(:checked) .icon * {
|
||||
fill: var(--Base-Text-Medium-contrast);
|
||||
}
|
||||
|
||||
.label[data-declined="true"]:hover .icon,
|
||||
.label[data-declined="true"]:hover .icon *,
|
||||
.label[data-declined="true"]:has(:checked) .icon,
|
||||
.label[data-declined="true"]:has(:checked) .icon * {
|
||||
fill: var(--Base-Text-Disabled);
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
grid-column: 1 / 2;
|
||||
grid-row: 2;
|
||||
}
|
||||
|
||||
.title {
|
||||
grid-column: 1 / 2;
|
||||
}
|
||||
|
||||
.label .text {
|
||||
margin-top: var(--Spacing-x1);
|
||||
grid-column: 1/-1;
|
||||
}
|
||||
|
||||
.listItem {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
gap: var(--Spacing-x-quarter);
|
||||
grid-column: 1/-1;
|
||||
}
|
||||
|
||||
.listItem:first-of-type {
|
||||
margin-top: var(--Spacing-x1);
|
||||
}
|
||||
|
||||
.listItem:nth-of-type(n + 2) {
|
||||
margin-top: var(--Spacing-x-quarter);
|
||||
}
|
||||
|
||||
.highlight {
|
||||
color: var(--Scandic-Brand-Scandic-Red);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import type { IconProps } from "@/types/components/icon"
|
||||
|
||||
interface BaseCardProps
|
||||
extends Omit<React.LabelHTMLAttributes<HTMLLabelElement>, "title"> {
|
||||
Icon?: (props: IconProps) => JSX.Element
|
||||
declined?: boolean
|
||||
highlightSubtitle?: boolean
|
||||
iconHeight?: number
|
||||
iconWidth?: number
|
||||
name: string
|
||||
subtitle?: React.ReactNode
|
||||
title: React.ReactNode
|
||||
type: "checkbox" | "radio"
|
||||
value?: string
|
||||
}
|
||||
|
||||
interface ListCardProps extends BaseCardProps {
|
||||
list: {
|
||||
title: string
|
||||
}[]
|
||||
text?: never
|
||||
}
|
||||
|
||||
interface TextCardProps extends BaseCardProps {
|
||||
list?: never
|
||||
text: React.ReactNode
|
||||
}
|
||||
|
||||
interface CleanCardProps extends BaseCardProps {
|
||||
list?: never
|
||||
text?: never
|
||||
}
|
||||
|
||||
export type CardProps = ListCardProps | TextCardProps | CleanCardProps
|
||||
|
||||
export type CheckboxProps =
|
||||
| Omit<ListCardProps, "type">
|
||||
| Omit<TextCardProps, "type">
|
||||
export type RadioProps =
|
||||
| Omit<ListCardProps, "type">
|
||||
| Omit<TextCardProps, "type">
|
||||
| Omit<CleanCardProps, "type">
|
||||
|
||||
export interface ListProps extends Pick<ListCardProps, "declined"> {
|
||||
list?: ListCardProps["list"]
|
||||
}
|
||||
|
||||
export interface SubtitleProps
|
||||
extends Pick<BaseCardProps, "highlightSubtitle" | "subtitle"> {}
|
||||
|
||||
export interface TextProps extends Pick<TextCardProps, "text"> {}
|
||||
@@ -0,0 +1,115 @@
|
||||
"use client"
|
||||
|
||||
import { useFormContext } from "react-hook-form"
|
||||
|
||||
import { CheckIcon, CloseIcon } from "@/components/Icons"
|
||||
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
||||
import Footnote from "@/components/TempDesignSystem/Text/Footnote"
|
||||
|
||||
import styles from "./card.module.css"
|
||||
|
||||
import type { CardProps, ListProps, SubtitleProps, TextProps } from "./card"
|
||||
|
||||
export default function Card({
|
||||
Icon,
|
||||
iconHeight = 32,
|
||||
iconWidth = 32,
|
||||
declined = false,
|
||||
highlightSubtitle = false,
|
||||
id,
|
||||
list,
|
||||
name,
|
||||
subtitle,
|
||||
text,
|
||||
title,
|
||||
type,
|
||||
value,
|
||||
}: CardProps) {
|
||||
const { register, setValue } = useFormContext()
|
||||
|
||||
function onLabelClick(event: React.MouseEvent) {
|
||||
// Preventing click event on label elements firing twice: https://github.com/facebook/react/issues/14295
|
||||
event.preventDefault()
|
||||
setValue(name, value)
|
||||
}
|
||||
return (
|
||||
<label
|
||||
className={styles.label}
|
||||
data-declined={declined}
|
||||
onClick={onLabelClick}
|
||||
tabIndex={0}
|
||||
>
|
||||
<Caption className={styles.title} color="burgundy" type="label" uppercase>
|
||||
{title}
|
||||
</Caption>
|
||||
<Subtitle highlightSubtitle={highlightSubtitle} subtitle={subtitle} />
|
||||
{Icon ? (
|
||||
<Icon
|
||||
className={styles.icon}
|
||||
color="uiTextHighContrast"
|
||||
height={iconHeight}
|
||||
width={iconWidth}
|
||||
/>
|
||||
) : null}
|
||||
<List declined={declined} list={list} />
|
||||
<Text text={text} />
|
||||
<input
|
||||
{...register(name)}
|
||||
aria-hidden
|
||||
id={id || name}
|
||||
hidden
|
||||
type={type}
|
||||
value={value}
|
||||
/>
|
||||
</label>
|
||||
)
|
||||
}
|
||||
|
||||
function List({ declined, list }: ListProps) {
|
||||
if (!list) {
|
||||
return null
|
||||
}
|
||||
|
||||
return list.map((listItem) => (
|
||||
<span key={listItem.title} className={styles.listItem}>
|
||||
{declined ? (
|
||||
<CloseIcon color="uiTextMediumContrast" height={20} width={20} />
|
||||
) : (
|
||||
<CheckIcon color="baseIconLowContrast" height={20} width={20} />
|
||||
)}
|
||||
<Footnote color="uiTextMediumContrast">{listItem.title}</Footnote>
|
||||
</span>
|
||||
))
|
||||
}
|
||||
|
||||
function Subtitle({ highlightSubtitle, subtitle }: SubtitleProps) {
|
||||
if (!subtitle) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<Caption
|
||||
className={styles.subtitle}
|
||||
color={highlightSubtitle ? "baseTextAccent" : "uiTextMediumContrast"}
|
||||
type="label"
|
||||
uppercase
|
||||
>
|
||||
{subtitle}
|
||||
</Caption>
|
||||
)
|
||||
}
|
||||
|
||||
function Text({ text }: TextProps) {
|
||||
if (!text) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<Footnote className={styles.text} color="uiTextMediumContrast">
|
||||
{text}
|
||||
</Footnote>
|
||||
)
|
||||
}
|
||||
|
||||
export function Highlight({ children }: React.PropsWithChildren) {
|
||||
return <span className={styles.highlight}>{children}</span>
|
||||
}
|
||||
Reference in New Issue
Block a user