226 lines
7.7 KiB
TypeScript
226 lines
7.7 KiB
TypeScript
"use client";
|
|
/*
|
|
* Documentation:
|
|
* KanbanColumn — https://app.subframe.com/f023064a5ca0/library?component=KanbanColumn_bbc08458-14aa-4512-a807-e673a64315ab
|
|
*/
|
|
|
|
import React from "react";
|
|
import { FeatherChevronsLeft } from "@subframe/core";
|
|
import { FeatherChevronsRight } from "@subframe/core";
|
|
import { FeatherLock } from "@subframe/core";
|
|
import * as SubframeCore from "@subframe/core";
|
|
import * as SubframeUtils from "../../utils";
|
|
|
|
export interface KanbanColumnRootProps
|
|
extends React.HTMLAttributes<HTMLDivElement> {
|
|
collapsed?: boolean;
|
|
name?: React.ReactNode;
|
|
price?: React.ReactNode;
|
|
icon?: React.ReactNode;
|
|
badge?: React.ReactNode;
|
|
cards?: React.ReactNode;
|
|
sumMode?: "visible" | "locked" | "hidden";
|
|
lockedSumSlot?: React.ReactNode;
|
|
twoColumn?: boolean;
|
|
wrapAfter?: number;
|
|
/**
|
|
* Local adjustment: the export draws the collapsed head with `cursor-pointer`
|
|
* and a chevron but wires nothing to it, so a collapsed column could never be
|
|
* opened again. With this callback the collapsed head IS the expand control.
|
|
*/
|
|
onToggleCollapse?: () => void;
|
|
/** Accessible name of that expand control — the caller owns the copy. */
|
|
expandLabel?: string;
|
|
className?: string;
|
|
}
|
|
|
|
const KanbanColumnRoot = React.forwardRef<
|
|
HTMLDivElement,
|
|
KanbanColumnRootProps
|
|
>(function KanbanColumnRoot(
|
|
{
|
|
collapsed = false,
|
|
name,
|
|
price,
|
|
icon = <FeatherChevronsLeft />,
|
|
badge,
|
|
cards,
|
|
sumMode = "hidden",
|
|
lockedSumSlot,
|
|
twoColumn = false,
|
|
wrapAfter = 6,
|
|
onToggleCollapse,
|
|
expandLabel,
|
|
className,
|
|
...otherProps
|
|
}: KanbanColumnRootProps,
|
|
ref
|
|
) {
|
|
// Only the collapsed head is interactive: expanded, the same row holds the
|
|
// kebab menu, and a click target around it would swallow its clicks.
|
|
const expandProps =
|
|
collapsed && onToggleCollapse
|
|
? {
|
|
role: "button" as const,
|
|
tabIndex: 0,
|
|
"aria-label": expandLabel,
|
|
onClick: onToggleCollapse,
|
|
onKeyDown: (event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
if (event.key === "Enter" || event.key === " ") {
|
|
event.preventDefault();
|
|
onToggleCollapse();
|
|
}
|
|
},
|
|
}
|
|
: {};
|
|
return (
|
|
<div
|
|
className={SubframeUtils.twClassNames(
|
|
"group/bbc08458 flex w-80 flex-col items-center gap-2 rounded-md border-2 border-solid border-border-default bg-surface-neutral-tertiary px-1.5 py-1.5 shrink-0 min-w-80 self-start",
|
|
{
|
|
"w-[680px] min-w-[680px]": twoColumn,
|
|
"h-full w-12 px-0 min-w-12": collapsed,
|
|
},
|
|
className
|
|
)}
|
|
ref={ref}
|
|
{...otherProps}
|
|
>
|
|
<div
|
|
className={SubframeUtils.twClassNames(
|
|
"flex w-full flex-col items-center",
|
|
{ "grow shrink-0 basis-0 bg-surface-neutral-tertiary": collapsed }
|
|
)}
|
|
>
|
|
<div
|
|
className={SubframeUtils.twClassNames(
|
|
"flex w-full items-center justify-between px-1 pt-1.5 pb-1 gap-2",
|
|
{
|
|
"flex-col rounded-md py-3 cursor-pointer": collapsed,
|
|
"hover:bg-surface-neutral-secondary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand-200":
|
|
collapsed && Boolean(onToggleCollapse),
|
|
}
|
|
)}
|
|
{...expandProps}
|
|
>
|
|
<FeatherChevronsRight
|
|
className={SubframeUtils.twClassNames(
|
|
"hidden text-body-small-semibold-0 font-body-small-semibold-0 text-icon-neutral-tertiary",
|
|
{ "inline-flex": collapsed }
|
|
)}
|
|
/>
|
|
<div
|
|
className={SubframeUtils.twClassNames(
|
|
"hidden grow shrink-0 basis-0 flex-col items-center gap-2 self-stretch py-3",
|
|
{ flex: collapsed }
|
|
)}
|
|
>
|
|
<div className="flex h-0.5 w-full flex-none flex-col items-center gap-2 bg-border-default" />
|
|
</div>
|
|
{name ? (
|
|
<span
|
|
className={SubframeUtils.twClassNames(
|
|
"hidden break-words text-body-small-semibold-150 font-body-small-semibold-150 text-text-neutral-primary [writing-mode:vertical-rl] rotate-180",
|
|
{ inline: collapsed }
|
|
)}
|
|
>
|
|
{name}
|
|
</span>
|
|
) : null}
|
|
<div
|
|
className={SubframeUtils.twClassNames(
|
|
"flex min-w-[0px] items-center gap-2.5 grow shrink",
|
|
{ "flex-col px-1 py-1": collapsed }
|
|
)}
|
|
>
|
|
{name ? (
|
|
<span
|
|
className={SubframeUtils.twClassNames(
|
|
"min-w-[0px] break-words text-body-small-semibold-150 font-body-small-semibold-150 text-text-neutral-primary",
|
|
{ hidden: collapsed }
|
|
)}
|
|
>
|
|
{name}
|
|
</span>
|
|
) : null}
|
|
{badge ? (
|
|
<div
|
|
className={SubframeUtils.twClassNames(
|
|
"flex items-center gap-2.5 shrink-0",
|
|
{
|
|
// Local adjustment: collapsed, the count reads sideways like
|
|
// the stage name above it — horizontally it would either
|
|
// widen the 48px rail or clip.
|
|
"px-1 py-2 [writing-mode:vertical-rl] rotate-180": collapsed,
|
|
}
|
|
)}
|
|
>
|
|
{badge}
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
<div
|
|
className={SubframeUtils.twClassNames(
|
|
"flex min-w-[0px] items-center gap-2 shrink-0",
|
|
{ hidden: collapsed }
|
|
)}
|
|
>
|
|
{sumMode === "locked" && lockedSumSlot ? (
|
|
<div className="flex shrink-0 items-center gap-1">
|
|
<FeatherLock className="text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-icon-neutral-subtle" />
|
|
<span className="whitespace-nowrap text-body-extra-small-regular-150 font-body-extra-small-regular-150 text-text-neutral-subtle">
|
|
{lockedSumSlot}
|
|
</span>
|
|
</div>
|
|
) : null}
|
|
{price ? (
|
|
<span
|
|
className={SubframeUtils.twClassNames(
|
|
"hidden break-words text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary",
|
|
{ inline: sumMode === "visible" }
|
|
)}
|
|
>
|
|
{price}
|
|
</span>
|
|
) : null}
|
|
{icon ? (
|
|
<SubframeCore.IconWrapper className="text-body-small-semibold-0 font-body-small-semibold-0 text-icon-neutral-tertiary">
|
|
{icon}
|
|
</SubframeCore.IconWrapper>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div
|
|
className={SubframeUtils.twClassNames(
|
|
"flex h-0.5 w-full flex-none flex-col items-center gap-2 bg-border-default",
|
|
{ hidden: collapsed }
|
|
)}
|
|
/>
|
|
{cards ? (
|
|
<div
|
|
className={SubframeUtils.twClassNames(
|
|
"flex w-full flex-col items-center gap-3 pb-2",
|
|
{
|
|
"min-w-[0px] flex-none items-start grid grid-flow-col grid-rows-6 grid-cols-2 justify-items-stretch mobile:grid-flow-row mobile:grid-rows-none mobile:grid-cols-1":
|
|
twoColumn,
|
|
hidden: collapsed,
|
|
}
|
|
)}
|
|
// Local adjustment: honor wrapAfter instead of the fixed grid-rows-6
|
|
// from the Subframe export (inline style wins over the class).
|
|
style={
|
|
twoColumn
|
|
? { gridTemplateRows: `repeat(${wrapAfter}, min-content)` }
|
|
: undefined
|
|
}
|
|
>
|
|
{cards}
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
);
|
|
});
|
|
|
|
export const KanbanColumn = KanbanColumnRoot;
|