-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathoption.ts
More file actions
36 lines (30 loc) · 833 Bytes
/
option.ts
File metadata and controls
36 lines (30 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { type Option as PromptOption, isCancel } from '@clack/prompts';
import type { JSX } from '../types.js';
import { resolveChildren } from '../utils.js';
export interface OptionProps<T> {
value: T;
hint?: string;
children?: JSX.Element | JSX.Element[] | string;
}
export function Option<T>(props: OptionProps<T>): JSX.Element {
return {
render: async (options) => {
const { children, ...opts } = props;
if (children) {
const resolvedChildren = await resolveChildren(children, options);
const childStrings: string[] = [];
for (const child of resolvedChildren) {
if (isCancel(child)) {
continue;
}
childStrings.push(String(child));
}
return {
...opts,
label: childStrings.join('\n'),
} as PromptOption<T>;
}
return opts as PromptOption<T>;
},
};
}