@leafygreen-ui/combobox 1.0.2 → 1.2.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 +65 -0
- package/README.md +2 -2
- package/dist/Chip.d.ts.map +1 -1
- package/dist/Combobox.d.ts +7 -1
- package/dist/Combobox.d.ts.map +1 -1
- package/dist/Combobox.styles.d.ts +7 -3
- package/dist/Combobox.styles.d.ts.map +1 -1
- package/dist/Combobox.types.d.ts +33 -6
- package/dist/Combobox.types.d.ts.map +1 -1
- package/dist/ComboboxContext.d.ts +1 -1
- package/dist/ComboboxContext.d.ts.map +1 -1
- package/dist/ComboboxOption.d.ts.map +1 -1
- package/dist/ComboboxTestUtils.d.ts +3 -4
- package/dist/ComboboxTestUtils.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/OptionObjectUtils.d.ts +5 -0
- package/dist/utils/OptionObjectUtils.d.ts.map +1 -0
- package/dist/utils/flattenChildren.d.ts +11 -0
- package/dist/utils/flattenChildren.d.ts.map +1 -0
- package/dist/utils/getNameAndValue.d.ts +14 -0
- package/dist/utils/getNameAndValue.d.ts.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/wrapJSX.d.ts +14 -0
- package/dist/utils/wrapJSX.d.ts.map +1 -0
- package/package.json +22 -12
- package/src/Chip.tsx +16 -9
- package/src/Combobox.spec.tsx +336 -164
- package/src/Combobox.story.tsx +274 -248
- package/src/Combobox.styles.ts +94 -24
- package/src/Combobox.tsx +456 -279
- package/src/Combobox.types.ts +46 -8
- package/src/ComboboxContext.tsx +2 -2
- package/src/ComboboxOption.tsx +36 -11
- package/src/ComboboxTestUtils.tsx +22 -8
- package/src/utils/ComboboxUtils.spec.tsx +227 -0
- package/src/utils/OptionObjectUtils.ts +26 -0
- package/src/utils/flattenChildren.tsx +47 -0
- package/src/utils/getNameAndValue.ts +23 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/wrapJSX.tsx +54 -0
- package/tsconfig.json +3 -0
- package/tsconfig.tsbuildinfo +1 -3977
- package/dist/util.d.ts +0 -53
- package/dist/util.d.ts.map +0 -1
- package/src/util.tsx +0 -117
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { wrapJSX } from './wrapJSX';
|
|
2
|
+
export { getNameAndValue } from './getNameAndValue';
|
|
3
|
+
export {
|
|
4
|
+
getOptionObjectFromValue,
|
|
5
|
+
getDisplayNameForValue,
|
|
6
|
+
getValueForDisplayName,
|
|
7
|
+
} from './OptionObjectUtils';
|
|
8
|
+
export { flattenChildren } from './flattenChildren';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React, { ReactChild } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* Wraps every instance of `wrap` found in `str` in the provided `element`.
|
|
6
|
+
*
|
|
7
|
+
* E.g. `wrapJSX('Apple', 'ap', 'em') => <em>Ap</em>ple`
|
|
8
|
+
*
|
|
9
|
+
* @param str
|
|
10
|
+
* @param wrap
|
|
11
|
+
* @param element
|
|
12
|
+
* @returns `JSX.Element`
|
|
13
|
+
*/
|
|
14
|
+
export const wrapJSX = (
|
|
15
|
+
str: string,
|
|
16
|
+
wrap?: string,
|
|
17
|
+
element?: keyof HTMLElementTagNameMap,
|
|
18
|
+
): JSX.Element => {
|
|
19
|
+
if (wrap && element) {
|
|
20
|
+
const regex = new RegExp(wrap, 'gi');
|
|
21
|
+
const matches = str.matchAll(regex);
|
|
22
|
+
|
|
23
|
+
if (matches) {
|
|
24
|
+
const outArray = str.split('') as Array<ReactChild>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* For every match, splice it into the "string",
|
|
28
|
+
* wrapped in the React element
|
|
29
|
+
*/
|
|
30
|
+
// Consider adding --downlevelIteration TS flag so we don't need Array.from
|
|
31
|
+
for (const match of Array.from(matches)) {
|
|
32
|
+
const matchIndex = match.index ?? -1;
|
|
33
|
+
const matchContent = match[0];
|
|
34
|
+
const matchLength = matchContent.length;
|
|
35
|
+
const key = matchIndex + matchContent + matchLength;
|
|
36
|
+
|
|
37
|
+
// We create a replacement array that's
|
|
38
|
+
// the same length as the match we're deleting,
|
|
39
|
+
// in order to keep the matchIndexes aligned
|
|
40
|
+
// with the indexes of the output array
|
|
41
|
+
const replacement = new Array<ReactChild>(matchLength).fill('');
|
|
42
|
+
replacement[0] = React.createElement(element, { key }, matchContent);
|
|
43
|
+
|
|
44
|
+
outArray.splice(matchIndex, matchLength, ...replacement);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return <>{outArray}</>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return <>{str}</>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return <>{str}</>;
|
|
54
|
+
};
|