Removed GopherJS, basic frontend completed, need backend changes for

torrent storage
This commit is contained in:
2017-11-30 18:12:11 -05:00
parent 67fdef16b1
commit e98ad2cc88
69321 changed files with 5498914 additions and 337 deletions

47
torrent-project/node_modules/material-ui/Tabs/Tab.d.ts generated vendored Normal file
View File

@@ -0,0 +1,47 @@
import * as React from 'react';
import { StandardProps } from '..';
import { ButtonBaseProps } from '../ButtonBase';
import { ButtonBaseClassKey } from '../ButtonBase/ButtonBase';
export interface TabProps extends StandardProps<
ButtonBaseProps,
TabClassKey,
'onChange'
> {
disabled?: boolean;
fullWidth?: boolean;
icon?: string | React.ReactElement<any>;
value?: any;
label?: React.ReactNode;
onChange?: (
event: React.ChangeEvent<{ checked: boolean }>,
value: any
) => void;
onClick?: React.EventHandler<any>;
selected?: boolean;
style?: object;
textColor?: string | 'accent' | 'primary' | 'inherit';
}
export type TabClassKey =
| ButtonBaseClassKey
| 'rootLabelIcon'
| 'rootAccent'
| 'rootAccentSelected'
| 'rootAccentDisabled'
| 'rootPrimary'
| 'rootPrimarySelected'
| 'rootPrimaryDisabled'
| 'rootInherit'
| 'rootInheritSelected'
| 'rootInheritDisabled'
| 'fullWidth'
| 'wrapper'
| 'labelContainer'
| 'label'
| 'labelWrapped'
;
declare const Tab: React.ComponentType<TabProps>;
export default Tab;

361
torrent-project/node_modules/material-ui/Tabs/Tab.js generated vendored Normal file
View File

@@ -0,0 +1,361 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.styles = undefined;
var _keys = require('babel-runtime/core-js/object/keys');
var _keys2 = _interopRequireDefault(_keys);
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _extends3 = require('babel-runtime/helpers/extends');
var _extends4 = _interopRequireDefault(_extends3);
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
var _ButtonBase = require('../ButtonBase');
var _ButtonBase2 = _interopRequireDefault(_ButtonBase);
var _helpers = require('../utils/helpers');
var _Icon = require('../Icon');
var _Icon2 = _interopRequireDefault(_Icon);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Element = require('react').babelPluginFlowReactPropTypes_proptype_Element || require('prop-types').any;
// @inheritedComponent ButtonBase
var styles = exports.styles = function styles(theme) {
return {
root: (0, _extends4.default)({}, theme.typography.button, (0, _defineProperty3.default)({
maxWidth: 264,
position: 'relative',
minWidth: 72,
padding: 0,
height: 48,
flex: 'none',
overflow: 'hidden'
}, theme.breakpoints.up('md'), {
minWidth: 160
})),
rootLabelIcon: {
height: 72
},
rootAccent: {
color: theme.palette.text.secondary
},
rootAccentSelected: {
color: theme.palette.secondary.A200
},
rootAccentDisabled: {
color: theme.palette.text.disabled
},
rootPrimary: {
color: theme.palette.text.secondary
},
rootPrimarySelected: {
color: theme.palette.primary[500]
},
rootPrimaryDisabled: {
color: theme.palette.text.disabled
},
rootInherit: {
color: 'inherit',
opacity: 0.7
},
rootInheritSelected: {
opacity: 1
},
rootInheritDisabled: {
opacity: 0.4
},
fullWidth: {
flexGrow: 1
},
wrapper: {
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
width: '100%',
flexDirection: 'column'
},
labelContainer: (0, _defineProperty3.default)({
paddingTop: 6,
paddingBottom: 6,
paddingLeft: 12,
paddingRight: 12
}, theme.breakpoints.up('md'), {
paddingLeft: theme.spacing.unit * 3,
paddingRight: theme.spacing.unit * 3
}),
label: (0, _defineProperty3.default)({
fontSize: theme.typography.pxToRem(theme.typography.fontSize),
whiteSpace: 'normal'
}, theme.breakpoints.up('md'), {
fontSize: theme.typography.pxToRem(theme.typography.fontSize - 1)
}),
labelWrapped: (0, _defineProperty3.default)({}, theme.breakpoints.down('md'), {
fontSize: theme.typography.pxToRem(theme.typography.fontSize - 2)
})
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* If `true`, the tab will be disabled.
*/
disabled: require('prop-types').bool,
/**
* @ignore
*/
fullWidth: require('prop-types').bool,
/**
* The icon element. If a string is provided, it will be used as a font ligature.
*/
icon: require('prop-types').oneOfType([require('prop-types').string, typeof babelPluginFlowReactPropTypes_proptype_Element === 'function' ? babelPluginFlowReactPropTypes_proptype_Element : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Element)]),
/**
* @ignore
* For server side rendering consideration, we let the selected tab
* render the indicator.
*/
indicator: require('prop-types').oneOfType([require('prop-types').string, typeof babelPluginFlowReactPropTypes_proptype_Element === 'function' ? babelPluginFlowReactPropTypes_proptype_Element : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Element)]),
/**
* The label element.
*/
label: require('prop-types').oneOfType([require('prop-types').string, typeof babelPluginFlowReactPropTypes_proptype_Element === 'function' ? babelPluginFlowReactPropTypes_proptype_Element : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Element)]),
/**
* @ignore
*/
onChange: require('prop-types').func,
/**
* @ignore
*/
onClick: require('prop-types').func,
/**
* @ignore
*/
selected: require('prop-types').bool,
/**
* @ignore
*/
style: require('prop-types').object,
/**
* @ignore
*/
textColor: require('prop-types').oneOfType([require('prop-types').oneOf(['accent']), require('prop-types').oneOf(['primary']), require('prop-types').oneOf(['inherit']), require('prop-types').string]),
/**
* You can provide your own value. Otherwise, we fallback to the child position index.
*/
value: require('prop-types').any
};
var Tab = function (_React$Component) {
(0, _inherits3.default)(Tab, _React$Component);
function Tab() {
var _ref;
var _temp, _this, _ret;
(0, _classCallCheck3.default)(this, Tab);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = Tab.__proto__ || (0, _getPrototypeOf2.default)(Tab)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
wrappedText: false
}, _this.handleChange = function (event) {
var _this$props = _this.props,
onChange = _this$props.onChange,
value = _this$props.value,
onClick = _this$props.onClick;
if (onChange) {
onChange(event, value);
}
if (onClick) {
onClick(event);
}
}, _this.label = undefined, _this.checkTextWrap = function () {
if (_this.label) {
var _wrappedText = _this.label.getClientRects().length > 1;
if (_this.state.wrappedText !== _wrappedText) {
_this.setState({ wrappedText: _wrappedText });
}
}
}, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
}
(0, _createClass3.default)(Tab, [{
key: 'componentDidMount',
value: function componentDidMount() {
this.checkTextWrap();
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate(prevProps, prevState) {
if (this.state.wrappedText === prevState.wrappedText) {
/**
* At certain text and tab lengths, a larger font size may wrap to two lines while the smaller
* font size still only requires one line. This check will prevent an infinite render loop
* fron occurring in that scenario.
*/
this.checkTextWrap();
}
}
}, {
key: 'render',
value: function render() {
var _this2 = this,
_classNames2;
var _props = this.props,
classes = _props.classes,
classNameProp = _props.className,
disabled = _props.disabled,
fullWidth = _props.fullWidth,
iconProp = _props.icon,
indicator = _props.indicator,
labelProp = _props.label,
onChange = _props.onChange,
selected = _props.selected,
styleProp = _props.style,
textColor = _props.textColor,
value = _props.value,
other = (0, _objectWithoutProperties3.default)(_props, ['classes', 'className', 'disabled', 'fullWidth', 'icon', 'indicator', 'label', 'onChange', 'selected', 'style', 'textColor', 'value']);
var icon = void 0;
if (iconProp !== undefined) {
icon = _react2.default.isValidElement(iconProp) ? iconProp : _react2.default.createElement(
_Icon2.default,
null,
iconProp
);
}
var label = void 0;
if (labelProp !== undefined) {
label = _react2.default.createElement(
'div',
{ className: classes.labelContainer },
_react2.default.createElement(
'span',
{
className: (0, _classnames2.default)(classes.label, (0, _defineProperty3.default)({}, classes.labelWrapped, this.state.wrappedText)),
ref: function ref(node) {
_this2.label = node;
}
},
labelProp
)
);
}
var className = (0, _classnames2.default)(classes.root, (_classNames2 = {}, (0, _defineProperty3.default)(_classNames2, classes['root' + (0, _helpers.capitalizeFirstLetter)(textColor)], true), (0, _defineProperty3.default)(_classNames2, classes['root' + (0, _helpers.capitalizeFirstLetter)(textColor) + 'Disabled'], disabled), (0, _defineProperty3.default)(_classNames2, classes['root' + (0, _helpers.capitalizeFirstLetter)(textColor) + 'Selected'], selected), (0, _defineProperty3.default)(_classNames2, classes.rootLabelIcon, icon && label), (0, _defineProperty3.default)(_classNames2, classes.fullWidth, fullWidth), _classNames2), classNameProp);
var style = {};
if (textColor !== 'accent' && textColor !== 'inherit') {
style.color = textColor;
}
style = (0, _keys2.default)(style).length > 0 ? (0, _extends4.default)({}, style, styleProp) : styleProp;
return _react2.default.createElement(
_ButtonBase2.default,
(0, _extends4.default)({
focusRipple: true,
className: className,
style: style,
role: 'tab',
'aria-selected': selected,
disabled: disabled
}, other, {
onClick: this.handleChange
}),
_react2.default.createElement(
'span',
{ className: classes.wrapper },
icon,
label
),
indicator
);
}
}]);
return Tab;
}(_react2.default.Component);
Tab.defaultProps = {
disabled: false
};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiTab' })(Tab);

View File

@@ -0,0 +1,292 @@
// @flow
// @inheritedComponent ButtonBase
import React from 'react';
import type { Element } from 'react';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import ButtonBase from '../ButtonBase';
import { capitalizeFirstLetter } from '../utils/helpers';
import Icon from '../Icon';
export const styles = (theme: Object) => ({
root: {
...theme.typography.button,
maxWidth: 264,
position: 'relative',
minWidth: 72,
padding: 0,
height: 48,
flex: 'none',
overflow: 'hidden',
[theme.breakpoints.up('md')]: {
minWidth: 160,
},
},
rootLabelIcon: {
height: 72,
},
rootAccent: {
color: theme.palette.text.secondary,
},
rootAccentSelected: {
color: theme.palette.secondary.A200,
},
rootAccentDisabled: {
color: theme.palette.text.disabled,
},
rootPrimary: {
color: theme.palette.text.secondary,
},
rootPrimarySelected: {
color: theme.palette.primary[500],
},
rootPrimaryDisabled: {
color: theme.palette.text.disabled,
},
rootInherit: {
color: 'inherit',
opacity: 0.7,
},
rootInheritSelected: {
opacity: 1,
},
rootInheritDisabled: {
opacity: 0.4,
},
fullWidth: {
flexGrow: 1,
},
wrapper: {
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
width: '100%',
flexDirection: 'column',
},
labelContainer: {
paddingTop: 6,
paddingBottom: 6,
paddingLeft: 12,
paddingRight: 12,
[theme.breakpoints.up('md')]: {
paddingLeft: theme.spacing.unit * 3,
paddingRight: theme.spacing.unit * 3,
},
},
label: {
fontSize: theme.typography.pxToRem(theme.typography.fontSize),
whiteSpace: 'normal',
[theme.breakpoints.up('md')]: {
fontSize: theme.typography.pxToRem(theme.typography.fontSize - 1),
},
},
labelWrapped: {
[theme.breakpoints.down('md')]: {
fontSize: theme.typography.pxToRem(theme.typography.fontSize - 2),
},
},
});
type ProvidedProps = {
classes: Object,
};
export type Props = {
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* If `true`, the tab will be disabled.
*/
disabled?: boolean,
/**
* @ignore
*/
fullWidth?: boolean,
/**
* The icon element. If a string is provided, it will be used as a font ligature.
*/
icon?: string | Element<any>,
/**
* @ignore
* For server side rendering consideration, we let the selected tab
* render the indicator.
*/
indicator?: string | Element<any>,
/**
* The label element.
*/
label?: string | Element<any>,
/**
* @ignore
*/
onChange?: (event: SyntheticEvent<>, value: any) => void,
/**
* @ignore
*/
onClick?: (event: SyntheticEvent<>) => void,
/**
* @ignore
*/
selected?: boolean,
/**
* @ignore
*/
style?: Object,
/**
* @ignore
*/
textColor?: 'accent' | 'primary' | 'inherit' | string,
/**
* You can provide your own value. Otherwise, we fallback to the child position index.
*/
value?: any,
};
type State = {
wrappedText: boolean,
};
class Tab extends React.Component<ProvidedProps & Props, State> {
static defaultProps = {
disabled: false,
};
state = {
wrappedText: false,
};
componentDidMount() {
this.checkTextWrap();
}
componentDidUpdate(prevProps, prevState) {
if (this.state.wrappedText === prevState.wrappedText) {
/**
* At certain text and tab lengths, a larger font size may wrap to two lines while the smaller
* font size still only requires one line. This check will prevent an infinite render loop
* fron occurring in that scenario.
*/
this.checkTextWrap();
}
}
handleChange = (event: SyntheticEvent<>) => {
const { onChange, value, onClick } = this.props;
if (onChange) {
onChange(event, value);
}
if (onClick) {
onClick(event);
}
};
label = undefined;
checkTextWrap = () => {
if (this.label) {
const wrappedText = this.label.getClientRects().length > 1;
if (this.state.wrappedText !== wrappedText) {
this.setState({ wrappedText });
}
}
};
render() {
const {
classes,
className: classNameProp,
disabled,
fullWidth,
icon: iconProp,
indicator,
label: labelProp,
onChange,
selected,
style: styleProp,
textColor,
value,
...other
} = this.props;
let icon;
if (iconProp !== undefined) {
icon = React.isValidElement(iconProp) ? iconProp : <Icon>{iconProp}</Icon>;
}
let label;
if (labelProp !== undefined) {
label = (
<div className={classes.labelContainer}>
<span
className={classNames(classes.label, {
[classes.labelWrapped]: this.state.wrappedText,
})}
ref={node => {
this.label = node;
}}
>
{labelProp}
</span>
</div>
);
}
const className = classNames(
classes.root,
{
[classes[`root${capitalizeFirstLetter(textColor)}`]]: true,
[classes[`root${capitalizeFirstLetter(textColor)}Disabled`]]: disabled,
[classes[`root${capitalizeFirstLetter(textColor)}Selected`]]: selected,
[classes.rootLabelIcon]: icon && label,
[classes.fullWidth]: fullWidth,
},
classNameProp,
);
let style = {};
if (textColor !== 'accent' && textColor !== 'inherit') {
style.color = textColor;
}
style =
Object.keys(style).length > 0
? {
...style,
...styleProp,
}
: styleProp;
return (
<ButtonBase
focusRipple
className={className}
style={style}
role="tab"
aria-selected={selected}
disabled={disabled}
{...other}
onClick={this.handleChange}
>
<span className={classes.wrapper}>
{icon}
{label}
</span>
{indicator}
</ButtonBase>
);
}
}
export default withStyles(styles, { name: 'MuiTab' })(Tab);

View File

@@ -0,0 +1,20 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface TabIndicatorProps extends StandardProps<
React.HTMLAttributes<HTMLDivElement>,
TabIndicatorClassKey
> {
color: 'accent' | 'primary' | string;
style: { left: number; width: number };
}
export type TabIndicatorClassKey =
| 'root'
| 'colorAccent'
| 'colorPrimary'
;
declare const TabIndicator: React.ComponentType<TabIndicatorProps>;
export default TabIndicator;

View File

@@ -0,0 +1,113 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.styles = undefined;
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _ref; // weak
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
var _helpers = require('../utils/helpers');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var styles = exports.styles = function styles(theme) {
return {
root: {
position: 'absolute',
height: 2,
bottom: 0,
width: '100%',
transition: theme.transitions.create(),
willChange: 'left, width'
},
colorAccent: {
backgroundColor: theme.palette.secondary.A200
},
colorPrimary: {
backgroundColor: theme.palette.primary[500]
}
};
};
var babelPluginFlowReactPropTypes_proptype_IndicatorStyle = {
left: require('prop-types').number.isRequired,
width: require('prop-types').number.isRequired
};
var babelPluginFlowReactPropTypes_proptype_ProvidedProps = {
classes: require('prop-types').object.isRequired
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* @ignore
* The color of the tab indicator.
*/
color: require('prop-types').oneOfType([require('prop-types').oneOf(['accent']), require('prop-types').oneOf(['primary']), require('prop-types').string]).isRequired,
/**
* @ignore
* The style of the root element.
*/
style: require('prop-types').shape({
left: require('prop-types').number.isRequired,
width: require('prop-types').number.isRequired
}).isRequired
};
/**
* @ignore - internal component.
*/
function TabIndicator(props) {
var classes = props.classes,
classNameProp = props.className,
color = props.color,
styleProp = props.style;
var colorPredefined = ['primary', 'accent'].indexOf(color) !== -1;
var className = (0, _classnames2.default)(classes.root, (0, _defineProperty3.default)({}, classes['color' + (0, _helpers.capitalizeFirstLetter)(color)], colorPredefined), classNameProp);
var style = colorPredefined ? styleProp : (0, _extends3.default)({}, styleProp, {
backgroundColor: color
});
return _react2.default.createElement('div', { className: className, style: style });
}
TabIndicator.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'color', require('prop-types').oneOfType([require('prop-types').oneOf(['accent']), require('prop-types').oneOf(['primary']), require('prop-types').string]).isRequired), (0, _defineProperty3.default)(_ref, 'style', require('prop-types').shape({
left: require('prop-types').number.isRequired,
width: require('prop-types').number.isRequired
}).isRequired), _ref) : {};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiTabIndicator' })(TabIndicator);

View File

@@ -0,0 +1,79 @@
// @flow weak
import React from 'react';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import { capitalizeFirstLetter } from '../utils/helpers';
export const styles = (theme: Object) => ({
root: {
position: 'absolute',
height: 2,
bottom: 0,
width: '100%',
transition: theme.transitions.create(),
willChange: 'left, width',
},
colorAccent: {
backgroundColor: theme.palette.secondary.A200,
},
colorPrimary: {
backgroundColor: theme.palette.primary[500],
},
});
export type IndicatorStyle = {
left: number,
width: number,
};
export type ProvidedProps = {
classes: Object,
};
export type Props = {
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* @ignore
* The color of the tab indicator.
*/
color: 'accent' | 'primary' | string,
/**
* @ignore
* The style of the root element.
*/
style: IndicatorStyle,
};
/**
* @ignore - internal component.
*/
function TabIndicator(props: ProvidedProps & Props) {
const { classes, className: classNameProp, color, style: styleProp } = props;
const colorPredefined = ['primary', 'accent'].indexOf(color) !== -1;
const className = classNames(
classes.root,
{
[classes[`color${capitalizeFirstLetter(color)}`]]: colorPredefined,
},
classNameProp,
);
const style = colorPredefined
? styleProp
: {
...styleProp,
backgroundColor: color,
};
return <div className={className} style={style} />;
}
export default withStyles(styles, { name: 'MuiTabIndicator' })(TabIndicator);

View File

@@ -0,0 +1,19 @@
import { StandardProps } from '..';
import { ButtonBaseProps, ButtonBaseClassKey } from '../ButtonBase/ButtonBase';
export interface TabScrollButtonProps extends StandardProps<
ButtonBaseProps,
TabScrollButtonClassKey
> {
direction?: 'left' | 'right';
visible?: boolean;
}
export type TabScrollButtonClassKey =
| ButtonBaseClassKey
| 'root'
;
declare const TabScrollButton: React.ComponentType<TabScrollButtonProps>;
export default TabScrollButton;

View File

@@ -0,0 +1,120 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.styles = undefined;
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref3; // weak
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
var _ButtonBase = require('../ButtonBase');
var _ButtonBase2 = _interopRequireDefault(_ButtonBase);
var _KeyboardArrowLeft = require('../svg-icons/KeyboardArrowLeft');
var _KeyboardArrowLeft2 = _interopRequireDefault(_KeyboardArrowLeft);
var _KeyboardArrowRight = require('../svg-icons/KeyboardArrowRight');
var _KeyboardArrowRight2 = _interopRequireDefault(_KeyboardArrowRight);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var styles = exports.styles = function styles(theme) {
return {
root: {
color: 'inherit',
flex: '0 0 ' + theme.spacing.unit * 7 + 'px'
}
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* Which direction should the button indicate?
*/
direction: require('prop-types').oneOf(['left', 'right']).isRequired,
/**
* Callback to execute for button press.
*/
onClick: require('prop-types').func,
/**
* Should the button be present or just consume space.
*/
visible: require('prop-types').bool
};
var _ref = _react2.default.createElement(_KeyboardArrowLeft2.default, null);
var _ref2 = _react2.default.createElement(_KeyboardArrowRight2.default, null);
/**
* @ignore - internal component.
*/
function TabScrollButton(props) {
var classes = props.classes,
classNameProp = props.className,
direction = props.direction,
onClick = props.onClick,
visible = props.visible,
other = (0, _objectWithoutProperties3.default)(props, ['classes', 'className', 'direction', 'onClick', 'visible']);
var className = (0, _classnames2.default)(classes.root, classNameProp);
if (!visible) {
return _react2.default.createElement('div', { className: className });
}
return _react2.default.createElement(
_ButtonBase2.default,
(0, _extends3.default)({ className: className, onClick: onClick, tabIndex: -1 }, other),
direction === 'left' ? _ref : _ref2
);
}
TabScrollButton.propTypes = process.env.NODE_ENV !== "production" ? (_ref3 = {
classes: require('prop-types').object.isRequired
}, (0, _defineProperty3.default)(_ref3, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref3, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref3, 'direction', require('prop-types').oneOf(['left', 'right']).isRequired), (0, _defineProperty3.default)(_ref3, 'onClick', require('prop-types').func), (0, _defineProperty3.default)(_ref3, 'visible', require('prop-types').bool), _ref3) : {};
TabScrollButton.defaultProps = {
visible: true
};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiTabScrollButton' })(TabScrollButton);

View File

@@ -0,0 +1,67 @@
// @flow weak
import React from 'react';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import ButtonBase from '../ButtonBase';
import KeyboardArrowLeft from '../svg-icons/KeyboardArrowLeft';
import KeyboardArrowRight from '../svg-icons/KeyboardArrowRight';
export const styles = (theme: Object) => ({
root: {
color: 'inherit',
flex: `0 0 ${theme.spacing.unit * 7}px`,
},
});
type ProvidedProps = {
classes: Object,
};
export type Props = {
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* Which direction should the button indicate?
*/
direction: 'left' | 'right',
/**
* Callback to execute for button press.
*/
onClick?: Function,
/**
* Should the button be present or just consume space.
*/
visible?: boolean,
};
/**
* @ignore - internal component.
*/
function TabScrollButton(props: ProvidedProps & Props) {
const { classes, className: classNameProp, direction, onClick, visible, ...other } = props;
const className = classNames(classes.root, classNameProp);
if (!visible) {
return <div className={className} />;
}
return (
<ButtonBase className={className} onClick={onClick} tabIndex={-1} {...other}>
{direction === 'left' ? <KeyboardArrowLeft /> : <KeyboardArrowRight />}
</ButtonBase>
);
}
TabScrollButton.defaultProps = {
visible: true,
};
export default withStyles(styles, { name: 'MuiTabScrollButton' })(TabScrollButton);

View File

@@ -0,0 +1,36 @@
import * as React from 'react';
import { StandardProps } from '..';
import { ButtonBaseProps, ButtonBaseClassKey } from '../ButtonBase/ButtonBase';
export interface TabsProps extends StandardProps<
ButtonBaseProps,
TabsClassKey,
'onChange'
> {
buttonClassName?: string;
centered?: boolean;
children?: React.ReactNode;
fullWidth?: boolean;
value: any;
indicatorClassName?: string;
indicatorColor?: 'accent' | 'primary' | string;
onChange: (event: React.ChangeEvent<{}>, value: any) => void;
scrollable?: boolean;
scrollButtons?: 'auto' | 'on' | 'off';
TabScrollButton?: React.ReactType,
textColor?: 'accent' | 'primary' | 'inherit' | string;
width?: string;
}
export type TabsClassKey =
| ButtonBaseClassKey
| 'flexContainer'
| 'scrollingContainer'
| 'fixed'
| 'scrollable'
| 'centered'
;
declare const Tabs: React.ComponentType<TabsProps>;
export default Tabs;

542
torrent-project/node_modules/material-ui/Tabs/Tabs.js generated vendored Normal file
View File

@@ -0,0 +1,542 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.styles = undefined;
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _isNan = require('babel-runtime/core-js/number/is-nan');
var _isNan2 = _interopRequireDefault(_isNan);
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _warning = require('warning');
var _warning2 = _interopRequireDefault(_warning);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _reactEventListener = require('react-event-listener');
var _reactEventListener2 = _interopRequireDefault(_reactEventListener);
var _debounce = require('lodash/debounce');
var _debounce2 = _interopRequireDefault(_debounce);
var _reactScrollbarSize = require('react-scrollbar-size');
var _reactScrollbarSize2 = _interopRequireDefault(_reactScrollbarSize);
var _normalizeScrollLeft = require('normalize-scroll-left');
var _scroll = require('scroll');
var _scroll2 = _interopRequireDefault(_scroll);
var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
var _TabIndicator = require('./TabIndicator');
var _TabIndicator2 = _interopRequireDefault(_TabIndicator);
var _TabScrollButton = require('./TabScrollButton');
var _TabScrollButton2 = _interopRequireDefault(_TabScrollButton);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_ComponentType = require('prop-types').func;
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var babelPluginFlowReactPropTypes_proptype_IndicatorStyle = require('./TabIndicator').babelPluginFlowReactPropTypes_proptype_IndicatorStyle || require('prop-types').any;
var styles = exports.styles = function styles(theme) {
return {
root: {
overflow: 'hidden',
minHeight: 48,
WebkitOverflowScrolling: 'touch' // Add iOS momentum scrolling.
},
flexContainer: {
display: 'flex'
},
scrollingContainer: {
position: 'relative',
display: 'inline-block',
flex: '1 1 auto',
whiteSpace: 'nowrap'
},
fixed: {
overflowX: 'hidden',
width: '100%'
},
scrollable: {
overflowX: 'scroll'
},
centered: {
justifyContent: 'center'
},
buttonAuto: (0, _defineProperty3.default)({}, theme.breakpoints.down('sm'), {
display: 'none'
})
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The CSS class name of the scroll button elements.
*/
buttonClassName: require('prop-types').string,
/**
* If `true`, the tabs will be centered.
* This property is intended for large views.
*/
centered: require('prop-types').bool,
/**
* The content of the component.
*/
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* If `true`, the tabs will grow to use all the available space.
* This property is intended for small views, like on mobile.
*/
fullWidth: require('prop-types').bool,
/**
* The CSS class name of the indicator element.
*/
indicatorClassName: require('prop-types').string,
/**
* Determines the color of the indicator.
*/
indicatorColor: require('prop-types').oneOfType([require('prop-types').oneOf(['accent']), require('prop-types').oneOf(['primary']), require('prop-types').string]),
/**
* Callback fired when the value changes.
*
* @param {object} event The event source of the callback
* @param {number} value We default to the index of the child
*/
onChange: require('prop-types').func.isRequired,
/**
* True invokes scrolling properties and allow for horizontally scrolling
* (or swiping) the tab bar.
*/
scrollable: require('prop-types').bool,
/**
* Determine behavior of scroll buttons when tabs are set to scroll
* `auto` will only present them on medium and larger viewports
* `on` will always present them
* `off` will never present them
*/
scrollButtons: require('prop-types').oneOf(['auto', 'on', 'off']),
/**
* The component used to render the scroll buttons.
*/
TabScrollButton: typeof babelPluginFlowReactPropTypes_proptype_ComponentType === 'function' ? babelPluginFlowReactPropTypes_proptype_ComponentType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ComponentType),
/**
* Determines the color of the `Tab`.
*/
textColor: require('prop-types').oneOf(['accent', 'primary', 'inherit']),
/**
* @ignore
*/
theme: require('prop-types').object,
/**
* The value of the currently selected `Tab`.
* If you don't want any selected `Tab`, you can set this property to `false`.
*/
value: require('prop-types').any.isRequired
};
var babelPluginFlowReactPropTypes_proptype_TabsMeta = {
clientWidth: require('prop-types').number.isRequired,
scrollLeft: require('prop-types').number.isRequired,
scrollLeftNormalized: require('prop-types').number.isRequired,
scrollWidth: require('prop-types').number.isRequired,
// ClientRect
left: require('prop-types').number.isRequired,
right: require('prop-types').number.isRequired
};
var Tabs = function (_React$Component) {
(0, _inherits3.default)(Tabs, _React$Component);
function Tabs() {
var _ref;
var _temp, _this, _ret;
(0, _classCallCheck3.default)(this, Tabs);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = Tabs.__proto__ || (0, _getPrototypeOf2.default)(Tabs)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
indicatorStyle: {
left: 0,
width: 0
},
scrollerStyle: {
marginBottom: 0
},
showLeftScroll: false,
showRightScroll: false,
mounted: false
}, _this.getConditionalElements = function () {
var _this$props = _this.props,
classes = _this$props.classes,
buttonClassName = _this$props.buttonClassName,
scrollable = _this$props.scrollable,
scrollButtons = _this$props.scrollButtons,
TabScrollButtonProp = _this$props.TabScrollButton,
theme = _this$props.theme;
var conditionalElements = {};
conditionalElements.scrollbarSizeListener = scrollable ? _react2.default.createElement(_reactScrollbarSize2.default, {
onLoad: _this.handleScrollbarSizeChange,
onChange: _this.handleScrollbarSizeChange
}) : null;
var showScrollButtons = scrollable && (scrollButtons === 'auto' || scrollButtons === 'on');
conditionalElements.scrollButtonLeft = showScrollButtons ? _react2.default.createElement(TabScrollButtonProp, {
direction: theme.direction === 'rtl' ? 'right' : 'left',
onClick: _this.handleLeftScrollClick,
visible: _this.state.showLeftScroll,
className: (0, _classnames2.default)((0, _defineProperty3.default)({}, classes.buttonAuto, scrollButtons === 'auto'), buttonClassName)
}) : null;
conditionalElements.scrollButtonRight = showScrollButtons ? _react2.default.createElement(TabScrollButtonProp, {
direction: theme.direction === 'rtl' ? 'left' : 'right',
onClick: _this.handleRightScrollClick,
visible: _this.state.showRightScroll,
className: (0, _classnames2.default)((0, _defineProperty3.default)({}, classes.buttonAuto, scrollButtons === 'auto'), buttonClassName)
}) : null;
return conditionalElements;
}, _this.getTabsMeta = function (value, direction) {
var tabsMeta = void 0;
if (_this.tabs) {
var rect = _this.tabs.getBoundingClientRect();
// create a new object with ClientRect class props + scrollLeft
tabsMeta = {
clientWidth: _this.tabs ? _this.tabs.clientWidth : 0,
scrollLeft: _this.tabs ? _this.tabs.scrollLeft : 0,
scrollLeftNormalized: _this.tabs ? (0, _normalizeScrollLeft.getNormalizedScrollLeft)(_this.tabs, direction) : 0,
scrollWidth: _this.tabs ? _this.tabs.scrollWidth : 0,
left: rect.left,
right: rect.right
};
}
var tabMeta = void 0;
if (_this.tabs && value !== false) {
var _children = _this.tabs.children[0].children;
if (_children.length > 0) {
var tab = _children[_this.valueToIndex[value]];
process.env.NODE_ENV !== "production" ? (0, _warning2.default)(Boolean(tab), 'Material-UI: the value provided `' + value + '` is invalid') : void 0;
tabMeta = tab ? tab.getBoundingClientRect() : null;
}
}
return { tabsMeta: tabsMeta, tabMeta: tabMeta };
}, _this.tabs = undefined, _this.valueToIndex = {}, _this.handleResize = (0, _debounce2.default)(function () {
_this.updateIndicatorState(_this.props);
_this.updateScrollButtonState();
}, 166), _this.handleLeftScrollClick = function () {
if (_this.tabs) {
_this.moveTabsScroll(-_this.tabs.clientWidth);
}
}, _this.handleRightScrollClick = function () {
if (_this.tabs) {
_this.moveTabsScroll(_this.tabs.clientWidth);
}
}, _this.handleScrollbarSizeChange = function (_ref2) {
var scrollbarHeight = _ref2.scrollbarHeight;
_this.setState({
scrollerStyle: {
marginBottom: -scrollbarHeight
}
});
}, _this.handleTabsScroll = (0, _debounce2.default)(function () {
_this.updateScrollButtonState();
}, 166), _this.moveTabsScroll = function (delta) {
var theme = _this.props.theme;
if (_this.tabs) {
var multiplier = theme.direction === 'rtl' ? -1 : 1;
var nextScrollLeft = _this.tabs.scrollLeft + delta * multiplier;
// Fix for Edge
var invert = theme.direction === 'rtl' && (0, _normalizeScrollLeft.detectScrollType)() === 'reverse' ? -1 : 1;
_scroll2.default.left(_this.tabs, invert * nextScrollLeft);
}
}, _this.scrollSelectedIntoView = function () {
var _this$props2 = _this.props,
theme = _this$props2.theme,
value = _this$props2.value;
var _this$getTabsMeta = _this.getTabsMeta(value, theme.direction),
tabsMeta = _this$getTabsMeta.tabsMeta,
tabMeta = _this$getTabsMeta.tabMeta;
if (!tabMeta || !tabsMeta) {
return;
}
if (tabMeta.left < tabsMeta.left) {
// left side of button is out of view
var nextScrollLeft = tabsMeta.scrollLeft + (tabMeta.left - tabsMeta.left);
_scroll2.default.left(_this.tabs, nextScrollLeft);
} else if (tabMeta.right > tabsMeta.right) {
// right side of button is out of view
var _nextScrollLeft = tabsMeta.scrollLeft + (tabMeta.right - tabsMeta.right);
_scroll2.default.left(_this.tabs, _nextScrollLeft);
}
}, _this.updateScrollButtonState = function () {
var _this$props3 = _this.props,
scrollable = _this$props3.scrollable,
scrollButtons = _this$props3.scrollButtons,
theme = _this$props3.theme;
if (_this.tabs && scrollable && scrollButtons !== 'off') {
var _this$tabs = _this.tabs,
_scrollWidth = _this$tabs.scrollWidth,
_clientWidth = _this$tabs.clientWidth;
var _scrollLeft = (0, _normalizeScrollLeft.getNormalizedScrollLeft)(_this.tabs, theme.direction);
var _showLeftScroll = theme.direction === 'rtl' ? _scrollWidth > _clientWidth + _scrollLeft : _scrollLeft > 0;
var _showRightScroll = theme.direction === 'rtl' ? _scrollLeft > 0 : _scrollWidth > _clientWidth + _scrollLeft;
if (_showLeftScroll !== _this.state.showLeftScroll || _showRightScroll !== _this.state.showRightScroll) {
_this.setState({ showLeftScroll: _showLeftScroll, showRightScroll: _showRightScroll });
}
}
}, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
}
(0, _createClass3.default)(Tabs, [{
key: 'componentDidMount',
value: function componentDidMount() {
// eslint-disable-next-line react/no-did-mount-set-state
this.setState({ mounted: true });
this.updateIndicatorState(this.props);
this.updateScrollButtonState();
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate(prevProps, prevState) {
this.updateScrollButtonState();
// The index might have changed at the same time.
// We need to check again the right indicator position.
this.updateIndicatorState(this.props);
if (this.state.indicatorStyle !== prevState.indicatorStyle) {
this.scrollSelectedIntoView();
}
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.handleResize.cancel();
this.handleTabsScroll.cancel();
}
}, {
key: 'updateIndicatorState',
value: function updateIndicatorState(props) {
var theme = props.theme,
value = props.value;
var _getTabsMeta = this.getTabsMeta(value, theme.direction),
tabsMeta = _getTabsMeta.tabsMeta,
tabMeta = _getTabsMeta.tabMeta;
var left = 0;
if (tabMeta && tabsMeta) {
var correction = theme.direction === 'rtl' ? tabsMeta.scrollLeftNormalized + tabsMeta.clientWidth - tabsMeta.scrollWidth : tabsMeta.scrollLeft;
left = tabMeta.left - tabsMeta.left + correction;
}
var indicatorStyle = {
left: left,
// May be wrong until the font is loaded.
width: tabMeta ? tabMeta.width : 0
};
if ((indicatorStyle.left !== this.state.indicatorStyle.left || indicatorStyle.width !== this.state.indicatorStyle.width) && !(0, _isNan2.default)(indicatorStyle.left) && !(0, _isNan2.default)(indicatorStyle.width)) {
this.setState({ indicatorStyle: indicatorStyle });
}
}
}, {
key: 'render',
value: function render() {
var _classNames3,
_this2 = this;
var _props = this.props,
buttonClassName = _props.buttonClassName,
centered = _props.centered,
classes = _props.classes,
childrenProp = _props.children,
classNameProp = _props.className,
fullWidth = _props.fullWidth,
indicatorClassName = _props.indicatorClassName,
indicatorColor = _props.indicatorColor,
onChange = _props.onChange,
scrollable = _props.scrollable,
scrollButtons = _props.scrollButtons,
TabScrollButtonProp = _props.TabScrollButton,
textColor = _props.textColor,
theme = _props.theme,
value = _props.value,
other = (0, _objectWithoutProperties3.default)(_props, ['buttonClassName', 'centered', 'classes', 'children', 'className', 'fullWidth', 'indicatorClassName', 'indicatorColor', 'onChange', 'scrollable', 'scrollButtons', 'TabScrollButton', 'textColor', 'theme', 'value']);
var className = (0, _classnames2.default)(classes.root, classNameProp);
var scrollerClassName = (0, _classnames2.default)(classes.scrollingContainer, (_classNames3 = {}, (0, _defineProperty3.default)(_classNames3, classes.fixed, !scrollable), (0, _defineProperty3.default)(_classNames3, classes.scrollable, scrollable), _classNames3));
var tabItemContainerClassName = (0, _classnames2.default)(classes.flexContainer, (0, _defineProperty3.default)({}, classes.centered, centered && !scrollable));
var indicator = _react2.default.createElement(_TabIndicator2.default, {
style: this.state.indicatorStyle,
className: indicatorClassName,
color: indicatorColor
});
this.valueToIndex = {};
var childIndex = 0;
var children = _react2.default.Children.map(childrenProp, function (child) {
if (!_react2.default.isValidElement(child)) {
return null;
}
var childValue = child.props.value || childIndex;
_this2.valueToIndex[childValue] = childIndex;
var selected = childValue === value;
childIndex += 1;
return _react2.default.cloneElement(child, {
fullWidth: fullWidth,
indicator: selected && !_this2.state.mounted && indicator,
selected: selected,
onChange: onChange,
textColor: textColor,
value: childValue
});
});
var conditionalElements = this.getConditionalElements();
return _react2.default.createElement(
'div',
(0, _extends3.default)({ className: className }, other),
_react2.default.createElement(_reactEventListener2.default, { target: 'window', onResize: this.handleResize }),
conditionalElements.scrollbarSizeListener,
_react2.default.createElement(
'div',
{ className: classes.flexContainer },
conditionalElements.scrollButtonLeft,
_react2.default.createElement(
'div',
{
className: scrollerClassName,
style: this.state.scrollerStyle,
ref: function ref(node) {
_this2.tabs = node;
},
role: 'tablist',
onScroll: this.handleTabsScroll
},
_react2.default.createElement(
'div',
{ className: tabItemContainerClassName },
children
),
this.state.mounted && indicator
),
conditionalElements.scrollButtonRight
)
);
}
}]);
return Tabs;
}(_react2.default.Component);
Tabs.defaultProps = {
centered: false,
fullWidth: false,
indicatorColor: 'accent',
scrollable: false,
scrollButtons: 'auto',
TabScrollButton: _TabScrollButton2.default,
textColor: 'inherit'
};
exports.default = (0, _withStyles2.default)(styles, { withTheme: true, name: 'MuiTabs' })(Tabs);

View File

@@ -0,0 +1,475 @@
// @flow
import React from 'react';
import type { Node, ComponentType } from 'react';
import warning from 'warning';
import classNames from 'classnames';
import EventListener from 'react-event-listener';
import debounce from 'lodash/debounce';
import ScrollbarSize from 'react-scrollbar-size';
import { getNormalizedScrollLeft, detectScrollType } from 'normalize-scroll-left';
import scroll from 'scroll';
import withStyles from '../styles/withStyles';
import TabIndicator from './TabIndicator';
import TabScrollButton from './TabScrollButton';
import type { IndicatorStyle } from './TabIndicator';
export const styles = (theme: Object) => ({
root: {
overflow: 'hidden',
minHeight: 48,
WebkitOverflowScrolling: 'touch', // Add iOS momentum scrolling.
},
flexContainer: {
display: 'flex',
},
scrollingContainer: {
position: 'relative',
display: 'inline-block',
flex: '1 1 auto',
whiteSpace: 'nowrap',
},
fixed: {
overflowX: 'hidden',
width: '100%',
},
scrollable: {
overflowX: 'scroll',
},
centered: {
justifyContent: 'center',
},
buttonAuto: {
[theme.breakpoints.down('sm')]: {
display: 'none',
},
},
});
type ProvidedProps = {
classes: Object,
indicatorColor: string,
TabScrollButton: ComponentType<*>,
theme: Object,
};
export type Props = {
/**
* The CSS class name of the scroll button elements.
*/
buttonClassName?: string,
/**
* If `true`, the tabs will be centered.
* This property is intended for large views.
*/
centered?: boolean,
/**
* The content of the component.
*/
children?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* If `true`, the tabs will grow to use all the available space.
* This property is intended for small views, like on mobile.
*/
fullWidth?: boolean,
/**
* The CSS class name of the indicator element.
*/
indicatorClassName?: string,
/**
* Determines the color of the indicator.
*/
indicatorColor?: 'accent' | 'primary' | string,
/**
* Callback fired when the value changes.
*
* @param {object} event The event source of the callback
* @param {number} value We default to the index of the child
*/
onChange: Function,
/**
* True invokes scrolling properties and allow for horizontally scrolling
* (or swiping) the tab bar.
*/
scrollable?: boolean,
/**
* Determine behavior of scroll buttons when tabs are set to scroll
* `auto` will only present them on medium and larger viewports
* `on` will always present them
* `off` will never present them
*/
scrollButtons?: 'auto' | 'on' | 'off',
/**
* The component used to render the scroll buttons.
*/
TabScrollButton?: ComponentType<*>,
/**
* Determines the color of the `Tab`.
*/
textColor?: 'accent' | 'primary' | 'inherit',
/**
* @ignore
*/
theme?: Object,
/**
* The value of the currently selected `Tab`.
* If you don't want any selected `Tab`, you can set this property to `false`.
*/
value: any,
};
type State = {
indicatorStyle: IndicatorStyle,
scrollerStyle: Object,
showLeftScroll: boolean,
showRightScroll: boolean,
mounted: boolean,
};
export type TabsMeta = {
clientWidth: number,
scrollLeft: number,
scrollLeftNormalized: number,
scrollWidth: number,
// ClientRect
left: number,
right: number,
};
class Tabs extends React.Component<ProvidedProps & Props, State> {
static defaultProps = {
centered: false,
fullWidth: false,
indicatorColor: 'accent',
scrollable: false,
scrollButtons: 'auto',
TabScrollButton,
textColor: 'inherit',
};
state = {
indicatorStyle: {
left: 0,
width: 0,
},
scrollerStyle: {
marginBottom: 0,
},
showLeftScroll: false,
showRightScroll: false,
mounted: false,
};
componentDidMount() {
// eslint-disable-next-line react/no-did-mount-set-state
this.setState({ mounted: true });
this.updateIndicatorState(this.props);
this.updateScrollButtonState();
}
componentDidUpdate(prevProps, prevState) {
this.updateScrollButtonState();
// The index might have changed at the same time.
// We need to check again the right indicator position.
this.updateIndicatorState(this.props);
if (this.state.indicatorStyle !== prevState.indicatorStyle) {
this.scrollSelectedIntoView();
}
}
componentWillUnmount() {
this.handleResize.cancel();
this.handleTabsScroll.cancel();
}
getConditionalElements = () => {
const {
classes,
buttonClassName,
scrollable,
scrollButtons,
TabScrollButton: TabScrollButtonProp,
theme,
} = this.props;
const conditionalElements = {};
conditionalElements.scrollbarSizeListener = scrollable ? (
<ScrollbarSize
onLoad={this.handleScrollbarSizeChange}
onChange={this.handleScrollbarSizeChange}
/>
) : null;
const showScrollButtons = scrollable && (scrollButtons === 'auto' || scrollButtons === 'on');
conditionalElements.scrollButtonLeft = showScrollButtons ? (
<TabScrollButtonProp
direction={theme.direction === 'rtl' ? 'right' : 'left'}
onClick={this.handleLeftScrollClick}
visible={this.state.showLeftScroll}
className={classNames(
{
[classes.buttonAuto]: scrollButtons === 'auto',
},
buttonClassName,
)}
/>
) : null;
conditionalElements.scrollButtonRight = showScrollButtons ? (
<TabScrollButtonProp
direction={theme.direction === 'rtl' ? 'left' : 'right'}
onClick={this.handleRightScrollClick}
visible={this.state.showRightScroll}
className={classNames(
{
[classes.buttonAuto]: scrollButtons === 'auto',
},
buttonClassName,
)}
/>
) : null;
return conditionalElements;
};
getTabsMeta = (value, direction): { tabsMeta: ?TabsMeta, tabMeta: ?ClientRect } => {
let tabsMeta;
if (this.tabs) {
const rect = this.tabs.getBoundingClientRect();
// create a new object with ClientRect class props + scrollLeft
tabsMeta = {
clientWidth: this.tabs ? this.tabs.clientWidth : 0,
scrollLeft: this.tabs ? this.tabs.scrollLeft : 0,
scrollLeftNormalized: this.tabs ? getNormalizedScrollLeft(this.tabs, direction) : 0,
scrollWidth: this.tabs ? this.tabs.scrollWidth : 0,
left: rect.left,
right: rect.right,
};
}
let tabMeta;
if (this.tabs && value !== false) {
const children = this.tabs.children[0].children;
if (children.length > 0) {
const tab = children[this.valueToIndex[value]];
warning(Boolean(tab), `Material-UI: the value provided \`${value}\` is invalid`);
tabMeta = tab ? tab.getBoundingClientRect() : null;
}
}
return { tabsMeta, tabMeta };
};
tabs: ?HTMLElement = undefined;
valueToIndex: { [key: any]: any } = {};
handleResize = debounce(() => {
this.updateIndicatorState(this.props);
this.updateScrollButtonState();
}, 166);
handleLeftScrollClick = () => {
if (this.tabs) {
this.moveTabsScroll(-this.tabs.clientWidth);
}
};
handleRightScrollClick = () => {
if (this.tabs) {
this.moveTabsScroll(this.tabs.clientWidth);
}
};
handleScrollbarSizeChange = ({ scrollbarHeight }) => {
this.setState({
scrollerStyle: {
marginBottom: -scrollbarHeight,
},
});
};
handleTabsScroll = debounce(() => {
this.updateScrollButtonState();
}, 166);
moveTabsScroll = delta => {
const { theme } = this.props;
if (this.tabs) {
const multiplier = theme.direction === 'rtl' ? -1 : 1;
const nextScrollLeft = this.tabs.scrollLeft + delta * multiplier;
// Fix for Edge
const invert = theme.direction === 'rtl' && detectScrollType() === 'reverse' ? -1 : 1;
scroll.left(this.tabs, invert * nextScrollLeft);
}
};
updateIndicatorState(props) {
const { theme, value } = props;
const { tabsMeta, tabMeta } = this.getTabsMeta(value, theme.direction);
let left = 0;
if (tabMeta && tabsMeta) {
const correction =
theme.direction === 'rtl'
? tabsMeta.scrollLeftNormalized + tabsMeta.clientWidth - tabsMeta.scrollWidth
: tabsMeta.scrollLeft;
left = tabMeta.left - tabsMeta.left + correction;
}
const indicatorStyle = {
left,
// May be wrong until the font is loaded.
width: tabMeta ? tabMeta.width : 0,
};
if (
(indicatorStyle.left !== this.state.indicatorStyle.left ||
indicatorStyle.width !== this.state.indicatorStyle.width) &&
!Number.isNaN(indicatorStyle.left) &&
!Number.isNaN(indicatorStyle.width)
) {
this.setState({ indicatorStyle });
}
}
scrollSelectedIntoView = () => {
const { theme, value } = this.props;
const { tabsMeta, tabMeta } = this.getTabsMeta(value, theme.direction);
if (!tabMeta || !tabsMeta) {
return;
}
if (tabMeta.left < tabsMeta.left) {
// left side of button is out of view
const nextScrollLeft = tabsMeta.scrollLeft + (tabMeta.left - tabsMeta.left);
scroll.left(this.tabs, nextScrollLeft);
} else if (tabMeta.right > tabsMeta.right) {
// right side of button is out of view
const nextScrollLeft = tabsMeta.scrollLeft + (tabMeta.right - tabsMeta.right);
scroll.left(this.tabs, nextScrollLeft);
}
};
updateScrollButtonState = () => {
const { scrollable, scrollButtons, theme } = this.props;
if (this.tabs && scrollable && scrollButtons !== 'off') {
const { scrollWidth, clientWidth } = this.tabs;
const scrollLeft = getNormalizedScrollLeft(this.tabs, theme.direction);
const showLeftScroll =
theme.direction === 'rtl' ? scrollWidth > clientWidth + scrollLeft : scrollLeft > 0;
const showRightScroll =
theme.direction === 'rtl' ? scrollLeft > 0 : scrollWidth > clientWidth + scrollLeft;
if (
showLeftScroll !== this.state.showLeftScroll ||
showRightScroll !== this.state.showRightScroll
) {
this.setState({ showLeftScroll, showRightScroll });
}
}
};
render() {
const {
buttonClassName,
centered,
classes,
children: childrenProp,
className: classNameProp,
fullWidth,
indicatorClassName,
indicatorColor,
onChange,
scrollable,
scrollButtons,
TabScrollButton: TabScrollButtonProp,
textColor,
theme,
value,
...other
} = this.props;
const className = classNames(classes.root, classNameProp);
const scrollerClassName = classNames(classes.scrollingContainer, {
[classes.fixed]: !scrollable,
[classes.scrollable]: scrollable,
});
const tabItemContainerClassName = classNames(classes.flexContainer, {
[classes.centered]: centered && !scrollable,
});
const indicator = (
<TabIndicator
style={this.state.indicatorStyle}
className={indicatorClassName}
color={indicatorColor}
/>
);
this.valueToIndex = {};
let childIndex = 0;
const children = React.Children.map(childrenProp, child => {
if (!React.isValidElement(child)) {
return null;
}
const childValue = child.props.value || childIndex;
this.valueToIndex[childValue] = childIndex;
const selected = childValue === value;
childIndex += 1;
return React.cloneElement(child, {
fullWidth,
indicator: selected && !this.state.mounted && indicator,
selected,
onChange,
textColor,
value: childValue,
});
});
const conditionalElements = this.getConditionalElements();
return (
<div className={className} {...other}>
<EventListener target="window" onResize={this.handleResize} />
{conditionalElements.scrollbarSizeListener}
<div className={classes.flexContainer}>
{conditionalElements.scrollButtonLeft}
<div
className={scrollerClassName}
style={this.state.scrollerStyle}
ref={node => {
this.tabs = node;
}}
role="tablist"
onScroll={this.handleTabsScroll}
>
<div className={tabItemContainerClassName}>{children}</div>
{this.state.mounted && indicator}
</div>
{conditionalElements.scrollButtonRight}
</div>
</div>
);
}
}
export default withStyles(styles, { withTheme: true, name: 'MuiTabs' })(Tabs);

View File

@@ -0,0 +1,4 @@
export { default } from './Tabs';
export * from './Tabs';
export { default as Tab } from './Tab';
export * from './Tab';

25
torrent-project/node_modules/material-ui/Tabs/index.js generated vendored Normal file
View File

@@ -0,0 +1,25 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _Tabs = require('./Tabs');
Object.defineProperty(exports, 'default', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_Tabs).default;
}
});
var _Tab = require('./Tab');
Object.defineProperty(exports, 'Tab', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_Tab).default;
}
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

View File

@@ -0,0 +1,3 @@
// @flow
export { default } from './Tabs';
export { default as Tab } from './Tab';