@redsift/pickers 11.5.0 → 11.6.0-muiv5-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_virtual/_rollupPluginBabelHelpers.js +93 -0
- package/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
- package/components/combobox/Combobox.d.ts +29 -0
- package/components/combobox/Combobox.js +151 -0
- package/components/combobox/Combobox.js.map +1 -0
- package/components/combobox/context.js +6 -0
- package/components/combobox/context.js.map +1 -0
- package/components/combobox/intl/en-US.json.js +13 -0
- package/components/combobox/intl/en-US.json.js.map +1 -0
- package/components/combobox/intl/fr-FR.json.js +13 -0
- package/components/combobox/intl/fr-FR.json.js.map +1 -0
- package/components/combobox/intl/index.js +10 -0
- package/components/combobox/intl/index.js.map +1 -0
- package/components/combobox/types.d.ts +107 -0
- package/components/combobox/types.js +22 -0
- package/components/combobox/types.js.map +1 -0
- package/components/combobox-content/ComboboxContent.d.ts +17 -0
- package/components/combobox-content/ComboboxContent.js +70 -0
- package/components/combobox-content/ComboboxContent.js.map +1 -0
- package/components/combobox-content/types.d.ts +11 -0
- package/components/combobox-content-footer/ComboboxContentFooter.d.ts +9 -0
- package/components/combobox-content-footer/ComboboxContentFooter.js +28 -0
- package/components/combobox-content-footer/ComboboxContentFooter.js.map +1 -0
- package/components/combobox-content-footer/styles.js +12 -0
- package/components/combobox-content-footer/styles.js.map +1 -0
- package/components/combobox-content-footer/types.d.ts +11 -0
- package/components/combobox-content-header/ComboboxContentHeader.d.ts +9 -0
- package/components/combobox-content-header/ComboboxContentHeader.js +28 -0
- package/components/combobox-content-header/ComboboxContentHeader.js.map +1 -0
- package/components/combobox-content-header/styles.js +12 -0
- package/components/combobox-content-header/styles.js.map +1 -0
- package/components/combobox-content-header/types.d.ts +11 -0
- package/components/combobox-content-listbox/ComboboxContentListbox.d.ts +9 -0
- package/components/combobox-content-listbox/ComboboxContentListbox.js +124 -0
- package/components/combobox-content-listbox/ComboboxContentListbox.js.map +1 -0
- package/components/combobox-content-listbox/types.d.ts +12 -0
- package/components/combobox-trigger/ComboboxTrigger.d.ts +9 -0
- package/components/combobox-trigger/ComboboxTrigger.js +352 -0
- package/components/combobox-trigger/ComboboxTrigger.js.map +1 -0
- package/components/combobox-trigger/types.d.ts +27 -0
- package/components/item/Item.d.ts +8 -0
- package/components/item/Item.js +137 -0
- package/components/item/Item.js.map +1 -0
- package/components/item/useMenuItem.js +69 -0
- package/components/item/useMenuItem.js.map +1 -0
- package/components/menu-button/MenuButton.d.ts +29 -0
- package/components/menu-button/MenuButton.js +76 -0
- package/components/menu-button/MenuButton.js.map +1 -0
- package/components/menu-button/context.js +6 -0
- package/components/menu-button/context.js.map +1 -0
- package/components/menu-button/types.d.ts +45 -0
- package/components/menu-button-content/MenuButtonContent.d.ts +17 -0
- package/components/menu-button-content/MenuButtonContent.js +68 -0
- package/components/menu-button-content/MenuButtonContent.js.map +1 -0
- package/components/menu-button-content/types.d.ts +9 -0
- package/components/menu-button-content-footer/MenuButtonContentFooter.d.ts +9 -0
- package/components/menu-button-content-footer/MenuButtonContentFooter.js +28 -0
- package/components/menu-button-content-footer/MenuButtonContentFooter.js.map +1 -0
- package/components/menu-button-content-footer/styles.js +12 -0
- package/components/menu-button-content-footer/styles.js.map +1 -0
- package/components/menu-button-content-footer/types.d.ts +11 -0
- package/components/menu-button-content-header/MenuButtonContentHeader.d.ts +9 -0
- package/components/menu-button-content-header/MenuButtonContentHeader.js +28 -0
- package/components/menu-button-content-header/MenuButtonContentHeader.js.map +1 -0
- package/components/menu-button-content-header/styles.js +12 -0
- package/components/menu-button-content-header/styles.js.map +1 -0
- package/components/menu-button-content-header/types.d.ts +11 -0
- package/components/menu-button-content-menu/MenuButtonContentMenu.d.ts +9 -0
- package/components/menu-button-content-menu/MenuButtonContentMenu.js +41 -0
- package/components/menu-button-content-menu/MenuButtonContentMenu.js.map +1 -0
- package/components/menu-button-content-menu/types.d.ts +9 -0
- package/components/menu-button-trigger/MenuButtonTrigger.d.ts +9 -0
- package/components/menu-button-trigger/MenuButtonTrigger.js +167 -0
- package/components/menu-button-trigger/MenuButtonTrigger.js.map +1 -0
- package/components/menu-button-trigger/types.d.ts +15 -0
- package/components/select/Select.d.ts +22 -0
- package/components/select/Select.js +116 -0
- package/components/select/Select.js.map +1 -0
- package/components/select/context.js +6 -0
- package/components/select/context.js.map +1 -0
- package/components/select/types.d.ts +61 -0
- package/components/select-content/SelectContent.d.ts +9 -0
- package/components/select-content/SelectContent.js +62 -0
- package/components/select-content/SelectContent.js.map +1 -0
- package/components/select-content/types.d.ts +9 -0
- package/components/select-trigger/SelectTrigger.d.ts +9 -0
- package/components/select-trigger/SelectTrigger.js +249 -0
- package/components/select-trigger/SelectTrigger.js.map +1 -0
- package/components/select-trigger/types.d.ts +17 -0
- package/index.d.ts +31 -438
- package/index.js +17 -1822
- package/index.js.map +1 -1
- package/package.json +8 -8
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) {
|
|
2
|
+
var keys = Object.keys(object);
|
|
3
|
+
if (Object.getOwnPropertySymbols) {
|
|
4
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
5
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
6
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
7
|
+
})), keys.push.apply(keys, symbols);
|
|
8
|
+
}
|
|
9
|
+
return keys;
|
|
10
|
+
}
|
|
11
|
+
function _objectSpread2(target) {
|
|
12
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
13
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
14
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
15
|
+
_defineProperty(target, key, source[key]);
|
|
16
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
17
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return target;
|
|
21
|
+
}
|
|
22
|
+
function _defineProperty(obj, key, value) {
|
|
23
|
+
key = _toPropertyKey(key);
|
|
24
|
+
if (key in obj) {
|
|
25
|
+
Object.defineProperty(obj, key, {
|
|
26
|
+
value: value,
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
obj[key] = value;
|
|
33
|
+
}
|
|
34
|
+
return obj;
|
|
35
|
+
}
|
|
36
|
+
function _extends() {
|
|
37
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
38
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
39
|
+
var source = arguments[i];
|
|
40
|
+
for (var key in source) {
|
|
41
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
42
|
+
target[key] = source[key];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return target;
|
|
47
|
+
};
|
|
48
|
+
return _extends.apply(this, arguments);
|
|
49
|
+
}
|
|
50
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
51
|
+
if (source == null) return {};
|
|
52
|
+
var target = {};
|
|
53
|
+
var sourceKeys = Object.keys(source);
|
|
54
|
+
var key, i;
|
|
55
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
56
|
+
key = sourceKeys[i];
|
|
57
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
58
|
+
target[key] = source[key];
|
|
59
|
+
}
|
|
60
|
+
return target;
|
|
61
|
+
}
|
|
62
|
+
function _objectWithoutProperties(source, excluded) {
|
|
63
|
+
if (source == null) return {};
|
|
64
|
+
var target = _objectWithoutPropertiesLoose(source, excluded);
|
|
65
|
+
var key, i;
|
|
66
|
+
if (Object.getOwnPropertySymbols) {
|
|
67
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
68
|
+
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
|
69
|
+
key = sourceSymbolKeys[i];
|
|
70
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
71
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
72
|
+
target[key] = source[key];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return target;
|
|
76
|
+
}
|
|
77
|
+
function _toPrimitive(input, hint) {
|
|
78
|
+
if (typeof input !== "object" || input === null) return input;
|
|
79
|
+
var prim = input[Symbol.toPrimitive];
|
|
80
|
+
if (prim !== undefined) {
|
|
81
|
+
var res = prim.call(input, hint || "default");
|
|
82
|
+
if (typeof res !== "object") return res;
|
|
83
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
84
|
+
}
|
|
85
|
+
return (hint === "string" ? String : Number)(input);
|
|
86
|
+
}
|
|
87
|
+
function _toPropertyKey(arg) {
|
|
88
|
+
var key = _toPrimitive(arg, "string");
|
|
89
|
+
return typeof key === "symbol" ? key : String(key);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { _defineProperty as defineProperty, _extends as extends, _objectSpread2 as objectSpread2, _objectWithoutProperties as objectWithoutProperties, _objectWithoutPropertiesLoose as objectWithoutPropertiesLoose, _toPrimitive as toPrimitive, _toPropertyKey as toPropertyKey };
|
|
93
|
+
//# sourceMappingURL=_rollupPluginBabelHelpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_rollupPluginBabelHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as _redsift_design_system from '@redsift/design-system';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ComboboxProps } from './types.js';
|
|
4
|
+
import { ComboboxTriggerProps } from '../combobox-trigger/types.js';
|
|
5
|
+
import { ComboboxContentProps } from '../combobox-content/types.js';
|
|
6
|
+
import { ComboboxContentHeaderProps } from '../combobox-content-header/types.js';
|
|
7
|
+
import { ComboboxContentListboxProps } from '../combobox-content-listbox/types.js';
|
|
8
|
+
import { ComboboxContentFooterProps } from '../combobox-content-footer/types.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The Combobox component.
|
|
12
|
+
*/
|
|
13
|
+
declare const BaseCombobox: React.FC<ComboboxProps> & {
|
|
14
|
+
displayName?: string;
|
|
15
|
+
className?: string;
|
|
16
|
+
};
|
|
17
|
+
declare const Combobox: React.FC<ComboboxProps> & {
|
|
18
|
+
displayName?: string | undefined;
|
|
19
|
+
className?: string | undefined;
|
|
20
|
+
} & {
|
|
21
|
+
Trigger: _redsift_design_system.Comp<ComboboxTriggerProps, HTMLButtonElement>;
|
|
22
|
+
Content: _redsift_design_system.Comp<ComboboxContentProps, HTMLDivElement> & {
|
|
23
|
+
Header: _redsift_design_system.Comp<ComboboxContentHeaderProps, HTMLDivElement>;
|
|
24
|
+
Listbox: _redsift_design_system.Comp<ComboboxContentListboxProps, HTMLDivElement>;
|
|
25
|
+
Footer: _redsift_design_system.Comp<ComboboxContentFooterProps, HTMLDivElement>;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { BaseCombobox, Combobox };
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import React, { useState, useEffect, useReducer, useMemo, useRef } from 'react';
|
|
3
|
+
import { ComboboxSelectionMode, ComboboxVariant } from './types.js';
|
|
4
|
+
import { Popover } from '@redsift/popovers';
|
|
5
|
+
import { ComboboxContext } from './context.js';
|
|
6
|
+
import { useTheme, ListboxReducer, ListboxActionType, useId, ThemeProvider, FocusWithinGroup, ListboxContext, Flexbox, Text, Theme } from '@redsift/design-system';
|
|
7
|
+
import { ComboboxTrigger } from '../combobox-trigger/ComboboxTrigger.js';
|
|
8
|
+
import { ComboboxContent } from '../combobox-content/ComboboxContent.js';
|
|
9
|
+
|
|
10
|
+
const COMPONENT_NAME = 'Combobox';
|
|
11
|
+
const CLASSNAME = 'redsift-combobox';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The Combobox component.
|
|
15
|
+
*/
|
|
16
|
+
const BaseCombobox = props => {
|
|
17
|
+
const {
|
|
18
|
+
defaultValue,
|
|
19
|
+
description,
|
|
20
|
+
descriptionProps,
|
|
21
|
+
filter = {
|
|
22
|
+
type: 'startsWith',
|
|
23
|
+
caseSensitive: false
|
|
24
|
+
},
|
|
25
|
+
formRef,
|
|
26
|
+
submitRef,
|
|
27
|
+
inputValue: propsInputValue,
|
|
28
|
+
isDisabled,
|
|
29
|
+
isInvalid,
|
|
30
|
+
maxOptionsLength,
|
|
31
|
+
minWidth = 'trigger-width',
|
|
32
|
+
onChange,
|
|
33
|
+
onInputChange,
|
|
34
|
+
selectionMode = ComboboxSelectionMode.single,
|
|
35
|
+
theme: propsTheme,
|
|
36
|
+
triggerClassName,
|
|
37
|
+
value,
|
|
38
|
+
variant = ComboboxVariant.options,
|
|
39
|
+
wrapperProps
|
|
40
|
+
} = props;
|
|
41
|
+
const theme = useTheme(propsTheme);
|
|
42
|
+
const [selectedValue, setValue] = useState(value || defaultValue || (selectionMode === 'multiple' ? [] : ''));
|
|
43
|
+
const [inputValue, setInputValue] = useState(propsInputValue || '');
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (value) {
|
|
46
|
+
state.setValue(value);
|
|
47
|
+
}
|
|
48
|
+
}, [value]);
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (propsInputValue) {
|
|
51
|
+
state.setInputValue(propsInputValue);
|
|
52
|
+
}
|
|
53
|
+
}, [propsInputValue]);
|
|
54
|
+
|
|
55
|
+
/** Listbox context */
|
|
56
|
+
const [listboxState, listboxDispatch] = useReducer(ListboxReducer, {
|
|
57
|
+
isDisabled,
|
|
58
|
+
selectedValues: selectionMode === ComboboxSelectionMode.multiple ? selectedValue : [selectedValue],
|
|
59
|
+
selectionMode
|
|
60
|
+
});
|
|
61
|
+
const listboxContext = useMemo(() => ({
|
|
62
|
+
state: listboxState,
|
|
63
|
+
dispatch: listboxDispatch
|
|
64
|
+
}), [listboxState]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
listboxDispatch({
|
|
67
|
+
type: ListboxActionType.UPDATE_OPTIONS,
|
|
68
|
+
payload: {
|
|
69
|
+
isDisabled: isDisabled || false
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}, [isDisabled]);
|
|
73
|
+
const freeTextItemRef = useRef();
|
|
74
|
+
const [freeTextItemId] = useId();
|
|
75
|
+
|
|
76
|
+
/** Combobox context. */
|
|
77
|
+
const state = {
|
|
78
|
+
filter,
|
|
79
|
+
formRef,
|
|
80
|
+
submitRef,
|
|
81
|
+
value: selectedValue,
|
|
82
|
+
inputValue,
|
|
83
|
+
isDisabled: isDisabled || false,
|
|
84
|
+
isInvalid: isInvalid || false,
|
|
85
|
+
selectionMode,
|
|
86
|
+
variant,
|
|
87
|
+
freeTextItemRef: freeTextItemRef,
|
|
88
|
+
freeTextItemId,
|
|
89
|
+
triggerClassName,
|
|
90
|
+
setValue(value) {
|
|
91
|
+
if (isDisabled) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const previousValue = selectedValue;
|
|
95
|
+
setValue(value);
|
|
96
|
+
if (value !== previousValue && onChange) {
|
|
97
|
+
onChange(value);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
setInputValue(value) {
|
|
101
|
+
if (isDisabled) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const previousValue = inputValue;
|
|
105
|
+
setInputValue(value);
|
|
106
|
+
if (value !== previousValue && onInputChange) {
|
|
107
|
+
onInputChange(value);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
return /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
112
|
+
value: {
|
|
113
|
+
theme
|
|
114
|
+
}
|
|
115
|
+
}, /*#__PURE__*/React.createElement(FocusWithinGroup, {
|
|
116
|
+
focusType: "virtual-focus",
|
|
117
|
+
focusOnInit: false,
|
|
118
|
+
maxOptionsLength: maxOptionsLength
|
|
119
|
+
}, /*#__PURE__*/React.createElement(ComboboxContext.Provider, {
|
|
120
|
+
value: state
|
|
121
|
+
}, /*#__PURE__*/React.createElement(ListboxContext.Provider, {
|
|
122
|
+
value: listboxContext
|
|
123
|
+
}, /*#__PURE__*/React.createElement(Flexbox, _extends({
|
|
124
|
+
flexDirection: "column",
|
|
125
|
+
alignItems: "flex-start",
|
|
126
|
+
gap: "0px"
|
|
127
|
+
}, wrapperProps), /*#__PURE__*/React.createElement(Popover, _extends({
|
|
128
|
+
theme: theme,
|
|
129
|
+
overrideDisplayName: {
|
|
130
|
+
content: 'ComboboxContent',
|
|
131
|
+
trigger: 'ComboboxTrigger'
|
|
132
|
+
},
|
|
133
|
+
placement: "bottom-start",
|
|
134
|
+
role: "listbox",
|
|
135
|
+
minWidth: minWidth
|
|
136
|
+
}, props)), description && typeof description === 'string' ? /*#__PURE__*/React.createElement(Text, _extends({
|
|
137
|
+
theme: theme,
|
|
138
|
+
marginTop: "8px",
|
|
139
|
+
variant: "caption",
|
|
140
|
+
color: isInvalid ? 'error' : theme === Theme.light ? 'dark-grey' : 'white'
|
|
141
|
+
}, descriptionProps), description) : /*#__PURE__*/React.isValidElement(description) ? description : null)))));
|
|
142
|
+
};
|
|
143
|
+
BaseCombobox.className = CLASSNAME;
|
|
144
|
+
BaseCombobox.displayName = COMPONENT_NAME;
|
|
145
|
+
const Combobox = Object.assign(BaseCombobox, {
|
|
146
|
+
Trigger: ComboboxTrigger,
|
|
147
|
+
Content: ComboboxContent
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
export { BaseCombobox, Combobox };
|
|
151
|
+
//# sourceMappingURL=Combobox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Combobox.js","sources":["../../../src/components/combobox/Combobox.tsx"],"sourcesContent":["import React, { RefObject, useEffect, useMemo, useReducer, useRef, useState } from 'react';\nimport { ComboboxContent } from '../combobox-content';\nimport { ComboboxTrigger } from '../combobox-trigger';\n\nimport { ComboboxProps, ComboboxSelectionMode, ComboboxValue, ComboboxVariant } from './types';\nimport { Popover } from '@redsift/popovers';\nimport { ComboboxContext } from './context';\nimport {\n ListboxReducer,\n ListboxState,\n ListboxContextProps,\n FocusWithinGroup,\n ListboxContext,\n Flexbox,\n Text,\n ListboxActionType,\n Theme,\n useTheme,\n ThemeProvider,\n useId,\n} from '@redsift/design-system';\n\nconst COMPONENT_NAME = 'Combobox';\nconst CLASSNAME = 'redsift-combobox';\n\n/**\n * The Combobox component.\n */\nexport const BaseCombobox: React.FC<ComboboxProps> & {\n displayName?: string;\n className?: string;\n} = (props) => {\n const {\n defaultValue,\n description,\n descriptionProps,\n filter = {\n type: 'startsWith',\n caseSensitive: false,\n },\n formRef,\n submitRef,\n inputValue: propsInputValue,\n isDisabled,\n isInvalid,\n maxOptionsLength,\n minWidth = 'trigger-width',\n onChange,\n onInputChange,\n selectionMode = ComboboxSelectionMode.single,\n theme: propsTheme,\n triggerClassName,\n value,\n variant = ComboboxVariant.options,\n wrapperProps,\n } = props;\n\n const theme = useTheme(propsTheme);\n\n const [selectedValue, setValue] = useState<ComboboxValue>(\n value || defaultValue || (selectionMode === 'multiple' ? [] : '')\n );\n const [inputValue, setInputValue] = useState<string>(propsInputValue || '');\n useEffect(() => {\n if (value) {\n state.setValue(value);\n }\n }, [value]);\n useEffect(() => {\n if (propsInputValue) {\n state.setInputValue(propsInputValue);\n }\n }, [propsInputValue]);\n\n /** Listbox context */\n const [listboxState, listboxDispatch] = useReducer(ListboxReducer, {\n isDisabled,\n selectedValues: selectionMode === ComboboxSelectionMode.multiple ? selectedValue : [selectedValue],\n selectionMode,\n } as ListboxState);\n const listboxContext = useMemo<ListboxContextProps>(\n () => ({\n state: listboxState,\n dispatch: listboxDispatch,\n }),\n [listboxState]\n );\n useEffect(() => {\n listboxDispatch({\n type: ListboxActionType.UPDATE_OPTIONS,\n payload: {\n isDisabled: isDisabled || false,\n },\n });\n }, [isDisabled]);\n\n const freeTextItemRef = useRef<HTMLDivElement>();\n const [freeTextItemId] = useId();\n\n /** Combobox context. */\n const state = {\n filter,\n formRef,\n submitRef,\n value: selectedValue,\n inputValue,\n isDisabled: isDisabled || false,\n isInvalid: isInvalid || false,\n selectionMode,\n variant,\n freeTextItemRef: freeTextItemRef as RefObject<HTMLDivElement>,\n freeTextItemId,\n triggerClassName,\n setValue(value: ComboboxValue) {\n if (isDisabled) {\n return;\n }\n\n const previousValue = selectedValue;\n setValue(value);\n if (value !== previousValue && onChange) {\n onChange(value);\n }\n },\n setInputValue(value: string) {\n if (isDisabled) {\n return;\n }\n\n const previousValue = inputValue;\n setInputValue(value);\n if (value !== previousValue && onInputChange) {\n onInputChange(value);\n }\n },\n };\n\n return (\n <ThemeProvider value={{ theme }}>\n <FocusWithinGroup focusType=\"virtual-focus\" focusOnInit={false} maxOptionsLength={maxOptionsLength}>\n <ComboboxContext.Provider value={state}>\n <ListboxContext.Provider value={listboxContext}>\n <Flexbox flexDirection=\"column\" alignItems=\"flex-start\" gap=\"0px\" {...wrapperProps}>\n <Popover\n theme={theme}\n overrideDisplayName={{ content: 'ComboboxContent', trigger: 'ComboboxTrigger' }}\n placement=\"bottom-start\"\n role=\"listbox\"\n minWidth={minWidth}\n {...props}\n />\n {description && typeof description === 'string' ? (\n <Text\n theme={theme}\n marginTop=\"8px\"\n variant=\"caption\"\n color={isInvalid ? 'error' : theme === Theme.light ? 'dark-grey' : 'white'}\n {...descriptionProps}\n >\n {description}\n </Text>\n ) : React.isValidElement(description) ? (\n description\n ) : null}\n </Flexbox>\n </ListboxContext.Provider>\n </ComboboxContext.Provider>\n </FocusWithinGroup>\n </ThemeProvider>\n );\n};\nBaseCombobox.className = CLASSNAME;\nBaseCombobox.displayName = COMPONENT_NAME;\n\nexport const Combobox = Object.assign(BaseCombobox, {\n Trigger: ComboboxTrigger,\n Content: ComboboxContent,\n});\n"],"names":["COMPONENT_NAME","CLASSNAME","BaseCombobox","props","defaultValue","description","descriptionProps","filter","type","caseSensitive","formRef","submitRef","inputValue","propsInputValue","isDisabled","isInvalid","maxOptionsLength","minWidth","onChange","onInputChange","selectionMode","ComboboxSelectionMode","single","theme","propsTheme","triggerClassName","value","variant","ComboboxVariant","options","wrapperProps","useTheme","selectedValue","setValue","useState","setInputValue","useEffect","state","listboxState","listboxDispatch","useReducer","ListboxReducer","selectedValues","multiple","listboxContext","useMemo","dispatch","ListboxActionType","UPDATE_OPTIONS","payload","freeTextItemRef","useRef","freeTextItemId","useId","previousValue","React","createElement","ThemeProvider","FocusWithinGroup","focusType","focusOnInit","ComboboxContext","Provider","ListboxContext","Flexbox","_extends","flexDirection","alignItems","gap","Popover","overrideDisplayName","content","trigger","placement","role","Text","marginTop","color","Theme","light","isValidElement","className","displayName","Combobox","Object","assign","Trigger","ComboboxTrigger","Content","ComboboxContent"],"mappings":";;;;;;;;;AAsBA,MAAMA,cAAc,GAAG,UAAU,CAAA;AACjC,MAAMC,SAAS,GAAG,kBAAkB,CAAA;;AAEpC;AACA;AACA;AACaC,MAAAA,YAGZ,GAAIC,KAAK,IAAK;EACb,MAAM;IACJC,YAAY;IACZC,WAAW;IACXC,gBAAgB;AAChBC,IAAAA,MAAM,GAAG;AACPC,MAAAA,IAAI,EAAE,YAAY;AAClBC,MAAAA,aAAa,EAAE,KAAA;KAChB;IACDC,OAAO;IACPC,SAAS;AACTC,IAAAA,UAAU,EAAEC,eAAe;IAC3BC,UAAU;IACVC,SAAS;IACTC,gBAAgB;AAChBC,IAAAA,QAAQ,GAAG,eAAe;IAC1BC,QAAQ;IACRC,aAAa;IACbC,aAAa,GAAGC,qBAAqB,CAACC,MAAM;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,IAAAA,OAAO,EAAC,SAAS;AACjBkD,IAAAA,KAAK,EAAE9D,SAAS,GAAG,OAAO,GAAGQ,KAAK,KAAKuD,KAAK,CAACC,KAAK,GAAG,WAAW,GAAG,OAAA;GAC/DzE,EAAAA,gBAAgB,GAEnBD,WACG,CAAC,gBACLkD,KAAK,CAACyB,cAAc,CAAC3E,WAAW,CAAC,GACnCA,WAAW,GACT,IACG,CACc,CACD,CACV,CACL,CAAC,CAAA;AAEpB,EAAC;AACDH,YAAY,CAAC+E,SAAS,GAAGhF,SAAS,CAAA;AAClCC,YAAY,CAACgF,WAAW,GAAGlF,cAAc,CAAA;AAElC,MAAMmF,QAAQ,GAAGC,MAAM,CAACC,MAAM,CAACnF,YAAY,EAAE;AAClDoF,EAAAA,OAAO,EAAEC,eAAe;AACxBC,EAAAA,OAAO,EAAEC,eAAAA;AACX,CAAC;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sources":["../../../src/components/combobox/context.ts"],"sourcesContent":["import React from 'react';\nimport { ComboboxState } from './types';\n\nexport const ComboboxContext = React.createContext<ComboboxState | null>(null);\n"],"names":["ComboboxContext","React","createContext"],"mappings":";;AAGO,MAAMA,eAAe,gBAAGC,KAAK,CAACC,aAAa,CAAuB,IAAI;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var collapse = "Collapse";
|
|
2
|
+
var expand = "Expand";
|
|
3
|
+
var selected = "{count, plural, =0 {None selected} other {# selected}}";
|
|
4
|
+
var unselect = "Unselect {label}";
|
|
5
|
+
var enUS = {
|
|
6
|
+
collapse: collapse,
|
|
7
|
+
expand: expand,
|
|
8
|
+
selected: selected,
|
|
9
|
+
unselect: unselect
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { collapse, enUS as default, expand, selected, unselect };
|
|
13
|
+
//# sourceMappingURL=en-US.json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"en-US.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var collapse = "Réduire";
|
|
2
|
+
var expand = "Développer";
|
|
3
|
+
var selected = "{count, plural, =0 {Aucun sélectionné} =1 {1 sélectionné} other {# sélectionnés}}";
|
|
4
|
+
var unselect = "Déselectionner {label}";
|
|
5
|
+
var frFR = {
|
|
6
|
+
collapse: collapse,
|
|
7
|
+
expand: expand,
|
|
8
|
+
selected: selected,
|
|
9
|
+
unselect: unselect
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { collapse, frFR as default, expand, selected, unselect };
|
|
13
|
+
//# sourceMappingURL=fr-FR.json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fr-FR.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/components/combobox/intl/index.ts"],"sourcesContent":["import enUS from './en-US.json';\nimport frFR from './fr-FR.json';\n\nexport default {\n 'en-US': enUS,\n 'fr-FR': frFR,\n};\n"],"names":["enUS","frFR"],"mappings":";;;AAGA,mBAAe;AACb,EAAA,OAAO,EAAEA,IAAI;AACb,EAAA,OAAO,EAAEC,IAAAA;AACX,CAAC;;;;"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { ValueOf, TextProps, Theme, FlexboxProps } from '@redsift/design-system';
|
|
2
|
+
import { PopoverProps } from '@redsift/popovers';
|
|
3
|
+
import { RefObject, ReactElement } from 'react';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Component variant.
|
|
7
|
+
*/
|
|
8
|
+
declare const ComboboxSelectionMode: {
|
|
9
|
+
readonly single: "single";
|
|
10
|
+
readonly multiple: "multiple";
|
|
11
|
+
};
|
|
12
|
+
type ComboboxSelectionMode = ValueOf<typeof ComboboxSelectionMode>;
|
|
13
|
+
declare const ComboboxVariant: {
|
|
14
|
+
readonly options: "options";
|
|
15
|
+
readonly suggestions: "suggestions";
|
|
16
|
+
};
|
|
17
|
+
type ComboboxVariant = ValueOf<typeof ComboboxVariant>;
|
|
18
|
+
type ComboboxValue = string | string[];
|
|
19
|
+
/**
|
|
20
|
+
* Context props.
|
|
21
|
+
*/
|
|
22
|
+
type ComboboxState = {
|
|
23
|
+
/** Filtering parameters. */
|
|
24
|
+
readonly filter?: {
|
|
25
|
+
type: 'startsWith' | 'contains' | 'endsWith';
|
|
26
|
+
caseSensitive?: boolean;
|
|
27
|
+
};
|
|
28
|
+
/** Whether the combobox is disabled or not. */
|
|
29
|
+
readonly isDisabled: boolean;
|
|
30
|
+
/** Whether the combobox is invalid or not. */
|
|
31
|
+
readonly isInvalid: boolean;
|
|
32
|
+
/** Sets the selected value. */
|
|
33
|
+
setValue(value: ComboboxValue): void;
|
|
34
|
+
/** Current selected value. */
|
|
35
|
+
readonly value: ComboboxValue;
|
|
36
|
+
/** Sets the input value. */
|
|
37
|
+
setInputValue(inputValue: string): void;
|
|
38
|
+
/** Current input value. */
|
|
39
|
+
readonly inputValue: string;
|
|
40
|
+
/** Whether the Combobox allow multiple selection or not. */
|
|
41
|
+
selectionMode?: ComboboxSelectionMode;
|
|
42
|
+
/** If 'options', the input field cannot have free text, the selection has to be made within the options. If 'suggestions', then choosing from the list isn't mandatory and the user can write free text within the input. */
|
|
43
|
+
variant?: ComboboxVariant;
|
|
44
|
+
/** Ref to the first item used to create values. */
|
|
45
|
+
freeTextItemRef?: RefObject<HTMLDivElement>;
|
|
46
|
+
/** Id of the first item used to create values. */
|
|
47
|
+
freeTextItemId?: string;
|
|
48
|
+
/** Class name to append to the trigger. */
|
|
49
|
+
readonly triggerClassName?: string;
|
|
50
|
+
/** Ref to the form, if any. */
|
|
51
|
+
formRef?: RefObject<HTMLFormElement>;
|
|
52
|
+
/** Ref to the submit button, if any. */
|
|
53
|
+
submitRef?: RefObject<HTMLButtonElement>;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Component props.
|
|
57
|
+
*/
|
|
58
|
+
interface ComboboxProps extends PopoverProps {
|
|
59
|
+
/** If 'options', the input field cannot have free text, the selection has to be made within the options. If 'suggestions', then choosing from the list isn't mandatory and the user can write free text within the input. */
|
|
60
|
+
variant?: ComboboxVariant;
|
|
61
|
+
/**
|
|
62
|
+
* Default selected value.
|
|
63
|
+
* Used for uncontrolled version.
|
|
64
|
+
*/
|
|
65
|
+
defaultValue?: ComboboxValue;
|
|
66
|
+
/** Description of the combobox. */
|
|
67
|
+
description?: string | ReactElement;
|
|
68
|
+
/** Additional description properties. */
|
|
69
|
+
descriptionProps?: Omit<TextProps, 'ref'>;
|
|
70
|
+
/** Filtering parameters. */
|
|
71
|
+
filter?: {
|
|
72
|
+
type: 'startsWith' | 'contains' | 'endsWith';
|
|
73
|
+
caseSensitive?: boolean;
|
|
74
|
+
};
|
|
75
|
+
/** Ref to the form, if any. */
|
|
76
|
+
formRef?: RefObject<HTMLFormElement>;
|
|
77
|
+
/** Ref to the submit button, if any. */
|
|
78
|
+
submitRef?: RefObject<HTMLButtonElement>;
|
|
79
|
+
/** Whether the component is disabled or not. */
|
|
80
|
+
isDisabled?: boolean;
|
|
81
|
+
/** Whether the component is invalid or not. */
|
|
82
|
+
isInvalid?: boolean;
|
|
83
|
+
/** Maximum number of options displayed. Useful when too many options are displayed. */
|
|
84
|
+
maxOptionsLength?: number;
|
|
85
|
+
/** Method to handle selection change. */
|
|
86
|
+
onChange?(value: ComboboxValue): void;
|
|
87
|
+
/** Method to handle input change. */
|
|
88
|
+
onInputChange?(value: string): void;
|
|
89
|
+
/**
|
|
90
|
+
* Currently selected value.
|
|
91
|
+
* Used for controlled version.
|
|
92
|
+
*/
|
|
93
|
+
value?: ComboboxValue;
|
|
94
|
+
/** Input value. */
|
|
95
|
+
inputValue?: string;
|
|
96
|
+
/** Whether the Combobox allow multiple selection or not. */
|
|
97
|
+
selectionMode?: ComboboxSelectionMode;
|
|
98
|
+
/** Theme. */
|
|
99
|
+
theme?: Theme;
|
|
100
|
+
/** Class name to append to the trigger. */
|
|
101
|
+
triggerClassName?: string;
|
|
102
|
+
/** Props to forward to the wrapper. */
|
|
103
|
+
wrapperProps?: Omit<FlexboxProps, 'ref'>;
|
|
104
|
+
}
|
|
105
|
+
type StyledComboboxProps = ComboboxProps;
|
|
106
|
+
|
|
107
|
+
export { ComboboxProps, ComboboxSelectionMode, ComboboxState, ComboboxValue, ComboboxVariant, StyledComboboxProps };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component variant.
|
|
3
|
+
*/
|
|
4
|
+
const ComboboxSelectionMode = {
|
|
5
|
+
single: 'single',
|
|
6
|
+
multiple: 'multiple'
|
|
7
|
+
};
|
|
8
|
+
const ComboboxVariant = {
|
|
9
|
+
options: 'options',
|
|
10
|
+
suggestions: 'suggestions'
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Context props.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Component props.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export { ComboboxSelectionMode, ComboboxVariant };
|
|
22
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../src/components/combobox/types.ts"],"sourcesContent":["import { FlexboxProps, TextProps, Theme, ValueOf } from '@redsift/design-system';\nimport { PopoverProps } from '@redsift/popovers';\nimport { ReactElement, RefObject } from 'react';\n\n/**\n * Component variant.\n */\nexport const ComboboxSelectionMode = {\n single: 'single',\n multiple: 'multiple',\n} as const;\nexport type ComboboxSelectionMode = ValueOf<typeof ComboboxSelectionMode>;\n\nexport const ComboboxVariant = {\n options: 'options',\n suggestions: 'suggestions',\n} as const;\nexport type ComboboxVariant = ValueOf<typeof ComboboxVariant>;\n\nexport type ComboboxValue = string | string[];\n\n/**\n * Context props.\n */\nexport type ComboboxState = {\n /** Filtering parameters. */\n readonly filter?: {\n type: 'startsWith' | 'contains' | 'endsWith';\n caseSensitive?: boolean;\n };\n /** Whether the combobox is disabled or not. */\n readonly isDisabled: boolean;\n /** Whether the combobox is invalid or not. */\n readonly isInvalid: boolean;\n /** Sets the selected value. */\n setValue(value: ComboboxValue): void;\n /** Current selected value. */\n readonly value: ComboboxValue;\n /** Sets the input value. */\n setInputValue(inputValue: string): void;\n /** Current input value. */\n readonly inputValue: string;\n /** Whether the Combobox allow multiple selection or not. */\n selectionMode?: ComboboxSelectionMode;\n /** If 'options', the input field cannot have free text, the selection has to be made within the options. If 'suggestions', then choosing from the list isn't mandatory and the user can write free text within the input. */\n variant?: ComboboxVariant;\n /** Ref to the first item used to create values. */\n freeTextItemRef?: RefObject<HTMLDivElement>;\n /** Id of the first item used to create values. */\n freeTextItemId?: string;\n /** Class name to append to the trigger. */\n readonly triggerClassName?: string;\n /** Ref to the form, if any. */\n formRef?: RefObject<HTMLFormElement>;\n /** Ref to the submit button, if any. */\n submitRef?: RefObject<HTMLButtonElement>;\n};\n\n/**\n * Component props.\n */\nexport interface ComboboxProps extends PopoverProps {\n /** If 'options', the input field cannot have free text, the selection has to be made within the options. If 'suggestions', then choosing from the list isn't mandatory and the user can write free text within the input. */\n variant?: ComboboxVariant;\n /**\n * Default selected value.\n * Used for uncontrolled version.\n */\n defaultValue?: ComboboxValue;\n /** Description of the combobox. */\n description?: string | ReactElement;\n /** Additional description properties. */\n descriptionProps?: Omit<TextProps, 'ref'>;\n /** Filtering parameters. */\n filter?: {\n type: 'startsWith' | 'contains' | 'endsWith';\n caseSensitive?: boolean;\n };\n /** Ref to the form, if any. */\n formRef?: RefObject<HTMLFormElement>;\n /** Ref to the submit button, if any. */\n submitRef?: RefObject<HTMLButtonElement>;\n /** Whether the component is disabled or not. */\n isDisabled?: boolean;\n /** Whether the component is invalid or not. */\n isInvalid?: boolean;\n /** Maximum number of options displayed. Useful when too many options are displayed. */\n maxOptionsLength?: number;\n /** Method to handle selection change. */\n onChange?(value: ComboboxValue): void;\n /** Method to handle input change. */\n onInputChange?(value: string): void;\n /**\n * Currently selected value.\n * Used for controlled version.\n */\n value?: ComboboxValue;\n /** Input value. */\n inputValue?: string;\n /** Whether the Combobox allow multiple selection or not. */\n selectionMode?: ComboboxSelectionMode;\n /** Theme. */\n theme?: Theme;\n /** Class name to append to the trigger. */\n triggerClassName?: string;\n /** Props to forward to the wrapper. */\n wrapperProps?: Omit<FlexboxProps, 'ref'>;\n}\n\nexport type StyledComboboxProps = ComboboxProps;\n"],"names":["ComboboxSelectionMode","single","multiple","ComboboxVariant","options","suggestions"],"mappings":"AAIA;AACA;AACA;AACO,MAAMA,qBAAqB,GAAG;AACnCC,EAAAA,MAAM,EAAE,QAAQ;AAChBC,EAAAA,QAAQ,EAAE,UAAA;AACZ,EAAU;AAGH,MAAMC,eAAe,GAAG;AAC7BC,EAAAA,OAAO,EAAE,SAAS;AAClBC,EAAAA,WAAW,EAAE,aAAA;AACf,EAAU;;AAKV;AACA;AACA;;AAmCA;AACA;AACA;;;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Comp } from '@redsift/design-system';
|
|
2
|
+
import { ComboboxContentProps } from './types.js';
|
|
3
|
+
import { ComboboxContentHeaderProps } from '../combobox-content-header/types.js';
|
|
4
|
+
import { ComboboxContentListboxProps } from '../combobox-content-listbox/types.js';
|
|
5
|
+
import { ComboboxContentFooterProps } from '../combobox-content-footer/types.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The ComboboxContent component.
|
|
9
|
+
*/
|
|
10
|
+
declare const BaseComboboxContent: Comp<ComboboxContentProps, HTMLDivElement>;
|
|
11
|
+
declare const ComboboxContent: Comp<ComboboxContentProps, HTMLDivElement> & {
|
|
12
|
+
Header: Comp<ComboboxContentHeaderProps, HTMLDivElement>;
|
|
13
|
+
Listbox: Comp<ComboboxContentListboxProps, HTMLDivElement>;
|
|
14
|
+
Footer: Comp<ComboboxContentFooterProps, HTMLDivElement>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { BaseComboboxContent, ComboboxContent };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { extends as _extends, objectSpread2 as _objectSpread2 } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import React, { forwardRef, useContext } from 'react';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { getContainerProps, AppContainerContext, FocusWithinGroupContext, ListboxContext, useTheme, partitionComponents, isComponent, Flexbox } from '@redsift/design-system';
|
|
5
|
+
import { usePopoverContext, useMergeRefs, FloatingPortal, StyledPopoverContent, PopoverContent } from '@redsift/popovers';
|
|
6
|
+
import { ComboboxContentListbox } from '../combobox-content-listbox/ComboboxContentListbox.js';
|
|
7
|
+
import { ComboboxContext } from '../combobox/context.js';
|
|
8
|
+
import { ComboboxContentHeader } from '../combobox-content-header/ComboboxContentHeader.js';
|
|
9
|
+
import { ComboboxContentFooter } from '../combobox-content-footer/ComboboxContentFooter.js';
|
|
10
|
+
|
|
11
|
+
const COMPONENT_NAME = 'ComboboxContent';
|
|
12
|
+
const CLASSNAME = 'redsift-combobox-content';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The ComboboxContent component.
|
|
16
|
+
*/
|
|
17
|
+
const BaseComboboxContent = /*#__PURE__*/forwardRef((props, ref) => {
|
|
18
|
+
var _comboboxState$inputV;
|
|
19
|
+
const {
|
|
20
|
+
children,
|
|
21
|
+
className,
|
|
22
|
+
style
|
|
23
|
+
} = props;
|
|
24
|
+
const containerProps = getContainerProps(props);
|
|
25
|
+
const {
|
|
26
|
+
getFloatingProps,
|
|
27
|
+
isOpen,
|
|
28
|
+
refs,
|
|
29
|
+
strategy,
|
|
30
|
+
x,
|
|
31
|
+
y
|
|
32
|
+
} = usePopoverContext();
|
|
33
|
+
const popoverRef = useMergeRefs([refs.setFloating, ref]);
|
|
34
|
+
const appContainerState = useContext(AppContainerContext);
|
|
35
|
+
const comboboxState = useContext(ComboboxContext);
|
|
36
|
+
const focusContext = useContext(FocusWithinGroupContext);
|
|
37
|
+
const listboxState = useContext(ListboxContext);
|
|
38
|
+
const theme = useTheme();
|
|
39
|
+
const [[header], [listbox], [footer]] = partitionComponents(React.Children.toArray(children), [isComponent('ComboboxContentHeader'), isComponent('ComboboxContentListbox'), isComponent('ComboboxContentFooter')]);
|
|
40
|
+
return /*#__PURE__*/React.createElement(FloatingPortal, {
|
|
41
|
+
root: appContainerState === null || appContainerState === void 0 ? void 0 : appContainerState.appContainerRef.current
|
|
42
|
+
}, isOpen && /*#__PURE__*/React.createElement(StyledPopoverContent, _extends({
|
|
43
|
+
$theme: theme,
|
|
44
|
+
ref: popoverRef
|
|
45
|
+
}, getFloatingProps(props), {
|
|
46
|
+
style: _objectSpread2(_objectSpread2({
|
|
47
|
+
position: strategy,
|
|
48
|
+
top: y !== null && y !== void 0 ? y : 0,
|
|
49
|
+
left: x !== null && x !== void 0 ? x : 0
|
|
50
|
+
}, style), comboboxState !== null && comboboxState !== void 0 && (_comboboxState$inputV = comboboxState.inputValue) !== null && _comboboxState$inputV !== void 0 && _comboboxState$inputV.length && focusContext.state.tabStops.length === 0 ? {
|
|
51
|
+
display: 'none'
|
|
52
|
+
} : {}),
|
|
53
|
+
className: classNames(PopoverContent.className, BaseComboboxContent.className, className),
|
|
54
|
+
"aria-disabled": listboxState.state.isDisabled
|
|
55
|
+
}), /*#__PURE__*/React.createElement(Flexbox, _extends({
|
|
56
|
+
flexDirection: "column",
|
|
57
|
+
gap: "0px",
|
|
58
|
+
width: "100%"
|
|
59
|
+
}, containerProps), header, listbox, footer)));
|
|
60
|
+
});
|
|
61
|
+
BaseComboboxContent.className = CLASSNAME;
|
|
62
|
+
BaseComboboxContent.displayName = COMPONENT_NAME;
|
|
63
|
+
const ComboboxContent = Object.assign(BaseComboboxContent, {
|
|
64
|
+
Header: ComboboxContentHeader,
|
|
65
|
+
Listbox: ComboboxContentListbox,
|
|
66
|
+
Footer: ComboboxContentFooter
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export { BaseComboboxContent, ComboboxContent };
|
|
70
|
+
//# sourceMappingURL=ComboboxContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComboboxContent.js","sources":["../../../src/components/combobox-content/ComboboxContent.tsx"],"sourcesContent":["import React, { forwardRef, useContext } from 'react';\nimport classNames from 'classnames';\n\nimport {\n AppContainerContext,\n Comp,\n Flexbox,\n FocusWithinGroupContext,\n ListboxContext,\n getContainerProps,\n isComponent,\n partitionComponents,\n useTheme,\n} from '@redsift/design-system';\nimport { ComboboxContentProps } from './types';\nimport {\n FloatingPortal,\n PopoverContent,\n usePopoverContext,\n StyledPopoverContent,\n useMergeRefs,\n} from '@redsift/popovers';\nimport { ComboboxContentHeader } from '../combobox-content-header';\nimport { ComboboxContentFooter } from '../combobox-content-footer';\nimport { ComboboxContentListbox } from '../combobox-content-listbox/ComboboxContentListbox';\nimport { ComboboxContext } from '../combobox/context';\n\nconst COMPONENT_NAME = 'ComboboxContent';\nconst CLASSNAME = 'redsift-combobox-content';\n\n/**\n * The ComboboxContent component.\n */\nexport const BaseComboboxContent: Comp<ComboboxContentProps, HTMLDivElement> = forwardRef((props, ref) => {\n const { children, className, style } = props;\n const containerProps = getContainerProps(props);\n\n const { getFloatingProps, isOpen, refs, strategy, x, y } = usePopoverContext();\n const popoverRef = useMergeRefs([refs.setFloating, ref]);\n\n const appContainerState = useContext(AppContainerContext);\n const comboboxState = useContext(ComboboxContext);\n const focusContext = useContext(FocusWithinGroupContext);\n const listboxState = useContext(ListboxContext);\n const theme = useTheme();\n\n const [[header], [listbox], [footer]] = partitionComponents(React.Children.toArray(children), [\n isComponent('ComboboxContentHeader'),\n isComponent('ComboboxContentListbox'),\n isComponent('ComboboxContentFooter'),\n ]);\n\n return (\n <FloatingPortal root={appContainerState?.appContainerRef.current}>\n {isOpen && (\n <StyledPopoverContent\n $theme={theme!}\n ref={popoverRef}\n {...getFloatingProps(props)}\n style={{\n position: strategy,\n top: y ?? 0,\n left: x ?? 0,\n ...style,\n ...(comboboxState?.inputValue?.length && focusContext.state.tabStops.length === 0\n ? { display: 'none' }\n : {}),\n }}\n className={classNames(PopoverContent.className, BaseComboboxContent.className, className)}\n aria-disabled={listboxState.state.isDisabled}\n >\n <Flexbox flexDirection=\"column\" gap=\"0px\" width=\"100%\" {...containerProps}>\n {header}\n {listbox}\n {footer}\n </Flexbox>\n </StyledPopoverContent>\n )}\n </FloatingPortal>\n );\n});\nBaseComboboxContent.className = CLASSNAME;\nBaseComboboxContent.displayName = COMPONENT_NAME;\n\nexport const ComboboxContent = Object.assign(BaseComboboxContent, {\n Header: ComboboxContentHeader,\n Listbox: ComboboxContentListbox,\n Footer: ComboboxContentFooter,\n});\n"],"names":["COMPONENT_NAME","CLASSNAME","BaseComboboxContent","forwardRef","props","ref","_comboboxState$inputV","children","className","style","containerProps","getContainerProps","getFloatingProps","isOpen","refs","strategy","x","y","usePopoverContext","popoverRef","useMergeRefs","setFloating","appContainerState","useContext","AppContainerContext","comboboxState","ComboboxContext","focusContext","FocusWithinGroupContext","listboxState","ListboxContext","theme","useTheme","header","listbox","footer","partitionComponents","React","Children","toArray","isComponent","createElement","FloatingPortal","root","appContainerRef","current","StyledPopoverContent","_extends","$theme","_objectSpread","position","top","left","inputValue","length","state","tabStops","display","classNames","PopoverContent","isDisabled","Flexbox","flexDirection","gap","width","displayName","ComboboxContent","Object","assign","Header","ComboboxContentHeader","Listbox","ComboboxContentListbox","Footer","ComboboxContentFooter"],"mappings":";;;;;;;;;;AA2BA,MAAMA,cAAc,GAAG,iBAAiB,CAAA;AACxC,MAAMC,SAAS,GAAG,0BAA0B,CAAA;;AAE5C;AACA;AACA;AACO,MAAMC,mBAA+D,gBAAGC,UAAU,CAAC,CAACC,KAAK,EAAEC,GAAG,KAAK;AAAA,EAAA,IAAAC,qBAAA,CAAA;EACxG,MAAM;IAAEC,QAA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CAAA;AACzCC,mBAAmB,CAAC+D,WAAW,GAAGjE,cAAc,CAAA;AAEzC,MAAMkE,eAAe,GAAGC,MAAM,CAACC,MAAM,CAAClE,mBAAmB,EAAE;AAChEmE,EAAAA,MAAM,EAAEC,qBAAqB;AAC7BC,EAAAA,OAAO,EAAEC,sBAAsB;AAC/BC,EAAAA,MAAM,EAAEC,qBAAAA;AACV,CAAC;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PopoverContentProps } from '@redsift/popovers';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Component props.
|
|
5
|
+
*/
|
|
6
|
+
interface ComboboxContentProps extends PopoverContentProps {
|
|
7
|
+
/** Whether the popover should stay open even if there is no result after filter. */
|
|
8
|
+
shouldStayOpenEvenIfEmpty?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { ComboboxContentProps };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ComboboxContentFooterProps } from './types.js';
|
|
2
|
+
import { Comp } from '@redsift/design-system';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The ComboboxContentFooter component.
|
|
6
|
+
*/
|
|
7
|
+
declare const ComboboxContentFooter: Comp<ComboboxContentFooterProps, HTMLDivElement>;
|
|
8
|
+
|
|
9
|
+
export { ComboboxContentFooter };
|