Skip to content

Commit 05f8b2a

Browse files
committed
feat: Improved submit output
1 parent 1df7b37 commit 05f8b2a

4 files changed

Lines changed: 17 additions & 9 deletions

File tree

next-releasenotes.md

Whitespace-only changes.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "@codify-cli/ink-form",
2+
"name": "@codifycli/ink-form",
33
"type": "module",
4-
"version": "0.0.0",
4+
"version": "0.0.2",
55
"description": "Complex user-friendly form component for Codify",
66
"main": "lib/index.js",
77
"exports": "./lib/index.js",
@@ -18,7 +18,7 @@
1818
"commandline",
1919
"cmd"
2020
],
21-
"repository": "https://github.com/kevinwang5658/codify-ink-form",
21+
"repository": "https://github.com/codifyCLI/codify-ink-form",
2222
"author": "Lukas Bach <lbach@outlook.de> modified by Kevin Wang",
2323
"devDependencies": {
2424
"@types/node": "20.14.8",
@@ -55,7 +55,8 @@
5555
"ink-text-input": "^6.0.0"
5656
},
5757
"publishConfig": {
58-
"access": "public"
58+
"access": "restricted",
59+
"registry": "https://npm.pkg.github.com"
5960
},
6061
"publish": {
6162
"preScripts": "build,build:docs,lint",

src/Form.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { FullScreen, useStdoutDimensions } from './FullScreen.js';
1414
export const Form: React.FC<FormProps> = props => {
1515
const isControlled = props.value !== undefined;
1616
const [currentTab, setCurrentTab] = useState(0);
17-
const [isSubmitted, setIsSubmitted] = useState(false);
1817
const [sections, setSections] = useState(props.form.sections);
1918
const form = { ...props.form, sections }
2019
const [value, setValue] = useState<Array<Record<string, unknown>>>(props.value ?? Array.from({ length: sections.length }, () => ({})));
@@ -64,6 +63,15 @@ export const Form: React.FC<FormProps> = props => {
6463
props.onChange?.(value);
6564
};
6665

66+
const onSubmitForm = () => {
67+
const formattedValue = value.map((v, index) => ({
68+
section: sections[index],
69+
value: v
70+
}))
71+
72+
props.onSubmit?.(formattedValue)
73+
}
74+
6775
useInput(
6876
(input, key) => {
6977
if (key.upArrow) {
@@ -168,10 +176,7 @@ export const Form: React.FC<FormProps> = props => {
168176
<Button label="Remove" id={'removeButton'} isEnabled={sections.length > 1} onClicked={() => removeCurrentSection()}/>
169177
</Box>
170178
<Box flexDirection="row-reverse">
171-
<SubmitButton canSubmit={canSubmitForm} onSubmit={() => {
172-
props.onSubmit?.(value)
173-
setIsSubmitted(true);
174-
}}/>
179+
<SubmitButton canSubmit={canSubmitForm} onSubmit={onSubmitForm}/>
175180
</Box>
176181
</Box>
177182
</Box>

src/demo/Test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export function Test() {
3333
process.stdout.write('\x1b[?1000l');
3434
setIsSubmitted(true)
3535

36+
console.log(value)
37+
3638
setTimeout(() => {
3739
stdout.write('Hihi\n');
3840
}, 1000)

0 commit comments

Comments
 (0)