UNPKG

@awsui/components-react

Version:

On July 19th, 2022, we launched [Cloudscape Design System](https://cloudscape.design). Cloudscape is an evolution of AWS-UI. It consists of user interface guidelines, front-end components, design resources, and development tools for building intuitive, en

38 lines 3.48 kB
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import React, { useEffect, useRef, useState } from 'react'; import clsx from 'clsx'; import { useMergeRefs } from '@awsui/component-toolkit/internal'; import InternalIcon from '../../icon/internal.js'; import { getBaseProps } from '../../internal/base-component'; import CheckboxIcon from '../../internal/components/checkbox-icon'; import Option from '../../internal/components/option'; import SelectableItem from '../../internal/components/selectable-item'; import Tooltip from '../../internal/components/tooltip'; import useHiddenDescription from '../../internal/hooks/use-hidden-description'; import styles from './styles.css.js'; const Item = ({ option, highlighted, selected, filteringValue, hasCheckbox, virtualPosition, padBottom, isNextSelected, isPreviousSelected, screenReaderContent, ariaPosinset, ariaSetsize, highlightType, withScrollbar, sticky, ...restProps }, ref) => { const baseProps = getBaseProps(restProps); const isParent = option.type === 'parent'; const isChild = option.type === 'child'; const wrappedOption = option.option; const disabled = option.disabled || wrappedOption.disabled; const disabledReason = disabled && wrappedOption.disabledReason ? wrappedOption.disabledReason : ''; const isDisabledWithReason = !!disabledReason; const internalRef = useRef(null); const { descriptionEl, descriptionId } = useHiddenDescription(disabledReason); const [canShowTooltip, setCanShowTooltip] = useState(true); useEffect(() => setCanShowTooltip(true), [highlighted]); return (React.createElement(SelectableItem, { ariaSelected: Boolean(selected), selected: selected, isNextSelected: isNextSelected, isPreviousSelected: isPreviousSelected, highlighted: highlighted, disabled: option.disabled, isParent: isParent, isChild: isChild, ref: useMergeRefs(ref, internalRef), virtualPosition: virtualPosition, padBottom: padBottom, screenReaderContent: screenReaderContent, ariaPosinset: ariaPosinset, ariaSetsize: ariaSetsize, highlightType: highlightType, ariaDescribedby: isDisabledWithReason ? descriptionId : '', value: option.option.value, withScrollbar: withScrollbar, sticky: sticky, ...baseProps }, React.createElement("div", { className: clsx(styles.item, !isParent && wrappedOption.labelTag && styles['show-label-tag']) }, hasCheckbox && !isParent && (React.createElement("div", { className: styles.checkbox }, React.createElement(CheckboxIcon, { checked: selected || false, disabled: option.disabled }))), React.createElement(Option, { option: { ...wrappedOption, disabled }, highlightedOption: highlighted, selectedOption: selected, highlightText: filteringValue, isGroupOption: isParent }), !hasCheckbox && !isParent && selected && (React.createElement("div", { className: styles['selected-icon'] }, React.createElement(InternalIcon, { name: "check" }))), isDisabledWithReason && (React.createElement(React.Fragment, null, descriptionEl, highlighted && canShowTooltip && (React.createElement(Tooltip, { className: styles['disabled-reason-tooltip'], trackRef: internalRef, value: disabledReason, position: "right", hideOnOverscroll: true, onDismiss: () => setCanShowTooltip(false) }))))))); }; export default React.memo(React.forwardRef(Item)); //# sourceMappingURL=item.js.map