Skip to content

FEATURE: add API for custom sidebar sections to have expandable "more…" sections #33110

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

awesomerobot
Copy link
Member

image image

This adds the ability to define a "more" section menu to custom sidebar/navigation sections. This includes the ability to add a custom button w/ action at the bottom of the menu, as well as customize the "more" trigger icon and text.

This also allows API added sections to be visible for anonymous users.

Here's a working example for a custom "site info" section

import { apiInitializer } from "discourse/lib/api";

export default apiInitializer((api) => {
  api.addSidebarSection(
    (BaseCustomSidebarSection, BaseCustomSidebarSectionLink) => {
      return class extends BaseCustomSidebarSection {
        get name() {
          return "about-section";
        }

        get text() {
          return "Site info";
        }

        get actionsIcon() {
          return "gear";
        }

        get actions() {
          return [
            {
              id: "action-example",
              title: "action-example",
              action: () => {
                console.log("Custom action...");
              },
            },
          ];
        }

        get links() {
          return [
            new (class extends BaseCustomSidebarSectionLink {
              get name() {
                return "about";
              }
              get route() {
                return "about";
              }
              get title() {
                return "About";
              }
              get text() {
                return "About";
              }
              get prefixType() {
                return "icon";
              }
              get prefixValue() {
                return "circle-info";
              }
            })(),

            new (class extends BaseCustomSidebarSectionLink {
              get name() {
                return "faq";
              }
              get route() {
                return "faq";
              }
              get title() {
                return "FAQ";
              }
              get text() {
                return "FAQ";
              }
              get prefixType() {
                return "icon";
              }
              get prefixValue() {
                return "circle-question";
              }
            })(),
          ];
        }

        get moreLinks() {
          const links = [
            new (class extends BaseCustomSidebarSectionLink {
              get name() {
                return "terms";
              }
              get route() {
                return "tos";
              }
              get title() {
                return "Terms of Service";
              }
              get text() {
                return "Terms of Service";
              }
              get prefixType() {
                return "icon";
              }
              get prefixValue() {
                return "gavel";
              }
            })(),

            new (class extends BaseCustomSidebarSectionLink {
              get name() {
                return "privacy";
              }
              get href() {
                return "https://meta.discourse.org/privacy";
              }
              get title() {
                return "Privacy policy";
              }
              get text() {
                return "Privacy policy";
              }
              get prefixType() {
                return "icon";
              }
              get prefixValue() {
                return "user";
              }
            })(),
          ];

          return links;
        }

        get moreSectionText() {
          return "Legal";
        }

        get moreSectionIcon() {
          return "scroll";
        }
      };
    },
  );
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant