@object-ui/components 0.5.0 → 2.0.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/.turbo/turbo-build.log +12 -25
- package/CHANGELOG.md +13 -0
- package/dist/index.css +1 -1
- package/dist/index.js +23366 -22221
- package/dist/index.umd.cjs +30 -30
- package/dist/src/custom/action-param-dialog.d.ts +21 -0
- package/dist/src/custom/index.d.ts +2 -0
- package/dist/src/custom/navigation-overlay.d.ts +50 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/renderers/action/action-button.d.ts +11 -0
- package/dist/src/renderers/action/action-group.d.ts +25 -0
- package/dist/src/renderers/action/action-icon.d.ts +10 -0
- package/dist/src/renderers/action/action-menu.d.ts +19 -0
- package/dist/src/renderers/action/index.d.ts +0 -0
- package/dist/src/renderers/action/resolve-icon.d.ts +6 -0
- package/package.json +9 -8
- package/src/__tests__/PageRendererRegions.test.tsx +664 -55
- package/src/__tests__/compliance.test.tsx +72 -0
- package/src/__tests__/navigation-overlay.test.tsx +273 -0
- package/src/__tests__/view-compliance.test.tsx +153 -0
- package/src/custom/action-param-dialog.tsx +264 -0
- package/src/custom/index.ts +2 -0
- package/src/custom/navigation-overlay.tsx +296 -0
- package/src/index.ts +1 -0
- package/src/renderers/action/action-button.tsx +147 -0
- package/src/renderers/action/action-group.tsx +270 -0
- package/src/renderers/action/action-icon.tsx +150 -0
- package/src/renderers/action/action-menu.tsx +203 -0
- package/src/renderers/action/index.ts +18 -0
- package/src/renderers/action/resolve-icon.ts +35 -0
- package/src/renderers/complex/__tests__/data-table-batch-editing.test.tsx +275 -0
- package/src/renderers/complex/__tests__/data-table-cell-renderer.test.tsx +120 -0
- package/src/renderers/complex/__tests__/data-table-editing.test.tsx +221 -0
- package/src/renderers/complex/data-table.tsx +242 -21
- package/src/renderers/form/form.tsx +23 -4
- package/src/renderers/index.ts +1 -0
- package/src/renderers/layout/page.tsx +416 -52
- package/src/renderers/navigation/sidebar.tsx +6 -0
- package/src/renderers/placeholders.tsx +2 -2
- package/src/stories/Introduction.mdx +54 -27
- package/src/stories/MockedData.stories.tsx +87 -37
- package/src/stories-json/accordion.stories.tsx +1 -1
- package/src/stories-json/aggrid.stories.tsx +1 -1
- package/src/stories-json/alert.stories.tsx +1 -1
- package/src/stories-json/aspect-ratio.stories.tsx +1 -1
- package/src/stories-json/avatar.stories.tsx +1 -1
- package/src/stories-json/badge.stories.tsx +1 -1
- package/src/stories-json/breadcrumb.stories.tsx +1 -1
- package/src/stories-json/button-group.stories.tsx +1 -1
- package/src/stories-json/button.stories.tsx +1 -1
- package/src/stories-json/calendar.stories.tsx +1 -1
- package/src/stories-json/card.stories.tsx +1 -1
- package/src/stories-json/carousel.stories.tsx +1 -1
- package/src/stories-json/charts.stories.tsx +1 -1
- package/src/stories-json/chatbot.stories.tsx +1 -1
- package/src/stories-json/code-editor.stories.tsx +1 -1
- package/src/stories-json/collapsible.stories.tsx +1 -1
- package/src/stories-json/controls.stories.tsx +1 -1
- package/src/stories-json/crm-live-data.stories.tsx +154 -0
- package/src/stories-json/data-table.stories.tsx +80 -4
- package/src/stories-json/data_display_extras.stories.tsx +1 -1
- package/src/stories-json/date-picker.stories.tsx +1 -1
- package/src/stories-json/detail-view.stories.tsx +1 -1
- package/src/stories-json/dialog.stories.tsx +1 -1
- package/src/stories-json/feedback_extras.stories.tsx +1 -1
- package/src/stories-json/feedback_others.stories.tsx +1 -1
- package/src/stories-json/form-variants.stories.tsx +210 -0
- package/src/stories-json/form_advanced.stories.tsx +1 -1
- package/src/stories-json/form_extras.stories.tsx +1 -1
- package/src/stories-json/grid.stories.tsx +1 -1
- package/src/stories-json/icon.stories.tsx +1 -1
- package/src/stories-json/input.stories.tsx +1 -1
- package/src/stories-json/kanban.stories.tsx +1 -1
- package/src/stories-json/layout_extended.stories.tsx +1 -1
- package/src/stories-json/layout_flex.stories.tsx +1 -1
- package/src/stories-json/list-view.stories.tsx +1 -1
- package/src/stories-json/markdown.stories.tsx +1 -1
- package/src/stories-json/menus.stories.tsx +1 -1
- package/src/stories-json/metric-card.stories.tsx +1 -1
- package/src/stories-json/navigation-menu.stories.tsx +1 -1
- package/src/stories-json/object-aggrid-advanced.stories.tsx +389 -0
- package/src/stories-json/object-aggrid.stories.tsx +1 -1
- package/src/stories-json/object-form.stories.tsx +1 -1
- package/src/stories-json/object-gantt.stories.tsx +1 -1
- package/src/stories-json/object-grid.stories.tsx +159 -1
- package/src/stories-json/object-map.stories.tsx +1 -1
- package/src/stories-json/object-view.stories.tsx +1 -1
- package/src/stories-json/overlay_extras.stories.tsx +1 -1
- package/src/stories-json/overlay_others.stories.tsx +1 -1
- package/src/stories-json/resizable.stories.tsx +1 -1
- package/src/stories-json/select.stories.tsx +1 -1
- package/src/stories-json/separator.stories.tsx +1 -1
- package/src/stories-json/statistic.stories.tsx +1 -1
- package/src/stories-json/tabs.stories.tsx +1 -1
- package/src/stories-json/timeline.stories.tsx +1 -1
- package/src/stories-json/typography.stories.tsx +1 -1
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* action:button — Smart action button driven by ActionSchema.
|
|
11
|
+
*
|
|
12
|
+
* Renders a Shadcn Button wired to the ActionRunner. Supports:
|
|
13
|
+
* - All 5 spec action types (script, url, modal, flow, api)
|
|
14
|
+
* - Conditional visibility & enabled state
|
|
15
|
+
* - Loading indicator during async execution
|
|
16
|
+
* - Icon rendering via Lucide
|
|
17
|
+
* - Variant / size / className overrides from schema
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import React, { forwardRef, useCallback, useState } from 'react';
|
|
21
|
+
import { ComponentRegistry } from '@object-ui/core';
|
|
22
|
+
import type { ActionSchema } from '@object-ui/types';
|
|
23
|
+
import { useAction } from '@object-ui/react';
|
|
24
|
+
import { useCondition } from '@object-ui/react';
|
|
25
|
+
import { Button } from '../../ui';
|
|
26
|
+
import { cn } from '../../lib/utils';
|
|
27
|
+
import { Loader2 } from 'lucide-react';
|
|
28
|
+
import { resolveIcon } from './resolve-icon';
|
|
29
|
+
|
|
30
|
+
export interface ActionButtonProps {
|
|
31
|
+
schema: ActionSchema & { type: string; className?: string };
|
|
32
|
+
className?: string;
|
|
33
|
+
/** Override context for this specific action */
|
|
34
|
+
context?: Record<string, any>;
|
|
35
|
+
[key: string]: any;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const ActionButtonRenderer = forwardRef<HTMLButtonElement, ActionButtonProps>(
|
|
39
|
+
({ schema, className, context: localContext, ...props }, ref) => {
|
|
40
|
+
const {
|
|
41
|
+
'data-obj-id': dataObjId,
|
|
42
|
+
'data-obj-type': dataObjType,
|
|
43
|
+
style,
|
|
44
|
+
...rest
|
|
45
|
+
} = props;
|
|
46
|
+
|
|
47
|
+
const { execute } = useAction();
|
|
48
|
+
const [loading, setLoading] = useState(false);
|
|
49
|
+
|
|
50
|
+
// Evaluate visibility and enabled conditions
|
|
51
|
+
const isVisible = useCondition(schema.visible ? `\${${schema.visible}}` : undefined);
|
|
52
|
+
const isEnabled = useCondition(schema.enabled ? `\${${schema.enabled}}` : undefined);
|
|
53
|
+
|
|
54
|
+
// Resolve icon
|
|
55
|
+
const Icon = resolveIcon(schema.icon);
|
|
56
|
+
|
|
57
|
+
// Map schema variant to Shadcn button variant
|
|
58
|
+
const variant = schema.variant === 'primary' ? 'default' : (schema.variant || 'default');
|
|
59
|
+
const size = schema.size === 'md' ? 'default' : (schema.size || 'default');
|
|
60
|
+
|
|
61
|
+
const handleClick = useCallback(async () => {
|
|
62
|
+
if (loading) return;
|
|
63
|
+
setLoading(true);
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
await execute({
|
|
67
|
+
type: schema.type,
|
|
68
|
+
name: schema.name,
|
|
69
|
+
target: schema.target,
|
|
70
|
+
execute: schema.execute,
|
|
71
|
+
endpoint: schema.endpoint,
|
|
72
|
+
method: schema.method,
|
|
73
|
+
params: schema.params as Record<string, any> | undefined,
|
|
74
|
+
confirmText: schema.confirmText,
|
|
75
|
+
successMessage: schema.successMessage,
|
|
76
|
+
errorMessage: schema.errorMessage,
|
|
77
|
+
refreshAfter: schema.refreshAfter,
|
|
78
|
+
toast: schema.toast,
|
|
79
|
+
...localContext,
|
|
80
|
+
});
|
|
81
|
+
} finally {
|
|
82
|
+
setLoading(false);
|
|
83
|
+
}
|
|
84
|
+
}, [schema, execute, loading, localContext]);
|
|
85
|
+
|
|
86
|
+
if (schema.visible && !isVisible) return null;
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<Button
|
|
90
|
+
ref={ref}
|
|
91
|
+
type="button"
|
|
92
|
+
variant={variant as any}
|
|
93
|
+
size={size as any}
|
|
94
|
+
className={cn(schema.className, className)}
|
|
95
|
+
disabled={(schema.enabled ? !isEnabled : false) || loading}
|
|
96
|
+
onClick={handleClick}
|
|
97
|
+
{...rest}
|
|
98
|
+
{...{ 'data-obj-id': dataObjId, 'data-obj-type': dataObjType, style }}
|
|
99
|
+
>
|
|
100
|
+
{loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
|
101
|
+
{!loading && Icon && <Icon className={cn('h-4 w-4', schema.label && 'mr-2')} />}
|
|
102
|
+
{schema.label}
|
|
103
|
+
</Button>
|
|
104
|
+
);
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
ActionButtonRenderer.displayName = 'ActionButtonRenderer';
|
|
109
|
+
|
|
110
|
+
ComponentRegistry.register('action:button', ActionButtonRenderer, {
|
|
111
|
+
namespace: 'action',
|
|
112
|
+
label: 'Action Button',
|
|
113
|
+
inputs: [
|
|
114
|
+
{ name: 'name', type: 'string', label: 'Action Name' },
|
|
115
|
+
{ name: 'label', type: 'string', label: 'Label', defaultValue: 'Action' },
|
|
116
|
+
{ name: 'icon', type: 'string', label: 'Icon' },
|
|
117
|
+
{
|
|
118
|
+
name: 'type',
|
|
119
|
+
type: 'enum',
|
|
120
|
+
label: 'Action Type',
|
|
121
|
+
enum: ['script', 'url', 'modal', 'flow', 'api'],
|
|
122
|
+
defaultValue: 'script',
|
|
123
|
+
},
|
|
124
|
+
{ name: 'target', type: 'string', label: 'Target' },
|
|
125
|
+
{
|
|
126
|
+
name: 'variant',
|
|
127
|
+
type: 'enum',
|
|
128
|
+
label: 'Variant',
|
|
129
|
+
enum: ['default', 'primary', 'secondary', 'destructive', 'outline', 'ghost'],
|
|
130
|
+
defaultValue: 'default',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: 'size',
|
|
134
|
+
type: 'enum',
|
|
135
|
+
label: 'Size',
|
|
136
|
+
enum: ['sm', 'md', 'lg'],
|
|
137
|
+
defaultValue: 'md',
|
|
138
|
+
},
|
|
139
|
+
{ name: 'className', type: 'string', label: 'CSS Class', advanced: true },
|
|
140
|
+
],
|
|
141
|
+
defaultProps: {
|
|
142
|
+
label: 'Action',
|
|
143
|
+
type: 'script',
|
|
144
|
+
variant: 'default',
|
|
145
|
+
size: 'md',
|
|
146
|
+
},
|
|
147
|
+
});
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* action:group — Toolbar or button group for organizing related actions.
|
|
11
|
+
*
|
|
12
|
+
* Supports two display modes:
|
|
13
|
+
* - 'inline': Renders all actions as a horizontal button row
|
|
14
|
+
* - 'dropdown': Renders a primary button + dropdown for overflow
|
|
15
|
+
*
|
|
16
|
+
* Filters actions by location when `location` prop is provided.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import React, { forwardRef, useCallback, useState } from 'react';
|
|
20
|
+
import { ComponentRegistry } from '@object-ui/core';
|
|
21
|
+
import type { ActionSchema, ActionGroup, ActionLocation } from '@object-ui/types';
|
|
22
|
+
import { useAction } from '@object-ui/react';
|
|
23
|
+
import { useCondition } from '@object-ui/react';
|
|
24
|
+
import { Button } from '../../ui';
|
|
25
|
+
import {
|
|
26
|
+
DropdownMenu,
|
|
27
|
+
DropdownMenuContent,
|
|
28
|
+
DropdownMenuItem,
|
|
29
|
+
DropdownMenuSeparator,
|
|
30
|
+
DropdownMenuTrigger,
|
|
31
|
+
} from '../../ui';
|
|
32
|
+
import { cn } from '../../lib/utils';
|
|
33
|
+
import { Loader2, ChevronDown } from 'lucide-react';
|
|
34
|
+
import { resolveIcon } from './resolve-icon';
|
|
35
|
+
|
|
36
|
+
export interface ActionGroupSchema {
|
|
37
|
+
type: 'action:group';
|
|
38
|
+
/** Group name */
|
|
39
|
+
name?: string;
|
|
40
|
+
/** Group label */
|
|
41
|
+
label?: string;
|
|
42
|
+
/** Group icon */
|
|
43
|
+
icon?: string;
|
|
44
|
+
/** Actions in this group */
|
|
45
|
+
actions?: ActionSchema[];
|
|
46
|
+
/** Display mode: inline button row or dropdown */
|
|
47
|
+
display?: 'dropdown' | 'inline';
|
|
48
|
+
/** Filter actions by location */
|
|
49
|
+
location?: ActionLocation;
|
|
50
|
+
/** Group visibility condition */
|
|
51
|
+
visible?: string;
|
|
52
|
+
/** Button variant for inline actions */
|
|
53
|
+
variant?: string;
|
|
54
|
+
/** Button size for inline actions */
|
|
55
|
+
size?: string;
|
|
56
|
+
/** Custom CSS class */
|
|
57
|
+
className?: string;
|
|
58
|
+
[key: string]: any;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Inline action button within a group.
|
|
63
|
+
*/
|
|
64
|
+
const InlineActionButton: React.FC<{
|
|
65
|
+
action: ActionSchema;
|
|
66
|
+
variant?: string;
|
|
67
|
+
size?: string;
|
|
68
|
+
onExecute: (action: ActionSchema) => Promise<void>;
|
|
69
|
+
}> = ({ action, variant, size, onExecute }) => {
|
|
70
|
+
const [loading, setLoading] = useState(false);
|
|
71
|
+
const isVisible = useCondition(action.visible ? `\${${action.visible}}` : undefined);
|
|
72
|
+
const isEnabled = useCondition(action.enabled ? `\${${action.enabled}}` : undefined);
|
|
73
|
+
|
|
74
|
+
const Icon = resolveIcon(action.icon);
|
|
75
|
+
const btnVariant = (action.variant as string) === 'primary' ? 'default' : (action.variant || variant || 'outline');
|
|
76
|
+
const btnSize = action.size === 'md' ? 'default' : (action.size || size || 'sm');
|
|
77
|
+
|
|
78
|
+
const handleClick = useCallback(async () => {
|
|
79
|
+
if (loading) return;
|
|
80
|
+
setLoading(true);
|
|
81
|
+
try {
|
|
82
|
+
await onExecute(action);
|
|
83
|
+
} finally {
|
|
84
|
+
setLoading(false);
|
|
85
|
+
}
|
|
86
|
+
}, [action, onExecute, loading]);
|
|
87
|
+
|
|
88
|
+
if (action.visible && !isVisible) return null;
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<Button
|
|
92
|
+
type="button"
|
|
93
|
+
variant={btnVariant as any}
|
|
94
|
+
size={btnSize as any}
|
|
95
|
+
className={action.className}
|
|
96
|
+
disabled={(action.enabled ? !isEnabled : false) || loading}
|
|
97
|
+
onClick={handleClick}
|
|
98
|
+
>
|
|
99
|
+
{loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
|
100
|
+
{!loading && Icon && <Icon className={cn('h-4 w-4', action.label && 'mr-2')} />}
|
|
101
|
+
{action.label}
|
|
102
|
+
</Button>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
InlineActionButton.displayName = 'InlineActionButton';
|
|
107
|
+
|
|
108
|
+
const ActionGroupRenderer = forwardRef<HTMLDivElement, { schema: ActionGroupSchema; [key: string]: any }>(
|
|
109
|
+
({ schema, className, ...props }, ref) => {
|
|
110
|
+
const {
|
|
111
|
+
'data-obj-id': dataObjId,
|
|
112
|
+
'data-obj-type': dataObjType,
|
|
113
|
+
style,
|
|
114
|
+
...rest
|
|
115
|
+
} = props;
|
|
116
|
+
|
|
117
|
+
const { execute } = useAction();
|
|
118
|
+
const [dropdownLoading, setDropdownLoading] = useState(false);
|
|
119
|
+
|
|
120
|
+
const isVisible = useCondition(schema.visible ? `\${${schema.visible}}` : undefined);
|
|
121
|
+
|
|
122
|
+
// Filter actions by location if specified
|
|
123
|
+
let actions = schema.actions || [];
|
|
124
|
+
if (schema.location) {
|
|
125
|
+
actions = actions.filter(
|
|
126
|
+
a => !a.locations || a.locations.includes(schema.location!),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const handleExecute = useCallback(
|
|
131
|
+
async (action: ActionSchema) => {
|
|
132
|
+
await execute({
|
|
133
|
+
type: action.type,
|
|
134
|
+
name: action.name,
|
|
135
|
+
target: action.target,
|
|
136
|
+
execute: action.execute,
|
|
137
|
+
endpoint: action.endpoint,
|
|
138
|
+
method: action.method,
|
|
139
|
+
params: action.params as Record<string, any> | undefined,
|
|
140
|
+
confirmText: action.confirmText,
|
|
141
|
+
successMessage: action.successMessage,
|
|
142
|
+
errorMessage: action.errorMessage,
|
|
143
|
+
refreshAfter: action.refreshAfter,
|
|
144
|
+
toast: action.toast,
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
[execute],
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
if (schema.visible && !isVisible) return null;
|
|
151
|
+
if (actions.length === 0) return null;
|
|
152
|
+
|
|
153
|
+
const display = schema.display || 'inline';
|
|
154
|
+
|
|
155
|
+
// --- DROPDOWN MODE ---
|
|
156
|
+
if (display === 'dropdown') {
|
|
157
|
+
const TriggerIcon = resolveIcon(schema.icon);
|
|
158
|
+
return (
|
|
159
|
+
<DropdownMenu>
|
|
160
|
+
<DropdownMenuTrigger asChild>
|
|
161
|
+
<Button
|
|
162
|
+
type="button"
|
|
163
|
+
variant={(schema.variant || 'outline') as any}
|
|
164
|
+
size={(schema.size === 'md' ? 'default' : (schema.size || 'default')) as any}
|
|
165
|
+
className={cn(schema.className, className)}
|
|
166
|
+
disabled={dropdownLoading}
|
|
167
|
+
{...{ 'data-obj-id': dataObjId, 'data-obj-type': dataObjType, style }}
|
|
168
|
+
>
|
|
169
|
+
{dropdownLoading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
|
170
|
+
{!dropdownLoading && TriggerIcon && <TriggerIcon className="mr-2 h-4 w-4" />}
|
|
171
|
+
{schema.label || 'Actions'}
|
|
172
|
+
<ChevronDown className="ml-2 h-3 w-3 opacity-50" />
|
|
173
|
+
</Button>
|
|
174
|
+
</DropdownMenuTrigger>
|
|
175
|
+
|
|
176
|
+
<DropdownMenuContent align="end">
|
|
177
|
+
{actions.map((action, index) => {
|
|
178
|
+
const Icon = resolveIcon(action.icon);
|
|
179
|
+
const showSeparator = action.tags?.includes('separator-before') && index > 0;
|
|
180
|
+
return (
|
|
181
|
+
<React.Fragment key={action.name || index}>
|
|
182
|
+
{showSeparator && <DropdownMenuSeparator />}
|
|
183
|
+
<DropdownMenuItem
|
|
184
|
+
onSelect={async (e) => {
|
|
185
|
+
e.preventDefault();
|
|
186
|
+
setDropdownLoading(true);
|
|
187
|
+
try {
|
|
188
|
+
await handleExecute(action);
|
|
189
|
+
} finally {
|
|
190
|
+
setDropdownLoading(false);
|
|
191
|
+
}
|
|
192
|
+
}}
|
|
193
|
+
className={cn(
|
|
194
|
+
action.variant === 'destructive' && 'text-destructive focus:text-destructive',
|
|
195
|
+
action.className,
|
|
196
|
+
)}
|
|
197
|
+
>
|
|
198
|
+
{Icon && <Icon className="mr-2 h-4 w-4" />}
|
|
199
|
+
<span>{action.label || action.name}</span>
|
|
200
|
+
</DropdownMenuItem>
|
|
201
|
+
</React.Fragment>
|
|
202
|
+
);
|
|
203
|
+
})}
|
|
204
|
+
</DropdownMenuContent>
|
|
205
|
+
</DropdownMenu>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// --- INLINE MODE (default) ---
|
|
210
|
+
return (
|
|
211
|
+
<div
|
|
212
|
+
ref={ref}
|
|
213
|
+
className={cn('flex items-center gap-2', schema.className, className)}
|
|
214
|
+
{...rest}
|
|
215
|
+
{...{ 'data-obj-id': dataObjId, 'data-obj-type': dataObjType, style }}
|
|
216
|
+
>
|
|
217
|
+
{actions.map((action) => (
|
|
218
|
+
<InlineActionButton
|
|
219
|
+
key={action.name}
|
|
220
|
+
action={action}
|
|
221
|
+
variant={schema.variant}
|
|
222
|
+
size={schema.size}
|
|
223
|
+
onExecute={handleExecute}
|
|
224
|
+
/>
|
|
225
|
+
))}
|
|
226
|
+
</div>
|
|
227
|
+
);
|
|
228
|
+
},
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
ActionGroupRenderer.displayName = 'ActionGroupRenderer';
|
|
232
|
+
|
|
233
|
+
ComponentRegistry.register('action:group', ActionGroupRenderer, {
|
|
234
|
+
namespace: 'action',
|
|
235
|
+
label: 'Action Group',
|
|
236
|
+
inputs: [
|
|
237
|
+
{ name: 'name', type: 'string', label: 'Group Name' },
|
|
238
|
+
{ name: 'label', type: 'string', label: 'Label' },
|
|
239
|
+
{ name: 'icon', type: 'string', label: 'Icon' },
|
|
240
|
+
{ name: 'actions', type: 'object', label: 'Actions' },
|
|
241
|
+
{
|
|
242
|
+
name: 'display',
|
|
243
|
+
type: 'enum',
|
|
244
|
+
label: 'Display Mode',
|
|
245
|
+
enum: ['inline', 'dropdown'],
|
|
246
|
+
defaultValue: 'inline',
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
name: 'variant',
|
|
250
|
+
type: 'enum',
|
|
251
|
+
label: 'Variant',
|
|
252
|
+
enum: ['default', 'secondary', 'outline', 'ghost'],
|
|
253
|
+
defaultValue: 'outline',
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
name: 'size',
|
|
257
|
+
type: 'enum',
|
|
258
|
+
label: 'Size',
|
|
259
|
+
enum: ['sm', 'md', 'lg'],
|
|
260
|
+
defaultValue: 'sm',
|
|
261
|
+
},
|
|
262
|
+
{ name: 'className', type: 'string', label: 'CSS Class', advanced: true },
|
|
263
|
+
],
|
|
264
|
+
defaultProps: {
|
|
265
|
+
display: 'inline',
|
|
266
|
+
variant: 'outline',
|
|
267
|
+
size: 'sm',
|
|
268
|
+
actions: [],
|
|
269
|
+
},
|
|
270
|
+
});
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* action:icon — Icon-only action button for dense layouts.
|
|
11
|
+
*
|
|
12
|
+
* Renders a Shadcn Button (size="icon") with tooltip and ActionRunner integration.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import React, { forwardRef, useCallback, useState } from 'react';
|
|
16
|
+
import { ComponentRegistry } from '@object-ui/core';
|
|
17
|
+
import type { ActionSchema } from '@object-ui/types';
|
|
18
|
+
import { useAction } from '@object-ui/react';
|
|
19
|
+
import { useCondition } from '@object-ui/react';
|
|
20
|
+
import { Button } from '../../ui';
|
|
21
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../../ui';
|
|
22
|
+
import { cn } from '../../lib/utils';
|
|
23
|
+
import { Loader2 } from 'lucide-react';
|
|
24
|
+
import { resolveIcon } from './resolve-icon';
|
|
25
|
+
|
|
26
|
+
export interface ActionIconProps {
|
|
27
|
+
schema: ActionSchema & { type: string; className?: string };
|
|
28
|
+
className?: string;
|
|
29
|
+
context?: Record<string, any>;
|
|
30
|
+
[key: string]: any;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const ActionIconRenderer = forwardRef<HTMLButtonElement, ActionIconProps>(
|
|
34
|
+
({ schema, className, context: localContext, ...props }, ref) => {
|
|
35
|
+
const {
|
|
36
|
+
'data-obj-id': dataObjId,
|
|
37
|
+
'data-obj-type': dataObjType,
|
|
38
|
+
style,
|
|
39
|
+
...rest
|
|
40
|
+
} = props;
|
|
41
|
+
|
|
42
|
+
const { execute } = useAction();
|
|
43
|
+
const [loading, setLoading] = useState(false);
|
|
44
|
+
|
|
45
|
+
const isVisible = useCondition(schema.visible ? `\${${schema.visible}}` : undefined);
|
|
46
|
+
const isEnabled = useCondition(schema.enabled ? `\${${schema.enabled}}` : undefined);
|
|
47
|
+
|
|
48
|
+
const Icon = resolveIcon(schema.icon);
|
|
49
|
+
const variant = schema.variant === 'primary' ? 'default' : (schema.variant || 'ghost');
|
|
50
|
+
const size = 'icon';
|
|
51
|
+
|
|
52
|
+
const handleClick = useCallback(async () => {
|
|
53
|
+
if (loading) return;
|
|
54
|
+
setLoading(true);
|
|
55
|
+
try {
|
|
56
|
+
await execute({
|
|
57
|
+
type: schema.type,
|
|
58
|
+
name: schema.name,
|
|
59
|
+
target: schema.target,
|
|
60
|
+
execute: schema.execute,
|
|
61
|
+
endpoint: schema.endpoint,
|
|
62
|
+
method: schema.method,
|
|
63
|
+
params: schema.params as Record<string, any> | undefined,
|
|
64
|
+
confirmText: schema.confirmText,
|
|
65
|
+
successMessage: schema.successMessage,
|
|
66
|
+
errorMessage: schema.errorMessage,
|
|
67
|
+
refreshAfter: schema.refreshAfter,
|
|
68
|
+
toast: schema.toast,
|
|
69
|
+
...localContext,
|
|
70
|
+
});
|
|
71
|
+
} finally {
|
|
72
|
+
setLoading(false);
|
|
73
|
+
}
|
|
74
|
+
}, [schema, execute, loading, localContext]);
|
|
75
|
+
|
|
76
|
+
if (schema.visible && !isVisible) return null;
|
|
77
|
+
|
|
78
|
+
const button = (
|
|
79
|
+
<Button
|
|
80
|
+
ref={ref}
|
|
81
|
+
type="button"
|
|
82
|
+
variant={variant as any}
|
|
83
|
+
size={size}
|
|
84
|
+
className={cn('h-8 w-8', schema.className, className)}
|
|
85
|
+
disabled={(schema.enabled ? !isEnabled : false) || loading}
|
|
86
|
+
onClick={handleClick}
|
|
87
|
+
aria-label={schema.label || schema.name}
|
|
88
|
+
{...rest}
|
|
89
|
+
{...{ 'data-obj-id': dataObjId, 'data-obj-type': dataObjType, style }}
|
|
90
|
+
>
|
|
91
|
+
{loading ? (
|
|
92
|
+
<Loader2 className="h-4 w-4 animate-spin" />
|
|
93
|
+
) : Icon ? (
|
|
94
|
+
<Icon className="h-4 w-4" />
|
|
95
|
+
) : (
|
|
96
|
+
<span className="text-xs">{schema.label?.charAt(0) || '?'}</span>
|
|
97
|
+
)}
|
|
98
|
+
</Button>
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
// Wrap with tooltip if label is provided
|
|
102
|
+
if (schema.label || schema.description) {
|
|
103
|
+
return (
|
|
104
|
+
<TooltipProvider delayDuration={300}>
|
|
105
|
+
<Tooltip>
|
|
106
|
+
<TooltipTrigger asChild>{button}</TooltipTrigger>
|
|
107
|
+
<TooltipContent>
|
|
108
|
+
<p>{schema.label || schema.description}</p>
|
|
109
|
+
</TooltipContent>
|
|
110
|
+
</Tooltip>
|
|
111
|
+
</TooltipProvider>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return button;
|
|
116
|
+
},
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
ActionIconRenderer.displayName = 'ActionIconRenderer';
|
|
120
|
+
|
|
121
|
+
ComponentRegistry.register('action:icon', ActionIconRenderer, {
|
|
122
|
+
namespace: 'action',
|
|
123
|
+
label: 'Action Icon',
|
|
124
|
+
inputs: [
|
|
125
|
+
{ name: 'name', type: 'string', label: 'Action Name' },
|
|
126
|
+
{ name: 'label', type: 'string', label: 'Tooltip Label' },
|
|
127
|
+
{ name: 'icon', type: 'string', label: 'Icon' },
|
|
128
|
+
{
|
|
129
|
+
name: 'type',
|
|
130
|
+
type: 'enum',
|
|
131
|
+
label: 'Action Type',
|
|
132
|
+
enum: ['script', 'url', 'modal', 'flow', 'api'],
|
|
133
|
+
defaultValue: 'script',
|
|
134
|
+
},
|
|
135
|
+
{ name: 'target', type: 'string', label: 'Target' },
|
|
136
|
+
{
|
|
137
|
+
name: 'variant',
|
|
138
|
+
type: 'enum',
|
|
139
|
+
label: 'Variant',
|
|
140
|
+
enum: ['default', 'secondary', 'destructive', 'outline', 'ghost'],
|
|
141
|
+
defaultValue: 'ghost',
|
|
142
|
+
},
|
|
143
|
+
{ name: 'className', type: 'string', label: 'CSS Class', advanced: true },
|
|
144
|
+
],
|
|
145
|
+
defaultProps: {
|
|
146
|
+
icon: 'play',
|
|
147
|
+
type: 'script',
|
|
148
|
+
variant: 'ghost',
|
|
149
|
+
},
|
|
150
|
+
});
|