0.2.0 - Mid migration

This commit is contained in:
Daniel Mason 2022-04-25 14:47:15 +12:00
parent 139e6a915e
commit 7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions

View file

@ -0,0 +1,66 @@
import * as React from 'react';
import { StandardProps } from '..';
import { InputProps } from '../Input';
import { NativeSelectInputProps } from './NativeSelectInput';
export interface NativeSelectProps
extends StandardProps<InputProps, NativeSelectClassKey, 'inputProps' | 'value' | 'onChange'> {
/**
* The option elements to populate the select with.
* Can be some `<option>` elements.
*/
children?: React.ReactNode;
/**
* The icon that displays the arrow.
*/
IconComponent?: React.ElementType;
/**
* An `Input` element; does not have to be a material-ui specific `Input`.
*/
input?: React.ReactElement<any, any>;
/**
* Attributes applied to the `select` element.
*/
inputProps?: NativeSelectInputProps;
/**
* Callback function fired when a menu item is selected.
*
* @param {object} event The event source of the callback.
* You can pull out the new value by accessing `event.target.value` (string).
* @document
*/
onChange?: NativeSelectInputProps['onChange'];
/**
* The input value. The DOM API casts this to a string.
* @document
*/
value?: unknown;
/**
* The variant to use.
*/
variant?: 'standard' | 'outlined' | 'filled';
}
export type NativeSelectClassKey =
| 'root'
| 'select'
| 'filled'
| 'outlined'
| 'selectMenu'
| 'disabled'
| 'icon'
| 'iconFilled'
| 'iconOutlined';
/**
* An alternative to `<Select native />` with a much smaller bundle size footprint.
* Demos:
*
* - [Selects](https://material-ui.com/components/selects/)
*
* API:
*
* - [NativeSelect API](https://material-ui.com/api/native-select/)
* - inherits [Input API](https://material-ui.com/api/input/)
*/
export default function NativeSelect(props: NativeSelectProps): JSX.Element;

View file

@ -0,0 +1,240 @@
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.styles = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _NativeSelectInput = _interopRequireDefault(require("./NativeSelectInput"));
var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
var _formControlState = _interopRequireDefault(require("../FormControl/formControlState"));
var _useFormControl = _interopRequireDefault(require("../FormControl/useFormControl"));
var _ArrowDropDown = _interopRequireDefault(require("../internal/svg-icons/ArrowDropDown"));
var _Input = _interopRequireDefault(require("../Input"));
var styles = function styles(theme) {
return {
/* Styles applied to the select component `root` class. */
root: {},
/* Styles applied to the select component `select` class. */
select: {
'-moz-appearance': 'none',
// Reset
'-webkit-appearance': 'none',
// Reset
// When interacting quickly, the text can end up selected.
// Native select can't be selected either.
userSelect: 'none',
borderRadius: 0,
// Reset
minWidth: 16,
// So it doesn't collapse.
cursor: 'pointer',
'&:focus': {
// Show that it's not an text input
backgroundColor: theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.05)' : 'rgba(255, 255, 255, 0.05)',
borderRadius: 0 // Reset Chrome style
},
// Remove IE 11 arrow
'&::-ms-expand': {
display: 'none'
},
'&$disabled': {
cursor: 'default'
},
'&[multiple]': {
height: 'auto'
},
'&:not([multiple]) option, &:not([multiple]) optgroup': {
backgroundColor: theme.palette.background.paper
},
'&&': {
paddingRight: 24
}
},
/* Styles applied to the select component if `variant="filled"`. */
filled: {
'&&': {
paddingRight: 32
}
},
/* Styles applied to the select component if `variant="outlined"`. */
outlined: {
borderRadius: theme.shape.borderRadius,
'&&': {
paddingRight: 32
}
},
/* Styles applied to the select component `selectMenu` class. */
selectMenu: {
height: 'auto',
// Resets for multpile select with chips
minHeight: '1.1876em',
// Required for select\text-field height consistency
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
overflow: 'hidden'
},
/* Pseudo-class applied to the select component `disabled` class. */
disabled: {},
/* Styles applied to the icon component. */
icon: {
// We use a position absolute over a flexbox in order to forward the pointer events
// to the input and to support wrapping tags..
position: 'absolute',
right: 0,
top: 'calc(50% - 12px)',
// Center vertically
pointerEvents: 'none',
// Don't block pointer events on the select under the icon.
color: theme.palette.action.active,
'&$disabled': {
color: theme.palette.action.disabled
}
},
/* Styles applied to the icon component if the popup is open. */
iconOpen: {
transform: 'rotate(180deg)'
},
/* Styles applied to the icon component if `variant="filled"`. */
iconFilled: {
right: 7
},
/* Styles applied to the icon component if `variant="outlined"`. */
iconOutlined: {
right: 7
},
/* Styles applied to the underlying native input component. */
nativeInput: {
bottom: 0,
left: 0,
position: 'absolute',
opacity: 0,
pointerEvents: 'none',
width: '100%'
}
};
};
exports.styles = styles;
var defaultInput = /*#__PURE__*/React.createElement(_Input.default, null);
/**
* An alternative to `<Select native />` with a much smaller bundle size footprint.
*/
var NativeSelect = /*#__PURE__*/React.forwardRef(function NativeSelect(props, ref) {
var children = props.children,
classes = props.classes,
_props$IconComponent = props.IconComponent,
IconComponent = _props$IconComponent === void 0 ? _ArrowDropDown.default : _props$IconComponent,
_props$input = props.input,
input = _props$input === void 0 ? defaultInput : _props$input,
inputProps = props.inputProps,
variant = props.variant,
other = (0, _objectWithoutProperties2.default)(props, ["children", "classes", "IconComponent", "input", "inputProps", "variant"]);
var muiFormControl = (0, _useFormControl.default)();
var fcs = (0, _formControlState.default)({
props: props,
muiFormControl: muiFormControl,
states: ['variant']
});
return /*#__PURE__*/React.cloneElement(input, (0, _extends2.default)({
// Most of the logic is implemented in `NativeSelectInput`.
// The `Select` component is a simple API wrapper to expose something better to play with.
inputComponent: _NativeSelectInput.default,
inputProps: (0, _extends2.default)({
children: children,
classes: classes,
IconComponent: IconComponent,
variant: fcs.variant,
type: undefined
}, inputProps, input ? input.props.inputProps : {}),
ref: ref
}, other));
});
process.env.NODE_ENV !== "production" ? NativeSelect.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the d.ts file and run "yarn proptypes" |
// ----------------------------------------------------------------------
/**
* The option elements to populate the select with.
* Can be some `<option>` elements.
*/
children: _propTypes.default.node,
/**
* Override or extend the styles applied to the component.
* See [CSS API](#css) below for more details.
*/
classes: _propTypes.default.object,
/**
* The icon that displays the arrow.
*/
IconComponent: _propTypes.default.elementType,
/**
* An `Input` element; does not have to be a material-ui specific `Input`.
*/
input: _propTypes.default.element,
/**
* Attributes applied to the `select` element.
*/
inputProps: _propTypes.default.object,
/**
* Callback function fired when a menu item is selected.
*
* @param {object} event The event source of the callback.
* You can pull out the new value by accessing `event.target.value` (string).
*/
onChange: _propTypes.default.func,
/**
* The input value. The DOM API casts this to a string.
*/
value: _propTypes.default.any,
/**
* The variant to use.
*/
variant: _propTypes.default.oneOf(['filled', 'outlined', 'standard'])
} : void 0;
NativeSelect.muiName = 'Select';
var _default = (0, _withStyles.default)(styles, {
name: 'MuiNativeSelect'
})(NativeSelect);
exports.default = _default;

View file

@ -0,0 +1,12 @@
import * as React from 'react';
export interface NativeSelectInputProps extends React.SelectHTMLAttributes<HTMLSelectElement> {
disabled?: boolean;
IconComponent?: React.ElementType;
inputRef?: React.Ref<HTMLSelectElement>;
variant?: 'standard' | 'outlined' | 'filled';
}
declare const NativeSelectInput: React.ComponentType<NativeSelectInputProps>;
export default NativeSelectInput;

View file

@ -0,0 +1,110 @@
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _clsx = _interopRequireDefault(require("clsx"));
var _utils = require("@material-ui/utils");
var _capitalize = _interopRequireDefault(require("../utils/capitalize"));
/**
* @ignore - internal component.
*/
var NativeSelectInput = /*#__PURE__*/React.forwardRef(function NativeSelectInput(props, ref) {
var classes = props.classes,
className = props.className,
disabled = props.disabled,
IconComponent = props.IconComponent,
inputRef = props.inputRef,
_props$variant = props.variant,
variant = _props$variant === void 0 ? 'standard' : _props$variant,
other = (0, _objectWithoutProperties2.default)(props, ["classes", "className", "disabled", "IconComponent", "inputRef", "variant"]);
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("select", (0, _extends2.default)({
className: (0, _clsx.default)(classes.root, // TODO v5: merge root and select
classes.select, classes[variant], className, disabled && classes.disabled),
disabled: disabled,
ref: inputRef || ref
}, other)), props.multiple ? null : /*#__PURE__*/React.createElement(IconComponent, {
className: (0, _clsx.default)(classes.icon, classes["icon".concat((0, _capitalize.default)(variant))], disabled && classes.disabled)
}));
});
process.env.NODE_ENV !== "production" ? NativeSelectInput.propTypes = {
/**
* The option elements to populate the select with.
* Can be some `<option>` elements.
*/
children: _propTypes.default.node,
/**
* Override or extend the styles applied to the component.
* See [CSS API](#css) below for more details.
*/
classes: _propTypes.default.object.isRequired,
/**
* The CSS class name of the select element.
*/
className: _propTypes.default.string,
/**
* If `true`, the select will be disabled.
*/
disabled: _propTypes.default.bool,
/**
* The icon that displays the arrow.
*/
IconComponent: _propTypes.default.elementType.isRequired,
/**
* Use that prop to pass a ref to the native select element.
* @deprecated
*/
inputRef: _utils.refType,
/**
* @ignore
*/
multiple: _propTypes.default.bool,
/**
* Name attribute of the `select` or hidden `input` element.
*/
name: _propTypes.default.string,
/**
* Callback function fired when a menu item is selected.
*
* @param {object} event The event source of the callback.
* You can pull out the new value by accessing `event.target.value` (string).
*/
onChange: _propTypes.default.func,
/**
* The input value.
*/
value: _propTypes.default.any,
/**
* The variant to use.
*/
variant: _propTypes.default.oneOf(['standard', 'outlined', 'filled'])
} : void 0;
var _default = NativeSelectInput;
exports.default = _default;

View file

@ -0,0 +1,2 @@
export { default } from './NativeSelect';
export * from './NativeSelect';

View file

@ -0,0 +1,15 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function get() {
return _NativeSelect.default;
}
});
var _NativeSelect = _interopRequireDefault(require("./NativeSelect"));

View file

@ -0,0 +1,5 @@
{
"sideEffects": false,
"module": "../esm/NativeSelect/index.js",
"typings": "./index.d.ts"
}