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
10 changes: 10 additions & 0 deletions packages/app-elements/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ const en = {
not_authorized: "Not authorized",
not_authorized_description: "You are not authorized to access this page.",
not_handled: "Not handled",
pagination_range: "{{first}}-{{last}} of {{total}}",
previous_page: "Previous page",
next_page: "Next page",
parcel_total: "Total",
parcel_weight: "Weight",
parcel_item: "{{count}} item",
Expand Down Expand Up @@ -461,6 +464,13 @@ const en = {
title: "Resource details",
attributes: "Attributes",
events: "Events",
relationships: "Relationships",
no_relationships: "This resource has no relationships.",
has_one: "Has one",
has_many: "Has many",
no_records: "No records.",
relationship_error: "Could not load these records.",
view_record: "View {{id}}",
json: "Json",
no_events: "No events found for this resource.",
unknown_event: "Unknown event",
Expand Down
10 changes: 10 additions & 0 deletions packages/app-elements/src/locales/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ const it: typeof en = {
not_authorized_description:
"Non sei autorizzato ad accedere a questa pagina.",
not_handled: "Non gestito",
pagination_range: "{{first}}-{{last}} di {{total}}",
previous_page: "Pagina precedente",
next_page: "Pagina successiva",
parcel_total: "Totale",
parcel_weight: "Peso",
parcel_item: "{{count}} prodotto",
Expand Down Expand Up @@ -238,6 +241,13 @@ const it: typeof en = {
title: "Dettagli risorsa",
attributes: "Attributi",
events: "Eventi",
relationships: "Relazioni",
no_relationships: "Questa risorsa non ha relazioni.",
has_one: "Singola",
has_many: "Multipla",
no_records: "Nessun record.",
relationship_error: "Impossibile caricare questi record.",
view_record: "Visualizza {{id}}",
json: "Json",
no_events: "Nessun evento trovato per questa risorsa.",
unknown_event: "Evento sconosciuto",
Expand Down
1 change: 1 addition & 0 deletions packages/app-elements/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ export {
ResourceDetailsTimelineItem,
type ResourceDetailsTimelineItemProps,
type ResourceDetailsTimelineProps,
type ResourceRelationshipsConfig,
type UseResourceDetailsModalProps,
type UseResourceDetailsModalReturn,
useResourceDetailsModal,
Expand Down
2 changes: 1 addition & 1 deletion packages/app-elements/src/ui/atoms/Tabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe("Tabs size", () => {
)

const active = getByRole("tab", { name: "Colors" })
expect(active).toHaveClass("text-xs", "font-semibold")
expect(active).toHaveClass("text-xs", "leading-5", "font-semibold")
expect(active.querySelector("span")).toHaveClass("border-b-transparent")
expect(getByRole("tablist")).toHaveClass("gap-4")
})
Expand Down
4 changes: 3 additions & 1 deletion packages/app-elements/src/ui/atoms/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,13 @@ function TabNav({
// room around the label for a rounded focus ring, cancelled out by the
// negative margin so the tabs keep their spacing
className={cn(
"focus-ring-inline text-center leading-6 cursor-pointer -mb-[2px]",
"focus-ring-inline text-center cursor-pointer -mb-[2px]",
// never break a two-word label ("In progress") onto a second line, and never
// let the row squeeze it: the row scrolls instead
"whitespace-nowrap shrink-0",
{
"leading-6": size === "regular",
"leading-5": size === "small",
"text-black font-semibold": isActive,
"text-gray-500": !isActive,
"text-xs": size === "small",
Expand Down
20 changes: 20 additions & 0 deletions packages/app-elements/src/ui/composite/Modal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ describe("Modal", () => {
expect(fireEvent.keyDown(closeButton, { key: " " })).toBe(true)
})

test("Should keep a fixed height only when given one", () => {
const { getByTestId, rerender } = render(
<Modal show onClose={vi.fn()}>
<Modal.Body>Short</Modal.Body>
</Modal>,
)
expect(
(getByTestId("modal").firstElementChild as HTMLElement).style.height,
).toBe("")

rerender(
<Modal show onClose={vi.fn()} height="500px">
<Modal.Body>Short</Modal.Body>
</Modal>,
)
expect(
(getByTestId("modal").firstElementChild as HTMLElement).style.height,
).toBe("500px")
})

test("Should move focus to the modal panel on open, not to the close button", () => {
const { closeButton, getByTestId } = setup()

Expand Down
39 changes: 33 additions & 6 deletions packages/app-elements/src/ui/composite/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ export type ModalProps = {
children: React.ReactNode
/** Max width preset */
size?: "large" | "medium" | "small" | "x-small"
/**
* Fixed height of the modal, as any CSS length (e.g. `clamp(480px, 70vh, 760px)`),
* with the body scrolling inside it. For content that changes while the modal
* is open, such as tabs or expandable rows, so the modal does not resize along
* with it. The modal never grows past its maximum height, `min(90vh, 800px)`.
*/
height?: string
/**
* Enables modal dismissal via backdrop click and Escape key.
*
Expand Down Expand Up @@ -76,7 +83,16 @@ type ModalComponent = React.ForwardRefExoticComponent<
ModalProps & React.RefAttributes<HTMLDivElement>
> & {
Header: React.FC<React.PropsWithChildren>
Body: React.FC<React.PropsWithChildren>
Body: React.FC<
React.PropsWithChildren<{
/**
* Drops the body's padding, for content that lays out its own: a row
* running from edge to edge, or one that sticks to the top while the
* body scrolls.
*/
flush?: boolean
}>
>
Footer: React.FC<React.PropsWithChildren>
}

Expand All @@ -88,6 +104,7 @@ const ModalRoot = (
onClose,
size = "small",
dismissible = false,
height,
onSubmit,
dialogRef: forwardedDialogRef,
}: ModalProps,
Expand Down Expand Up @@ -160,7 +177,7 @@ const ModalRoot = (
)

const contentClassName = cn(
"bg-white rounded-md shadow-xl",
"bg-white rounded shadow-xl",
"max-h-[min(90vh,800px)] flex flex-col",
)

Expand All @@ -170,11 +187,17 @@ const ModalRoot = (
<OverlayContext.Provider value={{ surface: "modal" }}>
<DialogPortalContext.Provider value={dialogElement}>
{onSubmit != null ? (
<form className={contentClassName} onSubmit={onSubmit}>
<form
className={contentClassName}
style={{ height }}
onSubmit={onSubmit}
>
{children}
</form>
) : (
<div className={contentClassName}>{children}</div>
<div className={contentClassName} style={{ height }}>
{children}
</div>
)}
</DialogPortalContext.Provider>
</OverlayContext.Provider>
Expand Down Expand Up @@ -294,8 +317,12 @@ Modal.Header = ({ children }) => {
)
}

Modal.Body = ({ children }) => {
return <div className="p-6 overflow-y-auto flex-1 min-h-0">{children}</div>
Modal.Body = ({ children, flush = false }) => {
return (
<div className={cn("overflow-y-auto flex-1 min-h-0", { "p-6": !flush })}>
{children}
</div>
)
}

Modal.Footer = ({ children }) => {
Expand Down
Loading
Loading