-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add placeholders for array, oneOf and prose inputs
- Loading branch information
Showing
6 changed files
with
183 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...s/editing-experience/components/form-builder/renderers/controls/JsonFormsArrayControl.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Box, Heading } from '@chakra-ui/react' | ||
import { | ||
createDefaultValue, | ||
isObjectArrayControl, | ||
rankWith, | ||
type ArrayLayoutProps, | ||
type RankedTester, | ||
} from '@jsonforms/core' | ||
import { withJsonFormsArrayLayoutProps } from '@jsonforms/react' | ||
import { Button } from '@opengovsg/design-system-react' | ||
|
||
export const jsonFormsArrayControlTester: RankedTester = rankWith( | ||
3, | ||
isObjectArrayControl, | ||
) | ||
|
||
export function JsonFormsArrayControl({ | ||
path, | ||
label, | ||
addItem, | ||
schema, | ||
rootSchema, | ||
}: ArrayLayoutProps) { | ||
return ( | ||
<Box py={2}> | ||
<Heading as="h3" size="sm" variant="subhead-1"> | ||
{label} | ||
</Heading> | ||
|
||
<p>Placeholder for drag-and-drop of objects</p> | ||
|
||
<Button | ||
onClick={addItem(path, createDefaultValue(schema, rootSchema))} | ||
mt={3} | ||
w="100%" | ||
variant="outline" | ||
> | ||
Add item | ||
</Button> | ||
</Box> | ||
) | ||
} | ||
|
||
export default withJsonFormsArrayLayoutProps(JsonFormsArrayControl) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...s/editing-experience/components/form-builder/renderers/controls/JsonFormsOneOfControl.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { Box, FormControl } from '@chakra-ui/react' | ||
import { | ||
createCombinatorRenderInfos, | ||
isOneOfControl, | ||
rankWith, | ||
type CombinatorRendererProps, | ||
type RankedTester, | ||
} from '@jsonforms/core' | ||
import { JsonFormsDispatch, withJsonFormsOneOfProps } from '@jsonforms/react' | ||
import { FormLabel, SingleSelect } from '@opengovsg/design-system-react' | ||
import { useState } from 'react' | ||
|
||
export const jsonFormsOneOfControlTester: RankedTester = rankWith( | ||
3, | ||
isOneOfControl, | ||
) | ||
|
||
export function JsonFormsOneOfControl({ | ||
schema, | ||
path, | ||
renderers, | ||
cells, | ||
rootSchema, | ||
uischema, | ||
uischemas, | ||
label, | ||
description, | ||
}: CombinatorRendererProps) { | ||
const oneOfRenderInfos = createCombinatorRenderInfos( | ||
schema.oneOf || [], | ||
rootSchema, | ||
'oneOf', | ||
uischema, | ||
path, | ||
uischemas, | ||
) | ||
const variants = oneOfRenderInfos.map((oneOfRenderInfo) => ({ | ||
label: oneOfRenderInfo.label, | ||
value: oneOfRenderInfo.label, | ||
})) | ||
|
||
const [variant, setVariant] = useState(oneOfRenderInfos[0]?.label || '') | ||
|
||
return ( | ||
<Box py={2}> | ||
<FormControl isRequired> | ||
<FormLabel description={description}>{label}</FormLabel> | ||
<SingleSelect | ||
value={variant} | ||
name={label} | ||
items={variants} | ||
isClearable={false} | ||
onChange={setVariant} | ||
/> | ||
</FormControl> | ||
|
||
{oneOfRenderInfos.map( | ||
(oneOfRenderInfo) => | ||
variant === oneOfRenderInfo.label && ( | ||
<JsonFormsDispatch | ||
key={oneOfRenderInfo.label} | ||
uischema={oneOfRenderInfo.uischema} | ||
schema={oneOfRenderInfo.schema} | ||
path={path} | ||
renderers={renderers} | ||
cells={cells} | ||
/> | ||
), | ||
)} | ||
</Box> | ||
) | ||
} | ||
|
||
export default withJsonFormsOneOfProps(JsonFormsOneOfControl) |
42 changes: 42 additions & 0 deletions
42
...s/editing-experience/components/form-builder/renderers/controls/JsonFormsProseControl.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Box, FormControl } from '@chakra-ui/react' | ||
import { | ||
hasType, | ||
rankWith, | ||
schemaMatches, | ||
type ControlProps, | ||
type RankedTester, | ||
} from '@jsonforms/core' | ||
import { withJsonFormsControlProps } from '@jsonforms/react' | ||
import { FormLabel, Textarea } from '@opengovsg/design-system-react' | ||
|
||
export const jsonFormsProseControlTester: RankedTester = rankWith( | ||
2, | ||
schemaMatches( | ||
(schema) => hasType(schema, 'array') && schema.format === 'prose', | ||
), | ||
) | ||
|
||
// TODO: Replace this with the Tiptap editor | ||
export function JsonFormsProseControl({ | ||
data, | ||
label, | ||
handleChange, | ||
path, | ||
description, | ||
required, | ||
}: ControlProps) { | ||
return ( | ||
<Box py={2}> | ||
<FormControl isRequired={required}> | ||
<FormLabel description={description}>{label}</FormLabel> | ||
<Textarea | ||
value={data || ''} | ||
onChange={(e) => handleChange(path, e.target.value)} | ||
placeholder={label} | ||
/> | ||
</FormControl> | ||
</Box> | ||
) | ||
} | ||
|
||
export default withJsonFormsControlProps(JsonFormsProseControl) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters