UNPKG

@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

29 lines (28 loc) 2.12 kB
import { __assign } from "tslib"; import React, { useMemo } from 'react'; import clsx from 'clsx'; import ButtonTrigger from '../../internal/components/button-trigger'; import styles from './styles.css.js'; import Option from '../../internal/components/option'; import { generateUniqueId } from '../../internal/hooks/use-unique-id'; var Trigger = function (_a) { var ariaLabelledby = _a.ariaLabelledby, ariaDescribedby = _a.ariaDescribedby, controlId = _a.controlId, invalid = _a.invalid, triggerProps = _a.triggerProps, selectedOption = _a.selectedOption, _b = _a.triggerVariant, triggerVariant = _b === void 0 ? undefined : _b, isOpen = _a.isOpen, placeholder = _a.placeholder, disabled = _a.disabled, ariaLabel = _a.ariaLabel; var id = useMemo(function () { return controlId !== null && controlId !== void 0 ? controlId : generateUniqueId(); }, [controlId]); var triggerContent = null; if (!selectedOption) { triggerContent = (React.createElement("span", { "aria-disabled": "true", className: clsx(styles.placeholder, styles.trigger), id: triggerProps.ariaLabelledby }, placeholder)); } else if (triggerVariant === 'option') { triggerContent = (React.createElement(Option, { id: triggerProps.ariaLabelledby, option: __assign(__assign({}, selectedOption), { disabled: disabled }), triggerVariant: true })); } else { triggerContent = (React.createElement("span", { id: triggerProps.ariaLabelledby, className: styles.trigger }, selectedOption.label || selectedOption.value)); } var finalAriaLabelledBy = useMemo(function () { return [ariaLabelledby, triggerProps.ariaLabelledby].filter(function (label) { return !!label; }).join(' '); }, [ariaLabelledby, triggerProps.ariaLabelledby]); var attributes = __assign(__assign({}, triggerProps), { children: triggerContent, pressed: isOpen, disabled: disabled, invalid: invalid, ariaLabel: ariaLabel, ariaDescribedby: ariaDescribedby, ariaLabelledby: finalAriaLabelledBy, id: id }); return React.createElement(ButtonTrigger, __assign({}, attributes)); }; export default Trigger;