@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
30 lines • 2.34 kB
JavaScript
import { __rest } from "tslib";
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import React from 'react';
import clsx from 'clsx';
import { getAnalyticsMetadataAttribute } from '@awsui/component-toolkit/internal/analytics-metadata';
import { getBaseProps } from '../internal/base-component';
import { useFormFieldContext } from '../internal/context/form-field-context';
import useRadioGroupForwardFocus from '../internal/hooks/forward-focus/radio-group';
import { useUniqueId } from '../internal/hooks/use-unique-id';
import RadioButton from './radio-button';
import styles from './styles.css.js';
const InternalRadioGroup = React.forwardRef((_a, ref) => {
var { name, value, items, ariaLabel, ariaRequired, ariaControls, onChange, readOnly, __internalRootRef = null } = _a, props = __rest(_a, ["name", "value", "items", "ariaLabel", "ariaRequired", "ariaControls", "onChange", "readOnly", "__internalRootRef"]);
const { ariaDescribedby, ariaLabelledby } = useFormFieldContext(props);
const baseProps = getBaseProps(props);
const generatedName = useUniqueId('awsui-radio-');
const [radioButtonRef, radioButtonRefIndex] = useRadioGroupForwardFocus(ref, items, value);
return (React.createElement("div", Object.assign({ role: "radiogroup", "aria-labelledby": ariaLabelledby, "aria-label": ariaLabel, "aria-describedby": ariaDescribedby, "aria-required": ariaRequired, "aria-controls": ariaControls, "aria-readonly": readOnly ? 'true' : undefined }, baseProps, { className: clsx(baseProps.className, styles.root), ref: __internalRootRef }), items &&
items.map((item, index) => (React.createElement(RadioButton, Object.assign({ key: item.value, ref: index === radioButtonRefIndex ? radioButtonRef : undefined, checked: item.value === value, name: name || generatedName, value: item.value, label: item.label, description: item.description, disabled: item.disabled, onChange: onChange, controlId: item.controlId, readOnly: readOnly }, getAnalyticsMetadataAttribute(!item.disabled && !readOnly
? {
detail: {
position: `${index + 1}`,
value: item.value,
},
}
: {})))))));
});
export default InternalRadioGroup;
//# sourceMappingURL=internal.js.map