Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Add `icon` type site setting (#38779)

Martin Brennan802fa4c3562e
diff --git a/app/assets/stylesheets/admin/settings.scss b/app/assets/stylesheets/admin/settings.scss
index 8d4dbaccd58..7b43301911a 100644
--- a/app/assets/stylesheets/admin/settings.scss
+++ b/app/assets/stylesheets/admin/settings.scss
@@ -3,6 +3,12 @@
.setting {
padding-bottom: 20px;
+ &.icon {
+ .setting-value .multi-select .formatted-selection {
+ display: none;
+ }
+ }
+
.setting-label {
float: left;
width: 17.6576%;
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 7d0f41ffc74..7da28c34cdb 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -70,6 +70,7 @@
# type: emoji_list - A list of emoji names (e.g. joy, cold_hands)
# type: tag_group_list - A list of tag group names.
# type: file_size_restriction - A file size restriction in bytes.
+# type: icon - A single fontawesome icon name from the Discourse icon set (e.g. heart, star)
#
required:
title:
diff --git a/frontend/discourse/admin/components/site-setting.gjs b/frontend/discourse/admin/components/site-setting.gjs
index 7e87e458aa7..d2059893922 100644
--- a/frontend/discourse/admin/components/site-setting.gjs
+++ b/frontend/discourse/admin/components/site-setting.gjs
@@ -56,6 +56,7 @@ const CUSTOM_TYPES = [
"locale_list",
"locale_enum",
"topic",
+ "icon",
];
export default class SiteSettingComponent extends Component {
diff --git a/frontend/discourse/admin/components/site-settings/icon.gjs b/frontend/discourse/admin/components/site-settings/icon.gjs
new file mode 100644
index 00000000000..561de0f9870
--- /dev/null
+++ b/frontend/discourse/admin/components/site-settings/icon.gjs
@@ -0,0 +1,26 @@
+import Component from "@glimmer/component";
+import { hash } from "@ember/helper";
+import { action } from "@ember/object";
+import IconPicker from "discourse/select-kit/components/icon-picker";
+
+export default class Icon extends Component {
+ @action
+ onChangeIcon(value) {
+ this.args.changeValueCallback(value);
+ }
+
+ <template>
+ <IconPicker
+ @value={{readonly @value}}
+ @onlyAvailable={{true}}
+ @options={{hash
+ maximum=1
+ disabled=@disabled
+ caretDownIcon="angle-down"
+ caretUpIcon="angle-up"
+ icons=@value
+ }}
+ @onChange={{this.onChangeIcon}}
+ />
+ </template>
+}
diff --git a/lib/site_settings/type_supervisor.rb b/lib/site_settings/type_supervisor.rb
index 9e6475ba125..f36c66386ab 100644
--- a/lib/site_settings/type_supervisor.rb
+++ b/lib/site_settings/type_supervisor.rb
@@ -69,6 +69,7 @@ class SiteSettings::TypeSupervisor
locale_enum: 29,
topic: 30,
datetime: 31,
+ icon: 32,
)
end
@@ -180,7 +181,7 @@ class SiteSettings::TypeSupervisor
nil
when self.class.types[:enum]
@defaults_provider[name].is_a?(Integer) ? value.to_i : value.to_s
- when self.class.types[:string], self.class.types[:datetime]
+ when self.class.types[:string], self.class.types[:datetime], self.class.types[:icon]
value.to_s
else
return value if self.class.types[type]
diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-reaction-button.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-reaction-button.gjs
index d423440fdee..b20414662c6 100644
--- a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-reaction-button.gjs
+++ b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-reaction-button.gjs
@@ -5,6 +5,7 @@ import { action } from "@ember/object";
import { service } from "@ember/service";
import { isBlank } from "@ember/utils";
import DButton from "discourse/components/d-button";
+import { isExistingIconId } from "discourse/lib/icon-library";
import { emojiUrlFor } from "discourse/lib/text";
import { i18n } from "discourse-i18n";
@@ -65,6 +66,7 @@ export default class ReactionsReactionButton extends Component {
if (icon === "heart") {
return "d-liked";
}
+
return icon;
}
@@ -75,7 +77,12 @@ export default class ReactionsReactionButton extends Component {
return "d-unliked";
}
- return `far-${icon}`;
+ // Not all icons have a far- version, so we need to check if it exists.
+ if (isExistingIconId(`far-${icon}`)) {
+ return `far-${icon}`;
+ }
+
+ return icon;
}
get title() {
diff --git a/plugins/discourse-reactions/config/settings.yml b/plugins/discourse-reactions/config/settings.yml
index baabe9e7078..9f4ad957e8d 100644
--- a/plugins/discourse-reactions/config/settings.yml
+++ b/plugins/discourse-reactions/config/settings.yml
@@ -4,6 +4,7 @@ discourse_reactions:
client: true
discourse_reactions_like_icon:
client: true
+ type: icon
default: "heart"
discourse_reactions_reaction_for_like:
client: true