@inquirer/checkbox
Advanced tools
Comparing version 1.3.4 to 1.3.5
@@ -17,3 +17,2 @@ "use strict"; | ||
const { prefix = (0, core_1.usePrefix)(), instructions } = config; | ||
const paginator = (0, core_1.useRef)(new core_1.Paginator()).current; | ||
const [status, setStatus] = (0, core_1.useState)('pending'); | ||
@@ -74,2 +73,25 @@ const [choices, setChoices] = (0, core_1.useState)(() => config.choices.map((choice) => (Object.assign({}, choice)))); | ||
const message = chalk_1.default.bold(config.message); | ||
const allChoices = choices | ||
.map((choice, index) => { | ||
if (core_1.Separator.isSeparator(choice)) { | ||
return ` ${choice.separator}`; | ||
} | ||
const line = choice.name || choice.value; | ||
if (choice.disabled) { | ||
const disabledLabel = typeof choice.disabled === 'string' ? choice.disabled : '(disabled)'; | ||
return chalk_1.default.dim(`- ${line} ${disabledLabel}`); | ||
} | ||
const checkbox = choice.checked | ||
? chalk_1.default.green(figures_1.default.circleFilled) | ||
: figures_1.default.circle; | ||
if (index === cursorPosition) { | ||
return chalk_1.default.cyan(`${figures_1.default.pointer}${checkbox} ${line}`); | ||
} | ||
return ` ${checkbox} ${line}`; | ||
}) | ||
.join('\n'); | ||
const windowedChoices = (0, core_1.usePagination)(allChoices, { | ||
active: cursorPosition, | ||
pageSize: config.pageSize, | ||
}); | ||
if (status === 'done') { | ||
@@ -96,23 +118,3 @@ const selection = choices | ||
} | ||
const allChoices = choices | ||
.map((choice, index) => { | ||
if (core_1.Separator.isSeparator(choice)) { | ||
return ` ${choice.separator}`; | ||
} | ||
const line = choice.name || choice.value; | ||
if (choice.disabled) { | ||
const disabledLabel = typeof choice.disabled === 'string' ? choice.disabled : '(disabled)'; | ||
return chalk_1.default.dim(`- ${line} ${disabledLabel}`); | ||
} | ||
const checkbox = choice.checked | ||
? chalk_1.default.green(figures_1.default.circleFilled) | ||
: figures_1.default.circle; | ||
if (index === cursorPosition) { | ||
return chalk_1.default.cyan(`${figures_1.default.pointer}${checkbox} ${line}`); | ||
} | ||
return ` ${checkbox} ${line}`; | ||
}) | ||
.join('\n'); | ||
const windowedChoices = paginator.paginate(allChoices, cursorPosition, config.pageSize); | ||
return `${prefix} ${message}${helpTip}\n${windowedChoices}${ansi_escapes_1.default.cursorHide}`; | ||
}); |
@@ -17,3 +17,2 @@ "use strict"; | ||
const { prefix = (0, core_1.usePrefix)(), instructions } = config; | ||
const paginator = (0, core_1.useRef)(new core_1.Paginator()).current; | ||
const [status, setStatus] = (0, core_1.useState)('pending'); | ||
@@ -74,2 +73,25 @@ const [choices, setChoices] = (0, core_1.useState)(() => config.choices.map((choice) => (Object.assign({}, choice)))); | ||
const message = chalk_1.default.bold(config.message); | ||
const allChoices = choices | ||
.map((choice, index) => { | ||
if (core_1.Separator.isSeparator(choice)) { | ||
return ` ${choice.separator}`; | ||
} | ||
const line = choice.name || choice.value; | ||
if (choice.disabled) { | ||
const disabledLabel = typeof choice.disabled === 'string' ? choice.disabled : '(disabled)'; | ||
return chalk_1.default.dim(`- ${line} ${disabledLabel}`); | ||
} | ||
const checkbox = choice.checked | ||
? chalk_1.default.green(figures_1.default.circleFilled) | ||
: figures_1.default.circle; | ||
if (index === cursorPosition) { | ||
return chalk_1.default.cyan(`${figures_1.default.pointer}${checkbox} ${line}`); | ||
} | ||
return ` ${checkbox} ${line}`; | ||
}) | ||
.join('\n'); | ||
const windowedChoices = (0, core_1.usePagination)(allChoices, { | ||
active: cursorPosition, | ||
pageSize: config.pageSize, | ||
}); | ||
if (status === 'done') { | ||
@@ -96,23 +118,3 @@ const selection = choices | ||
} | ||
const allChoices = choices | ||
.map((choice, index) => { | ||
if (core_1.Separator.isSeparator(choice)) { | ||
return ` ${choice.separator}`; | ||
} | ||
const line = choice.name || choice.value; | ||
if (choice.disabled) { | ||
const disabledLabel = typeof choice.disabled === 'string' ? choice.disabled : '(disabled)'; | ||
return chalk_1.default.dim(`- ${line} ${disabledLabel}`); | ||
} | ||
const checkbox = choice.checked | ||
? chalk_1.default.green(figures_1.default.circleFilled) | ||
: figures_1.default.circle; | ||
if (index === cursorPosition) { | ||
return chalk_1.default.cyan(`${figures_1.default.pointer}${checkbox} ${line}`); | ||
} | ||
return ` ${checkbox} ${line}`; | ||
}) | ||
.join('\n'); | ||
const windowedChoices = paginator.paginate(allChoices, cursorPosition, config.pageSize); | ||
return `${prefix} ${message}${helpTip}\n${windowedChoices}${ansi_escapes_1.default.cursorHide}`; | ||
}); |
{ | ||
"name": "@inquirer/checkbox", | ||
"version": "1.3.4", | ||
"version": "1.3.5", | ||
"engines": { | ||
@@ -60,3 +60,3 @@ "node": ">=14.18.0" | ||
"dependencies": { | ||
"@inquirer/core": "^2.3.1", | ||
"@inquirer/core": "^3.0.0", | ||
"@inquirer/type": "^1.1.1", | ||
@@ -92,3 +92,3 @@ "ansi-escapes": "^4.3.2", | ||
}, | ||
"gitHead": "b1b29c0b6da9420d739cd46704c205515de2db04" | ||
"gitHead": "18144628b03b62c346cb7d9d55a2c526b1ed5d8a" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
363
22518
+ Added@inquirer/core@3.1.2(transitive)
- Removed@inquirer/core@2.3.1(transitive)
Updated@inquirer/core@^3.0.0