Merge branch 'feat/component-conditional'
This commit is contained in:
@@ -1 +1,26 @@
|
||||
export {};
|
||||
import type { UElement, UNode, UniversalProps } from "@alkdev/ujsx";
|
||||
import type { CallResult } from "../schema/edge.js";
|
||||
|
||||
export interface ConditionalProps {
|
||||
test: ((results: Record<string, CallResult>) => boolean) | string;
|
||||
else?: UNode;
|
||||
}
|
||||
|
||||
function Conditional(
|
||||
props: ConditionalProps & { children?: UNode[] },
|
||||
): UElement {
|
||||
const { test, else: elseProp, children } = props;
|
||||
const elementProps: UniversalProps = { test: test as UniversalProps["test"] };
|
||||
if (elseProp !== undefined) {
|
||||
elementProps.else = elseProp;
|
||||
}
|
||||
return {
|
||||
type: "conditional",
|
||||
props: elementProps,
|
||||
children: children ?? [],
|
||||
};
|
||||
}
|
||||
|
||||
Conditional.displayName = "Conditional";
|
||||
|
||||
export { Conditional };
|
||||
@@ -1,3 +1,5 @@
|
||||
export { Conditional } from "./conditional.js";
|
||||
export type { ConditionalProps } from "./conditional.js";
|
||||
export { Operation } from "./operation.js";
|
||||
export type { OperationProps } from "./operation.js";
|
||||
export { Parallel } from "./parallel.js";
|
||||
|
||||
Reference in New Issue
Block a user