@redocly/theme
Version:
Shared UI components lib
165 lines (163 loc) • 7.36 kB
JavaScript
;
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 () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CatalogEntityHistoryButton = CatalogEntityHistoryButton;
const react_1 = __importStar(require("react"));
const styled_components_1 = __importDefault(require("styled-components"));
const RecentlyViewedIcon_1 = require("../../../../icons/RecentlyViewedIcon/RecentlyViewedIcon");
const CheckmarkOutlineIcon_1 = require("../../../../icons/CheckmarkOutlineIcon/CheckmarkOutlineIcon");
const hooks_1 = require("../../../../core/hooks");
const constants_1 = require("../../../../core/constants");
const Tooltip_1 = require("../../../../components/Tooltip/Tooltip");
const hooks_2 = require("../../../../core/hooks");
function CatalogEntityHistoryButton({ version, className, }) {
const [label, setLabel] = (0, react_1.useState)(version === constants_1.VERSION_NOT_SPECIFIED ? null : version);
const { useTranslate } = (0, hooks_1.useThemeHooks)();
const { translate } = useTranslate();
const [labelRef, isLabelTruncated] = (0, hooks_2.useIsTruncated)(label);
const handleClose = (0, react_1.useCallback)((e) => {
setLabel(e.detail.version === constants_1.VERSION_NOT_SPECIFIED
? e.detail.revision || 'r.1'
: `${e.detail.version || version}, ${e.detail.revision || 'r.1'}`);
}, [version]);
(0, react_1.useEffect)(() => {
window.addEventListener('portal:sidebar:close-version-history', (e) => handleClose(e));
return () => {
window.removeEventListener('portal:sidebar:close-version-history', (e) => handleClose(e));
};
}, [handleClose]);
const handleClick = () => {
window.dispatchEvent(new CustomEvent('portal:sidebar:open-version-history'));
};
return (react_1.default.createElement(CatalogHistoryButtonWrapper, { className: className, "data-component-name": "Catalog/CatalogHistoryButton" },
react_1.default.createElement(Separator, null),
react_1.default.createElement(HistoryItem, { onClick: handleClick },
react_1.default.createElement(HistoryIcon, null),
react_1.default.createElement(HistoryContent, null,
react_1.default.createElement(HistoryText, null, translate('catalog.history.button.label', 'Version history')),
label && (react_1.default.createElement(Tooltip_1.Tooltip, { tip: label, placement: "bottom", arrowPosition: "left", disabled: !isLabelTruncated },
react_1.default.createElement(VersionPillWrapper, null,
react_1.default.createElement(VersionPill, null,
react_1.default.createElement(CheckmarkIcon, null),
react_1.default.createElement("span", { ref: labelRef }, label)))))))));
}
const CatalogHistoryButtonWrapper = styled_components_1.default.div `
width: var(--catalog-history-button-width);
`;
const Separator = styled_components_1.default.div `
width: 100%;
height: 1px;
background-color: var(--catalog-history-separator-border-color);
margin-bottom: var(--catalog-history-separator-margin-bottom);
flex-shrink: 0;
`;
const HistoryItem = styled_components_1.default.button `
all: unset;
display: flex;
align-items: center;
justify-content: space-between;
gap: var(--catalog-history-item-gap);
padding: var(--catalog-history-item-padding);
margin-bottom: var(--catalog-history-item-margin-bottom);
width: var(--catalog-history-button-item-width);
border-radius: var(--catalog-history-item-border-radius);
cursor: pointer;
transition: background-color 0.2s ease;
&:hover {
background-color: var(--catalog-history-item-bg-color-hover);
}
`;
const HistoryContent = styled_components_1.default.div `
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
flex: 1;
gap: var(--catalog-history-item-gap);
min-width: 0;
max-width: var(--catalog-history-content-max-width);
`;
const HistoryText = styled_components_1.default.span `
flex: 0 0 auto;
font-family: var(--catalog-history-text-font-family);
font-size: var(--catalog-history-text-font-size);
font-weight: var(--catalog-history-text-font-weight);
line-height: var(--catalog-history-text-line-height);
color: var(--catalog-history-text-color);
white-space: nowrap;
`;
const VersionPillWrapper = styled_components_1.default.div `
flex: 0 1 auto;
min-width: 0;
max-width: var(--catalog-history-content-max-width);
`;
const HistoryIcon = (0, styled_components_1.default)(RecentlyViewedIcon_1.RecentlyViewedIcon) `
width: var(--catalog-history-icon-size);
height: var(--catalog-history-icon-size);
flex-shrink: 0;
`;
const VersionPill = styled_components_1.default.div `
display: flex;
align-items: center;
gap: var(--catalog-history-pill-gap);
padding: var(--catalog-history-pill-padding-vertical) var(--catalog-history-pill-padding-horizontal);
border: 1px solid var(--catalog-history-pill-border-color);
border-radius: var(--catalog-history-pill-border-radius);
background-color: transparent;
min-width: 0;
max-width: 100%;
span {
font-family: var(--catalog-history-pill-font-family);
font-size: var(--catalog-history-pill-font-size);
line-height: var(--catalog-history-pill-line-height);
color: var(--catalog-history-pill-text-color);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
min-width: 0;
}
`;
const CheckmarkIcon = (0, styled_components_1.default)(CheckmarkOutlineIcon_1.CheckmarkOutlineIcon) `
width: var(--catalog-history-pill-icon-size);
height: var(--catalog-history-pill-icon-size);
min-width: var(--catalog-history-pill-icon-size);
min-height: var(--catalog-history-pill-icon-size);
flex-shrink: 0;
color: var(--catalog-history-pill-icon-color);
`;
//# sourceMappingURL=CatalogEntityHistoryButton.js.map