-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve theming colors for flashing and improve flashing component
- Loading branch information
1 parent
18ea18b
commit 11cb365
Showing
8 changed files
with
276 additions
and
43 deletions.
There are no files selected for viewing
165 changes: 165 additions & 0 deletions
165
examples/src/pages/tests/table/props/data/flashing-when-ticking.page.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,165 @@ | ||
import { DataSourceApi } from '@infinite-table/infinite-react'; | ||
import { useEffect } from 'react'; | ||
|
||
type Developer = { | ||
birthDate: string; | ||
id: number; | ||
firstName: string; | ||
country: string; | ||
city: string; | ||
currency: string; | ||
email: string; | ||
preferredLanguage: string; | ||
hobby: string; | ||
salary: number; | ||
}; | ||
|
||
export const TICK_INTERVAL = 100; | ||
|
||
let tickingInterval: any | null = null; | ||
|
||
function singleUpdate(dataSourceApi: DataSourceApi<Developer>) { | ||
const arr = dataSourceApi.getRowInfoArray(); | ||
const len = arr.length; | ||
const randomIndex = Math.floor(Math.random() * len); | ||
const rowInfo = arr[randomIndex]; | ||
const id = rowInfo.id; | ||
|
||
if (rowInfo.isGroupRow) { | ||
return; | ||
} | ||
|
||
const currentData = rowInfo.data; | ||
|
||
// generate random signs for the updates for each column | ||
const sign = Math.random() > 0.5 ? 1 : -1; | ||
const currentSalary = currentData.salary; | ||
|
||
const randomDelta = Math.round(Math.random() * Math.abs(currentSalary * 0.1)); | ||
|
||
const newSalary = Math.max(currentSalary + randomDelta * sign, 1000); | ||
|
||
const partialData: Partial<Developer> = { | ||
id, | ||
salary: newSalary, | ||
}; | ||
dataSourceApi.updateData(partialData); | ||
} | ||
function start(dataSourceApi: DataSourceApi<Developer>) { | ||
tickingInterval = setInterval(() => { | ||
singleUpdate(dataSourceApi); | ||
}, TICK_INTERVAL); | ||
} | ||
|
||
function stop() { | ||
if (tickingInterval) { | ||
clearInterval(tickingInterval); | ||
} | ||
} | ||
|
||
export function useTickingData( | ||
dataSourceApi: DataSourceApi<Developer> | null, | ||
tick: boolean, | ||
) { | ||
useEffect(() => { | ||
if (!dataSourceApi) { | ||
return; | ||
} | ||
|
||
if (tick) { | ||
start(dataSourceApi); | ||
} else { | ||
stop(); | ||
} | ||
}, [dataSourceApi, tick]); | ||
} | ||
|
||
import { | ||
InfiniteTable, | ||
DataSource, | ||
InfiniteTablePropColumns, | ||
// FlashingColumnCell, | ||
createFlashingColumnCellComponent, | ||
} from '@infinite-table/infinite-react'; | ||
import * as React from 'react'; | ||
|
||
const FlashingColumnCell = createFlashingColumnCellComponent({ | ||
flashDuration: 1000, | ||
flashClassName: 'flash-cell', | ||
}); | ||
const columns: InfiniteTablePropColumns<Developer> = { | ||
id: { | ||
field: 'id', | ||
}, | ||
firstName: { | ||
field: 'firstName', | ||
}, | ||
salary: { | ||
field: 'salary', | ||
type: 'number', | ||
defaultEditable: true, | ||
getValueToPersist: ({ value }) => { | ||
return value * 1; | ||
}, | ||
components: { | ||
ColumnCell: FlashingColumnCell, | ||
}, | ||
}, | ||
}; | ||
|
||
export default function App() { | ||
const [ticking, setTicking] = React.useState(false); | ||
const [dataSourceApi, setDataSourceApi] = | ||
React.useState<DataSourceApi<Developer> | null>(null); | ||
|
||
useTickingData(dataSourceApi, ticking); | ||
|
||
return ( | ||
<> | ||
<div | ||
className={`infinite-theme-mode--dark infinite-theme-name--ocean`} | ||
style={{ | ||
display: 'flex', | ||
flexFlow: 'column', | ||
flex: 1, | ||
color: 'var(--infinite-cell-color)', | ||
background: 'var(--infinite-background)', | ||
}} | ||
> | ||
<div style={{ paddingBlock: 10 }}> | ||
<button | ||
onClick={() => { | ||
setTicking((x) => !x); | ||
}} | ||
> | ||
{ticking ? 'Stop' : 'Start'} updates | ||
</button> | ||
</div> | ||
|
||
<DataSource<Developer> | ||
data={dataSource} | ||
primaryKey="id" | ||
onReady={setDataSourceApi} | ||
> | ||
<InfiniteTable<Developer> | ||
columns={columns} | ||
domProps={{ | ||
style: { | ||
height: '80%', | ||
}, | ||
}} | ||
/> | ||
</DataSource> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
const dataSource = () => { | ||
return fetch(process.env.NEXT_PUBLIC_BASE_URL + `/developers100-sql?`) | ||
.then((r) => r.json()) | ||
.then((data: Developer[]) => { | ||
console.log(data); | ||
return data; | ||
}); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { ThemeVars } from './vars.css'; | ||
|
||
export const CommonThemeVars = { | ||
[ThemeVars.components.Cell.flashingBackground]: ThemeVars.color.accent, | ||
[ThemeVars.components.Cell.flashingUpBackground]: ThemeVars.color.success, | ||
[ThemeVars.components.Cell.flashingDownBackground]: ThemeVars.color.error, | ||
}; |
3 changes: 2 additions & 1 deletion
3
source/src/components/InfiniteTable/vars-minimalist-light.css.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
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,37 @@ | ||
--- | ||
title: Flashing column cells in Infinite Table | ||
author: admin | ||
draft: true | ||
--- | ||
|
||
Flashing cells is an important feature that has been requested by some of our users - both [in public](https://github.com/infinite-table/infinite-react/issues/250) and private conversations. | ||
|
||
It's also a very useful addition for DataGrids users that work in the financial industry. Version `5.0.0` of `<InfiniteTable />` shipped flashing and in this blogpost we want to show how to use it. | ||
|
||
## Configuring a flashing column. | ||
|
||
In order to configure a column to flash its cells when the data changes, you need to specify a custom `ColumnCell` component. | ||
|
||
```tsx | ||
|
||
import { FlashingColumnCell } from '@infinite-table/infinite-react'; | ||
|
||
const columns: InfiniteTablePropColumns<Developer> = { | ||
id: { | ||
field: 'id', | ||
}, | ||
firstName: { | ||
field: 'firstName', | ||
}, | ||
monthlyBonus: { | ||
field: 'monthlyBonus', | ||
components: { | ||
ColumnCell: FlashingColumnCell, | ||
} | ||
}, | ||
}; | ||
``` | ||
|
||
`@infinite-table/infinite-react` exports a `FlashingColumnCell` React component that you can pass to the `components.ColumnCell` prop of any column you want to flash. | ||
|
||
|