Skip to content

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

FEATURE: redesigned admin color palette index layout (#33628)

Kris8fea4eaaa5aa
diff --git a/app/assets/javascripts/admin/addon/components/color-palette-list-item.gjs b/app/assets/javascripts/admin/addon/components/color-palette-list-item.gjs
new file mode 100644
index 00000000000..9af3507551b
--- /dev/null
+++ b/app/assets/javascripts/admin/addon/components/color-palette-list-item.gjs
@@ -0,0 +1,242 @@
+import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
+import { array, fn } from "@ember/helper";
+import { action } from "@ember/object";
+import { LinkTo } from "@ember/routing";
+import { htmlSafe } from "@ember/template";
+import { not } from "truth-helpers";
+import DButton from "discourse/components/d-button";
+import DropdownMenu from "discourse/components/dropdown-menu";
+import icon from "discourse/helpers/d-icon";
+import { i18n } from "discourse-i18n";
+import SvgSingleColorPalettePlaceholder from "admin/components/svg/single-color-palette-placeholder";
+import { getColorSchemeStyles } from "admin/lib/color-transformations";
+import DButtonTooltip from "float-kit/components/d-button-tooltip";
+import DMenu from "float-kit/components/d-menu";
+import DTooltip from "float-kit/components/d-tooltip";
+
+export default class ColorPaletteListItem extends Component {
+ @tracked isLoading = false;
+
+ get isBuiltInDefault() {
+ return this.args.scheme?.is_builtin_default || false;
+ }
+
+ get setAsDefaultLabel() {
+ const themeName = this.args.defaultTheme?.name || "Default";
+
+ return i18n("admin.customize.colors.set_default", {
+ theme: themeName,
+ });
+ }
+
+ get canEdit() {
+ return !this.isBuiltInDefault && this.args.scheme?.id;
+ }
+
+ get canDelete() {
+ return !this.isBuiltInDefault && !this.args.scheme?.theme_id;
+ }
+
+ get showSetAsDefault() {
+ if (this.isBuiltInDefault) {
+ return this.args.defaultTheme?.color_scheme_id;
+ }
+ return true;
+ }
+
+ get isActive() {
+ if (this.isBuiltInDefault) {
+ return this.args.defaultTheme && !this.args.defaultTheme.color_scheme_id;
+ }
+ return (
+ this.args.defaultTheme &&
+ this.args.isDefaultThemeColorScheme(this.args.scheme)
+ );
+ }
+
+ get styles() {
+ if (this.isBuiltInDefault) {
+ return htmlSafe(
+ "--primary-low--preview: #e9e9e9; --tertiary-low--preview: #d1f0ff;"
+ );
+ }
+
+ // generate primary-low and tertiary-low
+ const existingStyles = getColorSchemeStyles(this.args.scheme);
+
+ // create variables from scheme.colors
+ const colorVariables =
+ this.args.scheme?.colors
+ ?.map((color) => {
+ let hex = color.hex || color.default_hex;
+
+ if (hex && !hex.startsWith("#")) {
+ hex = `#${hex}`;
+ }
+ return `--${color.name}--preview: ${hex}`;
+ })
+ .join("; ") || "";
+
+ const allStyles = colorVariables
+ ? `${existingStyles} ${colorVariables};`
+ : existingStyles;
+
+ return htmlSafe(allStyles);
+ }
+
+ @action
+ async handleAsyncAction(asyncFn, ...args) {
+ this.dMenu.close();
+ this.isLoading = true;
+ try {
+ await asyncFn(...args);
+ } finally {
+ this.isLoading = false;
+ }
+ }
+
+ @action
+ onRegisterApi(api) {
+ this.dMenu = api;
+ }
+
+ <template>
+ <li
+ style={{this.styles}}
+ class="admin-config-area-card color-palette"
+ data-palette-id={{@scheme.id}}
+ >
+ <div class="color-palette__container">
+ <div class="color-palette__preview">
+ <SvgSingleColorPalettePlaceholder />
+ </div>
+
+ <div class="color-palette__details">
+ <h3>{{@scheme.description}}</h3>
+ <div class="color-palette__theme-link">
+ {{#if @scheme.theme_id}}
+ <LinkTo
+ @route="adminCustomizeThemes.show"
+ @models={{array "themes" @scheme.theme_id}}
+ >
+ {{icon "link"}}
+ {{@scheme.theme_name}}
+ </LinkTo>
+ {{/if}}
+ </div>
+
+ <div class="color-palette__badges">
+ {{#if @scheme.user_selectable}}
+ <span
+ title={{i18n "admin.customize.theme.user_selectable"}}
+ class="theme-card__badge --selectable"
+ >
+ {{icon "user-check"}}
+ {{i18n "admin.customize.theme.user_selectable_badge_label"}}
+ </span>
+ {{/if}}
+ </div>
+
+ {{#if this.isActive}}
+ <span
+ title={{i18n "admin.customize.colors.active_badge.title"}}
+ class="theme-card__badge --active"
+ >
+ {{i18n "admin.customize.colors.active_badge.text"}}
+ </span>
+ {{/if}}
+ </div>
+
+ <div class="color-palette__controls">
+ <DButtonTooltip>
+ <:button>
+ <DButton
+ @route="adminCustomize.colors-show"
+ @routeModels={{array @scheme.id}}
+ @label="admin.customize.colors.edit"
+ class="btn-secondary"
+ @disabled={{not this.canEdit}}
+ />
+ </:button>
+ <:tooltip>
+ {{#unless this.canEdit}}
+ <DTooltip
+ @icon="circle-info"
+ @content={{i18n "admin.customize.colors.system_palette"}}
+ />
+ {{/unless}}
+ </:tooltip>
+ </DButtonTooltip>
+
+ {{#if this.showSetAsDefault}}
+ <DMenu
+ @triggerClass="btn-flat"
+ @modalForMobile={{true}}
+ @icon="ellipsis"
+ @triggers={{array "click"}}
+ @onRegisterApi={{this.onRegisterApi}}
+ @isLoading={{this.isLoading}}
+ >
+ <:content>
+ <DropdownMenu as |dropdown|>
+ {{#unless this.isBuiltInDefault}}
+ <dropdown.item>
+ <DButton
+ @action={{fn
+ this.handleAsyncAction
+ @toggleUserSelectable
+ @scheme
+ }}
+ @icon={{if
+ @scheme.user_selectable
+ "user-xmark"
+ "user-check"
+ }}
+ @label={{if
+ @scheme.user_selectable
+ "admin.customize.theme.user_selectable_unavailable_button_label"
+ "admin.customize.theme.user_selectable_button_label"
+ }}
+ class="btn-transparent"
+ />
+ </dropdown.item>
+ {{/unless}}
+
+ <dropdown.item>
+ <DButton
+ @action={{fn
+ this.handleAsyncAction
+ @setAsDefaultThemePalette
+ @scheme
+ }}
+ @icon="star"
+ @translatedLabel={{this.setAsDefaultLabel}}
+ class="btn-transparent btn-palette-default"
+ disabled={{this.isActive}}
+ />
+ </dropdown.item>
+
+ {{#if this.canDelete}}
+ <dropdown.item>
+ <DButton
+ @action={{fn
+ this.handleAsyncAction
+ @deleteColorScheme
+ @scheme
+ }}
+ @icon="trash-can"
+ @label="admin.customize.delete"
+ class="btn-transparent btn-danger"
+ />
+ </dropdown.item>
+ {{/if}}
+ </DropdownMenu>
+ </:content>
+ </DMenu>
+ {{/if}}
+ </div>
+ </div>
+ </li>
+ </template>
+}
diff --git a/app/assets/javascripts/admin/addon/components/svg/single-color-palette-placeholder.gjs b/app/assets/javascripts/admin/addon/components/svg/single-color-palette-placeholder.gjs
new file mode 100644
index 00000000000..375da7ee7de
--- /dev/null
+++ b/app/assets/javascripts/admin/addon/components/svg/single-color-palette-placeholder.gjs
@@ -0,0 +1,94 @@
+const SvgSingleColorPalettePlaceholder = <template>
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 558 171">
+ <rect
+ width="120"
+ height="25.616"
+ x="436.298"
+ y="95.819"
+ fill="var(--primary-low--preview, #e9e9e9)"
+ rx="4"
+ />
+ <rect
+ width="120"
+ height="24.64"
+ x="436.298"
+ y="144.442"
+ fill="var(--tertiary--preview, #08c)"
+ rx="4"
+ />
+ <rect
+ width="555.265"
+ height="71.394"
+ x=".22"
+ y=".341"
+ fill="var(--tertiary-low--preview, #d1f0ff)"
+ rx="4"
+ />
+ <rect
+ width="30"
+ height="24.64"
+ x="23.451"
+ y="145.418"
+ fill="var(--danger--preview, #c80001)"
+ rx="4"
+ />
+ <rect
+ width="30"
+ height="24.64"
+ x="88.578"
+ y="145.418"
+ fill="var(--success--preview, #090)"
+ rx="4"
+ />
+ <rect
+ width="30"
+ height="24.64"
+ x="153.704"
+ y="145.418"
+ fill="var(--love--preview, #fa6c8d)"
+ rx="4"
+ />
+ <rect
+ width="30"
+ height="24.64"
+ x="218.831"
+ y="145.418"
+ fill="var(--highlight--preview, #ffff4d)"
+ rx="4"
+ />
+ <rect
+ width="200.35"
+ height="4.526"
+ x="23.451"
+ y="43.772"
+ fill="var(--primary--preview, #222)"
+ rx="2.263"
+ />
+ <rect
+ width="333.847"
+ height="4.526"
+ x="23.451"
+ y="66.295"
+ fill="var(--primary--preview, #222)"
+ rx="2.263"
+ />
+ <rect
+ width="267.897"
+ height="4.526"
+ x="23.451"
+ y="90.819"
+ fill="var(--primary--preview, #222)"
+ rx="2.263"
+ />
+ <rect
+ width="299.961"
+ height="4.526"
+ x="23.451"
+ y="116.342"
+ fill="var(--primary--preview, #222)"
+ rx="2.263"
+ />
+ </svg>
+</template>;
+
+export default SvgSingleColorPalettePlaceholder;
diff --git a/app/assets/javascripts/admin/addon/controllers/admin-customize-colors-show.js b/app/assets/javascripts/admin/addon/controllers/admin-customize-colors-show.js
index 60c941be1b9..51ddb99f75e 100644
--- a/app/assets/javascripts/admin/addon/controllers/admin-customize-colors-show.js
+++ b/app/assets/javascripts/admin/addon/controllers/admin-customize-colors-show.js
@@ -60,7 +60,7 @@ export default class AdminCustomizeColorsShowController extends Controller {
);
newColorScheme.save().then(() => {
this.allColors.pushObject(newColorScheme);
- this.router.replaceWith("adminCustomize.colors.show", newColorScheme);
+ this.router.replaceWith("adminCustomize.colors-show", newColorScheme);
});
}
diff --git a/app/assets/javascripts/admin/addon/controllers/admin-customize-colors.js b/app/assets/javascripts/admin/addon/controllers/admin-customize-colors.js
index 1fa992114f5..fdb0126cecb 100644
--- a/app/assets/javascripts/admin/addon/controllers/admin-customize-colors.js
+++ b/app/assets/javascripts/admin/addon/controllers/admin-customize-colors.js
@@ -1,36 +1,166 @@
+import { tracked } from "@glimmer/tracking";
import Controller from "@ember/controller";
-import EmberObject, { action } from "@ember/object";
+import { action } from "@ember/object";
import { service } from "@ember/service";
-import discourseComputed from "discourse/lib/decorators";
+import { currentThemeId } from "discourse/lib/theme-selector";
import { i18n } from "discourse-i18n";
import ColorSchemeSelectBaseModal from "admin/components/modal/color-scheme-select-base";
+import { setDefaultColorScheme } from "admin/lib/color-scheme-manager";
+
+const COUNT_TO_FILTER = 8;
export default class AdminCustomizeColorsController extends Controller {
@service router;
@service modal;
+ @service store;
+ @service dialog;
+ @service toasts;
+ @service session;
+ @service site;
+
+ @tracked defaultTheme = null;
+ @tracked filterValue = "";
+ @tracked typeFilter = "all";
+
+ isDefaultThemeColorScheme = (scheme) => {
+ return this.defaultTheme?.color_scheme_id === scheme.id;
+ };
+
+ @tracked _initialSortedSchemes = [];
+ _initialUserColorSchemeId = undefined;
+ _initialDefaultThemeColorSchemeId = null;
+ _sortedOnce = false;
- @discourseComputed("[email protected]")
- baseColorScheme() {
- return this.model.findBy("is_base", true);
+ get canPreviewColorScheme() {
+ return currentThemeId() === this.defaultTheme?.id;
}
- @discourseComputed("[email protected]")
- baseColorSchemes() {
- return this.model.filterBy("is_base", true);
+ get allBaseColorSchemes() {
+ return this.model?.filterBy("is_base", true) || [];
}
- @discourseComputed("baseColorScheme")
- baseColors(baseColorScheme) {
- const baseColorsHash = EmberObject.create({});
- baseColorScheme.get("colors").forEach((color) => {
- baseColorsHash.set(color.get("name"), color);
+ _captureInitialState() {
+ this._initialUserColorSchemeId = this.session.userColorSchemeId;
+ this._initialDefaultThemeColorSchemeId = this.defaultTheme?.color_scheme_id;
+ }
+
+ get changedThemePreferences() {
+ // can't check against null, because the default scheme ID is null
+ if (this._initialUserColorSchemeId === undefined && this.defaultTheme) {
+ this._captureInitialState();
+ }
+
+ const changedColors =
+ this._initialUserColorSchemeId !== this._initialDefaultThemeColorSchemeId;
+ const changedTheme = this.defaultTheme?.id !== currentThemeId(this.site);
+
+ return changedColors || changedTheme;
+ }
+
+ get filteredColorSchemes() {
+ // only sort initially, this avoids position jumps when state changes on interaction
+ if (!this._sortedOnce && this.model?.length > 0) {
+ this._doInitialSort();
+ }
+
+ let schemes = [...this._initialSortedSchemes];
+
+ switch (this.typeFilter) {
+ case "user_selectable":
+ schemes = schemes.filter((scheme) => scheme.user_selectable);
+ break;
+ case "from_theme":
+ schemes = schemes.filter((scheme) => scheme.theme_id);
+ break;
+ }
+
+ if (this.filterValue) {
+ const term = this.filterValue.toLowerCase();
+ schemes = schemes.filter((scheme) => {
+ const nameMatches = scheme.name?.toLowerCase().includes(term);
+ const themeMatches = scheme.theme_name?.toLowerCase().includes(term);
+ return nameMatches || themeMatches;
+ });
+ }
+
+ return schemes;
+ }
+
+ _doInitialSort() {
+ let schemes = this.model.filter((scheme) => !scheme.is_base);
+
+ // built-in "Light (default)"
+ const lightBaseScheme = this.allBaseColorSchemes.find(
+ (scheme) => scheme.base_scheme_id === "Light" || scheme.name === "Light"
+ );
+ if (lightBaseScheme) {
+ const builtInDefault = {
+ ...lightBaseScheme,
+ id: 0,
+ name: i18n("admin.customize.theme.default_light_scheme"),
+ description: i18n("admin.customize.theme.default_light_scheme"),
+ is_builtin_default: true,
+ };
+ schemes.unshift(builtInDefault);
+ }
+
+ schemes.sort((a, b) => {
+ const defaultId = this.defaultTheme?.color_scheme_id;
+
+ const isDefaultA = a.is_builtin_default
+ ? defaultId === null
+ : a.id === defaultId;
+
+ const isDefaultB = b.is_builtin_default
+ ? defaultId === null
+ : b.id === defaultId;
+
+ if (isDefaultA !== isDefaultB) {
+ return isDefaultA ? -1 : 1;
+ }
+
+ if (a.user_selectable !== b.user_selectable) {
+ return a.user_selectable ? -1 : 1;
+ }
+
+ return (a.name || "").localeCompare(b.name || "");
});
- return baseColorsHash;
+
+ this._initialSortedSchemes = schemes;
+ this._sortedOnce = true;
+ }
+
+ get showFilters() {
+ return (
+ this.model.filter((scheme) => !scheme.is_base).length > COUNT_TO_FILTER
+ );
+ }
+
+ get typeFilterOptions() {
+ return [
+ {
+ value: "all",
+ label: i18n("admin.customize.colors.filters.all"),
+ },
+ {
+ value: "user_selectable",
+ label: i18n("admin.customize.colors.filters.user_selectable"),
+ },
+ {
+ value: "from_theme",
+ label: i18n("admin.customize.colors.filters.from_theme"),
+ },
+ ];
+ }
+
+ _resetSortedSchemes() {
+ this._sortedOnce = false;
+ this._initialSortedSchemes = [];
}
@action
newColorSchemeWithBase(baseKey) {
- const base = this.baseColorSchemes.findBy("base_scheme_id", baseKey);
+ const base = this.allBaseColorSchemes.findBy("base_scheme_id", baseKey);
const newColorScheme = base.copy();
newColorScheme.setProperties({
name: i18n("admin.customize.colors.new_name"),
@@ -39,7 +169,10 @@ export default class AdminCustomizeColorsController extends Controller {
newColorScheme.save().then(() => {
this.model.pushObject(newColorScheme);
newColorScheme.set("savingStatus", null);
- this.router.replaceWith("adminCustomize.colors.show", newColorScheme);
+
+ this._resetSortedSchemes();
+
+ this.router.replaceWith("adminCustomize.colors-show", newColorScheme);
});
}
@@ -47,9 +180,87 @@ export default class AdminCustomizeColorsController extends Controller {
newColorScheme() {
this.modal.show(ColorSchemeSelectBaseModal, {
model: {
- baseColorSchemes: this.baseColorSchemes,
+ baseColorSchemes: this.allBaseColorSchemes,
newColorSchemeWithBase: this.newColorSchemeWithBase,
},
});
}
+
+ @action
+ toggleUserSelectable(scheme) {
+ scheme.set("user_selectable", !scheme.get("user_selectable"));
+ return scheme.updateUserSelectable(scheme.get("user_selectable"));
+ }
+
+ @action
+ async setAsDefaultThemePalette(scheme) {
+ try {
+ if (this.canPreviewColorScheme) {
+ this.defaultTheme = await setDefaultColorScheme(scheme, this.store);
+ }
+
+ if (!this.canPreviewColorScheme) {
+ const schemeName = scheme.description || scheme.name;
+ const themeName = this.defaultTheme.name;
+ this.toasts.success({
+ data: {
+ message: i18n("admin.customize.colors.set_default_success", {
+ schemeName,
+ themeName,
+ }),
+ },
+ duration: 4000,
+ });
+ }
+ } catch (error) {
+ // eslint-disable-next-line no-console
+ console.error("Error setting default theme palette", error);
+ this.dialog.alert({
+ message: i18n("admin.customize.colors.default_error", {
+ defaultValue: "Error setting color palette as active",
+ }),
+ });
+ }
+ }
+
+ @action
+ deleteColorScheme(scheme) {
+ return new Promise((resolve, reject) => {
+ this.dialog.deleteConfirm({
+ title: i18n("admin.customize.colors.delete_confirm"),
+ didConfirm: () => {
+ return scheme
+ .destroy()
+ .then(() => {
+ this.model.removeObject(scheme);
+
+ this._resetSortedSchemes();
+
+ resolve();
+ })
+ .catch(reject);
+ },
+ didCancel: () => {
+ reject(new Error("Deletion cancelled"));
+ },
+ });
+ });
+ }
+
+ @action
+ onFilterChange(event) {
+ this.filterValue = event.target?.value || "";
+ }
+
+ @action
+ onTypeFilterChange(value) {
+ this.typeFilter = value;
+ }
+
+ @action
+ resetFilters() {
+ this.filterValue = "";
+ this.typeFilter = "all";
+ document.querySelector(".admin-filter__input")?.focus();
+ }
}
diff --git a/app/assets/javascripts/admin/addon/lib/color-scheme-manager.js b/app/assets/javascripts/admin/addon/lib/color-scheme-manager.js
new file mode 100644
index 00000000000..2575e7a7681
--- /dev/null
+++ b/app/assets/javascripts/admin/addon/lib/color-scheme-manager.js
@@ -0,0 +1,170 @@
+import { ajax } from "discourse/lib/ajax";
+
+/**
+ * determine if a scheme is the built-in default
+ * @param {Object} scheme
+ * @returns {boolean} true if built-in default scheme
+ */
+function isBuiltInDefault(scheme) {
+ return !scheme || scheme?.is_builtin_default;
+}
+
+/**
+ * get the scheme ID for API calls
+ * @param {Object} scheme
+ * @returns {number|null}
+ */
+function getSchemeId(scheme) {
+ return isBuiltInDefault(scheme) ? null : scheme?.id;
+}
+
+/**
+ * apply color scheme by updating stylesheet links
+ *
+ * @param {Object} scheme - color scheme to apply
+ * @param {Object} options
+ * @param {boolean} options.replace - replace existing tags? (default: false)
+ * @param {boolean} options.save - save changes to the server? (default: false)
+ * @returns {Promise}
+ */
+
+export async function applyColorScheme(scheme, options = {}) {
+ const { replace = false, save = false } = options;
+
+ try {
+ if (save && scheme && scheme.save) {
+ await scheme.save({ forceSave: true });
+ }
+
+ const id = getSchemeId(scheme);
+ const isBuiltIn = isBuiltInDefault(scheme);
+
+ let existingTags = [];
+ if (id) {
+ existingTags = document.querySelectorAll(`link[data-scheme-id="${id}"]`);
+ }
+
+ if (existingTags.length === 0 && !replace) {
+ return;
+ }
+
+ let darkTag;
+ let lightTag;
+
+ if (replace) {
+ const colorSchemeStylesheets = document.querySelectorAll(
+ "link[rel='stylesheet']"
+ );
+
+ for (const link of colorSchemeStylesheets) {
+ if (
+ link.hasAttribute("data-scheme-id") ||
+ link.classList.contains("dark-scheme") ||
+ link.classList.contains("light-scheme") ||
+ link.href.includes("color-scheme-stylesheet")
+ ) {
+ if (
+ link.href.includes("dark_scheme") ||
+ link.classList.contains("dark-scheme")
+ ) {
+ darkTag = darkTag || link;
+ } else {
+ lightTag = lightTag || link;
+ }
+ }
+ }
+ } else {
+ for (const tag of existingTags) {
+ if (tag.classList.contains("dark-scheme")) {
+ darkTag = tag;
+ } else {
+ lightTag = tag;
+ }
+ }
+ }
+
+ if (!id) {
+ return;
+ }
+
+ const apiUrl = `/color-scheme-stylesheet/${id}.json`;
+
+ const data = await ajax(apiUrl, {
+ data: {
+ include_dark_scheme: !!darkTag,
+ },
+ dataType: "json",
+ });
+
+ if (data?.new_href && lightTag) {
+ lightTag.href = data.new_href;
+
+ if (replace && id) {
+ lightTag.setAttribute("data-scheme-id", id);
+ } else if (replace && isBuiltIn) {
+ lightTag.removeAttribute("data-scheme-id");
+ }
+ }
+
+ if (data?.new_dark_href && darkTag) {
+ darkTag.href = data.new_dark_href;
+
+ if (replace && id) {
+ darkTag.setAttribute("data-scheme-id", id);
+ } else if (replace && isBuiltIn) {
+ darkTag.removeAttribute("data-scheme-id");
+ }
+ }
+
+ return data;
+ } catch (error) {
+ // eslint-disable-next-line no-console
+ console.error(`Failed to apply changes to color scheme`, error);
+ throw error;
+ }
+}
+
+/**
+ * set color scheme as active for the default theme and apply immediately
+ *
+ * @param {Object} scheme - color scheme to set as default
+ * @param {Object} options
+ * @param {boolean} options.reload - reload the page after setting? (default: false)
+ * @returns {Promise}
+ */
+
+export async function setDefaultColorScheme(scheme, store, options = {}) {
+ const { reload = false } = options;
+
+ try {
+ // can't live preview if isBuiltInDefault
+ const isBuiltIn = isBuiltInDefault(scheme);
+ const shouldReload = reload || isBuiltIn;
+
+ if (!shouldReload) {
+ await applyColorScheme(scheme, { replace: true });
+ }
+
+ const themes = await store.findAll("theme");
+ const defaultTheme = themes.findBy("default", true);
+
+ if (!defaultTheme) {
+ throw new Error("Could not find default theme");
+ }
+
+ const schemeId = getSchemeId(scheme);
+ defaultTheme.set("color_scheme_id", schemeId);
+
+ await defaultTheme.saveChanges("color_scheme_id");
+
+ if (shouldReload) {
+ window.location.reload();
+ }
+
+ return defaultTheme;
+ } catch (error) {
+ // eslint-disable-next-line no-console
+ console.error("Failed to set default color scheme", error);
+ throw error;
+ }
+}
diff --git a/app/assets/javascripts/admin/addon/lib/color-transformations.js b/app/assets/javascripts/admin/addon/lib/color-transformations.js
new file mode 100644
index 00000000000..acce7a56a08
--- /dev/null
+++ b/app/assets/javascripts/admin/addon/lib/color-transformations.js
@@ -0,0 +1,160 @@
+// replicates colors transformations from variables.scss
+// so we can generate transformed colors from color schemes in JS
+// currently only generates primary-low and tertiary-low
+
+// normalize hex color to 6 digits
+function normalizeHex(hex) {
+ hex = hex.replace("#", "");
+ if (hex.length === 3) {
+ return hex
+ .split("")
+ .map((c) => c + c)
+ .join("");
+ }
+ return hex;
+}
+
+// matches dc-color-brightness from variables.scss
+function colorBrightness(color) {
+ const hex = normalizeHex(color);
+ const r = parseInt(hex.substring(0, 2), 16);
+ const g = parseInt(hex.substring(2, 4), 16);
+ const b = parseInt(hex.substring(4, 6), 16);
+
+ return r * 0.299 + g * 0.587 + b * 0.114;
+}
+
+// convert RGB to HSL
+function rgbToHsl(r, g, b) {
+ r /= 255;
+ g /= 255;
+ b /= 255;
+
+ const max = Math.max(r, g, b);
+ const min = Math.min(r, g, b);
+ let h,
+ s,
+ l = (max + min) / 2;
+
+ if (max === min) {
+ h = s = 0;
+ } else {
+ const d = max - min;
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
+ switch (max) {
+ case r:
+ h = (g - b) / d + (g < b ? 6 : 0);
+ break;
+ case g:
+ h = (b - r) / d + 2;
+ break;
+ case b:
+ h = (r - g) / d + 4;
+ break;
+ }
+ h /= 6;
+ }
+
+ return [h, s, l];
+}
+
+// HSL to RGB
+function hslToRgb(h, s, l) {
+ let r, g, b;
+
+ if (s === 0) {
+ r = g = b = l;
+ } else {
+ const hue2rgb = (p, q, t) => {
+ if (t < 0) {
+ t += 1;
+ }
+ if (t > 1) {
+ t -= 1;
+ }
+ if (t < 1 / 6) {
+ return p + (q - p) * 6 * t;
+ }
+ if (t < 1 / 2) {
+ return q;
+ }
+ if (t < 2 / 3) {
+ return p + (q - p) * (2 / 3 - t) * 6;
+ }
+ return p;
+ };
+
+ const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
+ const p = 2 * l - q;
+ r = hue2rgb(p, q, h + 1 / 3);
+ g = hue2rgb(p, q, h);
+ b = hue2rgb(p, q, h - 1 / 3);
+ }
+
+ return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
+}
+
+// scale color lightness (approximates sass' scale-color)
+function scaleColorLightness(color, lightness) {
+ const hex = normalizeHex(color);
+ const r = parseInt(hex.substring(0, 2), 16);
+ const g = parseInt(hex.substring(2, 4), 16);
+ const b = parseInt(hex.substring(4, 6), 16);
+
+ // convert to HSL
+ const [h, s, l] = rgbToHsl(r, g, b);
+
+ // scale lightness similar to sass
+ let newL;
+ if (lightness > 0) {
+ newL = l + (1 - l) * (lightness / 100);
+ } else {
+ newL = l * (1 + lightness / 100);
+ }
+
+ const [newR, newG, newB] = hslToRgb(h, s, newL);
+
+ return `#${newR.toString(16).padStart(2, "0")}${newG.toString(16).padStart(2, "0")}${newB.toString(16).padStart(2, "0")}`;
+}
+
+function darkLightDiff(adjustedColor, comparisonColor, lightness, darkness) {
+ const adjustedBrightness = colorBrightness(adjustedColor);
+ const comparisonBrightness = colorBrightness(comparisonColor);
+
+ if (adjustedBrightness < comparisonBrightness) {
+ return scaleColorLightness(adjustedColor, lightness);
+ } else {
+ return scaleColorLightness(adjustedColor, darkness);
+ }
+}
+
+// get primary-low or tertiary-low color for preview
+export function getPreviewColor(scheme, colorName) {
+ const baseColor = scheme.colors?.find((c) => c.name === colorName);
+ const secondaryColor = scheme.colors?.find((c) => c.name === "secondary");
+
+ if (!baseColor || !secondaryColor) {
+ return "#ffffff"; // fallback
+ }
+
+ const base = baseColor.hex;
+ const secondary = secondaryColor.hex;
+
+ if (colorName === "primary") {
+ // primary-low: dark-light-diff($primary, $secondary, 90%, -78%)
+ return darkLightDiff(base, secondary, 90, -78);
+ } else if (colorName === "tertiary") {
+ // tertiary-low: dark-light-diff($tertiary, $secondary, 85%, -65%)
+ return darkLightDiff(base, secondary, 85, -65);
+ }
+
+ return base;
+}
+
+// generate CSS custom properties
+export function getColorSchemeStyles(scheme) {
+ const primaryLow = getPreviewColor(scheme, "primary");
+ const tertiaryLow = getPreviewColor(scheme, "tertiary");
+
+ return `--primary-low--preview: ${primaryLow}; --tertiary-low--preview: ${tertiaryLow};`;
+}
diff --git a/app/assets/javascripts/admin/addon/routes/admin-customize-colors-show.js b/app/assets/javascripts/admin/addon/routes/admin-customize-colors-show.js
index 83fe6d7ee7d..0834afc778d 100644
--- a/app/assets/javascripts/admin/addon/routes/admin-customize-colors-show.js
+++ b/app/assets/javascripts/admin/addon/routes/admin-customize-colors-show.js
@@ -1,17 +1,19 @@
import Route from "@ember/routing/route";
import { service } from "@ember/service";
+import ColorScheme from "admin/models/color-scheme";
export default class AdminCustomizeColorsShowRoute extends Route {
@service router;
model(params) {
- const all = this.modelFor("adminCustomize.colors");
- const model = all.findBy("id", parseInt(params.scheme_id, 10));
- if (model) {
- return model;
- } else {
- this.router.replaceWith("adminCustomize.colors.index");
- }
+ return ColorScheme.findAll().then((all) => {
+ const model = all.findBy("id", parseInt(params.scheme_id, 10));
+ if (model) {
+ return model;
+ } else {
+ this.router.replaceWith("adminCustomize.colors");
+ }
+ });
}
serialize(model) {
@@ -20,6 +22,8 @@ export default class AdminCustomizeColorsShowRoute extends Route {
setupController(controller) {
super.setupController(...arguments);
- controller.set("allColors", this.modelFor("adminCustomize.colors"));
+ ColorScheme.findAll().then((all) => {
+ controller.set("allColors", all);
+ });
}
}
diff --git a/app/assets/javascripts/admin/addon/routes/admin-customize-colors.js b/app/assets/javascripts/admin/addon/routes/admin-customize-colors.js
index ffb86ee21a6..59053a159dd 100644
--- a/app/assets/javascripts/admin/addon/routes/admin-customize-colors.js
+++ b/app/assets/javascripts/admin/addon/routes/admin-customize-colors.js
@@ -1,8 +1,21 @@
import Route from "@ember/routing/route";
+import { service } from "@ember/service";
+import { hash } from "rsvp";
import ColorScheme from "admin/models/color-scheme";
export default class AdminCustomizeColorsRoute extends Route {
+ @service store;
+
model() {
- return ColorScheme.findAll();
+ return hash({
+ colorSchemes: ColorScheme.findAll(),
+ themes: this.store.findAll("theme"),
+ });
+ }
+
+ setupController(controller, model) {
+ super.setupController(controller, model);
+ controller.set("model", model.colorSchemes);
+ controller.set("defaultTheme", model.themes.findBy("default", true));
}
}
diff --git a/app/assets/javascripts/admin/addon/routes/admin-route-map.js b/app/assets/javascripts/admin/addon/routes/admin-route-map.js
index 79a5ad7f5ba..94636133dbb 100644
--- a/app/assets/javascripts/admin/addon/routes/admin-route-map.js
+++ b/app/assets/javascripts/admin/addon/routes/admin-route-map.js
@@ -61,9 +61,8 @@ export default function () {
"adminCustomize",
{ path: "/customize", resetNamespace: true },
function () {
- this.route("colors", function () {
- this.route("show", { path: "/:scheme_id" });
- });
+ this.route("colors");
+ this.route("colors-show", { path: "/colors/:scheme_id" });
this.route(
"adminCustomizeThemes",
{ path: "/:type", resetNamespace: true },
diff --git a/app/assets/javascripts/admin/addon/templates/customize-colors-index.gjs b/app/assets/javascripts/admin/addon/templates/customize-colors-index.gjs
deleted file mode 100644
index 4436ba0be94..00000000000
--- a/app/assets/javascripts/admin/addon/templates/customize-colors-index.gjs
+++ /dev/null
@@ -1,10 +0,0 @@
-import RouteTemplate from "ember-route-template";
-import { i18n } from "discourse-i18n";
-
-export default RouteTemplate(
- <template>
- <div class="alert alert-info about-customize-colors">{{i18n
- "admin.customize.colors.about"
- }}</div>
- </template>
-);
diff --git a/app/assets/javascripts/admin/addon/templates/customize-colors-show.gjs b/app/assets/javascripts/admin/addon/templates/customize-colors-show.gjs
index 4109e7309fd..cf6fdde5042 100644
--- a/app/assets/javascripts/admin/addon/templates/customize-colors-show.gjs
+++ b/app/assets/javascripts/admin/addon/templates/customize-colors-show.gjs
@@ -5,12 +5,20 @@ import RouteTemplate from "ember-route-template";
import DButton from "discourse/components/d-button";
import TextField from "discourse/components/text-field";
import concatClass from "discourse/helpers/concat-class";
+import icon from "discourse/helpers/d-icon";
import { i18n } from "discourse-i18n";
import ColorInput from "admin/components/color-input";
import InlineEditCheckbox from "admin/components/inline-edit-checkbox";
export default RouteTemplate(
<template>
+ <div class="back-to-color-palettes">
+ <LinkTo @route="adminCustomize.colors">
+ {{icon "angle-left"}}
+ {{i18n "admin.customize.colors.back_to_colors"}}
+ </LinkTo>
+ </div>
+
<div class="color-scheme show-current-style">
<div class="admin-container">
<h1>{{#if
diff --git a/app/assets/javascripts/admin/addon/templates/customize-colors.gjs b/app/assets/javascripts/admin/addon/templates/customize-colors.gjs
index f755f1655b5..b86e1e42544 100644
--- a/app/assets/javascripts/admin/addon/templates/customize-colors.gjs
+++ b/app/assets/javascripts/admin/addon/templates/customize-colors.gjs
@@ -1,22 +1,20 @@
-import { LinkTo } from "@ember/routing";
+import { hash } from "@ember/helper";
+import { htmlSafe } from "@ember/template";
import RouteTemplate from "ember-route-template";
import DBreadcrumbsItem from "discourse/components/d-breadcrumbs-item";
import DButton from "discourse/components/d-button";
import DPageHeader from "discourse/components/d-page-header";
+import DPageSubheader from "discourse/components/d-page-subheader";
+import DSelect from "discourse/components/d-select";
+import FilterInput from "discourse/components/filter-input";
import PluginOutlet from "discourse/components/plugin-outlet";
-import icon from "discourse/helpers/d-icon";
+import lazyHash from "discourse/helpers/lazy-hash";
import { i18n } from "discourse-i18n";
+import ColorPaletteListItem from "admin/components/color-palette-list-item";
export default RouteTemplate(
<template>
- <DPageHeader
- @titleLabel={{i18n "admin.config.color_palettes.title"}}
- @descriptionLabel={{i18n
- "admin.config.color_palettes.header_description"
- }}
- @learnMoreUrl="https://meta.discourse.org/t/allow-users-to-select-new-color-palettes/60857"
- @hideTabs={{true}}
- >
+ <DPageHeader @hideTabs={{true}}>
<:breadcrumbs>
<DBreadcrumbsItem @path="/admin" @label={{i18n "admin_title"}} />
<DBreadcrumbsItem
@@ -26,36 +24,89 @@ export default RouteTemplate(
</:breadcrumbs>
</DPageHeader>
- <div class="content-list color-schemes">
- <ul>
- {{#each @controller.model as |scheme|}}
- {{#unless scheme.is_base}}
- <li>
- <LinkTo
- @route="adminCustomize.colors.show"
- @model={{scheme}}
- @replace={{true}}
- >
- {{icon "paintbrush"}}
- {{scheme.description}}
- </LinkTo>
- </li>
- {{/unless}}
- {{/each}}
- </ul>
+ <DPageSubheader
+ @titleLabel={{i18n "admin.config.color_palettes.title"}}
+ @descriptionLabel={{i18n
+ "admin.config.color_palettes.header_description"
+ }}
+ @learnMoreUrl="https://meta.discourse.org/t/allow-users-to-select-new-color-palettes/60857"
+ >
+ <:actions as |actions|>
+ <PluginOutlet
+ @name="admin-customize-colors-new-button"
+ @outletArgs={{lazyHash actions=actions controller=@controller}}
+ >
+ <actions.Primary
+ @label="admin.customize.new"
+ @action={{@controller.newColorScheme}}
+ @icon="plus"
+ />
+ </PluginOutlet>
+ </:actions>
+ </DPageSubheader>
- <PluginOutlet @name="admin-customize-colors-new-button">
- <DButton
- @action={{@controller.newColorScheme}}
- @icon="plus"
- @label="admin.customize.new"
- class="btn-default"
+ {{#if @controller.showFilters}}
+ <div class="color-palette__filters">
+ <FilterInput
+ placeholder={{i18n
+ "admin.customize.colors.filters.search_placeholder"
+ }}
+ @filterAction={{@controller.onFilterChange}}
+ @value={{@controller.filterValue}}
+ class="admin-filter__input"
+ @icons={{hash left="magnifying-glass"}}
/>
- </PluginOutlet>
- </div>
+ <DSelect
+ @value={{@controller.typeFilter}}
+ @includeNone={{false}}
+ @onChange={{@controller.onTypeFilterChange}}
+ as |select|
+ >
+ {{#each @controller.typeFilterOptions as |option|}}
+ <select.Option @value={{option.value}}>
+ {{option.label}}
+ </select.Option>
+ {{/each}}
+ </DSelect>
+ </div>
+ {{/if}}
+
+ {{#if @controller.changedThemePreferences}}
+ <div class="alert alert-info">
+ {{htmlSafe
+ (i18n
+ "admin.customize.colors.preference_warning"
+ link="/my/preferences/interface"
+ )
+ }}
+ </div>
+ {{/if}}
- {{outlet}}
+ <ul class="color-palette__list">
+ {{#each @controller.filteredColorSchemes as |scheme|}}
+ <ColorPaletteListItem
+ @scheme={{scheme}}
+ @defaultTheme={{@controller.defaultTheme}}
+ @isDefaultThemeColorScheme={{@controller.isDefaultThemeColorScheme}}
+ @toggleUserSelectable={{@controller.toggleUserSelectable}}
+ @setAsDefaultThemePalette={{@controller.setAsDefaultThemePalette}}
+ @deleteColorScheme={{@controller.deleteColorScheme}}
+ />
+ {{/each}}
+ </ul>
- <div class="clearfix"></div>
+ {{#if @controller.showFilters}}
+ {{#unless @controller.filteredColorSchemes.length}}
+ <div class="color-palette__no-results">
+ <h3>{{i18n "admin.customize.colors.filters.no_results"}}</h3>
+ <DButton
+ @icon="arrow-rotate-left"
+ @label="admin.customize.colors.filters.reset"
+ @action={{@controller.resetFilters}}
+ class="btn-default"
+ />
+ </div>
+ {{/unless}}
+ {{/if}}
</template>
);
diff --git a/app/assets/stylesheets/admin/admin_base.scss b/app/assets/stylesheets/admin/admin_base.scss
index 1da033f7933..049d436cf0b 100644
--- a/app/assets/stylesheets/admin/admin_base.scss
+++ b/app/assets/stylesheets/admin/admin_base.scss
@@ -1243,6 +1243,7 @@ a.inline-editable-field {
@import "admin/json_schema_editor";
@import "admin/schema_field";
@import "admin/staff_logs";
+@import "admin/color_palettes";
@import "admin/customize";
@import "admin/customize-install-theme";
@import "admin/api";
diff --git a/app/assets/stylesheets/admin/color_palettes.scss b/app/assets/stylesheets/admin/color_palettes.scss
new file mode 100644
index 00000000000..fddd54e465d
--- /dev/null
+++ b/app/assets/stylesheets/admin/color_palettes.scss
@@ -0,0 +1,107 @@
+.color-palette {
+ &.admin-config-area-card {
+ padding: 0;
+ }
+
+ &__list {
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
+ gap: 1em;
+ align-items: stretch;
+ width: 100%;
+ list-style-type: none;
+ margin: 0;
+ padding-bottom: var(--space-4);
+ }
+
+ &__container {
+ position: relative;
+ display: flex;
+ flex-direction: column;
+ flex: 1 1 auto;
+ }
+
+ &__preview {
+ background: var(--secondary--preview, #fff);
+ border-bottom: 1px solid var(--primary-low--preview, #e9e9e9);
+
+ svg {
+ padding: var(--space-4);
+ }
+ }
+
+ &__details {
+ display: flex;
+ flex-direction: column;
+ align-items: start;
+ flex: 1 1 auto;
+ padding: var(--space-4) var(--space-4) 0;
+
+ h3 {
+ margin-bottom: var(--space-1);
+ }
+
+ .color-palette__theme-link {
+ min-height: 2rem;
+ font-size: var(--font-down-1);
+
+ a {
+ color: var(--primary-medium);
+ }
+
+ .d-icon {
+ font-size: var(--font-down-1);
+ }
+ }
+ }
+
+ &__controls {
+ display: flex;
+ justify-content: space-between;
+ padding: 0 var(--space-4) var(--space-4) var(--space-4);
+ }
+
+ &__badges {
+ min-height: 2rem;
+ }
+
+ .fk-d-tooltip__trigger {
+ background: transparent;
+
+ .d-icon {
+ color: var(--primary-high);
+ }
+ }
+
+ &__filters {
+ display: flex;
+ gap: var(--space-2);
+ margin-bottom: var(--space-4);
+
+ .filter-input-container {
+ flex: 4 1 auto;
+ }
+
+ .d-select {
+ flex: 1 1 auto;
+ width: auto;
+ }
+ }
+
+ &__no-results {
+ display: flex;
+ flex-direction: column;
+ text-align: center;
+ justify-content: center;
+ padding: var(--space-6);
+ gap: var(--space-2);
+
+ h3 {
+ font-weight: normal;
+ }
+
+ .btn {
+ align-self: center;
+ }
+ }
+}
diff --git a/app/assets/stylesheets/admin/customize.scss b/app/assets/stylesheets/admin/customize.scss
index 17100ae12f8..0a994f01c2e 100644
--- a/app/assets/stylesheets/admin/customize.scss
+++ b/app/assets/stylesheets/admin/customize.scss
@@ -141,13 +141,6 @@
margin-top: 20px;
}
- .color-schemes li {
- .d-icon {
- margin-right: 0.25em;
- color: var(--primary-medium);
- }
- }
-
.show-current-style {
display: inline-block;
vertical-align: top;
@@ -962,59 +955,17 @@
}
}
-.about-customize-colors {
- text-align: center;
- width: 65%;
- margin-left: 30%;
-}
-
-.desktop-view .admin-customize {
- .show-current-style {
- width: 68%;
-
- &.legacy {
- padding-left: 2%;
- }
-
- .title {
- input {
- width: 80%;
- }
- }
- }
-
- .themes-list {
- width: 28%;
- }
-
- .back-to-themes-and-components {
- margin-bottom: 1em;
- }
+.back-to-themes-and-components {
+ margin-bottom: 1em;
}
.mobile-view .admin-customize {
- .show-current-style {
- padding: 0;
- width: 100%;
- }
-
- .themes-list,
- .color-schemes {
- width: 100%;
- margin-bottom: 1em;
- }
-
.admin-container {
display: flex;
flex-wrap: wrap;
padding: 0;
}
- .content-list.color-schemes ul {
- max-height: 250px;
- overflow-x: auto;
- }
-
.color-scheme {
h1,
h1 input {
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 6faf8413b04..02010fd2d26 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -5722,7 +5722,7 @@ en:
header_description: "Watched words are moderation tools that can perform multiple different actions including blocking, censoring, linking, or flagging posts containing certain words"
color_palettes:
title: "Color palettes"
- header_description: "Color palettes define the core colors used across your site’s interface, while themes can provide additional styling, layouts, and components. Both can work together to create your site’s unique look and feel, and both can be made available for users to select their preference."
+ header_description: "These palettes control the colors used throughout your community. When you make a palette user selectable, members can choose their preferred colors from their preferences."
emoji:
title: "Emoji"
header_description: "Add new emoji that will be available to everyone. Select multiple files to create emojis using their file names. The selected group will be used for all files that are added at the same time."
@@ -6510,7 +6510,7 @@ en:
install: "Install"
themes:
title: "Themes"
- description: "Site-wide themes that change the overall look and feel of your site for all users. Want to check which site settings your themes override? <a href=\"%{themeSiteSettingsUrl}\">View theme site settings</a>"
+ description: 'Site-wide themes that change the overall look and feel of your site for all users. Want to check which site settings your themes override? <a href="%{themeSiteSettingsUrl}">View theme site settings</a>'
themes_intro: "Install a new theme to get started, or create your own from scratch using these resources."
new_theme: "New theme"
back: "Back to themes"
@@ -6975,8 +6975,25 @@ en:
select_base:
title: "Select base color palette"
description: "Base palette:"
+ preference_warning: "You've changed <a href='%{link}'>your personal theme settings</a>, so palette changes may not be visible to you. Visitors that haven't changed their defaults will still see the changes you make here."
title: "Colors"
- edit: "Edit color palettes"
+ edit: "Edit"
+ set_default: "Set as active on %{theme}"
+ set_default_success: "%{schemeName} set as active palette for %{themeName}"
+ saved_refreshing: "Saved! Refreshing colors..."
+ from_theme: "From theme: %{name}"
+ filters:
+ search_placeholder: "Search by name or theme..."
+ all: "All"
+ user_selectable: "User selectable"
+ from_theme: "From theme"
+ no_results: "No color palettes found"
+ reset: "Reset filters"
+ active_badge:
+ text: "Active"
+ title: "Active color palette"
+ system_palette: "This is a built-in color palette, it cannot be edited or deleted."
+ back_to_colors: "Back to color palettes"
long_title: "Color palettes"
about: "Modify the colors used by your themes. Create a new color palette to start."
new_name: "New color palette"
diff --git a/spec/system/admin_color_palettes_features_spec.rb b/spec/system/admin_color_palettes_features_spec.rb
new file mode 100644
index 00000000000..8aafe6bd983
--- /dev/null
+++ b/spec/system/admin_color_palettes_features_spec.rb
@@ -0,0 +1,111 @@
+# frozen_string_literal: true
+
+describe "Admin Color Palettes Features", type: :system do
+ fab!(:admin)
+ fab!(:theme) { Fabricate(:theme, name: "Test Theme") }
+ fab!(:user_selectable_palette) do
+ Fabricate(:color_scheme, name: "User Selectable", user_selectable: true)
+ end
+ fab!(:theme_palette) { Fabricate(:color_scheme, name: "Theme Palette", theme: theme) }
+ fab!(:regular_palette) do
+ Fabricate(:color_scheme, name: "Regular Palette", user_selectable: false)
+ end
+
+ let(:toasts) { PageObjects::Components::Toasts.new }
+
+ before do
+ sign_in(admin)
+ # filter requires 8 palettes to show
+ 6.times { |i| Fabricate(:color_scheme, name: "Extra Palette #{i}") }
+ end
+
+ describe "filtering" do
+ it "shows filters when there are more than 8 color schemes" do
+ visit("/admin/customize/colors")
+
+ expect(page).to have_css(".color-palette__filters")
+ expect(page).to have_css(".admin-filter__input")
+ end
+
+ it "can filter by text search" do
+ visit("/admin/customize/colors")
+
+ find(".admin-filter__input").fill_in(with: user_selectable_palette.name)
+
+ expect(page).to have_css("[data-palette-id='#{user_selectable_palette.id}']")
+ expect(page).to have_no_css("[data-palette-id='#{regular_palette.id}']")
+ end
+
+ it "can filter by type" do
+ visit("/admin/customize/colors")
+
+ select_kit = PageObjects::Components::DSelect.new(".d-select")
+ select_kit.select("user_selectable")
+
+ expect(page).to have_css("[data-palette-id='#{user_selectable_palette.id}']")
+ expect(page).to have_no_css("[data-palette-id='#{regular_palette.id}']")
+ expect(page).to have_no_css(".color-palette:not([data-palette-id])")
+ end
+
+ it "shows no results state" do
+ visit("/admin/customize/colors")
+
+ find(".admin-filter__input").fill_in(with: "bananas")
+
+ expect(page).to have_css(".color-palette__no-results")
+ expect(page).to have_css(
+ "button",
+ text: I18n.t("admin_js.admin.customize.colors.filters.reset"),
+ )
+ end
+ end
+
+ describe "color palette list items" do
+ it "shows palette details" do
+ visit("/admin/customize/colors")
+
+ expect(page).to have_css("[data-palette-id='#{user_selectable_palette.id}']")
+ expect(page).to have_css("[data-palette-id='#{theme_palette.id}']")
+ expect(page).to have_css("[data-palette-id='#{regular_palette.id}']")
+ end
+
+ it "shows user selectable badge" do
+ visit("/admin/customize/colors")
+
+ within("[data-palette-id='#{user_selectable_palette.id}']") do
+ expect(page).to have_css(".theme-card__badge.--selectable")
+ end
+ end
+
+ it "shows theme link for theme palettes" do
+ visit("/admin/customize/colors")
+
+ within("[data-palette-id='#{theme_palette.id}']") { expect(page).to have_link(theme.name) }
+ end
+
+ it "can toggle user selectable status" do
+ visit("/admin/customize/colors")
+
+ within("[data-palette-id='#{regular_palette.id}']") { find(".btn-flat").click }
+
+ expect(page).to have_css(".dropdown-menu")
+ click_button(I18n.t("admin_js.admin.customize.theme.user_selectable_button_label"))
+
+ within("[data-palette-id='#{regular_palette.id}']") do
+ expect(page).to have_css(".theme-card__badge.--selectable")
+ end
+ end
+ end
+
+ describe "CSS variables" do
+ it "generates CSS variables for color schemes" do
+ visit("/admin/customize/colors")
+
+ palette_item = find("[data-palette-id='#{regular_palette.id}']")
+
+ expect(palette_item[:style]).to include("--primary--preview:")
+ expect(palette_item[:style]).to include("--secondary--preview:")
+ expect(palette_item[:style]).to include("--tertiary--preview:")
+ end
+ end
+end