UNPKG

7.18 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = exports.styles = void 0;
11
12var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
14var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
16var React = _interopRequireWildcard(require("react"));
17
18var _propTypes = _interopRequireDefault(require("prop-types"));
19
20var _clsx = _interopRequireDefault(require("clsx"));
21
22var _formControlState = _interopRequireDefault(require("../FormControl/formControlState"));
23
24var _useFormControl = _interopRequireDefault(require("../FormControl/useFormControl"));
25
26var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
27
28var _FormLabel = _interopRequireDefault(require("../FormLabel"));
29
30var styles = function styles(theme) {
31 return {
32 /* Styles applied to the root element. */
33 root: {
34 display: 'block',
35 transformOrigin: 'top left'
36 },
37
38 /* Pseudo-class applied to the root element if `focused={true}`. */
39 focused: {},
40
41 /* Pseudo-class applied to the root element if `disabled={true}`. */
42 disabled: {},
43
44 /* Pseudo-class applied to the root element if `error={true}`. */
45 error: {},
46
47 /* Pseudo-class applied to the root element if `required={true}`. */
48 required: {},
49
50 /* Pseudo-class applied to the asterisk element. */
51 asterisk: {},
52
53 /* Styles applied to the root element if the component is a descendant of `FormControl`. */
54 formControl: {
55 position: 'absolute',
56 left: 0,
57 top: 0,
58 // slight alteration to spec spacing to match visual spec result
59 transform: 'translate(0, 24px) scale(1)'
60 },
61
62 /* Styles applied to the root element if `margin="dense"`. */
63 marginDense: {
64 // Compensation for the `Input.inputDense` style.
65 transform: 'translate(0, 21px) scale(1)'
66 },
67
68 /* Styles applied to the `input` element if `shrink={true}`. */
69 shrink: {
70 transform: 'translate(0, 1.5px) scale(0.75)',
71 transformOrigin: 'top left'
72 },
73
74 /* Styles applied to the `input` element if `disableAnimation={false}`. */
75 animated: {
76 transition: theme.transitions.create(['color', 'transform'], {
77 duration: theme.transitions.duration.shorter,
78 easing: theme.transitions.easing.easeOut
79 })
80 },
81
82 /* Styles applied to the root element if `variant="filled"`. */
83 filled: {
84 // Chrome's autofill feature gives the input field a yellow background.
85 // Since the input field is behind the label in the HTML tree,
86 // the input field is drawn last and hides the label with an opaque background color.
87 // zIndex: 1 will raise the label above opaque background-colors of input.
88 zIndex: 1,
89 pointerEvents: 'none',
90 transform: 'translate(12px, 20px) scale(1)',
91 '&$marginDense': {
92 transform: 'translate(12px, 17px) scale(1)'
93 },
94 '&$shrink': {
95 transform: 'translate(12px, 10px) scale(0.75)',
96 '&$marginDense': {
97 transform: 'translate(12px, 7px) scale(0.75)'
98 }
99 }
100 },
101
102 /* Styles applied to the root element if `variant="outlined"`. */
103 outlined: {
104 // see comment above on filled.zIndex
105 zIndex: 1,
106 pointerEvents: 'none',
107 transform: 'translate(14px, 20px) scale(1)',
108 '&$marginDense': {
109 transform: 'translate(14px, 12px) scale(1)'
110 },
111 '&$shrink': {
112 transform: 'translate(14px, -6px) scale(0.75)'
113 }
114 }
115 };
116};
117
118exports.styles = styles;
119var InputLabel = /*#__PURE__*/React.forwardRef(function InputLabel(props, ref) {
120 var classes = props.classes,
121 className = props.className,
122 _props$disableAnimati = props.disableAnimation,
123 disableAnimation = _props$disableAnimati === void 0 ? false : _props$disableAnimati,
124 margin = props.margin,
125 shrinkProp = props.shrink,
126 variant = props.variant,
127 other = (0, _objectWithoutProperties2.default)(props, ["classes", "className", "disableAnimation", "margin", "shrink", "variant"]);
128 var muiFormControl = (0, _useFormControl.default)();
129 var shrink = shrinkProp;
130
131 if (typeof shrink === 'undefined' && muiFormControl) {
132 shrink = muiFormControl.filled || muiFormControl.focused || muiFormControl.adornedStart;
133 }
134
135 var fcs = (0, _formControlState.default)({
136 props: props,
137 muiFormControl: muiFormControl,
138 states: ['margin', 'variant']
139 });
140 return /*#__PURE__*/React.createElement(_FormLabel.default, (0, _extends2.default)({
141 "data-shrink": shrink,
142 className: (0, _clsx.default)(classes.root, className, muiFormControl && classes.formControl, !disableAnimation && classes.animated, shrink && classes.shrink, fcs.margin === 'dense' && classes.marginDense, {
143 'filled': classes.filled,
144 'outlined': classes.outlined
145 }[fcs.variant]),
146 classes: {
147 focused: classes.focused,
148 disabled: classes.disabled,
149 error: classes.error,
150 required: classes.required,
151 asterisk: classes.asterisk
152 },
153 ref: ref
154 }, other));
155});
156process.env.NODE_ENV !== "production" ? InputLabel.propTypes = {
157 // ----------------------------- Warning --------------------------------
158 // | These PropTypes are generated from the TypeScript type definitions |
159 // | To update them edit the d.ts file and run "yarn proptypes" |
160 // ----------------------------------------------------------------------
161
162 /**
163 * The contents of the `InputLabel`.
164 */
165 children: _propTypes.default.node,
166
167 /**
168 * Override or extend the styles applied to the component.
169 * See [CSS API](#css) below for more details.
170 */
171 classes: _propTypes.default.object,
172
173 /**
174 * @ignore
175 */
176 className: _propTypes.default.string,
177
178 /**
179 * The color of the component. It supports those theme colors that make sense for this component.
180 */
181 color: _propTypes.default.oneOf(['primary', 'secondary']),
182
183 /**
184 * If `true`, the transition animation is disabled.
185 */
186 disableAnimation: _propTypes.default.bool,
187
188 /**
189 * If `true`, apply disabled class.
190 */
191 disabled: _propTypes.default.bool,
192
193 /**
194 * If `true`, the label will be displayed in an error state.
195 */
196 error: _propTypes.default.bool,
197
198 /**
199 * If `true`, the input of this label is focused.
200 */
201 focused: _propTypes.default.bool,
202
203 /**
204 * If `dense`, will adjust vertical spacing. This is normally obtained via context from
205 * FormControl.
206 */
207 margin: _propTypes.default.oneOf(['dense']),
208
209 /**
210 * if `true`, the label will indicate that the input is required.
211 */
212 required: _propTypes.default.bool,
213
214 /**
215 * If `true`, the label is shrunk.
216 */
217 shrink: _propTypes.default.bool,
218
219 /**
220 * The variant to use.
221 */
222 variant: _propTypes.default.oneOf(['filled', 'outlined', 'standard'])
223} : void 0;
224
225var _default = (0, _withStyles.default)(styles, {
226 name: 'MuiInputLabel'
227})(InputLabel);
228
229exports.default = _default;
\No newline at end of file