Add joinJSX utility function
This commit is contained in:
parent
6f8ed688eb
commit
1729fa8561
1 changed files with 12 additions and 3 deletions
|
@ -12,7 +12,6 @@ import {
|
||||||
onUnmounted,
|
onUnmounted,
|
||||||
ref,
|
ref,
|
||||||
shallowRef,
|
shallowRef,
|
||||||
toRef,
|
|
||||||
unref,
|
unref,
|
||||||
watchEffect
|
watchEffect
|
||||||
} from "vue";
|
} from "vue";
|
||||||
|
@ -38,10 +37,10 @@ export function coerceComponent(
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type VueFeature = {
|
export interface VueFeature {
|
||||||
[ComponentKey]: GenericComponent;
|
[ComponentKey]: GenericComponent;
|
||||||
[GatherProps]: () => Record<string, unknown>;
|
[GatherProps]: () => Record<string, unknown>;
|
||||||
};
|
}
|
||||||
|
|
||||||
export function render(object: VueFeature | CoercableComponent): JSX.Element | DefineComponent {
|
export function render(object: VueFeature | CoercableComponent): JSX.Element | DefineComponent {
|
||||||
if (isCoercableComponent(object)) {
|
if (isCoercableComponent(object)) {
|
||||||
|
@ -86,6 +85,16 @@ export function renderColJSX(...objects: (VueFeature | CoercableComponent)[]): J
|
||||||
return <Col>{objects.map(renderJSX)}</Col>;
|
return <Col>{objects.map(renderJSX)}</Col>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function joinJSX(objects: JSX.Element[], joiner: JSX.Element): JSX.Element {
|
||||||
|
return objects.reduce((acc, curr) => (
|
||||||
|
<>
|
||||||
|
{acc}
|
||||||
|
{joiner}
|
||||||
|
{curr}
|
||||||
|
</>
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
export function isCoercableComponent(component: unknown): component is CoercableComponent {
|
export function isCoercableComponent(component: unknown): component is CoercableComponent {
|
||||||
if (typeof component === "string") {
|
if (typeof component === "string") {
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue