Skip to content

Commit

Permalink
refactor(DEV-13634): pass functional customization via new theme config
Browse files Browse the repository at this point in the history
  • Loading branch information
saladNights committed Dec 23, 2024
1 parent d210da6 commit f51b8aa
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 39 deletions.
1 change: 0 additions & 1 deletion packages/sdk-react/mui-styles.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
type MonitePayableDetailsInfoProps,
type MonitePayableStatusChipProps,
type MonitePayableTableProps,
type MoniteTablePaginationProps,
} from '@/core/theme/types';
import { type MoniteIconWrapperProps } from '@/ui/iconWrapper/IconWrapper';
import {
Expand Down
8 changes: 8 additions & 0 deletions packages/sdk-react/src/core/theme/monite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,13 @@ export const getTheme = (theme: ThemeConfig) => {
lineHeight: theme.typography?.body2?.lineHeight || '20px',
},
},

components: {
TablePagination: {
pageSizeOptions: theme.components?.TablePagination?.pageSizeOptions || [
15, 30, 100,
],
},
},
};
};
2 changes: 1 addition & 1 deletion packages/sdk-react/src/core/theme/mui-monite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ export const getTheme = (theme: ThemeConfig): ThemeOptions => {
},
MoniteTablePagination: {
defaultProps: {
pageSizeOptions: [15, 30, 100],
pageSizeOptions: moniteTheme.components.TablePagination.pageSizeOptions,
},
},
MuiDataGrid: {
Expand Down
25 changes: 7 additions & 18 deletions packages/sdk-react/src/core/theme/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { components, Services } from '@/api';
import { ChipProps, SelectProps } from '@mui/material';
import { ChipProps } from '@mui/material';

type TypographyStyle = {
fontSize?: string | number;
Expand Down Expand Up @@ -38,6 +38,12 @@ export type ThemeConfig = {
body1?: TypographyStyle;
body2?: TypographyStyle;
};

components?: {
TablePagination?: {
pageSizeOptions?: number[];
};
};
};

export type MonitePalette = {
Expand Down Expand Up @@ -93,23 +99,6 @@ export type MonitePalette = {
divider: string;
};

interface MoniteTablePaginationRootSlotProps {
pageSizeOptions?: number[];
}

interface MoniteTablePaginationSlotProps {
slotProps?: {
pageSizeSelect?: Omit<
SelectProps,
'value' | 'defaultValue' | 'aria-label' | 'ref' | 'components'
>;
};
}

export interface MoniteTablePaginationProps
extends MoniteTablePaginationSlotProps,
MoniteTablePaginationRootSlotProps {}

interface BaseChipProps {
/** The variant of the Chip. */
variant?: ChipProps['variant'];
Expand Down
20 changes: 1 addition & 19 deletions packages/sdk-react/src/ui/table/TablePagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
} from '@mui/material';
import { styled, useThemeProps } from '@mui/material/styles';

// eslint-disable-next-line lingui/no-unlocalized-strings
const componentName = 'MoniteTablePagination' as const;
const DEFAULT_PAGE_SIZE = 10 as const;

Expand Down Expand Up @@ -56,24 +55,7 @@ interface TablePaginationProps<T> extends MoniteTablePaginationProps {
* @param paginationModel The current pagination model. It should contain the current page and the page size.
* @param nextPage The next page number. If undefined, the next page button will be disabled.
* @param prevPage The previous page number. If undefined, the previous page button will be disabled.
* @param pageSizeOptions The page size options. If not provided, will be used from MUI theme or hidden if only one option is available.
* @example MUI theming
* // You can configure the component through MUI theming like this:
* createTheme(myTheme, {
* components: {
* MoniteTablePagination: {
* defaultProps: {
* // The default page size options
* pageSizeOptions: [5, 10, 15, 20],
* slotProps: {
* pageSizeSelect: {
* size: 'small',
* },
* },
* },
* }
* }
* }
* @param pageSizeOptions The page size options. If not provided, will be used from theme or hidden if only one option is available.
*/
export const TablePagination = <T,>({
onPaginationModelChange,
Expand Down
5 changes: 5 additions & 0 deletions packages/sdk-react/src/utils/storybook-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ const defaultThemeConfig: ThemeConfig = {

text: '#401d6d',
},
components: {
TablePagination: {
pageSizeOptions: [10, 20, 100],
},
},
};

export const GlobalStorybookDecorator = (props: {
Expand Down

0 comments on commit f51b8aa

Please sign in to comment.