Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: remove alternative category badge styles, set bullet style as default #24198

Merged
merged 40 commits into from Nov 13, 2023

Conversation

awesomerobot
Copy link
Member

@awesomerobot awesomerobot commented Nov 1, 2023

Details and additional discussion have been posted to https://meta.discourse.org/t/moving-to-a-single-category-style-site-setting/282441

Goal

Once merged, this will eliminate the site setting category style which would allow admins to select bullet, box, bar, or none category badge styles.

The default for this setting was bullet, and this will now be the only style included in Discourse core (as seen below).

Screenshot 2023-11-06 at 4 14 52 PM

A theme component that allows for the other styles has been created for admins who wish to remain on the other styles: https://github.com/discourse/discourse-category-badge-styles

Details

At this point there’s no HTML structure to the bullet portion of the badge, it’s all displayed with CSS…

The markup for a parent category:

<a class="badge-category__wrapper" href="/c/general/4">
  <span data-category-id="4" data-drop-close="true" class="badge-category" title="Create  Test topics here that don’t fit into any other existing category test.">
    <span class="badge-category__name">General</span>
  </span>
</a>

The markup for a child category:

<a class="badge-category__wrapper" href="/c/general/getting-started/11">
  <span data-category-id="11" data-parent-category-id="4" data-drop-close="true" class="badge-category --has-parent" title="Made it was really insist. Peering down with. Thence he was as asphalt. Division whose skins glowed like the end of us out of Nature. Prove it upon his shoulder.">
    <span class="badge-category__name">Getting Started</span>
  </span>
</a>

How this works:

  1. Each .badge-category gets data attributes for category-id and parent-category-id

  2. category-badge-css-generator.js produces CSS for each badge, in the form of custom properties:

.badge-category[data-category-id="${category.id}"] { --category-badge-color: var(--category-${category.id}-color); --category-badge-text-color: #${category.text_color};  }

These custom properties are scoped to .badge-category based on the data attribute:

  • category-badge-color
  • category-badge-text-color
  • parent-category-badge-color
  1. CSS creates the bullet within a psuedo selector:
.badge-category:before {
   content: "";
   background: var(--category-badge-color);
   flex: 0 0 auto;
   width: 0.67rem; 
   height: 0.67rem;
 }

If there’s a parent category, the badge is split using a CSS gradient. Parents get a .--has-parent modifier class that applies this:

.badge-category {
  &.--has-parent {
     &:before {
       background: linear-gradient(
         90deg,
         var(--parent-category-badge-color) 50%,
         var(--category-badge-color) 50%
       );
     }
   }
 }

This applies to all category badges, except for:

  • Sidebar/navigation categories

    These are structured differently because the sidebar calls for a prefix for each link. This special case makes sense given the API for adding sidebar links. Sharing classes and styles with these is more complicated than it's worth at the moment.

  • Hashtag mentions in posts

    Mentions are similar to the sidebar where they all share a structure and API, so this is another case where these are a different "organism" in a sense.

Things to update after this is merged

This PR also adjusts some padding and spacing for consistency, and removes a bunch of style-specific CSS.

Once merged this will rely on updates to:

@github-actions github-actions bot added the chat PRs which include a change to Chat plugin label Nov 1, 2023
@awesomerobot awesomerobot marked this pull request as ready for review November 6, 2023 21:28
@awesomerobot awesomerobot added the 👍 OP to merge PR author can go ahead and merge! label Nov 6, 2023
@awesomerobot awesomerobot merged commit 797da58 into main Nov 13, 2023
13 of 14 checks passed
@awesomerobot awesomerobot deleted the category-bullet-only branch November 13, 2023 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chat PRs which include a change to Chat plugin 👍 OP to merge PR author can go ahead and merge!
2 participants