@flodesk/grain 4.0.0 → 5.0.0
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 +14 -48
- package/package.json +1 -1
|
@@ -12,7 +12,7 @@ import "core-js/modules/es.string.iterator.js";
|
|
|
12
12
|
import "core-js/modules/web.dom-collections.iterator.js";
|
|
13
13
|
import "core-js/modules/es.array.from.js";
|
|
14
14
|
import "core-js/modules/es.regexp.exec.js";
|
|
15
|
-
var _excluded = ["value", "placeholder", "
|
|
15
|
+
var _excluded = ["value", "placeholder", "label", "id", "icon"];
|
|
16
16
|
|
|
17
17
|
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
|
|
18
18
|
|
|
@@ -36,55 +36,28 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
36
36
|
|
|
37
37
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
38
38
|
|
|
39
|
-
import { getColor, getRadius
|
|
39
|
+
import { getColor, getRadius } from '../utilities';
|
|
40
40
|
import PropTypes from 'prop-types';
|
|
41
41
|
import React from 'react';
|
|
42
42
|
import styled from '@emotion/styled';
|
|
43
|
-
import { types } from '../types';
|
|
44
43
|
import { css } from '@emotion/react';
|
|
45
44
|
import { Box } from './box';
|
|
46
45
|
import { Icon } from './icon';
|
|
47
46
|
import { transitions } from '../foundational';
|
|
48
|
-
var variables = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n --grn-
|
|
49
|
-
var
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
iconOffsetPx: 8,
|
|
55
|
-
iconTextGapPx: 4
|
|
56
|
-
},
|
|
57
|
-
m: {
|
|
58
|
-
height: 'var(--grn-textBoxHeight-m)',
|
|
59
|
-
padding: '0 12px',
|
|
60
|
-
labelGap: '4px',
|
|
61
|
-
iconOffsetPx: 12,
|
|
62
|
-
iconTextGapPx: 8
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
var Wrapper = styled.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n ", ";\n font-size: ", ";\n"])), variables, function (p) {
|
|
66
|
-
return getTextSize(p.size);
|
|
67
|
-
});
|
|
68
|
-
var Label = styled.label(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n display: block;\n margin-bottom: ", ";\n"])), function (p) {
|
|
69
|
-
return sizesStyles[p.size].labelGap;
|
|
70
|
-
});
|
|
71
|
-
var InputField = styled.input(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n ", ";\n appearance: none;\n border: none;\n font-family: inherit;\n background-color: transparent;\n color: inherit;\n font-size: inherit;\n transition-property: border-color;\n border: 1px solid var(--grn-color-fieldBorder);\n width: 100%;\n border-radius: ", ";\n height: ", ";\n padding: ", ";\n ", ";\n outline: none;\n\n &::placeholder {\n color: ", ";\n }\n\n &:hover {\n border-color: var(--grn-color-fieldBorder-hover);\n }\n\n &:focus {\n transition: 0s;\n border-color: var(--grn-color-grey6);\n }\n"])), transitions, function () {
|
|
47
|
+
var variables = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n --grn-fieldBorderColor: var(--grn-color-fade3);\n --grn-fieldBorderColor-hover: var(--grn-color-fade6);\n --grn-fieldXPadding: 12px;\n"])));
|
|
48
|
+
var iconOffsetPx = 12;
|
|
49
|
+
var iconTextGapPx = 8;
|
|
50
|
+
var Wrapper = styled.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n ", ";\n"])), variables);
|
|
51
|
+
var Label = styled.label(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n display: block;\n margin-bottom: 4px;\n"])));
|
|
52
|
+
var InputField = styled.input(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n ", ";\n appearance: none;\n border: none;\n font: inherit;\n color: inherit;\n background-color: transparent;\n transition-property: border-color;\n border: 1px solid var(--grn-fieldBorderColor);\n width: 100%;\n border-radius: ", ";\n height: var(--grn-textBoxHeight-m);\n padding: 0 var(--grn-fieldXPadding) 0 ", ";\n outline: none;\n\n &::placeholder {\n color: ", ";\n }\n\n &:hover {\n border-color: var(--grn-fieldBorderColor-hover);\n }\n\n &:focus {\n transition: 0s;\n border-color: var(--grn-color-grey6);\n }\n"])), transitions, function () {
|
|
72
53
|
return getRadius('s');
|
|
73
54
|
}, function (p) {
|
|
74
|
-
return
|
|
75
|
-
}, function (p) {
|
|
76
|
-
return sizesStyles[p.size].padding;
|
|
77
|
-
}, function (p) {
|
|
78
|
-
return p.paddingLeft && "padding-left: ".concat(p.paddingLeft, "px");
|
|
55
|
+
return p.paddingLeft;
|
|
79
56
|
}, getColor('grey5'));
|
|
80
|
-
var IconSection = styled.div(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n position: absolute;\n margin: auto;\n left: ", "px;\n top: 0;\n bottom: 0;\n height: fit-content;\n pointer-events: none;\n"])),
|
|
81
|
-
return sizesStyles[p.size].iconOffsetPx;
|
|
82
|
-
});
|
|
57
|
+
var IconSection = styled.div(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n position: absolute;\n margin: auto;\n left: ", "px;\n top: 0;\n bottom: 0;\n height: fit-content;\n pointer-events: none;\n"])), iconOffsetPx);
|
|
83
58
|
export var TextInput = function TextInput(_ref) {
|
|
84
59
|
var value = _ref.value,
|
|
85
60
|
placeholder = _ref.placeholder,
|
|
86
|
-
_ref$size = _ref.size,
|
|
87
|
-
size = _ref$size === void 0 ? 'm' : _ref$size,
|
|
88
61
|
label = _ref.label,
|
|
89
62
|
id = _ref.id,
|
|
90
63
|
icon = _ref.icon,
|
|
@@ -102,25 +75,19 @@ export var TextInput = function TextInput(_ref) {
|
|
|
102
75
|
setIconWidth(iconRef.current.getBoundingClientRect().width);
|
|
103
76
|
}
|
|
104
77
|
}, []);
|
|
105
|
-
var paddingLeft = icon
|
|
78
|
+
var paddingLeft = icon ? "".concat(iconOffsetPx + iconWidth + iconTextGapPx, "px") : "var(--grn-fieldXPadding)";
|
|
106
79
|
return /*#__PURE__*/React.createElement(Wrapper, {
|
|
107
|
-
size: size,
|
|
108
80
|
type: "text"
|
|
109
81
|
}, label && /*#__PURE__*/React.createElement(Label, {
|
|
110
|
-
htmlFor: id
|
|
111
|
-
size: size
|
|
82
|
+
htmlFor: id
|
|
112
83
|
}, label), /*#__PURE__*/React.createElement(Box, {
|
|
113
84
|
position: "relative"
|
|
114
|
-
}, icon && /*#__PURE__*/React.createElement(IconSection, {
|
|
115
|
-
size: size
|
|
116
|
-
}, /*#__PURE__*/React.createElement(Icon, {
|
|
85
|
+
}, icon && /*#__PURE__*/React.createElement(IconSection, null, /*#__PURE__*/React.createElement(Icon, {
|
|
117
86
|
ref: iconRef,
|
|
118
|
-
icon: icon
|
|
119
|
-
size: size
|
|
87
|
+
icon: icon
|
|
120
88
|
})), /*#__PURE__*/React.createElement(InputField, Object.assign({
|
|
121
89
|
value: value,
|
|
122
90
|
placeholder: placeholder,
|
|
123
|
-
size: size,
|
|
124
91
|
label: label,
|
|
125
92
|
icon: icon,
|
|
126
93
|
id: id,
|
|
@@ -131,7 +98,6 @@ TextInput.propTypes = {
|
|
|
131
98
|
id: PropTypes.string.isRequired,
|
|
132
99
|
placeholder: PropTypes.string,
|
|
133
100
|
value: PropTypes.string,
|
|
134
|
-
size: types.fieldSize,
|
|
135
101
|
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
136
102
|
icon: PropTypes.node
|
|
137
103
|
};
|