[WEB-1501] dev: multiple select core components (#4667)
* dev: multiple select core components * chore: added export statement
This commit is contained in:
parent
c8c86a33f8
commit
98ebe88c86
10 changed files with 691 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
|||
export * from "./filters";
|
||||
export * from "./modals";
|
||||
export * from "./multiple-select";
|
||||
export * from "./sidebar";
|
||||
export * from "./activity";
|
||||
export * from "./favorite-star";
|
||||
|
|
|
|||
36
web/components/core/multiple-select/entity-select-action.tsx
Normal file
36
web/components/core/multiple-select/entity-select-action.tsx
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
// ui
|
||||
import { Checkbox } from "@plane/ui";
|
||||
// helpers
|
||||
import { cn } from "@/helpers/common.helper";
|
||||
// hooks
|
||||
import { TSelectionHelper } from "@/hooks/use-multiple-select";
|
||||
|
||||
type Props = {
|
||||
className?: string;
|
||||
disabled?: boolean;
|
||||
groupId: string;
|
||||
id: string;
|
||||
selectionHelpers: TSelectionHelper;
|
||||
};
|
||||
|
||||
export const MultipleSelectEntityAction: React.FC<Props> = (props) => {
|
||||
const { className, disabled = false, groupId, id, selectionHelpers } = props;
|
||||
// derived values
|
||||
const isSelected = selectionHelpers.getIsEntitySelected(id);
|
||||
|
||||
return (
|
||||
<Checkbox
|
||||
className={cn("!outline-none size-3.5", className)}
|
||||
iconClassName="size-3"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
selectionHelpers.handleEntityClick(e, id, groupId);
|
||||
}}
|
||||
checked={isSelected}
|
||||
data-entity-group-id={groupId}
|
||||
data-entity-id={id}
|
||||
disabled={disabled}
|
||||
readOnly
|
||||
/>
|
||||
);
|
||||
};
|
||||
30
web/components/core/multiple-select/group-select-action.tsx
Normal file
30
web/components/core/multiple-select/group-select-action.tsx
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// ui
|
||||
import { Checkbox } from "@plane/ui";
|
||||
// helpers
|
||||
import { cn } from "@/helpers/common.helper";
|
||||
// hooks
|
||||
import { TSelectionHelper } from "@/hooks/use-multiple-select";
|
||||
|
||||
type Props = {
|
||||
className?: string;
|
||||
disabled?: boolean;
|
||||
groupID: string;
|
||||
selectionHelpers: TSelectionHelper;
|
||||
};
|
||||
|
||||
export const MultipleSelectGroupAction: React.FC<Props> = (props) => {
|
||||
const { className, disabled = false, groupID, selectionHelpers } = props;
|
||||
// derived values
|
||||
const groupSelectionStatus = selectionHelpers.isGroupSelected(groupID);
|
||||
|
||||
return (
|
||||
<Checkbox
|
||||
className={cn("size-3.5 !outline-none", className)}
|
||||
iconClassName="size-3"
|
||||
onClick={() => selectionHelpers.handleGroupClick(groupID)}
|
||||
checked={groupSelectionStatus === "complete"}
|
||||
indeterminate={groupSelectionStatus === "partial"}
|
||||
disabled={disabled}
|
||||
/>
|
||||
);
|
||||
};
|
||||
3
web/components/core/multiple-select/index.ts
Normal file
3
web/components/core/multiple-select/index.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export * from "./entity-select-action";
|
||||
export * from "./group-select-action";
|
||||
export * from "./select-group";
|
||||
22
web/components/core/multiple-select/select-group.tsx
Normal file
22
web/components/core/multiple-select/select-group.tsx
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { observer } from "mobx-react";
|
||||
// hooks
|
||||
import { TSelectionHelper, useMultipleSelect } from "@/hooks/use-multiple-select";
|
||||
|
||||
type Props = {
|
||||
children: (helpers: TSelectionHelper) => React.ReactNode;
|
||||
containerRef: React.MutableRefObject<HTMLElement | null>;
|
||||
entities: Record<string, string[]>; // { groupID: entityIds[] }
|
||||
};
|
||||
|
||||
export const MultipleSelectGroup: React.FC<Props> = observer((props) => {
|
||||
const { children, containerRef, entities } = props;
|
||||
|
||||
const helpers = useMultipleSelect({
|
||||
containerRef,
|
||||
entities,
|
||||
});
|
||||
|
||||
return <>{children(helpers)}</>;
|
||||
});
|
||||
|
||||
MultipleSelectGroup.displayName = "MultipleSelectGroup";
|
||||
Loading…
Add table
Add a link
Reference in a new issue