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

32 lines 2.35 kB
import { __rest } from "tslib"; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import React, { useRef } from 'react'; import clsx from 'clsx'; import { copyAnalyticsMetadataAttribute } from '@awsui/component-toolkit/internal/analytics-metadata'; import { fireNonCancelableEvent } from '../internal/events'; import { useMergeRefs } from '../internal/hooks/use-merge-refs'; import { useVisualRefresh } from '../internal/hooks/use-visual-mode'; import RadioButton from '../radio-group/radio-button'; import analyticsSelectors from './analytics-metadata/styles.css.js'; import styles from './styles.css.js'; export const Tile = React.forwardRef((_a, forwardedRef) => { var { item, selected, name, breakpoint, onChange, readOnly } = _a, rest = __rest(_a, ["item", "selected", "name", "breakpoint", "onChange", "readOnly"]); const internalRef = useRef(null); const isVisualRefresh = useVisualRefresh(); const mergedRef = useMergeRefs(internalRef, forwardedRef); return (React.createElement("div", Object.assign({ className: clsx(styles['tile-container'], { [styles['has-metadata']]: item.description || item.image }, { [styles.selected]: selected }, { [styles.disabled]: !!item.disabled }, { [styles.readonly]: readOnly }, { [styles.refresh]: isVisualRefresh }, styles[`breakpoint-${breakpoint}`]), "data-value": item.value, onClick: () => { var _a; if (item.disabled || readOnly) { return; } (_a = internalRef.current) === null || _a === void 0 ? void 0 : _a.focus(); if (!selected) { fireNonCancelableEvent(onChange, { value: item.value }); } } }, copyAnalyticsMetadataAttribute(rest)), React.createElement("div", { className: clsx(styles.control, { [styles['no-image']]: !item.image }) }, React.createElement(RadioButton, { checked: selected, ref: mergedRef, name: name, value: item.value, label: item.label, description: item.description, disabled: item.disabled, controlId: item.controlId, readOnly: readOnly, className: analyticsSelectors['radio-button'] })), item.image && React.createElement("div", { className: clsx(styles.image, { [styles.disabled]: !!item.disabled }) }, item.image))); }); //# sourceMappingURL=tile.js.map