Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 43 additions & 34 deletions ui/README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@unitae/ui",
"version": "0.10.0",
"description": "Unitae UI components: stat tiles, chart kit (with table twins), status, avatars, selection bar, segmented control, form sections, save bar, panels, section headings, map pieces and the brand mark. Built on @unitae/tokens.",
"version": "0.11.0",
"description": "Unitae UI components: stat tiles, chart kit (with table twins), status, avatars, selection bar, segmented control, form sections, save bar, panels, section headings, map pieces, the app shell pieces (sidebar, top bar, title row, quick views, filters, pagination, empty and error states, sign-in frame) and the brand mark. Built on @unitae/tokens.",
"license": "MIT",
"type": "module",
"repository": {
Expand Down
53 changes: 53 additions & 0 deletions ui/src/auth-frame.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { ReactNode } from 'react'
import { cn } from './utils.ts'

export interface AuthFrameProps {
/** Opens the column: a monogram, the `Lockup`, or a quiet icon tile on a page that reports rather than asks. */
emblem?: ReactNode
/** A line above the title, e.g. the congregation's name or « Erreur 404 ». */
eyebrow?: ReactNode
/** The page's action, e.g. « Se connecter ». */
title: ReactNode
/** What the page says under its title. */
description?: ReactNode
/** A slightly wider column, for a page that is mostly reading. */
wide?: boolean
/** Closes the page: the mark, the privacy link, a language switch. */
footer?: ReactNode
children?: ReactNode
className?: string
}

/**
* The frame of every page outside an app's shell — signing in, a link sent, a payment, an error the app could not
* frame: the bare page, one narrow column in the middle, no card.
*/
export function AuthFrame({
emblem,
eyebrow,
title,
description,
wide = false,
footer,
children,
className,
}: AuthFrameProps) {
return (
<div className={cn('flex min-h-svh flex-col items-center bg-background px-4', className)}>
<main className="flex w-full flex-1 items-center justify-center py-16">
<div className={cn('flex w-full max-w-[22.5rem] flex-col gap-5', wide && 'max-w-[25rem]')}>
<div className="flex flex-col items-start gap-3.5">
{emblem}
<div className="flex flex-col gap-1">
{eyebrow != null && <p className="m-0 text-faint text-sm">{eyebrow}</p>}
<h1 className="m-0 text-h1">{title}</h1>
</div>
{description != null && <p className="m-0 text-muted-foreground text-sm leading-relaxed">{description}</p>}
</div>
{children}
</div>
</main>
{footer != null && <footer className="flex items-center gap-4 py-6 text-faint text-xs">{footer}</footer>}
</div>
)
}
31 changes: 31 additions & 0 deletions ui/src/empty-state.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { ReactNode } from 'react'
import { cn } from './utils.ts'

export interface EmptyStateProps {
/** A quiet icon in a neutral tile; no illustration. */
icon?: ReactNode
/** One plain sentence. */
title: ReactNode
description?: ReactNode
/** When the reader can act: the action, usually one button. */
action?: ReactNode
className?: string
}

/** What a list or a page shows with nothing in it: one plain sentence and, when the reader can act, the action. */
export function EmptyState({ icon, title, description, action, className }: EmptyStateProps) {
return (
<div className={cn('flex flex-col items-center justify-center gap-3 py-8 text-center sm:py-16', className)}>
{icon != null && (
<div className="flex size-12 items-center justify-center rounded-lg bg-muted text-muted-foreground ring-1 ring-border/60 [&>svg]:size-6">
{icon}
</div>
)}
<div className="flex flex-col gap-1">
<p className="m-0 font-medium text-foreground text-sm">{title}</p>
{description != null && <p className="m-0 max-w-sm text-muted-foreground text-sm">{description}</p>}
</div>
{action != null && <div className="mt-2">{action}</div>}
</div>
)
}
37 changes: 37 additions & 0 deletions ui/src/error-state.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { ReactNode } from 'react'
import { cn } from './utils.ts'

export interface ErrorStateProps {
/** A quiet icon in a neutral tile, e.g. a magnifier for « introuvable ». */
icon?: ReactNode
/** Above the title, e.g. « Erreur 404 ». */
code?: ReactNode
title: ReactNode
/** What happened and what to do, in plain words. */
description?: ReactNode
/** The ways on: one filled button (a retry, or the most useful way back), the others quieter. */
actions?: ReactNode
/** Below the actions, e.g. the technical details of a server error in a `<details>`. */
details?: ReactNode
className?: string
}

/** An error drawn where the page would have been, so the shell around it stays and the way back is one click. */
export function ErrorState({ icon, code, title, description, actions, details, className }: ErrorStateProps) {
return (
<div className={cn('flex w-full max-w-[25rem] flex-col gap-4.5', className)}>
{icon != null && (
<span className="grid size-10 place-content-center rounded-md border border-border bg-sidebar text-faint [&>svg]:size-5">
{icon}
</span>
)}
<div className="flex flex-col gap-1">
{code != null && <p className="m-0 text-faint text-sm tabular-nums">{code}</p>}
<h1 className="m-0 text-h1">{title}</h1>
</div>
{description != null && <p className="m-0 text-muted-foreground text-sm leading-relaxed">{description}</p>}
{actions != null && <div className="flex flex-wrap gap-2">{actions}</div>}
{details}
</div>
)
}
153 changes: 153 additions & 0 deletions ui/src/filters.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import type { ComponentProps, ReactNode } from 'react'
import { cn } from './utils.ts'

export interface FilterButtonProps extends Omit<ComponentProps<'button'>, 'children'> {
/** The button's text, e.g. « Filtres ». */
label: string
/** How many filters are on; nothing shows at 0. */
count?: number
/** The accessible name while filters are on, e.g. « Filtres, 2 actifs ». */
activeLabel?: string
}

/**
* The one « Filtres » button of a list's toolbar, saying how many filters are on. The popover it opens is the app's
* (it passes the trigger props through, refs included, so a Radix `asChild` trigger works).
*/
export function FilterButton({
label,
count = 0,
activeLabel,
className,
type = 'button',
...props
}: FilterButtonProps) {
return (
<button
type={type}
aria-label={count > 0 && activeLabel ? activeLabel : undefined}
className={cn(
'inline-flex h-(--u-control-height,2.25rem) items-center gap-2 rounded-md border border-input bg-surface px-3 font-medium text-foreground text-sm outline-none transition-colors duration-(--u-duration-fast) hover:bg-hover focus-visible:ring-2 focus-visible:ring-ring',
className,
)}
{...props}
>
<svg viewBox="0 0 16 16" width={16} height={16} aria-hidden="true" className="text-muted-foreground">
<path
d="M2.5 4h11M4.5 8h7M6.5 12h3"
fill="none"
stroke="currentColor"
strokeWidth={1.5}
strokeLinecap="round"
/>
</svg>
{label}
{count > 0 && (
<span className="inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-foreground px-1.5 text-background text-xs tabular-nums">
{count}
</span>
)}
</button>
)
}

export interface FilterChipItem {
/** Identifies the chip, e.g. the query parameter its × clears. */
key: string
/** The filter's name, e.g. « Groupe ». */
label: string
/** What it is set to, e.g. « Nord ». */
value: string
/** Where its × leads (the address without this filter), rendered through `renderLink`; else `onRemove`. */
removeHref?: string
onRemove?: () => void
}

export interface FilterChipLinkProps {
href: string
className: string
'aria-label'?: string
children: ReactNode
}

export interface FilterChipBarProps {
chips: FilterChipItem[]
/** Names the region for screen readers, e.g. « Filtres actifs ». */
'aria-label': string
/** The × button's accessible name for a chip, e.g. `c => \`Retirer ${c.label} : ${c.value}\``. */
removeLabel: (chip: FilterChipItem) => string
/** The text of the link that clears them all, e.g. « Effacer les filtres ». */
clearLabel: string
clearHref?: string
onClear?: () => void
/** Renders a link with the app's router link. */
renderLink?: (props: FilterChipLinkProps) => ReactNode
className?: string
}

const removeClass =
'inline-flex size-6 items-center justify-center rounded-full text-muted-foreground outline-none transition-colors duration-(--u-duration-fast) hover:bg-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring'
const clearClass = 'text-sm text-brand-text underline-offset-4 hover:underline'

function Cross() {
return (
<svg viewBox="0 0 16 16" width={14} height={14} aria-hidden="true">
<path d="M4 4l8 8M12 4l-8 8" fill="none" stroke="currentColor" strokeWidth={1.5} strokeLinecap="round" />
</svg>
)
}

/**
* The active filters under a list's toolbar, one chip each (« Groupe : Nord »), and the link that clears them all.
* Only a chip's × removes its filter, so a click on the label never drops one by mistake. Nothing shows without one.
*/
export function FilterChipBar({
chips,
removeLabel,
clearLabel,
clearHref,
onClear,
renderLink,
className,
...rest
}: FilterChipBarProps) {
if (chips.length === 0) return null
const link = (props: FilterChipLinkProps) => (renderLink ? renderLink(props) : <a {...props} />)
return (
<section
aria-label={rest['aria-label']}
aria-live="polite"
className={cn('flex flex-wrap items-center gap-1.5', className)}
>
{chips.map((chip) => (
<span
key={chip.key}
title={`${chip.label} : ${chip.value}`}
className="inline-flex h-7 items-center gap-1 rounded-full border border-border bg-card pr-0.5 pl-2.5 text-sm"
>
<span className="text-muted-foreground">{chip.label} :</span>
<span className="block max-w-[16ch] truncate sm:max-w-[24ch]">{chip.value}</span>
{chip.removeHref != null ? (
link({
href: chip.removeHref,
className: removeClass,
'aria-label': removeLabel(chip),
children: <Cross />,
})
) : (
<button type="button" onClick={chip.onRemove} aria-label={removeLabel(chip)} className={removeClass}>
<Cross />
</button>
)}
</span>
))}
{clearHref != null ? (
link({ href: clearHref, className: clearClass, children: clearLabel })
) : (
<button type="button" onClick={onClear} className={cn(clearClass, 'border-0 bg-transparent p-0')}>
{clearLabel}
</button>
)}
</section>
)
}
31 changes: 31 additions & 0 deletions ui/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { AuthFrame, type AuthFrameProps } from './auth-frame.tsx'
export { Avatar, type AvatarProps, initials } from './avatar.tsx'
export {
BarList,
Expand Down Expand Up @@ -29,7 +30,17 @@ export {
} from './charts.tsx'
export { DateChip, type DateChipProps } from './date-chip.tsx'
export { DateField, type DateFieldLabels, type DateFieldProps } from './date-field.tsx'
export { EmptyState, type EmptyStateProps } from './empty-state.tsx'
export { ErrorState, type ErrorStateProps } from './error-state.tsx'
export { type Fact, FactList, type FactListProps } from './fact-list.tsx'
export {
FilterButton,
type FilterButtonProps,
FilterChipBar,
type FilterChipBarProps,
type FilterChipItem,
type FilterChipLinkProps,
} from './filters.tsx'
export { FormSection, type FormSectionProps } from './form-section.tsx'
export {
MapAttribution,
Expand All @@ -54,6 +65,8 @@ export {
type MapStatusProps,
} from './map.tsx'
export { Lockup, type LockupProps, Mark, type MarkProps } from './mark.tsx'
export { PageTitle, type PageTitleProps } from './page-title.tsx'
export { PaginationBar, type PaginationBarProps } from './pagination-bar.tsx'
export { Panel, type PanelProps } from './panel.tsx'
export {
type PeriodLinkProps,
Expand All @@ -63,11 +76,21 @@ export {
} from './period-stepper.tsx'
export { ProgressBar, type ProgressBarProps, type ProgressTone } from './progress-bar.tsx'
export { ProgressRing, type ProgressRingProps } from './progress-ring.tsx'
export { type QuickView, QuickViews, type QuickViewsProps } from './quick-views.tsx'
export { SaveBar, type SaveBarProps } from './save-bar.tsx'
export { SectionHeading, type SectionHeadingProps } from './section-heading.tsx'
export { SegmentedControl, type SegmentedControlProps, type SegmentedOption } from './segmented-control.tsx'
export { SelectionBar, type SelectionBarProps } from './selection-bar.tsx'
export { SidePanel, type SidePanelProps, type SidePanelWalk } from './side-panel.tsx'
export {
NavGroup,
type NavGroupProps,
NavItem,
type NavItemProps,
type NavLinkProps,
SidebarFrame,
type SidebarFrameProps,
} from './sidebar-nav.tsx'
export {
MetricStrip,
type MetricStripProps,
Expand All @@ -79,4 +102,12 @@ export {
type StatTone,
} from './stat-tile.tsx'
export { Kbd, Status, StatusIcon, type StatusProps, type StatusTone, Tag, type TagProps } from './status.tsx'
export {
Breadcrumb,
type BreadcrumbItem,
type BreadcrumbLinkProps,
type BreadcrumbProps,
TopbarRow,
type TopbarRowProps,
} from './topbar.tsx'
export { chartContext, chartMuted, chartOther, cn, seriesColor, share } from './utils.ts'
Loading
Loading