Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@inquirer/expand TS migration #1135

Merged
merged 1 commit into from Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/expand/demo.js → packages/expand/demo.ts
@@ -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
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
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
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist"
},
"include": ["./src"]
}