Skip to content

Commit c26349e

Browse files
committed
wip: add a bunch more components
1 parent c933bd9 commit c26349e

File tree

15 files changed

+657
-498
lines changed

15 files changed

+657
-498
lines changed
Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1-
import { type Option, isCancel } from '@clack/prompts';
1+
import { type Option as PromptOption, isCancel } from '@clack/prompts';
22
import type { JSX } from '../types.js';
33
import { resolveChildren } from '../utils.js';
44

5-
export interface OptionProps {
6-
value: unknown;
5+
export interface OptionProps<T> {
6+
value: T;
7+
hint?: string;
78
children?: JSX.Element | JSX.Element[] | string;
89
}
910

10-
export async function Option(props: OptionProps): Promise<Option<unknown>> {
11-
let label = '';
12-
if (props.children) {
13-
const children = await resolveChildren(props.children);
11+
export async function Option<T>(props: OptionProps<T>): Promise<PromptOption<T>> {
12+
const { children, ...opts } = props;
13+
14+
if (children) {
15+
const resolvedChildren = await resolveChildren(children);
1416
const childStrings: string[] = [];
1517

16-
for (const child of children) {
18+
for (const child of resolvedChildren) {
1719
if (isCancel(child)) {
1820
continue;
1921
}
2022
childStrings.push(String(child));
2123
}
2224

23-
label = childStrings.join('\n');
24-
} else {
25-
label = String(props.value);
25+
return {
26+
...opts,
27+
label: childStrings.join('\n'),
28+
} as PromptOption<T>;
2629
}
27-
return {
28-
value: props.value,
29-
label,
30-
};
30+
31+
return opts as PromptOption<T>;
3132
}

packages/jsx/src/components/select.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,11 @@ import type { JSX } from '../types.js';
44
import { resolveChildren } from '../utils.js';
55

66
export interface SelectProps extends Omit<SelectOptions<unknown>, 'options'> {
7-
children: JSX.Element[] | JSX.Element;
7+
children: JSX.Element[] | JSX.Element | string;
88
}
99

1010
const isOptionLike = (obj: unknown): obj is Option<unknown> => {
11-
return (
12-
obj !== null &&
13-
typeof obj === 'object' &&
14-
Object.hasOwnProperty.call(obj, 'label') &&
15-
Object.hasOwnProperty.call(obj, 'value') &&
16-
typeof (obj as { label: string }).label === 'string'
17-
);
11+
return obj !== null && typeof obj === 'object' && Object.hasOwnProperty.call(obj, 'value');
1812
};
1913

2014
export async function Select(props: SelectProps): ReturnType<typeof select> {

packages/jsx/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
namespace JSX {
2-
export type IntrinsicElements = {};
2+
export type IntrinsicElements = never;
33

44
export type Element = Promise<unknown>;
55
}

packages/jsx/test/__snapshots__/jsx.test.tsx.snap

Lines changed: 0 additions & 302 deletions
This file was deleted.

0 commit comments

Comments
 (0)