@sap-ux/ui-components
Version:
SAP UI Components Library
51 lines • 2.33 kB
JavaScript
import * as React from 'react';
import { UIIcon } from '../../UIIcon/index.js';
import { getUIId } from '../../../utilities/index.js';
import './UIToggleGroupOption.scss';
/**
* UIToggleGroupOption component
*
* @exports
* @class UIToggleGroupOption
* @extends {React.Component<UIToggleGroupOptionProps, {}>}
*/
export class UIToggleGroupOption extends React.Component {
/**
* Initializes component properties.
*
* @param {UIToggleGroupOptionProps} props
*/
constructor(props) {
super(props);
this.onClick = (evt) => {
this.props.onClick?.(evt, this.props);
};
this.onBlur = (evt) => {
this.props.onBlur?.(evt, this.props);
};
this.onFocus = (evt) => {
this.props.onFocus?.(evt, this.props);
};
this.onClick = this.onClick.bind(this);
this.onFocus = this.onFocus.bind(this);
this.onBlur = this.onBlur.bind(this);
}
/**
* @returns {JSX.Element}
*/
render() {
const labelId = this.props.labelId ? this.props.labelId : getUIId('ui-toggle-group-option-');
return (React.createElement("button", { ...(this.props.title && { title: this.props.title }), "data-is-focusable": "true", className: [
'ui-toggle-group-option',
this.props.focused ? 'ui-toggle-group-option--focused' : '',
this.props.selected ? 'ui-toggle-group-option--selected' : '',
this.props.disabled ? 'ui-toggle-group-option--disabled' : ''
]
.filter((x) => !!x)
.join(' '), ...(this.props.ariaLabel && { 'aria-labelledby': labelId }), disabled: this.props.disabled || false, onClick: this.onClick, onFocus: this.onFocus, onBlur: this.onBlur },
React.createElement("span", { className: "ui-toggle-group-option-content", tabIndex: -1 },
this.props.text && (React.createElement("span", { id: labelId, className: "ui-toggle-group-option-content-text", ...(this.props.ariaLabel && { 'aria-label': this.props.ariaLabel }) }, this.props.text)),
this.props.icon && (React.createElement(UIIcon, { className: "ui-toggle-group-option-content-icon", iconName: this.props.icon })))));
}
}
//# sourceMappingURL=UIToggleGroupOption.js.map