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
2 changes: 2 additions & 0 deletions ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Tell Tailwind v4 to read the classes the components use, next to the tokens impo
| `Avatar` | A person's initials in a quiet disc, next to their name (`initials(name)` is exported too) |
| `SelectionBar` | Floating actions on a list selection; announces the count, Escape clears |
| `SegmentedControl` | 2–5 exclusive choices with a sliding indicator and arrow-key navigation; `null` = no choice |
| `FactList` | Facts as label / value pairs in a `<dl>`; empty values left out, or `emptyLabel` for them |
| `DateChip` | A day as a small tile, month over day, beside a row that says the full date |
| `FormSection` | One part of a long form: title, kicker and actions left, fields right (`col-span-full`) |
| `SaveBar` | A form's save actions at the bottom, with the unsaved-changes dot and an announced label |
| `Panel` | A bordered block of a page: title and actions, rows edge to edge or `padded` fields, footer |
Expand Down
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@unitae/ui",
"version": "0.6.0",
"version": "0.7.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 and the brand mark. Built on @unitae/tokens.",
"license": "MIT",
"type": "module",
Expand Down
25 changes: 25 additions & 0 deletions ui/src/date-chip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { cn } from './utils.ts'

export interface DateChipProps {
/** The month, already formatted in the reader's language (« mars », « nov. »). Shown in capitals. */
month: string
/** The day of the month. */
day: string
className?: string
}

/** A day as a small tile, the month over the day. Decorative: the row beside it says the full date. */
export function DateChip({ month, day, className }: DateChipProps) {
return (
<span
aria-hidden="true"
className={cn(
'flex size-11 shrink-0 flex-col items-center justify-center rounded-md border border-border leading-none',
className,
)}
>
<span className="font-semibold text-[10px] text-brand-text uppercase tracking-wide">{month}</span>
<span className="mt-1 font-semibold text-base tabular-nums">{day}</span>
</span>
)
}
46 changes: 46 additions & 0 deletions ui/src/fact-list.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Fragment, type ReactNode } from 'react'
import { cn } from './utils.ts'

export interface Fact {
label: ReactNode
/** Left out, or replaced by the list's `emptyLabel`, when it is null, undefined or an empty string. */
value: ReactNode
/** A quiet line under the value: an age, a relative date, who leads the group. */
hint?: ReactNode
/** A stable key, when the label is not a unique string. */
key?: string
}

export interface FactListProps {
facts: Fact[]
/** The words for a missing value, e.g. « Non renseigné ». Without them, a fact without a value is left out. */
emptyLabel?: ReactNode
className?: string
}

function isEmpty(value: ReactNode) {
return value == null || value === '' || value === false
}

/**
* Facts about one thing as label / value pairs: a person's contact details, a group's leaders. A description list,
* labels in a column of their own width, values taking the rest and wrapping anywhere (addresses, e-mails).
*/
export function FactList({ facts, emptyLabel, className }: FactListProps) {
const shown = emptyLabel == null ? facts.filter((fact) => !isEmpty(fact.value)) : facts
if (shown.length === 0) return null

return (
<dl className={cn('m-0 grid grid-cols-[max-content_minmax(0,1fr)] gap-x-4 gap-y-2.5 text-sm', className)}>
{shown.map((fact, index) => (
<Fragment key={fact.key ?? (typeof fact.label === 'string' ? fact.label : String(index))}>
<dt className="text-faint">{fact.label}</dt>
<dd className="m-0 min-w-0 text-foreground wrap-anywhere">
{isEmpty(fact.value) ? <span className="text-faint">{emptyLabel}</span> : fact.value}
{fact.hint != null && <span className="mt-0.5 block text-faint text-xs">{fact.hint}</span>}
</dd>
</Fragment>
))}
</dl>
)
}
2 changes: 2 additions & 0 deletions ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export {
type LineChartProps,
type LineSeries,
} from './charts.tsx'
export { DateChip, type DateChipProps } from './date-chip.tsx'
export { type Fact, FactList, type FactListProps } from './fact-list.tsx'
export { FormSection, type FormSectionProps } from './form-section.tsx'
export { Lockup, type LockupProps, Mark, type MarkProps } from './mark.tsx'
export { Panel, type PanelProps } from './panel.tsx'
Expand Down
52 changes: 52 additions & 0 deletions ui/test/components.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
BarList,
ChartCard,
ColumnChart,
DateChip,
FactList,
FormSection,
LineChart,
Mark,
Expand Down Expand Up @@ -568,3 +570,53 @@ describe('stacked columns and dashed lines', () => {
expect(screen.getByRole('img', { name: "Cumul de l'année" })).toBeTruthy()
})
})

describe('FactList', () => {
it('pairs each label with its value in a description list, the hint under the value', () => {
render(
<FactList
facts={[
{ label: 'Téléphone', value: '06 12 34 56 78' },
{ label: 'Naissance', value: '14 mai 1981', hint: '45 ans' },
]}
/>,
)
const terms = screen.getAllByRole('term').map((term) => term.textContent)
const definitions = screen.getAllByRole('definition').map((definition) => definition.textContent)
expect(terms).toEqual(['Téléphone', 'Naissance'])
expect(definitions).toEqual(['06 12 34 56 78', '14 mai 198145 ans'])
expect(screen.getByText('45 ans')).toBeTruthy()
})

it('leaves out a fact without a value', () => {
render(
<FactList
facts={[
{ label: 'Téléphone', value: null },
{ label: 'Adresse', value: '' },
{ label: 'E-mail', value: 'p.fontaine@exemple.fr' },
]}
/>,
)
expect(screen.getAllByRole('term').map((term) => term.textContent)).toEqual(['E-mail'])
})

it('says a value is missing when it is given the words for it', () => {
render(<FactList emptyLabel="Non renseigné" facts={[{ label: 'Téléphone', value: undefined }]} />)
expect(screen.getByRole('definition').textContent).toBe('Non renseigné')
})

it('draws nothing when no fact is left', () => {
const { container } = render(<FactList facts={[{ label: 'Téléphone', value: null }]} />)
expect(container.querySelector('dl')).toBeNull()
})
})

describe('DateChip', () => {
it('stacks the month over the day and stays decorative, the row saying the full date', () => {
const { container } = render(<DateChip month="mars" day="19" />)
const chip = container.firstElementChild as HTMLElement
expect(chip.getAttribute('aria-hidden')).toBe('true')
expect(chip.textContent).toBe('mars19')
})
})
Loading