Skip to content

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

FEATURE: introduce DComboButton and apply to create topic button (#36513)

Jarek Radosz0151699d04d8
diff --git a/app/assets/stylesheets/common/base/uc-modernize-foundation-theme.scss b/app/assets/stylesheets/common/base/uc-modernize-foundation-theme.scss
index 252d91dc245..d53a499d48f 100644
--- a/app/assets/stylesheets/common/base/uc-modernize-foundation-theme.scss
+++ b/app/assets/stylesheets/common/base/uc-modernize-foundation-theme.scss
@@ -252,17 +252,6 @@
font-size: var(--d-topic-list-data-font-size);
}
- #create-topic {
- --d-button-default-border: 1px solid var(--tertiary);
- --d-button-default-border--hover: 1px solid var(--tertiary-hover);
- --d-button-default-bg-color: var(--tertiary);
- --d-button-default-bg-color--hover: var(--tertiary-hover);
- --d-button-default-text-color: var(--secondary);
- --d-button-default-icon-color: var(--secondary);
- --d-button-default-text-color--hover: var(--secondary);
- --d-button-default-icon-color--hover: var(--secondary);
- }
-
// Select Kit
.select-kit .select-kit-header:not(.btn),
.d-date-input .date-picker {
diff --git a/app/assets/stylesheets/common/components/_index.scss b/app/assets/stylesheets/common/components/_index.scss
index 1614535bd6a..b7e3b0a2702 100644
--- a/app/assets/stylesheets/common/components/_index.scss
+++ b/app/assets/stylesheets/common/components/_index.scss
@@ -23,6 +23,7 @@
@import "date-picker";
@import "date-time-input-range";
@import "date-time-input";
+@import "d-combo-button";
@import "drafts-dropdown-menu";
@import "empty-states";
@import "file-size-input";
diff --git a/app/assets/stylesheets/common/components/d-combo-button.scss b/app/assets/stylesheets/common/components/d-combo-button.scss
new file mode 100644
index 00000000000..a6d90117e8a
--- /dev/null
+++ b/app/assets/stylesheets/common/components/d-combo-button.scss
@@ -0,0 +1,20 @@
+.d-combo-button.--has-menu {
+ display: inline-flex;
+
+ .d-combo-button-button {
+ border-top-right-radius: 0;
+ border-bottom-right-radius: 0;
+ border-right-color: transparent;
+ }
+
+ .d-combo-button-menu {
+ border-top-left-radius: 0;
+ border-bottom-left-radius: 0;
+ border-left-color: transparent;
+ margin-left: 0.1em; // more flexible than border, and scales with UI zoom
+
+ &.fk-d-menu__trigger .d-icon {
+ font-size: var(--font-down-1);
+ }
+ }
+}
diff --git a/app/assets/stylesheets/common/components/drafts-dropdown-menu.scss b/app/assets/stylesheets/common/components/drafts-dropdown-menu.scss
index c22f166859e..3e714c0e575 100644
--- a/app/assets/stylesheets/common/components/drafts-dropdown-menu.scss
+++ b/app/assets/stylesheets/common/components/drafts-dropdown-menu.scss
@@ -1,12 +1,3 @@
-// Styles for the drafts dropdown menu
-.topic-drafts-menu-trigger {
- margin-left: -0.25em;
-}
-
-.topic-drafts-menu-content {
- margin-top: -0.4em;
-}
-
.topic-drafts-menu-content .dropdown-menu {
.btn .d-button-label {
@include ellipsis;
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 8f1a87fee44..0b06f2ef132 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -3749,6 +3749,7 @@ en:
other: "%{count} posts in topic"
create: "New Topic"
create_long: "Create a new topic"
+ create_group: "New topic and drafts"
open_draft: "Open Draft"
private_message: "Start a message"
archive_message:
diff --git a/frontend/discourse/app/components/create-topic-button.gjs b/frontend/discourse/app/components/create-topic-button.gjs
index 9e3c5b465e2..11ba111adaf 100644
--- a/frontend/discourse/app/components/create-topic-button.gjs
+++ b/frontend/discourse/app/components/create-topic-button.gjs
@@ -1,7 +1,5 @@
import Component from "@glimmer/component";
-import { tracked } from "@glimmer/tracking";
import { service } from "@ember/service";
-import DButton from "discourse/components/d-button";
import TopicDraftsDropdown from "discourse/components/topic-drafts-dropdown";
import concatClass from "discourse/helpers/concat-class";
import { applyValueTransformer } from "discourse/lib/transformer";
@@ -9,8 +7,7 @@ import { applyValueTransformer } from "discourse/lib/transformer";
export default class CreateTopicButton extends Component {
@service router;
- @tracked label = this.args.label ?? "topic.create";
-
+ label = this.args.label ?? "topic.create";
btnId = this.args.btnId ?? "create-topic";
get btnTypeClass() {
@@ -38,20 +35,15 @@ export default class CreateTopicButton extends Component {
<template>
{{#if @canCreateTopic}}
- <DButton
+ <TopicDraftsDropdown
@action={{@action}}
- @icon="far-pen-to-square"
@label={{this.label}}
- id={{this.btnId}}
- class={{this.btnClasses}}
+ @btnId={{this.btnId}}
+ @btnClasses={{this.btnClasses}}
+ @btnTypeClass={{this.btnTypeClass}}
+ @showDrafts={{@showDrafts}}
+ ...attributes
/>
-
- {{#if @showDrafts}}
- <TopicDraftsDropdown
- @disabled={{false}}
- @btnTypeClass={{this.btnTypeClass}}
- />
- {{/if}}
{{/if}}
</template>
}
diff --git a/frontend/discourse/app/components/d-combo-button.gjs b/frontend/discourse/app/components/d-combo-button.gjs
new file mode 100644
index 00000000000..425b6145a7a
--- /dev/null
+++ b/frontend/discourse/app/components/d-combo-button.gjs
@@ -0,0 +1,41 @@
+import Component from "@glimmer/component";
+import { hash } from "@ember/helper";
+import curryComponent from "ember-curry-component";
+import DButton from "discourse/components/d-button";
+import DMenu from "discourse/float-kit/components/d-menu";
+
+// eslint-disable-next-line ember/no-empty-glimmer-component-classes
+class Button extends Component {
+ <template>
+ {{#let (curryComponent DButton this.args) as |CurriedComponent|}}
+ <CurriedComponent class="d-combo-button-button" ...attributes>
+ {{yield}}
+ </CurriedComponent>
+ {{/let}}
+ </template>
+}
+
+// eslint-disable-next-line ember/no-empty-glimmer-component-classes
+class Menu extends Component {
+ <template>
+ {{#let (curryComponent DMenu this.args) as |CurriedComponent|}}
+ <CurriedComponent
+ @icon="chevron-down"
+ class="d-combo-button-menu"
+ ...attributes
+ >
+ <:content>
+ {{yield}}
+ </:content>
+ </CurriedComponent>
+ {{/let}}
+ </template>
+}
+
+const DComboButton = <template>
+ <div class="d-combo-button" role="group" ...attributes>
+ {{yield (hash Button=Button Menu=Menu)}}
+ </div>
+</template>;
+
+export default DComboButton;
diff --git a/frontend/discourse/app/components/d-navigation.gjs b/frontend/discourse/app/components/d-navigation.gjs
index e201649aaf4..090853e7bdb 100644
--- a/frontend/discourse/app/components/d-navigation.gjs
+++ b/frontend/discourse/app/components/d-navigation.gjs
@@ -309,6 +309,10 @@ export default class DNavigation extends Component {
@canCreateTopic={{this.canCreateTopic}}
@action={{this.clickCreateTopicButton}}
@label={{this.createTopicLabel}}
+ @btnTypeClass={{if
+ this.siteSettings.modernize_foundation_theme
+ "btn-primary"
+ }}
@showDrafts={{if (gt this.draftCount 0) true false}}
/>
diff --git a/frontend/discourse/app/components/topic-drafts-dropdown.gjs b/frontend/discourse/app/components/topic-drafts-dropdown.gjs
index 4bf804fe072..d9cae8c9e39 100644
--- a/frontend/discourse/app/components/topic-drafts-dropdown.gjs
+++ b/frontend/discourse/app/components/topic-drafts-dropdown.gjs
@@ -4,9 +4,8 @@ import { fn } from "@ember/helper";
import { action } from "@ember/object";
import { service } from "@ember/service";
import DButton from "discourse/components/d-button";
+import DComboButton from "discourse/components/d-combo-button";
import DropdownMenu from "discourse/components/dropdown-menu";
-import DMenu from "discourse/float-kit/components/d-menu";
-import concatClass from "discourse/helpers/concat-class";
import DiscourseURL from "discourse/lib/url";
import {
NEW_PRIVATE_MESSAGE_KEY,
@@ -23,6 +22,7 @@ export default class TopicDraftsDropdown extends Component {
@tracked drafts = [];
@tracked loading = false;
+ dMenu;
get draftCount() {
return this.currentUser.draft_count;
@@ -40,6 +40,10 @@ export default class TopicDraftsDropdown extends Component {
: "";
}
+ get showViewAll() {
+ return this.draftCount > DRAFTS_LIMIT;
+ }
+
draftIcon(item) {
if (item.draft_key.startsWith(NEW_TOPIC_KEY)) {
return "layer-group";
@@ -50,10 +54,6 @@ export default class TopicDraftsDropdown extends Component {
}
}
- get showViewAll() {
- return this.draftCount > DRAFTS_LIMIT;
- }
-
@action
onRegisterApi(api) {
this.dMenu = api;
@@ -98,50 +98,64 @@ export default class TopicDraftsDropdown extends Component {
}
<template>
- <DMenu
- @identifier="topic-drafts-menu"
- @title={{i18n "drafts.dropdown.title"}}
- @icon="chevron-down"
- @onShow={{this.onShowMenu}}
- @onRegisterApi={{this.onRegisterApi}}
- @modalForMobile={{true}}
- @disabled={{@disabled}}
- class={{concatClass "btn-small" @btnTypeClass}}
+ <DComboButton
+ class={{if @showDrafts "--has-menu"}}
+ aria-label={{i18n "topic.create_group"}}
+ ...attributes
+ as |combo|
>
- <:content>
- <DropdownMenu as |dropdown|>
- {{#each this.drafts as |draft|}}
- <dropdown.item class="topic-drafts-item">
- <DButton
- @action={{fn this.resumeDraft draft}}
- @icon={{this.draftIcon draft}}
- @translatedLabel={{or
- draft.title
- (i18n "drafts.dropdown.untitled")
- }}
- class="btn-secondary"
- />
- </dropdown.item>
- {{/each}}
-
- {{#if this.showViewAll}}
- <dropdown.divider />
-
- <dropdown.item>
- <DButton
- @href="/my/activity/drafts"
- @model={{this.currentUser}}
- class="btn-link view-all-drafts"
- >
- <span
- data-other-drafts={{this.otherDraftsCount}}
- >{{this.otherDraftsText}}</span>
- <span>{{i18n "drafts.dropdown.view_all"}}</span>
- </DButton>
- </dropdown.item>
- {{/if}}
- </DropdownMenu>
- </:content>
- </DMenu>
+ <combo.Button
+ @action={{@action}}
+ @label={{@label}}
+ @icon="far-pen-to-square"
+ id={{@btnId}}
+ class={{@btnClasses}}
+ />
+
+ {{#if @showDrafts}}
+ <combo.Menu
+ @identifier="topic-drafts-menu"
+ @title={{i18n "drafts.dropdown.title"}}
+ @onShow={{this.onShowMenu}}
+ @onRegisterApi={{this.onRegisterApi}}
+ @modalForMobile={{true}}
+ aria-label={{i18n "drafts.dropdown.title"}}
+ class={{@btnTypeClass}}
+ >
+ <DropdownMenu as |dropdown|>
+ {{#each this.drafts as |draft|}}
+ <dropdown.item class="topic-drafts-item">
+ <DButton
+ @action={{fn this.resumeDraft draft}}
+ @icon={{this.draftIcon draft}}
+ @translatedLabel={{or
+ draft.title
+ (i18n "drafts.dropdown.untitled")
+ }}
+ class="btn-secondary"
+ />
+ </dropdown.item>
+ {{/each}}
+
+ {{#if this.showViewAll}}
+ <dropdown.divider />
+
+ <dropdown.item>
+ <DButton
+ @href="/my/activity/drafts"
+ @model={{this.currentUser}}
+ class="btn-link view-all-drafts"
+ >
+ <span
+ data-other-drafts={{this.otherDraftsCount}}
+ >{{this.otherDraftsText}}</span>
+ <span>{{i18n "drafts.dropdown.view_all"}}</span>
+ </DButton>
+ </dropdown.item>
+ {{/if}}
+ </DropdownMenu>
+ </combo.Menu>
+ {{/if}}
+ </DComboButton>
</template>
}
diff --git a/themes/horizon/javascripts/discourse/components/sidebar-new-topic-button.gjs b/themes/horizon/javascripts/discourse/components/sidebar-new-topic-button.gjs
index cc18c7aa95d..b9bf54ba948 100644
--- a/themes/horizon/javascripts/discourse/components/sidebar-new-topic-button.gjs
+++ b/themes/horizon/javascripts/discourse/components/sidebar-new-topic-button.gjs
@@ -84,22 +84,19 @@ export default class SidebarNewTopicButton extends Component {
<template>
{{#if this.shouldRender}}
{{bodyClass "horizon-new-topic-button-enabled"}}
- <div
- class="sidebar-new-topic-button__wrapper"
+ <CreateTopicButton
{{didInsert this.getCategoryAndTag}}
{{didUpdate this.getCategoryAndTag this.router.currentRoute}}
{{didInsert this.watchForComposer}}
{{willDestroy this.stopWatchingForComposer}}
- >
- <CreateTopicButton
- @canCreateTopic={{this.canCreateTopic}}
- @action={{this.createNewTopic}}
- @label="topic.create"
- @btnClass="sidebar-new-topic-button"
- @btnTypeClass="btn-primary"
- @showDrafts={{gt this.draftCount 0}}
- />
- </div>
+ @canCreateTopic={{this.canCreateTopic}}
+ @action={{this.createNewTopic}}
+ @label="topic.create"
+ @btnClass="sidebar-new-topic-button"
+ @btnTypeClass="btn-primary"
+ @showDrafts={{gt this.draftCount 0}}
+ class="sidebar-new-topic-button__wrapper"
+ />
{{/if}}
</template>
}
diff --git a/themes/horizon/scss/sidebar-new-topic-button.scss b/themes/horizon/scss/sidebar-new-topic-button.scss
index bc2c3100064..92fbb1e789d 100644
--- a/themes/horizon/scss/sidebar-new-topic-button.scss
+++ b/themes/horizon/scss/sidebar-new-topic-button.scss
@@ -22,7 +22,7 @@
&:focus-visible,
&:hover {
.discourse-no-touch & {
- background-color: var(--accent-color);
+ background-color: var(--button-box-shadow);
box-shadow: 0 0 0 4px var(--button-box-shadow);
color: var(--accent-text-color);
@@ -38,14 +38,6 @@
&:has(.topic-drafts-menu-trigger) {
.sidebar-new-topic-button {
- border-radius: var(--d-button-border-radius) 0 0
- var(--d-button-border-radius);
- border-right: 1px solid
- light-dark(
- oklch(from var(--primary-300) l c h),
- oklch(from var(--primary-700) l c h)
- ) !important;
-
&:focus-visible,
&:hover {
.discourse-no-touch & {