Files
spacedrive/interface/app/$libraryId/Explorer/ContextMenu/ConditionalItem.tsx
nikec 9c0aec8167 [ENG-300] Explorer multi-select (#1197)
* grid

* Improved multi-select, grid list & view offset. Added gap option & app frame.

* List view multi-select

* Include multi-select in overview, fix page ref type

* Add gap to options panel

* Fix drag

* Update categories z-index

* going pretty well

* fix a couple bugs

* fix another bug :)

* minor improvements

* Separate grid activeItem

* extra comments

* um akshully don't ref during render

* show thumbnails yay

* cleanup

* Clean up

* Fix ranges

* here it is

* fix cols drag

* don't enforce selecto context

* explorer view selectable

* Update index.tsx

* Context menu support for multi-select (#1187)

* here it is

* stopPropagation

* cut copy multiple

---------

Co-authored-by: nikec <nikec.job@gmail.com>

* explorer view selectable

* Update index.tsx

* items Map

* fix renamable

* Update inspector

* Hide tag assign if empty

* fix merge

* cleanup

* fix un-rendered drag select

* fix double click quick preview

* update thumbnail

* mostly handle multiple select in keybindings

* fix ts

* remove another todo

* move useItemAs hooks to @sd/client

* fix thumb controls

* multi-select double click

* cleaner?

* smaller gap

---------

Co-authored-by: Jamie Pine <ijamespine@me.com>
Co-authored-by: Brendan Allan <brendonovich@outlook.com>
Co-authored-by: Jamie Pine <32987599+jamiepine@users.noreply.github.com>
Co-authored-by: Utku <74243531+utkubakir@users.noreply.github.com>
Co-authored-by: Ericson "Fogo" Soares <ericson.ds999@gmail.com>
2023-08-15 08:23:41 +00:00

46 lines
1.4 KiB
TypeScript

import { ReactNode } from 'react';
type UseCondition<TProps extends object> = () => TProps | null;
export class ConditionalItem<TProps extends object> {
// Named like a hook to please eslint
useCondition: UseCondition<TProps>;
// Capital 'C' to please eslint + make rendering after destructuring easier
Component: React.FC<TProps>;
constructor(public args: { useCondition: UseCondition<TProps>; Component: React.FC<TProps> }) {
this.useCondition = args.useCondition;
this.Component = args.Component;
}
}
export interface ConditionalGroupProps {
items: ConditionalItem<any>[];
children?: (children: ReactNode) => ReactNode;
}
/**
* Takes an array of `ConditionalItem` and attempts to render them all,
* returning `null` if all conditions are `null`.
*
* @param items An array of `ConditionalItem` to render.
* @param children An optional render function that can be used to wrap the rendered items.
*/
export const Conditional = ({ items, children }: ConditionalGroupProps) => {
const itemConditions = items.map((item) => item.useCondition());
if (itemConditions.every((c) => c === null)) return null;
const renderedItems = (
<>
{itemConditions.map((props, i) => {
if (props === null) return null;
const { Component } = items[i]!;
return <Component key={i} {...props} />;
})}
</>
);
return <>{children ? children(renderedItems) : renderedItems}</>;
};