-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use new Checkbox everywhere * Remove unnecessary braces * Add popover component * Use popover for export options * Update changelog
- Loading branch information
Showing
24 changed files
with
393 additions
and
768 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
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
72 changes: 0 additions & 72 deletions
72
packages/graph-explorer/src/components/Checkbox/Checkbox.styles.ts
This file was deleted.
Oops, something went wrong.
142 changes: 0 additions & 142 deletions
142
packages/graph-explorer/src/components/Checkbox/Checkbox.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
105 changes: 105 additions & 0 deletions
105
packages/graph-explorer/src/components/CheckboxList.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,105 @@ | ||
import { cn } from "@/utils"; | ||
import { ReactNode } from "react"; | ||
import { Checkbox, Label } from "./radix"; | ||
import Divider from "./Divider"; | ||
|
||
export type CheckboxListItemProps = { | ||
id: string; | ||
text: ReactNode; | ||
endAdornment?: ReactNode; | ||
isDisabled?: boolean; | ||
}; | ||
|
||
export type CheckboxListProps = { | ||
/** | ||
* Override or extend the styles applied to the component. | ||
*/ | ||
className?: string; | ||
/** | ||
* The content to display as element title. | ||
*/ | ||
title?: string; | ||
/** | ||
* Checkboxes array to be displayed. | ||
*/ | ||
checkboxes: Array<CheckboxListItemProps>; | ||
/** | ||
* Id values shown as selected checkboxes | ||
*/ | ||
selectedIds: Set<string>; | ||
/** | ||
* If true <code>true</code> the component is disabled | ||
*/ | ||
isDisabled?: boolean; | ||
/** | ||
* Callback fired when the state is changed | ||
*/ | ||
onChange(id: string, isSelected: boolean): void; | ||
/** | ||
* Callback fired when the state of all checkboxes it wants to be changed. | ||
* If this method is not defined, the "all/none" Checkbox is removed. | ||
*/ | ||
onChangeAll?(isSelected: boolean): void; | ||
}; | ||
|
||
export default function CheckboxList({ | ||
className, | ||
title, | ||
checkboxes, | ||
isDisabled, | ||
selectedIds, | ||
onChange, | ||
onChangeAll, | ||
}: CheckboxListProps) { | ||
const numOfSelections = selectedIds.size; | ||
const totalCheckboxes = checkboxes.length; | ||
const allDisabled = checkboxes.reduce( | ||
(disabled, ch) => disabled && !!ch.isDisabled, | ||
true | ||
); | ||
|
||
return ( | ||
<div className={cn("space-y-2", className)}> | ||
{title && <div className="text-base font-medium">{title}</div>} | ||
<div className="border-divider flex flex-col gap-3 rounded-lg border py-3"> | ||
{checkboxes.map(checkbox => { | ||
return ( | ||
<Label | ||
key={checkbox.id} | ||
className="w-full px-3 hover:cursor-pointer" | ||
> | ||
<Checkbox | ||
aria-label={`checkbox for ${checkbox.id}`} | ||
checked={selectedIds.has(checkbox.id)} | ||
disabled={isDisabled || checkbox.isDisabled} | ||
onCheckedChange={isSelected => | ||
onChange(checkbox.id, Boolean(isSelected)) | ||
} | ||
></Checkbox> | ||
<div className="grow">{checkbox.text}</div> | ||
<div className="[&_svg]:size-5">{checkbox.endAdornment}</div> | ||
</Label> | ||
); | ||
})} | ||
<Divider /> | ||
{onChangeAll && ( | ||
<Label className="inline-flex items-center gap-2 px-3 tabular-nums hover:cursor-pointer"> | ||
<Checkbox | ||
aria-label="checkbox for all" | ||
checked={ | ||
numOfSelections > 0 && numOfSelections !== totalCheckboxes | ||
? "indeterminate" | ||
: numOfSelections === totalCheckboxes | ||
} | ||
disabled={isDisabled || allDisabled} | ||
onCheckedChange={isSelected => { | ||
onChangeAll(Boolean(isSelected)); | ||
}} | ||
/> | ||
{numOfSelections} selected of {totalCheckboxes} | ||
</Label> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.