-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6596de
commit eca12c3
Showing
31 changed files
with
546 additions
and
55 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
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,50 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
export interface ColumnManagerProps { | ||
/** The render-prop function that will receive the relevant props for implementing toggleable columns */ | ||
children: (props: { | ||
/** An array of visible column keys that can be passed directly down to the `<MultiColumnList>` */ | ||
visibleColumns: string[]; | ||
/** Renders a <MenuSection> that wraps renderCheckboxes for toggling columns. This makes it easy to implement inside e.g. a pane action menu. */ | ||
renderColumnsMenu: ReactNode; | ||
/** A method that toggles the visiblity for a given column – e.g. `toggleColumn('email')` */ | ||
toggleColumn: (key: string) => void; | ||
}) => ReactNode; | ||
/** An object that maps keys to labels. The order of the keys will determine the default order of the columns. */ | ||
columnMapping: Record<string, ReactNode>; | ||
/** An array of keys to exclude from the list of toggleable columns */ | ||
excludeKeys?: string[]; | ||
/** | ||
* The unique ID is used to generate the storage key for persisting the visible columns in sessionStorage. | ||
* The ID will also be used as a prefixed ID for any UI that is passed down to the render-prop function. | ||
*/ | ||
id: string; | ||
/** Whether or not to persist the visible columns in sessionStorage */ | ||
persist?: boolean; | ||
} | ||
|
||
/** | ||
* A render-prop component for implementing toggleable columns in a `<MultiColumnList>`. | ||
* | ||
* @example | ||
* ``` | ||
* const columnMapping = { | ||
* status: 'Status', | ||
* name: 'Name', | ||
* barcode: 'Barcode', | ||
* username: 'Username', | ||
* email: 'Email' | ||
* }; | ||
* | ||
* <ColumnManager | ||
* id="users-list-columns" // Required | ||
* columnMapping={columnMapping} // Required | ||
* excludeKeys={['name']} // Exclude these keys from being toggleable | ||
* > | ||
* {({ visibleColumns, renderColumnsMenu, toggleColumn }) => { | ||
* // Render UI | ||
* }} | ||
* </ColumnManager> | ||
* ``` | ||
*/ | ||
export default function ColumnManager(props: ColumnManagerProps): JSX.Element; |
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,17 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
export interface ColumnManagerMenuProps { | ||
/** An object that maps keys to labels */ | ||
columnMapping: Record<string, ReactNode>; | ||
/** An array of keys to exclude from the list of columns */ | ||
excludeColumns?: string[]; | ||
/** Unique ID */ | ||
prefix: string; | ||
/** An array of visible column keys */ | ||
visibleColumns: string[]; | ||
} | ||
|
||
/** | ||
* Renders an action menu section for toggling columns. Provided by `<ColumnManager>` as `renderColumnsMenu`. | ||
*/ | ||
export default function ColumnManagerMenu(props: ColumnManagerMenuProps): JSX.Element; |
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,3 @@ | ||
export { default as ColumnManager, ColumnManagerProps } from './ColumnManager'; | ||
export { default as ColumnManagerMenu, ColumnManagerMenuProps } from './ColumnManagerMenu'; | ||
export { default as useColumnManager } from './useColumnManager'; |
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,11 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
export default function useColumnManager( | ||
prefix: string, | ||
columnMapping: Record<string, ReactNode>, | ||
persist?: boolean, | ||
visibleColumnsProp?: string[], | ||
): { | ||
visibleColumns: string[]; | ||
toggleColumn: (key: string) => void; | ||
}; |
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.