react-antd-admin-panel
Version:
Modern TypeScript-first React admin panel builder with Ant Design 6
221 lines • 5.11 kB
TypeScript
import type { ReactNode } from 'react';
import type { ButtonType } from 'antd/es/button';
/**
* Action types
*/
export type ActionType = 'submit' | 'callback' | 'link' | 'reset';
/**
* Confirmation dialog configuration
*/
export interface ActionConfirm {
/** Confirmation dialog title */
title?: string;
/** Confirmation dialog content/message */
content: string;
/** OK button text */
okText?: string;
/** Cancel button text */
cancelText?: string;
/** Danger mode (red OK button) */
danger?: boolean;
}
/**
* Access requirement for the action
*/
export interface ActionAccess {
/** Required role */
role?: string;
/** Required roles (any match) */
roles?: string[];
/** Required permission */
permission?: string;
/** Required feature */
feature?: string;
/** Required feature level */
level?: number;
}
/**
* Action - Clickable action builder with confirmation and callbacks
*
* Defines an action that can be triggered by user interaction.
* Supports confirmation dialogs, loading states, and callbacks.
*
* @example
* ```typescript
* // Submit action with confirmation
* const saveAction = new Action()
* .key('save')
* .label('Save Changes')
* .icon(<SaveOutlined />)
* .buttonType('primary')
* .confirm('Are you sure you want to save?')
* .onComplete(() => message.success('Saved!'))
* .onError(() => message.error('Failed'));
*
* // Callback action
* const deleteAction = new Action()
* .key('delete')
* .label('Delete')
* .buttonType('primary')
* .danger(true)
* .confirm({ content: 'Delete this item?', danger: true })
* .callback(async (action) => {
* await api.delete(itemId);
* });
*
* // Link action
* const viewAction = new Action()
* .key('view')
* .label('View Details')
* .type('link')
* .route('/users/123');
* ```
*/
export declare class Action {
private _key?;
private _label?;
private _icon?;
private _tooltip?;
private _type;
private _buttonType;
private _danger;
private _disabled;
private _loading;
private _confirm?;
private _route?;
private _access?;
private _callback?;
private _onComplete?;
private _onError?;
/**
* Set action key/identifier
*/
key(value: string): this;
/**
* Get action key
*/
getKey(): string | undefined;
/**
* Set action label
*/
label(value: string): this;
/**
* Get action label
*/
getLabel(): string | undefined;
/**
* Set action icon
*/
icon(value: ReactNode): this;
/**
* Get action icon
*/
getIcon(): ReactNode;
/**
* Set tooltip text (also used as aria-label for icon-only buttons)
*/
tooltip(value: string): this;
/**
* Get tooltip text
*/
getTooltip(): string | undefined;
/**
* Set action type
*/
type(value: ActionType): this;
/**
* Get action type
*/
getType(): ActionType;
/**
* Set button type (Ant Design ButtonType)
*/
buttonType(value: ButtonType): this;
/**
* Get button type
*/
getButtonType(): ButtonType;
/**
* Set danger mode
*/
danger(value?: boolean): this;
/**
* Check if danger mode
*/
isDanger(): boolean;
/**
* Set disabled state
*/
disabled(value?: boolean): this;
/**
* Check if disabled
*/
isDisabled(): boolean;
/**
* Set loading state
*/
loading(value?: boolean): this;
/**
* Check if loading
*/
isLoading(): boolean;
/**
* Set confirmation dialog (string shorthand or full config)
*/
confirm(value: string | ActionConfirm): this;
/**
* Get confirmation config
*/
getConfirm(): ActionConfirm | undefined;
/**
* Set route for link type actions
*/
route(value: string): this;
/**
* Get route
*/
getRoute(): string | undefined;
/**
* Set access requirements
*/
access(value: ActionAccess): this;
/**
* Get access requirements
*/
getAccess(): ActionAccess | undefined;
/**
* Set callback function for 'callback' type actions
*/
callback(fn: (action: Action, args?: unknown) => void | Promise<void>): this;
/**
* Get callback function
*/
getCallback(): ((action: Action, args?: unknown) => void | Promise<void>) | undefined;
/**
* Set completion callback
*/
onComplete(fn: (result?: unknown) => void): this;
/**
* Call completion callback
*/
callComplete(result?: unknown): void;
/**
* Set error callback
*/
onError(fn: (error: Error) => void): this;
/**
* Call error callback
*/
callError(error: Error): void;
/**
* Execute the action's callback
* For 'callback' type actions
*/
execute(args?: unknown): Promise<void>;
/**
* Clone this action
*/
clone(): Action;
}
export default Action;
//# sourceMappingURL=Action.d.ts.map