@algolia/satellite 1.0.0-beta.166 → 1.0.0-beta.168
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/cjs/AutoComplete/AutoComplete.d.ts +1 -1
- package/cjs/AutoComplete/AutoComplete.js +14 -4
- package/cjs/AutoComplete/index.d.ts +1 -0
- package/cjs/AutoComplete/index.js +10 -1
- package/cjs/AutoComplete/types.d.ts +2 -0
- package/cjs/Checkbox/Checkbox.js +4 -2
- package/cjs/Dropzone/Dropzone.js +4 -2
- package/cjs/Field/Field.d.ts +3 -2
- package/cjs/Field/Field.js +18 -8
- package/cjs/Field/FieldContext.d.ts +16 -0
- package/cjs/Field/FieldContext.js +14 -0
- package/cjs/Field/index.d.ts +3 -2
- package/cjs/Field/index.js +14 -17
- package/cjs/Field/useField.d.ts +2 -0
- package/cjs/Field/useField.js +11 -0
- package/cjs/Input/Input.js +6 -4
- package/esm/AutoComplete/AutoComplete.d.ts +1 -1
- package/esm/AutoComplete/AutoComplete.js +15 -5
- package/esm/AutoComplete/index.d.ts +1 -0
- package/esm/AutoComplete/index.js +1 -0
- package/esm/AutoComplete/types.d.ts +2 -0
- package/esm/Checkbox/Checkbox.js +5 -3
- package/esm/Dropzone/Dropzone.js +5 -3
- package/esm/Field/Field.d.ts +3 -2
- package/esm/Field/Field.js +18 -5
- package/esm/Field/FieldContext.d.ts +16 -0
- package/esm/Field/FieldContext.js +8 -0
- package/esm/Field/index.d.ts +3 -2
- package/esm/Field/index.js +2 -2
- package/esm/Field/useField.d.ts +2 -0
- package/esm/Field/useField.js +5 -0
- package/esm/Input/Input.js +6 -4
- package/package.json +1 -1
- package/cjs/Field/FieldStateContext.d.ts +0 -12
- package/cjs/Field/FieldStateContext.js +0 -12
- package/cjs/Field/useFieldState.d.ts +0 -2
- package/cjs/Field/useFieldState.js +0 -15
- package/esm/Field/FieldStateContext.d.ts +0 -12
- package/esm/Field/FieldStateContext.js +0 -6
- package/esm/Field/useFieldState.d.ts +0 -2
- package/esm/Field/useFieldState.js +0 -6
@@ -16,5 +16,5 @@ import type { AutoCompleteProps, Option } from "./types";
|
|
16
16
|
* - Provide matching results quickly
|
17
17
|
* - Style different data
|
18
18
|
*/
|
19
|
-
export declare const AutoComplete: <O extends Option = Option>({ locale: localeProp, id, name, placeholder, autoFocus, inputValue: inputValueProp, onTextChange, onFocus, onBlur, disabled, clearable, renderValueTemplate, noWrap, separatorKeys, multiple, value, selectOnBlur, onChange, options, optionItemComponent, creatable, createFromInputValue, emptyState, maxResults: maxItems, menuFooter, menuSize, variant, icon: Icon, endItem, className, menuClassName, valuesClassName, internalsRef, }: AutoCompleteProps<O>) => JSX.Element;
|
19
|
+
export declare const AutoComplete: <O extends Option = Option>({ locale: localeProp, id, labelId, "aria-label": ariaLabel, name, placeholder, autoFocus, inputValue: inputValueProp, onTextChange, onFocus, onBlur, disabled, clearable, renderValueTemplate, noWrap, separatorKeys, multiple, value, selectOnBlur, onChange, options, optionItemComponent, creatable, createFromInputValue, emptyState, maxResults: maxItems, menuFooter, menuSize, variant, icon: Icon, endItem, className, menuClassName, valuesClassName, internalsRef, }: AutoCompleteProps<O>) => JSX.Element;
|
20
20
|
export default AutoComplete;
|
@@ -69,6 +69,8 @@ var updateRef = function updateRef(ref, value) {
|
|
69
69
|
var AutoComplete = exports.AutoComplete = function AutoComplete(_ref) {
|
70
70
|
var localeProp = _ref.locale,
|
71
71
|
id = _ref.id,
|
72
|
+
labelId = _ref.labelId,
|
73
|
+
ariaLabel = _ref["aria-label"],
|
72
74
|
name = _ref.name,
|
73
75
|
placeholder = _ref.placeholder,
|
74
76
|
autoFocus = _ref.autoFocus,
|
@@ -103,8 +105,9 @@ var AutoComplete = exports.AutoComplete = function AutoComplete(_ref) {
|
|
103
105
|
valuesClassName = _ref.valuesClassName,
|
104
106
|
internalsRef = _ref.internalsRef;
|
105
107
|
var createPortal = (0, _Satellite.useCreatePortal)();
|
106
|
-
var
|
107
|
-
status =
|
108
|
+
var _useField = (0, _Field.useField)(),
|
109
|
+
status = _useField.state.status,
|
110
|
+
fieldLabelId = _useField.labelId;
|
108
111
|
var localeContext = (0, _Satellite.useLocale)("autoComplete");
|
109
112
|
var locale = (0, _react.useMemo)(function () {
|
110
113
|
return _objectSpread(_objectSpread(_objectSpread({}, _utils.DEFAULT_AUTOCOMPLETE_LOCALE), localeContext), localeProp);
|
@@ -120,6 +123,9 @@ var AutoComplete = exports.AutoComplete = function AutoComplete(_ref) {
|
|
120
123
|
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
121
124
|
internalInputValue = _useState4[0],
|
122
125
|
setInternalInputValue = _useState4[1];
|
126
|
+
(0, _react.useEffect)(function () {
|
127
|
+
return setInternalInputValue((inputValueProp !== null && inputValueProp !== void 0 ? inputValueProp : multiple) ? "" : value ? (0, _utils.optionToString)(value) : "");
|
128
|
+
}, [multiple, inputValueProp, value]);
|
123
129
|
var inputValue = inputValueProp !== null && inputValueProp !== void 0 ? inputValueProp : internalInputValue;
|
124
130
|
var _useState5 = (0, _react.useState)(null),
|
125
131
|
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
|
@@ -172,6 +178,8 @@ var AutoComplete = exports.AutoComplete = function AutoComplete(_ref) {
|
|
172
178
|
}
|
173
179
|
});
|
174
180
|
var combobox = (0, _downshift.useCombobox)({
|
181
|
+
inputId: id,
|
182
|
+
labelId: labelId !== null && labelId !== void 0 ? labelId : fieldLabelId,
|
175
183
|
items: items,
|
176
184
|
itemToString: _utils.optionToString,
|
177
185
|
scrollIntoView: function scrollIntoView(node) {
|
@@ -252,7 +260,9 @@ var AutoComplete = exports.AutoComplete = function AutoComplete(_ref) {
|
|
252
260
|
return Boolean(item.disabled);
|
253
261
|
}
|
254
262
|
});
|
255
|
-
var inputProps = combobox.getInputProps(
|
263
|
+
var inputProps = combobox.getInputProps(_objectSpread({
|
264
|
+
"aria-label": ariaLabel
|
265
|
+
}, multipleSelection.getDropdownProps({
|
256
266
|
ref: inputRef,
|
257
267
|
autoFocus: autoFocus,
|
258
268
|
disabled: disabled,
|
@@ -284,7 +294,7 @@ var AutoComplete = exports.AutoComplete = function AutoComplete(_ref) {
|
|
284
294
|
}
|
285
295
|
}
|
286
296
|
}
|
287
|
-
}));
|
297
|
+
})));
|
288
298
|
(0, _react.useEffect)(function () {
|
289
299
|
if (!combobox.isOpen) return;
|
290
300
|
if (items.length === 0 && combobox.highlightedIndex >= 0) {
|
@@ -3,4 +3,5 @@ export * from "./components/DefaultOptionItem";
|
|
3
3
|
export * from "./components/AutoCompleteEmptyState";
|
4
4
|
export * from "./components/AutocompleteContext";
|
5
5
|
export * from "./types";
|
6
|
+
export { defaultCreateFromInputValue } from "./utils";
|
6
7
|
export { default } from "./AutoComplete";
|
@@ -4,13 +4,21 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
5
5
|
value: true
|
6
6
|
});
|
7
|
-
var _exportNames = {
|
7
|
+
var _exportNames = {
|
8
|
+
defaultCreateFromInputValue: true
|
9
|
+
};
|
8
10
|
Object.defineProperty(exports, "default", {
|
9
11
|
enumerable: true,
|
10
12
|
get: function get() {
|
11
13
|
return _AutoComplete["default"];
|
12
14
|
}
|
13
15
|
});
|
16
|
+
Object.defineProperty(exports, "defaultCreateFromInputValue", {
|
17
|
+
enumerable: true,
|
18
|
+
get: function get() {
|
19
|
+
return _utils.defaultCreateFromInputValue;
|
20
|
+
}
|
21
|
+
});
|
14
22
|
var _AutoComplete = _interopRequireWildcard(require("./AutoComplete"));
|
15
23
|
Object.keys(_AutoComplete).forEach(function (key) {
|
16
24
|
if (key === "default" || key === "__esModule") return;
|
@@ -71,5 +79,6 @@ Object.keys(_types).forEach(function (key) {
|
|
71
79
|
}
|
72
80
|
});
|
73
81
|
});
|
82
|
+
var _utils = require("./utils");
|
74
83
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
75
84
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
package/cjs/Checkbox/Checkbox.js
CHANGED
@@ -49,8 +49,9 @@ var Checkbox = exports.Checkbox = /*#__PURE__*/(0, _react.forwardRef)(function (
|
|
49
49
|
var id = (0, _react.useMemo)(function () {
|
50
50
|
return checkboxProps.id || generateFieldId();
|
51
51
|
}, [checkboxProps.id]);
|
52
|
-
var
|
53
|
-
status =
|
52
|
+
var _useField = (0, _Field.useField)(),
|
53
|
+
status = _useField.state.status,
|
54
|
+
labelId = _useField.labelId;
|
54
55
|
var isControlled = typeof checked === "boolean";
|
55
56
|
var _useState = (0, _react.useState)(Boolean(isControlled ? checked : defaultChecked)),
|
56
57
|
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
@@ -78,6 +79,7 @@ var Checkbox = exports.Checkbox = /*#__PURE__*/(0, _react.forwardRef)(function (
|
|
78
79
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", _objectSpread(_objectSpread({}, checkboxProps), {}, {
|
79
80
|
"aria-checked": indeterminate ? "mixed" : isChecked,
|
80
81
|
id: id,
|
82
|
+
"aria-labelledby": labelId,
|
81
83
|
className: (0, _satellitePrefixer["default"])(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2["default"])(["\n opacity-0 absolute inset-0\n ", "\n "])), disabled ? "cursor-not-allowed" : "cursor-pointer"),
|
82
84
|
type: "checkbox",
|
83
85
|
ref: ref,
|
package/cjs/Dropzone/Dropzone.js
CHANGED
@@ -70,8 +70,9 @@ var Dropzone = exports.Dropzone = function Dropzone(_ref2) {
|
|
70
70
|
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
71
71
|
focused = _useState4[0],
|
72
72
|
setFocused = _useState4[1];
|
73
|
-
var
|
74
|
-
status =
|
73
|
+
var _useField = (0, _Field.useField)(),
|
74
|
+
status = _useField.state.status,
|
75
|
+
labelId = _useField.labelId;
|
75
76
|
var onDrop = (0, _react.useCallback)(function (acceptedFiles, fileRejections) {
|
76
77
|
var updatedFiles = multiple ? [].concat((0, _toConsumableArray2["default"])(files), (0, _toConsumableArray2["default"])(acceptedFiles)) : acceptedFiles;
|
77
78
|
setFiles(updatedFiles);
|
@@ -110,6 +111,7 @@ var Dropzone = exports.Dropzone = function Dropzone(_ref2) {
|
|
110
111
|
})), {}, {
|
111
112
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", _objectSpread({}, getInputProps({
|
112
113
|
id: dropzoneId,
|
114
|
+
"aria-labelledby": labelId,
|
113
115
|
onFocus: function onFocus() {
|
114
116
|
return setFocused(true);
|
115
117
|
},
|
package/cjs/Field/Field.d.ts
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
import type
|
2
|
-
import type { FieldState } from "./
|
1
|
+
import { type ReactChild, type ReactNode, type VFC } from "react";
|
2
|
+
import type { FieldState } from "./FieldContext";
|
3
3
|
export interface FieldProps {
|
4
4
|
/** @ignore */
|
5
5
|
className?: string;
|
6
6
|
/** Label to display above the nested input */
|
7
7
|
label?: ReactChild;
|
8
|
+
labelId?: string;
|
8
9
|
labelFor?: string;
|
9
10
|
/** Helpful description to show below the `Field` */
|
10
11
|
description?: ReactNode;
|
package/cjs/Field/Field.js
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
6
5
|
value: true
|
7
6
|
});
|
8
7
|
exports["default"] = exports.Field = void 0;
|
9
8
|
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
10
9
|
var _clsx = _interopRequireDefault(require("clsx"));
|
10
|
+
var _react = require("react");
|
11
11
|
var _reactFeather = require("react-feather");
|
12
12
|
var _satellitePrefixer = _interopRequireDefault(require("../styles/helpers/satellitePrefixer"));
|
13
|
-
var
|
13
|
+
var _utils = require("../utils");
|
14
|
+
var _FieldContext = require("./FieldContext");
|
14
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
15
16
|
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9;
|
16
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
17
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
18
17
|
/**
|
19
18
|
* Use text fields to help users enter, select, and search for text. Text fields are normally found within a form but can also be part of a modal, search, or card
|
20
19
|
*
|
@@ -53,20 +52,31 @@ var Field = exports.Field = function Field(_ref) {
|
|
53
52
|
var className = _ref.className,
|
54
53
|
label = _ref.label,
|
55
54
|
labelFor = _ref.labelFor,
|
55
|
+
labelIdProp = _ref.labelId,
|
56
56
|
description = _ref.description,
|
57
57
|
_ref$state = _ref.state,
|
58
|
-
state = _ref$state === void 0 ?
|
58
|
+
state = _ref$state === void 0 ? _FieldContext.DEFAULT_FIELD_STATE : _ref$state,
|
59
59
|
_ref$inline = _ref.inline,
|
60
60
|
inline = _ref$inline === void 0 ? false : _ref$inline,
|
61
61
|
children = _ref.children;
|
62
|
-
|
63
|
-
|
62
|
+
var hasLabel = !!label;
|
63
|
+
var labelId = (0, _react.useMemo)(
|
64
|
+
// eslint-disable-next-line @algolia/satellite/prefer-stl-helper
|
65
|
+
function () {
|
66
|
+
return hasLabel ? labelIdProp !== null && labelIdProp !== void 0 ? labelIdProp : (0, _utils.uniqueId)("stl-field-label-") : undefined;
|
67
|
+
}, [labelIdProp, hasLabel]);
|
68
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_FieldContext.FieldContext.Provider, {
|
69
|
+
value: {
|
70
|
+
state: state,
|
71
|
+
labelId: labelId
|
72
|
+
},
|
64
73
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
65
74
|
className: className,
|
66
75
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
|
67
76
|
className: (0, _satellitePrefixer["default"])(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["cursor-pointer flex ", ""])), !inline && "flex-col"),
|
68
77
|
htmlFor: labelFor,
|
69
|
-
children: [
|
78
|
+
children: [hasLabel && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
79
|
+
id: labelId,
|
70
80
|
className: (0, _satellitePrefixer["default"])(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["truncate ", ""])), inline ? "mr-2" : "mb-1"),
|
71
81
|
children: label
|
72
82
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
export declare type FieldState = {
|
3
|
+
status: "default";
|
4
|
+
} | {
|
5
|
+
status: "validated";
|
6
|
+
} | {
|
7
|
+
status: "invalid";
|
8
|
+
errors: string[];
|
9
|
+
};
|
10
|
+
export declare type FieldContextValue = {
|
11
|
+
state: FieldState;
|
12
|
+
labelId?: string;
|
13
|
+
};
|
14
|
+
export declare const DEFAULT_FIELD_STATE: FieldState;
|
15
|
+
export declare const DEFAULT_CONTEXT_VALUE: FieldContextValue;
|
16
|
+
export declare const FieldContext: import("react").Context<FieldContextValue>;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.FieldContext = exports.DEFAULT_FIELD_STATE = exports.DEFAULT_CONTEXT_VALUE = void 0;
|
7
|
+
var _react = require("react");
|
8
|
+
var DEFAULT_FIELD_STATE = exports.DEFAULT_FIELD_STATE = {
|
9
|
+
status: "default"
|
10
|
+
};
|
11
|
+
var DEFAULT_CONTEXT_VALUE = exports.DEFAULT_CONTEXT_VALUE = {
|
12
|
+
state: DEFAULT_FIELD_STATE
|
13
|
+
};
|
14
|
+
var FieldContext = exports.FieldContext = /*#__PURE__*/(0, _react.createContext)(DEFAULT_CONTEXT_VALUE);
|
package/cjs/Field/index.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
export * from "./Field";
|
2
|
-
export
|
3
|
-
export
|
2
|
+
export type { FieldState, FieldContextValue } from "./FieldContext";
|
3
|
+
export { FieldContext } from "./FieldContext";
|
4
|
+
export * from "./useField";
|
4
5
|
export { default } from "./Field";
|
package/cjs/Field/index.js
CHANGED
@@ -4,7 +4,15 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
5
5
|
value: true
|
6
6
|
});
|
7
|
-
var _exportNames = {
|
7
|
+
var _exportNames = {
|
8
|
+
FieldContext: true
|
9
|
+
};
|
10
|
+
Object.defineProperty(exports, "FieldContext", {
|
11
|
+
enumerable: true,
|
12
|
+
get: function get() {
|
13
|
+
return _FieldContext.FieldContext;
|
14
|
+
}
|
15
|
+
});
|
8
16
|
Object.defineProperty(exports, "default", {
|
9
17
|
enumerable: true,
|
10
18
|
get: function get() {
|
@@ -23,27 +31,16 @@ Object.keys(_Field).forEach(function (key) {
|
|
23
31
|
}
|
24
32
|
});
|
25
33
|
});
|
26
|
-
var
|
27
|
-
|
28
|
-
|
29
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
30
|
-
if (key in exports && exports[key] === _FieldStateContext[key]) return;
|
31
|
-
Object.defineProperty(exports, key, {
|
32
|
-
enumerable: true,
|
33
|
-
get: function get() {
|
34
|
-
return _FieldStateContext[key];
|
35
|
-
}
|
36
|
-
});
|
37
|
-
});
|
38
|
-
var _useFieldState = require("./useFieldState");
|
39
|
-
Object.keys(_useFieldState).forEach(function (key) {
|
34
|
+
var _FieldContext = require("./FieldContext");
|
35
|
+
var _useField = require("./useField");
|
36
|
+
Object.keys(_useField).forEach(function (key) {
|
40
37
|
if (key === "default" || key === "__esModule") return;
|
41
38
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
42
|
-
if (key in exports && exports[key] ===
|
39
|
+
if (key in exports && exports[key] === _useField[key]) return;
|
43
40
|
Object.defineProperty(exports, key, {
|
44
41
|
enumerable: true,
|
45
42
|
get: function get() {
|
46
|
-
return
|
43
|
+
return _useField[key];
|
47
44
|
}
|
48
45
|
});
|
49
46
|
});
|
@@ -0,0 +1,11 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useField = void 0;
|
7
|
+
var _react = require("react");
|
8
|
+
var _FieldContext = require("./FieldContext");
|
9
|
+
var useField = exports.useField = function useField() {
|
10
|
+
return (0, _react.useContext)(_FieldContext.FieldContext);
|
11
|
+
};
|
package/cjs/Input/Input.js
CHANGED
@@ -13,7 +13,7 @@ var _clsx = _interopRequireDefault(require("clsx"));
|
|
13
13
|
var _react = require("react");
|
14
14
|
var _reactFeather = require("react-feather");
|
15
15
|
var _Button = require("../Button");
|
16
|
-
var
|
16
|
+
var _Field = require("../Field");
|
17
17
|
var _Satellite = require("../Satellite");
|
18
18
|
var _satellitePrefixer = _interopRequireDefault(require("../styles/helpers/satellitePrefixer"));
|
19
19
|
var _isNil = _interopRequireDefault(require("../utils/isNil"));
|
@@ -88,8 +88,9 @@ var Input = exports.Input = /*#__PURE__*/(0, _react.forwardRef)(function (_ref,
|
|
88
88
|
inputRefCallback = _useForwardedRef2[0],
|
89
89
|
inputRef = _useForwardedRef2[1];
|
90
90
|
var triggerInputChange = (0, _useTriggerInputChange["default"])(inputRef);
|
91
|
-
var
|
92
|
-
status =
|
91
|
+
var _useField = (0, _Field.useField)(),
|
92
|
+
status = _useField.state.status,
|
93
|
+
labelId = _useField.labelId;
|
93
94
|
var isControlled = ("value" in inputProps);
|
94
95
|
var _useState3 = (0, _react.useState)(function () {
|
95
96
|
return isControlled ? inputProps.value : inputProps.defaultValue;
|
@@ -121,7 +122,8 @@ var Input = exports.Input = /*#__PURE__*/(0, _react.forwardRef)(function (_ref,
|
|
121
122
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", _objectSpread(_objectSpread({
|
122
123
|
className: (0, _satellitePrefixer["default"])(_templateObject9 || (_templateObject9 = (0, _taggedTemplateLiteral2["default"])(["mx-4 no-search-input-decoration"]))),
|
123
124
|
ref: inputRefCallback,
|
124
|
-
type: type
|
125
|
+
type: type,
|
126
|
+
"aria-labelledby": labelId
|
125
127
|
}, inputProps), {}, {
|
126
128
|
readOnly: readOnly,
|
127
129
|
disabled: disabled,
|
@@ -16,5 +16,5 @@ import type { AutoCompleteProps, Option } from "./types";
|
|
16
16
|
* - Provide matching results quickly
|
17
17
|
* - Style different data
|
18
18
|
*/
|
19
|
-
export declare const AutoComplete: <O extends Option = Option>({ locale: localeProp, id, name, placeholder, autoFocus, inputValue: inputValueProp, onTextChange, onFocus, onBlur, disabled, clearable, renderValueTemplate, noWrap, separatorKeys, multiple, value, selectOnBlur, onChange, options, optionItemComponent, creatable, createFromInputValue, emptyState, maxResults: maxItems, menuFooter, menuSize, variant, icon: Icon, endItem, className, menuClassName, valuesClassName, internalsRef, }: AutoCompleteProps<O>) => JSX.Element;
|
19
|
+
export declare const AutoComplete: <O extends Option = Option>({ locale: localeProp, id, labelId, "aria-label": ariaLabel, name, placeholder, autoFocus, inputValue: inputValueProp, onTextChange, onFocus, onBlur, disabled, clearable, renderValueTemplate, noWrap, separatorKeys, multiple, value, selectOnBlur, onChange, options, optionItemComponent, creatable, createFromInputValue, emptyState, maxResults: maxItems, menuFooter, menuSize, variant, icon: Icon, endItem, className, menuClassName, valuesClassName, internalsRef, }: AutoCompleteProps<O>) => JSX.Element;
|
20
20
|
export default AutoComplete;
|
@@ -13,7 +13,7 @@ import { usePopper } from "react-popper";
|
|
13
13
|
import useMeasure from "react-use/lib/useMeasure";
|
14
14
|
import { Card } from "../Card";
|
15
15
|
import { ClickAwayContainer } from "../ClickAwayContainer";
|
16
|
-
import {
|
16
|
+
import { useField } from "../Field";
|
17
17
|
import { useCreatePortal, useLocale } from "../Satellite";
|
18
18
|
import ScrollIndicator from "../ScrollIndicator";
|
19
19
|
import stl from "../styles/helpers/satellitePrefixer";
|
@@ -63,6 +63,8 @@ var updateRef = function updateRef(ref, value) {
|
|
63
63
|
export var AutoComplete = function AutoComplete(_ref) {
|
64
64
|
var localeProp = _ref.locale,
|
65
65
|
id = _ref.id,
|
66
|
+
labelId = _ref.labelId,
|
67
|
+
ariaLabel = _ref["aria-label"],
|
66
68
|
name = _ref.name,
|
67
69
|
placeholder = _ref.placeholder,
|
68
70
|
autoFocus = _ref.autoFocus,
|
@@ -97,8 +99,9 @@ export var AutoComplete = function AutoComplete(_ref) {
|
|
97
99
|
valuesClassName = _ref.valuesClassName,
|
98
100
|
internalsRef = _ref.internalsRef;
|
99
101
|
var createPortal = useCreatePortal();
|
100
|
-
var
|
101
|
-
status =
|
102
|
+
var _useField = useField(),
|
103
|
+
status = _useField.state.status,
|
104
|
+
fieldLabelId = _useField.labelId;
|
102
105
|
var localeContext = useLocale("autoComplete");
|
103
106
|
var locale = useMemo(function () {
|
104
107
|
return _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_AUTOCOMPLETE_LOCALE), localeContext), localeProp);
|
@@ -114,6 +117,9 @@ export var AutoComplete = function AutoComplete(_ref) {
|
|
114
117
|
_useState4 = _slicedToArray(_useState3, 2),
|
115
118
|
internalInputValue = _useState4[0],
|
116
119
|
setInternalInputValue = _useState4[1];
|
120
|
+
useEffect(function () {
|
121
|
+
return setInternalInputValue((inputValueProp !== null && inputValueProp !== void 0 ? inputValueProp : multiple) ? "" : value ? optionToString(value) : "");
|
122
|
+
}, [multiple, inputValueProp, value]);
|
117
123
|
var inputValue = inputValueProp !== null && inputValueProp !== void 0 ? inputValueProp : internalInputValue;
|
118
124
|
var _useState5 = useState(null),
|
119
125
|
_useState6 = _slicedToArray(_useState5, 2),
|
@@ -166,6 +172,8 @@ export var AutoComplete = function AutoComplete(_ref) {
|
|
166
172
|
}
|
167
173
|
});
|
168
174
|
var combobox = useCombobox({
|
175
|
+
inputId: id,
|
176
|
+
labelId: labelId !== null && labelId !== void 0 ? labelId : fieldLabelId,
|
169
177
|
items: items,
|
170
178
|
itemToString: optionToString,
|
171
179
|
scrollIntoView: function scrollIntoView(node) {
|
@@ -246,7 +254,9 @@ export var AutoComplete = function AutoComplete(_ref) {
|
|
246
254
|
return Boolean(item.disabled);
|
247
255
|
}
|
248
256
|
});
|
249
|
-
var inputProps = combobox.getInputProps(
|
257
|
+
var inputProps = combobox.getInputProps(_objectSpread({
|
258
|
+
"aria-label": ariaLabel
|
259
|
+
}, multipleSelection.getDropdownProps({
|
250
260
|
ref: inputRef,
|
251
261
|
autoFocus: autoFocus,
|
252
262
|
disabled: disabled,
|
@@ -278,7 +288,7 @@ export var AutoComplete = function AutoComplete(_ref) {
|
|
278
288
|
}
|
279
289
|
}
|
280
290
|
}
|
281
|
-
}));
|
291
|
+
})));
|
282
292
|
useEffect(function () {
|
283
293
|
if (!combobox.isOpen) return;
|
284
294
|
if (items.length === 0 && combobox.highlightedIndex >= 0) {
|
@@ -3,4 +3,5 @@ export * from "./components/DefaultOptionItem";
|
|
3
3
|
export * from "./components/AutoCompleteEmptyState";
|
4
4
|
export * from "./components/AutocompleteContext";
|
5
5
|
export * from "./types";
|
6
|
+
export { defaultCreateFromInputValue } from "./utils";
|
6
7
|
export { default } from "./AutoComplete";
|
@@ -3,4 +3,5 @@ export * from "./components/DefaultOptionItem";
|
|
3
3
|
export * from "./components/AutoCompleteEmptyState";
|
4
4
|
export * from "./components/AutocompleteContext";
|
5
5
|
export * from "./types";
|
6
|
+
export { defaultCreateFromInputValue } from "./utils";
|
6
7
|
export { default } from "./AutoComplete";
|
package/esm/Checkbox/Checkbox.js
CHANGED
@@ -9,7 +9,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
9
9
|
import cx from "clsx";
|
10
10
|
import { forwardRef, useMemo, useState } from "react";
|
11
11
|
import { Check, Minus } from "react-feather";
|
12
|
-
import {
|
12
|
+
import { useField } from "../Field";
|
13
13
|
import stl from "../styles/helpers/satellitePrefixer";
|
14
14
|
import isRenderedChild from "../utils/isRenderedChild";
|
15
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
@@ -43,8 +43,9 @@ export var Checkbox = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
43
43
|
var id = useMemo(function () {
|
44
44
|
return checkboxProps.id || generateFieldId();
|
45
45
|
}, [checkboxProps.id]);
|
46
|
-
var
|
47
|
-
status =
|
46
|
+
var _useField = useField(),
|
47
|
+
status = _useField.state.status,
|
48
|
+
labelId = _useField.labelId;
|
48
49
|
var isControlled = typeof checked === "boolean";
|
49
50
|
var _useState = useState(Boolean(isControlled ? checked : defaultChecked)),
|
50
51
|
_useState2 = _slicedToArray(_useState, 2),
|
@@ -72,6 +73,7 @@ export var Checkbox = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
72
73
|
}), /*#__PURE__*/_jsx("input", _objectSpread(_objectSpread({}, checkboxProps), {}, {
|
73
74
|
"aria-checked": indeterminate ? "mixed" : isChecked,
|
74
75
|
id: id,
|
76
|
+
"aria-labelledby": labelId,
|
75
77
|
className: stl(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n opacity-0 absolute inset-0\n ", "\n "])), disabled ? "cursor-not-allowed" : "cursor-pointer"),
|
76
78
|
type: "checkbox",
|
77
79
|
ref: ref,
|
package/esm/Dropzone/Dropzone.js
CHANGED
@@ -12,7 +12,7 @@ import { Fragment, useCallback, useMemo, useState } from "react";
|
|
12
12
|
import { useDropzone } from "react-dropzone";
|
13
13
|
import { Check, UploadCloud, X } from "react-feather";
|
14
14
|
import { IconButton } from "../Button";
|
15
|
-
import {
|
15
|
+
import { useField } from "../Field";
|
16
16
|
import { useLocale } from "../Satellite";
|
17
17
|
import stl from "../styles/helpers/satellitePrefixer";
|
18
18
|
import { formatHumanSize } from "../utils/formatters";
|
@@ -64,8 +64,9 @@ export var Dropzone = function Dropzone(_ref2) {
|
|
64
64
|
_useState4 = _slicedToArray(_useState3, 2),
|
65
65
|
focused = _useState4[0],
|
66
66
|
setFocused = _useState4[1];
|
67
|
-
var
|
68
|
-
status =
|
67
|
+
var _useField = useField(),
|
68
|
+
status = _useField.state.status,
|
69
|
+
labelId = _useField.labelId;
|
69
70
|
var onDrop = useCallback(function (acceptedFiles, fileRejections) {
|
70
71
|
var updatedFiles = multiple ? [].concat(_toConsumableArray(files), _toConsumableArray(acceptedFiles)) : acceptedFiles;
|
71
72
|
setFiles(updatedFiles);
|
@@ -104,6 +105,7 @@ export var Dropzone = function Dropzone(_ref2) {
|
|
104
105
|
})), {}, {
|
105
106
|
children: [/*#__PURE__*/_jsx("input", _objectSpread({}, getInputProps({
|
106
107
|
id: dropzoneId,
|
108
|
+
"aria-labelledby": labelId,
|
107
109
|
onFocus: function onFocus() {
|
108
110
|
return setFocused(true);
|
109
111
|
},
|
package/esm/Field/Field.d.ts
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
import type
|
2
|
-
import type { FieldState } from "./
|
1
|
+
import { type ReactChild, type ReactNode, type VFC } from "react";
|
2
|
+
import type { FieldState } from "./FieldContext";
|
3
3
|
export interface FieldProps {
|
4
4
|
/** @ignore */
|
5
5
|
className?: string;
|
6
6
|
/** Label to display above the nested input */
|
7
7
|
label?: ReactChild;
|
8
|
+
labelId?: string;
|
8
9
|
labelFor?: string;
|
9
10
|
/** Helpful description to show below the `Field` */
|
10
11
|
description?: ReactNode;
|
package/esm/Field/Field.js
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
|
2
2
|
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9;
|
3
3
|
import cx from "clsx";
|
4
|
+
import { useMemo } from "react";
|
4
5
|
import { AlertCircle } from "react-feather";
|
5
6
|
import stl from "../styles/helpers/satellitePrefixer";
|
6
|
-
import
|
7
|
+
import { uniqueId } from "../utils";
|
8
|
+
import { DEFAULT_FIELD_STATE, FieldContext } from "./FieldContext";
|
7
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
8
10
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
9
11
|
/**
|
@@ -44,20 +46,31 @@ export var Field = function Field(_ref) {
|
|
44
46
|
var className = _ref.className,
|
45
47
|
label = _ref.label,
|
46
48
|
labelFor = _ref.labelFor,
|
49
|
+
labelIdProp = _ref.labelId,
|
47
50
|
description = _ref.description,
|
48
51
|
_ref$state = _ref.state,
|
49
|
-
state = _ref$state === void 0 ?
|
52
|
+
state = _ref$state === void 0 ? DEFAULT_FIELD_STATE : _ref$state,
|
50
53
|
_ref$inline = _ref.inline,
|
51
54
|
inline = _ref$inline === void 0 ? false : _ref$inline,
|
52
55
|
children = _ref.children;
|
53
|
-
|
54
|
-
|
56
|
+
var hasLabel = !!label;
|
57
|
+
var labelId = useMemo(
|
58
|
+
// eslint-disable-next-line @algolia/satellite/prefer-stl-helper
|
59
|
+
function () {
|
60
|
+
return hasLabel ? labelIdProp !== null && labelIdProp !== void 0 ? labelIdProp : uniqueId("stl-field-label-") : undefined;
|
61
|
+
}, [labelIdProp, hasLabel]);
|
62
|
+
return /*#__PURE__*/_jsx(FieldContext.Provider, {
|
63
|
+
value: {
|
64
|
+
state: state,
|
65
|
+
labelId: labelId
|
66
|
+
},
|
55
67
|
children: /*#__PURE__*/_jsxs("div", {
|
56
68
|
className: className,
|
57
69
|
children: [/*#__PURE__*/_jsxs("label", {
|
58
70
|
className: stl(_templateObject || (_templateObject = _taggedTemplateLiteral(["cursor-pointer flex ", ""])), !inline && "flex-col"),
|
59
71
|
htmlFor: labelFor,
|
60
|
-
children: [
|
72
|
+
children: [hasLabel && /*#__PURE__*/_jsx("div", {
|
73
|
+
id: labelId,
|
61
74
|
className: stl(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["truncate ", ""])), inline ? "mr-2" : "mb-1"),
|
62
75
|
children: label
|
63
76
|
}), /*#__PURE__*/_jsx("div", {
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
export declare type FieldState = {
|
3
|
+
status: "default";
|
4
|
+
} | {
|
5
|
+
status: "validated";
|
6
|
+
} | {
|
7
|
+
status: "invalid";
|
8
|
+
errors: string[];
|
9
|
+
};
|
10
|
+
export declare type FieldContextValue = {
|
11
|
+
state: FieldState;
|
12
|
+
labelId?: string;
|
13
|
+
};
|
14
|
+
export declare const DEFAULT_FIELD_STATE: FieldState;
|
15
|
+
export declare const DEFAULT_CONTEXT_VALUE: FieldContextValue;
|
16
|
+
export declare const FieldContext: import("react").Context<FieldContextValue>;
|
package/esm/Field/index.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
export * from "./Field";
|
2
|
-
export
|
3
|
-
export
|
2
|
+
export type { FieldState, FieldContextValue } from "./FieldContext";
|
3
|
+
export { FieldContext } from "./FieldContext";
|
4
|
+
export * from "./useField";
|
4
5
|
export { default } from "./Field";
|
package/esm/Field/index.js
CHANGED
package/esm/Input/Input.js
CHANGED
@@ -10,7 +10,7 @@ import cx from "clsx";
|
|
10
10
|
import { forwardRef, Fragment, useEffect, useState } from "react";
|
11
11
|
import { Check, ChevronDown, ChevronUp, Search, X } from "react-feather";
|
12
12
|
import { IconButton } from "../Button";
|
13
|
-
import
|
13
|
+
import { useField } from "../Field";
|
14
14
|
import { useLocale } from "../Satellite";
|
15
15
|
import stl from "../styles/helpers/satellitePrefixer";
|
16
16
|
import isNil from "../utils/isNil";
|
@@ -82,8 +82,9 @@ export var Input = /*#__PURE__*/forwardRef(function (_ref, externalRef) {
|
|
82
82
|
inputRefCallback = _useForwardedRef2[0],
|
83
83
|
inputRef = _useForwardedRef2[1];
|
84
84
|
var triggerInputChange = useTriggerInputChange(inputRef);
|
85
|
-
var
|
86
|
-
status =
|
85
|
+
var _useField = useField(),
|
86
|
+
status = _useField.state.status,
|
87
|
+
labelId = _useField.labelId;
|
87
88
|
var isControlled = ("value" in inputProps);
|
88
89
|
var _useState3 = useState(function () {
|
89
90
|
return isControlled ? inputProps.value : inputProps.defaultValue;
|
@@ -115,7 +116,8 @@ export var Input = /*#__PURE__*/forwardRef(function (_ref, externalRef) {
|
|
115
116
|
}), /*#__PURE__*/_jsx("input", _objectSpread(_objectSpread({
|
116
117
|
className: stl(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["mx-4 no-search-input-decoration"]))),
|
117
118
|
ref: inputRefCallback,
|
118
|
-
type: type
|
119
|
+
type: type,
|
120
|
+
"aria-labelledby": labelId
|
119
121
|
}, inputProps), {}, {
|
120
122
|
readOnly: readOnly,
|
121
123
|
disabled: disabled,
|
package/package.json
CHANGED
@@ -1,12 +0,0 @@
|
|
1
|
-
/// <reference types="react" />
|
2
|
-
export declare type FieldState = {
|
3
|
-
status: "default";
|
4
|
-
} | {
|
5
|
-
status: "validated";
|
6
|
-
} | {
|
7
|
-
status: "invalid";
|
8
|
-
errors: string[];
|
9
|
-
};
|
10
|
-
export declare const DEFAULT_STATE: FieldState;
|
11
|
-
export declare const FieldStateContext: import("react").Context<FieldState>;
|
12
|
-
export default FieldStateContext;
|
@@ -1,12 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports["default"] = exports.FieldStateContext = exports.DEFAULT_STATE = void 0;
|
7
|
-
var _react = require("react");
|
8
|
-
var DEFAULT_STATE = exports.DEFAULT_STATE = {
|
9
|
-
status: "default"
|
10
|
-
};
|
11
|
-
var FieldStateContext = exports.FieldStateContext = /*#__PURE__*/(0, _react.createContext)(DEFAULT_STATE);
|
12
|
-
var _default = exports["default"] = FieldStateContext;
|
@@ -1,15 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
5
|
-
value: true
|
6
|
-
});
|
7
|
-
exports.useFieldState = exports["default"] = void 0;
|
8
|
-
var _react = require("react");
|
9
|
-
var _FieldStateContext = _interopRequireWildcard(require("./FieldStateContext"));
|
10
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
11
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
12
|
-
var useFieldState = exports.useFieldState = function useFieldState() {
|
13
|
-
return (0, _react.useContext)(_FieldStateContext["default"]) || _FieldStateContext.DEFAULT_STATE;
|
14
|
-
};
|
15
|
-
var _default = exports["default"] = useFieldState;
|
@@ -1,12 +0,0 @@
|
|
1
|
-
/// <reference types="react" />
|
2
|
-
export declare type FieldState = {
|
3
|
-
status: "default";
|
4
|
-
} | {
|
5
|
-
status: "validated";
|
6
|
-
} | {
|
7
|
-
status: "invalid";
|
8
|
-
errors: string[];
|
9
|
-
};
|
10
|
-
export declare const DEFAULT_STATE: FieldState;
|
11
|
-
export declare const FieldStateContext: import("react").Context<FieldState>;
|
12
|
-
export default FieldStateContext;
|