Skip to content

Commit

Permalink
Augment MUI theme types with lab components
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonF committed Jun 9, 2020
1 parent ab725a1 commit 79e4fd5
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/material-ui-lab/src/theme-types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './overrides';
export * from './props';
44 changes: 44 additions & 0 deletions packages/material-ui-lab/src/theme-types/overrides.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { AlertClassKey } from '../Alert';
import { AlertTitleClassKey } from '../AlertTitle';
import { AutocompleteClassKey } from '../Autocomplete';
import { AvatarGroupClassKey } from '../AvatarGroup';
import { PaginationClassKey } from '../Pagination';
import { PaginationItemClassKey } from '../PaginationItem';
import { RatingClassKey } from '../Rating';
import { SkeletonClassKey } from '../Skeleton';
import { SpeedDialClassKey } from '../SpeedDial';
import { SpeedDialActionClassKey } from '../SpeedDialAction';
import { SpeedDialIconClassKey } from '../SpeedDialIcon';
import { TabListClassKey } from '../TabList';
import { TabPanelClassKey } from '../TabPanel';
import { ToggleButtonClassKey } from '../ToggleButton';
import { ToggleButtonGroupClassKey } from '../ToggleButtonGroup';
import { TreeItemClassKey } from '../TreeItem';
import { TreeViewClassKey } from '../TreeView';

export interface LabComponentNameToClassKey {
MuiAlert: AlertClassKey;
MuiAlertTitle: AlertTitleClassKey;
MuiAutocomplete: AutocompleteClassKey;
MuiAvatarGroup: AvatarGroupClassKey;
MuiPagination: PaginationClassKey;
MuiPaginationItem: PaginationItemClassKey;
MuiRating: RatingClassKey;
MuiSkeleton: SkeletonClassKey;
MuiSpeedDial: SpeedDialClassKey;
MuiSpeedDialAction: SpeedDialActionClassKey;
MuiSpeedDialIcon: SpeedDialIconClassKey;
MuiTabList: TabListClassKey;
MuiTabPanel: TabPanelClassKey;
MuiToggleButton: ToggleButtonClassKey;
MuiToggleButtonGroup: ToggleButtonGroupClassKey;
MuiTreeItem: TreeItemClassKey;
MuiTreeView: TreeViewClassKey;
}

declare module '@material-ui/core/styles/overrides' {
interface ComponentNameToClassKey extends LabComponentNameToClassKey {}
}

// disable automatic export
export {};
15 changes: 15 additions & 0 deletions packages/material-ui-lab/src/theme-types/overrides.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createMuiTheme } from '@material-ui/core';

createMuiTheme({
overrides: {
MuiAvatarGroup: {
avatar: {
border: 'none',
},
// @ts-expect-error invalid class key
wrong: {
display: 'flex',
},
},
},
});
44 changes: 44 additions & 0 deletions packages/material-ui-lab/src/theme-types/props.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { AlertProps } from '../Alert';
import { AlertTitleProps } from '../AlertTitle';
import { AutocompleteProps } from '../Autocomplete';
import { AvatarGroupProps } from '../AvatarGroup';
import { PaginationProps } from '../Pagination';
import { PaginationItemProps } from '../PaginationItem';
import { RatingProps } from '../Rating';
import { SkeletonProps } from '../Skeleton';
import { SpeedDialProps } from '../SpeedDial';
import { SpeedDialActionProps } from '../SpeedDialAction';
import { SpeedDialIconProps } from '../SpeedDialIcon';
import { TabListProps } from '../TabList';
import { TabPanelProps } from '../TabPanel';
import { ToggleButtonProps } from '../ToggleButton';
import { ToggleButtonGroupProps } from '../ToggleButtonGroup';
import { TreeItemProps } from '../TreeItem';
import { TreeViewProps } from '../TreeView';

export interface LabComponentsPropsList {
MuiAlert: AlertProps;
MuiAlertTitle: AlertTitleProps;
MuiAutocomplete: AutocompleteProps<any, any, any, any>;
MuiAvatarGroup: AvatarGroupProps;
MuiPagination: PaginationProps;
MuiPaginationItem: PaginationItemProps;
MuiRating: RatingProps;
MuiSkeleton: SkeletonProps;
MuiSpeedDial: SpeedDialProps;
MuiSpeedDialAction: SpeedDialActionProps;
MuiSpeedDialIcon: SpeedDialIconProps;
MuiTabList: TabListProps;
MuiTabPanel: TabPanelProps;
MuiToggleButton: ToggleButtonProps;
MuiToggleButtonGroup: ToggleButtonGroupProps;
MuiTreeItem: TreeItemProps;
MuiTreeView: TreeViewProps;
}

declare module '@material-ui/core/styles/props' {
interface ComponentsPropsList extends LabComponentsPropsList {}
}

// disable automatic export
export {};
27 changes: 27 additions & 0 deletions packages/material-ui-lab/src/theme-types/props.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { createMuiTheme } from '@material-ui/core';

createMuiTheme({
props: {
MuiAvatarGroup: {
spacing: 'small',
// @ts-expect-error invalid prop
maximum: 5,
},
},
});

// Ensure Autocomplete generics are loose
const trueOrFalse = true as boolean;
const val = '' as string | null | string[];
createMuiTheme({
props: {
MuiAutocomplete: {
multiple: trueOrFalse,
disableClearable: trueOrFalse,
freeSolo: trueOrFalse,
options: [],
value: val,
defaultValue: val,
},
},
});

0 comments on commit 79e4fd5

Please sign in to comment.