@awsui/components-react
Version:
AWS UI is a collection of [React](https://reactjs.org/) components that help create intuitive, responsive, and accessible user experiences for web applications. It is developed by Amazon Web Services (AWS). This work is available under the terms of the [A
28 lines (27 loc) • 1.83 kB
JavaScript
import { __assign, __rest } from "tslib";
import React from 'react';
import OptionComponent from '../internal/components/option';
import SelectableItem from '../internal/components/selectable-item';
import { getBaseProps } from '../internal/base-component';
import { getTestOptionIndexes } from '../internal/components/options-list/utils/test-indexes';
var AutosuggestOption = function (_a, ref) {
var highlightText = _a.highlightText, option = _a.option, highlighted = _a.highlighted, enteredTextLabel = _a.enteredTextLabel, virtualPosition = _a.virtualPosition, rest = __rest(_a, ["highlightText", "option", "highlighted", "enteredTextLabel", "virtualPosition"]);
var baseProps = getBaseProps(rest);
var useEntered = 'type' in option && option.type === 'use-entered';
var isParent = 'type' in option && option.type === 'parent';
var isChild = 'type' in option && option.type === 'child';
var _b = getTestOptionIndexes(option) || {}, throughIndex = _b.throughIndex, inGroupIndex = _b.inGroupIndex, groupIndex = _b.groupIndex;
var optionContent;
if (useEntered) {
optionContent = enteredTextLabel(option.value || '');
}
else if (isParent) {
optionContent = option.label;
}
else {
optionContent = React.createElement(OptionComponent, { option: option, highlightText: highlightText });
}
return (React.createElement(SelectableItem, __assign({ highlighted: highlighted, disabled: option.disabled, hasBackground: useEntered, isParent: isParent, isChild: isChild }, baseProps, { virtualPosition: virtualPosition, "data-test-index": throughIndex, "data-in-group-index": inGroupIndex, "data-group-index": groupIndex, ref: ref }),
React.createElement("div", null, optionContent)));
};
export default React.memo(React.forwardRef(AutosuggestOption));