UNPKG

@kui-shell/plugin-client-common

Version:

Kui plugin that offers stylesheets

69 lines 3.52 kB
/* * Copyright 2020 The Kubernetes Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import React from 'react'; import { pexecInCurrentTab } from '@kui-shell/core/mdist/api/Exec'; import Tooltip from '../../spi/Tooltip'; const Popover = React.lazy(() => import('../../spi/Popover')); export default class TextWithIconWidget extends React.PureComponent { constructor() { super(...arguments); this._onClick = !this.props.textOnclick ? undefined : () => { if (typeof this.props.textOnclick === 'string') { pexecInCurrentTab(this.props.textOnclick); } else { this.props.textOnclick(); } }; } /** Render the content (excluding any popover/tooltip wrappers) part */ content() { const iconClassName = 'kui--status-stripe-icon ' + (this.props.iconIsNarrow ? 'tiny-right-pad' : 'small-right-pad') + (this.props.iconOnclick ? ' clickable' : ''); const iconPart = !this.props.children || React.Children.count(this.props.children) === 0 ? (React.createElement(React.Fragment, null)) : this.props.iconOnclick ? (React.createElement("a", { href: "#", className: iconClassName, onMouseDown: evt => evt.preventDefault(), onClick: !this.props.iconOnclick ? undefined : (evt) => { evt.stopPropagation(); if (typeof this.props.iconOnclick === 'string') { pexecInCurrentTab(this.props.iconOnclick); } else { this.props.iconOnclick(); } } }, this.props.children)) : (React.createElement("span", { className: iconClassName }, this.props.children)); const textPart = React.createElement("span", { className: "kui--status-stripe-text" }, this.props.text); const className = 'kui--status-stripe-element' + (this.props.textOnclick || this.props.popover ? ' kui--status-stripe-element-clickable' : '') + (!this.props.id ? '' : ' ' + this.props.id) + (this.props.className ? ' ' + this.props.className : ''); return (React.createElement(Tooltip, { content: this.props.title, position: this.props.position }, React.createElement("div", { className: className, onClick: this._onClick, "data-view": this.props.viewLevel }, iconPart, textPart))); } render() { if (this.props.popover) { return (React.createElement(Popover, Object.assign({ maxWidth: "60rem", minWidth: "5rem", triggerClassName: "kui--status-stripe-element-wrapper", position: this.props.position || 'top-start' /* default value; the props.popover may override this */ }, this.props.popover), this.content())); } else { return this.content(); } } } //# sourceMappingURL=TextWithIconWidget.js.map