| 1 |
import { __rest } from "tslib"; |
| 2 |
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; |
| 3 |
import { css } from '@patternfly/react-styles'; |
| 4 |
import styles from '@patternfly/react-styles/css/components/ToggleGroup/toggle-group.mjs'; |
| 5 |
import { ToggleGroupItemVariant, ToggleGroupItemElement } from './ToggleGroupItemElement'; |
| 6 |
export const ToggleGroupItem = (_a) => { |
| 7 |
var { text, icon, iconPosition = 'start', className, isDisabled = false, isSelected = false, 'aria-label': ariaLabel, onChange = () => { }, buttonId } = _a, props = __rest(_a, ["text", "icon", "iconPosition", "className", "isDisabled", "isSelected", 'aria-label', "onChange", "buttonId"]); |
| 8 |
const handleChange = (event) => { |
| 9 |
onChange(event, !isSelected); |
| 10 |
}; |
| 11 |
if (!ariaLabel && icon && !text) { |
| 12 |
/* eslint-disable no-console */ |
| 13 |
console.warn('An accessible aria-label is required when using the toggle group item icon variant.'); |
| 14 |
} |
| 15 |
const toggleGroupIcon = _jsx(ToggleGroupItemElement, { variant: ToggleGroupItemVariant.icon, children: icon }); |
| 16 |
return (_jsx("div", Object.assign({ className: css(styles.toggleGroupItem, className) }, props, { children: _jsxs("button", { type: "button", className: css(styles.toggleGroupButton, isSelected && styles.modifiers.selected), "aria-pressed": isSelected, onClick: handleChange, "aria-label": ariaLabel, disabled: isDisabled, id: buttonId, children: [icon && iconPosition === 'start' && toggleGroupIcon, text && _jsx(ToggleGroupItemElement, { variant: ToggleGroupItemVariant.text, children: text }), icon && iconPosition === 'end' && toggleGroupIcon] }) }))); |
| 17 |
}; |
| 18 |
ToggleGroupItem.displayName = 'ToggleGroupItem'; |
| 19 |
//# sourceMappingURL=ToggleGroupItem.js.map |