-
-
Notifications
You must be signed in to change notification settings - Fork 197
Expand file tree
/
Copy pathnote.ts
More file actions
39 lines (35 loc) · 974 Bytes
/
note.ts
File metadata and controls
39 lines (35 loc) · 974 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
37
38
39
import type { NoteOptions } from '@clack/prompts';
import { isCancel, note } from '@clack/prompts';
import type { JSX } from '../types.js';
import { resolveChildren } from '../utils.js';
export interface NoteProps extends NoteOptions {
children?: JSX.Element[] | JSX.Element | string;
message?: string;
title?: string;
}
export function Note(props: NoteProps): JSX.Element {
return {
render: async (options) => {
let message = '';
if (props.children) {
const messages: string[] = [];
const children = await resolveChildren(props.children, options);
for (const child of children) {
// TODO (43081j): handle cancelling of children
if (isCancel(child)) {
continue;
}
messages.push(String(child));
}
message = messages.join('\n');
} else if (props.message) {
message = props.message;
}
note(message, props.title, {
input: options?.input,
output: options?.output,
...props,
});
},
};
}