UNPKG

5.46 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 _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
14var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
15
16var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
17
18var React = _interopRequireWildcard(require("react"));
19
20var _propTypes = _interopRequireDefault(require("prop-types"));
21
22var _clsx = _interopRequireDefault(require("clsx"));
23
24var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
25
26var _useTheme = _interopRequireDefault(require("../styles/useTheme"));
27
28var _capitalize = _interopRequireDefault(require("../utils/capitalize"));
29
30var styles = function styles(theme) {
31 return {
32 /* Styles applied to the root element. */
33 root: {
34 position: 'absolute',
35 bottom: 0,
36 right: 0,
37 top: -5,
38 left: 0,
39 margin: 0,
40 padding: '0 8px',
41 pointerEvents: 'none',
42 borderRadius: 'inherit',
43 borderStyle: 'solid',
44 borderWidth: 1,
45 overflow: 'hidden'
46 },
47
48 /* Styles applied to the legend element when `labelWidth` is provided. */
49 legend: {
50 textAlign: 'left',
51 padding: 0,
52 lineHeight: '11px',
53 // sync with `height` in `legend` styles
54 transition: theme.transitions.create('width', {
55 duration: 150,
56 easing: theme.transitions.easing.easeOut
57 })
58 },
59
60 /* Styles applied to the legend element. */
61 legendLabelled: {
62 display: 'block',
63 width: 'auto',
64 textAlign: 'left',
65 padding: 0,
66 height: 11,
67 // sync with `lineHeight` in `legend` styles
68 fontSize: '0.75em',
69 visibility: 'hidden',
70 maxWidth: 0.01,
71 transition: theme.transitions.create('max-width', {
72 duration: 50,
73 easing: theme.transitions.easing.easeOut
74 }),
75 '& > span': {
76 paddingLeft: 5,
77 paddingRight: 5,
78 display: 'inline-block'
79 }
80 },
81
82 /* Styles applied to the legend element is notched. */
83 legendNotched: {
84 maxWidth: 1000,
85 transition: theme.transitions.create('max-width', {
86 duration: 100,
87 easing: theme.transitions.easing.easeOut,
88 delay: 50
89 })
90 }
91 };
92};
93/**
94 * @ignore - internal component.
95 */
96
97
98exports.styles = styles;
99var NotchedOutline = /*#__PURE__*/React.forwardRef(function NotchedOutline(props, ref) {
100 var children = props.children,
101 classes = props.classes,
102 className = props.className,
103 label = props.label,
104 labelWidthProp = props.labelWidth,
105 notched = props.notched,
106 style = props.style,
107 other = (0, _objectWithoutProperties2.default)(props, ["children", "classes", "className", "label", "labelWidth", "notched", "style"]);
108 var theme = (0, _useTheme.default)();
109 var align = theme.direction === 'rtl' ? 'right' : 'left';
110
111 if (label !== undefined) {
112 return /*#__PURE__*/React.createElement("fieldset", (0, _extends3.default)({
113 "aria-hidden": true,
114 className: (0, _clsx.default)(classes.root, className),
115 ref: ref,
116 style: style
117 }, other), /*#__PURE__*/React.createElement("legend", {
118 className: (0, _clsx.default)(classes.legendLabelled, notched && classes.legendNotched)
119 }, label ? /*#__PURE__*/React.createElement("span", null, label) : /*#__PURE__*/React.createElement("span", {
120 dangerouslySetInnerHTML: {
121 __html: '​'
122 }
123 })));
124 }
125
126 var labelWidth = labelWidthProp > 0 ? labelWidthProp * 0.75 + 8 : 0.01;
127 return /*#__PURE__*/React.createElement("fieldset", (0, _extends3.default)({
128 "aria-hidden": true,
129 style: (0, _extends3.default)((0, _defineProperty2.default)({}, "padding".concat((0, _capitalize.default)(align)), 8), style),
130 className: (0, _clsx.default)(classes.root, className),
131 ref: ref
132 }, other), /*#__PURE__*/React.createElement("legend", {
133 className: classes.legend,
134 style: {
135 // IE 11: fieldset with legend does not render
136 // a border radius. This maintains consistency
137 // by always having a legend rendered
138 width: notched ? labelWidth : 0.01
139 }
140 }, /*#__PURE__*/React.createElement("span", {
141 dangerouslySetInnerHTML: {
142 __html: '​'
143 }
144 })));
145});
146process.env.NODE_ENV !== "production" ? NotchedOutline.propTypes = {
147 /**
148 * The content of the component.
149 */
150 children: _propTypes.default.node,
151
152 /**
153 * Override or extend the styles applied to the component.
154 * See [CSS API](#css) below for more details.
155 */
156 classes: _propTypes.default.object,
157
158 /**
159 * @ignore
160 */
161 className: _propTypes.default.string,
162
163 /**
164 * The label.
165 */
166 label: _propTypes.default.node,
167
168 /**
169 * The width of the label.
170 */
171 labelWidth: _propTypes.default.number.isRequired,
172
173 /**
174 * If `true`, the outline is notched to accommodate the label.
175 */
176 notched: _propTypes.default.bool.isRequired,
177
178 /**
179 * @ignore
180 */
181 style: _propTypes.default.object
182} : void 0;
183
184var _default = (0, _withStyles.default)(styles, {
185 name: 'PrivateNotchedOutline'
186})(NotchedOutline);
187
188exports.default = _default;
\No newline at end of file