Skip to content

Commit 161a7e2

Browse files
committed
feat: Altered layout and UI to look more like a JSON object
1 parent c5da68d commit 161a7e2

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

src/Form.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Box, measureElement, useFocusManager, useInput } from 'ink';
1+
import { Box, Text, measureElement, useFocusManager, useInput } from 'ink';
22
import { useEffect, useMemo, useRef, useState } from 'react';
33
import * as React from 'react';
44
import { FormProps } from './types.js';
@@ -127,6 +127,10 @@ export const Form: React.FC<FormProps> = props => {
127127
<DescriptionRenderer description={props.form.sections[currentTab]?.description} />
128128
</Box>
129129
)}
130+
<Box marginLeft={1} marginTop={1}>
131+
<Text bold>{sections[currentTab].title}</Text>
132+
</Box>
133+
<Text>{' {'}</Text>
130134
<Box flexDirection="column">
131135
{currentTab > props.form.sections.length - 1
132136
? null
@@ -143,6 +147,7 @@ export const Form: React.FC<FormProps> = props => {
143147
customManagers={props.customManagers}
144148
/>
145149
))}
150+
<Text>{' }'}</Text>
146151
<Box flexDirection="row-reverse">
147152
<Button label="Add Item (duplicate)" onClicked={() => duplicateCurrentItem()}/>
148153
</Box>

src/FormFieldRenderer.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,17 @@ export const FormFieldRenderer: React.FC<FormFieldRendererProps<any>> = props =>
5252
if (!isEditing) {
5353
const RenderValue = manager?.renderValue ?? (() => <>{props.value}</>);
5454
return (
55-
<Box marginX={2} paddingX={1} borderStyle="round" borderColor={isFocused ? 'blue' : undefined}>
55+
<Box paddingX={1}>
5656
<Box flexGrow={1}>
57-
<Text underline={isFocused} color={isFocused ? 'blue' : undefined}>
58-
{props.field.label ?? props.field.name}
59-
</Text>
60-
{props.field.required && <Text color="red">*</Text>}
61-
<Text>: </Text>
62-
<Text dimColor>
63-
<RenderValue value={props.value as any} field={props.field} />
57+
<Text backgroundColor={isFocused ? 'magentaBright' : undefined}>
58+
<Text>
59+
{`${isFocused ? '> ' : ' '}${(props.field.label ?? props.field.name)}`}
60+
</Text>
61+
{props.field.required && <Text color="red">*</Text>}
62+
<Text>: </Text>
63+
<Text dimColor>
64+
<RenderValue value={props.value as any} field={props.field} />
65+
</Text>
6466
</Text>
6567
</Box>
6668
{isFocused && (

src/ScrollArea.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ const reducer = (state, action) => {
1919
...state,
2020
scrollTop: Math.min(
2121
state.innerHeight - state.height,
22-
state.scrollTop + 3
22+
state.scrollTop + 1
2323
)
2424
};
2525

2626
case 'SCROLL_UP':
2727
return {
2828
...state,
29-
scrollTop: Math.max(0, state.scrollTop - 3)
29+
scrollTop: Math.max(0, state.scrollTop - 1)
3030
};
3131

3232
default:
@@ -47,7 +47,7 @@ export function ScrollArea({height, isStart, children}) {
4747
const innerRef = React.useRef();
4848

4949
useEffect(() => {
50-
if (isStart || (children.length + 3) * 3 < (height - 6)) {
50+
if (isStart || (children.length) * 1 + 3 * 3 < (height - 6)) {
5151
setCanScroll(false);
5252
dispatch({
5353
type: 'RESET'

0 commit comments

Comments
 (0)