diff --git a/demo/DemoTable.tsx b/demo/DemoTable.tsx index 51acfea..76f7785 100644 --- a/demo/DemoTable.tsx +++ b/demo/DemoTable.tsx @@ -3,6 +3,8 @@ import {createSmartable, SmartableColumns, SmartableData} from "../src/Smartable import {createColumn, createColumns} from "../src/Smartable/Column"; import {RowDefinition} from "../src/Smartable/Row"; import {CellDefinition} from "../src/Smartable/Cell"; +import {ClickableCell} from "../src/Smartable/Cells/ClickableCell"; +import {Buttons, Modal, ModalType, useModals} from "@kernelui/core"; /** * Some ants names. @@ -111,12 +113,15 @@ export function randomComputationTime(): number export function DemoTable() { + const modals = useModals(); + const demoDataPromise = useMemo>>(() => ( new Promise((resolve) => { // Resolving promise in 2s. window.setTimeout(() => { resolve(Array.from({ length: 15 }).map(() => { // Compute random quantity and unit price. + const name = randomName(); const quantity = randomQuantity(); const price = randomPrice(); @@ -132,7 +137,15 @@ export function DemoTable() return { cells: { name: { - data: randomName(), + data: name, + element: { + const uuid = modals.open( + A great description about these ants. + + + + ); + }} />, }, quantity: { data: quantity, diff --git a/src/Smartable/Cell.tsx b/src/Smartable/Cell.tsx index 70e77f2..8dff04c 100644 --- a/src/Smartable/Cell.tsx +++ b/src/Smartable/Cell.tsx @@ -2,7 +2,6 @@ import React, {useContext} from "react"; import {ColumnKey, useColumn} from "./Column"; import {Smartable} from "./Smartable"; import {useRow} from "./Row"; -import {SpinningLoader} from "@kernelui/core"; /** * Smartable cell definition. @@ -23,14 +22,14 @@ export interface CellDefinition /** * Default cell component. */ -export function Cell({children}: React.PropsWithChildren<{}>) +export function Cell({children, ...props}: React.PropsWithChildren>) { // Get cell data. const {data} = useCell(); // Try to render cell data to string when no children given. return ( - {children ?? String(data)} + {children ?? String(data)} ); } diff --git a/src/Smartable/Cells/ClickableCell.tsx b/src/Smartable/Cells/ClickableCell.tsx new file mode 100644 index 0000000..0a25ce2 --- /dev/null +++ b/src/Smartable/Cells/ClickableCell.tsx @@ -0,0 +1,17 @@ +import React from "react"; +import {Cell} from "../Cell"; +import {Modify} from "@kernelui/core"; + +/** + * Clickable cell component. + */ +export function ClickableCell({role, children, ...props}: React.PropsWithChildren, { + role?: never; +}>>) +{ + return ( + + {children} + + ) +} diff --git a/src/styles/_cells.less b/src/styles/_cells.less new file mode 100644 index 0000000..b74e813 --- /dev/null +++ b/src/styles/_cells.less @@ -0,0 +1,11 @@ +td[role="button"] +{ + transition: background 0.2s ease; + + &:hover + { + background: rgba(0, 0, 0, 0.1); + } + + cursor: pointer; +} diff --git a/src/styles/smartable.less b/src/styles/smartable.less index b1d009f..bf1d56c 100644 --- a/src/styles/smartable.less +++ b/src/styles/smartable.less @@ -1,5 +1,6 @@ table.smartable { + @import "_cells"; @import "_headings"; @import "_loaders"; }