-
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
70fdd01
commit de0a4d3
Showing
9 changed files
with
134 additions
and
44 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
39 changes: 39 additions & 0 deletions
39
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,39 @@ | ||
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 ( | ||
<React.Fragment> | ||
{!!column.editable ? ( | ||
<Checkbox checked={isChecked} onClick={handleCommit(!isChecked)} /> | ||
) : ( | ||
<CheckboxIcon checked={isChecked} disabled={true} /> | ||
)} | ||
</React.Fragment> | ||
); | ||
}, | ||
dataAndColumnUnchanged | ||
); | ||
|
||
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
82 changes: 54 additions & 28 deletions
82
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,59 @@ | ||
.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); | ||
--vuuCheckboxIcon-background-checked: var(--vuu-color-purple-10); | ||
--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, | ||
var(--salt-selectable-background-selected) | ||
); | ||
border-color: var( | ||
--vuuCheckboxIcon-borderColor-checked, | ||
var(--salt-selectable-borderColor-selected) | ||
); | ||
} | ||
|
||
.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-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 { | ||
--vuuCheckboxIcon-background-disabled: var( | ||
--vuuCheckboxIcon-background-disbaled, | ||
var(--salt-selectable-background-disabled) | ||
); | ||
background-color: var(--vuuCheckboxIcon-background-disabled); | ||
border-color: var(--vuuCheckboxIcon-background-disabled); | ||
} | ||
|
||
.vuuCheckboxIcon-checked-disabled::after { | ||
background-color: 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