-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add dynamic label and icon to actions (#71)
- Loading branch information
Showing
23 changed files
with
7,712 additions
and
5,117 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@smile/react-front-kit-table': minor | ||
--- | ||
|
||
Update `label` and `icon` action props to accept a function. |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 @@ | ||
export * from './table'; |
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,45 @@ | ||
import type { ITableAction, ITableConfirmAction } from '../types'; | ||
import type { MRT_Row } from 'mantine-react-table'; | ||
import type { ReactNode } from 'react'; | ||
|
||
export function isConfirmAction<Data extends Record<string, unknown>>( | ||
action: ITableAction<Data>, | ||
): action is ITableConfirmAction<Data> { | ||
return 'item' in action; | ||
} | ||
|
||
export function getActionLabel<Data extends Record<string, unknown>>( | ||
action?: ITableAction<Data> | null, | ||
rows?: MRT_Row<Data> | MRT_Row<Data>[], | ||
): string { | ||
if (!action) { | ||
return ''; | ||
} | ||
if (isConfirmAction(action)) { | ||
return typeof action.label === 'function' | ||
? action.label(action.item) | ||
: action.label; | ||
} | ||
if (typeof action.label === 'function') { | ||
return rows ? action.label(rows) : ''; | ||
} | ||
return action.label; | ||
} | ||
|
||
export function getActionIcon<Data extends Record<string, unknown>>( | ||
action?: ITableAction<Data> | null, | ||
rows?: MRT_Row<Data> | MRT_Row<Data>[], | ||
): ReactNode { | ||
if (!action) { | ||
return ''; | ||
} | ||
if (isConfirmAction(action)) { | ||
return typeof action.icon === 'function' | ||
? action.icon(action.item) | ||
: action.icon; | ||
} | ||
if (typeof action.icon === 'function') { | ||
return rows ? action.icon(rows) : ''; | ||
} | ||
return action.icon; | ||
} |
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,3 +1,5 @@ | ||
/* eslint-disable react-refresh/only-export-components */ | ||
export * from './Components/Table/Table'; | ||
export * from './Components/TableGridView/TableGridView'; | ||
export * from './helpers'; | ||
export * from './types'; |
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 './table'; |
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,9 @@ | ||
import type { IAction, IConfirmAction } from '@smile/react-front-kit-shared'; | ||
import type { MRT_Row } from 'mantine-react-table'; | ||
|
||
export type ITableAction<Data extends Record<string, unknown>> = IAction< | ||
MRT_Row<Data> | MRT_Row<Data>[] | ||
>; | ||
|
||
export type ITableConfirmAction<Data extends Record<string, unknown>> = | ||
IConfirmAction<MRT_Row<Data> | MRT_Row<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
Oops, something went wrong.