Skip to content

Commit 8b61f27

Browse files
committed
UX improvements 2
1 parent 2f3c142 commit 8b61f27

7 files changed

Lines changed: 20 additions & 19 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@codifycli/ink-form",
33
"type": "module",
4-
"version": "0.0.8",
4+
"version": "0.0.10",
55
"description": "Complex user-friendly form component for Codify",
66
"main": "lib/index.js",
77
"exports": "./lib/index.js",

src/Form.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ export const Form: React.FC<FormProps> = props => {
2020
const [editingField, setEditingField] = useState<string>();
2121
const canSubmitForm = useMemo(() => canSubmit(form, value), [value, form]);
2222
const focusManager = useFocusManager();
23-
const [focusedElement, setFocusedElement] = useState(-1); // this is -1 because there is no initial focus. The first down click will focus on element 0
23+
const [focusedElement, setFocusedElement] = useState(0); // this is -1 because there is no initial focus. The first down click will focus on element 0
2424
const headerRef = useRef();
2525
const headerHeight = headerRef.current ? measureElement(headerRef.current).height : 5
2626
const [, fullHeight] = useStdoutDimensions()
2727

2828
useEffect(() => {
2929
focusManager.enableFocus();
30+
setTimeout(() => focusManager.focusNext(), 50)
3031
}, []);
3132

3233
useEffect(() => {
@@ -54,7 +55,8 @@ export const Form: React.FC<FormProps> = props => {
5455

5556
const onChangeTab = (tab: number) => {
5657
setCurrentTab(tab);
57-
setFocusedElement(-1)
58+
setFocusedElement(0)
59+
setTimeout(() => focusManager.focusNext(), 50)
5860
}
5961

6062
const setValueAndPropagate = (index: number, newValue: Record<string, unknown>) => {
@@ -84,7 +86,7 @@ export const Form: React.FC<FormProps> = props => {
8486
} else if (key.downArrow) {
8587
// This calculates the maximum amount of children there is. We don't want to scroll past the last item
8688
// Fields.length is number of json fields. 2 is the add and remove buttons. Submit button is sometimes focusable
87-
const totalFocusableElements = sections[currentTab].fields.length + 2 + (canSubmitForm ? 1 : 0) + ((sections.length <= 1) ? -1 : 0)
89+
const totalFocusableElements = sections[currentTab].fields.length + (canSubmitForm ? 1 : 0)
8890
if (focusedElement + 1 >= totalFocusableElements) {
8991
return;
9092
}
@@ -126,6 +128,7 @@ export const Form: React.FC<FormProps> = props => {
126128

127129
setSections(newTabs);
128130
setValue([...value]);
131+
onChangeTab(Math.min(currentTab + 1, newTabs.length - 1));
129132
}
130133

131134
const removeCurrentSection = () => {
@@ -198,14 +201,13 @@ export const Form: React.FC<FormProps> = props => {
198201
{!editingField && (
199202
<Box flexDirection='column' marginTop={1}>
200203
<Box flexDirection="row">
201-
<Button label="[A]dd resource" id={'addButton'} onClicked={() => duplicateCurrentSection()}/>
202-
<Button label="[R]emove resource" id={'removeButton'} isEnabled={sections.length > 1} onClicked={() => removeCurrentSection()}/>
203204
<SubmitButton canSubmit={canSubmitForm} onSubmit={onSubmitForm}/>
204205
</Box>
205-
<Text dimColor color='gray'> Provide all required information (<Text color="red">*</Text>) to submit.</Text>
206-
<Text dimColor color='gray'> Up/down: navigate options.</Text>
207-
<Text dimColor color='gray'> Left/right: navigate between resources.</Text>
208-
<Text dimColor color='gray'> Enter: select or edit.</Text>
206+
<Text color='gray'> Up/down: navigate between parameters.</Text>
207+
<Text color='gray'> Left/right: navigate between resources.</Text>
208+
<Text color='gray'> Enter: select or edit.</Text>
209+
<Text color='gray'> [A]: add an additional instance.</Text>
210+
<Text color='gray'> [R]: remove import.</Text>
209211
</Box>
210212

211213
// </Box>

src/FormFieldRenderer.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,11 @@ export const FormFieldRenderer: React.FC<FormFieldRendererProps<any>> = props =>
7373
<Text dimColor>
7474
<RenderValue value={props.value as any ?? '<undefined>'} field={props.field} />
7575
</Text>
76+
{isFocused && (
77+
<Text color='gray' dimColor> (enter to edit)</Text>
78+
)}
7679
</Text>
7780
</Box>
78-
{/*{isFocused && (*/}
79-
{/* <Box>*/}
80-
{/* <Text>Press enter to edit</Text>*/}
81-
{/* </Box>*/}
82-
{/*)}*/}
8381
</Box>
8482
);
8583
} else {

src/FormHeader.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const FormHeader: React.FC<
3232
<Box
3333
borderStyle="single"
3434
width="100%"
35+
paddingBottom={1}
3536
flexDirection="column"
3637
ref={props.headerRef}>
3738
<Box width="100%" marginBottom={1}>

src/ScrollArea.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function ScrollArea({height, isStart, children, numFields, editingMode})
4949
// isStart ensures that the first down event will not scroll. This is because initially nothing has focus so the first down gives focus to the first element
5050
// The children.length calculation calculates a rough estimate of the total height. The 3 is the height of the buttons at the bottom.
5151
// The 5 is the fixed length of the static elements
52-
if (isStart || ((numFields + (3 * 3) + 5) < height)) {
52+
if (isStart || ((numFields + 13) < height)) {
5353
setCanScroll(false);
5454
dispatch({
5555
type: 'RESET'

src/SubmitButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const SubmitButton: React.FC<{
1616
<Box marginRight={2}>
1717
<Box borderStyle={'round'} borderColor={!props.canSubmit ? 'gray' : isFocused ? 'blue' : 'green'} paddingX={2}>
1818
<Text color={!props.canSubmit ? 'gray' : isFocused ? 'blue' : 'green'} bold={true} underline={isFocused}>
19-
{props.canSubmit ? '[S]ubmit' : 'Cannot submit yet'}
19+
{props.canSubmit ? '[s] Submit' : 'Cannot submit yet'}
2020
</Text>
2121
</Box>
2222
</Box>

src/demo/Test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export function Test() {
4040
}, 1000)
4141
}}
4242
form={{
43-
title: "Need more info to identify resources for import",
44-
description: 'multiples could exist on the system',
43+
title: "Identify which instance to import",
44+
description: 'fill out the required information to submit',
4545
sections: [
4646
{
4747
title: "asdf-global",

0 commit comments

Comments
 (0)