mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:30:26 -06:00
DEV: Allow plugins to add extra icons to category-link (#9743)
This commit is contained in:
parent
6230f5c554
commit
9bce91f59f
@ -18,6 +18,12 @@ function categoryStripe(color, classes) {
|
||||
return "<span class='" + classes + "' " + style + "></span>";
|
||||
}
|
||||
|
||||
let _extraIconRenderers = [];
|
||||
|
||||
export function addExtraIconRenderer(renderer) {
|
||||
_extraIconRenderers.push(renderer);
|
||||
}
|
||||
|
||||
/**
|
||||
Generates category badge HTML
|
||||
|
||||
@ -149,12 +155,15 @@ function defaultCategoryLinkRenderer(category, opts) {
|
||||
}
|
||||
|
||||
if (restricted) {
|
||||
html += `${iconHTML(
|
||||
"lock"
|
||||
)}<span class="category-name" ${categoryDir}>${categoryName}</span>`;
|
||||
} else {
|
||||
html += `<span class="category-name" ${categoryDir}>${categoryName}</span>`;
|
||||
html += iconHTML("lock");
|
||||
}
|
||||
_extraIconRenderers.forEach(renderer => {
|
||||
const iconName = renderer(category);
|
||||
if (iconName) {
|
||||
html += iconHTML(iconName);
|
||||
}
|
||||
});
|
||||
html += `<span class="category-name" ${categoryDir}>${categoryName}</span>`;
|
||||
html += "</span>";
|
||||
|
||||
if (opts.topicCount && categoryStyle !== "box") {
|
||||
|
@ -48,6 +48,7 @@ import {
|
||||
addComposerUploadMarkdownResolver
|
||||
} from "discourse/components/composer-editor";
|
||||
import { addCategorySortCriteria } from "discourse/components/edit-category-settings";
|
||||
import { addExtraIconRenderer } from "discourse/helpers/category-link";
|
||||
import { queryRegistry } from "discourse/widgets/widget";
|
||||
import Composer from "discourse/models/composer";
|
||||
import { on } from "@ember/object/evented";
|
||||
@ -1065,6 +1066,22 @@ class PluginApi {
|
||||
decorateTopicTitle(callback) {
|
||||
addTopicTitleDecorator(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows adding icons to the category-link html
|
||||
*
|
||||
* ```
|
||||
* api.addCategoryLinkIcon((category) => {
|
||||
* if (category.someProperty) {
|
||||
return "eye"
|
||||
}
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
**/
|
||||
addCategoryLinkIcon(renderer) {
|
||||
addExtraIconRenderer(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
let _pluginv01;
|
||||
|
Loading…
Reference in New Issue
Block a user