UNPKG

@sap-ux/ui-components

Version:
78 lines 3.56 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.UIToggleGroupOption = void 0; const React = __importStar(require("react")); const UIIcon_1 = require("../../UIIcon"); const utilities_1 = require("../../../utilities"); require("./UIToggleGroupOption.scss"); /** * UIToggleGroupOption component * * @exports * @class UIToggleGroupOption * @extends {React.Component<UIToggleGroupOptionProps, {}>} */ 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 : (0, utilities_1.getUIId)('ui-toggle-group-option-'); return (React.createElement("button", { role: "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_1.UIIcon, { className: "ui-toggle-group-option-content-icon", iconName: this.props.icon }))))); } } exports.UIToggleGroupOption = UIToggleGroupOption; //# sourceMappingURL=UIToggleGroupOption.js.map