@opengovsg/oui 0.0.7 → 0.0.8
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/dist/cjs/badge/badge.cjs +42 -0
- package/dist/cjs/badge/index.cjs +8 -0
- package/dist/cjs/badge/use-badge.cjs +111 -0
- package/dist/cjs/combo-box/combo-box-fuzzy.cjs +52 -30
- package/dist/cjs/combo-box/combo-box-item.cjs +70 -0
- package/dist/cjs/combo-box/combo-box-variant-context.cjs +13 -0
- package/dist/cjs/combo-box/combo-box.cjs +46 -100
- package/dist/cjs/combo-box/index.cjs +5 -1
- package/dist/cjs/index.cjs +14 -3
- package/dist/cjs/select/index.cjs +5 -0
- package/dist/cjs/select/select-item.cjs +1 -0
- package/dist/cjs/select/select-variant-context.cjs +1 -0
- package/dist/cjs/system/react-utils/index.cjs +2 -0
- package/dist/cjs/system/react-utils/refs.cjs +12 -0
- package/dist/cjs/tag-field/tag-field-list.cjs +3 -2
- package/dist/cjs/tag-field/tag-field-trigger.cjs +1 -0
- package/dist/cjs/tag-field/tag-field.cjs +1 -1
- package/dist/esm/badge/badge.js +40 -0
- package/dist/esm/badge/index.js +2 -0
- package/dist/esm/badge/use-badge.js +109 -0
- package/dist/esm/combo-box/combo-box-fuzzy.js +55 -33
- package/dist/esm/combo-box/combo-box-item.js +68 -0
- package/dist/esm/combo-box/combo-box-variant-context.js +10 -0
- package/dist/esm/combo-box/combo-box.js +48 -101
- package/dist/esm/combo-box/index.js +3 -1
- package/dist/esm/index.js +7 -2
- package/dist/esm/select/index.js +2 -0
- package/dist/esm/select/select-item.js +1 -0
- package/dist/esm/select/select-variant-context.js +1 -0
- package/dist/esm/system/react-utils/index.js +1 -0
- package/dist/esm/system/react-utils/refs.js +10 -0
- package/dist/esm/tag-field/tag-field-list.js +3 -2
- package/dist/esm/tag-field/tag-field-trigger.js +1 -0
- package/dist/esm/tag-field/tag-field.js +1 -1
- package/dist/types/badge/badge.d.ts +3 -0
- package/dist/types/badge/badge.d.ts.map +1 -0
- package/dist/types/badge/index.d.ts +2 -0
- package/dist/types/badge/index.d.ts.map +1 -0
- package/dist/types/badge/use-badge.d.ts +166 -0
- package/dist/types/badge/use-badge.d.ts.map +1 -0
- package/dist/types/combo-box/combo-box-fuzzy.d.ts +12 -4
- package/dist/types/combo-box/combo-box-fuzzy.d.ts.map +1 -1
- package/dist/types/combo-box/combo-box-item.d.ts +11 -0
- package/dist/types/combo-box/combo-box-item.d.ts.map +1 -0
- package/dist/types/combo-box/combo-box-variant-context.d.ts +4 -0
- package/dist/types/combo-box/combo-box-variant-context.d.ts.map +1 -0
- package/dist/types/combo-box/combo-box.d.ts +5 -21
- package/dist/types/combo-box/combo-box.d.ts.map +1 -1
- package/dist/types/combo-box/index.d.ts +2 -0
- package/dist/types/combo-box/index.d.ts.map +1 -1
- package/dist/types/index.d.mts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/select/index.d.ts +2 -0
- package/dist/types/select/index.d.ts.map +1 -1
- package/dist/types/select/select-item.d.ts.map +1 -1
- package/dist/types/select/select-variant-context.d.ts.map +1 -1
- package/dist/types/system/react-utils/index.d.ts +1 -0
- package/dist/types/system/react-utils/index.d.ts.map +1 -1
- package/dist/types/system/react-utils/refs.d.ts +4 -0
- package/dist/types/system/react-utils/refs.d.ts.map +1 -0
- package/dist/types/tag-field/tag-field-list.d.ts +5 -5
- package/dist/types/tag-field/tag-field-list.d.ts.map +1 -1
- package/dist/types/tag-field/tag-field-root.d.ts +4 -4
- package/dist/types/tag-field/tag-field-root.d.ts.map +1 -1
- package/dist/types/tag-field/tag-field-tag-list.d.ts +2 -3
- package/dist/types/tag-field/tag-field-tag-list.d.ts.map +1 -1
- package/dist/types/tag-field/tag-field-trigger.d.ts.map +1 -1
- package/dist/types/tag-field/tag-field.d.ts +2 -2
- package/dist/types/tag-field/tag-field.d.ts.map +1 -1
- package/dist/types/tag-field/types.d.ts +0 -5
- package/dist/types/tag-field/types.d.ts.map +1 -1
- package/package.json +6 -5
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
var input = require('./input/input.cjs');
|
|
4
5
|
var useControllableState = require('./hooks/use-controllable-state.cjs');
|
|
5
6
|
var button = require('./button/button.cjs');
|
|
6
7
|
var govtBanner = require('./govt-banner/govt-banner.cjs');
|
|
@@ -10,19 +11,24 @@ var spinner = require('./spinner/spinner.cjs');
|
|
|
10
11
|
var useSpinner = require('./spinner/use-spinner.cjs');
|
|
11
12
|
var toggle = require('./toggle/toggle.cjs');
|
|
12
13
|
var skipNavLink = require('./skip-nav-link/skip-nav-link.cjs');
|
|
13
|
-
var input = require('./input/input.cjs');
|
|
14
14
|
var textField = require('./text-field/text-field.cjs');
|
|
15
15
|
var field = require('./field/field.cjs');
|
|
16
16
|
var textArea = require('./text-area/text-area.cjs');
|
|
17
17
|
var textAreaField = require('./text-area-field/text-area-field.cjs');
|
|
18
18
|
var comboBox = require('./combo-box/combo-box.cjs');
|
|
19
19
|
var comboBoxFuzzy = require('./combo-box/combo-box-fuzzy.cjs');
|
|
20
|
+
var comboBoxItem = require('./combo-box/combo-box-item.cjs');
|
|
21
|
+
var comboBoxVariantContext = require('./combo-box/combo-box-variant-context.cjs');
|
|
20
22
|
var banner = require('./banner/banner.cjs');
|
|
21
23
|
var tagField = require('./tag-field/tag-field.cjs');
|
|
22
24
|
var select = require('./select/select.cjs');
|
|
25
|
+
var selectItem = require('./select/select-item.cjs');
|
|
26
|
+
var selectVariantContext = require('./select/select-variant-context.cjs');
|
|
27
|
+
var badge = require('./badge/badge.cjs');
|
|
23
28
|
|
|
24
29
|
|
|
25
30
|
|
|
31
|
+
exports.Input = input.Input;
|
|
26
32
|
exports.useControllableState = useControllableState.useControllableState;
|
|
27
33
|
exports.Button = button.Button;
|
|
28
34
|
exports.GovtBanner = govtBanner.GovtBanner;
|
|
@@ -32,7 +38,6 @@ exports.Spinner = spinner.Spinner;
|
|
|
32
38
|
exports.useSpinner = useSpinner.useSpinner;
|
|
33
39
|
exports.Toggle = toggle.Toggle;
|
|
34
40
|
exports.SkipNavLink = skipNavLink.SkipNavLink;
|
|
35
|
-
exports.Input = input.Input;
|
|
36
41
|
exports.TextField = textField.TextField;
|
|
37
42
|
exports.Description = field.Description;
|
|
38
43
|
exports.FieldError = field.FieldError;
|
|
@@ -42,8 +47,14 @@ exports.TextArea = textArea.TextArea;
|
|
|
42
47
|
exports.TextAreaField = textAreaField.TextAreaField;
|
|
43
48
|
exports.ComboBox = comboBox.ComboBox;
|
|
44
49
|
exports.ComboBoxEmptyState = comboBox.ComboBoxEmptyState;
|
|
45
|
-
exports.ComboBoxItem = comboBox.ComboBoxItem;
|
|
46
50
|
exports.ComboBoxFuzzy = comboBoxFuzzy.ComboBoxFuzzy;
|
|
51
|
+
exports.ComboBoxItem = comboBoxItem.ComboBoxItem;
|
|
52
|
+
exports.ComboBoxVariantContext = comboBoxVariantContext.ComboBoxVariantContext;
|
|
53
|
+
exports.useComboBoxVariantContext = comboBoxVariantContext.useComboBoxVariantContext;
|
|
47
54
|
exports.Banner = banner.Banner;
|
|
48
55
|
exports.TagField = tagField.TagField;
|
|
49
56
|
exports.Select = select.Select;
|
|
57
|
+
exports.SelectItem = selectItem.SelectItem;
|
|
58
|
+
exports.SelectVariantContext = selectVariantContext.SelectVariantContext;
|
|
59
|
+
exports.useSelectVariantContext = selectVariantContext.useSelectVariantContext;
|
|
60
|
+
exports.Badge = badge.Badge;
|
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var select = require('./select.cjs');
|
|
5
|
+
var selectItem = require('./select-item.cjs');
|
|
6
|
+
var selectVariantContext = require('./select-variant-context.cjs');
|
|
5
7
|
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
exports.Select = select.Select;
|
|
11
|
+
exports.SelectItem = selectItem.SelectItem;
|
|
12
|
+
exports.SelectVariantContext = selectVariantContext.SelectVariantContext;
|
|
13
|
+
exports.useSelectVariantContext = selectVariantContext.useSelectVariantContext;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
"use client";
|
|
2
3
|
'use strict';
|
|
3
4
|
|
|
4
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
@@ -56,8 +57,8 @@ const TagFieldListInner = (props, ref) => {
|
|
|
56
57
|
item,
|
|
57
58
|
isHighlighted: highlightedIndex === virtualRow.index,
|
|
58
59
|
key: virtualRow.key,
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
itemClassNames,
|
|
61
|
+
...itemProps
|
|
61
62
|
};
|
|
62
63
|
if (typeof props.children === "function") {
|
|
63
64
|
return props.children(childProps);
|
|
@@ -6,13 +6,13 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
6
6
|
var react = require('react');
|
|
7
7
|
var reactAriaComponents = require('react-aria-components');
|
|
8
8
|
var ouiTheme = require('@opengovsg/oui-theme');
|
|
9
|
+
var input = require('../input/input.cjs');
|
|
9
10
|
var tagFieldList = require('./tag-field-list.cjs');
|
|
10
11
|
var tagFieldRoot = require('./tag-field-root.cjs');
|
|
11
12
|
var tagFieldTagList = require('./tag-field-tag-list.cjs');
|
|
12
13
|
var tagFieldTrigger = require('./tag-field-trigger.cjs');
|
|
13
14
|
var chevronDown = require('../node_modules/.pnpm/lucide-react@0.475.0_react@19.0.0/node_modules/lucide-react/dist/esm/icons/chevron-down.cjs');
|
|
14
15
|
var field = require('../field/field.cjs');
|
|
15
|
-
var input = require('../input/input.cjs');
|
|
16
16
|
|
|
17
17
|
function TagField({
|
|
18
18
|
classNames,
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
4
|
+
import { forwardRef, useMemo } from 'react';
|
|
5
|
+
import { useBadge } from './use-badge.js';
|
|
6
|
+
import X from '../node_modules/.pnpm/lucide-react@0.475.0_react@19.0.0/node_modules/lucide-react/dist/esm/icons/x.js';
|
|
7
|
+
|
|
8
|
+
const Badge = forwardRef((props, ref) => {
|
|
9
|
+
const {
|
|
10
|
+
Component,
|
|
11
|
+
children,
|
|
12
|
+
slots,
|
|
13
|
+
classNames,
|
|
14
|
+
getChipProps,
|
|
15
|
+
getCloseButtonProps,
|
|
16
|
+
startContent,
|
|
17
|
+
endContent,
|
|
18
|
+
isCloseable
|
|
19
|
+
} = useBadge({ ...props, ref });
|
|
20
|
+
const start = useMemo(() => {
|
|
21
|
+
if (props.variant === "dot" && !startContent) {
|
|
22
|
+
return /* @__PURE__ */ jsx("span", { className: slots.dot({ className: classNames?.dot }) });
|
|
23
|
+
}
|
|
24
|
+
return startContent;
|
|
25
|
+
}, [props.variant, startContent, slots, classNames?.dot]);
|
|
26
|
+
const end = useMemo(() => {
|
|
27
|
+
if (isCloseable) {
|
|
28
|
+
return /* @__PURE__ */ jsx("span", { ...getCloseButtonProps(), children: endContent ?? /* @__PURE__ */ jsx(X, { className: "size-full" }) });
|
|
29
|
+
}
|
|
30
|
+
return endContent;
|
|
31
|
+
}, [endContent, getCloseButtonProps, isCloseable]);
|
|
32
|
+
return /* @__PURE__ */ jsxs(Component, { ...getChipProps(), children: [
|
|
33
|
+
start,
|
|
34
|
+
/* @__PURE__ */ jsx("span", { className: slots.content({ className: classNames?.content }), children }),
|
|
35
|
+
end
|
|
36
|
+
] });
|
|
37
|
+
});
|
|
38
|
+
Badge.displayName = "Badge";
|
|
39
|
+
|
|
40
|
+
export { Badge };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { useMemo, useCallback, cloneElement, isValidElement } from 'react';
|
|
3
|
+
import { mergeProps } from '@react-aria/utils';
|
|
4
|
+
import { useMessageFormatter, useFocusRing, usePress } from 'react-aria';
|
|
5
|
+
import { useDeepCompareMemo } from 'use-deep-compare';
|
|
6
|
+
import { badgeStyles, cn, badgeCloseButtonStyles } from '@opengovsg/oui-theme';
|
|
7
|
+
import { mapPropsVariants } from '../system/utils.js';
|
|
8
|
+
import { useDomRef } from '../system/react-utils/refs.js';
|
|
9
|
+
|
|
10
|
+
const i18nStrings = {
|
|
11
|
+
"en-SG": {
|
|
12
|
+
close: "Close badge"
|
|
13
|
+
},
|
|
14
|
+
"zh-SG": {
|
|
15
|
+
close: "\u5173\u95ED\u5FBD\u7AE0"
|
|
16
|
+
},
|
|
17
|
+
"ms-SG": {
|
|
18
|
+
close: "Tutup lencana"
|
|
19
|
+
},
|
|
20
|
+
"ta-SG": {
|
|
21
|
+
close: "\u0BAA\u0BC7\u0B9F\u0BCD\u0B9C\u0BC8 \u0BAE\u0BC2\u0B9F\u0BC1"
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
function useBadge(originalProps) {
|
|
25
|
+
const [_props, variantProps] = mapPropsVariants(
|
|
26
|
+
originalProps,
|
|
27
|
+
badgeStyles.variantKeys
|
|
28
|
+
);
|
|
29
|
+
const {
|
|
30
|
+
ref,
|
|
31
|
+
as,
|
|
32
|
+
children,
|
|
33
|
+
startContent,
|
|
34
|
+
endContent,
|
|
35
|
+
onClose,
|
|
36
|
+
classNames,
|
|
37
|
+
className,
|
|
38
|
+
...props
|
|
39
|
+
} = _props;
|
|
40
|
+
const domRef = useDomRef(ref);
|
|
41
|
+
const Component = useMemo(() => as || "div", [as]);
|
|
42
|
+
const baseClassName = cn(classNames?.base, className);
|
|
43
|
+
const formatMessage = useMessageFormatter(i18nStrings);
|
|
44
|
+
const isCloseable = variantProps.isCloseable || !!onClose;
|
|
45
|
+
const {
|
|
46
|
+
focusProps: closeFocusProps,
|
|
47
|
+
isFocusVisible: isCloseButtonFocusVisible
|
|
48
|
+
} = useFocusRing();
|
|
49
|
+
const slots = useDeepCompareMemo(
|
|
50
|
+
() => ({
|
|
51
|
+
...badgeStyles({ isCloseable, ...variantProps }),
|
|
52
|
+
closeButton: badgeCloseButtonStyles
|
|
53
|
+
}),
|
|
54
|
+
[variantProps, isCloseable, badgeStyles, badgeCloseButtonStyles]
|
|
55
|
+
);
|
|
56
|
+
const { pressProps: closePressProps } = usePress({
|
|
57
|
+
isDisabled: !!variantProps?.isDisabled,
|
|
58
|
+
onPress: onClose
|
|
59
|
+
});
|
|
60
|
+
const getContentClone = useCallback(
|
|
61
|
+
(content) => isValidElement(content) ? cloneElement(content, {
|
|
62
|
+
// @ts-expect-error types are not full
|
|
63
|
+
className: content.props?.className
|
|
64
|
+
}) : null,
|
|
65
|
+
[]
|
|
66
|
+
);
|
|
67
|
+
const getChipProps = useCallback(() => {
|
|
68
|
+
return {
|
|
69
|
+
ref: domRef,
|
|
70
|
+
className: slots.base({ className: baseClassName }),
|
|
71
|
+
"aria-disabled": variantProps?.isDisabled,
|
|
72
|
+
...props
|
|
73
|
+
};
|
|
74
|
+
}, [baseClassName, domRef, props, slots, variantProps?.isDisabled]);
|
|
75
|
+
const getCloseButtonProps = useCallback(() => {
|
|
76
|
+
return {
|
|
77
|
+
role: "button",
|
|
78
|
+
tabIndex: 0,
|
|
79
|
+
className: slots.closeButton({
|
|
80
|
+
size: variantProps?.size,
|
|
81
|
+
className: classNames?.closeButton,
|
|
82
|
+
isFocusVisible: isCloseButtonFocusVisible
|
|
83
|
+
}),
|
|
84
|
+
"aria-label": formatMessage("close"),
|
|
85
|
+
...mergeProps(closePressProps, closeFocusProps)
|
|
86
|
+
};
|
|
87
|
+
}, [
|
|
88
|
+
classNames?.closeButton,
|
|
89
|
+
closeFocusProps,
|
|
90
|
+
closePressProps,
|
|
91
|
+
formatMessage,
|
|
92
|
+
isCloseButtonFocusVisible,
|
|
93
|
+
slots,
|
|
94
|
+
variantProps?.size
|
|
95
|
+
]);
|
|
96
|
+
return {
|
|
97
|
+
Component,
|
|
98
|
+
children,
|
|
99
|
+
slots,
|
|
100
|
+
classNames,
|
|
101
|
+
isCloseable,
|
|
102
|
+
startContent: getContentClone(startContent),
|
|
103
|
+
endContent: getContentClone(endContent),
|
|
104
|
+
getCloseButtonProps,
|
|
105
|
+
getChipProps
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { useBadge };
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
"use client";
|
|
3
|
-
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
import { useDeferredValue, useMemo, useState, useCallback } from 'react';
|
|
5
5
|
import fuzzysort from 'fuzzysort';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { Text } from 'react-aria-components';
|
|
7
|
+
import { comboBoxStyles, comboBoxItemStyles, comboBoxFuzzyHighlightedTextStyles } from '@opengovsg/oui-theme';
|
|
8
|
+
import { mapPropsVariants } from '../system/utils.js';
|
|
9
|
+
import { ComboBox } from './combo-box.js';
|
|
10
|
+
import { ComboBoxItem } from './combo-box-item.js';
|
|
8
11
|
|
|
9
12
|
function HighlightedText({
|
|
10
13
|
result,
|
|
@@ -27,18 +30,24 @@ function HighlightedText({
|
|
|
27
30
|
i
|
|
28
31
|
));
|
|
29
32
|
}
|
|
30
|
-
function ComboBoxFuzzy({
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
function ComboBoxFuzzy(originalProps) {
|
|
34
|
+
const [_props, variantProps] = mapPropsVariants(
|
|
35
|
+
originalProps,
|
|
36
|
+
comboBoxStyles.variantKeys
|
|
37
|
+
);
|
|
38
|
+
const {
|
|
39
|
+
items,
|
|
40
|
+
itemClassNames,
|
|
41
|
+
onSelectionChange: onSelectionChangeProp,
|
|
42
|
+
onInputChange: onInputChangeProp,
|
|
43
|
+
inputValue,
|
|
44
|
+
...props
|
|
45
|
+
} = _props;
|
|
46
|
+
const deferredInputValue = useDeferredValue(inputValue);
|
|
38
47
|
const preparedItems = useMemo(() => {
|
|
39
48
|
return items?.map((item) => ({
|
|
40
49
|
...item,
|
|
41
|
-
prepared: fuzzysort.prepare(item.
|
|
50
|
+
prepared: fuzzysort.prepare(item.textValue)
|
|
42
51
|
})) ?? [];
|
|
43
52
|
}, [items]);
|
|
44
53
|
const [filteredResults, setFilteredResults] = useState({ items, result: {} });
|
|
@@ -61,7 +70,7 @@ function ComboBoxFuzzy({
|
|
|
61
70
|
}).reduce(
|
|
62
71
|
(acc, result) => {
|
|
63
72
|
acc.items.push(result.obj);
|
|
64
|
-
acc.result[result.obj.
|
|
73
|
+
acc.result[result.obj.textValue] = result;
|
|
65
74
|
return acc;
|
|
66
75
|
},
|
|
67
76
|
{ items: [], result: {} }
|
|
@@ -70,34 +79,47 @@ function ComboBoxFuzzy({
|
|
|
70
79
|
},
|
|
71
80
|
[onInputChangeProp, preparedItems]
|
|
72
81
|
);
|
|
82
|
+
const comboboxItemStyles = comboBoxItemStyles(variantProps);
|
|
73
83
|
return /* @__PURE__ */ jsx(
|
|
74
84
|
ComboBox,
|
|
75
85
|
{
|
|
76
86
|
...props,
|
|
87
|
+
inputValue,
|
|
77
88
|
items: filteredResults.items,
|
|
78
89
|
dependencies: [deferredInputValue],
|
|
79
90
|
onSelectionChange,
|
|
80
91
|
onInputChange,
|
|
81
|
-
children: (item) => /* @__PURE__ */ jsx(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
92
|
+
children: (item) => /* @__PURE__ */ jsx(ComboBoxItem, { textValue: item.textValue, id: item.id, children: ({ isSelected, isFocused }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
93
|
+
/* @__PURE__ */ jsx(
|
|
94
|
+
Text,
|
|
95
|
+
{
|
|
96
|
+
className: comboboxItemStyles.label({
|
|
97
|
+
className: itemClassNames?.label
|
|
98
|
+
}),
|
|
99
|
+
slot: "label",
|
|
100
|
+
children: /* @__PURE__ */ jsx(
|
|
101
|
+
HighlightedText,
|
|
102
|
+
{
|
|
103
|
+
className: itemClassNames?.highlight,
|
|
104
|
+
result: filteredResults.result?.[item.textValue],
|
|
105
|
+
originalText: item.textValue,
|
|
106
|
+
isSelected,
|
|
107
|
+
isFocused
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
),
|
|
112
|
+
item.description && /* @__PURE__ */ jsx(
|
|
113
|
+
Text,
|
|
114
|
+
{
|
|
115
|
+
className: comboboxItemStyles.description({
|
|
116
|
+
className: itemClassNames?.description
|
|
117
|
+
}),
|
|
118
|
+
slot: "description",
|
|
119
|
+
children: item.description
|
|
120
|
+
}
|
|
121
|
+
)
|
|
122
|
+
] }) }, item.id)
|
|
101
123
|
}
|
|
102
124
|
);
|
|
103
125
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
import { useContextProps, ListBoxItem, composeRenderProps, Text } from 'react-aria-components';
|
|
6
|
+
import { comboBoxItemStyles } from '@opengovsg/oui-theme';
|
|
7
|
+
import { forwardRef, mapPropsVariants } from '../system/utils.js';
|
|
8
|
+
import { ComboBoxVariantContext } from './combo-box-variant-context.js';
|
|
9
|
+
|
|
10
|
+
const ComboBoxItem = forwardRef(function ComboBoxItem2(originalProps, ref) {
|
|
11
|
+
[originalProps, ref] = useContextProps(
|
|
12
|
+
originalProps,
|
|
13
|
+
ref,
|
|
14
|
+
ComboBoxVariantContext
|
|
15
|
+
);
|
|
16
|
+
const [
|
|
17
|
+
{ className, description, children, classNames, ...props },
|
|
18
|
+
variantProps
|
|
19
|
+
] = mapPropsVariants(originalProps, comboBoxItemStyles.variantKeys);
|
|
20
|
+
const styles = comboBoxItemStyles(variantProps);
|
|
21
|
+
const defaultTextValue = useMemo(() => {
|
|
22
|
+
if (props.textValue) {
|
|
23
|
+
return props.textValue;
|
|
24
|
+
}
|
|
25
|
+
if (typeof children === "string") {
|
|
26
|
+
return children;
|
|
27
|
+
}
|
|
28
|
+
return void 0;
|
|
29
|
+
}, [children, props.textValue]);
|
|
30
|
+
return /* @__PURE__ */ jsx(
|
|
31
|
+
ListBoxItem,
|
|
32
|
+
{
|
|
33
|
+
textValue: defaultTextValue,
|
|
34
|
+
...props,
|
|
35
|
+
className: composeRenderProps(
|
|
36
|
+
className ?? classNames?.container,
|
|
37
|
+
(className2, renderProps) => styles.container({ ...renderProps, className: className2 })
|
|
38
|
+
),
|
|
39
|
+
children: (renderProps) => {
|
|
40
|
+
if (typeof children === "function") {
|
|
41
|
+
return children(renderProps);
|
|
42
|
+
}
|
|
43
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
44
|
+
/* @__PURE__ */ jsx(
|
|
45
|
+
Text,
|
|
46
|
+
{
|
|
47
|
+
className: styles.label({ className: classNames?.label }),
|
|
48
|
+
slot: "label",
|
|
49
|
+
children
|
|
50
|
+
}
|
|
51
|
+
),
|
|
52
|
+
description && /* @__PURE__ */ jsx(
|
|
53
|
+
Text,
|
|
54
|
+
{
|
|
55
|
+
className: styles.description({
|
|
56
|
+
className: classNames?.description
|
|
57
|
+
}),
|
|
58
|
+
slot: "description",
|
|
59
|
+
children: description
|
|
60
|
+
}
|
|
61
|
+
)
|
|
62
|
+
] });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
export { ComboBoxItem };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
import { createContext } from '../system/react-utils/context.js';
|
|
4
|
+
|
|
5
|
+
const [ComboBoxVariantContext, useComboBoxVariantContext] = createContext({
|
|
6
|
+
name: "ComboBoxVariantContext",
|
|
7
|
+
strict: true
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export { ComboBoxVariantContext, useComboBoxVariantContext };
|