@gram-ai/elements 1.27.3 → 1.27.5
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 +72 -60
- package/README.typedoc.md +6 -6
- package/bin/cli.js +74 -74
- package/dist/compat-shims-CO9JXXV4.cjs.map +1 -1
- package/dist/{compat-shims-BPJ7Q68c.js → compat-shims-DxtUrORi.js} +4 -2
- package/dist/compat-shims-DxtUrORi.js.map +1 -0
- package/dist/components/ShareButton/index.d.ts +2 -2
- package/dist/components/assistant-ui/message-feedback.d.ts +1 -1
- package/dist/components/assistant-ui/tooltip-icon-button.d.ts +2 -2
- package/dist/components/ui/avatar.d.ts +2 -2
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/components/ui/calendar.d.ts +1 -1
- package/dist/components/ui/collapsible.d.ts +1 -1
- package/dist/components/ui/dialog.d.ts +4 -4
- package/dist/components/ui/popover.d.ts +2 -2
- package/dist/components/ui/skeleton.d.ts +1 -1
- package/dist/components/ui/time-range-picker.d.ts +4 -2
- package/dist/components/ui/tool-ui.d.ts +7 -7
- package/dist/components/ui/tooltip.d.ts +2 -2
- package/dist/contexts/ConnectionStatusContext.d.ts +1 -1
- package/dist/elements.cjs +1 -1
- package/dist/elements.css +1 -1
- package/dist/elements.js +2 -2
- package/dist/hooks/useDensity.d.ts +73 -73
- package/dist/hooks/useMCPTools.d.ts +1 -1
- package/dist/hooks/useRadius.d.ts +1 -1
- package/dist/{index-BpJstUh1.cjs → index-C4bFBGfl.cjs} +4 -4
- package/dist/{index-BpJstUh1.cjs.map → index-C4bFBGfl.cjs.map} +1 -1
- package/dist/{index-CUitXazZ.js → index-D93pV0_o.js} +55 -55
- package/dist/{index-CUitXazZ.js.map → index-D93pV0_o.js.map} +1 -1
- package/dist/{index-DBrhzauj.js → index-DuCQRbcQ.js} +6386 -6337
- package/dist/index-DuCQRbcQ.js.map +1 -0
- package/dist/{index-DxfW52oA.cjs → index-y_PNN5vK.cjs} +64 -46
- package/dist/index-y_PNN5vK.cjs.map +1 -0
- package/dist/lib/cassette.d.ts +4 -4
- package/dist/lib/errorTracking.d.ts +1 -1
- package/dist/lib/messageConverter.d.ts +1 -1
- package/dist/lib/models.d.ts +1 -1
- package/dist/plugins/chart/ui/bar-chart.d.ts +1 -1
- package/dist/plugins/generative-ui/ui/accordion-wrapper.d.ts +2 -2
- package/dist/plugins/generative-ui/ui/accordion.d.ts +1 -1
- package/dist/plugins/generative-ui/ui/action-button.d.ts +2 -2
- package/dist/plugins/generative-ui/ui/alert-wrapper.d.ts +1 -1
- package/dist/plugins/generative-ui/ui/alert.d.ts +4 -4
- package/dist/plugins/generative-ui/ui/avatar.d.ts +5 -5
- package/dist/plugins/generative-ui/ui/badge.d.ts +2 -2
- package/dist/plugins/generative-ui/ui/button-wrapper.d.ts +2 -2
- package/dist/plugins/generative-ui/ui/button.d.ts +2 -2
- package/dist/plugins/generative-ui/ui/card-wrapper.d.ts +2 -2
- package/dist/plugins/generative-ui/ui/card.d.ts +8 -8
- package/dist/plugins/generative-ui/ui/checkbox.d.ts +1 -1
- package/dist/plugins/generative-ui/ui/data-table.d.ts +2 -2
- package/dist/plugins/generative-ui/ui/dialog.d.ts +3 -3
- package/dist/plugins/generative-ui/ui/dropdown-menu.d.ts +3 -3
- package/dist/plugins/generative-ui/ui/grid.d.ts +3 -3
- package/dist/plugins/generative-ui/ui/input-wrapper.d.ts +1 -1
- package/dist/plugins/generative-ui/ui/input.d.ts +2 -2
- package/dist/plugins/generative-ui/ui/label.d.ts +1 -1
- package/dist/plugins/generative-ui/ui/metric.d.ts +3 -3
- package/dist/plugins/generative-ui/ui/pagination.d.ts +6 -6
- package/dist/plugins/generative-ui/ui/popover.d.ts +4 -4
- package/dist/plugins/generative-ui/ui/progress.d.ts +2 -2
- package/dist/plugins/generative-ui/ui/radio-group.d.ts +1 -1
- package/dist/plugins/generative-ui/ui/select.d.ts +2 -2
- package/dist/plugins/generative-ui/ui/separator.d.ts +1 -1
- package/dist/plugins/generative-ui/ui/skeleton.d.ts +1 -1
- package/dist/plugins/generative-ui/ui/stack.d.ts +6 -6
- package/dist/plugins/generative-ui/ui/switch.d.ts +2 -2
- package/dist/plugins/generative-ui/ui/table.d.ts +9 -9
- package/dist/plugins/generative-ui/ui/tabs-wrapper.d.ts +1 -1
- package/dist/plugins/generative-ui/ui/tabs.d.ts +1 -1
- package/dist/plugins/generative-ui/ui/text.d.ts +3 -3
- package/dist/plugins/generative-ui/ui/textarea.d.ts +2 -2
- package/dist/plugins/generative-ui/ui/tooltip.d.ts +1 -1
- package/dist/plugins.cjs +1 -1
- package/dist/plugins.js +1 -1
- package/dist/{profiler-D6ndqfsd.js → profiler-FpBY9eRv.js} +2 -2
- package/dist/{profiler-D6ndqfsd.js.map → profiler-FpBY9eRv.js.map} +1 -1
- package/dist/{profiler-DhnzZ34c.cjs → profiler-_mthyjvo.cjs} +2 -2
- package/dist/{profiler-DhnzZ34c.cjs.map → profiler-_mthyjvo.cjs.map} +1 -1
- package/dist/react-shim.js +1 -1
- package/dist/server/express.cjs.map +1 -1
- package/dist/server/express.js.map +1 -1
- package/dist/{startRecording-BwXmdmy1.cjs → startRecording-NJcpiHw-.cjs} +2 -2
- package/dist/{startRecording-BwXmdmy1.cjs.map → startRecording-NJcpiHw-.cjs.map} +1 -1
- package/dist/{startRecording-B_9CRZ_P.js → startRecording-r5MXQ2Dm.js} +2 -2
- package/dist/{startRecording-B_9CRZ_P.js.map → startRecording-r5MXQ2Dm.js.map} +1 -1
- package/dist/types/index.d.ts +2 -2
- package/package.json +1 -5
- package/src/compat-plugin.ts +14 -14
- package/src/compat-shims.ts +33 -31
- package/src/compat.test.ts +48 -48
- package/src/compat.ts +6 -6
- package/src/components/Chat/index.tsx +17 -17
- package/src/components/Chat/stories/Charts.stories.tsx +98 -98
- package/src/components/Chat/stories/Composer.stories.tsx +15 -15
- package/src/components/Chat/stories/ConnectionConfiguration.stories.tsx +44 -44
- package/src/components/Chat/stories/CustomComponents.stories.tsx +17 -17
- package/src/components/Chat/stories/Density.stories.tsx +20 -20
- package/src/components/Chat/stories/ErrorBoundary.stories.tsx +47 -47
- package/src/components/Chat/stories/FrontendTools.stories.tsx +39 -39
- package/src/components/Chat/stories/GenerativeUI.stories.tsx +48 -48
- package/src/components/Chat/stories/MessageFeedback.stories.tsx +52 -52
- package/src/components/Chat/stories/Modal.stories.tsx +28 -28
- package/src/components/Chat/stories/Model.stories.tsx +11 -11
- package/src/components/Chat/stories/Radius.stories.tsx +20 -20
- package/src/components/Chat/stories/Sidecar.stories.tsx +13 -13
- package/src/components/Chat/stories/StyleIsolation.stories.tsx +11 -11
- package/src/components/Chat/stories/Theme.stories.tsx +25 -25
- package/src/components/Chat/stories/Thread.stories.tsx +25 -25
- package/src/components/Chat/stories/ToolApproval.stories.tsx +55 -55
- package/src/components/Chat/stories/ToolMentions.stories.tsx +17 -17
- package/src/components/Chat/stories/Tools.stories.tsx +88 -88
- package/src/components/Chat/stories/Variants.stories.tsx +32 -32
- package/src/components/Chat/stories/Welcome.stories.tsx +14 -14
- package/src/components/ChatHistory.tsx +7 -7
- package/src/components/FrontendTools/index.tsx +5 -5
- package/src/components/Replay.stories.tsx +157 -157
- package/src/components/Replay.tsx +76 -73
- package/src/components/ShadowRoot.tsx +40 -40
- package/src/components/ShareButton/index.tsx +32 -32
- package/src/components/assistant-ui/assistant-modal.tsx +92 -87
- package/src/components/assistant-ui/assistant-sidecar.tsx +35 -35
- package/src/components/assistant-ui/attachment.tsx +80 -80
- package/src/components/assistant-ui/connection-status-indicator.tsx +33 -33
- package/src/components/assistant-ui/error-boundary.tsx +34 -34
- package/src/components/assistant-ui/follow-on-suggestions.tsx +26 -26
- package/src/components/assistant-ui/markdown-text.tsx +69 -69
- package/src/components/assistant-ui/mentioned-tools-badges.tsx +38 -38
- package/src/components/assistant-ui/message-feedback.tsx +74 -61
- package/src/components/assistant-ui/reasoning.tsx +83 -83
- package/src/components/assistant-ui/thread-list.tsx +45 -45
- package/src/components/assistant-ui/thread.tsx +278 -278
- package/src/components/assistant-ui/tool-fallback.tsx +37 -37
- package/src/components/assistant-ui/tool-group.tsx +26 -26
- package/src/components/assistant-ui/tool-mention-autocomplete.tsx +122 -122
- package/src/components/assistant-ui/tooltip-icon-button.tsx +18 -18
- package/src/components/ui/avatar.tsx +12 -12
- package/src/components/ui/button.tsx +12 -12
- package/src/components/ui/buttonVariants.ts +17 -17
- package/src/components/ui/calendar.tsx +106 -106
- package/src/components/ui/charts.stories.tsx +56 -56
- package/src/components/ui/collapsible.tsx +5 -5
- package/src/components/ui/dialog.tsx +30 -30
- package/src/components/ui/generative-ui.stories.tsx +200 -200
- package/src/components/ui/generative-ui.tsx +26 -26
- package/src/components/ui/popover.tsx +14 -14
- package/src/components/ui/skeleton.tsx +5 -5
- package/src/components/ui/time-range-picker.stories.tsx +80 -80
- package/src/components/ui/time-range-picker.tsx +272 -235
- package/src/components/ui/tool-ui.stories.tsx +37 -37
- package/src/components/ui/tool-ui.tsx +221 -215
- package/src/components/ui/tooltip.tsx +15 -15
- package/src/constants/tailwind.ts +1 -1
- package/src/contexts/ChatIdContext.tsx +7 -7
- package/src/contexts/ConnectionStatusContext.tsx +64 -64
- package/src/contexts/ElementsProvider.tsx +222 -211
- package/src/contexts/ReplayContext.ts +3 -3
- package/src/contexts/ToolApprovalContext.tsx +54 -54
- package/src/contexts/ToolExecutionContext.tsx +34 -34
- package/src/contexts/contexts.ts +7 -7
- package/src/contexts/portal-container-context.ts +2 -2
- package/src/contexts/portal-container.tsx +7 -7
- package/src/embedded.ts +1 -1
- package/src/global.css +25 -25
- package/src/hooks/useAuth.ts +72 -72
- package/src/hooks/useDensity.ts +79 -79
- package/src/hooks/useElements.ts +6 -6
- package/src/hooks/useExpanded.ts +12 -12
- package/src/hooks/useFollowOnSuggestions.ts +87 -82
- package/src/hooks/useGramThreadListAdapter.tsx +99 -99
- package/src/hooks/useMCPTools.ts +47 -47
- package/src/hooks/useModel.ts +14 -14
- package/src/hooks/usePluginComponents.ts +11 -11
- package/src/hooks/usePortalContainer.ts +5 -5
- package/src/hooks/useRadius.ts +23 -23
- package/src/hooks/useRecordCassette.ts +34 -34
- package/src/hooks/useSession.ts +11 -11
- package/src/hooks/useThemeProps.ts +13 -13
- package/src/hooks/useThreadId.ts +4 -4
- package/src/hooks/useToolApproval.ts +7 -7
- package/src/hooks/useToolMentions.ts +40 -40
- package/src/index.ts +26 -26
- package/src/lib/api.test.ts +61 -61
- package/src/lib/api.ts +4 -3
- package/src/lib/auth.ts +13 -13
- package/src/lib/cassette.ts +84 -84
- package/src/lib/easing.ts +1 -1
- package/src/lib/errorTracking.config.ts +5 -5
- package/src/lib/errorTracking.ts +29 -29
- package/src/lib/generative-ui.ts +7 -7
- package/src/lib/humanize.ts +3 -3
- package/src/lib/messageConverter.test.ts +130 -127
- package/src/lib/messageConverter.ts +196 -196
- package/src/lib/models.ts +21 -20
- package/src/lib/token.test.ts +56 -56
- package/src/lib/token.ts +14 -14
- package/src/lib/tool-mentions.ts +45 -45
- package/src/lib/tools.ts +66 -62
- package/src/lib/utils.ts +5 -5
- package/src/lib.d.ts +1 -1
- package/src/plugins/README.md +5 -5
- package/src/plugins/chart/catalog.ts +18 -18
- package/src/plugins/chart/chart.test.ts +31 -31
- package/src/plugins/chart/component.tsx +34 -34
- package/src/plugins/chart/index.ts +4 -4
- package/src/plugins/chart/ui/area-chart.tsx +42 -42
- package/src/plugins/chart/ui/bar-chart.tsx +46 -46
- package/src/plugins/chart/ui/donut-chart.tsx +48 -48
- package/src/plugins/chart/ui/index.ts +7 -7
- package/src/plugins/chart/ui/line-chart.tsx +43 -43
- package/src/plugins/chart/ui/pie-chart.tsx +44 -44
- package/src/plugins/chart/ui/radar-chart.tsx +33 -33
- package/src/plugins/chart/ui/scatter-chart.tsx +43 -43
- package/src/plugins/components/MacOSWindowFrame.tsx +15 -15
- package/src/plugins/components/PluginLoadingState.tsx +10 -10
- package/src/plugins/components/index.ts +1 -1
- package/src/plugins/generative-ui/catalog.ts +54 -54
- package/src/plugins/generative-ui/component.tsx +85 -85
- package/src/plugins/generative-ui/index.ts +4 -4
- package/src/plugins/generative-ui/ui/accordion-wrapper.tsx +16 -16
- package/src/plugins/generative-ui/ui/accordion.tsx +16 -16
- package/src/plugins/generative-ui/ui/action-button.tsx +28 -28
- package/src/plugins/generative-ui/ui/alert-wrapper.tsx +8 -8
- package/src/plugins/generative-ui/ui/alert.tsx +20 -20
- package/src/plugins/generative-ui/ui/avatar-wrapper.tsx +7 -7
- package/src/plugins/generative-ui/ui/avatar.tsx +30 -30
- package/src/plugins/generative-ui/ui/badge.tsx +22 -22
- package/src/plugins/generative-ui/ui/button-wrapper.tsx +12 -12
- package/src/plugins/generative-ui/ui/button.tsx +28 -28
- package/src/plugins/generative-ui/ui/card-wrapper.tsx +8 -8
- package/src/plugins/generative-ui/ui/card.tsx +27 -27
- package/src/plugins/generative-ui/ui/checkbox-wrapper.tsx +9 -9
- package/src/plugins/generative-ui/ui/checkbox.tsx +9 -9
- package/src/plugins/generative-ui/ui/data-table.tsx +8 -8
- package/src/plugins/generative-ui/ui/dialog.tsx +31 -31
- package/src/plugins/generative-ui/ui/dropdown-menu.tsx +44 -44
- package/src/plugins/generative-ui/ui/grid.tsx +12 -12
- package/src/plugins/generative-ui/ui/index.ts +40 -40
- package/src/plugins/generative-ui/ui/input-wrapper.tsx +11 -11
- package/src/plugins/generative-ui/ui/input.tsx +9 -9
- package/src/plugins/generative-ui/ui/label.tsx +8 -8
- package/src/plugins/generative-ui/ui/list.tsx +11 -11
- package/src/plugins/generative-ui/ui/metric.tsx +23 -23
- package/src/plugins/generative-ui/ui/pagination.tsx +28 -28
- package/src/plugins/generative-ui/ui/popover.tsx +21 -21
- package/src/plugins/generative-ui/ui/progress.tsx +13 -13
- package/src/plugins/generative-ui/ui/radio-group.tsx +12 -12
- package/src/plugins/generative-ui/ui/select-wrapper.tsx +7 -7
- package/src/plugins/generative-ui/ui/select.tsx +37 -37
- package/src/plugins/generative-ui/ui/separator.tsx +9 -9
- package/src/plugins/generative-ui/ui/skeleton-wrapper.tsx +10 -10
- package/src/plugins/generative-ui/ui/skeleton.tsx +5 -5
- package/src/plugins/generative-ui/ui/stack.tsx +28 -28
- package/src/plugins/generative-ui/ui/switch.tsx +11 -11
- package/src/plugins/generative-ui/ui/table.tsx +32 -32
- package/src/plugins/generative-ui/ui/tabs-wrapper.tsx +11 -11
- package/src/plugins/generative-ui/ui/tabs.tsx +26 -26
- package/src/plugins/generative-ui/ui/text.tsx +12 -12
- package/src/plugins/generative-ui/ui/textarea.tsx +7 -7
- package/src/plugins/generative-ui/ui/tooltip.tsx +12 -12
- package/src/plugins/index.ts +7 -7
- package/src/react-shim.ts +6 -6
- package/src/server/bun.ts +12 -12
- package/src/server/core.ts +25 -25
- package/src/server/express.ts +17 -15
- package/src/server/fastify.ts +14 -14
- package/src/server/hono.ts +9 -9
- package/src/server/nextjs.ts +12 -12
- package/src/server/tanstack-start.ts +12 -12
- package/src/server.ts +27 -27
- package/src/storybook.d.ts +4 -4
- package/src/types/index.ts +122 -122
- package/src/types/plugins.ts +7 -7
- package/src/vite-env.d.ts +12 -12
- package/dist/compat-shims-BPJ7Q68c.js.map +0 -1
- package/dist/index-DBrhzauj.js.map +0 -1
- package/dist/index-DxfW52oA.cjs.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
2
|
|
|
3
|
-
import { useDensity } from
|
|
4
|
-
import { cn } from
|
|
5
|
-
import { isJsonRenderTree, type JsonRenderNode } from
|
|
6
|
-
import { AlertCircleIcon } from
|
|
7
|
-
import { FC, useMemo } from
|
|
3
|
+
import { useDensity } from "@/hooks/useDensity";
|
|
4
|
+
import { cn } from "@/lib/utils";
|
|
5
|
+
import { isJsonRenderTree, type JsonRenderNode } from "@/lib/generative-ui";
|
|
6
|
+
import { AlertCircleIcon } from "lucide-react";
|
|
7
|
+
import { FC, useMemo } from "react";
|
|
8
8
|
|
|
9
9
|
// Import all components from the generative-ui plugin ui directory
|
|
10
10
|
import {
|
|
@@ -30,13 +30,13 @@ import {
|
|
|
30
30
|
TabsWrapper,
|
|
31
31
|
TabContentWrapper,
|
|
32
32
|
Text,
|
|
33
|
-
} from
|
|
33
|
+
} from "@/plugins/generative-ui/ui";
|
|
34
34
|
|
|
35
35
|
interface GenerativeUIProps {
|
|
36
36
|
/** The JSON content to render - can be a json-render tree or raw object */
|
|
37
|
-
content: unknown
|
|
37
|
+
content: unknown;
|
|
38
38
|
/** Additional class names */
|
|
39
|
-
className?: string
|
|
39
|
+
className?: string;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
@@ -76,29 +76,29 @@ const components: Record<string, FC<any>> = {
|
|
|
76
76
|
Input: InputWrapper,
|
|
77
77
|
Checkbox: CheckboxWrapper,
|
|
78
78
|
Select: SelectWrapper,
|
|
79
|
-
}
|
|
79
|
+
};
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
82
|
* Recursively render a json-render tree node
|
|
83
83
|
*/
|
|
84
84
|
function renderNode(node: JsonRenderNode, key?: number): React.ReactNode {
|
|
85
|
-
const Component = components[node.type]
|
|
85
|
+
const Component = components[node.type];
|
|
86
86
|
|
|
87
87
|
if (!Component) {
|
|
88
88
|
// Unknown component type - render as debug info
|
|
89
89
|
return (
|
|
90
|
-
<div key={key} className="text-muted-foreground
|
|
90
|
+
<div key={key} className="text-xs text-muted-foreground">
|
|
91
91
|
Unknown component: {node.type}
|
|
92
92
|
</div>
|
|
93
|
-
)
|
|
93
|
+
);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
// Recursively render children (ensure it's an array)
|
|
97
97
|
const children = Array.isArray(node.children)
|
|
98
98
|
? node.children.map((child, i) => renderNode(child, i))
|
|
99
|
-
: undefined
|
|
99
|
+
: undefined;
|
|
100
100
|
|
|
101
|
-
return <Component key={key} {...(node.props ?? {})} children={children}
|
|
101
|
+
return <Component key={key} {...(node.props ?? {})} children={children} />;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
/**
|
|
@@ -106,32 +106,32 @@ function renderNode(node: JsonRenderNode, key?: number): React.ReactNode {
|
|
|
106
106
|
* This is used by the generativeUI plugin to render `ui` code blocks.
|
|
107
107
|
*/
|
|
108
108
|
export const GenerativeUI: FC<GenerativeUIProps> = ({ content, className }) => {
|
|
109
|
-
const d = useDensity()
|
|
109
|
+
const d = useDensity();
|
|
110
110
|
|
|
111
111
|
// Check if content is a valid json-render tree
|
|
112
112
|
const tree = useMemo(() => {
|
|
113
113
|
if (isJsonRenderTree(content)) {
|
|
114
|
-
return content
|
|
114
|
+
return content;
|
|
115
115
|
}
|
|
116
|
-
return null
|
|
117
|
-
}, [content])
|
|
116
|
+
return null;
|
|
117
|
+
}, [content]);
|
|
118
118
|
|
|
119
119
|
if (!tree) {
|
|
120
120
|
return (
|
|
121
121
|
<div
|
|
122
122
|
className={cn(
|
|
123
|
-
|
|
124
|
-
d(
|
|
125
|
-
className
|
|
123
|
+
"flex items-center gap-2 text-sm text-muted-foreground",
|
|
124
|
+
d("p-md"),
|
|
125
|
+
className,
|
|
126
126
|
)}
|
|
127
127
|
>
|
|
128
128
|
<AlertCircleIcon className="size-4" />
|
|
129
129
|
<span>Invalid generative UI structure</span>
|
|
130
130
|
</div>
|
|
131
|
-
)
|
|
131
|
+
);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
return <div className={cn(
|
|
135
|
-
}
|
|
134
|
+
return <div className={cn("w-full", className)}>{renderNode(tree)}</div>;
|
|
135
|
+
};
|
|
136
136
|
|
|
137
|
-
export type { GenerativeUIProps }
|
|
137
|
+
export type { GenerativeUIProps };
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import * as PopoverPrimitive from
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
|
3
3
|
|
|
4
|
-
import { cn } from
|
|
5
|
-
import { usePortalContainer } from
|
|
4
|
+
import { cn } from "@/lib/utils";
|
|
5
|
+
import { usePortalContainer } from "@/hooks/usePortalContainer";
|
|
6
6
|
|
|
7
7
|
function Popover({
|
|
8
8
|
...props
|
|
9
9
|
}: React.ComponentProps<typeof PopoverPrimitive.Root>) {
|
|
10
|
-
return <PopoverPrimitive.Root data-slot="popover" {...props}
|
|
10
|
+
return <PopoverPrimitive.Root data-slot="popover" {...props} />;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
function PopoverTrigger({
|
|
14
14
|
...props
|
|
15
15
|
}: React.ComponentProps<typeof PopoverPrimitive.Trigger>) {
|
|
16
|
-
return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props}
|
|
16
|
+
return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
function PopoverContent({
|
|
20
20
|
className,
|
|
21
|
-
align =
|
|
21
|
+
align = "center",
|
|
22
22
|
sideOffset = 4,
|
|
23
23
|
container,
|
|
24
24
|
...props
|
|
25
25
|
}: React.ComponentProps<typeof PopoverPrimitive.Content> & {
|
|
26
|
-
container?: HTMLElement | null
|
|
26
|
+
container?: HTMLElement | null;
|
|
27
27
|
}) {
|
|
28
|
-
const portalContainer = usePortalContainer()
|
|
28
|
+
const portalContainer = usePortalContainer();
|
|
29
29
|
return (
|
|
30
30
|
<PopoverPrimitive.Portal container={container ?? portalContainer}>
|
|
31
31
|
<PopoverPrimitive.Content
|
|
@@ -33,19 +33,19 @@ function PopoverContent({
|
|
|
33
33
|
align={align}
|
|
34
34
|
sideOffset={sideOffset}
|
|
35
35
|
className={cn(
|
|
36
|
-
|
|
37
|
-
className
|
|
36
|
+
"z-[70] w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
|
|
37
|
+
className,
|
|
38
38
|
)}
|
|
39
39
|
{...props}
|
|
40
40
|
/>
|
|
41
41
|
</PopoverPrimitive.Portal>
|
|
42
|
-
)
|
|
42
|
+
);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
function PopoverAnchor({
|
|
46
46
|
...props
|
|
47
47
|
}: React.ComponentProps<typeof PopoverPrimitive.Anchor>) {
|
|
48
|
-
return <PopoverPrimitive.Anchor data-slot="popover-anchor" {...props}
|
|
48
|
+
return <PopoverPrimitive.Anchor data-slot="popover-anchor" {...props} />;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor }
|
|
51
|
+
export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { cn } from
|
|
1
|
+
import { cn } from "@/lib/utils";
|
|
2
2
|
|
|
3
|
-
function Skeleton({ className, ...props }: React.ComponentProps<
|
|
3
|
+
function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
|
|
4
4
|
return (
|
|
5
5
|
<div
|
|
6
6
|
data-slot="skeleton"
|
|
7
|
-
className={cn(
|
|
7
|
+
className={cn("animate-pulse rounded-md bg-accent", className)}
|
|
8
8
|
{...props}
|
|
9
9
|
/>
|
|
10
|
-
)
|
|
10
|
+
);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export { Skeleton }
|
|
13
|
+
export { Skeleton };
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from
|
|
2
|
-
import { useState } from
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import { useState } from "react";
|
|
3
3
|
import {
|
|
4
4
|
TimeRangePicker,
|
|
5
5
|
type TimeRange,
|
|
6
6
|
type DateRangePreset,
|
|
7
|
-
} from
|
|
7
|
+
} from "./time-range-picker";
|
|
8
8
|
|
|
9
9
|
const meta: Meta<typeof TimeRangePicker> = {
|
|
10
|
-
title:
|
|
10
|
+
title: "UI/TimeRangePicker",
|
|
11
11
|
component: TimeRangePicker,
|
|
12
|
-
tags: [
|
|
12
|
+
tags: ["autodocs"],
|
|
13
13
|
parameters: {
|
|
14
|
-
layout:
|
|
14
|
+
layout: "centered",
|
|
15
15
|
},
|
|
16
16
|
decorators: [
|
|
17
17
|
(Story) => (
|
|
18
|
-
<div className="gram-elements
|
|
18
|
+
<div className="gram-elements min-w-[400px] bg-background p-8 text-foreground">
|
|
19
19
|
<Story />
|
|
20
20
|
</div>
|
|
21
21
|
),
|
|
22
22
|
],
|
|
23
23
|
argTypes: {
|
|
24
24
|
showLive: {
|
|
25
|
-
control:
|
|
25
|
+
control: "boolean",
|
|
26
26
|
},
|
|
27
27
|
disabled: {
|
|
28
|
-
control:
|
|
28
|
+
control: "boolean",
|
|
29
29
|
},
|
|
30
30
|
timezone: {
|
|
31
|
-
control:
|
|
31
|
+
control: "text",
|
|
32
32
|
},
|
|
33
33
|
},
|
|
34
|
-
}
|
|
34
|
+
};
|
|
35
35
|
|
|
36
|
-
export default meta
|
|
37
|
-
type Story = StoryObj<typeof TimeRangePicker
|
|
36
|
+
export default meta;
|
|
37
|
+
type Story = StoryObj<typeof TimeRangePicker>;
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Default time range picker with preset badges and calendar.
|
|
@@ -42,103 +42,103 @@ type Story = StoryObj<typeof TimeRangePicker>
|
|
|
42
42
|
*/
|
|
43
43
|
export const Default: Story = {
|
|
44
44
|
render: () => {
|
|
45
|
-
const [preset, setPreset] = useState<DateRangePreset | null>(
|
|
46
|
-
const [customRange, setCustomRange] = useState<TimeRange | null>(null)
|
|
45
|
+
const [preset, setPreset] = useState<DateRangePreset | null>("7d");
|
|
46
|
+
const [customRange, setCustomRange] = useState<TimeRange | null>(null);
|
|
47
47
|
|
|
48
48
|
return (
|
|
49
49
|
<TimeRangePicker
|
|
50
50
|
preset={customRange ? null : preset}
|
|
51
51
|
customRange={customRange}
|
|
52
52
|
onPresetChange={(p) => {
|
|
53
|
-
setPreset(p)
|
|
54
|
-
setCustomRange(null)
|
|
53
|
+
setPreset(p);
|
|
54
|
+
setCustomRange(null);
|
|
55
55
|
}}
|
|
56
56
|
onCustomRangeChange={(from, to, label) => {
|
|
57
|
-
setCustomRange({ from, to })
|
|
58
|
-
setPreset(null)
|
|
59
|
-
console.log(
|
|
57
|
+
setCustomRange({ from, to });
|
|
58
|
+
setPreset(null);
|
|
59
|
+
console.log("Custom range:", { from, to, label });
|
|
60
60
|
}}
|
|
61
61
|
onClearCustomRange={() => {
|
|
62
|
-
setCustomRange(null)
|
|
63
|
-
setPreset(
|
|
62
|
+
setCustomRange(null);
|
|
63
|
+
setPreset("7d");
|
|
64
64
|
}}
|
|
65
65
|
/>
|
|
66
|
-
)
|
|
66
|
+
);
|
|
67
67
|
},
|
|
68
|
-
}
|
|
68
|
+
};
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* Time range picker with timezone indicator.
|
|
72
72
|
*/
|
|
73
73
|
export const WithTimezone: Story = {
|
|
74
74
|
render: () => {
|
|
75
|
-
const [preset, setPreset] = useState<DateRangePreset | null>(
|
|
76
|
-
const [customRange, setCustomRange] = useState<TimeRange | null>(null)
|
|
75
|
+
const [preset, setPreset] = useState<DateRangePreset | null>("30d");
|
|
76
|
+
const [customRange, setCustomRange] = useState<TimeRange | null>(null);
|
|
77
77
|
|
|
78
78
|
return (
|
|
79
79
|
<TimeRangePicker
|
|
80
80
|
preset={customRange ? null : preset}
|
|
81
81
|
customRange={customRange}
|
|
82
82
|
onPresetChange={(p) => {
|
|
83
|
-
setPreset(p)
|
|
84
|
-
setCustomRange(null)
|
|
83
|
+
setPreset(p);
|
|
84
|
+
setCustomRange(null);
|
|
85
85
|
}}
|
|
86
86
|
onCustomRangeChange={(from, to) => {
|
|
87
|
-
setCustomRange({ from, to })
|
|
88
|
-
setPreset(null)
|
|
87
|
+
setCustomRange({ from, to });
|
|
88
|
+
setPreset(null);
|
|
89
89
|
}}
|
|
90
90
|
onClearCustomRange={() => {
|
|
91
|
-
setCustomRange(null)
|
|
92
|
-
setPreset(
|
|
91
|
+
setCustomRange(null);
|
|
92
|
+
setPreset("30d");
|
|
93
93
|
}}
|
|
94
94
|
timezone="UTC-08:00"
|
|
95
95
|
/>
|
|
96
|
-
)
|
|
96
|
+
);
|
|
97
97
|
},
|
|
98
|
-
}
|
|
98
|
+
};
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
101
|
* With LIVE mode toggle enabled.
|
|
102
102
|
*/
|
|
103
103
|
export const WithLiveMode: Story = {
|
|
104
104
|
render: () => {
|
|
105
|
-
const [preset, setPreset] = useState<DateRangePreset | null>(
|
|
106
|
-
const [customRange, setCustomRange] = useState<TimeRange | null>(null)
|
|
107
|
-
const [isLive, setIsLive] = useState(true)
|
|
105
|
+
const [preset, setPreset] = useState<DateRangePreset | null>("15m");
|
|
106
|
+
const [customRange, setCustomRange] = useState<TimeRange | null>(null);
|
|
107
|
+
const [isLive, setIsLive] = useState(true);
|
|
108
108
|
|
|
109
109
|
return (
|
|
110
110
|
<TimeRangePicker
|
|
111
111
|
preset={customRange ? null : preset}
|
|
112
112
|
customRange={customRange}
|
|
113
113
|
onPresetChange={(p) => {
|
|
114
|
-
setPreset(p)
|
|
115
|
-
setCustomRange(null)
|
|
114
|
+
setPreset(p);
|
|
115
|
+
setCustomRange(null);
|
|
116
116
|
}}
|
|
117
117
|
onCustomRangeChange={(from, to) => {
|
|
118
|
-
setCustomRange({ from, to })
|
|
119
|
-
setPreset(null)
|
|
118
|
+
setCustomRange({ from, to });
|
|
119
|
+
setPreset(null);
|
|
120
120
|
}}
|
|
121
121
|
onClearCustomRange={() => {
|
|
122
|
-
setCustomRange(null)
|
|
123
|
-
setPreset(
|
|
122
|
+
setCustomRange(null);
|
|
123
|
+
setPreset("15m");
|
|
124
124
|
}}
|
|
125
125
|
showLive
|
|
126
126
|
isLive={isLive}
|
|
127
127
|
onLiveChange={setIsLive}
|
|
128
128
|
/>
|
|
129
|
-
)
|
|
129
|
+
);
|
|
130
130
|
},
|
|
131
|
-
}
|
|
131
|
+
};
|
|
132
132
|
|
|
133
133
|
/**
|
|
134
134
|
* Disabled state.
|
|
135
135
|
*/
|
|
136
136
|
export const Disabled: Story = {
|
|
137
137
|
args: {
|
|
138
|
-
preset:
|
|
138
|
+
preset: "7d",
|
|
139
139
|
disabled: true,
|
|
140
140
|
},
|
|
141
|
-
}
|
|
141
|
+
};
|
|
142
142
|
|
|
143
143
|
/**
|
|
144
144
|
* Full Datadog-style configuration with all features.
|
|
@@ -146,10 +146,10 @@ export const Disabled: Story = {
|
|
|
146
146
|
*/
|
|
147
147
|
export const DatadogStyle: Story = {
|
|
148
148
|
render: () => {
|
|
149
|
-
const [preset, setPreset] = useState<DateRangePreset | null>(
|
|
150
|
-
const [customRange, setCustomRange] = useState<TimeRange | null>(null)
|
|
151
|
-
const [customLabel, setCustomLabel] = useState<string | null>(null)
|
|
152
|
-
const [isLive, setIsLive] = useState(false)
|
|
149
|
+
const [preset, setPreset] = useState<DateRangePreset | null>("7d");
|
|
150
|
+
const [customRange, setCustomRange] = useState<TimeRange | null>(null);
|
|
151
|
+
const [customLabel, setCustomLabel] = useState<string | null>(null);
|
|
152
|
+
const [isLive, setIsLive] = useState(false);
|
|
153
153
|
|
|
154
154
|
return (
|
|
155
155
|
<div className="space-y-4">
|
|
@@ -158,26 +158,26 @@ export const DatadogStyle: Story = {
|
|
|
158
158
|
customRange={customRange}
|
|
159
159
|
customRangeLabel={customLabel}
|
|
160
160
|
onPresetChange={(p) => {
|
|
161
|
-
setPreset(p)
|
|
162
|
-
setCustomRange(null)
|
|
163
|
-
setCustomLabel(null)
|
|
161
|
+
setPreset(p);
|
|
162
|
+
setCustomRange(null);
|
|
163
|
+
setCustomLabel(null);
|
|
164
164
|
}}
|
|
165
165
|
onCustomRangeChange={(from, to, label) => {
|
|
166
|
-
setCustomRange({ from, to })
|
|
167
|
-
setPreset(null)
|
|
168
|
-
setCustomLabel(label || null)
|
|
166
|
+
setCustomRange({ from, to });
|
|
167
|
+
setPreset(null);
|
|
168
|
+
setCustomLabel(label || null);
|
|
169
169
|
}}
|
|
170
170
|
onClearCustomRange={() => {
|
|
171
|
-
setCustomRange(null)
|
|
172
|
-
setPreset(
|
|
173
|
-
setCustomLabel(null)
|
|
171
|
+
setCustomRange(null);
|
|
172
|
+
setPreset("7d");
|
|
173
|
+
setCustomLabel(null);
|
|
174
174
|
}}
|
|
175
175
|
showLive
|
|
176
176
|
isLive={isLive}
|
|
177
177
|
onLiveChange={setIsLive}
|
|
178
178
|
timezone="UTC-08:00"
|
|
179
179
|
/>
|
|
180
|
-
<div className="
|
|
180
|
+
<div className="rounded-md bg-muted p-3 text-xs text-muted-foreground">
|
|
181
181
|
<strong>Current state:</strong>
|
|
182
182
|
<pre className="mt-1 overflow-auto">
|
|
183
183
|
{JSON.stringify(
|
|
@@ -193,14 +193,14 @@ export const DatadogStyle: Story = {
|
|
|
193
193
|
isLive,
|
|
194
194
|
},
|
|
195
195
|
null,
|
|
196
|
-
2
|
|
196
|
+
2,
|
|
197
197
|
)}
|
|
198
198
|
</pre>
|
|
199
199
|
</div>
|
|
200
200
|
</div>
|
|
201
|
-
)
|
|
201
|
+
);
|
|
202
202
|
},
|
|
203
|
-
}
|
|
203
|
+
};
|
|
204
204
|
|
|
205
205
|
/**
|
|
206
206
|
* Natural language parsing demo.
|
|
@@ -213,13 +213,13 @@ export const DatadogStyle: Story = {
|
|
|
213
213
|
*/
|
|
214
214
|
export const NaturalLanguageParsing: Story = {
|
|
215
215
|
render: () => {
|
|
216
|
-
const [preset, setPreset] = useState<DateRangePreset | null>(
|
|
217
|
-
const [customRange, setCustomRange] = useState<TimeRange | null>(null)
|
|
218
|
-
const [customLabel, setCustomLabel] = useState<string | null>(null)
|
|
216
|
+
const [preset, setPreset] = useState<DateRangePreset | null>("30d");
|
|
217
|
+
const [customRange, setCustomRange] = useState<TimeRange | null>(null);
|
|
218
|
+
const [customLabel, setCustomLabel] = useState<string | null>(null);
|
|
219
219
|
|
|
220
220
|
return (
|
|
221
221
|
<div className="space-y-4">
|
|
222
|
-
<p className="text-muted-foreground
|
|
222
|
+
<p className="text-sm text-muted-foreground">
|
|
223
223
|
Try typing: "yesterday", "3 days ago", "last Wednesday", "January"
|
|
224
224
|
</p>
|
|
225
225
|
<TimeRangePicker
|
|
@@ -227,23 +227,23 @@ export const NaturalLanguageParsing: Story = {
|
|
|
227
227
|
customRange={customRange}
|
|
228
228
|
customRangeLabel={customLabel}
|
|
229
229
|
onPresetChange={(p) => {
|
|
230
|
-
setPreset(p)
|
|
231
|
-
setCustomRange(null)
|
|
232
|
-
setCustomLabel(null)
|
|
230
|
+
setPreset(p);
|
|
231
|
+
setCustomRange(null);
|
|
232
|
+
setCustomLabel(null);
|
|
233
233
|
}}
|
|
234
234
|
onCustomRangeChange={(from, to, label) => {
|
|
235
|
-
setCustomRange({ from, to })
|
|
236
|
-
setPreset(null)
|
|
237
|
-
setCustomLabel(label || null)
|
|
238
|
-
console.log(
|
|
235
|
+
setCustomRange({ from, to });
|
|
236
|
+
setPreset(null);
|
|
237
|
+
setCustomLabel(label || null);
|
|
238
|
+
console.log("AI parsed:", { from, to, label });
|
|
239
239
|
}}
|
|
240
240
|
onClearCustomRange={() => {
|
|
241
|
-
setCustomRange(null)
|
|
242
|
-
setPreset(
|
|
243
|
-
setCustomLabel(null)
|
|
241
|
+
setCustomRange(null);
|
|
242
|
+
setPreset("30d");
|
|
243
|
+
setCustomLabel(null);
|
|
244
244
|
}}
|
|
245
245
|
/>
|
|
246
246
|
</div>
|
|
247
|
-
)
|
|
247
|
+
);
|
|
248
248
|
},
|
|
249
|
-
}
|
|
249
|
+
};
|