1 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
2 | import _extends from "@babel/runtime/helpers/esm/extends";
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import formControlState from '../FormControl/formControlState';
|
7 | import useFormControl from '../FormControl/useFormControl';
|
8 | import capitalize from '../utils/capitalize';
|
9 | import withStyles from '../styles/withStyles';
|
10 | export const styles = theme => ({
|
11 |
|
12 | root: _extends({
|
13 | color: theme.palette.text.secondary
|
14 | }, theme.typography.body1, {
|
15 | lineHeight: 1,
|
16 | padding: 0,
|
17 | '&$focused': {
|
18 | color: theme.palette.primary.main
|
19 | },
|
20 | '&$disabled': {
|
21 | color: theme.palette.text.disabled
|
22 | },
|
23 | '&$error': {
|
24 | color: theme.palette.error.main
|
25 | }
|
26 | }),
|
27 |
|
28 |
|
29 | colorSecondary: {
|
30 | '&$focused': {
|
31 | color: theme.palette.secondary.main
|
32 | }
|
33 | },
|
34 |
|
35 |
|
36 | focused: {},
|
37 |
|
38 |
|
39 | disabled: {},
|
40 |
|
41 |
|
42 | error: {},
|
43 |
|
44 |
|
45 | filled: {},
|
46 |
|
47 |
|
48 | required: {},
|
49 |
|
50 |
|
51 | asterisk: {
|
52 | '&$error': {
|
53 | color: theme.palette.error.main
|
54 | }
|
55 | }
|
56 | });
|
57 | const FormLabel = React.forwardRef(function FormLabel(props, ref) {
|
58 | const {
|
59 | children,
|
60 | classes,
|
61 | className,
|
62 | component: Component = 'label'
|
63 | } = props,
|
64 | other = _objectWithoutPropertiesLoose(props, ["children", "classes", "className", "color", "component", "disabled", "error", "filled", "focused", "required"]);
|
65 |
|
66 | const muiFormControl = useFormControl();
|
67 | const fcs = formControlState({
|
68 | props,
|
69 | muiFormControl,
|
70 | states: ['color', 'required', 'focused', 'disabled', 'error', 'filled']
|
71 | });
|
72 | return React.createElement(Component, _extends({
|
73 | className: clsx(classes.root, classes[`color${capitalize(fcs.color || 'primary')}`], className, fcs.disabled && classes.disabled, fcs.error && classes.error, fcs.filled && classes.filled, fcs.focused && classes.focused, fcs.required && classes.required),
|
74 | ref: ref
|
75 | }, other), children, fcs.required && React.createElement("span", {
|
76 | "aria-hidden": true,
|
77 | className: clsx(classes.asterisk, fcs.error && classes.error)
|
78 | }, "\u2009", '*'));
|
79 | });
|
80 | process.env.NODE_ENV !== "production" ? FormLabel.propTypes = {
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | |
87 |
|
88 |
|
89 | children: PropTypes.node,
|
90 |
|
91 | |
92 |
|
93 |
|
94 |
|
95 | classes: PropTypes.object,
|
96 |
|
97 | |
98 |
|
99 |
|
100 | className: PropTypes.string,
|
101 |
|
102 | |
103 |
|
104 |
|
105 | color: PropTypes.oneOf(['primary', 'secondary']),
|
106 |
|
107 | |
108 |
|
109 |
|
110 |
|
111 | component: PropTypes
|
112 |
|
113 | .elementType,
|
114 |
|
115 | |
116 |
|
117 |
|
118 | disabled: PropTypes.bool,
|
119 |
|
120 | |
121 |
|
122 |
|
123 | error: PropTypes.bool,
|
124 |
|
125 | |
126 |
|
127 |
|
128 | filled: PropTypes.bool,
|
129 |
|
130 | |
131 |
|
132 |
|
133 | focused: PropTypes.bool,
|
134 |
|
135 | |
136 |
|
137 |
|
138 | required: PropTypes.bool
|
139 | } : void 0;
|
140 | export default withStyles(styles, {
|
141 | name: 'MuiFormLabel'
|
142 | })(FormLabel); |
\ | No newline at end of file |