MCPcopy Create free account
hub / github.com/bombshell-dev/clack / opt

Function opt

packages/prompts/src/multi-select.ts:44–83  ·  view source on GitHub ↗
(
		option: Option<Value>,
		state:
			| 'inactive'
			| 'active'
			| 'selected'
			| 'active-selected'
			| 'submitted'
			| 'cancelled'
			| 'disabled'
	)

Source from the content-addressed store, hash-verified

42
43export const multiselect = <Value>(opts: MultiSelectOptions<Value>) => {
44 const opt = (
45 option: Option<Value>,
46 state:
47 | 'inactive'
48 | 'active'
49 | 'selected'
50 | 'active-selected'
51 | 'submitted'
52 | 'cancelled'
53 | 'disabled'
54 ) => {
55 const label = option.label ?? String(option.value);
56 if (state === 'disabled') {
57 return `${styleText('gray', S_CHECKBOX_INACTIVE)} ${computeLabel(label, (str) => styleText(['strikethrough', 'gray'], str))}${
58 option.hint ? ` ${styleText('dim', `(${option.hint ?? 'disabled'})`)}` : ''
59 }`;
60 }
61 if (state === 'active') {
62 return `${styleText('cyan', S_CHECKBOX_ACTIVE)} ${label}${
63 option.hint ? ` ${styleText('dim', `(${option.hint})`)}` : ''
64 }`;
65 }
66 if (state === 'selected') {
67 return `${styleText('green', S_CHECKBOX_SELECTED)} ${computeLabel(label, (text) => styleText('dim', text))}${
68 option.hint ? ` ${styleText('dim', `(${option.hint})`)}` : ''
69 }`;
70 }
71 if (state === 'cancelled') {
72 return `${computeLabel(label, (text) => styleText(['strikethrough', 'dim'], text))}`;
73 }
74 if (state === 'active-selected') {
75 return `${styleText('green', S_CHECKBOX_SELECTED)} ${label}${
76 option.hint ? ` ${styleText('dim', `(${option.hint})`)}` : ''
77 }`;
78 }
79 if (state === 'submitted') {
80 return `${computeLabel(label, (text) => styleText('dim', text))}`;
81 }
82 return `${styleText('dim', S_CHECKBOX_INACTIVE)} ${computeLabel(label, (text) => styleText('dim', text))}`;
83 };
84 const required = opts.required ?? true;
85 const showInstructions = opts.showInstructions ?? true;
86

Callers 2

styleOptionFunction · 0.70
renderFunction · 0.70

Calls 1

computeLabelFunction · 0.70

Tested by

no test coverage detected