Completely updated React, fixed #11, (hopefully)

This commit is contained in:
2018-03-04 19:11:49 -05:00
parent 6e0afd6e2a
commit 34e5f5139a
13674 changed files with 333464 additions and 473223 deletions

View File

@@ -3,18 +3,19 @@ import { StandardProps } from '..';
import { Breakpoint } from '../styles/createBreakpoints';
export interface HiddenProps extends StandardProps<{}, never> {
only?: Breakpoint | Array<Breakpoint>;
xsUp?: boolean;
smUp?: boolean;
mdUp?: boolean;
implementation?: 'js' | 'css';
initialWidth?: Breakpoint;
lgDown?: boolean;
lgUp?: boolean;
mdDown?: boolean;
mdUp?: boolean;
only?: Breakpoint | Array<Breakpoint>;
smDown?: boolean;
smUp?: boolean;
xlDown?: boolean;
xlUp?: boolean;
xsDown?: boolean;
smDown?: boolean;
mdDown?: boolean;
lgDown?: boolean;
xlDown?: boolean;
implementation?: 'js' | 'css';
xsUp?: boolean;
}
declare const Hidden: React.ComponentType<HiddenProps>;

View File

@@ -1,11 +1,9 @@
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
import React from 'react';
import PropTypes from 'prop-types';
import HiddenJs from './HiddenJs';
import HiddenCss from './HiddenCss';
/**
* Responsively hides children based on the selected implementation.
*/
@@ -20,18 +18,90 @@ function Hidden(props) {
return React.createElement(HiddenCss, other);
}
Hidden.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* @ignore
*/
className: PropTypes.string,
/**
* Specify which implementation to use. 'js' is the default, 'css' works better for server
* side rendering.
*/
implementation: PropTypes.oneOf(['js', 'css']),
/**
* You can use this property when choosing the `js` implementation with server side rendering.
*
* As `window.innerWidth` is unavailable on the server,
* we default to rendering an empty componenent during the first mount.
* In some situation you might want to use an heristic to approximate
* the screen width of the client browser screen width.
*
* For instance, you could be using the user-agent or the client-hints.
* http://caniuse.com/#search=client%20hint
*/
initialWidth: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']),
/**
* If true, screens this size and down will be hidden.
*/
lgDown: PropTypes.bool,
/**
* If true, screens this size and up will be hidden.
*/
lgUp: PropTypes.bool,
/**
* If true, screens this size and down will be hidden.
*/
mdDown: PropTypes.bool,
/**
* If true, screens this size and up will be hidden.
*/
mdUp: PropTypes.bool,
/**
* Hide the given breakpoint(s).
*/
only: PropTypes.oneOfType([PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']), PropTypes.arrayOf(PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']))]),
/**
* If true, screens this size and down will be hidden.
*/
smDown: PropTypes.bool,
/**
* If true, screens this size and up will be hidden.
*/
smUp: PropTypes.bool,
/**
* If true, screens this size and down will be hidden.
*/
xlDown: PropTypes.bool,
/**
* If true, screens this size and up will be hidden.
*/
xlUp: PropTypes.bool,
/**
* If true, screens this size and down will be hidden.
*/
xsDown: PropTypes.bool,
/**
* If true, screens this size and up will be hidden.
*/
xsUp: PropTypes.bool
} : {};
Hidden.defaultProps = {
implementation: 'js',
xsUp: false,
smUp: false,
mdUp: false,
lgDown: false,
lgUp: false,
mdDown: false,
mdUp: false,
smDown: false,
smUp: false,
xlDown: false,
xlUp: false,
xsDown: false,
smDown: false,
mdDown: false,
lgDown: false,
xlDown: false
xsUp: false
};
export default Hidden;

View File

@@ -0,0 +1,20 @@
import * as React from 'react';
import { Breakpoint } from '../styles/createBreakpoints';
export interface HiddenCssProps {
lgDown?: boolean;
lgUp?: boolean;
mdDown?: boolean;
mdUp?: boolean;
only?: Breakpoint | Array<Breakpoint>;
smDown?: boolean;
smUp?: boolean;
xlDown?: boolean;
xlUp?: boolean;
xsDown?: boolean;
xsUp?: boolean;
}
declare const HiddenCss: React.ComponentType<HiddenCssProps>;
export default HiddenCss;

View File

@@ -1,36 +1,31 @@
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
/* eslint-disable flowtype/require-valid-file-annotation */
import _Object$keys from 'babel-runtime/core-js/object/keys';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
import React from 'react';
import PropTypes from 'prop-types';
import warning from 'warning';
import { keys as breakpointKeys } from '../styles/createBreakpoints';
import { capitalizeFirstLetter } from '../utils/helpers';
import { capitalize } from '../utils/helpers';
import withStyles from '../styles/withStyles';
function generateStyles(theme) {
const styles = theme => {
const hidden = {
display: 'none'
};
return breakpointKeys.reduce((styles, key) => {
styles[`only${capitalizeFirstLetter(key)}`] = {
return breakpointKeys.reduce((acc, key) => {
acc[`only${capitalize(key)}`] = {
[theme.breakpoints.only(key)]: hidden
};
styles[`${key}Up`] = {
acc[`${key}Up`] = {
[theme.breakpoints.up(key)]: hidden
};
styles[`${key}Down`] = {
acc[`${key}Down`] = {
[theme.breakpoints.down(key)]: hidden
};
return styles;
return acc;
}, {});
}
const styles = theme => generateStyles(theme);
};
/**
* @ignore - internal component.
@@ -39,23 +34,28 @@ function HiddenCss(props) {
const {
children,
classes,
only,
xsUp,
smUp,
mdUp,
className,
lgDown,
lgUp,
mdDown,
mdUp,
only,
smDown,
smUp,
xlDown,
xlUp,
xsDown,
smDown,
mdDown,
lgDown,
xlDown
xsUp
} = props,
other = _objectWithoutProperties(props, ['children', 'classes', 'only', 'xsUp', 'smUp', 'mdUp', 'lgUp', 'xlUp', 'xsDown', 'smDown', 'mdDown', 'lgDown', 'xlDown']);
other = _objectWithoutProperties(props, ['children', 'classes', 'className', 'lgDown', 'lgUp', 'mdDown', 'mdUp', 'only', 'smDown', 'smUp', 'xlDown', 'xlUp', 'xsDown', 'xsUp']);
warning(Object.keys(other).length === 0 || Object.keys(other).length === 1 && other.hasOwnProperty('ref'), `Material-UI: unsupported properties received ${Object.keys(other).join(', ')} by \`<Hidden />\`.`);
process.env.NODE_ENV !== "production" ? warning(_Object$keys(other).length === 0 || _Object$keys(other).length === 1 && other.hasOwnProperty('ref'), `Material-UI: unsupported properties received ${_Object$keys(other).join(', ')} by \`<Hidden />\`.`) : void 0;
const className = [];
const classNames = [];
if (className) {
classNames.push(className);
}
for (let i = 0; i < breakpointKeys.length; i += 1) {
const breakpoint = breakpointKeys[i];
@@ -63,22 +63,89 @@ function HiddenCss(props) {
const breakpointDown = props[`${breakpoint}Down`];
if (breakpointUp) {
className.push(classes[`${breakpoint}Up`]);
classNames.push(classes[`${breakpoint}Up`]);
}
if (breakpointDown) {
className.push(classes[`${breakpoint}Down`]);
classNames.push(classes[`${breakpoint}Down`]);
}
}
if (only) {
className.push(classes[`only${capitalizeFirstLetter(only)}`]);
const onlyBreakpoints = Array.isArray(only) ? only : [only];
onlyBreakpoints.forEach(breakpoint => {
classNames.push(classes[`only${capitalize(breakpoint)}`]);
});
}
return React.createElement(
'span',
{ className: className },
'div',
{ className: classNames.join(' ') },
children
);
}
HiddenCss.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* Specify which implementation to use. 'js' is the default, 'css' works better for server
* side rendering.
*/
implementation: PropTypes.oneOf(['js', 'css']),
/**
* If true, screens this size and down will be hidden.
*/
lgDown: PropTypes.bool,
/**
* If true, screens this size and up will be hidden.
*/
lgUp: PropTypes.bool,
/**
* If true, screens this size and down will be hidden.
*/
mdDown: PropTypes.bool,
/**
* If true, screens this size and up will be hidden.
*/
mdUp: PropTypes.bool,
/**
* Hide the given breakpoint(s).
*/
only: PropTypes.oneOfType([PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']), PropTypes.arrayOf(PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']))]),
/**
* If true, screens this size and down will be hidden.
*/
smDown: PropTypes.bool,
/**
* If true, screens this size and up will be hidden.
*/
smUp: PropTypes.bool,
/**
* If true, screens this size and down will be hidden.
*/
xlDown: PropTypes.bool,
/**
* If true, screens this size and up will be hidden.
*/
xlUp: PropTypes.bool,
/**
* If true, screens this size and down will be hidden.
*/
xsDown: PropTypes.bool,
/**
* If true, screens this size and up will be hidden.
*/
xsUp: PropTypes.bool
} : {};
export default withStyles(styles, { name: 'MuiHiddenCss' })(HiddenCss);

View File

@@ -2,17 +2,18 @@ import * as React from 'react';
import { Breakpoint } from '../styles/createBreakpoints';
export interface HiddenJsProps {
only?: Breakpoint | Array<Breakpoint>;
xsUp?: boolean;
smUp?: boolean;
mdUp?: boolean;
initialWidth?: Breakpoint;
lgDown?: boolean;
lgUp?: boolean;
mdDown?: boolean;
mdUp?: boolean;
only?: Breakpoint | Array<Breakpoint>;
smDown?: boolean;
smUp?: boolean;
xlDown?: boolean;
xlUp?: boolean;
xsDown?: boolean;
smDown?: boolean;
mdDown?: boolean;
lgDown?: boolean;
xlDown?: boolean;
xsUp?: boolean;
}
declare const HiddenJs: React.ComponentType<HiddenJsProps>;

View File

@@ -1,33 +1,13 @@
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
import warning from 'warning';
import PropTypes from 'prop-types';
import { keys as breakpointKeys } from '../styles/createBreakpoints';
import withWidth, { isWidthDown, isWidthUp } from '../utils/withWidth';
import exactProp from '../utils/exactProp';
/**
* @ignore - internal component.
*/
function HiddenJs(props) {
const {
children,
only,
xsUp,
smUp,
mdUp,
lgUp,
xlUp,
xsDown,
smDown,
mdDown,
lgDown,
xlDown,
width
} = props,
other = _objectWithoutProperties(props, ['children', 'only', 'xsUp', 'smUp', 'mdUp', 'lgUp', 'xlUp', 'xsDown', 'smDown', 'mdDown', 'lgDown', 'xlDown', 'width']);
warning(Object.keys(other).length === 0, `Material-UI: unsupported properties received ${JSON.stringify(other)} by \`<Hidden />\`.`);
const { children, only, width } = props;
let visible = true;
@@ -67,4 +47,83 @@ function HiddenJs(props) {
return children;
}
HiddenJs.propTypes = {
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* @ignore
*/
className: PropTypes.string,
/**
* Specify which implementation to use. 'js' is the default, 'css' works better for server
* side rendering.
*/
implementation: PropTypes.oneOf(['js', 'css']),
/**
* You can use this property when choosing the `js` implementation with server side rendering.
*
* As `window.innerWidth` is unavailable on the server,
* we default to rendering an empty componenent during the first mount.
* In some situation you might want to use an heristic to approximate
* the screen width of the client browser screen width.
*
* For instance, you could be using the user-agent or the client-hints.
* http://caniuse.com/#search=client%20hint
*/
initialWidth: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']),
/**
* If true, screens this size and down will be hidden.
*/
lgDown: PropTypes.bool,
/**
* If true, screens this size and up will be hidden.
*/
lgUp: PropTypes.bool,
/**
* If true, screens this size and down will be hidden.
*/
mdDown: PropTypes.bool,
/**
* If true, screens this size and up will be hidden.
*/
mdUp: PropTypes.bool,
/**
* Hide the given breakpoint(s).
*/
only: PropTypes.oneOfType([PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']), PropTypes.arrayOf(PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']))]),
/**
* If true, screens this size and down will be hidden.
*/
smDown: PropTypes.bool,
/**
* If true, screens this size and up will be hidden.
*/
smUp: PropTypes.bool,
/**
* @ignore
* width prop provided by withWidth decorator.
*/
width: PropTypes.string.isRequired,
/**
* If true, screens this size and down will be hidden.
*/
xlDown: PropTypes.bool,
/**
* If true, screens this size and up will be hidden.
*/
xlUp: PropTypes.bool,
/**
* If true, screens this size and down will be hidden.
*/
xsDown: PropTypes.bool,
/**
* If true, screens this size and up will be hidden.
*/
xsUp: PropTypes.bool
};
HiddenJs.propTypes = exactProp(HiddenJs.propTypes, 'HiddenJs');
export default withWidth()(HiddenJs);

View File

@@ -1,4 +1,2 @@
export { default } from './Hidden';
export * from './Hidden';
export { default as HiddenJs } from './HiddenJs';
export * from './HiddenJs';

View File

@@ -1,2 +1 @@
export { default } from './Hidden';
export { default as HiddenJs } from './HiddenJs';
export { default } from './Hidden';