1 | "use strict";
|
2 |
|
3 | var _typeof = require("@babel/runtime/helpers/typeof");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.useHint = exports["default"] = void 0;
|
9 |
|
10 | var _react = _interopRequireWildcard(require("react"));
|
11 |
|
12 | var _Context = require("../../core/Context");
|
13 |
|
14 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
15 |
|
16 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
17 |
|
18 |
|
19 |
|
20 | function interpolateStyle(styles, attr) {
|
21 | var subattr = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
22 |
|
23 |
|
24 | if (subattr) {
|
25 |
|
26 | subattr = subattr.replace(subattr[0], subattr[0].toUpperCase());
|
27 | }
|
28 |
|
29 | return ['Top', 'Right', 'Bottom', 'Left'].map(function (dir) {
|
30 | return styles["".concat(attr).concat(dir).concat(subattr)];
|
31 | }).join(' ');
|
32 | }
|
33 |
|
34 | function copyStyles(inputNode, hintNode) {
|
35 | var inputStyle = window.getComputedStyle(inputNode);
|
36 |
|
37 |
|
38 | hintNode.style.borderStyle = interpolateStyle(inputStyle, 'border', 'style');
|
39 | hintNode.style.borderWidth = interpolateStyle(inputStyle, 'border', 'width');
|
40 | hintNode.style.fontSize = inputStyle.fontSize;
|
41 | hintNode.style.fontWeight = inputStyle.fontWeight;
|
42 | hintNode.style.height = inputStyle.height;
|
43 | hintNode.style.lineHeight = inputStyle.lineHeight;
|
44 | hintNode.style.margin = interpolateStyle(inputStyle, 'margin');
|
45 | hintNode.style.padding = interpolateStyle(inputStyle, 'padding');
|
46 |
|
47 | }
|
48 |
|
49 | var useHint = function useHint() {
|
50 | var _useTypeaheadContext = (0, _Context.useTypeaheadContext)(),
|
51 | hintText = _useTypeaheadContext.hintText,
|
52 | inputNode = _useTypeaheadContext.inputNode;
|
53 |
|
54 | var hintRef = (0, _react.useRef)(null);
|
55 | (0, _react.useEffect)(function () {
|
56 | if (inputNode && hintRef.current) {
|
57 | copyStyles(inputNode, hintRef.current);
|
58 | }
|
59 | });
|
60 | return {
|
61 | hintRef: hintRef,
|
62 | hintText: hintText
|
63 | };
|
64 | };
|
65 |
|
66 | exports.useHint = useHint;
|
67 |
|
68 | var Hint = function Hint(_ref) {
|
69 | var children = _ref.children,
|
70 | className = _ref.className;
|
71 |
|
72 | var _useHint = useHint(),
|
73 | hintRef = _useHint.hintRef,
|
74 | hintText = _useHint.hintText;
|
75 |
|
76 | return _react["default"].createElement("div", {
|
77 | className: className,
|
78 | style: {
|
79 | display: 'flex',
|
80 | flex: 1,
|
81 | height: '100%',
|
82 | position: 'relative'
|
83 | }
|
84 | }, children, _react["default"].createElement("input", {
|
85 | "aria-hidden": true,
|
86 | className: "rbt-input-hint",
|
87 | ref: hintRef,
|
88 | readOnly: true,
|
89 | style: {
|
90 | backgroundColor: 'transparent',
|
91 | borderColor: 'transparent',
|
92 | boxShadow: 'none',
|
93 | color: 'rgba(0, 0, 0, 0.54)',
|
94 | left: 0,
|
95 | pointerEvents: 'none',
|
96 | position: 'absolute',
|
97 | top: 0,
|
98 | width: '100%'
|
99 | },
|
100 | tabIndex: -1,
|
101 | value: hintText
|
102 | }));
|
103 | };
|
104 |
|
105 | var _default = Hint;
|
106 | exports["default"] = _default; |
\ | No newline at end of file |