@pingux/astro 2.40.0-alpha.1 → 2.40.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.
@@ -15,12 +15,16 @@ _Object$defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
16
16
|
});
|
17
17
|
exports["default"] = exports.Default = void 0;
|
18
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
18
19
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
19
20
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
20
21
|
var _react = _interopRequireWildcard(require("react"));
|
22
|
+
var _reactAria = require("react-aria");
|
21
23
|
var _CheckIcon = _interopRequireDefault(require("@pingux/mdi-react/CheckIcon"));
|
22
24
|
var _CloseIcon = _interopRequireDefault(require("@pingux/mdi-react/CloseIcon"));
|
25
|
+
var _interactions = require("@react-aria/interactions");
|
23
26
|
var _storybookAddonDesigns = require("storybook-addon-designs");
|
27
|
+
var _hooks = require("../hooks");
|
24
28
|
var _index = require("../index");
|
25
29
|
var _figmaLinks = require("../utils/designUtils/figmaLinks");
|
26
30
|
var _react2 = require("@emotion/react");
|
@@ -50,6 +54,14 @@ var inputProps = {
|
|
50
54
|
ariaLabel: 'Example aria label'
|
51
55
|
};
|
52
56
|
var sx = {
|
57
|
+
containerFocused: {
|
58
|
+
padding: 0,
|
59
|
+
position: 'relative',
|
60
|
+
borderColor: 'accent.60',
|
61
|
+
borderStyle: 'solid',
|
62
|
+
borderRadius: '3px 2px 2px 3px',
|
63
|
+
borderWidth: '1px'
|
64
|
+
},
|
53
65
|
editablePreview: {
|
54
66
|
whiteSpace: 'pre-line',
|
55
67
|
width: '100%',
|
@@ -63,37 +75,61 @@ var sx = {
|
|
63
75
|
fontSize: 'md',
|
64
76
|
fontWeight: 1,
|
65
77
|
lineHeight: '18px',
|
78
|
+
'&:hover': {
|
79
|
+
cursor: 'pointer',
|
80
|
+
bg: 'accent.95'
|
81
|
+
},
|
66
82
|
'&:focus': {
|
67
83
|
outline: 'none',
|
68
|
-
|
84
|
+
borderRadius: '2px',
|
69
85
|
borderColor: 'active',
|
86
|
+
borderWidth: '2px',
|
87
|
+
borderStyle: 'solid',
|
88
|
+
paddingLeft: '3px',
|
89
|
+
paddingBottom: '4px'
|
90
|
+
},
|
91
|
+
'&.is-pressed': {
|
70
92
|
borderWidth: '1px',
|
71
|
-
|
93
|
+
paddingLeft: '4px',
|
94
|
+
paddingBottom: 'xs'
|
72
95
|
}
|
73
96
|
},
|
74
97
|
editableInputWrapper: {
|
75
|
-
marginRight: '
|
76
|
-
flexGrow: 1
|
98
|
+
marginRight: '36px',
|
99
|
+
flexGrow: 1,
|
100
|
+
'&.is-focused textarea': {
|
101
|
+
outline: 'none'
|
102
|
+
},
|
103
|
+
'& label': {
|
104
|
+
margin: 0
|
105
|
+
},
|
106
|
+
'& textarea': {
|
107
|
+
minHeight: '45px',
|
108
|
+
height: '45px',
|
109
|
+
padding: '13px 35px 15px 18px',
|
110
|
+
lineHeight: '100%',
|
111
|
+
resize: 'vertical'
|
112
|
+
}
|
77
113
|
},
|
78
114
|
editableInpuTextArea: {
|
79
115
|
maxHeight: '150px'
|
80
116
|
},
|
81
117
|
editableControlWrapper: {
|
82
118
|
position: 'absolute',
|
83
|
-
right: '
|
84
|
-
top: '
|
119
|
+
right: '5px',
|
120
|
+
top: 'calc(50% - 13px)',
|
85
121
|
alignItems: 'center',
|
86
122
|
justifyContent: 'space-between'
|
87
123
|
},
|
88
124
|
editableControlIconButton: {
|
89
|
-
marginRight: '
|
125
|
+
marginRight: '20px',
|
90
126
|
width: '20px',
|
91
127
|
height: '20px'
|
92
128
|
}
|
93
129
|
};
|
94
130
|
var Default = function Default() {
|
95
131
|
return (0, _react2.jsx)(Editable, {
|
96
|
-
value: "
|
132
|
+
value: "Inline Editable text"
|
97
133
|
}, (0, _react2.jsx)(EditablePreview, null), (0, _react2.jsx)(EditableInput, {
|
98
134
|
inputProps: inputProps
|
99
135
|
}), (0, _react2.jsx)(EditableControl, {
|
@@ -118,6 +154,7 @@ var Editable = function Editable(props) {
|
|
118
154
|
isEditing = props.isEditing;
|
119
155
|
var editableContextValue = {
|
120
156
|
isEditing: isEditing || false,
|
157
|
+
isFocused: false,
|
121
158
|
prevValue: '',
|
122
159
|
value: value || ''
|
123
160
|
};
|
@@ -126,7 +163,8 @@ var Editable = function Editable(props) {
|
|
126
163
|
editableContext = _useState2[0],
|
127
164
|
setEditableContext = _useState2[1];
|
128
165
|
return (0, _react2.jsx)(_index.Box, {
|
129
|
-
sx: {
|
166
|
+
sx: editableContext.isEditing && editableContext.isFocused ? sx.containerFocused : {
|
167
|
+
padding: '1px',
|
130
168
|
position: 'relative'
|
131
169
|
}
|
132
170
|
}, (0, _react2.jsx)(EditableAreaProvider, {
|
@@ -148,6 +186,12 @@ var EditablePreview = function EditablePreview() {
|
|
148
186
|
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
149
187
|
hasFocus = _useState4[0],
|
150
188
|
setFocus = _useState4[1];
|
189
|
+
var editablePreview = (0, _react.useRef)(null);
|
190
|
+
var _usePress = (0, _interactions.usePress)({
|
191
|
+
ref: editablePreview
|
192
|
+
}),
|
193
|
+
pressProps = _usePress.pressProps,
|
194
|
+
isPressed = _usePress.isPressed;
|
151
195
|
var editablePreviewDynamicSx = {
|
152
196
|
backgroundColor: hasFocus ? 'accent.95' : 'white',
|
153
197
|
borderBottom: editableContext.isEditing ? '0px' : '1px dashed',
|
@@ -155,6 +199,10 @@ var EditablePreview = function EditablePreview() {
|
|
155
199
|
background: editableContext.isEditing ? 'white' : 'accent.95'
|
156
200
|
}
|
157
201
|
};
|
202
|
+
var _useStatusClasses = (0, _hooks.useStatusClasses)('', {
|
203
|
+
isPressed: isPressed
|
204
|
+
}),
|
205
|
+
classNames = _useStatusClasses.classNames;
|
158
206
|
(0, _react.useEffect)(function () {
|
159
207
|
if (hasFocus && editableContext.isEditing) {
|
160
208
|
setFocus(false);
|
@@ -172,7 +220,8 @@ var EditablePreview = function EditablePreview() {
|
|
172
220
|
}));
|
173
221
|
}
|
174
222
|
};
|
175
|
-
return (0, _react2.jsx)(_index.Box, {
|
223
|
+
return (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({}, pressProps, {
|
224
|
+
ref: editablePreview,
|
176
225
|
tabIndex: editableContext.isEditing ? '-1' : '0',
|
177
226
|
display: editableContext.isEditing ? 'none' : 'flex',
|
178
227
|
"aria-hidden": editableContext.isEditing,
|
@@ -187,8 +236,9 @@ var EditablePreview = function EditablePreview() {
|
|
187
236
|
return setFocus(false);
|
188
237
|
},
|
189
238
|
placeholder: "Click or press enter to edit text",
|
239
|
+
className: classNames,
|
190
240
|
sx: _objectSpread(_objectSpread({}, editablePreviewDynamicSx), sx.editablePreview)
|
191
|
-
}, editableContext.value);
|
241
|
+
}), editableContext.value);
|
192
242
|
};
|
193
243
|
|
194
244
|
/**
|
@@ -212,6 +262,14 @@ var EditableInput = function EditableInput(props) {
|
|
212
262
|
_useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
|
213
263
|
editingValue = _useState8[0],
|
214
264
|
setEditingValue = _useState8[1];
|
265
|
+
var _useFocusRing = (0, _reactAria.useFocusRing)(),
|
266
|
+
focusProps = _useFocusRing.focusProps,
|
267
|
+
isFocusVisible = _useFocusRing.isFocusVisible;
|
268
|
+
(0, _react.useEffect)(function () {
|
269
|
+
setEditableContext(_objectSpread(_objectSpread({}, editableContext), {}, {
|
270
|
+
isFocused: isFocusVisible
|
271
|
+
}));
|
272
|
+
}, [isFocusVisible]);
|
215
273
|
(0, _react.useEffect)(function () {
|
216
274
|
setEditingValue(editableContext.value);
|
217
275
|
}, [editableContext.value]);
|
@@ -245,12 +303,18 @@ var EditableInput = function EditableInput(props) {
|
|
245
303
|
}));
|
246
304
|
}
|
247
305
|
};
|
306
|
+
var _useStatusClasses2 = (0, _hooks.useStatusClasses)('', {
|
307
|
+
isFocused: isFocusVisible
|
308
|
+
}),
|
309
|
+
classNames = _useStatusClasses2.classNames;
|
248
310
|
return (0, _react2.jsx)(_index.Box, {
|
249
311
|
display: editableContext.isEditing ? 'flex' : 'none',
|
250
312
|
"aria-hidden": !editableContext.isEditing,
|
313
|
+
className: classNames,
|
251
314
|
sx: sx.editableInputWrapper
|
252
|
-
}, (0, _react2.jsx)(_index.TextAreaField, {
|
253
|
-
rows: 1
|
315
|
+
}, (0, _react2.jsx)(_index.TextAreaField, (0, _extends2["default"])({
|
316
|
+
rows: 1
|
317
|
+
}, focusProps, {
|
254
318
|
ref: editableInput,
|
255
319
|
role: "textbox",
|
256
320
|
contenteditable: "true",
|
@@ -259,9 +323,8 @@ var EditableInput = function EditableInput(props) {
|
|
259
323
|
onKeyDown: handleKeyDown,
|
260
324
|
value: editingValue,
|
261
325
|
"aria-label": ariaLabel,
|
262
|
-
sx: sx.editableInpuTextArea
|
263
|
-
|
264
|
-
}));
|
326
|
+
sx: sx.editableInpuTextArea
|
327
|
+
})));
|
265
328
|
};
|
266
329
|
|
267
330
|
/**
|
@@ -6,14 +6,18 @@ import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/inst
|
|
6
6
|
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
7
7
|
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
8
8
|
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
9
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
9
10
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
10
11
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
11
12
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
12
13
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
13
14
|
import React, { createContext, useContext, useEffect, useRef, useState } from 'react';
|
15
|
+
import { useFocusRing } from 'react-aria';
|
14
16
|
import CheckIcon from '@pingux/mdi-react/CheckIcon';
|
15
17
|
import CloseIcon from '@pingux/mdi-react/CloseIcon';
|
18
|
+
import { usePress } from '@react-aria/interactions';
|
16
19
|
import { withDesign } from 'storybook-addon-designs';
|
20
|
+
import { useStatusClasses } from '../hooks';
|
17
21
|
import { Box, Icon, IconButton, TextAreaField } from '../index';
|
18
22
|
import { FIGMA_LINKS } from '../utils/designUtils/figmaLinks';
|
19
23
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
@@ -38,6 +42,14 @@ var inputProps = {
|
|
38
42
|
ariaLabel: 'Example aria label'
|
39
43
|
};
|
40
44
|
var sx = {
|
45
|
+
containerFocused: {
|
46
|
+
padding: 0,
|
47
|
+
position: 'relative',
|
48
|
+
borderColor: 'accent.60',
|
49
|
+
borderStyle: 'solid',
|
50
|
+
borderRadius: '3px 2px 2px 3px',
|
51
|
+
borderWidth: '1px'
|
52
|
+
},
|
41
53
|
editablePreview: {
|
42
54
|
whiteSpace: 'pre-line',
|
43
55
|
width: '100%',
|
@@ -51,37 +63,61 @@ var sx = {
|
|
51
63
|
fontSize: 'md',
|
52
64
|
fontWeight: 1,
|
53
65
|
lineHeight: '18px',
|
66
|
+
'&:hover': {
|
67
|
+
cursor: 'pointer',
|
68
|
+
bg: 'accent.95'
|
69
|
+
},
|
54
70
|
'&:focus': {
|
55
71
|
outline: 'none',
|
56
|
-
|
72
|
+
borderRadius: '2px',
|
57
73
|
borderColor: 'active',
|
74
|
+
borderWidth: '2px',
|
75
|
+
borderStyle: 'solid',
|
76
|
+
paddingLeft: '3px',
|
77
|
+
paddingBottom: '4px'
|
78
|
+
},
|
79
|
+
'&.is-pressed': {
|
58
80
|
borderWidth: '1px',
|
59
|
-
|
81
|
+
paddingLeft: '4px',
|
82
|
+
paddingBottom: 'xs'
|
60
83
|
}
|
61
84
|
},
|
62
85
|
editableInputWrapper: {
|
63
|
-
marginRight: '
|
64
|
-
flexGrow: 1
|
86
|
+
marginRight: '36px',
|
87
|
+
flexGrow: 1,
|
88
|
+
'&.is-focused textarea': {
|
89
|
+
outline: 'none'
|
90
|
+
},
|
91
|
+
'& label': {
|
92
|
+
margin: 0
|
93
|
+
},
|
94
|
+
'& textarea': {
|
95
|
+
minHeight: '45px',
|
96
|
+
height: '45px',
|
97
|
+
padding: '13px 35px 15px 18px',
|
98
|
+
lineHeight: '100%',
|
99
|
+
resize: 'vertical'
|
100
|
+
}
|
65
101
|
},
|
66
102
|
editableInpuTextArea: {
|
67
103
|
maxHeight: '150px'
|
68
104
|
},
|
69
105
|
editableControlWrapper: {
|
70
106
|
position: 'absolute',
|
71
|
-
right: '
|
72
|
-
top: '
|
107
|
+
right: '5px',
|
108
|
+
top: 'calc(50% - 13px)',
|
73
109
|
alignItems: 'center',
|
74
110
|
justifyContent: 'space-between'
|
75
111
|
},
|
76
112
|
editableControlIconButton: {
|
77
|
-
marginRight: '
|
113
|
+
marginRight: '20px',
|
78
114
|
width: '20px',
|
79
115
|
height: '20px'
|
80
116
|
}
|
81
117
|
};
|
82
118
|
export var Default = function Default() {
|
83
119
|
return ___EmotionJSX(Editable, {
|
84
|
-
value: "
|
120
|
+
value: "Inline Editable text"
|
85
121
|
}, ___EmotionJSX(EditablePreview, null), ___EmotionJSX(EditableInput, {
|
86
122
|
inputProps: inputProps
|
87
123
|
}), ___EmotionJSX(EditableControl, {
|
@@ -105,6 +141,7 @@ var Editable = function Editable(props) {
|
|
105
141
|
isEditing = props.isEditing;
|
106
142
|
var editableContextValue = {
|
107
143
|
isEditing: isEditing || false,
|
144
|
+
isFocused: false,
|
108
145
|
prevValue: '',
|
109
146
|
value: value || ''
|
110
147
|
};
|
@@ -113,7 +150,8 @@ var Editable = function Editable(props) {
|
|
113
150
|
editableContext = _useState2[0],
|
114
151
|
setEditableContext = _useState2[1];
|
115
152
|
return ___EmotionJSX(Box, {
|
116
|
-
sx: {
|
153
|
+
sx: editableContext.isEditing && editableContext.isFocused ? sx.containerFocused : {
|
154
|
+
padding: '1px',
|
117
155
|
position: 'relative'
|
118
156
|
}
|
119
157
|
}, ___EmotionJSX(EditableAreaProvider, {
|
@@ -135,6 +173,12 @@ var EditablePreview = function EditablePreview() {
|
|
135
173
|
_useState4 = _slicedToArray(_useState3, 2),
|
136
174
|
hasFocus = _useState4[0],
|
137
175
|
setFocus = _useState4[1];
|
176
|
+
var editablePreview = useRef(null);
|
177
|
+
var _usePress = usePress({
|
178
|
+
ref: editablePreview
|
179
|
+
}),
|
180
|
+
pressProps = _usePress.pressProps,
|
181
|
+
isPressed = _usePress.isPressed;
|
138
182
|
var editablePreviewDynamicSx = {
|
139
183
|
backgroundColor: hasFocus ? 'accent.95' : 'white',
|
140
184
|
borderBottom: editableContext.isEditing ? '0px' : '1px dashed',
|
@@ -142,6 +186,10 @@ var EditablePreview = function EditablePreview() {
|
|
142
186
|
background: editableContext.isEditing ? 'white' : 'accent.95'
|
143
187
|
}
|
144
188
|
};
|
189
|
+
var _useStatusClasses = useStatusClasses('', {
|
190
|
+
isPressed: isPressed
|
191
|
+
}),
|
192
|
+
classNames = _useStatusClasses.classNames;
|
145
193
|
useEffect(function () {
|
146
194
|
if (hasFocus && editableContext.isEditing) {
|
147
195
|
setFocus(false);
|
@@ -159,7 +207,8 @@ var EditablePreview = function EditablePreview() {
|
|
159
207
|
}));
|
160
208
|
}
|
161
209
|
};
|
162
|
-
return ___EmotionJSX(Box, {
|
210
|
+
return ___EmotionJSX(Box, _extends({}, pressProps, {
|
211
|
+
ref: editablePreview,
|
163
212
|
tabIndex: editableContext.isEditing ? '-1' : '0',
|
164
213
|
display: editableContext.isEditing ? 'none' : 'flex',
|
165
214
|
"aria-hidden": editableContext.isEditing,
|
@@ -174,8 +223,9 @@ var EditablePreview = function EditablePreview() {
|
|
174
223
|
return setFocus(false);
|
175
224
|
},
|
176
225
|
placeholder: "Click or press enter to edit text",
|
226
|
+
className: classNames,
|
177
227
|
sx: _objectSpread(_objectSpread({}, editablePreviewDynamicSx), sx.editablePreview)
|
178
|
-
}, editableContext.value);
|
228
|
+
}), editableContext.value);
|
179
229
|
};
|
180
230
|
|
181
231
|
/**
|
@@ -199,6 +249,14 @@ var EditableInput = function EditableInput(props) {
|
|
199
249
|
_useState8 = _slicedToArray(_useState7, 2),
|
200
250
|
editingValue = _useState8[0],
|
201
251
|
setEditingValue = _useState8[1];
|
252
|
+
var _useFocusRing = useFocusRing(),
|
253
|
+
focusProps = _useFocusRing.focusProps,
|
254
|
+
isFocusVisible = _useFocusRing.isFocusVisible;
|
255
|
+
useEffect(function () {
|
256
|
+
setEditableContext(_objectSpread(_objectSpread({}, editableContext), {}, {
|
257
|
+
isFocused: isFocusVisible
|
258
|
+
}));
|
259
|
+
}, [isFocusVisible]);
|
202
260
|
useEffect(function () {
|
203
261
|
setEditingValue(editableContext.value);
|
204
262
|
}, [editableContext.value]);
|
@@ -232,12 +290,18 @@ var EditableInput = function EditableInput(props) {
|
|
232
290
|
}));
|
233
291
|
}
|
234
292
|
};
|
293
|
+
var _useStatusClasses2 = useStatusClasses('', {
|
294
|
+
isFocused: isFocusVisible
|
295
|
+
}),
|
296
|
+
classNames = _useStatusClasses2.classNames;
|
235
297
|
return ___EmotionJSX(Box, {
|
236
298
|
display: editableContext.isEditing ? 'flex' : 'none',
|
237
299
|
"aria-hidden": !editableContext.isEditing,
|
300
|
+
className: classNames,
|
238
301
|
sx: sx.editableInputWrapper
|
239
|
-
}, ___EmotionJSX(TextAreaField, {
|
240
|
-
rows: 1
|
302
|
+
}, ___EmotionJSX(TextAreaField, _extends({
|
303
|
+
rows: 1
|
304
|
+
}, focusProps, {
|
241
305
|
ref: editableInput,
|
242
306
|
role: "textbox",
|
243
307
|
contenteditable: "true",
|
@@ -246,9 +310,8 @@ var EditableInput = function EditableInput(props) {
|
|
246
310
|
onKeyDown: handleKeyDown,
|
247
311
|
value: editingValue,
|
248
312
|
"aria-label": ariaLabel,
|
249
|
-
sx: sx.editableInpuTextArea
|
250
|
-
|
251
|
-
}));
|
313
|
+
sx: sx.editableInpuTextArea
|
314
|
+
})));
|
252
315
|
};
|
253
316
|
|
254
317
|
/**
|