WIP: Add global settings dialog with nav and placeholder sections
Introduce a data-driven global settings modal opened from a gear button in the bottom-left of the dashboard, with a grouped left menu and a right content pane. Sections are placeholders for now. - Add a settings size (sm:max-w-6xl) to the modal host - Add app/config/settings.js describing the section groups - Add the global settings container, nav, nav item, and section components - Add the bottom-left settings button and wire it to the dashboard - Make nav items full-width blocks and give buttons the hand cursor app-wide - Cover the container and the button with integration tests
This commit is contained in:
1 parent
6ba30ef2e8
commit
17e6cbaf89
11 files changed
+406
No files matched your search
@@ -10,6 +10,7 @@ const WIDTHS = {
|
||||
xl: 'sm:max-w-xl',
|
||||
'2xl': 'sm:max-w-2xl',
|
||||
'3xl': 'sm:max-w-3xl',
|
||||
settings: 'sm:max-w-6xl',
|
||||
};
|
||||
|
||||
export default class ModalHostComponent extends Component {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { action } from '@ember/object';
|
||||
import { on } from '@ember/modifier';
|
||||
import { service } from '@ember/service';
|
||||
import GlobalSettings from './settings/global-settings.gjs';
|
||||
|
||||
// Gear button pinned to the bottom left of the dashboard that opens the global
|
||||
// settings dialog.
|
||||
export default class SettingsButtonComponent extends Component {
|
||||
@service modal;
|
||||
|
||||
@action
|
||||
open() {
|
||||
this.modal.open({ component: GlobalSettings, size: 'settings' });
|
||||
}
|
||||
|
||||
<template>
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" this.open}}
|
||||
aria-label="Open settings"
|
||||
title="Settings"
|
||||
class="rounded-md p-2 text-white opacity-90 transition-opacity hover:opacity-100 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white/70"
|
||||
>
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
aria-hidden="true"
|
||||
class="size-5"
|
||||
>
|
||||
<path
|
||||
d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.325.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 0 1 1.37.49l1.296 2.247a1.125 1.125 0 0 1-.26 1.431l-1.003.827c-.293.241-.438.613-.43.992a7.723 7.723 0 0 1 0 .255c-.008.378.137.75.43.991l1.004.827c.424.35.534.955.26 1.43l-1.298 2.247a1.125 1.125 0 0 1-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.47 6.47 0 0 1-.22.128c-.331.183-.581.495-.644.869l-.213 1.281c-.09.543-.56.94-1.11.94h-2.594c-.55 0-1.019-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 0 1-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 0 1-1.369-.49l-1.297-2.247a1.125 1.125 0 0 1 .26-1.431l1.004-.827c.292-.24.437-.613.43-.991a6.932 6.932 0 0 1 0-.255c.007-.38-.138-.751-.43-.992l-1.004-.827a1.125 1.125 0 0 1-.26-1.43l1.297-2.247a1.125 1.125 0 0 1 1.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.086.22-.128.332-.183.582-.495.644-.869l.214-1.28Z"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
<path
|
||||
d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</template>
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { action } from '@ember/object';
|
||||
import { on } from '@ember/modifier';
|
||||
import {
|
||||
DEFAULT_SETTINGS_SECTION_ID,
|
||||
SETTINGS_GROUPS,
|
||||
findSettingsSection,
|
||||
} from '../../config/settings';
|
||||
import Nav from './global-settings/nav.gjs';
|
||||
import Section from './global-settings/section.gjs';
|
||||
|
||||
// Container for the global settings dialog: a left navigation menu and a right
|
||||
// content pane. Phase 1 only renders placeholder content per section; real
|
||||
// settings forms will replace the placeholders one section at a time.
|
||||
export default class SettingsGlobalSettings extends Component {
|
||||
@tracked activeId = DEFAULT_SETTINGS_SECTION_ID;
|
||||
|
||||
get groups() {
|
||||
return SETTINGS_GROUPS;
|
||||
}
|
||||
|
||||
get activeSection() {
|
||||
return findSettingsSection(this.activeId);
|
||||
}
|
||||
|
||||
get activeLabel() {
|
||||
return this.activeSection?.label ?? 'Settings';
|
||||
}
|
||||
|
||||
@action
|
||||
selectSection(id) {
|
||||
this.activeId = id;
|
||||
}
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="flex h-[85vh] w-full flex-col text-gray-900 sm:h-[min(85vh,48rem)] sm:flex-row"
|
||||
>
|
||||
<Nav
|
||||
@groups={{this.groups}}
|
||||
@activeId={{this.activeId}}
|
||||
@onSelect={{this.selectSection}}
|
||||
/>
|
||||
|
||||
<div class="flex min-h-0 flex-1 flex-col">
|
||||
<header
|
||||
class="flex items-center justify-between gap-4 border-b border-gray-200 px-6 py-4"
|
||||
>
|
||||
<h3 id="modal-title" class="text-base font-semibold text-gray-900">
|
||||
{{this.activeLabel}}
|
||||
</h3>
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" @close}}
|
||||
aria-label="Close settings"
|
||||
class="rounded-md p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
|
||||
>
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
aria-hidden="true"
|
||||
class="size-5"
|
||||
>
|
||||
<path
|
||||
d="M6 18 18 6M6 6l12 12"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</header>
|
||||
|
||||
{{#if this.activeSection}}
|
||||
<Section @section={{this.activeSection}} />
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { fn } from '@ember/helper';
|
||||
import { on } from '@ember/modifier';
|
||||
|
||||
// A single settings navigation entry. Renders as a button so keyboard and
|
||||
// pointer interaction behave the same on every platform.
|
||||
export default class SettingsGlobalSettingsNavItem extends Component {
|
||||
get isActive() {
|
||||
return this.args.item?.id === this.args.activeId;
|
||||
}
|
||||
|
||||
<template>
|
||||
<button
|
||||
type="button"
|
||||
aria-current={{if this.isActive "true"}}
|
||||
{{on "click" (fn @onSelect @item.id)}}
|
||||
class="flex shrink-0 items-center gap-3 rounded-md px-3 py-2 text-left text-sm font-medium whitespace-nowrap transition-colors sm:w-full
|
||||
{{if
|
||||
this.isActive
|
||||
'bg-gray-200 text-gray-900'
|
||||
'text-gray-700 hover:bg-gray-100 hover:text-gray-900'
|
||||
}}"
|
||||
>
|
||||
{{#if @item.icon}}
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
aria-hidden="true"
|
||||
class="size-5 shrink-0"
|
||||
>
|
||||
<path
|
||||
d={{@item.icon}}
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
{{/if}}
|
||||
<span>{{@item.label}}</span>
|
||||
</button>
|
||||
</template>
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import NavItem from './nav-item.gjs';
|
||||
|
||||
// Left hand menu of the global settings dialog. On small screens the groups
|
||||
// collapse into a horizontally scrollable row above the content; from `sm` up
|
||||
// it becomes a fixed width vertical sidebar with group headings.
|
||||
<template>
|
||||
<nav
|
||||
aria-label="Settings"
|
||||
class="flex shrink-0 gap-1 overflow-x-auto overflow-y-hidden border-b border-gray-200 bg-gray-50 p-2 sm:w-64 sm:flex-col sm:gap-0 sm:overflow-x-hidden sm:overflow-y-auto sm:border-r sm:border-b-0 sm:p-3"
|
||||
>
|
||||
{{#each @groups as |group|}}
|
||||
<div class="contents sm:block">
|
||||
{{#if group.label}}
|
||||
<p
|
||||
class="hidden px-3 pt-4 pb-1 text-xs font-semibold tracking-wide text-gray-400 uppercase sm:block"
|
||||
>
|
||||
{{group.label}}
|
||||
</p>
|
||||
{{/if}}
|
||||
|
||||
{{#each group.items as |item|}}
|
||||
<NavItem
|
||||
@item={{item}}
|
||||
@activeId={{@activeId}}
|
||||
@onSelect={{@onSelect}}
|
||||
/>
|
||||
{{/each}}
|
||||
</div>
|
||||
{{/each}}
|
||||
</nav>
|
||||
</template>
|
||||
@@ -0,0 +1,17 @@
|
||||
<template>
|
||||
<div class="min-h-0 flex-1 overflow-y-auto px-6 py-6">
|
||||
<p class="max-w-prose text-sm text-gray-500">{{@section.description}}</p>
|
||||
|
||||
<div
|
||||
class="mt-6 rounded-xl border border-dashed border-gray-300 bg-gray-50 p-8 text-center"
|
||||
>
|
||||
<p class="text-sm font-medium text-gray-600">
|
||||
{{@section.label}}
|
||||
settings are coming soon.
|
||||
</p>
|
||||
<p class="mt-1 text-sm text-gray-400">
|
||||
This section is a placeholder while the settings layout is being built.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,80 @@
|
||||
// Global settings dialog navigation. Phase 1 renders placeholder content for
|
||||
// each section; real forms will replace the placeholders one section at a time.
|
||||
//
|
||||
// `icon` values are inline SVG path data (24x24, stroke based) so the nav can
|
||||
// stay data driven without a separate icon component.
|
||||
|
||||
export const SETTINGS_GROUPS = [
|
||||
{
|
||||
items: [
|
||||
{
|
||||
id: 'appearance',
|
||||
label: 'Appearance',
|
||||
description:
|
||||
'Choose your wallpaper, theme, and how the dashboard looks.',
|
||||
icon: 'M9.53 16.122a3 3 0 0 0-5.78 1.128 2.25 2.25 0 0 1-2.4 2.245 4.5 4.5 0 0 0 8.4-2.245c0-.399-.078-.78-.22-1.128Zm0 0a15.998 15.998 0 0 0 3.388-1.62m-5.043-.025a15.994 15.994 0 0 1 1.622-3.395m3.42 3.42a15.995 15.995 0 0 0 4.764-4.648l3.876-5.814a1.151 1.151 0 0 0-1.597-1.597L14.146 6.32a15.996 15.996 0 0 0-4.649 4.763m3.42 3.42a6.776 6.776 0 0 0-3.42-3.42',
|
||||
},
|
||||
{
|
||||
id: 'clock',
|
||||
label: 'Clock',
|
||||
description: 'Pick how times are displayed across the dashboard.',
|
||||
icon: 'M12 6v6h4.5m4.5 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z',
|
||||
},
|
||||
{
|
||||
id: 'site-links',
|
||||
label: 'Site Links',
|
||||
description: 'Manage the quick links shown in the top right corner.',
|
||||
icon: 'M13.19 8.688a4.5 4.5 0 0 1 1.242 7.244l-4.5 4.5a4.5 4.5 0 0 1-6.364-6.364l1.757-1.757m13.35-.622 1.757-1.757a4.5 4.5 0 0 0-6.364-6.364l-4.5 4.5a4.5 4.5 0 0 0 1.242 7.244',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Integrations',
|
||||
items: [
|
||||
{
|
||||
id: 'connected',
|
||||
label: 'Connected Apps',
|
||||
description: 'Review and configure your connected integrations.',
|
||||
icon: 'M14.25 6.087c0-.355.186-.676.401-.959.221-.29.349-.634.349-1.003 0-1.036-1.007-1.875-2.25-1.875s-2.25.84-2.25 1.875c0 .369.128.713.349 1.003.215.283.401.604.401.959v0a.64.64 0 0 1-.657.643 48.39 48.39 0 0 1-4.163-.3c.186 1.613.293 3.25.315 4.907a.656.656 0 0 1-.658.663v0c-.355 0-.676-.186-.959-.401a1.647 1.647 0 0 0-1.003-.349c-1.036 0-1.875 1.007-1.875 2.25s.84 2.25 1.875 2.25c.369 0 .713-.128 1.003-.349.283-.215.604-.401.959-.401v0c.31 0 .555.26.532.57a48.039 48.039 0 0 1-.642 5.056c1.518.19 3.058.309 4.616.354a.64.64 0 0 0 .657-.643v0c0-.355-.186-.676-.401-.959a1.647 1.647 0 0 1-.349-1.003c0-1.035 1.008-1.875 2.25-1.875 1.243 0 2.25.84 2.25 1.875 0 .369-.128.713-.349 1.003-.215.283-.4.604-.4.959v0c0 .333.277.599.61.58a48.1 48.1 0 0 0 5.427-.63 48.05 48.05 0 0 0 .582-4.717.532.532 0 0 0-.533-.57v0c-.355 0-.676.186-.959.401-.29.221-.634.349-1.003.349-1.035 0-1.875-1.007-1.875-2.25s.84-2.25 1.875-2.25c.37 0 .713.128 1.003.349.283.215.604.401.96.401v0a.656.656 0 0 0 .658-.663 48.422 48.422 0 0 0-.37-5.36c-1.886.342-3.81.574-5.766.689a.578.578 0 0 1-.61-.58v0Z',
|
||||
},
|
||||
{
|
||||
id: 'notifications',
|
||||
label: 'Notifications',
|
||||
description: 'Decide which events should notify you.',
|
||||
icon: 'M14.857 17.082a23.848 23.848 0 0 0 5.454-1.31A8.967 8.967 0 0 1 18 9.75V9A6 6 0 0 0 6 9v.75a8.967 8.967 0 0 1-2.312 6.022c1.733.64 3.56 1.085 5.455 1.31m5.714 0a24.255 24.255 0 0 1-5.714 0m5.714 0a3 3 0 1 1-5.714 0',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Calendar',
|
||||
items: [
|
||||
{
|
||||
id: 'events',
|
||||
label: 'Events',
|
||||
description: 'Control the upcoming events widget and its sources.',
|
||||
icon: 'M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 0 1 2.25-2.25h13.5A2.25 2.25 0 0 1 21 7.5v11.25m-18 0A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75m-18 0v-7.5A2.25 2.25 0 0 1 5.25 9h13.5A2.25 2.25 0 0 1 21 11.25v7.5',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'About',
|
||||
items: [
|
||||
{
|
||||
id: 'about',
|
||||
label: 'About Dashtab',
|
||||
description: 'Version information and project links.',
|
||||
icon: 'm11.25 11.25.041-.02a.75.75 0 0 1 1.063.852l-.708 2.836a.75.75 0 0 0 1.063.853l.041-.021M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9-3.75h.008v.008H12V8.25Z',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export const SETTINGS_SECTIONS = SETTINGS_GROUPS.flatMap(
|
||||
(group) => group.items
|
||||
);
|
||||
|
||||
export const DEFAULT_SETTINGS_SECTION_ID = SETTINGS_SECTIONS[0]?.id ?? null;
|
||||
|
||||
export function findSettingsSection(id) {
|
||||
return SETTINGS_SECTIONS.find((section) => section.id === id) ?? null;
|
||||
}
|
||||
@@ -1,5 +1,13 @@
|
||||
@import 'tailwindcss';
|
||||
|
||||
/* Browsers render <button> with the default arrow cursor. Interactive controls
|
||||
should read as clickable, so restore the hand cursor app-wide. Explicit
|
||||
`cursor-*` utilities (e.g. the native-select controls) still win by
|
||||
specificity where a control intentionally opts out. */
|
||||
button {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* @theme { */
|
||||
/* --font-sans: Helvetica, "Liberation Sans", "Nimbus Sans", sans-serif; */
|
||||
/* } */
|
||||
|
||||
@@ -3,6 +3,7 @@ import DefaultClock from '../components/default-clock.gjs';
|
||||
import BitcoinTicker from '../components/bitcoin-ticker.gjs';
|
||||
import SiteLinks from '../components/site-links.gjs';
|
||||
import IntegrationsToolbar from '../components/integrations-toolbar.gjs';
|
||||
import SettingsButton from '../components/settings-button.gjs';
|
||||
import UpcomingEvents from '../components/upcoming-events.gjs';
|
||||
|
||||
<template>
|
||||
@@ -18,6 +19,10 @@ import UpcomingEvents from '../components/upcoming-events.gjs';
|
||||
<UpcomingEvents />
|
||||
</div>
|
||||
|
||||
<div class="col-start-1 row-start-3 flex items-end pl-12 pb-12">
|
||||
<SettingsButton />
|
||||
</div>
|
||||
|
||||
<div class="col-start-3 row-start-1 flex items-start justify-end pt-12 pr-12">
|
||||
<SiteLinks />
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'dashtab/tests/helpers';
|
||||
import { render, click } from '@ember/test-helpers';
|
||||
import SettingsButton from 'dashtab/components/settings-button';
|
||||
import ModalHost from 'dashtab/components/modal-host';
|
||||
import GlobalSettings from 'dashtab/components/settings/global-settings';
|
||||
|
||||
module('Integration | Component | settings-button', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('opens the global settings dialog', async function (assert) {
|
||||
const modal = this.owner.lookup('service:modal');
|
||||
|
||||
await render(<template><SettingsButton /></template>);
|
||||
await click('[aria-label="Open settings"]');
|
||||
|
||||
assert.strictEqual(modal.current.component, GlobalSettings);
|
||||
assert.strictEqual(modal.current.size, 'settings');
|
||||
});
|
||||
|
||||
test('opens at the settings panel width', async function (assert) {
|
||||
await render(<template><SettingsButton /><ModalHost /></template>);
|
||||
await click('[aria-label="Open settings"]');
|
||||
|
||||
assert.dom('el-dialog-panel').hasClass('sm:max-w-6xl');
|
||||
assert.dom('#modal-title').exists({ count: 1 });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'dashtab/tests/helpers';
|
||||
import { render, click } from '@ember/test-helpers';
|
||||
import GlobalSettings from 'dashtab/components/settings/global-settings';
|
||||
import { SETTINGS_SECTIONS } from 'dashtab/config/settings';
|
||||
|
||||
function sectionButton(element, label) {
|
||||
return [...element.querySelectorAll('nav button')].find(
|
||||
(button) => button.textContent.trim() === label
|
||||
);
|
||||
}
|
||||
|
||||
module('Integration | Component | settings/global-settings', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('renders a nav entry for every section', async function (assert) {
|
||||
const noop = () => {};
|
||||
|
||||
await render(<template><GlobalSettings @close={{noop}} /></template>);
|
||||
|
||||
for (const section of SETTINGS_SECTIONS) {
|
||||
assert
|
||||
.dom('nav[aria-label="Settings"]')
|
||||
.includesText(section.label, `nav lists "${section.label}"`);
|
||||
}
|
||||
});
|
||||
|
||||
test('shows the first section by default', async function (assert) {
|
||||
const noop = () => {};
|
||||
|
||||
await render(<template><GlobalSettings @close={{noop}} /></template>);
|
||||
|
||||
assert.dom('#modal-title').exists({ count: 1 });
|
||||
assert.dom('#modal-title').hasText(SETTINGS_SECTIONS[0].label);
|
||||
});
|
||||
|
||||
test('switching sections updates the heading and aria-current', async function (assert) {
|
||||
const noop = () => {};
|
||||
|
||||
await render(<template><GlobalSettings @close={{noop}} /></template>);
|
||||
|
||||
const target = SETTINGS_SECTIONS[1];
|
||||
const button = sectionButton(this.element, target.label);
|
||||
|
||||
await click(button);
|
||||
|
||||
assert.dom('#modal-title').hasText(target.label);
|
||||
assert.dom(button).hasAttribute('aria-current', 'true');
|
||||
assert
|
||||
.dom(sectionButton(this.element, SETTINGS_SECTIONS[0].label))
|
||||
.doesNotHaveAttribute('aria-current');
|
||||
});
|
||||
|
||||
test('the close button calls @close', async function (assert) {
|
||||
let closed = false;
|
||||
const close = () => {
|
||||
closed = true;
|
||||
};
|
||||
|
||||
await render(<template><GlobalSettings @close={{close}} /></template>);
|
||||
await click('[aria-label="Close settings"]');
|
||||
|
||||
assert.true(closed);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user