1- import { MultiSelectPrompt } from ' @clack/core' ;
2- import color from ' picocolors' ;
1+ import { MultiSelectPrompt } from " @clack/core" ;
2+ import color from " picocolors" ;
33import {
44 type CommonOptions ,
55 S_BAR ,
88 S_CHECKBOX_INACTIVE ,
99 S_CHECKBOX_SELECTED ,
1010 symbol ,
11- } from ' ./common.js' ;
12- import { limitOptions } from ' ./limit-options.js' ;
13- import type { Option } from ' ./select.js' ;
11+ } from " ./common.js" ;
12+ import { limitOptions } from " ./limit-options.js" ;
13+ import type { Option } from " ./select.js" ;
1414
1515export interface MultiSelectOptions < Value > extends CommonOptions {
1616 message : string ;
@@ -23,28 +23,36 @@ export interface MultiSelectOptions<Value> extends CommonOptions {
2323export const multiselect = < Value > ( opts : MultiSelectOptions < Value > ) => {
2424 const opt = (
2525 option : Option < Value > ,
26- state : 'inactive' | 'active' | 'selected' | 'active-selected' | 'submitted' | 'cancelled'
26+ state :
27+ | "inactive"
28+ | "active"
29+ | "selected"
30+ | "active-selected"
31+ | "submitted"
32+ | "cancelled"
33+ | "disabled"
2734 ) => {
2835 const label = option . label ?? String ( option . value ) ;
29- if ( state === 'active' ) {
30- return `${ color . cyan ( S_CHECKBOX_ACTIVE ) } ${ label } ${
31- option . hint ? ` ${ color . dim ( `(${ option . hint } )` ) } ` : ''
32- } `;
36+ if ( state === "disabled" ) {
37+ return `${ color . black ( S_CHECKBOX_SELECTED ) } ${ color . dim ( label ) } ${ option . hint ? ` ${ color . dim ( `(${ option . hint } )` ) } ` : ""
38+ } `;
3339 }
34- if ( state === 'selected' ) {
35- return `${ color . green ( S_CHECKBOX_SELECTED ) } ${ color . dim ( label ) } ${
36- option . hint ? ` ${ color . dim ( `(${ option . hint } )` ) } ` : ''
37- } `;
40+ if ( state === "active" ) {
41+ return `${ color . cyan ( S_CHECKBOX_ACTIVE ) } ${ label } ${ option . hint ? ` ${ color . dim ( `(${ option . hint } )` ) } ` : ""
42+ } `;
3843 }
39- if ( state === 'cancelled' ) {
44+ if ( state === "selected" ) {
45+ return `${ color . green ( S_CHECKBOX_SELECTED ) } ${ color . dim ( label ) } ${ option . hint ? ` ${ color . dim ( `(${ option . hint } )` ) } ` : ""
46+ } `;
47+ }
48+ if ( state === "cancelled" ) {
4049 return `${ color . strikethrough ( color . dim ( label ) ) } ` ;
4150 }
42- if ( state === 'active-selected' ) {
43- return `${ color . green ( S_CHECKBOX_SELECTED ) } ${ label } ${
44- option . hint ? ` ${ color . dim ( `(${ option . hint } )` ) } ` : ''
45- } `;
51+ if ( state === "active-selected" ) {
52+ return `${ color . green ( S_CHECKBOX_SELECTED ) } ${ label } ${ option . hint ? ` ${ color . dim ( `(${ option . hint } )` ) } ` : ""
53+ } `;
4654 }
47- if ( state === ' submitted' ) {
55+ if ( state === " submitted" ) {
4856 return `${ color . dim ( label ) } ` ;
4957 }
5058 return `${ color . dim ( S_CHECKBOX_INACTIVE ) } ${ color . dim ( label ) } ` ;
@@ -63,52 +71,58 @@ export const multiselect = <Value>(opts: MultiSelectOptions<Value>) => {
6371 if ( required && ( selected === undefined || selected . length === 0 ) )
6472 return `Please select at least one option.\n${ color . reset (
6573 color . dim (
66- `Press ${ color . gray ( color . bgWhite ( color . inverse ( ' space ' ) ) ) } to select, ${ color . gray (
67- color . bgWhite ( color . inverse ( ' enter ' ) )
74+ `Press ${ color . gray (
75+ color . bgWhite ( color . inverse ( " space " ) )
76+ ) } to select, ${ color . gray (
77+ color . bgWhite ( color . inverse ( " enter " ) )
6878 ) } to submit`
6979 )
7080 ) } `;
7181 } ,
7282 render ( ) {
73- const title = `${ color . gray ( S_BAR ) } \n${ symbol ( this . state ) } ${ opts . message } \n` ;
83+ const title = `${ color . gray ( S_BAR ) } \n${ symbol ( this . state ) } ${ opts . message
84+ } \n`;
7485 const value = this . value ?? [ ] ;
7586
7687 const styleOption = ( option : Option < Value > , active : boolean ) => {
88+ if ( option . disabled ) {
89+ return opt ( option , "disabled" ) ;
90+ }
7791 const selected = value . includes ( option . value ) ;
7892 if ( active && selected ) {
79- return opt ( option , ' active-selected' ) ;
93+ return opt ( option , " active-selected" ) ;
8094 }
8195 if ( selected ) {
82- return opt ( option , ' selected' ) ;
96+ return opt ( option , " selected" ) ;
8397 }
84- return opt ( option , active ? ' active' : ' inactive' ) ;
98+ return opt ( option , active ? " active" : " inactive" ) ;
8599 } ;
86100
87101 switch ( this . state ) {
88- case 'submit' : {
89- return `${ title } ${ color . gray ( S_BAR ) } ${
90- this . options
102+ case "submit" : {
103+ return `${ title } ${ color . gray ( S_BAR ) } ${ this . options
91104 . filter ( ( { value : optionValue } ) => value . includes ( optionValue ) )
92- . map ( ( option ) => opt ( option , ' submitted' ) )
93- . join ( color . dim ( ', ' ) ) || color . dim ( ' none' )
94- } `;
105+ . map ( ( option ) => opt ( option , " submitted" ) )
106+ . join ( color . dim ( ", " ) ) || color . dim ( " none" )
107+ } `;
95108 }
96- case ' cancel' : {
109+ case " cancel" : {
97110 const label = this . options
98111 . filter ( ( { value : optionValue } ) => value . includes ( optionValue ) )
99- . map ( ( option ) => opt ( option , 'cancelled' ) )
100- . join ( color . dim ( ', ' ) ) ;
101- return `${ title } ${ color . gray ( S_BAR ) } ${
102- label . trim ( ) ? ` ${ label } \n${ color . gray ( S_BAR ) } ` : ''
103- } `;
112+ . map ( ( option ) => opt ( option , "cancelled" ) )
113+ . join ( color . dim ( ", " ) ) ;
114+ return `${ title } ${ color . gray ( S_BAR ) } ${ label . trim ( ) ? ` ${ label } \n${ color . gray ( S_BAR ) } ` : ""
115+ } `;
104116 }
105- case ' error' : {
117+ case " error" : {
106118 const footer = this . error
107- . split ( '\n' )
119+ . split ( "\n" )
108120 . map ( ( ln , i ) =>
109- i === 0 ? `${ color . yellow ( S_BAR_END ) } ${ color . yellow ( ln ) } ` : ` ${ ln } `
121+ i === 0
122+ ? `${ color . yellow ( S_BAR_END ) } ${ color . yellow ( ln ) } `
123+ : ` ${ ln } `
110124 )
111- . join ( '\n' ) ;
125+ . join ( "\n" ) ;
112126 return `${ title + color . yellow ( S_BAR ) } ${ limitOptions ( {
113127 output : opts . output ,
114128 options : this . options ,
0 commit comments