grommet 2.25.0 → 2.25.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/components/Calendar/Calendar.js +232 -292
- package/components/Calendar/utils.js +16 -129
- package/components/Chart/calcs.js +44 -27
- package/components/Chart/stories/Scan.js +11 -9
- package/components/Chart/stories/data.js +16 -17
- package/components/CheckBox/CheckBox.js +3 -2
- package/components/DataChart/DataChart.js +3 -15
- package/components/DataChart/Detail.js +18 -11
- package/components/DataChart/stories/Pad.js +54 -0
- package/components/DateInput/DateInput.js +60 -68
- package/components/DateInput/utils.js +30 -5
- package/components/FileInput/FileInput.js +2 -1
- package/components/FileInput/StyledFileInput.js +1 -1
- package/components/Form/Form.js +6 -1
- package/components/FormField/FormField.js +25 -28
- package/components/Image/Image.js +4 -2
- package/components/Menu/index.d.ts +2 -2
- package/components/Select/SelectContainer.js +24 -36
- package/components/Tabs/Tabs.js +2 -1
- package/components/Video/StyledVideo.js +2 -2
- package/es6/components/Calendar/Calendar.js +230 -292
- package/es6/components/Calendar/utils.js +13 -114
- package/es6/components/Chart/calcs.js +44 -27
- package/es6/components/Chart/stories/Scan.js +10 -9
- package/es6/components/Chart/stories/data.js +16 -17
- package/es6/components/CheckBox/CheckBox.js +3 -2
- package/es6/components/DataChart/DataChart.js +4 -15
- package/es6/components/DataChart/Detail.js +20 -10
- package/es6/components/DataChart/stories/Pad.js +42 -0
- package/es6/components/DateInput/DateInput.js +57 -64
- package/es6/components/DateInput/utils.js +29 -7
- package/es6/components/FileInput/FileInput.js +2 -1
- package/es6/components/FileInput/StyledFileInput.js +1 -1
- package/es6/components/Form/Form.js +6 -1
- package/es6/components/FormField/FormField.js +25 -29
- package/es6/components/Image/Image.js +4 -2
- package/es6/components/Menu/index.d.ts +2 -2
- package/es6/components/Select/SelectContainer.js +25 -37
- package/es6/components/Tabs/Tabs.js +2 -1
- package/es6/components/Video/StyledVideo.js +2 -2
- package/es6/themes/base.d.ts +13 -27
- package/es6/themes/base.js +6 -1
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/package.json +44 -42
- package/themes/base.d.ts +13 -27
- package/themes/base.js +6 -1
|
@@ -20,9 +20,34 @@ import { FormContext } from '../Form';
|
|
|
20
20
|
import { Keyboard } from '../Keyboard';
|
|
21
21
|
import { MaskedInput } from '../MaskedInput';
|
|
22
22
|
import { useForwardedRef } from '../../utils';
|
|
23
|
-
import { getTimestamp, normalizeForTimezone } from '../Calendar/utils';
|
|
24
23
|
import { formatToSchema, schemaToMask, valuesAreEqual, valueToText, textToValue } from './utils';
|
|
25
24
|
import { DateInputPropTypes } from './propTypes';
|
|
25
|
+
import { getOutputFormat } from '../Calendar/Calendar';
|
|
26
|
+
|
|
27
|
+
var getReference = function getReference(value) {
|
|
28
|
+
var adjustedDate;
|
|
29
|
+
var res;
|
|
30
|
+
if (typeof value === 'string') res = value;else if (Array.isArray(value) && Array.isArray(value[0])) res = value[0].find(function (date) {
|
|
31
|
+
return date;
|
|
32
|
+
});else if (Array.isArray(value) && value.length) {
|
|
33
|
+
res = value[0];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (res) {
|
|
37
|
+
var _res;
|
|
38
|
+
|
|
39
|
+
adjustedDate = new Date(res); // if time is not specified in ISOstring, normalize to midnight
|
|
40
|
+
|
|
41
|
+
if (((_res = res) == null ? void 0 : _res.indexOf('T')) === -1) {
|
|
42
|
+
var offset = adjustedDate.getTimezoneOffset();
|
|
43
|
+
var hour = adjustedDate.getHours();
|
|
44
|
+
adjustedDate.setHours(hour, offset);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return adjustedDate;
|
|
49
|
+
};
|
|
50
|
+
|
|
26
51
|
var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
27
52
|
var buttonProps = _ref.buttonProps,
|
|
28
53
|
calendarProps = _ref.calendarProps,
|
|
@@ -67,25 +92,24 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
|
67
92
|
value = _useFormInput[0],
|
|
68
93
|
setValue = _useFormInput[1];
|
|
69
94
|
|
|
70
|
-
var
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (Array.isArray(value) && value.length) return getTimestamp(value[0]); // check to see if value is not an empty string
|
|
74
|
-
// empty string should behave like undefined
|
|
95
|
+
var _useState = useState(getOutputFormat(value)),
|
|
96
|
+
outputFormat = _useState[0],
|
|
97
|
+
setOutputFormat = _useState[1];
|
|
75
98
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
// will just rely on the UTC timestamp and don't need to normalize.
|
|
99
|
+
useEffect(function () {
|
|
100
|
+
setOutputFormat(function (previousFormat) {
|
|
101
|
+
var nextFormat = getOutputFormat(value); // when user types, date could become something like 07//2020
|
|
102
|
+
// and value becomes undefined. don't lose the format from the
|
|
103
|
+
// previous valid date
|
|
82
104
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
105
|
+
return previousFormat !== nextFormat ? previousFormat : nextFormat;
|
|
106
|
+
});
|
|
107
|
+
}, [value]); // keep track of timestamp from original date(s)
|
|
86
108
|
|
|
109
|
+
var _useState2 = useState(getReference(value)),
|
|
110
|
+
reference = _useState2[0],
|
|
111
|
+
setReference = _useState2[1]; // do we expect multiple dates?
|
|
87
112
|
|
|
88
|
-
var normalizedDate = normalizeForTimezone(value, timestamp, normalize); // do we expect multiple dates?
|
|
89
113
|
|
|
90
114
|
var range = Array.isArray(value) || format && format.includes('-'); // parse format and build a formal schema we can use elsewhere
|
|
91
115
|
|
|
@@ -97,9 +121,9 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
|
97
121
|
return schemaToMask(schema);
|
|
98
122
|
}, [schema]); // textValue is only used when a format is provided
|
|
99
123
|
|
|
100
|
-
var
|
|
101
|
-
textValue =
|
|
102
|
-
setTextValue =
|
|
124
|
+
var _useState3 = useState(schema ? valueToText(value, schema) : undefined),
|
|
125
|
+
textValue = _useState3[0],
|
|
126
|
+
setTextValue = _useState3[1]; // Setting the icon through `inputProps` is deprecated.
|
|
103
127
|
// The `icon` prop should be used instead.
|
|
104
128
|
|
|
105
129
|
|
|
@@ -124,17 +148,17 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
|
124
148
|
|
|
125
149
|
useEffect(function () {
|
|
126
150
|
if (schema && value !== undefined) {
|
|
127
|
-
var nextTextValue = valueToText(
|
|
151
|
+
var nextTextValue = valueToText(value, schema);
|
|
128
152
|
|
|
129
|
-
if (!valuesAreEqual(textToValue(textValue, schema, range,
|
|
153
|
+
if (!valuesAreEqual(textToValue(textValue, schema, range, reference), textToValue(nextTextValue, schema, range, reference)) || textValue === '' && nextTextValue !== '') {
|
|
130
154
|
setTextValue(nextTextValue);
|
|
131
155
|
}
|
|
132
156
|
}
|
|
133
|
-
}, [range, schema, textValue,
|
|
157
|
+
}, [range, schema, textValue, reference, value]); // when format and not inline, whether to show the Calendar in a Drop
|
|
134
158
|
|
|
135
|
-
var
|
|
136
|
-
open =
|
|
137
|
-
setOpen =
|
|
159
|
+
var _useState4 = useState(),
|
|
160
|
+
open = _useState4[0],
|
|
161
|
+
setOpen = _useState4[1];
|
|
138
162
|
|
|
139
163
|
var openCalendar = useCallback(function () {
|
|
140
164
|
setOpen(true);
|
|
@@ -154,33 +178,23 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
|
154
178
|
ref: inline ? ref : undefined,
|
|
155
179
|
id: inline && !format ? id : undefined,
|
|
156
180
|
range: range,
|
|
157
|
-
date: range ? undefined :
|
|
181
|
+
date: range ? undefined : value // when caller initializes with empty array, dates should be undefined
|
|
158
182
|
// allowing the user to select both begin and end of the range
|
|
159
183
|
,
|
|
160
|
-
dates: range && value.length ? [
|
|
184
|
+
dates: range && value.length ? [value] : undefined // places focus on days grid when Calendar opens
|
|
161
185
|
,
|
|
162
186
|
initialFocus: open ? 'days' : undefined,
|
|
163
|
-
normalize: normalize,
|
|
164
187
|
onSelect: disabled ? undefined : function (nextValue) {
|
|
165
188
|
var normalizedValue;
|
|
166
189
|
|
|
167
190
|
if (range && Array.isArray(nextValue)) {
|
|
168
191
|
normalizedValue = nextValue[0];
|
|
169
192
|
} // clicking an edge date removes it
|
|
170
|
-
else if (range) normalizedValue = [nextValue, nextValue];else normalizedValue = nextValue;
|
|
171
|
-
// been passed in, indicating that we should stay local if the
|
|
172
|
-
// user first picks a date via the Calendar.
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
var nextNormalize = normalize;
|
|
193
|
+
else if (range) normalizedValue = [nextValue, nextValue];else normalizedValue = nextValue;
|
|
176
194
|
|
|
177
|
-
if (
|
|
178
|
-
nextNormalize = false;
|
|
179
|
-
setNormalize(nextNormalize);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (schema) setTextValue(valueToText(normalizeForTimezone(normalizedValue, undefined, nextNormalize), schema));
|
|
195
|
+
if (schema) setTextValue(valueToText(normalizedValue, schema));
|
|
183
196
|
setValue(normalizedValue);
|
|
197
|
+
setReference(getReference(nextValue));
|
|
184
198
|
if (_onChange) _onChange({
|
|
185
199
|
value: normalizedValue
|
|
186
200
|
});
|
|
@@ -192,9 +206,7 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
|
192
206
|
}, 1);
|
|
193
207
|
}
|
|
194
208
|
}
|
|
195
|
-
},
|
|
196
|
-
timestamp: timestamp
|
|
197
|
-
})));
|
|
209
|
+
}, calendarProps));
|
|
198
210
|
var formContextValue = useMemo(function () {
|
|
199
211
|
return {
|
|
200
212
|
useFormInput: function useFormInput(_ref3) {
|
|
@@ -263,27 +275,8 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
|
263
275
|
onChange: function onChange(event) {
|
|
264
276
|
var nextTextValue = event.target.value;
|
|
265
277
|
setTextValue(nextTextValue);
|
|
266
|
-
var
|
|
267
|
-
//
|
|
268
|
-
|
|
269
|
-
if (timestamp === undefined && Date.parse(nextTextValue)) {
|
|
270
|
-
var _Date$toISOString$spl = new Date(nextTextValue).toISOString().split('T');
|
|
271
|
-
|
|
272
|
-
localTimestamp = _Date$toISOString$spl[1];
|
|
273
|
-
} // timestamp will be undefined if no defaultValue or value have
|
|
274
|
-
// been passed in, indicating that we should stay local
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
var nextNormalize = normalize;
|
|
278
|
-
|
|
279
|
-
if (timestamp === undefined) {
|
|
280
|
-
nextNormalize = false;
|
|
281
|
-
setNormalize(nextNormalize);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
var nextValue = textToValue(nextTextValue, schema, range, timestamp || localTimestamp, nextNormalize); // reset to original state
|
|
285
|
-
|
|
286
|
-
if (nextValue === undefined) setNormalize(true); // update value even when undefined
|
|
278
|
+
var nextValue = textToValue(nextTextValue, schema, range, reference, outputFormat);
|
|
279
|
+
if (nextValue !== undefined) setReference(getReference(nextValue)); // update value even when undefined
|
|
287
280
|
|
|
288
281
|
setValue(nextValue);
|
|
289
282
|
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
2
|
+
|
|
3
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
4
|
+
|
|
5
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
6
|
+
|
|
1
7
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
8
|
|
|
3
|
-
// Converting between Date and String types is handled via a "schema".
|
|
9
|
+
import { handleOffset } from '../Calendar/utils'; // Converting between Date and String types is handled via a "schema".
|
|
4
10
|
// The schema is an array of strings, split into strings with identical
|
|
5
11
|
// characters. So, 'mm/dd/yyyy' will be ['mm', '/', 'dd', '/', 'yyyyy'].
|
|
6
|
-
|
|
12
|
+
|
|
7
13
|
export var formatToSchema = function formatToSchema(format) {
|
|
8
14
|
if (!format) return undefined;
|
|
9
15
|
var result = [];
|
|
@@ -70,7 +76,16 @@ export var valueToText = function valueToText(value, schema) {
|
|
|
70
76
|
|
|
71
77
|
if (!value || Array.isArray(value) && !value.length) return text;
|
|
72
78
|
var dates = (Array.isArray(value) ? value : [value]).map(function (v) {
|
|
73
|
-
|
|
79
|
+
// TO DO should we extract this to a reusable function?
|
|
80
|
+
var adjustedDate = new Date(v); // if time is not specified in ISOstring, normalize to midnight
|
|
81
|
+
|
|
82
|
+
if (v.indexOf('T') === -1) {
|
|
83
|
+
var offset = adjustedDate.getTimezoneOffset();
|
|
84
|
+
var hour = adjustedDate.getHours();
|
|
85
|
+
adjustedDate.setHours(hour, offset);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return adjustedDate;
|
|
74
89
|
});
|
|
75
90
|
var dateIndex = 0;
|
|
76
91
|
var parts = {};
|
|
@@ -126,7 +141,7 @@ var pullDigits = function pullDigits(text, index) {
|
|
|
126
141
|
return text.slice(index, end);
|
|
127
142
|
};
|
|
128
143
|
|
|
129
|
-
export var textToValue = function textToValue(text, schema, range,
|
|
144
|
+
export var textToValue = function textToValue(text, schema, range, reference, outputFormat) {
|
|
130
145
|
if (!text) return range ? [] : undefined;
|
|
131
146
|
var result;
|
|
132
147
|
|
|
@@ -134,10 +149,17 @@ export var textToValue = function textToValue(text, schema, range, timestamp, no
|
|
|
134
149
|
var leapYear = parts.y % 4 === 0 && parts.y % 100 !== 0 || parts.y % 400 === 0; // Do a little sanity checking on the parts first.
|
|
135
150
|
// If not valid, leave as is.
|
|
136
151
|
|
|
137
|
-
if (!parts.m || !parts.d || !parts.y || parts.y.length < 4 || parts.m.length > 2 || parts.d.length > 2 || parts.m > 12 || parts.d > 31 || (parts.m === "02" || parts.m === "2") && parts.d > (leapYear ? 29 : 28)) return parts;
|
|
138
|
-
|
|
152
|
+
if (!parts.m || !parts.d || !parts.y || parts.y.length < 4 || parts.m.length > 2 || parts.d.length > 2 || parts.m > 12 || parts.d > 31 || (parts.m === "02" || parts.m === "2") && parts.d > (leapYear ? 29 : 28)) return parts; // use time info from reference date
|
|
153
|
+
|
|
154
|
+
var time = reference ? [reference.getHours(), reference.getMinutes(), reference.getSeconds(), reference.getMilliseconds()] : null;
|
|
155
|
+
|
|
156
|
+
var date = _construct(Date, [parts.y, parts.m - 1, parts.d].concat(time)).toISOString();
|
|
139
157
|
|
|
140
|
-
if (
|
|
158
|
+
if (date && outputFormat === 'no timezone') {
|
|
159
|
+
var _handleOffset$toISOSt = handleOffset(date).toISOString().split('T');
|
|
160
|
+
|
|
161
|
+
date = _handleOffset$toISOSt[0];
|
|
162
|
+
}
|
|
141
163
|
|
|
142
164
|
if (!range) {
|
|
143
165
|
if (!result) result = date;
|
|
@@ -42,7 +42,7 @@ var formatBytes = function formatBytes(size) {
|
|
|
42
42
|
var ContentsBox = styled(Box).withConfig({
|
|
43
43
|
displayName: "FileInput__ContentsBox",
|
|
44
44
|
componentId: "sc-1jzq7im-0"
|
|
45
|
-
})(["position:relative;", " ", ";", ";", ";"], function (props) {
|
|
45
|
+
})(["cursor:pointer;position:relative;", " ", ";", ";", ";"], function (props) {
|
|
46
46
|
return props.disabled && disabledStyle();
|
|
47
47
|
}, function (props) {
|
|
48
48
|
return props.theme.fileInput && props.theme.fileInput.extend;
|
|
@@ -292,6 +292,7 @@ var FileInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
292
292
|
justify: "between"
|
|
293
293
|
}, files.length <= aggregateThreshold && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Message, theme.fileInput.message, message), /*#__PURE__*/React.createElement(Keyboard, {
|
|
294
294
|
onSpace: function onSpace(event) {
|
|
295
|
+
event.preventDefault();
|
|
295
296
|
if (controlRef.current === event.target) inputRef.current.click();
|
|
296
297
|
},
|
|
297
298
|
onEnter: function onEnter(event) {
|
|
@@ -4,7 +4,7 @@ import { defaultProps } from '../../default-props';
|
|
|
4
4
|
var StyledFileInput = styled.input.withConfig({
|
|
5
5
|
displayName: "StyledFileInput",
|
|
6
6
|
componentId: "sc-rl7ywv-0"
|
|
7
|
-
})(["position:absolute;height:100%;width:100%;", " opacity:0;border:none;", " ", " &::-moz-focus-inner{border:none;outline:none;}"], inputStyle, function (props) {
|
|
7
|
+
})(["position:absolute;height:100%;width:100%;", " font-size:0;opacity:0;border:none;", " ", " &::-moz-focus-inner{border:none;outline:none;}&::-webkit-file-upload-button{cursor:pointer;}"], inputStyle, function (props) {
|
|
8
8
|
return !props.disabled && 'cursor: pointer;';
|
|
9
9
|
}, function (props) {
|
|
10
10
|
return props.rightOffset && "\n width: calc(100% - " + props.rightOffset + "px);\n right: " + props.rightOffset + "px;\n ";
|
|
@@ -486,7 +486,12 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
486
486
|
|
|
487
487
|
validationRulesRef.current[name].field = validateName(validateArg, required);
|
|
488
488
|
return function () {
|
|
489
|
-
|
|
489
|
+
delete validationRulesRef.current[name].field;
|
|
490
|
+
var requiredFieldIndex = requiredFields.current.indexOf(name);
|
|
491
|
+
|
|
492
|
+
if (requiredFieldIndex !== -1) {
|
|
493
|
+
requiredFields.current.splice(requiredFieldIndex, 1);
|
|
494
|
+
}
|
|
490
495
|
};
|
|
491
496
|
}
|
|
492
497
|
|
|
@@ -6,7 +6,7 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
6
6
|
|
|
7
7
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
8
8
|
|
|
9
|
-
import React, { Children, cloneElement, forwardRef, useContext, useState } from 'react';
|
|
9
|
+
import React, { Children, cloneElement, forwardRef, useContext, useState, useEffect } from 'react';
|
|
10
10
|
import styled, { ThemeContext } from 'styled-components';
|
|
11
11
|
import { defaultProps } from '../../default-props';
|
|
12
12
|
import { containsFocus, shouldKeepFocus } from '../../utils/DOM';
|
|
@@ -129,21 +129,22 @@ var Input = function Input(_ref2) {
|
|
|
129
129
|
}, rest, extraProps));
|
|
130
130
|
};
|
|
131
131
|
|
|
132
|
-
var
|
|
133
|
-
var
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
args[_key] = arguments[_key];
|
|
137
|
-
}
|
|
132
|
+
var useDebounce = function useDebounce() {
|
|
133
|
+
var _useState = useState(),
|
|
134
|
+
func = _useState[0],
|
|
135
|
+
setFunc = _useState[1];
|
|
138
136
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
137
|
+
var theme = useContext(ThemeContext) || defaultProps.theme;
|
|
138
|
+
useEffect(function () {
|
|
139
|
+
var timer;
|
|
140
|
+
if (func) timer = setTimeout(function () {
|
|
141
|
+
return func();
|
|
142
|
+
}, theme.global.debounceDelay);
|
|
143
|
+
return function () {
|
|
144
|
+
return clearTimeout(timer);
|
|
142
145
|
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
timeout = setTimeout(later, wait);
|
|
146
|
-
};
|
|
146
|
+
}, [func, theme.global.debounceDelay]);
|
|
147
|
+
return setFunc;
|
|
147
148
|
};
|
|
148
149
|
|
|
149
150
|
var FormField = /*#__PURE__*/forwardRef(function (_ref3, ref) {
|
|
@@ -185,13 +186,14 @@ var FormField = /*#__PURE__*/forwardRef(function (_ref3, ref) {
|
|
|
185
186
|
contextOnBlur = _formContext$useFormF.onBlur,
|
|
186
187
|
contextOnChange = _formContext$useFormF.onChange;
|
|
187
188
|
|
|
188
|
-
var
|
|
189
|
-
focus =
|
|
190
|
-
setFocus =
|
|
189
|
+
var _useState2 = useState(),
|
|
190
|
+
focus = _useState2[0],
|
|
191
|
+
setFocus = _useState2[1];
|
|
191
192
|
|
|
192
193
|
var formFieldRef = useForwardedRef(ref);
|
|
193
194
|
var formFieldTheme = theme.formField;
|
|
194
|
-
var themeBorder = formFieldTheme.border;
|
|
195
|
+
var themeBorder = formFieldTheme.border;
|
|
196
|
+
var debounce = useDebounce(); // This is here for backwards compatibility. In case the child is a grommet
|
|
195
197
|
// input component, set plain and focusIndicator props, if they aren't
|
|
196
198
|
// already set.
|
|
197
199
|
|
|
@@ -368,17 +370,11 @@ var FormField = /*#__PURE__*/forwardRef(function (_ref3, ref) {
|
|
|
368
370
|
onChange: contextOnChange || onChange ? function (event) {
|
|
369
371
|
event.persist();
|
|
370
372
|
if (onChange) onChange(event);
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
// field, but capture their attention before they move on
|
|
377
|
-
// past it. 2 second (2000ms) might be too long depending
|
|
378
|
-
// on how fast people type, and 200ms would be an eye blink
|
|
379
|
-
}, 500);
|
|
380
|
-
debouncedFn();
|
|
381
|
-
}
|
|
373
|
+
if (contextOnChange) debounce(function () {
|
|
374
|
+
return function () {
|
|
375
|
+
return contextOnChange(event);
|
|
376
|
+
};
|
|
377
|
+
});
|
|
382
378
|
} : undefined
|
|
383
379
|
}, containerRest), label && component !== CheckBox || help ? /*#__PURE__*/React.createElement(React.Fragment, null, label && component !== CheckBox && /*#__PURE__*/React.createElement(Text, _extends({
|
|
384
380
|
as: "label",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["a11yTitle", "fallback", "onError", "opacity", "fill", "src"];
|
|
1
|
+
var _excluded = ["a11yTitle", "fallback", "onError", "onLoad", "opacity", "fill", "src"];
|
|
2
2
|
|
|
3
3
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
4
|
|
|
@@ -11,6 +11,7 @@ var Image = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
11
11
|
var a11yTitle = _ref.a11yTitle,
|
|
12
12
|
fallback = _ref.fallback,
|
|
13
13
|
onError = _ref.onError,
|
|
14
|
+
onLoad = _ref.onLoad,
|
|
14
15
|
opacity = _ref.opacity,
|
|
15
16
|
fill = _ref.fill,
|
|
16
17
|
src = _ref.src,
|
|
@@ -30,7 +31,8 @@ var Image = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
30
31
|
}
|
|
31
32
|
};
|
|
32
33
|
|
|
33
|
-
var handleOnLoad = function handleOnLoad() {
|
|
34
|
+
var handleOnLoad = function handleOnLoad(event) {
|
|
35
|
+
if (onLoad) onLoad(event);
|
|
34
36
|
setFallbackInUse(false);
|
|
35
37
|
};
|
|
36
38
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { DropProps } from '../Drop';
|
|
3
|
-
import {
|
|
3
|
+
import { ButtonExtendedProps, ButtonType } from '../Button';
|
|
4
4
|
import {
|
|
5
5
|
A11yTitleType,
|
|
6
6
|
AlignSelfType,
|
|
@@ -31,7 +31,7 @@ export interface MenuProps {
|
|
|
31
31
|
dropProps?: DropProps;
|
|
32
32
|
gridArea?: GridAreaType;
|
|
33
33
|
icon?: boolean | React.ReactNode;
|
|
34
|
-
items:
|
|
34
|
+
items: ButtonExtendedProps[] | ButtonExtendedProps[][];
|
|
35
35
|
justifyContent?: JustifyContentType;
|
|
36
36
|
label?: string | React.ReactNode;
|
|
37
37
|
margin?: MarginType;
|
|
@@ -2,7 +2,7 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
2
2
|
|
|
3
3
|
import React, { forwardRef, useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
4
4
|
import styled, { ThemeContext } from 'styled-components';
|
|
5
|
-
import { selectedStyle, setFocusWithoutScroll } from '../../utils';
|
|
5
|
+
import { getHoverIndicatorStyle, selectedStyle, setFocusWithoutScroll } from '../../utils';
|
|
6
6
|
import { defaultProps } from '../../default-props';
|
|
7
7
|
import { Box } from '../Box';
|
|
8
8
|
import { Button } from '../Button';
|
|
@@ -20,8 +20,10 @@ var OptionsBox = styled.div.withConfig({
|
|
|
20
20
|
var SelectOption = styled(Button).withConfig({
|
|
21
21
|
displayName: "SelectContainer__SelectOption",
|
|
22
22
|
componentId: "sc-1wi0ul8-1"
|
|
23
|
-
})(["", " display:block;width:100%;"], function (props) {
|
|
23
|
+
})(["", " ", " display:block;width:100%;"], function (props) {
|
|
24
24
|
return props.selected && props.textComponent && selectedStyle;
|
|
25
|
+
}, function (props) {
|
|
26
|
+
return props.active && getHoverIndicatorStyle(!props.children && !props.theme.select.options ? undefined : 'background', props.theme);
|
|
25
27
|
});
|
|
26
28
|
var ClearButton = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
27
29
|
var clear = _ref.clear,
|
|
@@ -73,28 +75,24 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
73
75
|
replace = _ref2$replace === void 0 ? true : _ref2$replace;
|
|
74
76
|
var theme = useContext(ThemeContext) || defaultProps.theme;
|
|
75
77
|
|
|
76
|
-
var _useState = useState(-1),
|
|
78
|
+
var _useState = useState(usingKeyboard ? 0 : -1),
|
|
77
79
|
activeIndex = _useState[0],
|
|
78
80
|
setActiveIndex = _useState[1];
|
|
79
81
|
|
|
80
|
-
var _useState2 = useState(),
|
|
82
|
+
var _useState2 = useState(usingKeyboard),
|
|
81
83
|
keyboardNavigation = _useState2[0],
|
|
82
84
|
setKeyboardNavigation = _useState2[1];
|
|
83
85
|
|
|
84
86
|
var searchRef = useRef();
|
|
85
87
|
var optionsRef = useRef();
|
|
86
88
|
var clearRef = useRef();
|
|
89
|
+
var activeRef = useRef(); // for keyboard/screenreader, keep the active option in focus
|
|
90
|
+
|
|
87
91
|
useEffect(function () {
|
|
88
|
-
var
|
|
92
|
+
var _activeRef$current;
|
|
89
93
|
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
var index = activeIndex;
|
|
93
|
-
if (clear && clear.position !== 'bottom' && clearButton) index += 1;
|
|
94
|
-
var optionNode = optionsNode.children[index];
|
|
95
|
-
if (optionNode) optionNode.focus();
|
|
96
|
-
}
|
|
97
|
-
}, [activeIndex, clear]); // set initial focus
|
|
94
|
+
if (activeIndex) (_activeRef$current = activeRef.current) == null ? void 0 : _activeRef$current.focus();
|
|
95
|
+
}, [activeIndex]); // set initial focus
|
|
98
96
|
|
|
99
97
|
useEffect(function () {
|
|
100
98
|
// need to wait for Drop to be ready
|
|
@@ -110,11 +108,8 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
110
108
|
}
|
|
111
109
|
} else if (clear && clearButton && clearButton.focus && clear.position !== 'bottom') {
|
|
112
110
|
setFocusWithoutScroll(clearButton);
|
|
113
|
-
} else if (
|
|
114
|
-
|
|
115
|
-
// first child as the active index when the drop opens
|
|
116
|
-
setFocusWithoutScroll(optionsNode.children[0]);
|
|
117
|
-
setActiveIndex(0);
|
|
111
|
+
} else if (usingKeyboard && activeRef.current) {
|
|
112
|
+
setFocusWithoutScroll(activeRef.current);
|
|
118
113
|
} else if (optionsNode) {
|
|
119
114
|
setFocusWithoutScroll(optionsNode);
|
|
120
115
|
}
|
|
@@ -122,21 +117,7 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
122
117
|
return function () {
|
|
123
118
|
return clearTimeout(timer);
|
|
124
119
|
};
|
|
125
|
-
}, [onSearch, usingKeyboard, clear]);
|
|
126
|
-
|
|
127
|
-
useEffect(function () {
|
|
128
|
-
if (keyboardNavigation) {
|
|
129
|
-
// 100ms was empirically determined
|
|
130
|
-
var timer = setTimeout(function () {
|
|
131
|
-
return setKeyboardNavigation(false);
|
|
132
|
-
}, 100);
|
|
133
|
-
return function () {
|
|
134
|
-
return clearTimeout(timer);
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return undefined;
|
|
139
|
-
}, [keyboardNavigation]);
|
|
120
|
+
}, [onSearch, usingKeyboard, clear]);
|
|
140
121
|
var optionLabel = useCallback(function (index) {
|
|
141
122
|
return applyKey(options[index], labelKey);
|
|
142
123
|
}, [labelKey, options]);
|
|
@@ -355,7 +336,10 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
355
336
|
role: "listbox",
|
|
356
337
|
tabIndex: "-1",
|
|
357
338
|
ref: optionsRef,
|
|
358
|
-
"aria-multiselectable": multiple
|
|
339
|
+
"aria-multiselectable": multiple,
|
|
340
|
+
onMouseMove: function onMouseMove() {
|
|
341
|
+
return setKeyboardNavigation(false);
|
|
342
|
+
}
|
|
359
343
|
}, shouldShowClearButton('top') && /*#__PURE__*/React.createElement(ClearButton, {
|
|
360
344
|
ref: clearRef,
|
|
361
345
|
clear: clear,
|
|
@@ -392,8 +376,13 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
392
376
|
|
|
393
377
|
return /*#__PURE__*/React.createElement(SelectOption // eslint-disable-next-line react/no-array-index-key
|
|
394
378
|
, {
|
|
395
|
-
key: index
|
|
396
|
-
|
|
379
|
+
key: index // merge optionRef and activeRef
|
|
380
|
+
,
|
|
381
|
+
ref: function ref(node) {
|
|
382
|
+
// eslint-disable-next-line no-param-reassign
|
|
383
|
+
if (optionRef) optionRef.current = node;
|
|
384
|
+
if (optionActive) activeRef.current = node;
|
|
385
|
+
},
|
|
397
386
|
tabIndex: optionSelected ? '0' : '-1',
|
|
398
387
|
role: "option",
|
|
399
388
|
"aria-setsize": options.length,
|
|
@@ -404,7 +393,6 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
404
393
|
plain: !child ? undefined : true,
|
|
405
394
|
align: "start",
|
|
406
395
|
kind: !child ? 'option' : undefined,
|
|
407
|
-
hoverIndicator: !child ? undefined : 'background',
|
|
408
396
|
label: !child ? optionLabel(index) : undefined,
|
|
409
397
|
disabled: optionDisabled || undefined,
|
|
410
398
|
active: optionActive,
|
|
@@ -293,6 +293,7 @@ var Tabs = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
293
293
|
}, rest, {
|
|
294
294
|
background: theme.tabs.background
|
|
295
295
|
}), /*#__PURE__*/React.createElement(Box, _extends({
|
|
296
|
+
flex: false,
|
|
296
297
|
direction: overflow ? 'row' : 'column'
|
|
297
298
|
}, tabsHeaderStyles), overflow && /*#__PURE__*/React.createElement(Button, {
|
|
298
299
|
a11yTitle: "Previous Tab",
|
|
@@ -313,7 +314,7 @@ var Tabs = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
313
314
|
ref: headerRef,
|
|
314
315
|
as: Box,
|
|
315
316
|
direction: "row",
|
|
316
|
-
justify: justify,
|
|
317
|
+
justify: overflow ? 'start' : justify,
|
|
317
318
|
alignSelf: alignControls,
|
|
318
319
|
flex: !!overflow,
|
|
319
320
|
wrap: false,
|
|
@@ -49,9 +49,9 @@ var headStyle = css(["::after{content:'';height:100%;width:", ";background:", ";
|
|
|
49
49
|
var StyledVideoScrubber = styled.div.withConfig({
|
|
50
50
|
displayName: "StyledVideo__StyledVideoScrubber",
|
|
51
51
|
componentId: "sc-w4v8h9-3"
|
|
52
|
-
})(["cursor:pointer;width:100%;height:100%;", "
|
|
52
|
+
})(["cursor:pointer;width:100%;height:100%;", ";&:focus{", "}"], function (props) {
|
|
53
53
|
return props.value && headStyle;
|
|
54
|
-
});
|
|
54
|
+
}, focusStyle());
|
|
55
55
|
StyledVideoScrubber.defaultProps = {};
|
|
56
56
|
Object.setPrototypeOf(StyledVideoScrubber.defaultProps, defaultProps);
|
|
57
57
|
export { StyledVideo, StyledVideoContainer, StyledVideoControls, StyledVideoScrubber };
|
package/es6/themes/base.d.ts
CHANGED
|
@@ -242,6 +242,15 @@ interface FormFieldLabelType extends TextProps {
|
|
|
242
242
|
requiredIndicator?: boolean | JSX.Element | string;
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
+
type DigitalTexts =
|
|
246
|
+
| 'xsmall'
|
|
247
|
+
| 'small'
|
|
248
|
+
| 'medium'
|
|
249
|
+
| 'large'
|
|
250
|
+
| 'xlarge'
|
|
251
|
+
| 'xxlarge'
|
|
252
|
+
| string;
|
|
253
|
+
|
|
245
254
|
export interface ThemeType {
|
|
246
255
|
global?: {
|
|
247
256
|
active?: {
|
|
@@ -359,7 +368,8 @@ export interface ThemeType {
|
|
|
359
368
|
color?: ColorType;
|
|
360
369
|
size?: string;
|
|
361
370
|
};
|
|
362
|
-
shadow?:
|
|
371
|
+
shadow?:
|
|
372
|
+
string | {
|
|
363
373
|
color?: ColorType;
|
|
364
374
|
size?: string;
|
|
365
375
|
};
|
|
@@ -517,7 +527,7 @@ export interface ThemeType {
|
|
|
517
527
|
};
|
|
518
528
|
};
|
|
519
529
|
card?: {
|
|
520
|
-
container?: BoxProps;
|
|
530
|
+
container?: BoxProps | { extend?: ExtendType };
|
|
521
531
|
hover?: {
|
|
522
532
|
container?: {
|
|
523
533
|
elevation?: ElevationType;
|
|
@@ -626,31 +636,7 @@ export interface ThemeType {
|
|
|
626
636
|
};
|
|
627
637
|
digital?: {
|
|
628
638
|
text?: {
|
|
629
|
-
|
|
630
|
-
size?: string;
|
|
631
|
-
height?: number;
|
|
632
|
-
};
|
|
633
|
-
small?: {
|
|
634
|
-
size?: string;
|
|
635
|
-
height?: number;
|
|
636
|
-
};
|
|
637
|
-
medium?: {
|
|
638
|
-
size?: string;
|
|
639
|
-
height?: number;
|
|
640
|
-
};
|
|
641
|
-
large?: {
|
|
642
|
-
size?: string;
|
|
643
|
-
height?: number;
|
|
644
|
-
};
|
|
645
|
-
xlarge?: {
|
|
646
|
-
size?: string;
|
|
647
|
-
height?: number;
|
|
648
|
-
};
|
|
649
|
-
xxlarge?: {
|
|
650
|
-
size?: string;
|
|
651
|
-
height?: number;
|
|
652
|
-
};
|
|
653
|
-
[key: string]: {
|
|
639
|
+
[key in DigitalTexts]: {
|
|
654
640
|
size?: string;
|
|
655
641
|
height?: number;
|
|
656
642
|
};
|