@spaced-out/ui-design-system 0.2.7 → 0.2.8-beta.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/CHANGELOG.md +7 -0
- package/lib/components/ButtonTabs/ButtonTab/ButtonTab.module.css +6 -6
- package/lib/components/Typeahead/SimpleTypeahead.js +2 -0
- package/lib/components/Typeahead/SimpleTypeahead.js.flow +3 -0
- package/lib/components/Typeahead/Typeahead.js +49 -14
- package/lib/components/Typeahead/Typeahead.js.flow +72 -26
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.2.8-beta.0](https://github.com/spaced-out/ui-design-system/compare/v0.2.7...v0.2.8-beta.0) (2024-10-23)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* introduces prop 'allowInternalFilter' in typeahead and creates baseTypeahead with statelful and stateless variations. ([#280](https://github.com/spaced-out/ui-design-system/issues/280)) ([a2aa433](https://github.com/spaced-out/ui-design-system/commit/a2aa433dbb1b6d324a767ab26de10479d6a6eb51))
|
|
11
|
+
|
|
5
12
|
### [0.2.7](https://github.com/spaced-out/ui-design-system/compare/v0.2.6...v0.2.7) (2024-10-22)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -40,6 +40,12 @@
|
|
|
40
40
|
height: size34;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
&.disabled {
|
|
44
|
+
color: colorTextDisabled;
|
|
45
|
+
border: borderWidthPrimary solid colorBorderPrimary;
|
|
46
|
+
border-right-width: borderWidthNone;
|
|
47
|
+
}
|
|
48
|
+
|
|
43
49
|
&.rightCurved {
|
|
44
50
|
border-right-width: borderWidthPrimary;
|
|
45
51
|
border-top-right-radius: borderRadiusMedium;
|
|
@@ -51,12 +57,6 @@
|
|
|
51
57
|
border-bottom-left-radius: borderRadiusMedium;
|
|
52
58
|
}
|
|
53
59
|
|
|
54
|
-
&.disabled {
|
|
55
|
-
color: colorTextDisabled;
|
|
56
|
-
border: borderWidthPrimary solid colorBorderPrimary;
|
|
57
|
-
border-right-width: borderWidthNone;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
60
|
&:hover {
|
|
61
61
|
color: colorTextPrimary;
|
|
62
62
|
background-color: initial;
|
|
@@ -29,6 +29,7 @@ const SimpleTypeaheadBase = (props, ref) => {
|
|
|
29
29
|
footer,
|
|
30
30
|
menuClassNames,
|
|
31
31
|
clickAwayRef,
|
|
32
|
+
allowInternalFilter = true,
|
|
32
33
|
...inputProps
|
|
33
34
|
} = props;
|
|
34
35
|
const [typeaheadInputText, setTypeaheadInputText] = React.useState('');
|
|
@@ -52,6 +53,7 @@ const SimpleTypeaheadBase = (props, ref) => {
|
|
|
52
53
|
selectedKeys: typeaheadSelectedKeys
|
|
53
54
|
}));
|
|
54
55
|
return /*#__PURE__*/React.createElement(_Typeahead.Typeahead, _extends({}, inputProps, {
|
|
56
|
+
allowInternalFilter: allowInternalFilter,
|
|
55
57
|
classNames: classNames,
|
|
56
58
|
size: size,
|
|
57
59
|
placeholder: placeholder,
|
|
@@ -48,6 +48,7 @@ export type SimpleTypeaheadProps = {
|
|
|
48
48
|
resolveLabel?: (option: MenuOption) => string | React.Node,
|
|
49
49
|
resolveSecondaryLabel?: (option: MenuOption) => string | React.Node,
|
|
50
50
|
clickAwayRef?: ClickAwayRefType,
|
|
51
|
+
allowInternalFilter?: boolean,
|
|
51
52
|
...
|
|
52
53
|
};
|
|
53
54
|
|
|
@@ -70,6 +71,7 @@ const SimpleTypeaheadBase = (props: SimpleTypeaheadProps, ref) => {
|
|
|
70
71
|
footer,
|
|
71
72
|
menuClassNames,
|
|
72
73
|
clickAwayRef,
|
|
74
|
+
allowInternalFilter = true,
|
|
73
75
|
...inputProps
|
|
74
76
|
} = props;
|
|
75
77
|
|
|
@@ -111,6 +113,7 @@ const SimpleTypeaheadBase = (props: SimpleTypeaheadProps, ref) => {
|
|
|
111
113
|
return (
|
|
112
114
|
<Typeahead
|
|
113
115
|
{...inputProps}
|
|
116
|
+
allowInternalFilter={allowInternalFilter}
|
|
114
117
|
classNames={classNames}
|
|
115
118
|
size={size}
|
|
116
119
|
placeholder={placeholder}
|
|
@@ -18,7 +18,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
18
18
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
19
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
20
20
|
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); }
|
|
21
|
-
const
|
|
21
|
+
const BaseTypeahead = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
22
22
|
let {
|
|
23
23
|
size = 'medium',
|
|
24
24
|
classNames,
|
|
@@ -36,7 +36,7 @@ const Typeahead = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
36
36
|
clickAwayRef,
|
|
37
37
|
...inputProps
|
|
38
38
|
} = _ref;
|
|
39
|
-
const
|
|
39
|
+
const menuOptions = menu?.options;
|
|
40
40
|
const {
|
|
41
41
|
x,
|
|
42
42
|
y,
|
|
@@ -52,16 +52,6 @@ const Typeahead = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
52
52
|
const onMenuToggle = isOpen => {
|
|
53
53
|
isOpen ? onMenuOpen && onMenuOpen() : onMenuClose && onMenuClose();
|
|
54
54
|
};
|
|
55
|
-
React.useEffect(() => {
|
|
56
|
-
const optionsFiltered = menu?.options && menu.options.filter(option => {
|
|
57
|
-
if (!option.label || !typeaheadInputText) {
|
|
58
|
-
return true;
|
|
59
|
-
} else {
|
|
60
|
-
return option.label.toLowerCase().indexOf(typeaheadInputText.toLowerCase()) !== -1;
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
setFilteredOptions(optionsFiltered || []);
|
|
64
|
-
}, [typeaheadInputText, menu?.options]);
|
|
65
55
|
return /*#__PURE__*/React.createElement(_clickAway.ClickAway, {
|
|
66
56
|
onChange: onMenuToggle,
|
|
67
57
|
clickAwayRef: clickAwayRef
|
|
@@ -107,7 +97,7 @@ const Typeahead = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
107
97
|
onClear: _e => {
|
|
108
98
|
onClear?.();
|
|
109
99
|
}
|
|
110
|
-
})), isOpen && !isLoading && menu &&
|
|
100
|
+
})), isOpen && !isLoading && menu && menuOptions && !!menuOptions.length && /*#__PURE__*/React.createElement("div", {
|
|
111
101
|
ref: refs.setFloating,
|
|
112
102
|
style: {
|
|
113
103
|
position: strategy,
|
|
@@ -116,7 +106,7 @@ const Typeahead = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
116
106
|
width: _size.sizeFluid
|
|
117
107
|
}
|
|
118
108
|
}, /*#__PURE__*/React.createElement(_Menu.Menu, _extends({}, menu, {
|
|
119
|
-
options:
|
|
109
|
+
options: menuOptions,
|
|
120
110
|
onSelect: (option, e) => {
|
|
121
111
|
onSelect && onSelect(option, e);
|
|
122
112
|
if (!menu.optionsVariant || menu.optionsVariant === 'normal') {
|
|
@@ -128,4 +118,49 @@ const Typeahead = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
128
118
|
}))));
|
|
129
119
|
});
|
|
130
120
|
});
|
|
121
|
+
const StatefulTypeahead = /*#__PURE__*/React.forwardRef((_ref3, ref) => {
|
|
122
|
+
let {
|
|
123
|
+
menu,
|
|
124
|
+
...props
|
|
125
|
+
} = _ref3;
|
|
126
|
+
const {
|
|
127
|
+
typeaheadInputText = ''
|
|
128
|
+
} = props;
|
|
129
|
+
const [filteredOptions, setFilteredOptions] = React.useState(menu?.options);
|
|
130
|
+
React.useEffect(() => {
|
|
131
|
+
const optionsFiltered = menu?.options && menu.options.filter(option => {
|
|
132
|
+
if (!option.label || !typeaheadInputText) {
|
|
133
|
+
return true;
|
|
134
|
+
} else {
|
|
135
|
+
return option.label.toLowerCase().indexOf(typeaheadInputText.toLowerCase()) !== -1;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
setFilteredOptions(optionsFiltered || []);
|
|
139
|
+
}, [typeaheadInputText, menu?.options]);
|
|
140
|
+
return /*#__PURE__*/React.createElement(BaseTypeahead, _extends({}, props, {
|
|
141
|
+
menu: {
|
|
142
|
+
...menu,
|
|
143
|
+
options: filteredOptions
|
|
144
|
+
},
|
|
145
|
+
ref: ref
|
|
146
|
+
}));
|
|
147
|
+
});
|
|
148
|
+
const StatelessTypeahead = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement(BaseTypeahead, _extends({}, props, {
|
|
149
|
+
ref: ref
|
|
150
|
+
})));
|
|
151
|
+
const Typeahead = /*#__PURE__*/React.forwardRef((_ref4, ref) => {
|
|
152
|
+
let {
|
|
153
|
+
allowInternalFilter = true,
|
|
154
|
+
...props
|
|
155
|
+
} = _ref4;
|
|
156
|
+
if (allowInternalFilter) {
|
|
157
|
+
return /*#__PURE__*/React.createElement(StatefulTypeahead, _extends({}, props, {
|
|
158
|
+
ref: ref
|
|
159
|
+
}));
|
|
160
|
+
} else {
|
|
161
|
+
return /*#__PURE__*/React.createElement(StatelessTypeahead, _extends({}, props, {
|
|
162
|
+
ref: ref
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
165
|
+
});
|
|
131
166
|
exports.Typeahead = Typeahead;
|
|
@@ -27,7 +27,7 @@ import css from './Typeahead.module.css';
|
|
|
27
27
|
|
|
28
28
|
type ClassNames = $ReadOnly<{wrapper?: string, box?: string}>;
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
type BaseTypeaheadProps = {
|
|
31
31
|
...InputProps,
|
|
32
32
|
classNames?: ClassNames,
|
|
33
33
|
onSelect?: (option: MenuOption, ?SyntheticEvent<HTMLElement>) => mixed,
|
|
@@ -43,10 +43,16 @@ export type TypeaheadProps = {
|
|
|
43
43
|
...
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
export
|
|
47
|
-
|
|
46
|
+
export type TypeaheadProps = {
|
|
47
|
+
...BaseTypeaheadProps,
|
|
48
|
+
allowInternalFilter?: boolean,
|
|
49
|
+
...
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const BaseTypeahead: React$AbstractComponent<
|
|
53
|
+
BaseTypeaheadProps,
|
|
48
54
|
HTMLInputElement,
|
|
49
|
-
> = React.forwardRef<
|
|
55
|
+
> = React.forwardRef<BaseTypeaheadProps, HTMLInputElement>(
|
|
50
56
|
(
|
|
51
57
|
{
|
|
52
58
|
size = 'medium',
|
|
@@ -64,10 +70,10 @@ export const Typeahead: React$AbstractComponent<
|
|
|
64
70
|
onFocus,
|
|
65
71
|
clickAwayRef,
|
|
66
72
|
...inputProps
|
|
67
|
-
}:
|
|
73
|
+
}: BaseTypeaheadProps,
|
|
68
74
|
ref,
|
|
69
75
|
): React.Node => {
|
|
70
|
-
const
|
|
76
|
+
const menuOptions = menu?.options;
|
|
71
77
|
const {x, y, refs, strategy} = useFloating({
|
|
72
78
|
open: true,
|
|
73
79
|
strategy: 'absolute',
|
|
@@ -80,23 +86,6 @@ export const Typeahead: React$AbstractComponent<
|
|
|
80
86
|
isOpen ? onMenuOpen && onMenuOpen() : onMenuClose && onMenuClose();
|
|
81
87
|
};
|
|
82
88
|
|
|
83
|
-
React.useEffect(() => {
|
|
84
|
-
const optionsFiltered =
|
|
85
|
-
menu?.options &&
|
|
86
|
-
menu.options.filter((option) => {
|
|
87
|
-
if (!option.label || !typeaheadInputText) {
|
|
88
|
-
return true;
|
|
89
|
-
} else {
|
|
90
|
-
return (
|
|
91
|
-
option.label
|
|
92
|
-
.toLowerCase()
|
|
93
|
-
.indexOf(typeaheadInputText.toLowerCase()) !== -1
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
setFilteredOptions(optionsFiltered || []);
|
|
98
|
-
}, [typeaheadInputText, menu?.options]);
|
|
99
|
-
|
|
100
89
|
return (
|
|
101
90
|
<ClickAway onChange={onMenuToggle} clickAwayRef={clickAwayRef}>
|
|
102
91
|
{({isOpen, onOpen, clickAway, boundaryRef, triggerRef}) => (
|
|
@@ -138,8 +127,8 @@ export const Typeahead: React$AbstractComponent<
|
|
|
138
127
|
{isOpen &&
|
|
139
128
|
!isLoading &&
|
|
140
129
|
menu &&
|
|
141
|
-
|
|
142
|
-
!!
|
|
130
|
+
menuOptions &&
|
|
131
|
+
!!menuOptions.length && (
|
|
143
132
|
<div
|
|
144
133
|
ref={refs.setFloating}
|
|
145
134
|
style={{
|
|
@@ -151,7 +140,7 @@ export const Typeahead: React$AbstractComponent<
|
|
|
151
140
|
>
|
|
152
141
|
<Menu
|
|
153
142
|
{...menu}
|
|
154
|
-
options={
|
|
143
|
+
options={menuOptions}
|
|
155
144
|
onSelect={(option, e) => {
|
|
156
145
|
onSelect && onSelect(option, e);
|
|
157
146
|
if (
|
|
@@ -172,3 +161,60 @@ export const Typeahead: React$AbstractComponent<
|
|
|
172
161
|
);
|
|
173
162
|
},
|
|
174
163
|
);
|
|
164
|
+
|
|
165
|
+
const StatefulTypeahead: React$AbstractComponent<
|
|
166
|
+
BaseTypeaheadProps,
|
|
167
|
+
HTMLInputElement,
|
|
168
|
+
> = React.forwardRef<BaseTypeaheadProps, HTMLInputElement>(
|
|
169
|
+
({menu, ...props}: BaseTypeaheadProps, ref): React.Node => {
|
|
170
|
+
const {typeaheadInputText = ''} = props;
|
|
171
|
+
const [filteredOptions, setFilteredOptions] = React.useState(menu?.options);
|
|
172
|
+
|
|
173
|
+
React.useEffect(() => {
|
|
174
|
+
const optionsFiltered =
|
|
175
|
+
menu?.options &&
|
|
176
|
+
menu.options.filter((option) => {
|
|
177
|
+
if (!option.label || !typeaheadInputText) {
|
|
178
|
+
return true;
|
|
179
|
+
} else {
|
|
180
|
+
return (
|
|
181
|
+
option.label
|
|
182
|
+
.toLowerCase()
|
|
183
|
+
.indexOf(typeaheadInputText.toLowerCase()) !== -1
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
setFilteredOptions(optionsFiltered || []);
|
|
188
|
+
}, [typeaheadInputText, menu?.options]);
|
|
189
|
+
|
|
190
|
+
return (
|
|
191
|
+
<BaseTypeahead
|
|
192
|
+
{...props}
|
|
193
|
+
menu={{...menu, options: filteredOptions}}
|
|
194
|
+
ref={ref}
|
|
195
|
+
/>
|
|
196
|
+
);
|
|
197
|
+
},
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
const StatelessTypeahead: React$AbstractComponent<
|
|
201
|
+
BaseTypeaheadProps,
|
|
202
|
+
HTMLInputElement,
|
|
203
|
+
> = React.forwardRef<BaseTypeaheadProps, HTMLInputElement>(
|
|
204
|
+
(props: BaseTypeaheadProps, ref): React.Node => (
|
|
205
|
+
<BaseTypeahead {...props} ref={ref} />
|
|
206
|
+
),
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
export const Typeahead: React$AbstractComponent<
|
|
210
|
+
TypeaheadProps,
|
|
211
|
+
HTMLInputElement,
|
|
212
|
+
> = React.forwardRef<TypeaheadProps, HTMLInputElement>(
|
|
213
|
+
({allowInternalFilter = true, ...props}: TypeaheadProps, ref): React.Node => {
|
|
214
|
+
if (allowInternalFilter) {
|
|
215
|
+
return <StatefulTypeahead {...props} ref={ref} />;
|
|
216
|
+
} else {
|
|
217
|
+
return <StatelessTypeahead {...props} ref={ref} />;
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
);
|