Debian Codegraph @

node/@patternfly/react-core/dist/js/components/ToggleGroup/ToggleGroupItem.js

raw
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.ToggleGroupItem = void 0;
4 const tslib_1 = require("tslib");
5 const jsx_runtime_1 = require("react/jsx-runtime");
6 const react_styles_1 = require("@patternfly/react-styles");
7 const toggle_group_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/ToggleGroup/toggle-group"));
8 const ToggleGroupItemElement_1 = require("./ToggleGroupItemElement");
9 const ToggleGroupItem = (_a) => {
10 var { text, icon, iconPosition = 'start', className, isDisabled = false, isSelected = false, 'aria-label': ariaLabel, onChange = () => { }, buttonId } = _a, props = tslib_1.__rest(_a, ["text", "icon", "iconPosition", "className", "isDisabled", "isSelected", 'aria-label', "onChange", "buttonId"]);
11 const handleChange = (event) => {
12 onChange(event, !isSelected);
13 };
14 if (!ariaLabel && icon && !text) {
15 /* eslint-disable no-console */
16 console.warn('An accessible aria-label is required when using the toggle group item icon variant.');
17 }
18 const toggleGroupIcon = (0, jsx_runtime_1.jsx)(ToggleGroupItemElement_1.ToggleGroupItemElement, { variant: ToggleGroupItemElement_1.ToggleGroupItemVariant.icon, children: icon });
19 return ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: (0, react_styles_1.css)(toggle_group_1.default.toggleGroupItem, className) }, props, { children: (0, jsx_runtime_1.jsxs)("button", { type: "button", className: (0, react_styles_1.css)(toggle_group_1.default.toggleGroupButton, isSelected && toggle_group_1.default.modifiers.selected), "aria-pressed": isSelected, onClick: handleChange, "aria-label": ariaLabel, disabled: isDisabled, id: buttonId, children: [icon && iconPosition === 'start' && toggleGroupIcon, text && (0, jsx_runtime_1.jsx)(ToggleGroupItemElement_1.ToggleGroupItemElement, { variant: ToggleGroupItemElement_1.ToggleGroupItemVariant.text, children: text }), icon && iconPosition === 'end' && toggleGroupIcon] }) })));
20 };
21 exports.ToggleGroupItem = ToggleGroupItem;
22 exports.ToggleGroupItem.displayName = 'ToggleGroupItem';
23 //# sourceMappingURL=ToggleGroupItem.js.map