@flodesk/grain 6.3.0 → 6.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/components/text-input.js +12 -20
- package/es/hooks/index.js +2 -1
- package/es/hooks/useWidth.js +37 -0
- package/package.json +1 -1
|
@@ -43,6 +43,7 @@ import { IconButton } from './icon-button';
|
|
|
43
43
|
import { componentVars, FieldLabel, InputField } from '../foundational';
|
|
44
44
|
import { types } from '../types';
|
|
45
45
|
import { IconHide, IconShow } from '../icons';
|
|
46
|
+
import { useWidth } from '../hooks';
|
|
46
47
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
47
48
|
var iconOffsetPx = 12;
|
|
48
49
|
var iconTextGapPx = 8;
|
|
@@ -52,22 +53,22 @@ var IconSection = /*#__PURE__*/_styled("div", process.env.NODE_ENV === "producti
|
|
|
52
53
|
} : {
|
|
53
54
|
target: "e1o9e51y0",
|
|
54
55
|
label: "IconSection"
|
|
55
|
-
})("position:absolute;margin:auto;left:", iconOffsetPx, "px;top:0;bottom:0;height:fit-content;pointer-events:none;" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
56
|
+
})("position:absolute;margin:auto;left:", iconOffsetPx, "px;top:0;bottom:0;height:fit-content;pointer-events:none;" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb21wb25lbnRzL3RleHQtaW5wdXQuanN4Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQWM4QiIsImZpbGUiOiIuLi8uLi9zcmMvY29tcG9uZW50cy90ZXh0LWlucHV0LmpzeCIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBQcm9wVHlwZXMgZnJvbSAncHJvcC10eXBlcyc7XG5pbXBvcnQgUmVhY3QgZnJvbSAncmVhY3QnO1xuaW1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xuICAgICAgPC9Cb3g+XG4gICAgICB7ZXJyb3JNZXNzYWdlICYmIChcbiAgICAgICAgPEJveCBtYXJnaW5Ub3A9ezAuNX0+XG4gICAgICAgICAgPFRleHQgY29sb3I9XCJkYW5nZXJcIj57ZXJyb3JNZXNzYWdlfTwvVGV4dD5cbiAgICAgICAgPC9Cb3g+XG4gICAgICApfVxuICAgIDwvZGl2PlxuICApO1xufTtcblxuVGV4dElucHV0LnByb3BUeXBlcyA9IHtcbiAgaWQ6IFByb3BUeXBlcy5zdHJpbmcuaXNSZXF1aXJlZCxcbiAgcGxhY2Vob2xkZXI6IFByb3BUeXBlcy5zdHJpbmcsXG4gIHZhbHVlOiBQcm9wVHlwZXMuc3RyaW5nLFxuICBsYWJlbDogdHlwZXMubGFiZWwsXG4gIGljb246IFByb3BUeXBlcy5ub2RlLFxuICBoYXNFcnJvcjogUHJvcFR5cGVzLmJvb2wsXG4gIGVycm9yTWVzc2FnZTogUHJvcFR5cGVzLnN0cmluZyxcbiAgaXNEaXNhYmxlZDogUHJvcFR5cGVzLmJvb2wsXG4gIHR5cGU6IHR5cGVzLnRleHRJbnB1dCxcbn07XG4iXX0= */"));
|
|
56
57
|
|
|
57
|
-
var
|
|
58
|
+
var VisibilityButton = function VisibilityButton(_ref) {
|
|
58
59
|
var children = _ref.children,
|
|
59
60
|
internalType = _ref.internalType,
|
|
60
61
|
setInternalType = _ref.setInternalType,
|
|
61
62
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
62
63
|
|
|
63
|
-
var
|
|
64
|
+
var rightOffset = "calc((".concat(componentVars.textBoxHeight, " - ").concat(componentVars.clearButtonHeight, ") / 2)");
|
|
64
65
|
var typeAndIconMap = {
|
|
65
66
|
password: ___EmotionJSX(IconShow, null),
|
|
66
67
|
text: ___EmotionJSX(IconHide, null)
|
|
67
68
|
};
|
|
68
69
|
return ___EmotionJSX(Box, {
|
|
69
70
|
position: "absolute",
|
|
70
|
-
right:
|
|
71
|
+
right: rightOffset,
|
|
71
72
|
top: "0",
|
|
72
73
|
bottom: "0",
|
|
73
74
|
margin: "auto",
|
|
@@ -95,24 +96,15 @@ export var TextInput = function TextInput(_ref2) {
|
|
|
95
96
|
|
|
96
97
|
var iconRef = React.useRef(null);
|
|
97
98
|
|
|
98
|
-
var _React$useState = React.useState(),
|
|
99
|
+
var _React$useState = React.useState(type),
|
|
99
100
|
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
internalType = _React$useState2[0],
|
|
102
|
+
setInternalType = _React$useState2[1];
|
|
102
103
|
|
|
103
|
-
var
|
|
104
|
-
|
|
105
|
-
internalType = _React$useState4[0],
|
|
106
|
-
setInternalType = _React$useState4[1];
|
|
107
|
-
|
|
108
|
-
React.useEffect(function () {
|
|
109
|
-
if (iconRef.current) {
|
|
110
|
-
setIconWidth(iconRef.current.getBoundingClientRect().width);
|
|
111
|
-
}
|
|
112
|
-
}, []);
|
|
113
|
-
var hasShowButton = type === 'password';
|
|
104
|
+
var iconWidth = useWidth(iconRef);
|
|
105
|
+
var hasVisibilityButton = type === 'password';
|
|
114
106
|
var paddingLeft = icon ? "".concat(iconOffsetPx + iconWidth + iconTextGapPx, "px") : undefined;
|
|
115
|
-
var paddingRight =
|
|
107
|
+
var paddingRight = hasVisibilityButton ? componentVars.textBoxHeight : undefined;
|
|
116
108
|
return ___EmotionJSX("div", null, label && ___EmotionJSX(FieldLabel, {
|
|
117
109
|
htmlFor: id
|
|
118
110
|
}, label), ___EmotionJSX(Box, {
|
|
@@ -129,7 +121,7 @@ export var TextInput = function TextInput(_ref2) {
|
|
|
129
121
|
paddingRight: paddingRight,
|
|
130
122
|
hasError: hasError,
|
|
131
123
|
isDisabled: isDisabled
|
|
132
|
-
}, props)),
|
|
124
|
+
}, props)), hasVisibilityButton && ___EmotionJSX(VisibilityButton, {
|
|
133
125
|
setInternalType: setInternalType,
|
|
134
126
|
internalType: internalType
|
|
135
127
|
})), errorMessage && ___EmotionJSX(Box, {
|
package/es/hooks/index.js
CHANGED
|
@@ -2,4 +2,5 @@ export { useMedia } from './useMedia';
|
|
|
2
2
|
export { useKeyPress } from './useKeyPress';
|
|
3
3
|
export { useOnClickOutside } from './useOnClickOutside';
|
|
4
4
|
export { useWindowSize } from './useWindowSize';
|
|
5
|
-
export { useHasOverflow } from './useHasOverflow';
|
|
5
|
+
export { useHasOverflow } from './useHasOverflow';
|
|
6
|
+
export { useWidth } from './useWidth';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import "core-js/modules/es.symbol.js";
|
|
2
|
+
import "core-js/modules/es.symbol.description.js";
|
|
3
|
+
import "core-js/modules/es.object.to-string.js";
|
|
4
|
+
import "core-js/modules/es.symbol.iterator.js";
|
|
5
|
+
import "core-js/modules/es.array.iterator.js";
|
|
6
|
+
import "core-js/modules/es.string.iterator.js";
|
|
7
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
8
|
+
import "core-js/modules/es.array.slice.js";
|
|
9
|
+
import "core-js/modules/es.array.from.js";
|
|
10
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
11
|
+
|
|
12
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
13
|
+
|
|
14
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15
|
+
|
|
16
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
17
|
+
|
|
18
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
19
|
+
|
|
20
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
21
|
+
|
|
22
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
23
|
+
|
|
24
|
+
import { useEffect, useState } from 'react';
|
|
25
|
+
export var useWidth = function useWidth(ref) {
|
|
26
|
+
var _useState = useState(),
|
|
27
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
28
|
+
width = _useState2[0],
|
|
29
|
+
setWidth = _useState2[1];
|
|
30
|
+
|
|
31
|
+
useEffect(function () {
|
|
32
|
+
if (ref.current) {
|
|
33
|
+
setWidth(ref.current.getBoundingClientRect().width);
|
|
34
|
+
}
|
|
35
|
+
}, [ref]);
|
|
36
|
+
return width;
|
|
37
|
+
};
|