-
-
Notifications
You must be signed in to change notification settings - Fork 968
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): act-1431 - created view for array types (#1368)
* feat(docs): act-1431 - created view for array types * feat(docs): act-1431 - fix for numder types
- Loading branch information
1 parent
f7d3d0b
commit 9415cba
Showing
7 changed files
with
203 additions
and
18 deletions.
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
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
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
79 changes: 79 additions & 0 deletions
79
src/components/ParserOpenRPC/InteractiveBox/templates/ArrayFieldTemplate.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,79 @@ | ||
import React from "react"; | ||
import { useCollapsible, Collapsible } from "@docusaurus/theme-common"; | ||
import { ArrayFieldTemplateProps } from "@rjsf/utils"; | ||
import { BaseInputTemplate } from "@site/src/components/ParserOpenRPC/InteractiveBox/templates/BaseInputTemplate"; | ||
import clsx from "clsx"; | ||
import styles from "@site/src/components/ParserOpenRPC/InteractiveBox/styles.module.css"; | ||
|
||
export const ArrayFieldTemplate = ({ | ||
title, | ||
formData, | ||
items, | ||
canAdd, | ||
onAddClick | ||
}: ArrayFieldTemplateProps) => { | ||
const { collapsed, toggleCollapsed } = useCollapsible({ initialState: true }); | ||
return ( | ||
<> | ||
<div className={styles.tableRow}> | ||
<div className={styles.tableColumn}> | ||
<label className={styles.tableColumnParam}> | ||
{title} | ||
</label> | ||
</div> | ||
<div className={styles.tableColumn}> | ||
<div className={styles.arrayParentRow}> | ||
<div className={styles.arrayFormDataWrap}> | ||
{JSON.stringify(formData, null, " ")} | ||
</div> | ||
<span | ||
className={styles.arrayColumnType} | ||
onClick={toggleCollapsed} | ||
> | ||
array | ||
<span className={clsx(styles.chevronIcon, collapsed && styles.chevronIconDown)}> | ||
</span> | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
<Collapsible lazy collapsed={collapsed}> | ||
<> | ||
{items.map((el, i) => { | ||
const props = { | ||
...el.children.props, | ||
isArray: true | ||
} | ||
const { index, hasRemove, onDropIndexClick, schema } = el; | ||
const isNumber = schema.type === "number" || schema.type === "integer"; | ||
return ( | ||
<div key={`${i}`} className={styles.arrayItemRowWrap} style={{ paddingRight: `${isNumber ? "25px" : "0"}` }}> | ||
<span className={clsx(styles.addItemIcon, styles.arrayItemIcon)}>{i+1}</span> | ||
<BaseInputTemplate {...props} /> | ||
{hasRemove && ( | ||
<span | ||
onClick={onDropIndexClick(index)} | ||
className={styles.deleteIcon} | ||
> | ||
</span> | ||
)} | ||
</div> | ||
) | ||
})} | ||
{canAdd && ( | ||
<div className={styles.addItemBtnWrap}> | ||
<button | ||
type="button" | ||
onClick={onAddClick} | ||
className={styles.addItemBtn} | ||
> | ||
<span className={styles.addItemIcon}>+</span> | ||
Add array item | ||
</button> | ||
</div> | ||
)} | ||
</> | ||
</Collapsible> | ||
</> | ||
); | ||
}; |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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