export const SelectionTable: Story = {
args: {
},
};
export const GridWithResizing: Story = {
args: {
},
};
добавь argTypes и args
Assistant
To enhance the story setup for your MantineTable component in Storybook, you can define argTypes and args to specify and control the behavior of the component during development and testing. argTypes allow you to define the types and controls for the arguments that your component accepts, while args are the default values for those arguments in your stories.
Here's an updated version of your Storybook setup with argTypes and args added:
argTypes: Defines the types and controls available for each prop of your component. Each property of argTypes includes:
control: Specifies the type of control (e.g., array, select, etc.) for the Storybook interface.
description: Provides a brief description of what the prop does.
defaultValue: Sets a default value for the prop.
args: Allows setting default values for each story. These values are used to render the component.
Examples:
data and columns are defined as arrays with control set to array to allow data entry in Storybook.
onRowSelectionChange is defined as an action to log changes in row selection during interaction.
Props can be expanded for additional functionality, such as enabling row resizing.
This setup will help you and other developers interact with the MantineTable component in a more meaningful way within Storybook, visualizing how different props and settings affect its behavior.
User
import React from 'react';
import {
MantineReactTable,
useMantineReactTable,
type MRT_ColumnDef,
MRT_GlobalFilterTextInput,
MRT_ToggleFiltersButton,
MRT_AggregationFns,
MRT_SelectCheckbox,
} from 'mantine-react-table';
import { faker } from '@faker-js/faker';
export const SelectionTable: Story = {
args: {
},
};
export const GridWithResizing: Story = {
args: {
},
};
нужно добавить enableRowSelection
Assistant
To add enableRowSelection as a configurable option in your Storybook setup for the MantineTable, you can adjust the component to accept props from your stories and define argTypes to include the enableRowSelection prop. This way, you can control this feature through Storybook's UI.
Here's how you can update your MantineTable component and its corresponding stories:
Update MantineTable Component
First, update the MantineTable component to accept props for configuration:
Now, update your Storybook configuration to include enableRowSelection in argTypes and apply it in your stories:
javascript
User
import React from 'react';
import {
MantineReactTable,
useMantineReactTable,
type MRT_ColumnDef
} from 'mantine-react-table';
import { faker } from '@faker-js/faker';
export const SelectionTable: Story = {
args: {
},
};
нужно чтобы в таблице была возможность выбирать строки и эта таблица называлась SelectionTable
Assistant
To enable row selection in the SelectionTable story within your Storybook setup, you need to update the MantineTable component to accept props for dynamic configuration and modify the Storybook story to have enableRowSelection set to true for the SelectionTable.
Here's how you can achieve this:
Update MantineTable Component
First, modify your component to accept enableRowSelection as a prop:
Now, update your Storybook stories to make use of enableRowSelection:
javascript
User
добавь сюда еще enableRowSelection
Assistant
To incorporate enableRowSelection into the component and Storybook configuration, you need to ensure that it's properly passed and controlled for each story. Here's the complete setup:
Update MantineTable Component
Ensure the MantineTable component accepts enableRowSelection as a prop, allowing dynamic control through Storybook:
Set up your Storybook to pass enableRowSelection as an argument to the component:
javascript
User
добавь еще enableColumnResizing
Assistant
To add enableColumnResizing to your MantineTable component and Storybook configuration, you will need to modify both the component and the Storybook stories to accept and demonstrate this feature. Here's how you can do it:
Update MantineTable Component
First, ensure your MantineTable component can accept both enableRowSelection and enableColumnResizing as props:
Now, update your Storybook stories to include enableColumnResizing:
javascript
User
добавь стили к таблице, чтобы таблица расределялась по ширине контейнера, пусть меню вверху таблицы была справа, пагинация отображалась корректно
Assistant
To style the MantineTable component so that it distributes evenly across the width of its container, displays the top menu aligned to the right, and shows pagination correctly, you will need to apply some custom styles. Here’s how you could update your component and potentially use some CSS or inline styles to achieve this layout:
Update MantineTable Component with Styling
Below is an updated version of your MantineTable component, incorporating styles for layout adjustments using inline styles or a CSS module:
import type { StoryObj } from '@storybook/react';
import MantineTable from './table';
// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
const meta = {
title: 'Mantine/MRTable',
component: MantineTable,
parameters: {
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/react/configure/story-layout
layout: 'centered',
},
tags: ['autodocs'],
argTypes: {
enableRowSelection: {
control: 'boolean',
description: 'Enable or disable row selection',
defaultValue: false,
},
enableColumnResizing: {
control: 'boolean',
description: 'Enable or disable column resizing',
},
enableColumnOrdering: {
control: 'boolean',
description: 'Enable or disable column ordering',
},
}
};
нужно чтобы в таблицы можно было прокинуть любые данные
Assistant
To make your MantineTable component flexible enough to accept any arbitrary data and column definitions from Storybook, you'll need to structure the component to receive these as props. Here’s how you can update the component and your Storybook setup to achieve this:
Update MantineTable Component
First, modify your MantineTable component to accept data and columns as props:
Now, modify your Storybook stories to provide sample data and column definitions for each story:
javascript
User
к примеру так export const DefaultSemantic = ({ tableData, columns }: { tableData: any[], columns: MRT_ColumnDef[] })
Assistant
To set up your MantineTable component and Storybook stories to accept any arbitrary data and column definitions similarly to the example you've provided with DefaultSemantic, you'll need to adjust your component and story configurations accordingly.
Here’s how you can structure your MantineTable component and the DefaultSemantic story to allow passing tableData and columns:
Update MantineTable Component
First, ensure your MantineTable component can accept tableData and columns:
Modify your Storybook to demonstrate passing arbitrary data and column definitions:
javascript
User
import React from 'react';
import {
MantineReactTable,
useMantineReactTable,
type MRT_ColumnDef
} from 'mantine-react-table';
import { faker } from '@faker-js/faker';
import type { StoryObj } from '@storybook/react';
import MantineTable from './table';
// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
const meta = {
title: 'Mantine/MRTable',
component: MantineTable,
parameters: {
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/react/configure/story-layout
layout: 'centered',
},
tags: ['autodocs'],
argTypes: {
enableRowSelection: {
control: 'boolean',
description: 'Enable or disable row selection',
defaultValue: false,
},
enableColumnResizing: {
control: 'boolean',
description: 'Enable or disable column resizing',
},
enableColumnOrdering: {
control: 'boolean',
description: 'Enable or disable column ordering',
},
}
};
import { DefaultTable } from '@/components/MRTable/table.stories';
export default function Page() {
return (
)
}
Assistant
To allow data to be passed to your MantineTable component from a parent component or a page, you should refactor the component to accept data and columns as props. Then, when you render the table in your page, you can pass these props accordingly. Here's how you can achieve that:
Update MantineTable Component
First, modify the MantineTable component to accept data and columns from its props:
import type { StoryObj } from '@storybook/react';
import MantineTable from './table';
const meta = {
title: 'Mantine/MRTable',
component: MantineTable,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
argTypes: {
enableRowSelection: {
control: 'boolean',
description: 'Enable or disable row selection',
},
},
};
export default meta;
type Story = StoryObj<typeof MantineTable>;
export const DefaultTable: Story = {
args: {
enableRowSelection: false,
},
};
export const SelectionTable: Story = {
args: {
enableRowSelection: true,
},
};
export const GridWithResizing: Story = {
args: {
enableRowSelection: false,
},
};
Explanation:
Component Update: The MantineTable component now accepts a enableRowSelection prop, which defaults to false.
Storybook Configuration:
argTypes: Added enableRowSelection with a boolean control, allowing toggling between enabling and disabling row selection.
Stories:
DefaultTable: Row selection is disabled (enableRowSelection: false).
SelectionTable: Row selection is enabled (enableRowSelection: true).
GridWithResizing: Also demonstrates with row selection disabled as part of its current configuration.
By setting up your Storybook in this way, you can easily switch between configurations and visualize how enabling or disabling row selection affects your table component.
import type { StoryObj } from '@storybook/react';
import MantineTable from './table';
const meta = {
title: 'Mantine/MRTable',
component: MantineTable,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
argTypes: {
enableRowSelection: {
control: 'boolean',
description: 'Enable or disable row selection',
defaultValue: false,
},
},
};
export default meta;
type Story = StoryObj<typeof MantineTable>;
export const DefaultTable: Story = {
args: {
enableRowSelection: false,
},
};
export const SelectionTable: Story = {
args: {
enableRowSelection: true,
},
};
Explanation
Component Update: Added a MantineTableProps type with enableRowSelection, and updated the MantineTable component to receive this prop. This allows the Storybook stories to dynamically control row selection.
Storybook Configuration:
argTypes: Included enableRowSelection with a boolean control, making it easy to toggle this feature from the Storybook UI.
Stories:
DefaultTable: Row selection is disabled (enableRowSelection: false).
SelectionTable: Row selection is enabled (enableRowSelection: true), allowing users to select rows within the table.
By configuring enableRowSelection this way, you can easily switch between enabling and disabling row selection through Storybook, making it a versatile tool for testing and demonstration.
import type { StoryObj } from '@storybook/react';
import MantineTable from './table';
const meta = {
title: 'Mantine/MRTable',
component: MantineTable,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
argTypes: {
enableRowSelection: {
control: 'boolean',
description: 'Enable or disable row selection',
defaultValue: false,
},
},
};
export default meta;
type Story = StoryObj<typeof MantineTable>;
export const DefaultTable: Story = {
args: {
enableRowSelection: false,
},
};
export const SelectionTable: Story = {
args: {
enableRowSelection: true,
},
};
Explanation
MantineTable Component: The component now takes enableRowSelection as a prop. This flexibility allows us to change its behavior directly from a Storybook story.
Storybook Configuration:
argTypes: Specifies enableRowSelection as a boolean with a control in Storybook, providing a UI to toggle this option.
Stories:
DefaultTable: Demonstrates the table with row selection disabled.
SelectionTable: Configures the table with row selection enabled, allowing users to interact with row selections during testing and demo.
This setup allows you to easily demonstrate and test the row selection feature in your table component directly through Storybook.
import type { StoryObj } from '@storybook/react';
import MantineTable from './table';
const meta = {
title: 'Mantine/MRTable',
component: MantineTable,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
argTypes: {
enableRowSelection: {
control: 'boolean',
description: 'Enable or disable row selection',
},
enableColumnResizing: {
control: 'boolean',
description: 'Enable or disable column resizing',
},
},
};
export default meta;
type Story = StoryObj<typeof MantineTable>;
export const DefaultTable: Story = {
args: {
enableRowSelection: false,
enableColumnResizing: false,
},
};
export const SelectionTable: Story = {
args: {
enableRowSelection: true,
enableColumnResizing: false,
},
};
export const ResizableColumnsTable: Story = {
args: {
enableRowSelection: false,
enableColumnResizing: true,
},
};
export const SelectionAndResizableColumnsTable: Story = {
args: {
enableRowSelection: true,
enableColumnResizing: true,
},
};
Explanation
Component Update: The MantineTable component is now flexible, accepting both enableRowSelection and enableColumnResizing as props. This enables you to dynamically control these features.
Storybook Configuration:
argTypes: Defines both enableRowSelection and enableColumnResizing with boolean control, giving flexibility to toggle these features on or off.
Stories:
DefaultTable: Both features are disabled.
SelectionTable: Row selection is enabled, column resizing is disabled.
ResizableColumnsTable: Column resizing is enabled, row selection is disabled.
SelectionAndResizableColumnsTable: Both row selection and column resizing are enabled, demonstrating full interactivity capabilities.
This setup allows you to preview and verify both row selection and column resizing functionalities in isolation and combination directly within Storybook.
CSS Styles for Layout
Additionally, you might need some CSS to control the layout further. Below is an example of CSS that might be used to ensure the menu is on the right and other layout concerns are addressed. You can include this CSS in a relevant .css file or a module:
css
/* Ensure the toolbar is aligned to the right */
.toolbar {
display: flex;
justify-content: flex-end;
margin-bottom: 8px;
padding: 8px;
}
/* Add any general table styling necessary */
.mrt-table-container {
width: 100%;
display: flex;
flex-direction: column;
}
/* Style pagination if needed */
.mrt-pagination {
display: flex;
justify-content: center;
padding: 12px;
}
Explanation
MantineTable Component: Uses both inline styles and component customization to ensure the table spreads across the full width. The TableToolbar component is customized to align its children to the right.
CSS Adjustments: The additional CSS ensures the toolbar and pagination are displayed correctly, with the toolbar moved to the right and pagination centered or justified in a manner that complements the overall design.
This setup should help you create a responsive and well-styled table component using Mantine and Storybook. Adjust specific styles further based on your application's design needs.
Component Update: The MantineTable component now accepts data and columns as props, making it flexible enough to accommodate various datasets and configurations.
Storybook Configuration:
Each story provides different argument values for data and columns, as well as the table features like enableRowSelection, enableColumnResizing, and enableColumnOrdering.
sampleData and sampleColumns are used to demonstrate how the table behaves with sample props, but you can replace these with any desired data structure.
By making these updates, your MantineTable component and Storybook stories become highly customizable, allowing for varied testing and demonstration scenarios using different datasets and configurations.
Component Flexibility: The MantineTable component now takes tableData and columns as props, allowing you to pass any data and column configuration.
Flexible Stories:
DefaultSemantic and SelectionSemantic: These stories use function components to pass custom data and columns to MantineTable. Using properties allows you to easily switch the data set.
Sample Data: You can replace sampleData and sampleColumns with any data structure that fits your needs.
This setup provides a highly flexible framework for testing different data structures and table configurations within your Storybook environment.