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

View File

@@ -0,0 +1,67 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface InputProps extends StandardProps<
React.HTMLAttributes<HTMLDivElement>,
InputClassKey,
'onChange' | 'onKeyUp' | 'onKeyDown' | 'defaultValue'
> {
autoComplete?: string;
autoFocus?: boolean;
inputComponent?: React.ReactNode;
defaultValue?: string | number;
disabled?: boolean;
disableUnderline?: boolean;
endAdornment?: React.ReactNode;
error?: boolean;
fullWidth?: boolean;
id?: string;
inputProps?:
| React.TextareaHTMLAttributes<HTMLTextAreaElement>
| React.InputHTMLAttributes<HTMLInputElement>;
inputRef?: React.Ref<any>;
margin?: 'dense';
multiline?: boolean;
name?: string;
placeholder?: string;
rows?: string | number;
rowsMax?: string | number;
startAdornment?: React.ReactNode;
type?: string;
value?: string | number;
onClean?: () => void;
onDirty?: () => void;
/**
* `onChange`, `onKeyUp` + `onKeyDown` are applied to the inner `InputComponent`,
* which by default is an input or textarea. Since these handlers differ from the
* ones inherited by `React.HTMLAttributes<HTMLDivElement>` we need to omit them.
*
* Note that `blur` and `focus` event handler are applied to the outter `<div>`.
* So these can just be inherited from the native `<div>`.
*/
onChange?: React.ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement>;
onKeyUp?: React.KeyboardEventHandler<HTMLTextAreaElement | HTMLInputElement>;
onKeyDown?: React.KeyboardEventHandler<HTMLTextAreaElement | HTMLInputElement>;
}
export type InputClassKey =
| 'root'
| 'formControl'
| 'inkbar'
| 'error'
| 'input'
| 'inputDense'
| 'disabled'
| 'focused'
| 'underline'
| 'multiline'
| 'inputDisabled'
| 'inputSingleline'
| 'inputSearch'
| 'inputMultiline'
| 'fullWidth'
;
declare const Input: React.ComponentType<InputProps>;
export default Input;

687
torrent-project/node_modules/material-ui/Input/Input.js generated vendored Normal file
View File

@@ -0,0 +1,687 @@
'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 _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);
exports.hasValue = hasValue;
exports.isDirty = isDirty;
exports.isAdornedStart = isAdornedStart;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
var _reactHelpers = require('../utils/reactHelpers');
var _Textarea = require('./Textarea');
var _Textarea2 = _interopRequireDefault(_Textarea);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_ComponentType = require('prop-types').func; // weak
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
// Supports determination of isControlled().
// Controlled input accepts its current value as a prop.
//
// @see https://facebook.github.io/react/docs/forms.html#controlled-components
// @param value
// @returns {boolean} true if string (including '') or number (including zero)
function hasValue(value) {
return value !== undefined && value !== null && !(Array.isArray(value) && value.length === 0);
}
// Determine if field is dirty (a.k.a. filled).
//
// Response determines if label is presented above field or as placeholder.
//
// @param obj
// @param SSR
// @returns {boolean} False when not present or empty string.
// True when any number or string with length.
function isDirty(obj) {
var SSR = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
return obj && (hasValue(obj.value) && obj.value !== '' || SSR && hasValue(obj.defaultValue) && obj.defaultValue !== '');
}
// Determine if an Input is adorned on start.
// It's corresponding to the left with LTR.
//
// @param obj
// @returns {boolean} False when no adornments.
// True when adorned at the start.
function isAdornedStart(obj) {
return obj.startAdornment;
}
var styles = exports.styles = function styles(theme) {
var placeholder = {
color: 'currentColor',
opacity: theme.palette.type === 'light' ? 0.42 : 0.5,
transition: theme.transitions.create('opacity', {
duration: theme.transitions.duration.shorter,
easing: theme.transitions.easing.ease
})
};
var placeholderHidden = {
opacity: 0
};
var placeholderVisible = {
opacity: theme.palette.type === 'light' ? 0.42 : 0.5
};
return {
root: {
// Mimics the default input display property used by browsers for an input.
display: 'inline-flex',
alignItems: 'baseline',
position: 'relative',
fontFamily: theme.typography.fontFamily,
color: theme.palette.input.inputText,
fontSize: theme.typography.pxToRem(16)
},
formControl: {
'label + &': {
marginTop: theme.spacing.unit * 2
}
},
inkbar: {
'&:after': {
backgroundColor: theme.palette.primary[theme.palette.type === 'light' ? 'A700' : 'A200'],
left: 0,
bottom: 0,
// Doing the other way around crash on IE11 "''" https://github.com/cssinjs/jss/issues/242
content: '""',
height: 2,
position: 'absolute',
right: 0,
transform: 'scaleX(0)',
transition: theme.transitions.create('transform', {
duration: theme.transitions.duration.shorter,
easing: theme.transitions.easing.easeOut
}),
pointerEvents: 'none' // Transparent to the hover style.
},
'&$focused:after': {
transform: 'scaleX(1)'
}
},
error: {
'&:after': {
backgroundColor: theme.palette.error.A400,
transform: 'scaleX(1)' // error is always underlined in red
}
},
input: {
font: 'inherit',
color: 'currentColor',
// slight alteration to spec spacing to match visual spec result
padding: theme.spacing.unit - 1 + 'px 0 ' + (theme.spacing.unit + 1) + 'px',
border: 0,
boxSizing: 'content-box',
verticalAlign: 'middle',
background: 'none',
margin: 0, // Reset for Safari
display: 'block',
width: '100%',
'&::-webkit-input-placeholder': placeholder,
'&::-moz-placeholder': placeholder, // Firefox 19+
'&:-ms-input-placeholder': placeholder, // IE 11
'&::-ms-input-placeholder': placeholder, // Edge
'&:focus': {
outline: 0
},
// Reset Firefox invalid required input style
'&:invalid': {
boxShadow: 'none'
},
'&::-webkit-search-decoration': {
// Remove the padding when type=search.
appearance: 'none'
},
// Show and hide the placeholder logic
'label[data-shrink=false] + $formControl &': {
'&::-webkit-input-placeholder': placeholderHidden,
'&::-moz-placeholder': placeholderHidden, // Firefox 19+
'&:-ms-input-placeholder': placeholderHidden, // IE 11
'&::-ms-input-placeholder': placeholderHidden, // Edge
'&:focus::-webkit-input-placeholder': placeholderVisible,
'&:focus::-moz-placeholder': placeholderVisible, // Firefox 19+
'&:focus:-ms-input-placeholder': placeholderVisible, // IE 11
'&:focus::-ms-input-placeholder': placeholderVisible // Edge
}
},
inputDense: {
paddingTop: theme.spacing.unit / 2
},
disabled: {
color: theme.palette.text.disabled
},
focused: {},
underline: {
'&:before': {
backgroundColor: theme.palette.input.bottomLine,
left: 0,
bottom: 0,
// Doing the other way around crash on IE11 "''" https://github.com/cssinjs/jss/issues/242
content: '""',
height: 1,
position: 'absolute',
right: 0,
transition: theme.transitions.create('background-color', {
duration: theme.transitions.duration.shorter,
easing: theme.transitions.easing.ease
}),
pointerEvents: 'none' // Transparent to the hover style.
},
'&:hover:not($disabled):before': {
backgroundColor: theme.palette.text.primary,
height: 2
},
'&$disabled:before': {
background: 'transparent',
backgroundImage: 'linear-gradient(to right, ' + theme.palette.input.bottomLine + ' 33%, transparent 0%)',
backgroundPosition: 'left top',
backgroundRepeat: 'repeat-x',
backgroundSize: '5px 1px'
}
},
multiline: {
padding: theme.spacing.unit - 2 + 'px 0 ' + (theme.spacing.unit - 1) + 'px'
},
inputDisabled: {
opacity: 1 // Reset iOS opacity
},
inputSingleline: {
height: '1em'
},
inputSearch: {
appearance: 'textfield' // Improve type search style.
},
inputMultiline: {
resize: 'none',
padding: 0
},
fullWidth: {
width: '100%'
}
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* This property helps users to fill forms faster, especially on mobile devices.
* The name can be confusing, it's more like an autofill.
* You can learn more about it in this article
* https://developers.google.com/web/updates/2015/06/checkout-faster-with-autofill
*/
autoComplete: require('prop-types').string,
/**
* If `true`, the input will be focused during the first mount.
*/
autoFocus: require('prop-types').bool,
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* The CSS class name of the wrapper element.
*/
className: require('prop-types').string,
/**
* The default input value, useful when not controlling the component.
*/
defaultValue: require('prop-types').oneOfType([require('prop-types').string, require('prop-types').number]),
/**
* If `true`, the input will be disabled.
*/
disabled: require('prop-types').bool,
/**
* If `true`, the input will not have an underline.
*/
disableUnderline: require('prop-types').bool,
/**
* End `InputAdornment` for this component.
*/
endAdornment: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* If `true`, the input will indicate an error. This is normally obtained via context from
* FormControl.
*/
error: require('prop-types').bool,
/**
* If `true`, the input will take up the full width of its container.
*/
fullWidth: require('prop-types').bool,
/**
* The id of the `input` element.
*/
id: require('prop-types').string,
/**
* The component used for the input node.
* Either a string to use a DOM element or a component.
* It's an `input` by default.
*/
inputComponent: require('prop-types').oneOfType([require('prop-types').string, typeof babelPluginFlowReactPropTypes_proptype_ComponentType === 'function' ? babelPluginFlowReactPropTypes_proptype_ComponentType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ComponentType)]),
/**
* Properties applied to the `input` element.
*/
inputProps: require('prop-types').object,
/**
* Use that property to pass a ref callback to the native input component.
*/
inputRef: require('prop-types').func,
/**
* If `dense`, will adjust vertical spacing. This is normally obtained via context from
* FormControl.
*/
margin: require('prop-types').oneOf(['dense', 'none']),
/**
* If `true`, a textarea element will be rendered.
*/
multiline: require('prop-types').bool,
/**
* Name attribute of the `input` element.
*/
name: require('prop-types').string,
/**
* @ignore
*/
readOnly: require('prop-types').bool,
/**
* @ignore
*/
onBlur: require('prop-types').func,
/**
* Callback fired when the value is changed.
*
* @param {object} event The event source of the callback
*/
onChange: require('prop-types').func,
/**
* TODO
*/
onClean: require('prop-types').func,
/**
* TODO
*/
onDirty: require('prop-types').func,
/**
* @ignore
*/
onFocus: require('prop-types').func,
/**
* @ignore
*/
onKeyDown: require('prop-types').func,
/**
* @ignore
*/
onKeyUp: require('prop-types').func,
/**
* The short hint displayed in the input before the user enters a value.
*/
placeholder: require('prop-types').string,
/**
* Number of rows to display when multiline option is set to true.
*/
rows: require('prop-types').oneOfType([require('prop-types').string, require('prop-types').number]),
/**
* Maximum number of rows to display when multiline option is set to true.
*/
rowsMax: require('prop-types').oneOfType([require('prop-types').string, require('prop-types').number]),
/**
* Start `InputAdornment` for this component.
*/
startAdornment: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* Type of the input element. It should be a valid HTML5 input type.
*/
type: require('prop-types').string,
/**
* The input value, required for a controlled component.
*/
value: require('prop-types').oneOfType([require('prop-types').string, require('prop-types').number, require('prop-types').arrayOf(require('prop-types').oneOfType([require('prop-types').string, require('prop-types').number]))])
};
var Input = function (_React$Component) {
(0, _inherits3.default)(Input, _React$Component);
function Input() {
var _ref;
var _temp, _this, _ret;
(0, _classCallCheck3.default)(this, Input);
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 = Input.__proto__ || (0, _getPrototypeOf2.default)(Input)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
focused: false
}, _this.input = null, _this.handleFocus = function (event) {
_this.setState({ focused: true });
if (_this.props.onFocus) {
_this.props.onFocus(event);
}
}, _this.handleBlur = function (event) {
_this.setState({ focused: false });
if (_this.props.onBlur) {
_this.props.onBlur(event);
}
}, _this.handleChange = function (event) {
if (!_this.isControlled()) {
_this.checkDirty(_this.input);
}
// Perform in the willUpdate
if (_this.props.onChange) {
_this.props.onChange(event);
}
}, _this.handleRefInput = function (node) {
_this.input = node;
if (_this.props.inputRef) {
_this.props.inputRef(node);
}
}, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
}
(0, _createClass3.default)(Input, [{
key: 'componentWillMount',
value: function componentWillMount() {
if (this.isControlled()) {
this.checkDirty(this.props);
}
}
}, {
key: 'componentDidMount',
value: function componentDidMount() {
if (!this.isControlled()) {
this.checkDirty(this.input);
}
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
// The blur won't fire when the disabled state is set on a focused input.
// We need to book keep the focused state manually.
if (!this.props.disabled && nextProps.disabled) {
this.setState({
focused: false
});
}
}
}, {
key: 'componentWillUpdate',
value: function componentWillUpdate(nextProps) {
if (this.isControlled(nextProps)) {
this.checkDirty(nextProps);
} // else performed in the onChange
// Book keep the focused state.
if (!this.props.disabled && nextProps.disabled) {
var muiFormControl = this.context.muiFormControl;
if (muiFormControl && muiFormControl.onBlur) {
muiFormControl.onBlur();
}
}
}
// Holds the input reference
}, {
key: 'isControlled',
// A controlled input accepts its current value as a prop.
//
// @see https://facebook.github.io/react/docs/forms.html#controlled-components
// @returns {boolean} true if string (including '') or number (including zero)
value: function isControlled() {
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.props;
return hasValue(props.value);
}
}, {
key: 'checkDirty',
value: function checkDirty(obj) {
var muiFormControl = this.context.muiFormControl;
if (isDirty(obj)) {
if (muiFormControl && muiFormControl.onDirty) {
muiFormControl.onDirty();
}
if (this.props.onDirty) {
this.props.onDirty();
}
return;
}
if (muiFormControl && muiFormControl.onClean) {
muiFormControl.onClean();
}
if (this.props.onClean) {
this.props.onClean();
}
}
}, {
key: 'render',
value: function render() {
var _classNames, _classNames2;
var _props = this.props,
autoComplete = _props.autoComplete,
autoFocus = _props.autoFocus,
classes = _props.classes,
classNameProp = _props.className,
defaultValue = _props.defaultValue,
disabledProp = _props.disabled,
disableUnderline = _props.disableUnderline,
endAdornment = _props.endAdornment,
errorProp = _props.error,
fullWidth = _props.fullWidth,
id = _props.id,
inputComponent = _props.inputComponent,
_props$inputProps = _props.inputProps;
_props$inputProps = _props$inputProps === undefined ? {} : _props$inputProps;
var inputPropsClassName = _props$inputProps.className,
inputPropsProp = (0, _objectWithoutProperties3.default)(_props$inputProps, ['className']),
inputRef = _props.inputRef,
marginProp = _props.margin,
multiline = _props.multiline,
onBlur = _props.onBlur,
onFocus = _props.onFocus,
onChange = _props.onChange,
onClean = _props.onClean,
onDirty = _props.onDirty,
onKeyDown = _props.onKeyDown,
onKeyUp = _props.onKeyUp,
placeholder = _props.placeholder,
name = _props.name,
readOnly = _props.readOnly,
rows = _props.rows,
rowsMax = _props.rowsMax,
startAdornment = _props.startAdornment,
type = _props.type,
value = _props.value,
other = (0, _objectWithoutProperties3.default)(_props, ['autoComplete', 'autoFocus', 'classes', 'className', 'defaultValue', 'disabled', 'disableUnderline', 'endAdornment', 'error', 'fullWidth', 'id', 'inputComponent', 'inputProps', 'inputRef', 'margin', 'multiline', 'onBlur', 'onFocus', 'onChange', 'onClean', 'onDirty', 'onKeyDown', 'onKeyUp', 'placeholder', 'name', 'readOnly', 'rows', 'rowsMax', 'startAdornment', 'type', 'value']);
var muiFormControl = this.context.muiFormControl;
var disabled = disabledProp;
var error = errorProp;
var margin = marginProp;
if (muiFormControl) {
if (typeof disabled === 'undefined') {
disabled = muiFormControl.disabled;
}
if (typeof error === 'undefined') {
error = muiFormControl.error;
}
if (typeof margin === 'undefined') {
margin = muiFormControl.margin;
}
}
var className = (0, _classnames2.default)(classes.root, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.disabled, disabled), (0, _defineProperty3.default)(_classNames, classes.error, error), (0, _defineProperty3.default)(_classNames, classes.fullWidth, fullWidth), (0, _defineProperty3.default)(_classNames, classes.focused, this.state.focused), (0, _defineProperty3.default)(_classNames, classes.formControl, muiFormControl), (0, _defineProperty3.default)(_classNames, classes.inkbar, !disableUnderline), (0, _defineProperty3.default)(_classNames, classes.multiline, multiline), (0, _defineProperty3.default)(_classNames, classes.underline, !disableUnderline), _classNames), classNameProp);
var inputClassName = (0, _classnames2.default)(classes.input, (_classNames2 = {}, (0, _defineProperty3.default)(_classNames2, classes.inputDisabled, disabled), (0, _defineProperty3.default)(_classNames2, classes.inputSingleline, !multiline), (0, _defineProperty3.default)(_classNames2, classes.inputSearch, type === 'search'), (0, _defineProperty3.default)(_classNames2, classes.inputMultiline, multiline), (0, _defineProperty3.default)(_classNames2, classes.inputDense, margin === 'dense'), _classNames2), inputPropsClassName);
var required = muiFormControl && muiFormControl.required === true;
var InputComponent = 'input';
var inputProps = (0, _extends3.default)({
ref: this.handleRefInput
}, inputPropsProp);
if (inputComponent) {
InputComponent = inputComponent;
if ((0, _reactHelpers.isMuiComponent)(InputComponent, ['SelectInput'])) {
inputProps = (0, _extends3.default)({
selectRef: this.handleRefInput
}, inputProps, {
ref: null
});
}
} else if (multiline) {
if (rows && !rowsMax) {
InputComponent = 'textarea';
} else {
inputProps = (0, _extends3.default)({
rowsMax: rowsMax,
textareaRef: this.handleRefInput
}, inputProps, {
ref: null
});
InputComponent = _Textarea2.default;
}
}
return _react2.default.createElement(
'div',
(0, _extends3.default)({ onBlur: this.handleBlur, onFocus: this.handleFocus, className: className }, other),
startAdornment,
_react2.default.createElement(InputComponent, (0, _extends3.default)({
autoComplete: autoComplete,
autoFocus: autoFocus,
className: inputClassName,
onChange: this.handleChange,
onKeyUp: onKeyUp,
onKeyDown: onKeyDown,
disabled: disabled,
required: required ? true : undefined,
value: value,
id: id,
name: name,
defaultValue: defaultValue,
placeholder: placeholder,
type: type,
readOnly: readOnly,
rows: rows
}, inputProps)),
endAdornment
);
}
}]);
return Input;
}(_react2.default.Component);
Input.muiName = 'Input';
Input.defaultProps = {
disableUnderline: false,
fullWidth: false,
multiline: false,
type: 'text'
};
Input.contextTypes = {
muiFormControl: _propTypes2.default.object
};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiInput' })(Input);

View File

@@ -0,0 +1,611 @@
// @flow weak
import React from 'react';
import type { Node, ComponentType } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import { isMuiComponent } from '../utils/reactHelpers';
import Textarea from './Textarea';
// Supports determination of isControlled().
// Controlled input accepts its current value as a prop.
//
// @see https://facebook.github.io/react/docs/forms.html#controlled-components
// @param value
// @returns {boolean} true if string (including '') or number (including zero)
export function hasValue(value: ?(number | string | Array<*>)) {
return value !== undefined && value !== null && !(Array.isArray(value) && value.length === 0);
}
// Determine if field is dirty (a.k.a. filled).
//
// Response determines if label is presented above field or as placeholder.
//
// @param obj
// @param SSR
// @returns {boolean} False when not present or empty string.
// True when any number or string with length.
export function isDirty(obj, SSR = false) {
return (
obj &&
((hasValue(obj.value) && obj.value !== '') ||
(SSR && hasValue(obj.defaultValue) && obj.defaultValue !== ''))
);
}
// Determine if an Input is adorned on start.
// It's corresponding to the left with LTR.
//
// @param obj
// @returns {boolean} False when no adornments.
// True when adorned at the start.
export function isAdornedStart(obj) {
return obj.startAdornment;
}
export const styles = (theme: Object) => {
const placeholder = {
color: 'currentColor',
opacity: theme.palette.type === 'light' ? 0.42 : 0.5,
transition: theme.transitions.create('opacity', {
duration: theme.transitions.duration.shorter,
easing: theme.transitions.easing.ease,
}),
};
const placeholderHidden = {
opacity: 0,
};
const placeholderVisible = {
opacity: theme.palette.type === 'light' ? 0.42 : 0.5,
};
return {
root: {
// Mimics the default input display property used by browsers for an input.
display: 'inline-flex',
alignItems: 'baseline',
position: 'relative',
fontFamily: theme.typography.fontFamily,
color: theme.palette.input.inputText,
fontSize: theme.typography.pxToRem(16),
},
formControl: {
'label + &': {
marginTop: theme.spacing.unit * 2,
},
},
inkbar: {
'&:after': {
backgroundColor: theme.palette.primary[theme.palette.type === 'light' ? 'A700' : 'A200'],
left: 0,
bottom: 0,
// Doing the other way around crash on IE11 "''" https://github.com/cssinjs/jss/issues/242
content: '""',
height: 2,
position: 'absolute',
right: 0,
transform: 'scaleX(0)',
transition: theme.transitions.create('transform', {
duration: theme.transitions.duration.shorter,
easing: theme.transitions.easing.easeOut,
}),
pointerEvents: 'none', // Transparent to the hover style.
},
'&$focused:after': {
transform: 'scaleX(1)',
},
},
error: {
'&:after': {
backgroundColor: theme.palette.error.A400,
transform: 'scaleX(1)', // error is always underlined in red
},
},
input: {
font: 'inherit',
color: 'currentColor',
// slight alteration to spec spacing to match visual spec result
padding: `${theme.spacing.unit - 1}px 0 ${theme.spacing.unit + 1}px`,
border: 0,
boxSizing: 'content-box',
verticalAlign: 'middle',
background: 'none',
margin: 0, // Reset for Safari
display: 'block',
width: '100%',
'&::-webkit-input-placeholder': placeholder,
'&::-moz-placeholder': placeholder, // Firefox 19+
'&:-ms-input-placeholder': placeholder, // IE 11
'&::-ms-input-placeholder': placeholder, // Edge
'&:focus': {
outline: 0,
},
// Reset Firefox invalid required input style
'&:invalid': {
boxShadow: 'none',
},
'&::-webkit-search-decoration': {
// Remove the padding when type=search.
appearance: 'none',
},
// Show and hide the placeholder logic
'label[data-shrink=false] + $formControl &': {
'&::-webkit-input-placeholder': placeholderHidden,
'&::-moz-placeholder': placeholderHidden, // Firefox 19+
'&:-ms-input-placeholder': placeholderHidden, // IE 11
'&::-ms-input-placeholder': placeholderHidden, // Edge
'&:focus::-webkit-input-placeholder': placeholderVisible,
'&:focus::-moz-placeholder': placeholderVisible, // Firefox 19+
'&:focus:-ms-input-placeholder': placeholderVisible, // IE 11
'&:focus::-ms-input-placeholder': placeholderVisible, // Edge
},
},
inputDense: {
paddingTop: theme.spacing.unit / 2,
},
disabled: {
color: theme.palette.text.disabled,
},
focused: {},
underline: {
'&:before': {
backgroundColor: theme.palette.input.bottomLine,
left: 0,
bottom: 0,
// Doing the other way around crash on IE11 "''" https://github.com/cssinjs/jss/issues/242
content: '""',
height: 1,
position: 'absolute',
right: 0,
transition: theme.transitions.create('background-color', {
duration: theme.transitions.duration.shorter,
easing: theme.transitions.easing.ease,
}),
pointerEvents: 'none', // Transparent to the hover style.
},
'&:hover:not($disabled):before': {
backgroundColor: theme.palette.text.primary,
height: 2,
},
'&$disabled:before': {
background: 'transparent',
backgroundImage: `linear-gradient(to right, ${theme.palette.input
.bottomLine} 33%, transparent 0%)`,
backgroundPosition: 'left top',
backgroundRepeat: 'repeat-x',
backgroundSize: '5px 1px',
},
},
multiline: {
padding: `${theme.spacing.unit - 2}px 0 ${theme.spacing.unit - 1}px`,
},
inputDisabled: {
opacity: 1, // Reset iOS opacity
},
inputSingleline: {
height: '1em',
},
inputSearch: {
appearance: 'textfield', // Improve type search style.
},
inputMultiline: {
resize: 'none',
padding: 0,
},
fullWidth: {
width: '100%',
},
};
};
type ProvidedProps = {
classes: Object,
disableUnderline: boolean,
fullWidth: boolean,
multiline: boolean,
type: string,
};
export type Props = {
/**
* This property helps users to fill forms faster, especially on mobile devices.
* The name can be confusing, it's more like an autofill.
* You can learn more about it in this article
* https://developers.google.com/web/updates/2015/06/checkout-faster-with-autofill
*/
autoComplete?: string,
/**
* If `true`, the input will be focused during the first mount.
*/
autoFocus?: boolean,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* The CSS class name of the wrapper element.
*/
className?: string,
/**
* The default input value, useful when not controlling the component.
*/
defaultValue?: string | number,
/**
* If `true`, the input will be disabled.
*/
disabled?: boolean,
/**
* If `true`, the input will not have an underline.
*/
disableUnderline?: boolean,
/**
* End `InputAdornment` for this component.
*/
endAdornment?: Node,
/**
* If `true`, the input will indicate an error. This is normally obtained via context from
* FormControl.
*/
error?: boolean,
/**
* If `true`, the input will take up the full width of its container.
*/
fullWidth?: boolean,
/**
* The id of the `input` element.
*/
id?: string,
/**
* The component used for the input node.
* Either a string to use a DOM element or a component.
* It's an `input` by default.
*/
inputComponent?: string | ComponentType<*>,
/**
* Properties applied to the `input` element.
*/
inputProps?: Object,
/**
* Use that property to pass a ref callback to the native input component.
*/
inputRef?: Function,
/**
* If `dense`, will adjust vertical spacing. This is normally obtained via context from
* FormControl.
*/
margin?: 'dense' | 'none',
/**
* If `true`, a textarea element will be rendered.
*/
multiline?: boolean,
/**
* Name attribute of the `input` element.
*/
name?: string,
/**
* @ignore
*/
readOnly?: boolean,
/**
* @ignore
*/
onBlur?: (event: SyntheticFocusEvent<>) => void,
/**
* Callback fired when the value is changed.
*
* @param {object} event The event source of the callback
*/
onChange?: (event: SyntheticInputEvent<>) => void,
/**
* TODO
*/
onClean?: () => void,
/**
* TODO
*/
onDirty?: () => void,
/**
* @ignore
*/
onFocus?: (event: SyntheticFocusEvent<>) => void,
/**
* @ignore
*/
onKeyDown?: (event: SyntheticKeyboardEvent<>) => void,
/**
* @ignore
*/
onKeyUp?: (event: SyntheticKeyboardEvent<>) => void,
/**
* The short hint displayed in the input before the user enters a value.
*/
placeholder?: string,
/**
* Number of rows to display when multiline option is set to true.
*/
rows?: string | number,
/**
* Maximum number of rows to display when multiline option is set to true.
*/
rowsMax?: string | number,
/**
* Start `InputAdornment` for this component.
*/
startAdornment?: Node,
/**
* Type of the input element. It should be a valid HTML5 input type.
*/
type?: string,
/**
* The input value, required for a controlled component.
*/
value?: string | number | Array<string | number>,
};
type State = {
focused: boolean,
};
class Input extends React.Component<ProvidedProps & Props, State> {
static muiName = 'Input';
static defaultProps = {
disableUnderline: false,
fullWidth: false,
multiline: false,
type: 'text',
};
state = {
focused: false,
};
componentWillMount() {
if (this.isControlled()) {
this.checkDirty(this.props);
}
}
componentDidMount() {
if (!this.isControlled()) {
this.checkDirty(this.input);
}
}
componentWillReceiveProps(nextProps) {
// The blur won't fire when the disabled state is set on a focused input.
// We need to book keep the focused state manually.
if (!this.props.disabled && nextProps.disabled) {
this.setState({
focused: false,
});
}
}
componentWillUpdate(nextProps) {
if (this.isControlled(nextProps)) {
this.checkDirty(nextProps);
} // else performed in the onChange
// Book keep the focused state.
if (!this.props.disabled && nextProps.disabled) {
const { muiFormControl } = this.context;
if (muiFormControl && muiFormControl.onBlur) {
muiFormControl.onBlur();
}
}
}
// Holds the input reference
input = null;
handleFocus = (event: SyntheticFocusEvent<>) => {
this.setState({ focused: true });
if (this.props.onFocus) {
this.props.onFocus(event);
}
};
handleBlur = (event: SyntheticFocusEvent<>) => {
this.setState({ focused: false });
if (this.props.onBlur) {
this.props.onBlur(event);
}
};
handleChange = (event: SyntheticInputEvent<>) => {
if (!this.isControlled()) {
this.checkDirty(this.input);
}
// Perform in the willUpdate
if (this.props.onChange) {
this.props.onChange(event);
}
};
handleRefInput = node => {
this.input = node;
if (this.props.inputRef) {
this.props.inputRef(node);
}
};
// A controlled input accepts its current value as a prop.
//
// @see https://facebook.github.io/react/docs/forms.html#controlled-components
// @returns {boolean} true if string (including '') or number (including zero)
isControlled(props = this.props) {
return hasValue(props.value);
}
checkDirty(obj) {
const { muiFormControl } = this.context;
if (isDirty(obj)) {
if (muiFormControl && muiFormControl.onDirty) {
muiFormControl.onDirty();
}
if (this.props.onDirty) {
this.props.onDirty();
}
return;
}
if (muiFormControl && muiFormControl.onClean) {
muiFormControl.onClean();
}
if (this.props.onClean) {
this.props.onClean();
}
}
render() {
const {
autoComplete,
autoFocus,
classes,
className: classNameProp,
defaultValue,
disabled: disabledProp,
disableUnderline,
endAdornment,
error: errorProp,
fullWidth,
id,
inputComponent,
inputProps: { className: inputPropsClassName, ...inputPropsProp } = {},
inputRef,
margin: marginProp,
multiline,
onBlur,
onFocus,
onChange,
onClean,
onDirty,
onKeyDown,
onKeyUp,
placeholder,
name,
readOnly,
rows,
rowsMax,
startAdornment,
type,
// $FlowFixMe
value,
...other
} = this.props;
const { muiFormControl } = this.context;
let disabled = disabledProp;
let error = errorProp;
let margin = marginProp;
if (muiFormControl) {
if (typeof disabled === 'undefined') {
disabled = muiFormControl.disabled;
}
if (typeof error === 'undefined') {
error = muiFormControl.error;
}
if (typeof margin === 'undefined') {
margin = muiFormControl.margin;
}
}
const className = classNames(
classes.root,
{
[classes.disabled]: disabled,
[classes.error]: error,
[classes.fullWidth]: fullWidth,
[classes.focused]: this.state.focused,
[classes.formControl]: muiFormControl,
[classes.inkbar]: !disableUnderline,
[classes.multiline]: multiline,
[classes.underline]: !disableUnderline,
},
classNameProp,
);
const inputClassName = classNames(
classes.input,
{
[classes.inputDisabled]: disabled,
[classes.inputSingleline]: !multiline,
[classes.inputSearch]: type === 'search',
[classes.inputMultiline]: multiline,
[classes.inputDense]: margin === 'dense',
},
inputPropsClassName,
);
const required = muiFormControl && muiFormControl.required === true;
let InputComponent = 'input';
let inputProps = {
ref: this.handleRefInput,
...inputPropsProp,
};
if (inputComponent) {
InputComponent = inputComponent;
if (isMuiComponent(InputComponent, ['SelectInput'])) {
inputProps = {
selectRef: this.handleRefInput,
...inputProps,
ref: null,
};
}
} else if (multiline) {
if (rows && !rowsMax) {
InputComponent = 'textarea';
} else {
inputProps = {
rowsMax,
textareaRef: this.handleRefInput,
...inputProps,
ref: null,
};
InputComponent = Textarea;
}
}
return (
<div onBlur={this.handleBlur} onFocus={this.handleFocus} className={className} {...other}>
{startAdornment}
<InputComponent
autoComplete={autoComplete}
autoFocus={autoFocus}
className={inputClassName}
onChange={this.handleChange}
onKeyUp={onKeyUp}
onKeyDown={onKeyDown}
disabled={disabled}
required={required ? true : undefined}
value={value}
id={id}
name={name}
defaultValue={defaultValue}
placeholder={placeholder}
type={type}
readOnly={readOnly}
rows={rows}
{...inputProps}
/>
{endAdornment}
</div>
);
}
}
Input.contextTypes = {
muiFormControl: PropTypes.object,
};
export default withStyles(styles, { name: 'MuiInput' })(Input);

View File

@@ -0,0 +1,18 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface InputAdornmentProps extends StandardProps<{}, InputAdornmentClassKey> {
component?: React.ReactType;
disableTypography?: boolean;
position: 'start' | 'end';
}
export type InputAdornmentClassKey =
| 'root'
| 'positionStart'
| 'positionEnd'
;
declare const InputAdornment: React.ComponentType<InputAdornmentProps>;
export default InputAdornment;

View File

@@ -0,0 +1,130 @@
'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 _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _Typography = require('../Typography');
var _Typography2 = _interopRequireDefault(_Typography);
var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_ElementType = require('react').babelPluginFlowReactPropTypes_proptype_ElementType || require('prop-types').any;
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var styles = exports.styles = function styles(theme) {
return {
root: {
'label + div > &': {
marginTop: -theme.spacing.unit * 2
}
},
positionStart: {
marginRight: theme.spacing.unit
},
positionEnd: {
marginLeft: theme.spacing.unit
}
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The content of the component, normally an `IconButton` or string.
*/
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,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType),
/**
* If children is a string then disable wrapping in a Typography component.
*/
disableTypography: require('prop-types').bool,
/**
* The position this adornment should appear relative to the `Input`.
*/
position: require('prop-types').oneOf(['start', 'end']).isRequired
};
function InputAdornment(props) {
var _classNames;
var children = props.children,
Component = props.component,
classes = props.classes,
className = props.className,
disableTypography = props.disableTypography,
position = props.position,
other = (0, _objectWithoutProperties3.default)(props, ['children', 'component', 'classes', 'className', 'disableTypography', 'position']);
return _react2.default.createElement(
Component,
(0, _extends3.default)({
className: (0, _classnames2.default)(classes.root, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.positionStart, position === 'start'), (0, _defineProperty3.default)(_classNames, classes.positionEnd, position === 'end'), _classNames), className)
}, other),
typeof children === 'string' && !disableTypography ? _react2.default.createElement(
_Typography2.default,
{ color: 'secondary' },
children
) : children
);
}
InputAdornment.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
component: typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType.isRequired ? babelPluginFlowReactPropTypes_proptype_ElementType.isRequired : babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType).isRequired,
disableTypography: require('prop-types').bool.isRequired,
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'component', typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType)), (0, _defineProperty3.default)(_ref, 'disableTypography', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'position', require('prop-types').oneOf(['start', 'end']).isRequired), _ref) : {};
InputAdornment.defaultProps = {
component: 'div',
disableTypography: false
};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiInputAdornment' })(InputAdornment);

View File

@@ -0,0 +1,94 @@
// @flow
import React from 'react';
import type { Node, ElementType } from 'react';
import classNames from 'classnames';
import Typography from '../Typography';
import withStyles from '../styles/withStyles';
export const styles = (theme: Object) => ({
root: {
'label + div > &': {
marginTop: -theme.spacing.unit * 2,
},
},
positionStart: {
marginRight: theme.spacing.unit,
},
positionEnd: {
marginLeft: theme.spacing.unit,
},
});
type ProvidedProps = {
classes: Object,
component: ElementType,
disableTypography: boolean,
};
export type Props = {
/**
* The content of the component, normally an `IconButton` or string.
*/
children?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component?: ElementType,
/**
* If children is a string then disable wrapping in a Typography component.
*/
disableTypography?: boolean,
/**
* The position this adornment should appear relative to the `Input`.
*/
position: 'start' | 'end',
};
function InputAdornment(props: ProvidedProps & Props) {
const {
children,
component: Component,
classes,
className,
disableTypography,
position,
...other
} = props;
return (
<Component
className={classNames(
classes.root,
{
[classes.positionStart]: position === 'start',
[classes.positionEnd]: position === 'end',
},
className,
)}
{...other}
>
{typeof children === 'string' && !disableTypography ? (
<Typography color="secondary">{children}</Typography>
) : (
children
)}
</Component>
);
}
InputAdornment.defaultProps = {
component: 'div',
disableTypography: false,
};
export default withStyles(styles, { name: 'MuiInputAdornment' })(InputAdornment);

View File

@@ -0,0 +1,27 @@
import * as React from 'react';
import { StandardProps } from '..';
import { FormLabelProps, FormLabelClassKey } from '../Form/FormLabel';
export interface InputLabelProps extends StandardProps<
FormLabelProps,
InputLabelClassKey
> {
disableAnimation?: boolean;
disabled?: boolean;
error?: boolean;
focused?: boolean;
required?: boolean;
shrink?: boolean;
}
export type InputLabelClassKey =
| FormLabelClassKey
| 'formControl'
| 'labelDense'
| 'shrink'
| 'animated'
;
declare const InputLabel: React.ComponentType<InputLabelProps>;
export default InputLabel;

View File

@@ -0,0 +1,184 @@
'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 _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
var _Form = require('../Form');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var styles = exports.styles = function styles(theme) {
return {
root: {
transformOrigin: 'top ' + (theme.direction === 'ltr' ? 'left' : 'right')
},
formControl: {
position: 'absolute',
left: 0,
top: 0,
// slight alteration to spec spacing to match visual spec result
transform: 'translate(0, ' + (theme.spacing.unit * 3 - 1) + 'px) scale(1)'
},
labelDense: {
// Compensation for the `Input.inputDense` style.
transform: 'translate(0, ' + (theme.spacing.unit * 2.5 + 1) + 'px) scale(1)'
},
shrink: {
transform: 'translate(0, 1.5px) scale(0.75)',
transformOrigin: 'top ' + (theme.direction === 'ltr' ? 'left' : 'right')
},
animated: {
transition: theme.transitions.create('transform', {
duration: theme.transitions.duration.shorter,
easing: theme.transitions.easing.easeOut
})
},
disabled: {
color: theme.palette.input.disabled
}
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The contents of the `InputLabel`.
*/
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 transition animation is disabled.
*/
disableAnimation: require('prop-types').bool,
/**
* If `true`, apply disabled class.
*/
disabled: require('prop-types').bool,
/**
* If `true`, the label will be displayed in an error state.
*/
error: require('prop-types').bool,
/**
* `classes` property applied to the `FormControl` element.
*/
FormControlClasses: require('prop-types').object,
/**
* If `true`, the input of this label is focused.
*/
focused: require('prop-types').bool,
/**
* If `dense`, will adjust vertical spacing. This is normally obtained via context from
* FormControl.
*/
margin: require('prop-types').oneOf(['dense']),
/**
* if `true`, the label will indicate that the input is required.
*/
required: require('prop-types').bool,
/**
* If `true`, the label is shrunk.
*/
shrink: require('prop-types').bool
};
function InputLabel(props, context) {
var _classNames;
var disabled = props.disabled,
disableAnimation = props.disableAnimation,
children = props.children,
classes = props.classes,
classNameProp = props.className,
FormControlClasses = props.FormControlClasses,
shrinkProp = props.shrink,
marginProp = props.margin,
other = (0, _objectWithoutProperties3.default)(props, ['disabled', 'disableAnimation', 'children', 'classes', 'className', 'FormControlClasses', 'shrink', 'margin']);
var muiFormControl = context.muiFormControl;
var shrink = shrinkProp;
if (typeof shrink === 'undefined' && muiFormControl) {
shrink = muiFormControl.dirty || muiFormControl.focused || muiFormControl.adornedStart;
}
var margin = marginProp;
if (typeof margin === 'undefined' && muiFormControl) {
margin = muiFormControl.margin;
}
var className = (0, _classnames2.default)(classes.root, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.formControl, muiFormControl), (0, _defineProperty3.default)(_classNames, classes.animated, !disableAnimation), (0, _defineProperty3.default)(_classNames, classes.shrink, shrink), (0, _defineProperty3.default)(_classNames, classes.disabled, disabled), (0, _defineProperty3.default)(_classNames, classes.labelDense, margin === 'dense'), _classNames), classNameProp);
return _react2.default.createElement(
_Form.FormLabel,
(0, _extends3.default)({ 'data-shrink': shrink, className: className, classes: FormControlClasses }, other),
children
);
}
InputLabel.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
disabled: require('prop-types').bool.isRequired,
disableAnimation: require('prop-types').bool.isRequired,
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'disableAnimation', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'disabled', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'error', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'FormControlClasses', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'focused', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'margin', require('prop-types').oneOf(['dense'])), (0, _defineProperty3.default)(_ref, 'required', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'shrink', require('prop-types').bool), _ref) : {};
InputLabel.defaultProps = {
disabled: false,
disableAnimation: false
};
InputLabel.contextTypes = {
muiFormControl: _propTypes2.default.object
};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiInputLabel' })(InputLabel);

View File

@@ -0,0 +1,147 @@
// @flow
import React from 'react';
import type { Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import { FormLabel } from '../Form';
export const styles = (theme: Object) => ({
root: {
transformOrigin: `top ${theme.direction === 'ltr' ? 'left' : 'right'}`,
},
formControl: {
position: 'absolute',
left: 0,
top: 0,
// slight alteration to spec spacing to match visual spec result
transform: `translate(0, ${theme.spacing.unit * 3 - 1}px) scale(1)`,
},
labelDense: {
// Compensation for the `Input.inputDense` style.
transform: `translate(0, ${theme.spacing.unit * 2.5 + 1}px) scale(1)`,
},
shrink: {
transform: 'translate(0, 1.5px) scale(0.75)',
transformOrigin: `top ${theme.direction === 'ltr' ? 'left' : 'right'}`,
},
animated: {
transition: theme.transitions.create('transform', {
duration: theme.transitions.duration.shorter,
easing: theme.transitions.easing.easeOut,
}),
},
disabled: {
color: theme.palette.input.disabled,
},
});
type ProvidedProps = {
classes: Object,
disabled: boolean,
disableAnimation: boolean,
};
export type Props = {
/**
* The contents of the `InputLabel`.
*/
children?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* If `true`, the transition animation is disabled.
*/
disableAnimation?: boolean,
/**
* If `true`, apply disabled class.
*/
disabled?: boolean,
/**
* If `true`, the label will be displayed in an error state.
*/
error?: boolean,
/**
* `classes` property applied to the `FormControl` element.
*/
FormControlClasses?: Object,
/**
* If `true`, the input of this label is focused.
*/
focused?: boolean,
/**
* If `dense`, will adjust vertical spacing. This is normally obtained via context from
* FormControl.
*/
margin?: 'dense',
/**
* if `true`, the label will indicate that the input is required.
*/
required?: boolean,
/**
* If `true`, the label is shrunk.
*/
shrink?: boolean,
};
function InputLabel(props: ProvidedProps & Props, context: { muiFormControl: Object }) {
const {
disabled,
disableAnimation,
children,
classes,
className: classNameProp,
FormControlClasses,
shrink: shrinkProp,
margin: marginProp,
...other
} = props;
const { muiFormControl } = context;
let shrink = shrinkProp;
if (typeof shrink === 'undefined' && muiFormControl) {
shrink = muiFormControl.dirty || muiFormControl.focused || muiFormControl.adornedStart;
}
let margin = marginProp;
if (typeof margin === 'undefined' && muiFormControl) {
margin = muiFormControl.margin;
}
const className = classNames(
classes.root,
{
[classes.formControl]: muiFormControl,
[classes.animated]: !disableAnimation,
[classes.shrink]: shrink,
[classes.disabled]: disabled,
[classes.labelDense]: margin === 'dense',
},
classNameProp,
);
return (
<FormLabel data-shrink={shrink} className={className} classes={FormControlClasses} {...other}>
{children}
</FormLabel>
);
}
InputLabel.defaultProps = {
disabled: false,
disableAnimation: false,
};
InputLabel.contextTypes = {
muiFormControl: PropTypes.object,
};
export default withStyles(styles, { name: 'MuiInputLabel' })(InputLabel);

View File

@@ -0,0 +1,25 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface TextareaProps extends StandardProps<
React.TextareaHTMLAttributes<HTMLTextAreaElement>,
TextareaClassKey,
'rows'
> {
defaultValue?: any;
disabled?: boolean;
rows?: string | number;
rowsMax?: string | number;
textareaRef?: React.Ref<any>;
value?: string;
}
export type TextareaClassKey =
| 'root'
| 'shadow'
| 'textarea'
;
declare const Textarea: React.ComponentType<TextareaProps>;
export default Textarea;

View File

@@ -0,0 +1,299 @@
'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 _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 _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _debounce = require('lodash/debounce');
var _debounce2 = _interopRequireDefault(_debounce);
var _reactEventListener = require('react-event-listener');
var _reactEventListener2 = _interopRequireDefault(_reactEventListener);
var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var rowsHeight = 24;
var styles = exports.styles = {
root: {
position: 'relative', // because the shadow has position: 'absolute',
width: '100%'
},
textarea: {
width: '100%',
height: '100%',
resize: 'none',
font: 'inherit',
padding: 0,
cursor: 'inherit',
boxSizing: 'border-box',
lineHeight: 'inherit',
border: 'none',
outline: 'none',
background: 'transparent'
},
shadow: {
resize: 'none',
// Overflow also needed to here to remove the extra row
// added to textareas in Firefox.
overflow: 'hidden',
// Visibility needed to hide the extra text area on ipads
visibility: 'hidden',
position: 'absolute',
height: 'auto',
whiteSpace: 'pre-wrap'
}
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* @ignore
*/
defaultValue: require('prop-types').oneOfType([require('prop-types').string, require('prop-types').number]),
/**
* @ignore
*/
disabled: require('prop-types').bool,
/**
* @ignore
*/
onChange: require('prop-types').func,
/**
* Number of rows to display when multiline option is set to true.
*/
rows: require('prop-types').oneOfType([require('prop-types').string, require('prop-types').number]),
/**
* Maximum number of rows to display when multiline option is set to true.
*/
rowsMax: require('prop-types').oneOfType([require('prop-types').string, require('prop-types').number]),
/**
* Use that property to pass a ref callback to the native textarea element.
*/
textareaRef: require('prop-types').func,
/**
* @ignore
*/
value: require('prop-types').oneOfType([require('prop-types').string, require('prop-types').number])
};
/**
* @ignore - internal component.
*/
var Textarea = function (_React$Component) {
(0, _inherits3.default)(Textarea, _React$Component);
function Textarea() {
var _ref;
var _temp, _this, _ret;
(0, _classCallCheck3.default)(this, Textarea);
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 = Textarea.__proto__ || (0, _getPrototypeOf2.default)(Textarea)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
height: null
}, _this.handleResize = (0, _debounce2.default)(function (event) {
_this.syncHeightWithShadow(event);
}, 166), _this.handleRefInput = function (node) {
_this.input = node;
if (_this.props.textareaRef) {
_this.props.textareaRef(node);
}
}, _this.handleRefSinglelineShadow = function (node) {
_this.singlelineShadow = node;
}, _this.handleRefShadow = function (node) {
_this.shadow = node;
}, _this.handleChange = function (event) {
_this.value = event.target.value;
if (typeof _this.props.value === 'undefined' && _this.shadow) {
// The component is not controlled, we need to update the shallow value.
_this.shadow.value = _this.value;
_this.syncHeightWithShadow(event);
}
if (_this.props.onChange) {
_this.props.onChange(event);
}
}, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
}
(0, _createClass3.default)(Textarea, [{
key: 'componentWillMount',
value: function componentWillMount() {
// <Input> expects the components it renders to respond to 'value'
// so that it can check whether they are dirty
this.value = this.props.value || this.props.defaultValue || '';
this.setState({
height: Number(this.props.rows) * rowsHeight
});
}
}, {
key: 'componentDidMount',
value: function componentDidMount() {
this.syncHeightWithShadow(null);
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
if (nextProps.value !== this.props.value || Number(nextProps.rowsMax) !== Number(this.props.rowsMax)) {
this.syncHeightWithShadow(null, nextProps);
}
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.handleResize.cancel();
}
}, {
key: 'syncHeightWithShadow',
value: function syncHeightWithShadow(event) {
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.props;
if (this.shadow && this.singlelineShadow) {
// The component is controlled, we need to update the shallow value.
if (typeof this.props.value !== 'undefined') {
this.shadow.value = props.value == null ? '' : String(props.value);
}
var lineHeight = this.singlelineShadow.scrollHeight;
var newHeight = this.shadow.scrollHeight;
// Guarding for jsdom, where scrollHeight isn't present.
// See https://github.com/tmpvar/jsdom/issues/1013
if (newHeight === undefined) {
return;
}
if (Number(props.rowsMax) >= Number(props.rows)) {
newHeight = Math.min(Number(props.rowsMax) * lineHeight, newHeight);
}
newHeight = Math.max(newHeight, lineHeight);
if (this.state.height !== newHeight) {
this.setState({
height: newHeight
});
}
}
}
}, {
key: 'render',
value: function render() {
var _props = this.props,
classes = _props.classes,
className = _props.className,
defaultValue = _props.defaultValue,
onChange = _props.onChange,
rows = _props.rows,
rowsMax = _props.rowsMax,
textareaRef = _props.textareaRef,
value = _props.value,
other = (0, _objectWithoutProperties3.default)(_props, ['classes', 'className', 'defaultValue', 'onChange', 'rows', 'rowsMax', 'textareaRef', 'value']);
return _react2.default.createElement(
'div',
{ className: classes.root, style: { height: this.state.height } },
_react2.default.createElement(_reactEventListener2.default, { target: 'window', onResize: this.handleResize }),
_react2.default.createElement('textarea', {
ref: this.handleRefSinglelineShadow,
className: (0, _classnames2.default)(classes.shadow, classes.textarea),
tabIndex: -1,
rows: '1',
readOnly: true,
'aria-hidden': 'true',
value: ''
}),
_react2.default.createElement('textarea', {
ref: this.handleRefShadow,
className: (0, _classnames2.default)(classes.shadow, classes.textarea),
tabIndex: -1,
rows: rows,
'aria-hidden': 'true',
readOnly: true,
defaultValue: defaultValue,
value: value
}),
_react2.default.createElement('textarea', (0, _extends3.default)({
rows: rows,
className: (0, _classnames2.default)(classes.textarea, className),
defaultValue: defaultValue,
value: value,
onChange: this.handleChange
}, other, {
ref: this.handleRefInput
}))
);
}
}]);
return Textarea;
}(_react2.default.Component);
Textarea.defaultProps = {
rows: 1
};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiTextarea' })(Textarea);

View File

@@ -0,0 +1,244 @@
// @flow
import React from 'react';
import classnames from 'classnames';
import debounce from 'lodash/debounce';
import EventListener from 'react-event-listener';
import withStyles from '../styles/withStyles';
const rowsHeight = 24;
export const styles = {
root: {
position: 'relative', // because the shadow has position: 'absolute',
width: '100%',
},
textarea: {
width: '100%',
height: '100%',
resize: 'none',
font: 'inherit',
padding: 0,
cursor: 'inherit',
boxSizing: 'border-box',
lineHeight: 'inherit',
border: 'none',
outline: 'none',
background: 'transparent',
},
shadow: {
resize: 'none',
// Overflow also needed to here to remove the extra row
// added to textareas in Firefox.
overflow: 'hidden',
// Visibility needed to hide the extra text area on ipads
visibility: 'hidden',
position: 'absolute',
height: 'auto',
whiteSpace: 'pre-wrap',
},
};
type ProvidedProps = {
classes: Object,
};
export type Props = {
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* @ignore
*/
defaultValue?: string | number,
/**
* @ignore
*/
disabled?: boolean,
/**
* @ignore
*/
onChange?: Function,
/**
* Number of rows to display when multiline option is set to true.
*/
rows?: string | number,
/**
* Maximum number of rows to display when multiline option is set to true.
*/
rowsMax?: string | number,
/**
* Use that property to pass a ref callback to the native textarea element.
*/
textareaRef?: Function,
/**
* @ignore
*/
value?: string | number,
};
type State = {
height: ?number,
};
/**
* @ignore - internal component.
*/
class Textarea extends React.Component<ProvidedProps & Props, State> {
static defaultProps = {
rows: 1,
};
state = {
height: null,
};
componentWillMount() {
// <Input> expects the components it renders to respond to 'value'
// so that it can check whether they are dirty
this.value = this.props.value || this.props.defaultValue || '';
this.setState({
height: Number(this.props.rows) * rowsHeight,
});
}
componentDidMount() {
this.syncHeightWithShadow(null);
}
componentWillReceiveProps(nextProps) {
if (
nextProps.value !== this.props.value ||
Number(nextProps.rowsMax) !== Number(this.props.rowsMax)
) {
this.syncHeightWithShadow(null, nextProps);
}
}
componentWillUnmount() {
this.handleResize.cancel();
}
shadow: ?HTMLInputElement;
singlelineShadow: ?HTMLInputElement;
input: ?HTMLInputElement;
value: string | number;
handleResize = debounce(event => {
this.syncHeightWithShadow(event);
}, 166);
syncHeightWithShadow(event, props = this.props) {
if (this.shadow && this.singlelineShadow) {
// The component is controlled, we need to update the shallow value.
if (typeof this.props.value !== 'undefined') {
this.shadow.value = props.value == null ? '' : String(props.value);
}
const lineHeight = this.singlelineShadow.scrollHeight;
let newHeight = this.shadow.scrollHeight;
// Guarding for jsdom, where scrollHeight isn't present.
// See https://github.com/tmpvar/jsdom/issues/1013
if (newHeight === undefined) {
return;
}
if (Number(props.rowsMax) >= Number(props.rows)) {
newHeight = Math.min(Number(props.rowsMax) * lineHeight, newHeight);
}
newHeight = Math.max(newHeight, lineHeight);
if (this.state.height !== newHeight) {
this.setState({
height: newHeight,
});
}
}
}
handleRefInput = node => {
this.input = node;
if (this.props.textareaRef) {
this.props.textareaRef(node);
}
};
handleRefSinglelineShadow = node => {
this.singlelineShadow = node;
};
handleRefShadow = node => {
this.shadow = node;
};
handleChange = (event: SyntheticInputEvent<HTMLInputElement>) => {
this.value = event.target.value;
if (typeof this.props.value === 'undefined' && this.shadow) {
// The component is not controlled, we need to update the shallow value.
this.shadow.value = this.value;
this.syncHeightWithShadow(event);
}
if (this.props.onChange) {
this.props.onChange(event);
}
};
render() {
const {
classes,
className,
defaultValue,
onChange,
rows,
rowsMax,
textareaRef,
value,
...other
} = this.props;
return (
<div className={classes.root} style={{ height: this.state.height }}>
<EventListener target="window" onResize={this.handleResize} />
<textarea
ref={this.handleRefSinglelineShadow}
className={classnames(classes.shadow, classes.textarea)}
tabIndex={-1}
rows="1"
readOnly
aria-hidden="true"
value=""
/>
<textarea
ref={this.handleRefShadow}
className={classnames(classes.shadow, classes.textarea)}
tabIndex={-1}
rows={rows}
aria-hidden="true"
readOnly
defaultValue={defaultValue}
value={value}
/>
<textarea
rows={rows}
className={classnames(classes.textarea, className)}
defaultValue={defaultValue}
value={value}
onChange={this.handleChange}
{...other}
ref={this.handleRefInput}
/>
</div>
);
}
}
export default withStyles(styles, { name: 'MuiTextarea' })(Textarea);

View File

@@ -0,0 +1,7 @@
export { default } from './Input';
export * from './Input';
export { default as InputLabel } from './InputLabel';
export * from './InputLabel';
export { default as InputAdornment } from './InputAdornment';
export * from './InputAdornment';
// NOTE: Textarea is missing from exports (intentional?)

View File

@@ -0,0 +1,34 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _Input = require('./Input');
Object.defineProperty(exports, 'default', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_Input).default;
}
});
var _InputAdornment = require('./InputAdornment');
Object.defineProperty(exports, 'InputAdornment', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_InputAdornment).default;
}
});
var _InputLabel = require('./InputLabel');
Object.defineProperty(exports, 'InputLabel', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_InputLabel).default;
}
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

View File

@@ -0,0 +1,5 @@
// @flow
export { default } from './Input';
export { default as InputAdornment } from './InputAdornment';
export { default as InputLabel } from './InputLabel';