UX: improve composer toolbar flexibility (#18195)

This commit is contained in:
Kris 2022-09-13 14:20:33 -04:00 committed by GitHub
parent 19909a74b0
commit c69473128b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 67 deletions

View File

@ -50,7 +50,7 @@ let _createCallbacks = [];
class Toolbar { class Toolbar {
constructor(opts) { constructor(opts) {
const { site, siteSettings } = opts; const { siteSettings, capabilities } = opts;
this.shortcuts = {}; this.shortcuts = {};
this.context = null; this.context = null;
@ -106,16 +106,16 @@ class Toolbar {
}), }),
}); });
this.addButton({ if (!capabilities.touch) {
id: "code", this.addButton({
group: "insertions", id: "code",
shortcut: "E", group: "insertions",
preventFocus: true, shortcut: "E",
trimLeading: true, preventFocus: true,
action: (...args) => this.context.send("formatCode", args), trimLeading: true,
}); action: (...args) => this.context.send("formatCode", args),
});
if (!site.mobileView) {
this.addButton({ this.addButton({
id: "bullet", id: "bullet",
group: "extras", group: "extras",
@ -354,7 +354,7 @@ export default Component.extend(TextareaTextManipulation, {
@discourseComputed() @discourseComputed()
toolbar() { toolbar() {
const toolbar = new Toolbar( const toolbar = new Toolbar(
this.getProperties("site", "siteSettings", "showLink") this.getProperties("site", "siteSettings", "showLink", "capabilities")
); );
toolbar.context = this; toolbar.context = this;
@ -708,6 +708,7 @@ export default Component.extend(TextareaTextManipulation, {
this.applySurround(selected, head, tail, exampleKey, opts), this.applySurround(selected, head, tail, exampleKey, opts),
applyList: (head, exampleKey, opts) => applyList: (head, exampleKey, opts) =>
this._applyList(selected, head, exampleKey, opts), this._applyList(selected, head, exampleKey, opts),
formatCode: (...args) => this.send("formatCode", args),
addText: (text) => this.addText(selected, text), addText: (text) => this.addText(selected, text),
getText: () => this.value, getText: () => this.value,
toggleDirection: () => this._toggleDirection(), toggleDirection: () => this._toggleDirection(),

View File

@ -332,7 +332,17 @@ export default Controller.extend({
}) })
); );
if (this.site.mobileView) { if (this.capabilities.touch) {
options.push(
this._setupPopupMenuOption(() => {
return {
action: "applyFormatCode",
icon: "code",
label: "composer.code_title",
};
})
);
options.push( options.push(
this._setupPopupMenuOption(() => { this._setupPopupMenuOption(() => {
return { return {
@ -797,6 +807,10 @@ export default Controller.extend({
}); });
}, },
applyFormatCode() {
this.toolbarEvent.formatCode();
},
applyUnorderedList() { applyUnorderedList() {
this.toolbarEvent.applyList("* ", "list_item"); this.toolbarEvent.applyList("* ", "list_item");
}, },

View File

@ -15,10 +15,6 @@
<DButton @action={{b.action}} @type="button" @actionParam={{b}} @translatedTitle={{b.title}} @label={{b.label}} @icon={{b.icon}} @class={{b.className}} @preventFocus={{b.preventFocus}} @tabindex={{b.tabindex}} @onKeyDown={{this.rovingButtonBar}} /> <DButton @action={{b.action}} @type="button" @actionParam={{b}} @translatedTitle={{b.title}} @label={{b.label}} @icon={{b.icon}} @class={{b.className}} @preventFocus={{b.preventFocus}} @tabindex={{b.tabindex}} @onKeyDown={{this.rovingButtonBar}} />
{{/if}} {{/if}}
{{/each}} {{/each}}
{{#unless group.lastGroup}}
<div class="d-editor-spacer"></div>
{{/unless}}
{{/each}} {{/each}}
</div> </div>

View File

@ -546,14 +546,6 @@ body:not(.ios-safari-composer-hacks) {
} }
} }
.show-preview {
@media screen and (max-width: 850px) {
.d-editor-button-bar {
font-size: $font-down-1;
}
}
}
.toggle-preview { .toggle-preview {
margin-left: 8px; margin-left: 8px;
transition: all 0.33s ease-out; transition: all 0.33s ease-out;

View File

@ -305,29 +305,21 @@
// d-editor bar button sizing // d-editor bar button sizing
.d-editor-button-bar { .d-editor-button-bar {
display: flex; display: grid;
grid-template-columns: repeat(auto-fill, minmax(2.35em, 1fr));
@include breakpoint(tablet) {
// occupy available space on narrower screens
grid-template-columns: repeat(auto-fit, minmax(2em, 1fr));
}
@include breakpoint(mobile-medium) {
font-size: var(--font-down-1);
}
align-items: center; align-items: center;
border-bottom: 1px solid var(--primary-low); border-bottom: 1px solid var(--primary-low);
width: 100%; width: 100%;
box-sizing: border-box; box-sizing: border-box;
html:not(.keyboard-visible) & {
overflow-x: auto; // hiding overflow breaks the cog menu on iPad and mobile
}
flex-shrink: 0; flex-shrink: 0;
.d-editor-spacer {
height: 1em;
display: inline-block;
border-left: 1px solid var(--primary-low);
margin: 0 0.25em;
.mobile-view & {
display: none;
}
}
.btn:focus { .btn:focus {
@include default-focus; @include default-focus;
} }
@ -340,27 +332,14 @@
.d-icon { .d-icon {
color: currentColor; color: currentColor;
} }
&:hover { .discourse-no-touch & {
color: var(--primary-low); &:hover {
} color: var(--primary-low);
}
// ensures items grow/shrink on mobile to fit available space
@include breakpoint(mobile-large) {
.btn {
flex-grow: 1;
flex-shrink: 1;
flex-basis: auto;
padding-left: 0.25em;
padding-right: 0.25em;
}
.select-kit.toolbar-popup-menu-options {
flex-grow: 1;
flex-basis: auto;
.select-kit-header .select-kit-header-wrapper {
justify-content: center;
} }
} }
} }
.select-kit-header-wrapper {
justify-content: center;
}
} }

View File

@ -161,12 +161,10 @@
} }
} }
.d-editor-button-bar { .wmd-controls:not(.toolbar-visible) {
display: none; .d-editor-button-bar {
} display: none;
}
.toolbar-visible .d-editor-button-bar {
display: flex;
} }
.d-editor-button-bar .btn { .d-editor-button-bar .btn {