-
Notifications
You must be signed in to change notification settings - Fork 12
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
COMPATIBILITY: Modernize the component #11
Merged
Merged
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2b083da
DEV: Update the lint config files
Arkshine 62649eb
DEV: Resolve compatibility with upcoming core changes
Arkshine 53c8043
UX: Make the dropdown appear above header elements
Arkshine 4b5cd92
UX: Fix text flickering on hover
Arkshine 7df5cf4
UX: Add some space to the auth buttons wrapper instead
Arkshine 6942e44
UX: Adjust padding and panel position to avoid pushing elements around
Arkshine 9ea30ce
UX: Fix alignment following the new API usage
Arkshine 8d68d38
UX: Reduce transition delay
Arkshine 6f707b4
DEV: Pin theme component to 3.3.0.beta1-dev
Arkshine d615866
DEV: Add acceptances tests
Arkshine 0b8084c
DEV: Move some CSS to common
Arkshine 30943e2
DEV: Do not overwrite dropdown link with existing header link
Arkshine 709e888
DEV: Update CI linting workflow
Arkshine 6c5f54a
DEV: Use Discourse theme reusable workflow
Arkshine 78394f2
DEV: Allow interaction on non-interaction element
Arkshine 0a8d0fb
DEV: Remove duplicated workflow
Arkshine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("@discourse/lint-configs/eslint-theme"); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("@discourse/lint-configs/prettier"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("@discourse/lint-configs/template-lint"); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
javascripts/discourse/api-initializers/dropdown-header.gjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { apiInitializer } from "discourse/lib/api"; | ||
import CustomHeaderLinks from "../components/custom-header-links"; | ||
|
||
export default apiInitializer("1.29.0", (api) => { | ||
if (!settings.header_links) { | ||
return; | ||
} | ||
|
||
if (settings.links_position === "right") { | ||
api.headerButtons.add("dropdown-header", CustomHeaderLinks, { | ||
before: "auth", | ||
}); | ||
} else { | ||
api.renderAfterWrapperOutlet("home-logo", CustomHeaderLinks); | ||
} | ||
}); |
22 changes: 0 additions & 22 deletions
22
javascripts/discourse/api-initializers/dropdown-header.js.es6
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
javascripts/discourse/components/custom-header-dropdown.gjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import Component from "@ember/component"; | ||
import { fn } from "@ember/helper"; | ||
import { on } from "@ember/modifier"; | ||
import { action } from "@ember/object"; | ||
import { service } from "@ember/service"; | ||
import DiscourseURL from "discourse/lib/url"; | ||
import CustomIcon from "./custom-icon"; | ||
|
||
export default class CustomHeaderDropdown extends Component { | ||
@service site; | ||
@service router; | ||
|
||
@action | ||
redirectToUrl(url) { | ||
if (this.site.mobileView) { | ||
this.toggleHeaderLinks(); | ||
} | ||
|
||
DiscourseURL.routeTo(url); | ||
} | ||
|
||
<template> | ||
<li | ||
class="custom-header-dropdown-link" | ||
title={{@item.title}} | ||
{{on "click" (fn this.redirectToUrl @item.url)}} | ||
> | ||
<CustomIcon @icon={{@item.icon}} /> | ||
<span class="custom-header-link-title">{{@item.title}}</span> | ||
{{#if @item.description}} | ||
<span class="custom-header-link-desc">{{@item.description}}</span> | ||
{{/if}} | ||
</li> | ||
</template> | ||
} |
111 changes: 111 additions & 0 deletions
111
javascripts/discourse/components/custom-header-link.gjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import Component from "@ember/component"; | ||
import { fn } from "@ember/helper"; | ||
import { on } from "@ember/modifier"; | ||
import { action } from "@ember/object"; | ||
import { notEmpty } from "@ember/object/computed"; | ||
import { inject as service } from "@ember/service"; | ||
import concatClass from "discourse/helpers/concat-class"; | ||
import DiscourseURL from "discourse/lib/url"; | ||
import dIcon from "discourse-common/helpers/d-icon"; | ||
import CustomHeaderDropdown from "./custom-header-dropdown"; | ||
import CustomIcon from "./custom-icon"; | ||
|
||
export default class CustomHeaderLink extends Component { | ||
@service siteSettings; | ||
@service site; | ||
@service currentUser; | ||
|
||
@notEmpty("dropdownLinks") hasDropdown; | ||
|
||
get shouldDisplay() { | ||
if (!settings.security) { | ||
return true; | ||
} | ||
|
||
const permissions = JSON.parse(settings.security); | ||
const getPermissions = permissions | ||
.filter((p) => p.headerLinkId === this.item.id) | ||
.map((p) => p.title); | ||
|
||
const currentUserGroups = this.currentUser?.groups.map((g) => g.name); | ||
|
||
if (getPermissions?.length < 1) { | ||
return true; | ||
} | ||
|
||
if (getPermissions.length < 0) { | ||
return false; | ||
} | ||
|
||
if (!this.currentUser) { | ||
return false; | ||
} | ||
|
||
if (currentUserGroups.includes(getPermissions[0])) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
get showCaret() { | ||
return settings.show_caret_icons && this.hasDropdown; | ||
} | ||
|
||
get dropdownLinks() { | ||
const allDropdownItems = settings.dropdown_links | ||
? JSON.parse(settings.dropdown_links) | ||
: []; | ||
|
||
const dropdownLinks = allDropdownItems.filter( | ||
(d) => d.headerLinkId === this.item.id | ||
); | ||
|
||
return dropdownLinks; | ||
} | ||
|
||
@action | ||
redirectToUrl(url) { | ||
if (this.site.mobileView) { | ||
this.toggleHeaderLinks(); | ||
} | ||
|
||
DiscourseURL.routeTo(url); | ||
} | ||
|
||
<template> | ||
{{#if this.shouldDisplay}} | ||
<li | ||
class={{concatClass | ||
"custom-header-link" | ||
(if @item.url "with-url") | ||
(if this.hasDropdown "has-dropdown") | ||
}} | ||
title={{@item.title}} | ||
{{(if | ||
@item.url (modifier on "click" (fn this.redirectToUrl @item.url)) | ||
)}} | ||
> | ||
<CustomIcon @icon={{@item.icon}} /> | ||
<span class="custom-header-link-title">{{@item.title}}</span> | ||
|
||
{{#if this.showCaret}} | ||
<span class="custom-header-link-caret"> | ||
{{dIcon "caret-down"}} | ||
</span> | ||
{{/if}} | ||
|
||
{{#if this.hasDropdown}} | ||
<ul class="custom-header-dropdown"> | ||
{{#each this.dropdownLinks as |dropdownItem|}} | ||
<CustomHeaderDropdown | ||
@item={{dropdownItem}} | ||
@toggleHeaderLinks={{this.toggleHeaderLinks}} | ||
/> | ||
{{/each}} | ||
</ul> | ||
{{/if}} | ||
</li> | ||
{{/if}} | ||
</template> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { tracked } from "@glimmer/tracking"; | ||
import Component from "@ember/component"; | ||
import { hash } from "@ember/helper"; | ||
import { action } from "@ember/object"; | ||
import { inject as service } from "@ember/service"; | ||
import DButton from "discourse/components/d-button"; | ||
import concatClass from "discourse/helpers/concat-class"; | ||
import closeOnClickOutside from "discourse/modifiers/close-on-click-outside"; | ||
import i18n from "discourse-common/helpers/i18n"; | ||
import CustomHeaderLink from "./custom-header-link"; | ||
|
||
export default class CustomHeaderLinks extends Component { | ||
@service siteSettings; | ||
@service site; | ||
|
||
@tracked showLinks = !this.site.mobileView; | ||
|
||
@action | ||
toggleHeaderLinks() { | ||
this.showLinks = !this.showLinks; | ||
|
||
if (this.showLinks) { | ||
document.body.classList.add("dropdown-header-open"); | ||
} else { | ||
document.body.classList.remove("dropdown-header-open"); | ||
} | ||
} | ||
|
||
get headerLinks() { | ||
return JSON.parse(settings.header_links); | ||
} | ||
|
||
<template> | ||
<nav | ||
class={{concatClass | ||
"custom-header-links" | ||
(if @outletArgs.minimized "scrolling") | ||
}} | ||
> | ||
{{#if this.site.mobileView}} | ||
<span class="btn-custom-header-dropdown-mobile"> | ||
<DButton | ||
@icon="caret-square-down" | ||
@title={{i18n "custom_header.discord"}} | ||
@action={{this.toggleHeaderLinks}} | ||
/> | ||
</span> | ||
{{/if}} | ||
|
||
{{#if this.showLinks}} | ||
<ul | ||
class="top-level-links" | ||
{{(if | ||
this.site.mobileView | ||
(modifier | ||
closeOnClickOutside | ||
this.toggleHeaderLinks | ||
(hash target=this.element) | ||
) | ||
)}} | ||
> | ||
{{#each this.headerLinks as |item|}} | ||
<CustomHeaderLink | ||
@item={{item}} | ||
@toggleHeaderLinks={{this.toggleHeaderLinks}} | ||
/> | ||
{{/each}} | ||
</ul> | ||
{{/if}} | ||
</nav> | ||
</template> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Component from "@ember/component"; | ||
import { equal } from "@ember/object/computed"; | ||
import { tagName } from "@ember-decorators/component"; | ||
import concatClass from "discourse/helpers/concat-class"; | ||
import dIcon from "discourse-common/helpers/d-icon"; | ||
|
||
@tagName("") | ||
export default class CustomIcon extends Component { | ||
@equal("sourceType", "image_url") isImageUrl; | ||
@equal("sourceType", "font_awesome") isFontAwesome; | ||
|
||
get sourceType() { | ||
return settings.icon_source; | ||
} | ||
|
||
get source() { | ||
return this.icon.trim(); | ||
} | ||
|
||
<template> | ||
{{#if this.source}} | ||
<span class={{concatClass "custom-header-link-icon" @class}}> | ||
{{#if this.isImageUrl}} | ||
<img src={{this.source}} /> | ||
{{else if this.isFontAwesome}} | ||
{{dIcon this.source}} | ||
{{/if}} | ||
</span> | ||
{{/if}} | ||
</template> | ||
} |
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
javascripts/discourse/widgets/custom-header-dropdown.js.es6
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plugin outlet wrapper is not inside
.title
.