Skip to content

Commit

Permalink
@inquirer/expand TS migration (#1135)
Browse files Browse the repository at this point in the history
  • Loading branch information
TDP17 authored Jul 10, 2022
1 parent 33ce11d commit 6b76a9e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/expand/demo.js → packages/expand/demo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import expand from './index.js';
import expand from './src/index.js';

(async () => {
let answer;
Expand Down
9 changes: 8 additions & 1 deletion packages/expand/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"type": "module",
"version": "0.0.21-alpha.0",
"description": "Inquirer checkbox prompt",
"main": "index.js",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
"dist/"
],
"repository": "SBoudrias/Inquirer.js",
"keywords": [
"cli",
Expand All @@ -20,6 +24,9 @@
"chalk": "^5.0.1",
"figures": "^4.0.1"
},
"scripts": {
"tsc": "tsc"
},
"publishConfig": {
"access": "public"
}
Expand Down
17 changes: 12 additions & 5 deletions packages/expand/index.js → packages/expand/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,32 @@ import {
useKeypress,
usePrefix,
isEnterKey,
AsyncPromptConfig,
} from '@inquirer/core';
import chalk from 'chalk';

type ExpandConfig = AsyncPromptConfig & {
choices: { key: string; name: string; value?: string }[];
default?: string;
expanded?: boolean;
};

const helpChoice = {
key: 'h',
name: 'Help, list all options',
value: undefined,
};

export default createPrompt((config, done) => {
export default createPrompt<string, ExpandConfig>((config, done) => {
const {
choices,
default: defaultKey = 'h',
expanded: defaultExpandState = false,
} = config;
const [status, setStatus] = useState('pending');
const [value, setValue] = useState('');
const [expanded, setExpanded] = useState(defaultExpandState);
const [errorMsg, setError] = useState();
const [status, setStatus] = useState<string>('pending');
const [value, setValue] = useState<string>('');
const [expanded, setExpanded] = useState<boolean>(defaultExpandState);
const [errorMsg, setError] = useState<string | undefined>(undefined);
const prefix = usePrefix();

useKeypress((key, rl) => {
Expand Down
7 changes: 7 additions & 0 deletions packages/expand/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist"
},
"include": ["./src"]
}

0 comments on commit 6b76a9e

Please sign in to comment.