UNPKG

4.35 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import withStyles from '../styles/withStyles';
7import capitalize from '../utils/capitalize';
8export const styles = theme => ({
9 /* Styles applied to the root element. */
10 root: {
11 width: '100%',
12 marginLeft: 'auto',
13 boxSizing: 'border-box',
14 marginRight: 'auto',
15 paddingLeft: theme.spacing(2),
16 paddingRight: theme.spacing(2),
17 display: 'block',
18 // Fix IE 11 layout when used with main.
19 [theme.breakpoints.up('sm')]: {
20 paddingLeft: theme.spacing(3),
21 paddingRight: theme.spacing(3)
22 }
23 },
24
25 /* Styles applied to the root element if `disableGutters={true}`. */
26 disableGutters: {
27 paddingLeft: 0,
28 paddingRight: 0
29 },
30
31 /* Styles applied to the root element if `fixed={true}`. */
32 fixed: Object.keys(theme.breakpoints.values).reduce((acc, breakpoint) => {
33 const value = theme.breakpoints.values[breakpoint];
34
35 if (value !== 0) {
36 acc[theme.breakpoints.up(breakpoint)] = {
37 maxWidth: value
38 };
39 }
40
41 return acc;
42 }, {}),
43
44 /* Styles applied to the root element if `maxWidth="xs"`. */
45 maxWidthXs: {
46 [theme.breakpoints.up('xs')]: {
47 maxWidth: Math.max(theme.breakpoints.values.xs, 444)
48 }
49 },
50
51 /* Styles applied to the root element if `maxWidth="sm"`. */
52 maxWidthSm: {
53 [theme.breakpoints.up('sm')]: {
54 maxWidth: theme.breakpoints.values.sm
55 }
56 },
57
58 /* Styles applied to the root element if `maxWidth="md"`. */
59 maxWidthMd: {
60 [theme.breakpoints.up('md')]: {
61 maxWidth: theme.breakpoints.values.md
62 }
63 },
64
65 /* Styles applied to the root element if `maxWidth="lg"`. */
66 maxWidthLg: {
67 [theme.breakpoints.up('lg')]: {
68 maxWidth: theme.breakpoints.values.lg
69 }
70 },
71
72 /* Styles applied to the root element if `maxWidth="xl"`. */
73 maxWidthXl: {
74 [theme.breakpoints.up('xl')]: {
75 maxWidth: theme.breakpoints.values.xl
76 }
77 }
78});
79const Container = /*#__PURE__*/React.forwardRef(function Container(props, ref) {
80 const {
81 classes,
82 className,
83 component: Component = 'div',
84 disableGutters = false,
85 fixed = false,
86 maxWidth = 'lg'
87 } = props,
88 other = _objectWithoutPropertiesLoose(props, ["classes", "className", "component", "disableGutters", "fixed", "maxWidth"]);
89
90 return /*#__PURE__*/React.createElement(Component, _extends({
91 className: clsx(classes.root, className, fixed && classes.fixed, disableGutters && classes.disableGutters, maxWidth !== false && classes[`maxWidth${capitalize(String(maxWidth))}`]),
92 ref: ref
93 }, other));
94});
95process.env.NODE_ENV !== "production" ? Container.propTypes = {
96 // ----------------------------- Warning --------------------------------
97 // | These PropTypes are generated from the TypeScript type definitions |
98 // | To update them edit the d.ts file and run "yarn proptypes" |
99 // ----------------------------------------------------------------------
100
101 /**
102 * @ignore
103 */
104 children: PropTypes
105 /* @typescript-to-proptypes-ignore */
106 .node.isRequired,
107
108 /**
109 * Override or extend the styles applied to the component.
110 * See [CSS API](#css) below for more details.
111 */
112 classes: PropTypes.object,
113
114 /**
115 * @ignore
116 */
117 className: PropTypes.string,
118
119 /**
120 * The component used for the root node.
121 * Either a string to use a HTML element or a component.
122 */
123 component: PropTypes
124 /* @typescript-to-proptypes-ignore */
125 .elementType,
126
127 /**
128 * If `true`, the left and right padding is removed.
129 */
130 disableGutters: PropTypes.bool,
131
132 /**
133 * Set the max-width to match the min-width of the current breakpoint.
134 * This is useful if you'd prefer to design for a fixed set of sizes
135 * instead of trying to accommodate a fully fluid viewport.
136 * It's fluid by default.
137 */
138 fixed: PropTypes.bool,
139
140 /**
141 * Determine the max-width of the container.
142 * The container width grows with the size of the screen.
143 * Set to `false` to disable `maxWidth`.
144 */
145 maxWidth: PropTypes.oneOf(['lg', 'md', 'sm', 'xl', 'xs', false])
146} : void 0;
147export default withStyles(styles, {
148 name: 'MuiContainer'
149})(Container);
\No newline at end of file