react-antd-admin-panel
Version:
Modern TypeScript-first React admin panel builder with Ant Design 6
104 lines • 3.12 kB
TypeScript
import React from 'react';
import { BaseBuilder } from '../base/BaseBuilder';
import type { ComponentConfig } from '../types';
export interface ConditionConfig extends ComponentConfig {
condition?: (data?: any) => boolean;
fallback?: React.ReactNode;
}
export interface ConditionItem {
key?: string;
condition: (data?: any) => boolean;
content: React.ReactNode | (() => React.ReactNode);
}
/**
* Condition - Conditional rendering builder
* Renders content based on boolean conditions
*
* @example
* // Simple condition
* const cond = new Condition()
* .when(() => user.isAdmin, <AdminPanel />)
* .otherwise(<AccessDenied />);
*
* // Multiple conditions (switch-like)
* const cond = new Condition()
* .add('admin', (data) => data.role === 'admin', <AdminView />)
* .add('user', (data) => data.role === 'user', <UserView />)
* .default(<GuestView />);
*/
export declare class Condition extends BaseBuilder<ConditionConfig> {
private _items;
private _default?;
private _data?;
/**
* Add a conditional item
*/
add(key: string, condition: (data?: any) => boolean, content: React.ReactNode | (() => React.ReactNode)): this;
/**
* Add a condition with content (fluent API)
*/
when(condition: (data?: any) => boolean, content: React.ReactNode | (() => React.ReactNode)): this;
/**
* Set default content when no conditions match
*/
default(content: React.ReactNode | (() => React.ReactNode)): this;
/**
* Alias for default()
*/
otherwise(content: React.ReactNode | (() => React.ReactNode)): this;
/**
* Set data to evaluate conditions against
*/
data(value: any): this;
/**
* Check which condition matches and return its content
*/
private _resolveContent;
/**
* Clear all conditions
*/
clear(): this;
/**
* Get count of conditions
*/
count(): number;
/**
* Render the matching content
*/
render(): React.ReactNode;
}
/**
* ConditionGroup - Manage multiple conditions that can dynamically update
* Useful for form-driven UIs where different sections appear based on user input
*
* @example
* const group = new ConditionGroup()
* .add('basic', (data) => data.type === 'basic', basicSection)
* .add('advanced', (data) => data.type === 'advanced', advancedSection)
* .checkCondition(formData); // Updates active conditions
*/
export declare class ConditionGroup extends BaseBuilder<ConditionConfig> {
private _conditions;
private _activeKeys;
/**
* Add a named condition
*/
add(key: string, condition: (data?: any) => boolean, content: React.ReactNode | (() => React.ReactNode)): this;
/**
* Check conditions and update active items
*/
checkCondition(data?: any): this;
/**
* Get currently active condition keys
*/
getActiveKeys(): string[];
/**
* Clear all conditions
*/
clear(): this;
/**
* Render all matching conditions
*/
render(): React.ReactNode;
}
//# sourceMappingURL=Condition.d.ts.map