-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#483 add CheckboxCell renderer for boolean columns
- also adds this renderer as the default for boolean columns in case no renderer is specified.
- Loading branch information
1 parent
cabfb53
commit 5fb81d1
Showing
10 changed files
with
136 additions
and
45 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
36 changes: 36 additions & 0 deletions
36
vuu-ui/packages/vuu-table/src/table-next/cell-renderers/checkbox-cell/CheckboxCell.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 @@ | ||
import React, { memo, useCallback } from "react"; | ||
import { TableCellRendererProps } from "@finos/vuu-datagrid-types"; | ||
import { CheckboxIcon, WarnCommit } from "@finos/vuu-ui-controls"; | ||
import { Checkbox } from "@salt-ds/core"; | ||
import { dataAndColumnUnchanged } from "../cell-utils"; | ||
import { dispatchCustomEvent, registerComponent } from "@finos/vuu-utils"; | ||
|
||
export const CheckboxCell: React.FC<TableCellRendererProps> = memo( | ||
({ column, columnMap, onCommit = WarnCommit, row }) => { | ||
const dataIdx = columnMap[column.name]; | ||
const isChecked = row[dataIdx]; | ||
|
||
const handleCommit = useCallback( | ||
(value) => async (evt: React.MouseEvent) => { | ||
const res = await onCommit(value); | ||
if (res === true) { | ||
dispatchCustomEvent(evt.target as HTMLElement, "vuu-commit"); | ||
} | ||
return res; | ||
}, | ||
[onCommit] | ||
); | ||
|
||
return !!column.editable ? ( | ||
<Checkbox checked={isChecked} onClick={handleCommit(!isChecked)} /> | ||
) : ( | ||
<CheckboxIcon checked={isChecked} disabled={true} /> | ||
); | ||
}, | ||
dataAndColumnUnchanged | ||
); | ||
CheckboxCell.displayName = "CheckboxCell"; | ||
|
||
registerComponent("checkbox-cell", CheckboxCell, "cell-renderer", { | ||
serverDataType: "boolean", | ||
}); |
1 change: 1 addition & 0 deletions
1
vuu-ui/packages/vuu-table/src/table-next/cell-renderers/checkbox-cell/index.ts
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 @@ | ||
export * from "./CheckboxCell"; |
1 change: 1 addition & 0 deletions
1
vuu-ui/packages/vuu-table/src/table-next/cell-renderers/index.ts
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
86 changes: 58 additions & 28 deletions
86
vuu-ui/packages/vuu-ui-controls/src/list/CheckboxIcon.css
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 |
---|---|---|
@@ -1,33 +1,63 @@ | ||
.vuuCheckboxIcon { | ||
--vuu-icon-size: 12px; | ||
--vuu-icon-left: -1px; | ||
--vuu-icon-top: -1px; | ||
--vuu-icon-svg: var(--vuu-svg-tick); | ||
border-style: solid; | ||
border-color: var(--vuuCheckboxIcon-borderColor, var(--salt-selectable-borderColor)); | ||
border-radius: var(--vuuCheckboxIcon-borderRadius, 3px); | ||
border-width: 1px; | ||
display: inline-block; | ||
height: var(--vuuCheckboxIcon-size, 12px); | ||
position: relative; | ||
width: var(--vuuCheckboxIcon-size, 12px); | ||
--vuu-icon-size: 12px; | ||
--vuu-icon-left: -1px; | ||
--vuu-icon-top: -1px; | ||
--vuu-icon-svg: var(--vuu-svg-tick); | ||
border-style: solid; | ||
border-color: var( | ||
--vuuCheckboxIcon-borderColor, | ||
var(--salt-selectable-borderColor) | ||
); | ||
border-radius: var(--vuuCheckboxIcon-borderRadius, 3px); | ||
border-width: 1px; | ||
display: inline-block; | ||
height: var(--vuuCheckboxIcon-size, 12px); | ||
position: relative; | ||
width: var(--vuuCheckboxIcon-size, 12px); | ||
} | ||
|
||
.vuuCheckboxIcon-checked { | ||
background-color: var(--vuuCheckboxIcon-background-checked, var(--salt-selectable-background-selected)); | ||
border-color: var(--vuuCheckboxIcon-borderColor-checked, var(--salt-selectable-borderColor-selected)); | ||
.vuuCheckboxIcon-checked-enabled { | ||
background-color: var( | ||
--vuuCheckboxIcon-background-checked-enabled, | ||
var(--vuu-color-purple-10) | ||
); | ||
border-color: var( | ||
--vuuCheckboxIcon-borderColor-checked-enabled, | ||
var(--vuu-color-purple-10) | ||
); | ||
} | ||
|
||
.vuuCheckboxIcon-checked:after { | ||
content: ""; | ||
background-color: white; | ||
left: var(--vuu-icon-left, auto); | ||
height: var(--vuu-icon-height, var(--vuu-icon-size, 12px)); | ||
-webkit-mask: var(--vuu-icon-svg) center center/var(--vuu-icon-size) var(--vuu-icon-size); | ||
mask: var(--vuu-icon-svg) center center/var(--vuu-icon-size) var(--vuu-icon-size); | ||
mask-repeat: no-repeat; | ||
-webkit-mask-repeat: no-repeat; | ||
position: absolute; | ||
top: var(--vuu-icon-top, auto); | ||
width: var(--vuu-icon-width, var(--vuu-icon-size, 12px)); | ||
} | ||
.vuuCheckboxIcon-checked-disabled { | ||
background-color: var( | ||
--vuuCheckboxIcon-background-checked-disabled, | ||
var(--vuu-color-gray-35) | ||
); | ||
border-color: var( | ||
--vuuCheckboxIcon-borderColor-checked-disabled, | ||
var(--vuu-color-gray-35) | ||
); | ||
} | ||
|
||
.vuuCheckboxIcon-checked-enabled::after, | ||
.vuuCheckboxIcon-checked-disabled::after { | ||
content: ""; | ||
background-color: white; | ||
left: var(--vuu-icon-left, auto); | ||
height: var(--vuu-icon-height, var(--vuu-icon-size, 12px)); | ||
-webkit-mask: var(--vuu-icon-svg) center center/var(--vuu-icon-size) | ||
var(--vuu-icon-size); | ||
mask: var(--vuu-icon-svg) center center/var(--vuu-icon-size) | ||
var(--vuu-icon-size); | ||
mask-repeat: no-repeat; | ||
-webkit-mask-repeat: no-repeat; | ||
position: absolute; | ||
top: var(--vuu-icon-top, auto); | ||
width: var(--vuu-icon-width, var(--vuu-icon-size, 12px)); | ||
} | ||
|
||
.vuuCheckboxIcon-checked-disabled::after { | ||
background-color: var( | ||
--vuuCheckboxIcon-tick-checked-disabled, | ||
var(--vuu-color-gray-30) | ||
); | ||
} |
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
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