-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mantine, table): allow InlineConfirm actions in table (#3721)
chore(mantine, table): add demo for inline confirm
- Loading branch information
1 parent
17059aa
commit ef7f822
Showing
4 changed files
with
129 additions
and
20 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
85 changes: 85 additions & 0 deletions
85
packages/website/src/examples/layout/Table/TableConfirmAction.demo.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,85 @@ | ||
import {ColumnDef, createColumnHelper, InlineConfirm, showNotification, Table, useTable} from '@coveord/plasma-mantine'; | ||
import {DeleteSize16Px} from '@coveord/plasma-react-icons'; | ||
import {faker} from '@faker-js/faker'; | ||
import {useMemo} from 'react'; | ||
|
||
const columnHelper = createColumnHelper<Person>(); | ||
|
||
/** | ||
* Define your columns outside the component rendering the table | ||
* (or memoize them) to avoid unnecessary render loops | ||
*/ | ||
const columns: Array<ColumnDef<Person>> = [ | ||
columnHelper.accessor('firstName', { | ||
header: 'First name', | ||
enableSorting: false, | ||
}), | ||
columnHelper.accessor('lastName', { | ||
header: 'Last name', | ||
enableSorting: false, | ||
}), | ||
columnHelper.accessor('age', { | ||
header: 'Age', | ||
enableSorting: false, | ||
}), | ||
]; | ||
|
||
const Demo = () => { | ||
// How you manage your data and loading state is up to you | ||
// Just make sure data is a stable reference and isn't recreated on every render | ||
// Here for the sake of example we're building 10 rows of mock data | ||
const data = useMemo(() => makeData(10), []); | ||
|
||
// `useTable` hook provides a table store. | ||
// The store contains the current state of the table and methods to update it. | ||
const table = useTable<Person>({ | ||
initialState: {totalEntries: data.length}, | ||
}); | ||
|
||
return ( | ||
<Table<Person> store={table} data={data} columns={columns} getRowId={({id}) => id.toString()}> | ||
<Table.Actions> | ||
{(selectedRow: Person) => ( | ||
<> | ||
<InlineConfirm.Target | ||
component={Table.ActionItem} | ||
id="delete" | ||
leftSection={<DeleteSize16Px height={16} />} | ||
> | ||
Delete | ||
</InlineConfirm.Target> | ||
<InlineConfirm.Prompt | ||
id="delete" | ||
label={`Are you sure you want to delete ${selectedRow.firstName} ${selectedRow.lastName}?`} | ||
onConfirm={() => showNotification({message: 'Confirm clicked', autoClose: true})} | ||
onCancel={() => showNotification({message: 'Cancel clicked', autoClose: true})} | ||
/> | ||
</> | ||
)} | ||
</Table.Actions> | ||
<Table.Header /> | ||
</Table> | ||
); | ||
}; | ||
export default Demo; | ||
|
||
export type Person = { | ||
id: string; | ||
firstName: string; | ||
lastName: string; | ||
age: number; | ||
bio: string; | ||
pic: string; | ||
}; | ||
|
||
const makeData = (len: number): Person[] => | ||
Array(len) | ||
.fill(0) | ||
.map(() => ({ | ||
id: faker.string.uuid(), | ||
pic: faker.image.avatar(), | ||
firstName: faker.person.firstName(), | ||
lastName: faker.person.lastName(), | ||
age: faker.number.int(40), | ||
bio: faker.lorem.sentences({min: 1, max: 5}), | ||
})); |
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