@redocly/theme
Version:
Shared UI components lib
34 lines • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useThemeHooks = void 0;
const react_1 = require("react");
const contexts_1 = require("../../core/contexts");
const fallbacks = {
useTranslate: () => ({
translate: (value, options) => (typeof options === 'string' ? options : options === null || options === void 0 ? void 0 : options.defaultValue) || value || '',
}),
useSubmitFeedback: () => ({ submitFeedback: () => { } }),
useTelemetry: () => ({ telemetry: () => { } }),
useOtelTelemetry: () => ({ send: () => { } }),
useBreadcrumbs: () => [],
useCodeHighlight: () => ({ highlight: (rawContent) => rawContent }),
useUserMenu: () => ({}),
};
const useThemeHooks = () => {
const context = (0, react_1.useContext)(contexts_1.ThemeDataContext);
return new Proxy({}, {
get(_, prop) {
if (context && prop in context.hooks) {
return context.hooks[prop];
}
else if (prop in fallbacks) {
return fallbacks[prop];
}
else {
throw new Error(`Unknown hook ${prop.toString()}`);
}
},
});
};
exports.useThemeHooks = useThemeHooks;
//# sourceMappingURL=use-theme-hooks.js.map