@crisp-ui-kit/crisp 0.2.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/base.css +25 -0
- package/dist/button.css +1 -1
- package/dist/command.css +1 -1
- package/dist/contextmenu.css +1 -1
- package/dist/datatable.css +60 -0
- package/dist/datatable.d.ts +7 -0
- package/dist/datepicker.css +1 -1
- package/dist/dialog.css +1 -1
- package/dist/esm/components/accordion/accordion.js +32 -0
- package/dist/esm/components/accordion/accordion.recipe.js +23 -0
- package/dist/esm/components/accordion/index.js +2 -0
- package/dist/esm/components/avatar/avatar.js +8 -0
- package/dist/esm/components/avatar/avatar.recipe.js +39 -0
- package/dist/esm/components/avatar/index.js +2 -0
- package/dist/esm/components/avatargroup/avatargroup.js +16 -0
- package/dist/esm/components/avatargroup/avatargroup.recipe.js +15 -0
- package/dist/esm/components/avatargroup/index.js +2 -0
- package/dist/esm/components/badge/badge.js +8 -0
- package/dist/esm/components/badge/badge.recipe.js +65 -0
- package/dist/esm/components/badge/index.js +2 -0
- package/dist/esm/components/barchart/barchart.js +29 -0
- package/dist/esm/components/barchart/barchart.recipe.js +26 -0
- package/dist/esm/components/barchart/index.js +2 -0
- package/dist/esm/components/breadcrumb/breadcrumb.js +17 -0
- package/dist/esm/components/breadcrumb/breadcrumb.recipe.js +18 -0
- package/dist/esm/components/breadcrumb/index.js +2 -0
- package/dist/esm/components/bulkbar/bulkbar.js +16 -0
- package/dist/esm/components/bulkbar/bulkbar.recipe.js +28 -0
- package/dist/esm/components/bulkbar/index.js +2 -0
- package/dist/esm/components/button/button.js +15 -0
- package/dist/esm/components/button/button.recipe.js +39 -0
- package/dist/esm/components/button/index.js +2 -0
- package/dist/esm/components/callout/callout.js +22 -0
- package/dist/esm/components/callout/callout.recipe.js +26 -0
- package/dist/esm/components/callout/index.js +2 -0
- package/dist/esm/components/card/card.js +15 -0
- package/dist/esm/components/card/card.recipe.js +28 -0
- package/dist/esm/components/card/index.js +2 -0
- package/dist/esm/components/checkbox/checkbox.js +20 -0
- package/dist/esm/components/checkbox/checkbox.recipe.js +23 -0
- package/dist/esm/components/checkbox/index.js +2 -0
- package/dist/esm/components/contextmenu/contextmenu.js +42 -0
- package/dist/esm/components/contextmenu/contextmenu.recipe.js +21 -0
- package/dist/esm/components/contextmenu/index.js +2 -0
- package/dist/esm/components/datatable/datatable.js +245 -0
- package/dist/esm/components/datatable/datatable.recipe.js +72 -0
- package/dist/esm/components/datatable/index.js +2 -0
- package/dist/esm/components/datepicker/datepicker.js +57 -0
- package/dist/esm/components/datepicker/datepicker.recipe.js +32 -0
- package/dist/esm/components/datepicker/index.js +2 -0
- package/dist/esm/components/dialog/dialog.js +48 -0
- package/dist/esm/components/dialog/dialog.recipe.js +32 -0
- package/dist/esm/components/dialog/index.js +2 -0
- package/dist/esm/components/divider/divider.js +7 -0
- package/dist/esm/components/divider/divider.recipe.js +14 -0
- package/dist/esm/components/divider/index.js +2 -0
- package/dist/esm/components/donutchart/donutchart.js +38 -0
- package/dist/esm/components/donutchart/donutchart.recipe.js +27 -0
- package/dist/esm/components/donutchart/index.js +2 -0
- package/dist/esm/components/drawer/drawer.js +42 -0
- package/dist/esm/components/drawer/drawer.recipe.js +27 -0
- package/dist/esm/components/drawer/index.js +2 -0
- package/dist/esm/components/emptystate/emptystate.js +7 -0
- package/dist/esm/components/emptystate/emptystate.recipe.js +31 -0
- package/dist/esm/components/emptystate/index.js +2 -0
- package/dist/esm/components/formfield/formfield.js +14 -0
- package/dist/esm/components/formfield/formfield.recipe.js +19 -0
- package/dist/esm/components/formfield/index.js +2 -0
- package/dist/esm/components/input/index.js +2 -0
- package/dist/esm/components/input/input.js +8 -0
- package/dist/esm/components/input/input.recipe.js +23 -0
- package/dist/esm/components/kbd/index.js +2 -0
- package/dist/esm/components/kbd/kbd.js +8 -0
- package/dist/esm/components/kbd/kbd.recipe.js +20 -0
- package/dist/esm/components/linechart/index.js +2 -0
- package/dist/esm/components/linechart/linechart.js +41 -0
- package/dist/esm/components/linechart/linechart.recipe.js +27 -0
- package/dist/esm/components/menu/index.js +2 -0
- package/dist/esm/components/menu/menu.js +137 -0
- package/dist/esm/components/menu/menu.recipe.js +51 -0
- package/dist/esm/components/multiselect/index.js +2 -0
- package/dist/esm/components/multiselect/multiselect.js +118 -0
- package/dist/esm/components/multiselect/multiselect.recipe.js +68 -0
- package/dist/esm/components/popover/index.js +2 -0
- package/dist/esm/components/popover/popover.js +70 -0
- package/dist/esm/components/popover/popover.recipe.js +18 -0
- package/dist/esm/components/progress/index.js +2 -0
- package/dist/esm/components/progress/progress.js +23 -0
- package/dist/esm/components/progress/progress.recipe.js +17 -0
- package/dist/esm/components/radiogroup/index.js +2 -0
- package/dist/esm/components/radiogroup/radiogroup.js +46 -0
- package/dist/esm/components/radiogroup/radiogroup.recipe.js +37 -0
- package/dist/esm/components/segmented/index.js +2 -0
- package/dist/esm/components/segmented/segmented.js +59 -0
- package/dist/esm/components/segmented/segmented.recipe.js +20 -0
- package/dist/esm/components/select/index.js +2 -0
- package/dist/esm/components/select/select.js +144 -0
- package/dist/esm/components/select/select.recipe.js +76 -0
- package/dist/esm/components/skeleton/index.js +2 -0
- package/dist/esm/components/skeleton/skeleton.js +7 -0
- package/dist/esm/components/skeleton/skeleton.recipe.js +14 -0
- package/dist/esm/components/spinner/index.js +2 -0
- package/dist/esm/components/spinner/spinner.js +11 -0
- package/dist/esm/components/spinner/spinner.recipe.js +13 -0
- package/dist/esm/components/stagebar/index.js +2 -0
- package/dist/esm/components/stagebar/stagebar.js +23 -0
- package/dist/esm/components/stagebar/stagebar.recipe.js +14 -0
- package/dist/esm/components/statcard/index.js +2 -0
- package/dist/esm/components/statcard/statcard.js +12 -0
- package/dist/esm/components/statcard/statcard.recipe.js +34 -0
- package/dist/esm/components/switch/index.js +2 -0
- package/dist/esm/components/switch/switch.js +22 -0
- package/dist/esm/components/switch/switch.recipe.js +26 -0
- package/dist/esm/components/table/index.js +2 -0
- package/dist/esm/components/table/table.js +30 -0
- package/dist/esm/components/table/table.recipe.js +40 -0
- package/dist/esm/components/tabletoolbar/index.js +2 -0
- package/dist/esm/components/tabletoolbar/tabletoolbar.chrome.js +79 -0
- package/dist/esm/components/tabletoolbar/tabletoolbar.js +191 -0
- package/dist/esm/components/tabletoolbar/tabletoolbar.recipe.js +23 -0
- package/dist/esm/components/tabs/index.js +2 -0
- package/dist/esm/components/tabs/tabs.js +70 -0
- package/dist/esm/components/tabs/tabs.recipe.js +33 -0
- package/dist/esm/components/textarea/index.js +2 -0
- package/dist/esm/components/textarea/textarea.js +20 -0
- package/dist/esm/components/textarea/textarea.recipe.js +31 -0
- package/dist/esm/components/toast/index.js +2 -0
- package/dist/esm/components/toast/toast.js +58 -0
- package/dist/esm/components/toast/toast.recipe.js +28 -0
- package/dist/esm/components/tooltip/index.js +2 -0
- package/dist/esm/components/tooltip/tooltip.js +45 -0
- package/dist/esm/components/tooltip/tooltip.recipe.js +13 -0
- package/dist/esm/core/cx.js +1 -0
- package/dist/esm/core/define.js +3 -0
- package/dist/esm/core/index.js +4 -0
- package/dist/esm/core/primitive.js +13 -0
- package/dist/esm/core/resolve.js +41 -0
- package/dist/esm/core/types.js +1 -0
- package/dist/esm/index.js +71 -0
- package/dist/esm/product/appshell/appshell.js +44 -0
- package/dist/esm/product/appshell/appshell.recipe.js +27 -0
- package/dist/esm/product/appshell/index.js +2 -0
- package/dist/esm/product/board/board.js +42 -0
- package/dist/esm/product/board/board.recipe.js +28 -0
- package/dist/esm/product/board/index.js +2 -0
- package/dist/esm/product/command/command.js +188 -0
- package/dist/esm/product/command/command.recipe.js +19 -0
- package/dist/esm/product/command/index.js +2 -0
- package/dist/esm/product/entitycard/entitycard.js +11 -0
- package/dist/esm/product/entitycard/entitycard.recipe.js +29 -0
- package/dist/esm/product/entitycard/index.js +2 -0
- package/dist/esm/product/flowcanvas/flowcanvas.js +85 -0
- package/dist/esm/product/flowcanvas/flowcanvas.recipe.js +25 -0
- package/dist/esm/product/flowcanvas/index.js +2 -0
- package/dist/esm/product/inbox/inbox.js +13 -0
- package/dist/esm/product/inbox/inbox.recipe.js +43 -0
- package/dist/esm/product/inbox/index.js +2 -0
- package/dist/esm/product/listpage/index.js +2 -0
- package/dist/esm/product/listpage/listpage.js +21 -0
- package/dist/esm/product/listpage/listpage.recipe.js +43 -0
- package/dist/esm/product/navitem/index.js +1 -0
- package/dist/esm/product/navitem/navitem.js +8 -0
- package/dist/esm/product/navitem/navitem.recipe.js +21 -0
- package/dist/esm/product/onboarding/index.js +2 -0
- package/dist/esm/product/onboarding/onboarding.js +14 -0
- package/dist/esm/product/onboarding/onboarding.recipe.js +41 -0
- package/dist/esm/product/recordpage/index.js +2 -0
- package/dist/esm/product/recordpage/recordpage.js +286 -0
- package/dist/esm/product/recordpage/recordpage.recipe.js +157 -0
- package/dist/esm/product/recordpanel/index.js +2 -0
- package/dist/esm/product/recordpanel/recordpanel.js +47 -0
- package/dist/esm/product/recordpanel/recordpanel.recipe.js +52 -0
- package/dist/esm/product/recordstable/company-logos.js +26 -0
- package/dist/esm/product/recordstable/index.js +2 -0
- package/dist/esm/product/recordstable/recordstable.js +963 -0
- package/dist/esm/product/recordstable/recordstable.recipe.js +149 -0
- package/dist/esm/product/richtext/index.js +2 -0
- package/dist/esm/product/richtext/richtext.js +111 -0
- package/dist/esm/product/richtext/richtext.recipe.js +40 -0
- package/dist/esm/product/settingssection/index.js +2 -0
- package/dist/esm/product/settingssection/settingssection.js +11 -0
- package/dist/esm/product/settingssection/settingssection.recipe.js +20 -0
- package/dist/esm/product/settingsshell/index.js +2 -0
- package/dist/esm/product/settingsshell/settingsshell.js +23 -0
- package/dist/esm/product/settingsshell/settingsshell.recipe.js +38 -0
- package/dist/esm/product/sidebar/index.js +2 -0
- package/dist/esm/product/sidebar/sidebar.js +112 -0
- package/dist/esm/product/sidebar/sidebar.recipe.js +18 -0
- package/dist/esm/product/tasklist/index.js +2 -0
- package/dist/esm/product/tasklist/tasklist.js +16 -0
- package/dist/esm/product/tasklist/tasklist.recipe.js +35 -0
- package/dist/esm/product/trialbanner/index.js +2 -0
- package/dist/esm/product/trialbanner/trialbanner.js +10 -0
- package/dist/esm/product/trialbanner/trialbanner.recipe.js +29 -0
- package/dist/esm/product/viewtoggle/index.js +2 -0
- package/dist/esm/product/viewtoggle/viewtoggle.js +11 -0
- package/dist/esm/product/viewtoggle/viewtoggle.recipe.js +24 -0
- package/dist/esm/tokens/contract.js +18 -0
- package/dist/esm/tokens/index.js +4 -0
- package/dist/esm/tokens/palette.js +30 -0
- package/dist/esm/tokens/scale.js +60 -0
- package/dist/esm/tokens/semantic.js +30 -0
- package/dist/menu.css +2 -2
- package/dist/multiselect.css +3 -3
- package/dist/popover.css +1 -1
- package/dist/recordpage.css +5 -5
- package/dist/recordstable.css +4 -4
- package/dist/select.css +10 -4
- package/dist/select.d.ts +2 -1
- package/dist/sidebar.css +1 -1
- package/dist/statcard.css +6 -0
- package/dist/statcard.d.ts +2 -2
- package/dist/styles.css +222 -27
- package/dist/table.css +26 -0
- package/dist/table.d.ts +8 -0
- package/dist/tabletoolbar.css +70 -0
- package/dist/tabletoolbar.d.ts +7 -0
- package/dist/tokens.css +24 -0
- package/dist/types/components/datatable/datatable.d.ts +98 -0
- package/dist/types/components/datatable/datatable.recipe.d.ts +3 -0
- package/dist/types/components/datatable/index.d.ts +2 -0
- package/dist/types/components/select/select.d.ts +3 -1
- package/dist/types/components/select/select.recipe.d.ts +12 -0
- package/dist/types/components/statcard/statcard.d.ts +6 -1
- package/dist/types/components/statcard/statcard.recipe.d.ts +12 -2
- package/dist/types/components/table/index.d.ts +2 -0
- package/dist/types/components/table/table.d.ts +53 -0
- package/dist/types/components/table/table.recipe.d.ts +21 -0
- package/dist/types/components/tabletoolbar/index.d.ts +2 -0
- package/dist/types/components/tabletoolbar/tabletoolbar.chrome.d.ts +2 -0
- package/dist/types/components/tabletoolbar/tabletoolbar.d.ts +63 -0
- package/dist/types/components/tabletoolbar/tabletoolbar.recipe.d.ts +3 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/product/recordstable/company-logos.d.ts +1 -0
- package/dist/types/product/recordstable/recordstable.d.ts +42 -1
- package/dist/types/product/sidebar/index.d.ts +1 -1
- package/dist/types/product/sidebar/sidebar.d.ts +85 -0
- package/dist/types/tokens/contract.d.ts +12 -0
- package/dist/types/tokens/palette.d.ts +48 -0
- package/dist/types/tokens/semantic.d.ts +12 -0
- package/dist/viewtoggle.css +2 -2
- package/package.json +259 -9
- package/dist/index.js +0 -9690
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { defineRecipe, resolveRecipe } from "../../core/index.js";
|
|
2
|
+
import { contract as c } from "../../tokens/index.js";
|
|
3
|
+
const config = defineRecipe({
|
|
4
|
+
name: "button",
|
|
5
|
+
base: `display: inline-flex; align-items: center; justify-content: center; gap: ${c.space["1.5"]}; font-family: ${c.font.sans}; font-weight: ${c.weight.medium}; letter-spacing: -0.14px; line-height: 20px; white-space: nowrap; border: none; cursor: pointer; transition: background-color .2s, box-shadow .2s, color .2s; &:disabled { opacity: 0.5; cursor: not-allowed; }`,
|
|
6
|
+
variants: {
|
|
7
|
+
intent: {
|
|
8
|
+
primary: `background: ${c.bgBrandSolid}; color: ${c.fgOnBrand}; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.07), 0 2px 4px -2px rgba(38,109,240,0.12), 0 3px 6px -2px rgba(38,109,240,0.08); &:hover { background: ${c.bgBrandSolidPressed}; } &:active { background: ${c.bgBrandSolidPressed}; }`,
|
|
9
|
+
neutral: `background: ${c.bgSurface}; color: ${c.fgPrimary}; box-shadow: inset 0 0 0 1px ${c.ringNeutral}, 0 0 2px rgba(28,40,64,0.18), 0 1px 3px rgba(0,0,0,0.04); &:hover { background: ${c.bgRaised}; }`,
|
|
10
|
+
danger: `background: ${c.bgDanger}; color: ${c.fgOnBrand}; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.07), 0 2px 4px -2px rgba(229,72,77,0.20), 0 3px 6px -2px rgba(229,72,77,0.12); &:hover { filter: brightness(0.96); } &:active { filter: brightness(0.92); }`,
|
|
11
|
+
ghost: `background: transparent; color: ${c.fgMuted}; box-shadow: none; &:hover { background: ${c.bgRaised}; color: ${c.fgPrimary}; }`,
|
|
12
|
+
},
|
|
13
|
+
size: {
|
|
14
|
+
sm: `height: 24px; padding-inline: ${c.space["1.5"]}; font-size: ${c.text.md}; border-radius: ${c.radius.md};`,
|
|
15
|
+
md: `height: 28px; padding-inline: ${c.space["2"]}; font-size: ${c.text.lg}; border-radius: ${c.radius.md};`,
|
|
16
|
+
lg: `height: 40px; padding-inline: 14px; font-size: ${c.text.lg}; border-radius: 10px;`,
|
|
17
|
+
},
|
|
18
|
+
shape: {
|
|
19
|
+
text: ``,
|
|
20
|
+
icon: `padding-inline: 0; aspect-ratio: 1 / 1;`,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
defaultVariants: { intent: "primary", size: "md", shape: "text" },
|
|
24
|
+
compoundVariants: [],
|
|
25
|
+
});
|
|
26
|
+
export const buttonRecipe = Object.assign(resolveRecipe(config), {
|
|
27
|
+
config,
|
|
28
|
+
meta: {
|
|
29
|
+
primary: {
|
|
30
|
+
height: "28px",
|
|
31
|
+
borderRadius: "8px",
|
|
32
|
+
fontWeight: "500",
|
|
33
|
+
fontSize: "14px",
|
|
34
|
+
background: "rgb(38, 109, 240)",
|
|
35
|
+
color: "rgb(255, 255, 255)",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
export default config;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CircleAlert, CircleCheck, Info, TriangleAlert } from "lucide-react";
|
|
3
|
+
import { calloutRecipe } from "./callout.recipe.js";
|
|
4
|
+
const DEFAULT_ICONS = {
|
|
5
|
+
neutral: Info,
|
|
6
|
+
info: Info,
|
|
7
|
+
success: CircleCheck,
|
|
8
|
+
warning: TriangleAlert,
|
|
9
|
+
danger: CircleAlert,
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* An inline callout / banner — measured from Attio's info notices. `tone` tints
|
|
13
|
+
* the background and icon; pass a `title` and/or body `children`.
|
|
14
|
+
*/
|
|
15
|
+
export function Callout({ tone = "neutral", icon, title, children, action, className, }) {
|
|
16
|
+
const Fallback = DEFAULT_ICONS[tone];
|
|
17
|
+
const iconNode = icon === undefined
|
|
18
|
+
? Fallback && _jsx(Fallback, { size: 16, strokeWidth: 1.75, "aria-hidden": "true" })
|
|
19
|
+
: icon;
|
|
20
|
+
return (_jsxs("div", { className: calloutRecipe({ className }), "data-tone": tone, role: "note", children: [iconNode && _jsx("span", { className: "callout-icon", children: iconNode }), _jsxs("div", { className: "callout-body", children: [title != null && _jsx("div", { className: "callout-title", children: title }), children != null && _jsx("div", { className: "callout-desc", children: children })] }), action && _jsx("div", { className: "callout-action", children: action })] }));
|
|
21
|
+
}
|
|
22
|
+
Callout.displayName = "Callout";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineRecipe, resolveRecipe } from "../../core/index.js";
|
|
2
|
+
import { contract as c } from "../../tokens/index.js";
|
|
3
|
+
// A callout / banner — Attio's inline info notices (e.g. "Changes apply to all
|
|
4
|
+
// workspaces", the trial banner). Tone tints the background + icon.
|
|
5
|
+
const config = defineRecipe({
|
|
6
|
+
name: "callout",
|
|
7
|
+
base: `display: flex; align-items: flex-start; gap: ${c.space["2.5"]}; box-sizing: border-box; padding: ${c.space["3"]} ${c.space["4"]}; border-radius: ${c.radius.lg}; font-family: ${c.font.sans}; font-size: ${c.text.md}; background: color-mix(in srgb, ${c.fgPrimary} 4%, transparent); color: ${c.fgPrimary};
|
|
8
|
+
& .callout-icon { flex-shrink: 0; margin-top: 1px; display: inline-flex; color: ${c.fgMuted}; }
|
|
9
|
+
& .callout-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
|
|
10
|
+
& .callout-title { font-weight: ${c.weight.semibold}; }
|
|
11
|
+
& .callout-desc { color: ${c.fgMuted}; }
|
|
12
|
+
& .callout-action { flex-shrink: 0; }
|
|
13
|
+
&[data-tone="info"] { background: color-mix(in srgb, ${c.bgBrandSolid} 8%, transparent); }
|
|
14
|
+
&[data-tone="info"] .callout-icon { color: ${c.bgBrandSolid}; }
|
|
15
|
+
&[data-tone="success"] { background: color-mix(in srgb, ${c.bgSuccess} 10%, transparent); }
|
|
16
|
+
&[data-tone="success"] .callout-icon { color: ${c.bgSuccess}; }
|
|
17
|
+
&[data-tone="warning"] { background: color-mix(in srgb, ${c.bgWarning} 12%, transparent); }
|
|
18
|
+
&[data-tone="warning"] .callout-icon { color: ${c.bgWarning}; }
|
|
19
|
+
&[data-tone="danger"] { background: color-mix(in srgb, ${c.bgDanger} 10%, transparent); }
|
|
20
|
+
&[data-tone="danger"] .callout-icon { color: ${c.bgDanger}; }`,
|
|
21
|
+
variants: {},
|
|
22
|
+
defaultVariants: {},
|
|
23
|
+
compoundVariants: [],
|
|
24
|
+
});
|
|
25
|
+
export const calloutRecipe = resolveRecipe(config);
|
|
26
|
+
export default config;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cardRecipe } from "./card.recipe.js";
|
|
4
|
+
/** A bordered surface card. Compose with CardHeader / CardBody / CardFooter. */
|
|
5
|
+
export const Card = React.forwardRef(({ raised, interactive, className, ...props }, ref) => (_jsx("div", { ref: ref, className: cardRecipe({ raised, interactive, className }), ...props })));
|
|
6
|
+
Card.displayName = "Card";
|
|
7
|
+
export function CardHeader({ children, icon, action, }) {
|
|
8
|
+
return (_jsxs("div", { className: "card-header", children: [icon, _jsx("span", { className: "card-title", children: children }), action] }));
|
|
9
|
+
}
|
|
10
|
+
export function CardBody({ children, className, }) {
|
|
11
|
+
return (_jsx("div", { className: className ? `card-body ${className}` : "card-body", children: children }));
|
|
12
|
+
}
|
|
13
|
+
export function CardFooter({ children }) {
|
|
14
|
+
return _jsx("div", { className: "card-footer", children: children });
|
|
15
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineRecipe, resolveRecipe } from "../../core/index.js";
|
|
2
|
+
import { contract as c } from "../../tokens/index.js";
|
|
3
|
+
// A bordered surface card — the recurring container behind kanban cards, chart
|
|
4
|
+
// cards, workflow nodes, and highlight cells. `raised` adds a soft float shadow;
|
|
5
|
+
// `interactive` adds a hover affordance.
|
|
6
|
+
const config = defineRecipe({
|
|
7
|
+
name: "card",
|
|
8
|
+
base: `display: flex; flex-direction: column; box-sizing: border-box; border-radius: ${c.radius.xl}; background: ${c.bgSurface}; box-shadow: inset 0 0 0 1px ${c.borderSubtle}; font-family: ${c.font.sans}; color: ${c.fgPrimary};
|
|
9
|
+
& .card-header { display: flex; align-items: center; gap: ${c.space["2"]}; flex-shrink: 0; padding: ${c.space["3"]} ${c.space["4"]}; border-bottom: 1px solid ${c.borderSubtle}; font-size: ${c.text.lg}; font-weight: ${c.weight.semibold}; }
|
|
10
|
+
& .card-header svg { flex-shrink: 0; color: ${c.fgMuted}; }
|
|
11
|
+
& .card-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
12
|
+
& .card-body { flex: 1; min-height: 0; padding: ${c.space["4"]}; }
|
|
13
|
+
& .card-footer { display: flex; align-items: center; justify-content: flex-end; gap: ${c.space["2"]}; flex-shrink: 0; padding: ${c.space["3"]} ${c.space["4"]}; border-top: 1px solid ${c.borderSubtle}; }`,
|
|
14
|
+
variants: {
|
|
15
|
+
raised: {
|
|
16
|
+
true: `box-shadow: inset 0 0 0 1px ${c.borderSubtle}, 0 1px 2px rgba(0,0,0,0.04), 0 4px 12px -4px rgba(28,40,64,0.08);`,
|
|
17
|
+
false: "",
|
|
18
|
+
},
|
|
19
|
+
interactive: {
|
|
20
|
+
true: `cursor: pointer; transition: box-shadow 0.12s ease; &:hover { box-shadow: inset 0 0 0 1px ${c.borderDefault}, 0 1px 2px rgba(0,0,0,0.04), 0 6px 16px -6px rgba(28,40,64,0.12); }`,
|
|
21
|
+
false: "",
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
defaultVariants: { raised: false, interactive: false },
|
|
25
|
+
compoundVariants: [],
|
|
26
|
+
});
|
|
27
|
+
export const cardRecipe = resolveRecipe(config);
|
|
28
|
+
export default config;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { Primitive } from "../../core/index.js";
|
|
4
|
+
import { checkboxRecipe } from "./checkbox.recipe.js";
|
|
5
|
+
/**
|
|
6
|
+
* A native `<input type="checkbox">` styled to Attio's grid checkbox (16px,
|
|
7
|
+
* r6, brand fill + white check). Native on purpose: keyboard, focus, and form
|
|
8
|
+
* semantics come for free. `indeterminate` is a DOM-only property, so it is
|
|
9
|
+
* applied via ref rather than an attribute.
|
|
10
|
+
*/
|
|
11
|
+
export const Checkbox = React.forwardRef(({ className, indeterminate = false, asChild, ...props }, ref) => {
|
|
12
|
+
const innerRef = React.useRef(null);
|
|
13
|
+
React.useImperativeHandle(ref, () => innerRef.current);
|
|
14
|
+
React.useEffect(() => {
|
|
15
|
+
if (innerRef.current)
|
|
16
|
+
innerRef.current.indeterminate = indeterminate;
|
|
17
|
+
}, [indeterminate]);
|
|
18
|
+
return (_jsx(Primitive.input, { ref: innerRef, asChild: asChild, type: "checkbox", className: checkboxRecipe({ className }), ...props }));
|
|
19
|
+
});
|
|
20
|
+
Checkbox.displayName = "Checkbox";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { defineRecipe, resolveRecipe } from "../../core/index.js";
|
|
2
|
+
import { contract as c } from "../../tokens/index.js";
|
|
3
|
+
// A 16px square checkbox measured from Attio's record grid: r6, a subtle 1px
|
|
4
|
+
// inset ring when empty, brand fill + white check when on. The check is a
|
|
5
|
+
// data-URI SVG background so it renders reliably (input pseudo-content doesn't).
|
|
6
|
+
const CHECK = "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.5 6.5 5 9l4.5-5'/%3E%3C/svg%3E\")";
|
|
7
|
+
const config = defineRecipe({
|
|
8
|
+
name: "checkbox",
|
|
9
|
+
base: `appearance: none; -webkit-appearance: none; box-sizing: border-box; flex-shrink: 0; margin: 0; width: 16px; height: 16px; border: none; border-radius: ${c.radius.sm}; background: ${c.bgSurface}; box-shadow: inset 0 0 0 1px color-mix(in srgb, ${c.fgPrimary} 9%, transparent); cursor: pointer; transition: background-color .12s, box-shadow .12s; &:hover { box-shadow: inset 0 0 0 1px color-mix(in srgb, ${c.fgPrimary} 30%, transparent); } &:checked, &:indeterminate { background: ${c.bgBrandSolid} center / 10px no-repeat; box-shadow: none; } &:checked { background-image: ${CHECK}; } &:indeterminate { background-image: linear-gradient(${c.fgOnBrand}, ${c.fgOnBrand}); background-size: 8px 2px; } &:focus-visible { outline: 2px solid ${c.bgBrandSolid}; outline-offset: 1px; }`,
|
|
10
|
+
variants: {},
|
|
11
|
+
defaultVariants: {},
|
|
12
|
+
compoundVariants: [],
|
|
13
|
+
});
|
|
14
|
+
export const checkboxRecipe = Object.assign(resolveRecipe(config), {
|
|
15
|
+
config,
|
|
16
|
+
meta: {
|
|
17
|
+
box: {
|
|
18
|
+
size: "16px",
|
|
19
|
+
borderRadius: "6px",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
export default config;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { contextmenuRecipe } from "./contextmenu.recipe.js";
|
|
4
|
+
/**
|
|
5
|
+
* A right-click context menu — the popover surface positioned at the cursor.
|
|
6
|
+
* Wrap the target; right-clicking it opens the menu (flipping at the viewport
|
|
7
|
+
* edges), closing on select, outside pointer-down, and Escape.
|
|
8
|
+
*/
|
|
9
|
+
export function ContextMenu({ children, items, className }) {
|
|
10
|
+
const rootRef = React.useRef(null);
|
|
11
|
+
const [pos, setPos] = React.useState(null);
|
|
12
|
+
const open = (e) => {
|
|
13
|
+
e.preventDefault();
|
|
14
|
+
// flip so the menu stays on-screen near the right/bottom edges
|
|
15
|
+
const x = Math.min(e.clientX, window.innerWidth - 220);
|
|
16
|
+
const y = Math.min(e.clientY, window.innerHeight - 12 - items.length * 34);
|
|
17
|
+
setPos({ x: Math.max(8, x), y: Math.max(8, y) });
|
|
18
|
+
};
|
|
19
|
+
const close = React.useCallback(() => setPos(null), []);
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
if (!pos)
|
|
22
|
+
return;
|
|
23
|
+
const onDown = (e) => {
|
|
24
|
+
if (!rootRef.current?.contains(e.target))
|
|
25
|
+
close();
|
|
26
|
+
};
|
|
27
|
+
const onKey = (e) => e.key === "Escape" && close();
|
|
28
|
+
document.addEventListener("pointerdown", onDown);
|
|
29
|
+
document.addEventListener("keydown", onKey);
|
|
30
|
+
return () => {
|
|
31
|
+
document.removeEventListener("pointerdown", onDown);
|
|
32
|
+
document.removeEventListener("keydown", onKey);
|
|
33
|
+
};
|
|
34
|
+
}, [pos, close]);
|
|
35
|
+
return (_jsxs("div", { ref: rootRef, className: contextmenuRecipe({ className }), children: [_jsx("div", { onContextMenu: open, children: children }), pos && (_jsx("div", { className: "contextmenu-content", role: "menu", style: { left: pos.x, top: pos.y }, children: items.map((item, i) => item.separator ? (_jsx("hr", { className: "contextmenu-sep" }, i)) : (_jsxs("button", { type: "button", role: "menuitem", disabled: item.disabled, className: item.danger
|
|
36
|
+
? "contextmenu-item contextmenu-item--danger"
|
|
37
|
+
: "contextmenu-item", onClick: () => {
|
|
38
|
+
item.onSelect?.();
|
|
39
|
+
close();
|
|
40
|
+
}, children: [item.icon, item.label, item.shortcut && (_jsx("span", { className: "contextmenu-shortcut", children: item.shortcut }))] }, i))) }))] }));
|
|
41
|
+
}
|
|
42
|
+
ContextMenu.displayName = "ContextMenu";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineRecipe, resolveRecipe } from "../../core/index.js";
|
|
2
|
+
import { contract as c } from "../../tokens/index.js";
|
|
3
|
+
// A right-click menu on the measured popover surface, positioned at the cursor.
|
|
4
|
+
const config = defineRecipe({
|
|
5
|
+
name: "contextmenu",
|
|
6
|
+
base: `display: contents; font-family: ${c.font.sans};
|
|
7
|
+
& .contextmenu-content { position: fixed; z-index: 60; min-width: 200px; box-sizing: border-box; padding: ${c.space["1"]}; border-radius: ${c.radius.xl}; background: ${c.bgPopover}; box-shadow: inset 0 0 0 1px ${c.ringPopover}, 0 0 0 1px ${c.shadowPopover1}, 0 4px 8px -4px ${c.shadowPopover2}, 0 4px 12px -2px ${c.shadowPopover3}; opacity: 1; transform: none; transition: opacity .08s ease, transform .08s ease; transform-origin: top left; @starting-style { opacity: 0; transform: scale(0.97) translateY(-1px); } }
|
|
8
|
+
& .contextmenu-item { display: flex; align-items: center; gap: ${c.space["2"]}; width: 100%; height: 32px; box-sizing: border-box; padding: 0 ${c.space["2"]}; margin: 0; border: none; border-radius: ${c.radius.md}; background: none; color: ${c.fgPrimary}; font-family: inherit; font-size: ${c.text.lg}; text-align: left; white-space: nowrap; cursor: pointer; }
|
|
9
|
+
& .contextmenu-item svg { flex-shrink: 0; color: ${c.fgMuted}; }
|
|
10
|
+
& .contextmenu-item:hover { background: color-mix(in srgb, ${c.fgPrimary} 6%, transparent); }
|
|
11
|
+
& .contextmenu-item--danger { color: ${c.bgDanger}; }
|
|
12
|
+
& .contextmenu-item--danger svg { color: ${c.bgDanger}; }
|
|
13
|
+
& .contextmenu-item--danger:hover { background: color-mix(in srgb, ${c.bgDanger} 10%, transparent); }
|
|
14
|
+
& .contextmenu-shortcut { margin-left: auto; padding-left: ${c.space["3"]}; color: ${c.fgMuted}; font-size: ${c.text.sm}; }
|
|
15
|
+
& .contextmenu-sep { height: 1px; margin: ${c.space["1"]} 0; border: none; background: ${c.borderSubtle}; }`,
|
|
16
|
+
variants: {},
|
|
17
|
+
defaultVariants: {},
|
|
18
|
+
compoundVariants: [],
|
|
19
|
+
});
|
|
20
|
+
export const contextmenuRecipe = resolveRecipe(config);
|
|
21
|
+
export default config;
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ArrowDown, ArrowUp, ChevronsUpDown, Plus, Search } from "lucide-react";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Checkbox } from "../checkbox/index.js";
|
|
5
|
+
import { Table, TableBody, TableCell, TableFooter, TableHead, TableHeader, TableRow, } from "../table/index.js";
|
|
6
|
+
import { datatableRecipe } from "./datatable.recipe.js";
|
|
7
|
+
function cellValue(col, row) {
|
|
8
|
+
if (col.accessor)
|
|
9
|
+
return col.accessor(row);
|
|
10
|
+
return row[col.key];
|
|
11
|
+
}
|
|
12
|
+
function asText(v) {
|
|
13
|
+
if (v == null)
|
|
14
|
+
return "";
|
|
15
|
+
if (typeof v === "object" && "name" in v)
|
|
16
|
+
return v.name ?? "";
|
|
17
|
+
if (Array.isArray(v))
|
|
18
|
+
return v.join(", ");
|
|
19
|
+
return String(v);
|
|
20
|
+
}
|
|
21
|
+
// stable pastel tone per string value — colour-coded tags/statuses, like Attio
|
|
22
|
+
const TAG_TONES = [
|
|
23
|
+
"brand",
|
|
24
|
+
"success",
|
|
25
|
+
"warning",
|
|
26
|
+
"danger",
|
|
27
|
+
"purple",
|
|
28
|
+
"cyan",
|
|
29
|
+
"orange",
|
|
30
|
+
];
|
|
31
|
+
function toneFor(t) {
|
|
32
|
+
let h = 0;
|
|
33
|
+
for (let i = 0; i < t.length; i++)
|
|
34
|
+
h = (h * 31 + t.charCodeAt(i)) >>> 0;
|
|
35
|
+
return TAG_TONES[h % TAG_TONES.length];
|
|
36
|
+
}
|
|
37
|
+
function initials(name) {
|
|
38
|
+
const p = name.trim().split(/\s+/);
|
|
39
|
+
return ((p[0]?.[0] ?? "") + (p[1]?.[0] ?? "")).toUpperCase() || "?";
|
|
40
|
+
}
|
|
41
|
+
const DATE_FMT = new Intl.DateTimeFormat("en-US", {
|
|
42
|
+
month: "short",
|
|
43
|
+
day: "numeric",
|
|
44
|
+
year: "numeric",
|
|
45
|
+
});
|
|
46
|
+
function formatCell(type, v, symbol) {
|
|
47
|
+
if (type === "number")
|
|
48
|
+
return typeof v === "number" ? v.toLocaleString("en-US") : asText(v);
|
|
49
|
+
if (type === "currency")
|
|
50
|
+
return typeof v === "number"
|
|
51
|
+
? `${symbol ?? "$"}${v.toLocaleString("en-US")}`
|
|
52
|
+
: asText(v);
|
|
53
|
+
if (type === "date") {
|
|
54
|
+
const d = v ? new Date(v) : null;
|
|
55
|
+
return d && !Number.isNaN(d.getTime()) ? DATE_FMT.format(d) : asText(v);
|
|
56
|
+
}
|
|
57
|
+
return asText(v);
|
|
58
|
+
}
|
|
59
|
+
/** Built-in typed-cell renderer (used when a column has no custom `render`). */
|
|
60
|
+
function renderTyped(col, value, avatarTone) {
|
|
61
|
+
const empty = _jsx("span", { className: "datatable-muted", children: "\u2014" });
|
|
62
|
+
switch (col.type) {
|
|
63
|
+
case "entity": {
|
|
64
|
+
const e = (typeof value === "object" && value ? value : { name: asText(value) });
|
|
65
|
+
if (!e.name)
|
|
66
|
+
return empty;
|
|
67
|
+
return (_jsxs("span", { className: "datatable-entity", children: [_jsx("span", { className: "datatable-avatar", "data-tone": avatarTone === "hashed" ? toneFor(e.name) : undefined, children: e.avatar ? (_jsx("img", { src: e.avatar, alt: "" })) : (initials(e.name).slice(0, 2)) }), _jsx("span", { className: "datatable-entity-name", children: e.name })] }));
|
|
68
|
+
}
|
|
69
|
+
case "tags": {
|
|
70
|
+
const tags = Array.isArray(value) ? value : [];
|
|
71
|
+
if (!tags.length)
|
|
72
|
+
return empty;
|
|
73
|
+
return (_jsx("span", { className: "datatable-tags", children: tags.map((t) => (_jsx("span", { className: "datatable-tag", "data-tone": col.tones?.[t] ?? toneFor(t), children: t }, t))) }));
|
|
74
|
+
}
|
|
75
|
+
case "status": {
|
|
76
|
+
const s = asText(value);
|
|
77
|
+
if (!s)
|
|
78
|
+
return empty;
|
|
79
|
+
return (_jsx("span", { className: "datatable-tag", "data-tone": col.tones?.[s] ?? toneFor(s), children: s }));
|
|
80
|
+
}
|
|
81
|
+
default: {
|
|
82
|
+
const text = formatCell(col.type, value, col.symbol);
|
|
83
|
+
const isNum = col.type === "number" || col.type === "currency";
|
|
84
|
+
if (!text)
|
|
85
|
+
return empty;
|
|
86
|
+
return isNum ? _jsx("span", { className: "datatable-num", children: text }) : text;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const CHECK_W = 40;
|
|
91
|
+
export function DataTable({ columns, data, selectable = false, selectedIds, onSelectionChange, sort: sortProp, defaultSort, onSortChange, filterable = false, searchPlaceholder = "Search…", onEdit, stickyFirst = true, avatarTone = "brand", surface, interactive = false, onRowClick, onAddRow, addRowLabel = "New record", empty = "No results.", showCount = true, toolbar, className, }) {
|
|
92
|
+
const [query, setQuery] = React.useState("");
|
|
93
|
+
const [internalSort, setInternalSort] = React.useState(defaultSort ?? null);
|
|
94
|
+
const sort = sortProp !== undefined ? sortProp : internalSort;
|
|
95
|
+
const setSort = React.useCallback((next) => {
|
|
96
|
+
onSortChange?.(next);
|
|
97
|
+
if (sortProp === undefined)
|
|
98
|
+
setInternalSort(next);
|
|
99
|
+
}, [onSortChange, sortProp]);
|
|
100
|
+
const [internalSel, setInternalSel] = React.useState(new Set());
|
|
101
|
+
const selected = React.useMemo(() => (selectedIds ? new Set(selectedIds) : internalSel), [selectedIds, internalSel]);
|
|
102
|
+
const setSelected = React.useCallback((next) => {
|
|
103
|
+
onSelectionChange?.([...next]);
|
|
104
|
+
if (!selectedIds)
|
|
105
|
+
setInternalSel(next);
|
|
106
|
+
}, [onSelectionChange, selectedIds]);
|
|
107
|
+
const [editing, setEditing] = React.useState(null);
|
|
108
|
+
const [scrolledX, setScrolledX] = React.useState(false);
|
|
109
|
+
// column widths (drag-to-resize) + fixed-layout sizing
|
|
110
|
+
const [widths, setWidths] = React.useState({});
|
|
111
|
+
const [resizingKey, setResizingKey] = React.useState(null);
|
|
112
|
+
const resizeRef = React.useRef(null);
|
|
113
|
+
const colWidth = (col) => widths[col.key] ?? col.width ?? (col.type === "entity" ? 220 : 160);
|
|
114
|
+
const minWidth = (selectable ? CHECK_W : 0) +
|
|
115
|
+
columns.reduce((sum, col) => sum + colWidth(col), 0);
|
|
116
|
+
const colByKey = React.useMemo(() => {
|
|
117
|
+
const m = new Map();
|
|
118
|
+
for (const c of columns)
|
|
119
|
+
m.set(c.key, c);
|
|
120
|
+
return m;
|
|
121
|
+
}, [columns]);
|
|
122
|
+
const filtered = React.useMemo(() => {
|
|
123
|
+
const q = query.trim().toLowerCase();
|
|
124
|
+
if (!q)
|
|
125
|
+
return data;
|
|
126
|
+
const cols = columns.filter((c) => c.filterable !== false);
|
|
127
|
+
return data.filter((row) => cols.some((c) => asText(cellValue(c, row)).toLowerCase().includes(q)));
|
|
128
|
+
}, [data, columns, query]);
|
|
129
|
+
const rows = React.useMemo(() => {
|
|
130
|
+
if (!sort)
|
|
131
|
+
return filtered;
|
|
132
|
+
const col = colByKey.get(sort.key);
|
|
133
|
+
if (!col)
|
|
134
|
+
return filtered;
|
|
135
|
+
const dir = sort.dir === "asc" ? 1 : -1;
|
|
136
|
+
return [...filtered].sort((a, b) => {
|
|
137
|
+
const av = cellValue(col, a);
|
|
138
|
+
const bv = cellValue(col, b);
|
|
139
|
+
if (typeof av === "number" && typeof bv === "number")
|
|
140
|
+
return (av - bv) * dir;
|
|
141
|
+
return asText(av).localeCompare(asText(bv)) * dir;
|
|
142
|
+
});
|
|
143
|
+
}, [filtered, sort, colByKey]);
|
|
144
|
+
const allSelected = rows.length > 0 && rows.every((r) => selected.has(r.id));
|
|
145
|
+
const someSelected = selected.size > 0 && !allSelected;
|
|
146
|
+
function toggleAll() {
|
|
147
|
+
setSelected(allSelected ? new Set() : new Set(rows.map((r) => r.id)));
|
|
148
|
+
}
|
|
149
|
+
function toggleRow(id) {
|
|
150
|
+
const next = new Set(selected);
|
|
151
|
+
next.has(id) ? next.delete(id) : next.add(id);
|
|
152
|
+
setSelected(next);
|
|
153
|
+
}
|
|
154
|
+
function cycleSort(key) {
|
|
155
|
+
if (!sort || sort.key !== key)
|
|
156
|
+
setSort({ key, dir: "asc" });
|
|
157
|
+
else if (sort.dir === "asc")
|
|
158
|
+
setSort({ key, dir: "desc" });
|
|
159
|
+
else
|
|
160
|
+
setSort(null);
|
|
161
|
+
}
|
|
162
|
+
function commitEdit(id, key, value) {
|
|
163
|
+
onEdit?.(id, key, value);
|
|
164
|
+
setEditing(null);
|
|
165
|
+
}
|
|
166
|
+
const totalCols = columns.length + (selectable ? 1 : 0);
|
|
167
|
+
const hasSummary = columns.some((c) => c.summary);
|
|
168
|
+
// sticky attrs for the leading column(s): selection col + first data column
|
|
169
|
+
const stickyCol = (index) => {
|
|
170
|
+
if (!stickyFirst)
|
|
171
|
+
return {};
|
|
172
|
+
if (selectable && index === -1)
|
|
173
|
+
return { "data-sticky": "", style: { left: 0 } };
|
|
174
|
+
if (index === 0)
|
|
175
|
+
return {
|
|
176
|
+
"data-sticky": "",
|
|
177
|
+
"data-sticky-edge": "",
|
|
178
|
+
style: { left: selectable ? CHECK_W : 0 },
|
|
179
|
+
};
|
|
180
|
+
return {};
|
|
181
|
+
};
|
|
182
|
+
const alignFor = (col) => col.align ??
|
|
183
|
+
(col.type === "number" || col.type === "currency" ? "right" : undefined);
|
|
184
|
+
function startResize(col, e) {
|
|
185
|
+
e.preventDefault();
|
|
186
|
+
e.stopPropagation();
|
|
187
|
+
e.target.setPointerCapture(e.pointerId);
|
|
188
|
+
resizeRef.current = {
|
|
189
|
+
key: col.key,
|
|
190
|
+
startX: e.clientX,
|
|
191
|
+
startW: colWidth(col),
|
|
192
|
+
};
|
|
193
|
+
setResizingKey(col.key);
|
|
194
|
+
}
|
|
195
|
+
function moveResize(e) {
|
|
196
|
+
const r = resizeRef.current;
|
|
197
|
+
if (!r)
|
|
198
|
+
return;
|
|
199
|
+
const w = Math.max(64, r.startW + (e.clientX - r.startX));
|
|
200
|
+
setWidths((prev) => ({ ...prev, [r.key]: w }));
|
|
201
|
+
}
|
|
202
|
+
function endResize(e) {
|
|
203
|
+
resizeRef.current = null;
|
|
204
|
+
setResizingKey(null);
|
|
205
|
+
e.target.releasePointerCapture(e.pointerId);
|
|
206
|
+
}
|
|
207
|
+
function ChevronFor({ colKey }) {
|
|
208
|
+
if (sort?.key === colKey)
|
|
209
|
+
return sort.dir === "asc" ? (_jsx(ArrowUp, { className: "datatable-chevron", size: 13, strokeWidth: 2 })) : (_jsx(ArrowDown, { className: "datatable-chevron", size: 13, strokeWidth: 2 }));
|
|
210
|
+
return (_jsx(ChevronsUpDown, { className: "datatable-chevron", size: 13, strokeWidth: 2 }));
|
|
211
|
+
}
|
|
212
|
+
return (_jsxs("div", { className: datatableRecipe({ className }), children: [(filterable || showCount || toolbar) && (_jsxs("div", { className: "datatable-toolbar", children: [filterable && (_jsxs("span", { className: "datatable-search", children: [_jsx(Search, { size: 15, strokeWidth: 1.75, "aria-hidden": "true" }), _jsx("input", { type: "search", placeholder: searchPlaceholder, value: query, onChange: (e) => setQuery(e.target.value), "aria-label": "Search table" })] })), showCount && (_jsx("span", { className: "datatable-count", children: rows.length === data.length
|
|
213
|
+
? `${data.length} ${data.length === 1 ? "row" : "rows"}`
|
|
214
|
+
: `${rows.length} of ${data.length}` })), toolbar] })), _jsxs(Table, { interactive: interactive, surface: surface, style: { minWidth }, scrollProps: {
|
|
215
|
+
onScroll: (e) => setScrolledX(e.currentTarget.scrollLeft > 0),
|
|
216
|
+
...(scrolledX ? { "data-scrolled-x": "" } : {}),
|
|
217
|
+
}, children: [_jsxs("colgroup", { children: [selectable && _jsx("col", { style: { width: CHECK_W } }), columns.map((col) => (_jsx("col", { style: { width: colWidth(col) } }, col.key)))] }), _jsx(TableHeader, { children: _jsxs(TableRow, { children: [selectable && (_jsx(TableHead, { className: "datatable-col-check", ...stickyCol(-1), children: _jsx("span", { className: "datatable-check", children: _jsx(Checkbox, { "aria-label": "Select all rows", checked: allSelected, indeterminate: someSelected, onChange: toggleAll }) }) })), columns.map((col, i) => {
|
|
218
|
+
const Icon = col.icon;
|
|
219
|
+
const inner = (_jsxs("span", { className: "datatable-th-inner", children: [Icon ? _jsx(Icon, { size: 14, strokeWidth: 1.75 }) : null, _jsx("span", { className: "datatable-th-label", children: col.header }), col.sortable ? _jsx(ChevronFor, { colKey: col.key }) : null] }));
|
|
220
|
+
return (_jsxs(TableHead, { align: alignFor(col), ...stickyCol(i), children: [col.sortable ? (_jsx("button", { type: "button", className: "datatable-sort", "data-sorted": sort?.key === col.key ? sort.dir : undefined, onClick: () => cycleSort(col.key), children: inner })) : (inner), col.resizable !== false && (_jsx("span", { className: "datatable-resize", "data-resizing": resizingKey === col.key ? "" : undefined, onPointerDown: (e) => startResize(col, e), onPointerMove: moveResize, onPointerUp: endResize }))] }, col.key));
|
|
221
|
+
})] }) }), _jsx(TableBody, { children: rows.length === 0 ? (_jsx(TableRow, { children: _jsx(TableCell, { colSpan: totalCols, children: _jsx("div", { className: "datatable-empty", children: empty }) }) })) : (rows.map((row) => (_jsxs(TableRow, { "data-selected": selected.has(row.id) ? "" : undefined, onClick: onRowClick ? () => onRowClick(row) : undefined, style: onRowClick ? { cursor: "pointer" } : undefined, children: [selectable && (_jsx(TableCell, { className: "datatable-col-check", ...stickyCol(-1), onClick: (e) => e.stopPropagation(), children: _jsx("span", { className: "datatable-check", children: _jsx(Checkbox, { "aria-label": `Select row ${row.id}`, checked: selected.has(row.id), onChange: () => toggleRow(row.id) }) }) })), columns.map((col, i) => {
|
|
222
|
+
const isEditing = editing?.id === row.id && editing?.key === col.key;
|
|
223
|
+
const value = cellValue(col, row);
|
|
224
|
+
const sticky = stickyCol(i);
|
|
225
|
+
if (isEditing) {
|
|
226
|
+
return (_jsx(TableCell, { align: alignFor(col), ...sticky, onClick: (e) => e.stopPropagation(), children: _jsx("input", { className: "datatable-edit",
|
|
227
|
+
// biome-ignore lint/a11y/noAutofocus: focus the field the moment it opens
|
|
228
|
+
autoFocus: true, defaultValue: asText(value), "aria-label": `Edit ${col.key}`, onKeyDown: (e) => {
|
|
229
|
+
if (e.key === "Enter")
|
|
230
|
+
commitEdit(row.id, col.key, e.currentTarget.value);
|
|
231
|
+
else if (e.key === "Escape")
|
|
232
|
+
setEditing(null);
|
|
233
|
+
}, onBlur: (e) => commitEdit(row.id, col.key, e.currentTarget.value) }) }, col.key));
|
|
234
|
+
}
|
|
235
|
+
return (_jsx(TableCell, { align: alignFor(col), ...sticky, className: col.editable ? "datatable-editable" : undefined, onClick: col.editable
|
|
236
|
+
? (e) => {
|
|
237
|
+
e.stopPropagation();
|
|
238
|
+
setEditing({ id: row.id, key: col.key });
|
|
239
|
+
}
|
|
240
|
+
: undefined, children: col.render
|
|
241
|
+
? col.render(value, row)
|
|
242
|
+
: renderTyped(col, col.format ? col.format(value, row) : value, avatarTone) }, col.key));
|
|
243
|
+
})] }, row.id)))) }), (hasSummary || onAddRow) && (_jsxs(TableFooter, { children: [hasSummary && (_jsxs(TableRow, { children: [selectable && _jsx(TableCell, { ...stickyCol(-1) }), columns.map((col, i) => (_jsx(TableCell, { align: alignFor(col), ...stickyCol(i), children: col.summary ? col.summary(rows) : null }, col.key)))] })), onAddRow && (_jsx(TableRow, { children: _jsx(TableCell, { className: "datatable-addcell", colSpan: totalCols, children: _jsxs("button", { type: "button", className: "datatable-addrow", onClick: onAddRow, children: [_jsx(Plus, { size: 15, strokeWidth: 1.75, "aria-hidden": "true" }), addRowLabel] }) }) }))] }))] })] }));
|
|
244
|
+
}
|
|
245
|
+
DataTable.displayName = "DataTable";
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { defineRecipe, resolveRecipe } from "../../core/index.js";
|
|
2
|
+
import { contract as c } from "../../tokens/index.js";
|
|
3
|
+
// The feature-rich, config-driven data grid (sort / filter / selection /
|
|
4
|
+
// inline edit) built on the composable `Table` primitives. This recipe adds the
|
|
5
|
+
// toolbar, sortable header buttons, selection cells, selected-row tint, and the
|
|
6
|
+
// inline-edit input on top of the base `.table` styling.
|
|
7
|
+
const config = defineRecipe({
|
|
8
|
+
name: "datatable",
|
|
9
|
+
base: `display: flex; flex-direction: column; gap: ${c.space["2.5"]}; font-family: ${c.font.sans};
|
|
10
|
+
& .datatable-toolbar { display: flex; align-items: center; gap: ${c.space["2"]}; }
|
|
11
|
+
& .datatable-search { position: relative; flex: 1; max-width: 280px; display: inline-flex; align-items: center; }
|
|
12
|
+
& .datatable-search svg { position: absolute; left: ${c.space["2"]}; color: ${c.fgMuted}; pointer-events: none; }
|
|
13
|
+
& .datatable-search input { width: 100%; height: 32px; padding: 0 ${c.space["2"]} 0 ${c.space["6"]}; border: none; border-radius: ${c.radius.md}; background: ${c.bgSurface}; box-shadow: 0 0 2px rgba(28,40,64,0.18), 0 1px 3px rgba(0,0,0,0.04); font-family: inherit; font-size: ${c.text.lg}; color: ${c.fgPrimary}; outline: none; transition: box-shadow .15s; }
|
|
14
|
+
& .datatable-search input::placeholder { color: ${c.fgMuted}; }
|
|
15
|
+
& .datatable-search input:focus { box-shadow: inset 0 0 0 1px ${c.bgBrandSolid}; }
|
|
16
|
+
& .datatable-count { margin-left: auto; font-size: ${c.text.md}; color: ${c.fgMuted}; }
|
|
17
|
+
& .datatable-th-inner { display: inline-flex; align-items: center; gap: ${c.space["1.5"]}; width: 100%; height: 100%; }
|
|
18
|
+
& .datatable-th-inner > svg { flex-shrink: 0; color: ${c.fgMuted}; }
|
|
19
|
+
& .datatable-th-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
20
|
+
& .datatable-sort { display: inline-flex; align-items: center; gap: ${c.space["1.5"]}; width: 100%; height: 100%; margin: 0; padding: 0; border: none; background: none; font: inherit; letter-spacing: inherit; color: inherit; text-align: left; cursor: pointer; }
|
|
21
|
+
& th[data-align="right"] .datatable-sort { justify-content: flex-end; }
|
|
22
|
+
& .datatable-chevron { margin-left: auto; flex-shrink: 0; color: ${c.fgMuted}; opacity: 0; transition: opacity .12s; }
|
|
23
|
+
& th[data-align="right"] .datatable-chevron { margin-left: 0; }
|
|
24
|
+
& .datatable-sort:hover .datatable-chevron { opacity: 0.6; }
|
|
25
|
+
& .datatable-sort[data-sorted] .datatable-chevron { opacity: 1; color: ${c.fgPrimary}; }
|
|
26
|
+
/* sticky first column(s) + horizontal scroll shadow — RecordsTable's feel */
|
|
27
|
+
& th[data-sticky], & td[data-sticky] { position: sticky; z-index: 1; background: ${c.bgSurface}; }
|
|
28
|
+
& th[data-sticky] { z-index: 3; }
|
|
29
|
+
& tbody tr[data-selected] td[data-sticky] { background: color-mix(in srgb, ${c.bgBrandSolid} 6%, ${c.bgSurface}); }
|
|
30
|
+
& tbody tr:hover td[data-sticky] { background: color-mix(in srgb, ${c.fgPrimary} 3%, ${c.bgSurface}); }
|
|
31
|
+
& .table-scroll[data-scrolled-x] [data-sticky-edge] { clip-path: inset(0 -14px 0 0); box-shadow: 8px 0 12px -8px rgba(28,40,64,0.22); }
|
|
32
|
+
/* add-row + summary footer */
|
|
33
|
+
& .datatable-addcell { padding: 0; border-top: none; }
|
|
34
|
+
& .datatable-addrow { display: flex; align-items: center; gap: ${c.space["2"]}; width: 100%; height: ${c.size.tableRow}; padding: 0 ${c.space["2"]}; border: none; border-top: 1px solid ${c.borderSubtle}; background: ${c.bgSurface}; color: ${c.fgMuted}; font-family: inherit; font-size: ${c.text.lg}; cursor: pointer; transition: background-color .12s; }
|
|
35
|
+
& .datatable-addrow:hover { background: ${c.bgRaised}; color: ${c.fgPrimary}; }
|
|
36
|
+
& .datatable-addrow svg { flex-shrink: 0; }
|
|
37
|
+
& .datatable-check { display: flex; align-items: center; justify-content: center; }
|
|
38
|
+
& .datatable-col-check { width: 40px; padding: 0; text-align: center; }
|
|
39
|
+
& tbody tr[data-selected] td { background: color-mix(in srgb, ${c.bgBrandSolid} 6%, ${c.bgSurface}); }
|
|
40
|
+
& tbody tr[data-selected]:hover td { background: color-mix(in srgb, ${c.bgBrandSolid} 10%, ${c.bgSurface}); }
|
|
41
|
+
& .datatable-editable:hover { background: color-mix(in srgb, ${c.fgPrimary} 4%, ${c.bgSurface}); cursor: text; }
|
|
42
|
+
& .datatable-edit { width: 100%; height: 28px; margin: 0; padding: 0 ${c.space["1.5"]}; border: none; border-radius: ${c.radius.sm}; background: ${c.bgSurface}; box-shadow: inset 0 0 0 1px ${c.bgBrandSolid}; font-family: inherit; font-size: ${c.text.lg}; color: ${c.fgPrimary}; outline: none; vertical-align: middle; }
|
|
43
|
+
& .datatable-empty { padding: ${c.space["8"]} ${c.space["3"]}; text-align: center; color: ${c.fgMuted}; font-size: ${c.text.lg}; }
|
|
44
|
+
/* fixed layout so column widths (and resize) are exact — like RecordsTable */
|
|
45
|
+
& table { table-layout: fixed; }
|
|
46
|
+
/* column resize grip */
|
|
47
|
+
& .datatable-resize { position: absolute; top: 0; right: -3px; width: 9px; height: 100%; cursor: col-resize; z-index: 6; touch-action: none; }
|
|
48
|
+
& .datatable-resize::after { content: ""; position: absolute; top: 0; left: 3px; width: 2px; height: 100%; background: ${c.bgBrandSolid}; opacity: 0; transition: opacity .12s; }
|
|
49
|
+
& .datatable-resize:hover::after, & .datatable-resize[data-resizing]::after { opacity: 1; }
|
|
50
|
+
/* typed cells — entity (avatar + name), colour-coded tags, numbers, dates */
|
|
51
|
+
& .datatable-entity { display: flex; align-items: center; gap: ${c.space["1.5"]}; min-width: 0; color: ${c.fgPrimary}; font-weight: ${c.weight.medium}; }
|
|
52
|
+
& .datatable-entity-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
53
|
+
& .datatable-avatar { width: ${c.size.icon}; height: ${c.size.icon}; border-radius: ${c.radius.sm}; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; font-size: 10px; line-height: 1; font-weight: ${c.weight.semibold}; text-transform: uppercase; color: ${c.fgOnBrand}; background: ${c.bgBrandSolid}; }
|
|
54
|
+
& .datatable-avatar[data-tone="success"] { background: ${c.bgSuccess}; } & .datatable-avatar[data-tone="warning"] { background: ${c.bgWarning}; } & .datatable-avatar[data-tone="danger"] { background: ${c.bgDanger}; } & .datatable-avatar[data-tone="purple"] { background: ${c.bgPurple}; } & .datatable-avatar[data-tone="cyan"] { background: ${c.bgCyan}; } & .datatable-avatar[data-tone="orange"] { background: ${c.bgOrange}; }
|
|
55
|
+
& .datatable-avatar img { width: 100%; height: 100%; border-radius: inherit; object-fit: cover; }
|
|
56
|
+
& .datatable-tags { display: flex; align-items: center; gap: ${c.space["1"]}; overflow: hidden; }
|
|
57
|
+
& .datatable-tag { display: inline-flex; align-items: center; height: 22px; padding: 0 ${c.space["1"]}; border-radius: 7px; font-size: ${c.text.lg}; line-height: 20px; font-weight: ${c.weight.medium}; white-space: nowrap; background: color-mix(in srgb, ${c.fgPrimary} 6%, transparent); color: color-mix(in srgb, ${c.fgPrimary} 82%, transparent); }
|
|
58
|
+
& .datatable-tag[data-tone="brand"] { background: color-mix(in srgb, ${c.bgBrandSolid} 14%, transparent); color: color-mix(in srgb, ${c.bgBrandSolid} 82%, ${c.fgPrimary}); }
|
|
59
|
+
& .datatable-tag[data-tone="success"] { background: color-mix(in srgb, ${c.bgSuccess} 16%, transparent); color: color-mix(in srgb, ${c.bgSuccess} 78%, ${c.fgPrimary}); }
|
|
60
|
+
& .datatable-tag[data-tone="warning"] { background: color-mix(in srgb, ${c.bgWarning} 18%, transparent); color: color-mix(in srgb, ${c.bgWarning} 82%, ${c.fgPrimary}); }
|
|
61
|
+
& .datatable-tag[data-tone="danger"] { background: color-mix(in srgb, ${c.bgDanger} 15%, transparent); color: color-mix(in srgb, ${c.bgDanger} 80%, ${c.fgPrimary}); }
|
|
62
|
+
& .datatable-tag[data-tone="purple"] { background: color-mix(in srgb, ${c.bgPurple} 16%, transparent); color: color-mix(in srgb, ${c.bgPurple} 80%, ${c.fgPrimary}); }
|
|
63
|
+
& .datatable-tag[data-tone="cyan"] { background: color-mix(in srgb, ${c.bgCyan} 18%, transparent); color: color-mix(in srgb, ${c.bgCyan} 82%, ${c.fgPrimary}); }
|
|
64
|
+
& .datatable-tag[data-tone="orange"] { background: color-mix(in srgb, ${c.bgOrange} 16%, transparent); color: color-mix(in srgb, ${c.bgOrange} 82%, ${c.fgPrimary}); }
|
|
65
|
+
& .datatable-num { font-variant-numeric: tabular-nums; }
|
|
66
|
+
& .datatable-muted { color: ${c.fgMuted}; }`,
|
|
67
|
+
variants: {},
|
|
68
|
+
defaultVariants: {},
|
|
69
|
+
compoundVariants: [],
|
|
70
|
+
});
|
|
71
|
+
export const datatableRecipe = resolveRecipe(config);
|
|
72
|
+
export default config;
|