@inquirer/confirm 2.0.16 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -22,11 +22,31 @@ const answer = await confirm({ message: 'Continue?' });
22
22
 
23
23
  ## Options
24
24
 
25
- | Property | Type | Required | Description |
26
- | ----------- | --------------------- | -------- | ------------------------------------------------------- |
27
- | message | `string` | yes | The question to ask |
28
- | default | `boolean` | no | Default answer (true or false) |
29
- | transformer | `(boolean) => string` | no | Transform the prompt printed message to a custom string |
25
+ | Property | Type | Required | Description |
26
+ | ----------- | ----------------------- | -------- | ------------------------------------------------------- |
27
+ | message | `string` | yes | The question to ask |
28
+ | default | `boolean` | no | Default answer (true or false) |
29
+ | transformer | `(boolean) => string` | no | Transform the prompt printed message to a custom string |
30
+ | theme | [See Theming](#Theming) | no | Customize look of the prompt. |
31
+
32
+ ## Theming
33
+
34
+ You can theme a prompt by passing a `theme` object option. The theme object only need to includes the keys you wish to modify, we'll fallback on the defaults for the rest.
35
+
36
+ ```ts
37
+ type Theme = {
38
+ prefix: string;
39
+ spinner: {
40
+ interval: number;
41
+ frames: string[];
42
+ };
43
+ style: {
44
+ answer: (text: string) => string;
45
+ message: (text: string) => string;
46
+ defaultAnswer: (text: string) => string;
47
+ };
48
+ };
49
+ ```
30
50
 
31
51
  # License
32
52
 
package/dist/cjs/index.js CHANGED
@@ -1,15 +1,12 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const chalk_1 = __importDefault(require("chalk"));
7
3
  const core_1 = require("@inquirer/core");
8
4
  exports.default = (0, core_1.createPrompt)((config, done) => {
9
5
  const { transformer = (answer) => (answer ? 'yes' : 'no') } = config;
10
6
  const [status, setStatus] = (0, core_1.useState)('pending');
11
7
  const [value, setValue] = (0, core_1.useState)('');
12
- const prefix = (0, core_1.usePrefix)();
8
+ const theme = (0, core_1.makeTheme)(config.theme);
9
+ const prefix = (0, core_1.usePrefix)({ theme });
13
10
  (0, core_1.useKeypress)((key, rl) => {
14
11
  if ((0, core_1.isEnterKey)(key)) {
15
12
  let answer = config.default !== false;
@@ -28,11 +25,11 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
28
25
  let formattedValue = value;
29
26
  let defaultValue = '';
30
27
  if (status === 'done') {
31
- formattedValue = chalk_1.default.cyan(value);
28
+ formattedValue = theme.style.answer(value);
32
29
  }
33
30
  else {
34
- defaultValue = chalk_1.default.dim(config.default === false ? ' (y/N)' : ' (Y/n)');
31
+ defaultValue = ` ${theme.style.defaultAnswer(config.default === false ? 'y/N' : 'Y/n')}`;
35
32
  }
36
- const message = chalk_1.default.bold(config.message);
33
+ const message = theme.style.message(config.message);
37
34
  return `${prefix} ${message}${defaultValue} ${formattedValue}`;
38
35
  });
@@ -1,6 +1,10 @@
1
- declare const _default: import("@inquirer/type").Prompt<boolean, {
2
- message: string | Promise<string> | (() => Promise<string>);
3
- default?: boolean | undefined;
4
- transformer?: ((value: boolean) => string) | undefined;
5
- }>;
1
+ import { type Theme } from '@inquirer/core';
2
+ import type { PartialDeep } from '@inquirer/type';
3
+ type ConfirmConfig = {
4
+ message: string;
5
+ default?: boolean;
6
+ transformer?: (value: boolean) => string;
7
+ theme?: PartialDeep<Theme>;
8
+ };
9
+ declare const _default: import("@inquirer/type").Prompt<boolean, ConfirmConfig>;
6
10
  export default _default;
@@ -1,10 +1,10 @@
1
- import chalk from 'chalk';
2
- import { createPrompt, useState, useKeypress, isEnterKey, usePrefix, } from '@inquirer/core';
1
+ import { createPrompt, useState, useKeypress, isEnterKey, usePrefix, makeTheme, } from '@inquirer/core';
3
2
  export default createPrompt((config, done) => {
4
3
  const { transformer = (answer) => (answer ? 'yes' : 'no') } = config;
5
4
  const [status, setStatus] = useState('pending');
6
5
  const [value, setValue] = useState('');
7
- const prefix = usePrefix();
6
+ const theme = makeTheme(config.theme);
7
+ const prefix = usePrefix({ theme });
8
8
  useKeypress((key, rl) => {
9
9
  if (isEnterKey(key)) {
10
10
  let answer = config.default !== false;
@@ -23,11 +23,11 @@ export default createPrompt((config, done) => {
23
23
  let formattedValue = value;
24
24
  let defaultValue = '';
25
25
  if (status === 'done') {
26
- formattedValue = chalk.cyan(value);
26
+ formattedValue = theme.style.answer(value);
27
27
  }
28
28
  else {
29
- defaultValue = chalk.dim(config.default === false ? ' (y/N)' : ' (Y/n)');
29
+ defaultValue = ` ${theme.style.defaultAnswer(config.default === false ? 'y/N' : 'Y/n')}`;
30
30
  }
31
- const message = chalk.bold(config.message);
31
+ const message = theme.style.message(config.message);
32
32
  return `${prefix} ${message}${defaultValue} ${formattedValue}`;
33
33
  });
@@ -1,6 +1,10 @@
1
- declare const _default: import("@inquirer/type").Prompt<boolean, {
2
- message: string | Promise<string> | (() => Promise<string>);
3
- default?: boolean | undefined;
4
- transformer?: ((value: boolean) => string) | undefined;
5
- }>;
1
+ import { type Theme } from '@inquirer/core';
2
+ import type { PartialDeep } from '@inquirer/type';
3
+ type ConfirmConfig = {
4
+ message: string;
5
+ default?: boolean;
6
+ transformer?: (value: boolean) => string;
7
+ theme?: PartialDeep<Theme>;
8
+ };
9
+ declare const _default: import("@inquirer/type").Prompt<boolean, ConfirmConfig>;
6
10
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/confirm",
3
- "version": "2.0.16",
3
+ "version": "3.0.0",
4
4
  "description": "Inquirer confirm prompt",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "typings": "./dist/cjs/types/index.d.ts",
@@ -54,12 +54,11 @@
54
54
  "license": "MIT",
55
55
  "homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/confirm/README.md",
56
56
  "dependencies": {
57
- "@inquirer/core": "^5.1.2",
58
- "@inquirer/type": "^1.1.6",
59
- "chalk": "^4.1.2"
57
+ "@inquirer/core": "^7.0.0",
58
+ "@inquirer/type": "^1.2.0"
60
59
  },
61
60
  "devDependencies": {
62
- "@inquirer/testing": "^2.1.10"
61
+ "@inquirer/testing": "^2.1.11"
63
62
  },
64
63
  "scripts": {
65
64
  "tsc": "yarn run tsc:esm && yarn run tsc:cjs",
@@ -70,7 +69,7 @@
70
69
  "access": "public"
71
70
  },
72
71
  "engines": {
73
- "node": ">=14.18.0"
72
+ "node": ">=18"
74
73
  },
75
74
  "exports": {
76
75
  ".": {
@@ -84,5 +83,5 @@
84
83
  }
85
84
  }
86
85
  },
87
- "gitHead": "6c0d1d23e6881a10bc3d718d079a0a09ba382dd5"
86
+ "gitHead": "44016a40bc9e93455dfdb9fa6c25c27c1c109bd3"
88
87
  }