@blueprintjs/core
Version:
Core styles & components
78 lines • 4.26 kB
JavaScript
/*
* 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.
*/
import classNames from "classnames";
import * as React from "react";
import { IconNames } from "@blueprintjs/icons";
import { Classes, DISPLAYNAME_PREFIX } from "../../common";
import { H1, H2, H3, H4, H5, H6 } from "../html/html";
import { Icon } from "../icon/icon";
import { Text } from "../text/text";
/**
* EntityTitle component.
*
* @see https://blueprintjs.com/docs/#core/components/entity-title
*/
export var 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 : _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: classNames(Classes.ENTITY_TITLE_TITLE, (_a = {},
_a[Classes.SKELETON] = loading,
_a[Classes.TEXT_OVERFLOW_ELLIPSIS] = heading !== Text && ellipsize,
_a)),
ellipsize: heading === 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, { className: classNames(Classes.TEXT_MUTED, Classes.ENTITY_TITLE_SUBTITLE, (_a = {},
_a[Classes.SKELETON] = loading,
_a)), ellipsize: ellipsize }, subtitle));
}, [ellipsize, loading, subtitle]);
return (React.createElement("div", { className: classNames(className, Classes.ENTITY_TITLE, getClassNameFromHeading(heading), (_a = {},
_a[Classes.ENTITY_TITLE_ELLIPSIZE] = ellipsize,
_a[Classes.FILL] = fill,
_a)), ref: ref },
icon != null && (React.createElement("div", { className: classNames(Classes.ENTITY_TITLE_ICON_CONTAINER, (_b = {},
_b[Classes.ENTITY_TITLE_HAS_SUBTITLE] = maybeSubtitle != null,
_b)) },
React.createElement(Icon, { "aria-hidden": true, className: classNames(Classes.TEXT_MUTED, (_c = {}, _c[Classes.SKELETON] = loading, _c)), icon: loading ? IconNames.SQUARE : icon, tabIndex: -1 }))),
React.createElement("div", { className: Classes.ENTITY_TITLE_TEXT },
React.createElement("div", { className: classNames(Classes.ENTITY_TITLE_TITLE_AND_TAGS, (_d = {},
_d[Classes.SKELETON] = loading,
_d)) },
titleElement,
tags != null && React.createElement("div", { className: Classes.ENTITY_TITLE_TAGS_CONTAINER }, tags)),
maybeSubtitle)));
});
EntityTitle.displayName = "".concat(DISPLAYNAME_PREFIX, ".EntityTitle");
/**
* Construct header class name from H{*}. Returns `undefined` if `heading` is not a Blueprint heading.
*/
function getClassNameFromHeading(heading) {
var headerIndex = [H1, H2, H3, H4, H5, H6].findIndex(function (header) { return header === heading; });
if (headerIndex < 0) {
return undefined;
}
return [Classes.getClassNamespace(), "entity-title-heading", "h".concat(headerIndex + 1)].join("-");
}
//# sourceMappingURL=entityTitle.js.map