UNPKG

6.18 kBTypeScriptView Raw
1import * as React from 'react';
2import {
3 ResponsiveStyleValue,
4 SxProps,
5 SystemProps,
6 Breakpoint,
7 BreakpointOverrides,
8} from '@mui/system';
9import { IfEquals } from '@mui/types';
10import { Theme } from '../styles';
11import { OverridableComponent, OverrideProps } from '../OverridableComponent';
12import { GridClasses } from './gridClasses';
13
14export type GridDirection = 'row' | 'row-reverse' | 'column' | 'column-reverse';
15
16export type GridSpacing = number | string;
17
18export type GridWrap = 'nowrap' | 'wrap' | 'wrap-reverse';
19
20export type GridSize = 'auto' | number;
21
22export interface RegularBreakpoints {
23 /**
24 * If a number, it sets the number of columns the grid item uses.
25 * It can't be greater than the total number of columns of the container (12 by default).
26 * If 'auto', the grid item's width matches its content.
27 * If false, the prop is ignored.
28 * If true, the grid item's width grows to use the space available in the grid container.
29 * The value is applied for the `lg` breakpoint and wider screens if not overridden.
30 * @default false
31 */
32 lg?: boolean | GridSize;
33 /**
34 * If a number, it sets the number of columns the grid item uses.
35 * It can't be greater than the total number of columns of the container (12 by default).
36 * If 'auto', the grid item's width matches its content.
37 * If false, the prop is ignored.
38 * If true, the grid item's width grows to use the space available in the grid container.
39 * The value is applied for the `md` breakpoint and wider screens if not overridden.
40 * @default false
41 */
42 md?: boolean | GridSize;
43 /**
44 * If a number, it sets the number of columns the grid item uses.
45 * It can't be greater than the total number of columns of the container (12 by default).
46 * If 'auto', the grid item's width matches its content.
47 * If false, the prop is ignored.
48 * If true, the grid item's width grows to use the space available in the grid container.
49 * The value is applied for the `sm` breakpoint and wider screens if not overridden.
50 * @default false
51 */
52 sm?: boolean | GridSize;
53 /**
54 * If a number, it sets the number of columns the grid item uses.
55 * It can't be greater than the total number of columns of the container (12 by default).
56 * If 'auto', the grid item's width matches its content.
57 * If false, the prop is ignored.
58 * If true, the grid item's width grows to use the space available in the grid container.
59 * The value is applied for the `xl` breakpoint and wider screens if not overridden.
60 * @default false
61 */
62 xl?: boolean | GridSize;
63 /**
64 * If a number, it sets the number of columns the grid item uses.
65 * It can't be greater than the total number of columns of the container (12 by default).
66 * If 'auto', the grid item's width matches its content.
67 * If false, the prop is ignored.
68 * If true, the grid item's width grows to use the space available in the grid container.
69 * The value is applied for all the screen sizes with the lowest priority.
70 * @default false
71 */
72 xs?: boolean | GridSize;
73}
74
75type CustomBreakpoints = Partial<Record<Breakpoint, boolean | GridSize>>;
76
77interface BreakpointOverridesEmpty {}
78
79type Breakpoints = IfEquals<
80 BreakpointOverrides,
81 BreakpointOverridesEmpty,
82 RegularBreakpoints,
83 CustomBreakpoints
84>;
85
86export interface GridOwnProps extends SystemProps<Theme>, Breakpoints {
87 /**
88 * The content of the component.
89 */
90 children?: React.ReactNode;
91 /**
92 * Override or extend the styles applied to the component.
93 */
94 classes?: Partial<GridClasses>;
95 /**
96 * The number of columns.
97 * @default 12
98 */
99 columns?: ResponsiveStyleValue<number>;
100 /**
101 * Defines the horizontal space between the type `item` components.
102 * It overrides the value of the `spacing` prop.
103 */
104 columnSpacing?: ResponsiveStyleValue<GridSpacing>;
105 /**
106 * If `true`, the component will have the flex *container* behavior.
107 * You should be wrapping *items* with a *container*.
108 * @default false
109 */
110 container?: boolean;
111 /**
112 * Defines the `flex-direction` style property.
113 * It is applied for all screen sizes.
114 * @default 'row'
115 */
116 direction?: ResponsiveStyleValue<GridDirection>;
117 /**
118 * If `true`, the component will have the flex *item* behavior.
119 * You should be wrapping *items* with a *container*.
120 * @default false
121 */
122 item?: boolean;
123 /**
124 * Defines the vertical space between the type `item` components.
125 * It overrides the value of the `spacing` prop.
126 */
127 rowSpacing?: ResponsiveStyleValue<GridSpacing>;
128 /**
129 * Defines the space between the type `item` components.
130 * It can only be used on a type `container` component.
131 * @default 0
132 */
133 spacing?: ResponsiveStyleValue<GridSpacing>;
134 /**
135 * The system prop that allows defining system overrides as well as additional CSS styles.
136 */
137 sx?: SxProps<Theme>;
138 /**
139 * Defines the `flex-wrap` style property.
140 * It's applied for all screen sizes.
141 * @default 'wrap'
142 */
143 wrap?: GridWrap;
144 /**
145 * If `true`, it sets `min-width: 0` on the item.
146 * Refer to the limitations section of the documentation to better understand the use case.
147 * @default false
148 */
149 zeroMinWidth?: boolean;
150}
151
152/**
153 * @deprecated Use the [`Grid2`](https://mui.com/material-ui/react-grid2/) component instead.
154 */
155export interface GridTypeMap<
156 AdditionalProps = {},
157 RootComponent extends React.ElementType = 'div',
158> {
159 props: AdditionalProps & GridOwnProps;
160 defaultComponent: RootComponent;
161}
162
163/**
164 *
165 * Demos:
166 *
167 * - [Grid](https://mui.com/material-ui/react-grid/)
168 *
169 * API:
170 *
171 * - [Grid API](https://mui.com/material-ui/api/grid/)
172 *
173 * @deprecated Use the [`Grid2`](https://mui.com/material-ui/react-grid2/) component instead.
174 */
175declare const Grid: OverridableComponent<GridTypeMap>;
176
177/**
178 * @deprecated Use the [`Grid2`](https://mui.com/material-ui/react-grid2/) component instead.
179 */
180export type GridProps<
181 RootComponent extends React.ElementType = GridTypeMap['defaultComponent'],
182 AdditionalProps = {},
183> = OverrideProps<GridTypeMap<AdditionalProps, RootComponent>, RootComponent> & {
184 component?: React.ElementType;
185};
186
187export default Grid;