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

feat: add setting to only show icons on small screens #54

Merged
merged 2 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ indent_size = 2
[*.{diff,md}]
trim_trailing_whitespace = false

[*.{js,php}]
[*.php]
indent_size = 4
5 changes: 5 additions & 0 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@
(new Extend\ApiController(ShowForumController::class))
->addInclude(['links', 'links.parent'])
->prepareDataForSerialization(LoadForumLinksRelationship::class),

(new Extend\Settings())
->registerLessConfigVar('fof-links-show-only-icons-on-mobile', 'fof-links.show_icons_only_on_mobile', function ($value) {
return $value ? 'true' : 'false';
}),
];
18 changes: 8 additions & 10 deletions js/src/admin/components/EditLinkModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,23 +208,21 @@ export default class EditlinksModal extends Modal {
isInternal: this.isInternal(),
isNewtab: this.isNewtab(),
visibility: this.visibility(),
}
};
}

onsubmit(e) {
e.preventDefault();

this.loading = true;

this.link
.save(this.submitData())
.then(
() => this.hide(),
(response) => {
this.loading = false;
this.handleErrors(response);
}
);
this.link.save(this.submitData()).then(
() => this.hide(),
(response) => {
this.loading = false;
this.handleErrors(response);
}
);
}

delete() {
Expand Down
17 changes: 16 additions & 1 deletion js/src/admin/components/LinksPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,24 @@ export default class LinksPage extends ExtensionPage {
this.forcedRefreshKey = 0;
}

content() {
sections() {
const items = super.sections();

items.setPriority('content', 100);

items.add('links', this.links(), 80);

return items;
}

links() {
return (
<div className="LinksPage">
<div className="ExtensionPage-permissions-header">
<div className="container">
<h2 className="ExtensionTitle">{app.translator.trans('fof-links.admin.links.links')}</h2>
</div>
</div>
<div className="container">
{Button.component(
{
Expand Down
9 changes: 8 additions & 1 deletion js/src/admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@ export * from '../common/models';
app.initializers.add('fof-links', () => {
app.store.models.links = Link;

app.extensionData.for('fof-links').registerPage(LinksPage);
app.extensionData
.for('fof-links')
.registerPage(LinksPage)
.registerSetting({
setting: 'fof-links.show_icons_only_on_mobile',
label: app.translator.trans('fof-links.admin.settings.show_icons_only_on_mobile'),
type: 'boolean',
});
});
8 changes: 5 additions & 3 deletions js/src/forum/components/LinkItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export default class LinkItem extends LinkButton {
}}
data-toggle={this.attrs.isDropdownButton ? 'dropdown' : undefined}
>
{this.icon} {link.title()}
{this.icon}
<span className="LinksButton-title">{link.title()}</span>
</LinkLabelNode>
{this.attrs.inDropdown && <Separator />}
</>
Expand All @@ -75,7 +76,8 @@ export default class LinkItem extends LinkButton {

return (
<Link {...linkAttrs}>
{this.icon} {link.title()}
{this.icon}
<span className="LinksButton-title">{link.title()}</span>
</Link>
);
}
Expand All @@ -95,7 +97,7 @@ export default class LinkItem extends LinkButton {
const iconClass = link.icon();

if (iconClass) {
return icon(iconClass, { className: 'Button-icon' });
return icon(iconClass, { className: 'Button-icon LinksButton-icon' });
}

return null;
Expand Down
14 changes: 14 additions & 0 deletions less/forum.less
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@
width: auto;
margin-right: 10px;
}

@media (max-width: 1100px) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be easier to wrap both blocks with the when clause rather than two separate ones?

&-icon {
& when (@fof-links-show-only-icons-on-mobile = true) {
margin-right: 0;
}
}

&-title {
& when (@fof-links-show-only-icons-on-mobile = true) {
display: none;
}
}
}
}

@media @phone {
Expand Down
3 changes: 3 additions & 0 deletions locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ fof-links:
create_button: => fof-links.ref.create_link
links: => fof-links.ref.links

settings:
show_icons_only_on_mobile: Show icons only on mobile

# Strings in this namespace are referenced by two or more unique keys.
ref:
create_link: Create Link
Expand Down