grevlingui 0.1.25 → 0.1.27

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.
@@ -17,6 +17,16 @@
17
17
  z-index: 2;
18
18
  }
19
19
 
20
+ .numberSelect_input {
21
+ opacity: 1;
22
+ transition: opacity 300ms linear;
23
+ }
24
+
25
+ .numberSelect_input-hidden {
26
+ opacity: 0;
27
+ pointer-events: none;
28
+ }
29
+
20
30
  .numberSelect_increment {
21
31
  border-radius: 100%;
22
32
  position: absolute;
@@ -30,9 +30,21 @@ const NumberSelect = _ref => {
30
30
  size = 5,
31
31
  color = 'white',
32
32
  numberBgColor = '#663399',
33
- selectorColor = '#1E90FF'
33
+ selectorColor = '#1E90FF',
34
+ timeout = 1000
34
35
  } = _ref;
35
36
  const [editing, setEditing] = (0, _react.useState)(false);
37
+ const [closeTimeout, setCloseTimeout] = (0, _react.useState)();
38
+
39
+ const startTimeout = () => {
40
+ if (!timeout) return;
41
+ clearTimeout(closeTimeout);
42
+ setCloseTimeout(setTimeout(() => {
43
+ setEditing(false);
44
+ setCloseTimeout(undefined);
45
+ }, timeout));
46
+ };
47
+
36
48
  const fullSize = "".concat(size, "rem");
37
49
  const incrementorSize = "".concat(size * .8, "rem");
38
50
  const incrementorVerticalOffset = "-".concat(size * .9, "rem");
@@ -73,12 +85,15 @@ const NumberSelect = _ref => {
73
85
  }));
74
86
 
75
87
  const increment = change => () => {
88
+ startTimeout();
76
89
  const nv = change + value;
77
90
  if (nv > max || nv < min) return;
78
91
  setValue(nv);
79
92
  };
80
93
 
81
- const renderInputs = () => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
94
+ const renderInputs = () => /*#__PURE__*/_react.default.createElement("div", {
95
+ className: "numberSelect_input ".concat(editing ? '' : 'numberSelect_input-hidden')
96
+ }, /*#__PURE__*/_react.default.createElement("div", {
82
97
  className: "numberSelect_increment numberSelect_add ".concat(editing ? 'numberSelect_editing' : ''),
83
98
  style: addStyle,
84
99
  onClick: increment(1)
@@ -95,7 +110,10 @@ const NumberSelect = _ref => {
95
110
  className: "numberSelect"
96
111
  }, /*#__PURE__*/_react.default.createElement("div", {
97
112
  className: "numberSelect_value",
98
- onClick: () => setEditing(pv => !pv),
113
+ onClick: () => {
114
+ if (!editing) startTimeout();
115
+ setEditing(!editing);
116
+ },
99
117
  style: {
100
118
  height: fullSize,
101
119
  width: fullSize,
@@ -103,7 +121,7 @@ const NumberSelect = _ref => {
103
121
  backgroundColor: numberBgColor,
104
122
  fontSize: "".concat(size / 2, "rem")
105
123
  }
106
- }, value), editing && renderInputs());
124
+ }, value), renderInputs());
107
125
  };
108
126
 
109
127
  exports.NumberSelect = NumberSelect;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grevlingui",
3
- "version": "0.1.25",
3
+ "version": "0.1.27",
4
4
  "description": "GUI elements",
5
5
  "module": "index.js",
6
6
  "dependencies": {