Skip to content

Commit

Permalink
feat: support for non-interactable reordering
Browse files Browse the repository at this point in the history
  • Loading branch information
Tormak9970 committed Feb 1, 2023
1 parent 47a6fdd commit dbd01b1
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/custom-components/ReorderableList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Fragment, JSXElementConstructor, ReactElement, useState } from "react"
import { FaEllipsisH } from "react-icons/fa"
import { DialogButton, Field, Focusable, GamepadButton } from "../deck-components"
import { IconType } from "react-icons"
import { Fragment, JSXElementConstructor, ReactElement, useState } from "react";
import { Field, FieldProps, Focusable, GamepadButton } from "../deck-components";

export type ReorderableEntry<T> = {
label: string,
Expand All @@ -11,10 +9,9 @@ export type ReorderableEntry<T> = {

type ListProps<T> = {
entries: ReorderableEntry<T>[],
onAction: (entryReference: ReorderableEntry<T>) => void,
onSave: (entries: ReorderableEntry<T>[]) => void,
secondButton?: JSXElementConstructor<{entry:ReorderableEntry<T>}>,
primaryIcon?:IconType
interactables?: JSXElementConstructor<{entry:ReorderableEntry<T>}>,
fieldProps?: FieldProps
}

/**
Expand Down Expand Up @@ -63,8 +60,8 @@ export function ReorderableList<T>(props: ListProps<T>) {
onClick={toggleReorderEnabled}>
{
entryList.map((entry: ReorderableEntry<T>) => (
<ReorderableItem listData={entryList} entryData={entry} reorderEntryFunc={setEntryList} reorderEnabled={reorderEnabled} onAction={props.onAction} primaryIcon={props.primaryIcon ? props.primaryIcon : FaEllipsisH}>
{props.secondButton ? <props.secondButton entry={entry} /> : null}
<ReorderableItem listData={entryList} entryData={entry} reorderEntryFunc={setEntryList} reorderEnabled={reorderEnabled} fieldProps={props.fieldProps}>
{props.interactables ? <props.interactables entry={entry} /> : null}
</ReorderableItem>
))
}
Expand All @@ -75,13 +72,12 @@ export function ReorderableList<T>(props: ListProps<T>) {
}

type ListEntryProps<T> = {
fieldProps?: FieldProps,
listData: ReorderableEntry<T>[],
entryData: ReorderableEntry<T>,
reorderEntryFunc: CallableFunction,
reorderEnabled: boolean,
onAction: (entryReference: ReorderableEntry<T>) => void,
children:ReactElement|null,
primaryIcon: IconType
children:ReactElement|null
}

function ReorderableItem<T>(props: ListEntryProps<T>) {
Expand Down Expand Up @@ -124,12 +120,9 @@ function ReorderableItem<T>(props: ListEntryProps<T>) {

return(
// @ts-ignore
<Field label={props.entryData.label} style={props.reorderEnabled ? {...baseCssProps, background: "#678BA670"} : {...baseCssProps}}>
<Focusable style={{ display: "flex", width: "100%", position: "relative" }} onButtonDown={onReorder}>
<Field label={props.entryData.label} style={props.reorderEnabled ? {...baseCssProps, background: "#678BA670"} : {...baseCssProps}} {...props.fieldProps} focusable={!props.children} onButtonDown={onReorder}>
<Focusable style={{ display: "flex", width: "100%", position: "relative" }}>
{props.children}
<DialogButton style={{ height: "40px", minWidth: "40px", width: "40px", display: "flex", justifyContent: "center", alignItems: "center", padding: "10px" }} onClick={() => props.onAction(props.entryData)} onOKButton={() => props.onAction(props.entryData)}>
<props.primaryIcon />
</DialogButton>
</Focusable>
</Field>
);
Expand Down

0 comments on commit dbd01b1

Please sign in to comment.