UNPKG

@blueprintjs/core

Version:

Core styles & components

82 lines 4.76 kB
"use strict"; /* * Copyright 2024 Palantir Technologies, Inc. All rights reserved. * * 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. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.EntityTitle = void 0; var tslib_1 = require("tslib"); var classnames_1 = tslib_1.__importDefault(require("classnames")); var React = tslib_1.__importStar(require("react")); var icons_1 = require("@blueprintjs/icons"); var common_1 = require("../../common"); var html_1 = require("../html/html"); var icon_1 = require("../icon/icon"); var text_1 = require("../text/text"); /** * EntityTitle component. * * @see https://blueprintjs.com/docs/#core/components/entity-title */ exports.EntityTitle = React.forwardRef(function (props, ref) { var _a, _b, _c, _d; var className = props.className, _e = props.ellipsize, ellipsize = _e === void 0 ? false : _e, _f = props.fill, fill = _f === void 0 ? false : _f, _g = props.heading, heading = _g === void 0 ? text_1.Text : _g, icon = props.icon, _h = props.loading, loading = _h === void 0 ? false : _h, subtitle = props.subtitle, tags = props.tags, title = props.title, titleURL = props.titleURL; var titleElement = React.useMemo(function () { var _a; var maybeTitleWithURL = titleURL != null ? (React.createElement("a", { target: "_blank", href: titleURL, rel: "noreferrer" }, title)) : (title); return React.createElement(heading, { className: (0, classnames_1.default)(common_1.Classes.ENTITY_TITLE_TITLE, (_a = {}, _a[common_1.Classes.SKELETON] = loading, _a[common_1.Classes.TEXT_OVERFLOW_ELLIPSIS] = heading !== text_1.Text && ellipsize, _a)), ellipsize: heading === text_1.Text ? ellipsize : undefined, }, maybeTitleWithURL); }, [titleURL, title, heading, loading, ellipsize]); var maybeSubtitle = React.useMemo(function () { var _a; if (subtitle == null) { return null; } return (React.createElement(text_1.Text, { className: (0, classnames_1.default)(common_1.Classes.TEXT_MUTED, common_1.Classes.ENTITY_TITLE_SUBTITLE, (_a = {}, _a[common_1.Classes.SKELETON] = loading, _a)), ellipsize: ellipsize }, subtitle)); }, [ellipsize, loading, subtitle]); return (React.createElement("div", { className: (0, classnames_1.default)(className, common_1.Classes.ENTITY_TITLE, getClassNameFromHeading(heading), (_a = {}, _a[common_1.Classes.ENTITY_TITLE_ELLIPSIZE] = ellipsize, _a[common_1.Classes.FILL] = fill, _a)), ref: ref }, icon != null && (React.createElement("div", { className: (0, classnames_1.default)(common_1.Classes.ENTITY_TITLE_ICON_CONTAINER, (_b = {}, _b[common_1.Classes.ENTITY_TITLE_HAS_SUBTITLE] = maybeSubtitle != null, _b)) }, React.createElement(icon_1.Icon, { "aria-hidden": true, className: (0, classnames_1.default)(common_1.Classes.TEXT_MUTED, (_c = {}, _c[common_1.Classes.SKELETON] = loading, _c)), icon: loading ? icons_1.IconNames.SQUARE : icon, tabIndex: -1 }))), React.createElement("div", { className: common_1.Classes.ENTITY_TITLE_TEXT }, React.createElement("div", { className: (0, classnames_1.default)(common_1.Classes.ENTITY_TITLE_TITLE_AND_TAGS, (_d = {}, _d[common_1.Classes.SKELETON] = loading, _d)) }, titleElement, tags != null && React.createElement("div", { className: common_1.Classes.ENTITY_TITLE_TAGS_CONTAINER }, tags)), maybeSubtitle))); }); exports.EntityTitle.displayName = "".concat(common_1.DISPLAYNAME_PREFIX, ".EntityTitle"); /** * Construct header class name from H{*}. Returns `undefined` if `heading` is not a Blueprint heading. */ function getClassNameFromHeading(heading) { var headerIndex = [html_1.H1, html_1.H2, html_1.H3, html_1.H4, html_1.H5, html_1.H6].findIndex(function (header) { return header === heading; }); if (headerIndex < 0) { return undefined; } return [common_1.Classes.getClassNamespace(), "entity-title-heading", "h".concat(headerIndex + 1)].join("-"); } //# sourceMappingURL=entityTitle.js.map