Skip to content

Commit

Permalink
feat: add duplicate action to array field
Browse files Browse the repository at this point in the history
  • Loading branch information
siarhei-zharnasek authored Nov 14, 2024
1 parent ccec96e commit 229cbdd
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion packages/core/components/AutoField/fields/ArrayField/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import getClassNameFactory from "../../../../lib/get-class-name-factory";
import styles from "./styles.module.css";
import { List, Plus, Trash } from "lucide-react";
import { Copy, List, Plus, Trash } from "lucide-react";
import { AutoFieldPrivate, FieldPropsInternal } from "../..";
import { IconButton } from "../../../IconButton";
import { reorder, replace } from "../../../../lib";
Expand Down Expand Up @@ -218,6 +218,35 @@ export const ArrayField = ({
<div className={getClassNameItem("rhs")}>
{!readOnly && (
<div className={getClassNameItem("actions")}>
<div className={getClassNameItem("action")}>
<IconButton
type="button"
disabled={!!addDisabled}
onClick={(e) => {
e.stopPropagation();

const existingValue = [
...(value || []),
];

existingValue.splice(
i,
0,
existingValue[i]
);

onChange(
existingValue,
mapArrayStateToUi(
regenerateArrayState(existingValue)
)
);
}}
title="Duplicate"
>
<Copy size={16} />
</IconButton>
</div>
<div className={getClassNameItem("action")}>
<IconButton
type="button"
Expand Down

0 comments on commit 229cbdd

Please sign in to comment.