-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WEB-1501] dev: multiple select core components (#4667)
* dev: multiple select core components * chore: added export statement
- Loading branch information
1 parent
2127368
commit 87f1653
Showing
10 changed files
with
691 additions
and
0 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
36 changes: 36 additions & 0 deletions
36
web/components/core/multiple-select/entity-select-action.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,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 changes: 30 additions & 0 deletions
30
web/components/core/multiple-select/group-select-action.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,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} | ||
/> | ||
); | ||
}; |
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,3 @@ | ||
export * from "./entity-select-action"; | ||
export * from "./group-select-action"; | ||
export * from "./select-group"; |
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,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"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { useContext } from "react"; | ||
// store | ||
import { StoreContext } from "@/lib/store-context"; | ||
|
||
export const useMultipleSelectStore = () => { | ||
const context = useContext(StoreContext); | ||
if (context === undefined) throw new Error("useMultipleSelectStore must be used within StoreProvider"); | ||
return context.multipleSelect; | ||
}; |
Oops, something went wrong.