Skip to content

Commit 93918f9

Browse files
committed
Add form/json toggle instead of tabs
1 parent ac6412a commit 93918f9

File tree

3 files changed

+85
-59
lines changed

3 files changed

+85
-59
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react';
2+
import { createCollecticon } from '@devseed-ui/collecticons-chakra';
3+
4+
export const CollecticonForm = createCollecticon((props) => (
5+
<>
6+
{props.title && <title>{props.title}</title>}
7+
<path
8+
fillRule='evenodd'
9+
clipRule='evenodd'
10+
d='M2 9V11H14V9H2ZM1 7C0.447715 7 0 7.44772 0 8V12C0 12.5523 0.447715 13 1 13H15C15.5523 13 16 12.5523 16 12V8C16 7.44772 15.5523 7 15 7H1Z'
11+
fill='currentColor'
12+
/>
13+
<path
14+
fillRule='evenodd'
15+
clipRule='evenodd'
16+
d='M2 2V4H14V2H2ZM1 0C0.447715 0 0 0.447715 0 1V5C0 5.55228 0.447715 6 1 6H15C15.5523 6 16 5.55228 16 5V1C16 0.447715 15.5523 0 15 0H1Z'
17+
fill='currentColor'
18+
/>
19+
<rect y='14' width='8' height='2' fill='currentColor' />
20+
</>
21+
));

packages/client/src/pages/CollectionForm/EditForm.tsx

+60-58
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,16 @@ import {
44
useCollectionPlugins,
55
WidgetRenderer
66
} from '@stac-manager/data-core';
7-
import {
8-
Box,
9-
Button,
10-
Flex,
11-
Heading,
12-
Tab,
13-
TabList,
14-
TabPanel,
15-
TabPanels,
16-
Tabs
17-
} from '@chakra-ui/react';
7+
import { Box, Button, ButtonGroup, Flex, Heading } from '@chakra-ui/react';
188
import { Formik, FormikHelpers } from 'formik';
199
import { WidgetJSON } from '@stac-manager/data-widgets';
20-
import { CollecticonTickSmall } from '@devseed-ui/collecticons-chakra';
10+
import {
11+
CollecticonCode,
12+
CollecticonTickSmall
13+
} from '@devseed-ui/collecticons-chakra';
2114

2215
import { InnerPageHeaderSticky } from '$components/InnerPageHeader';
16+
import { CollecticonForm } from '$components/icons/form';
2317

2418
type FormView = 'fields' | 'json';
2519

@@ -88,52 +82,60 @@ export function EditForm(props: {
8882
</>
8983
}
9084
/>
91-
<Tabs
92-
isLazy
93-
variant='enclosed'
94-
index={view === 'fields' ? 0 : 1}
95-
onChange={(i) => {
96-
setView(['fields', 'json'][i] as FormView);
97-
setStacData(
98-
view === 'json' ? values.jsonData : toOutData(values)
99-
);
100-
}}
101-
>
102-
<TabList>
103-
<Tab bg='base.50a'>FORM</Tab>
104-
<Tab>JSON</Tab>
105-
</TabList>
106-
<TabPanels>
107-
<TabPanel p={0} display='flex' flexFlow='column' gap={4}>
108-
{view === 'fields' &&
109-
plugins.map((pl) => (
110-
<PluginBox key={pl.name} plugin={pl}>
111-
{({ field }) => (
112-
<Box
113-
p='16'
114-
borderRadius='lg'
115-
bg='base.50a'
116-
display='flex'
117-
flexDir='column'
118-
gap={8}
119-
>
120-
<Heading size='sm'>{pl.name}</Heading>
121-
<WidgetRenderer pointer='' field={field} />
122-
</Box>
123-
)}
124-
</PluginBox>
125-
))}
126-
</TabPanel>
127-
<TabPanel p={0} pt={4}>
128-
{view === 'json' && (
129-
<WidgetJSON
130-
field={{ type: 'json', label: 'Json Document' }}
131-
pointer='jsonData'
132-
/>
133-
)}
134-
</TabPanel>
135-
</TabPanels>
136-
</Tabs>
85+
<Flex alignItems='center' justifyContent='space-between' p={4}>
86+
<Heading size='md'>{initialData ? 'Edit' : 'New'}</Heading>
87+
88+
<ButtonGroup isAttached variant='outline' size='sm'>
89+
<Button
90+
aria-label='Edit Form'
91+
leftIcon={<CollecticonForm />}
92+
onClick={() => {
93+
setView('fields');
94+
setStacData(values.jsonData);
95+
}}
96+
isActive={view === 'fields'}
97+
>
98+
Form
99+
</Button>
100+
<Button
101+
aria-label='Edit JSON'
102+
leftIcon={<CollecticonCode />}
103+
onClick={() => {
104+
setView('json');
105+
setStacData(toOutData(values));
106+
}}
107+
isActive={view === 'json'}
108+
>
109+
JSON
110+
</Button>
111+
</ButtonGroup>
112+
</Flex>
113+
<Flex flexFlow='column' gap={4}>
114+
{view === 'fields' ? (
115+
plugins.map((pl) => (
116+
<PluginBox key={pl.name} plugin={pl}>
117+
{({ field }) => (
118+
<Box
119+
p='16'
120+
borderRadius='lg'
121+
bg='base.50a'
122+
display='flex'
123+
flexDir='column'
124+
gap={8}
125+
>
126+
<Heading size='sm'>{pl.name}</Heading>
127+
<WidgetRenderer pointer='' field={field} />
128+
</Box>
129+
)}
130+
</PluginBox>
131+
))
132+
) : (
133+
<WidgetJSON
134+
field={{ type: 'json', label: 'Json Document' }}
135+
pointer='jsonData'
136+
/>
137+
)}
138+
</Flex>
137139
</Flex>
138140
)}
139141
</Formik>

packages/client/src/theme/theme.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ const theme = {
7474
Button: {
7575
baseStyle: {
7676
borderRadius: 'md',
77-
fontWeight: '700'
77+
fontWeight: '700',
78+
':is(a):hover': {
79+
textDecoration: 'none'
80+
}
7881
},
7982
sizes: {
8083
xs: {

0 commit comments

Comments
 (0)