ember-joinery 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # ember-joinery
2
2
 
3
+ ## 1.1.0
4
+
5
+ No changes in this release.
6
+
3
7
  ## 1.0.1
4
8
 
5
9
  No changes in this release.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-joinery",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Copy Joinery's components into your Ember app, and update them: shadcn's `add`, for Ember.",
5
5
  "keywords": [
6
6
  "ember",
@@ -35,7 +35,7 @@
35
35
  "NOTICE"
36
36
  ],
37
37
  "devDependencies": {
38
- "@ember-joinery/ember": "1.0.1"
38
+ "@ember-joinery/ember": "1.1.0"
39
39
  },
40
40
  "engines": {
41
41
  "node": ">=22.12.0"
@@ -0,0 +1,221 @@
1
+ import Component from '@glimmer/component'
2
+ import { hash } from '@ember/helper'
3
+ import { on } from '@ember/modifier'
4
+ import type { TOC } from '@ember/component/template-only'
5
+ import type { WithBoundArgs } from '@glint/template'
6
+ import { As, type TagName } from '@ember-joinery/primitives/as'
7
+ import { idFor } from '@ember-joinery/primitives/id'
8
+ import { t } from '@ember-joinery/primitives/i18n'
9
+ import { messages } from '../messages.ts'
10
+
11
+ /**
12
+ * Where the sidebar and the aside start: `default` puts the header across the top, over both;
13
+ * `alt` runs them the full height, with the header beside them.
14
+ */
15
+ export type AppShellLayout = 'default' | 'alt'
16
+
17
+ /** What a bar draws where content scrolls under it: a line, a fade, or nothing. */
18
+ export type AppShellScrollEdge = 'hard' | 'soft' | 'none'
19
+
20
+ export interface AppShellBarSignature {
21
+ Args: {
22
+ /**
23
+ * Whether it is a material (`jn-material`), so it turns to glass where the app asks for it
24
+ * (`data-jn-material="glass"`). Default `true`.
25
+ */
26
+ material?: boolean
27
+ /** What it draws where content scrolls under it. Default `hard`, a line. */
28
+ scrollEdge?: AppShellScrollEdge
29
+ /** The tag to render instead of the region's own. */
30
+ as?: TagName
31
+ }
32
+ Blocks: { default: [] }
33
+ Element: HTMLElement
34
+ }
35
+
36
+ export interface AppShellPaneSignature {
37
+ Args: {
38
+ /** Its name for assistive technology. Default `Main` for the sidebar, `Details` for the aside. */
39
+ label?: string
40
+ /** Whether it is a material (`jn-material`, the `sidebar` surface). Default `false`. */
41
+ material?: boolean
42
+ /** The tag to render instead of the region's own (`nav` for the sidebar, `aside`). */
43
+ as?: TagName
44
+ }
45
+ Blocks: { default: [] }
46
+ Element: HTMLElement
47
+ }
48
+
49
+ export interface AppShellMainSignature {
50
+ Args: {
51
+ /** Set by the shell: the id its skip link goes to. */
52
+ mainId: string
53
+ /**
54
+ * Set by the shell: whether the content is what scrolls. A scrolling region needs keyboard
55
+ * access, so it is then in the tab order (`tabindex="0"`), and the arrow keys scroll it.
56
+ */
57
+ scrolls?: boolean
58
+ }
59
+ Blocks: { default: [] }
60
+ Element: HTMLElement
61
+ }
62
+
63
+ const edge = (value: AppShellScrollEdge | undefined): string | undefined =>
64
+ value === 'none' ? undefined : (value ?? 'hard')
65
+
66
+ const materialClass = (material: boolean | undefined, fallback: boolean): string | undefined =>
67
+ (material ?? fallback) ? 'jn-material' : undefined
68
+
69
+ const Header: TOC<AppShellBarSignature> = <template>
70
+ <As
71
+ @as={{if @as @as "header"}}
72
+ class={{materialClass @material true}}
73
+ data-material="bar"
74
+ data-scroll-edge={{edge @scrollEdge}}
75
+ data-jn-app-shell-header
76
+ ...attributes
77
+ >{{yield}}</As>
78
+ </template>
79
+
80
+ const Footer: TOC<AppShellBarSignature> = <template>
81
+ <As
82
+ @as={{if @as @as "footer"}}
83
+ class={{materialClass @material true}}
84
+ data-material="bar"
85
+ data-scroll-edge={{edge @scrollEdge}}
86
+ data-scroll-edge-side="top"
87
+ data-jn-app-shell-footer
88
+ ...attributes
89
+ >{{yield}}</As>
90
+ </template>
91
+
92
+ const Sidebar: TOC<AppShellPaneSignature> = <template>
93
+ <As
94
+ @as={{if @as @as "nav"}}
95
+ class={{materialClass @material false}}
96
+ data-material="sidebar"
97
+ data-material-blending="behind-window"
98
+ aria-label={{if @label @label (t messages.appShellSidebarLabel)}}
99
+ data-jn-app-shell-sidebar
100
+ ...attributes
101
+ >{{yield}}</As>
102
+ </template>
103
+
104
+ const Aside: TOC<AppShellPaneSignature> = <template>
105
+ <As
106
+ @as={{if @as @as "aside"}}
107
+ class={{materialClass @material false}}
108
+ data-material="sidebar"
109
+ aria-label={{if @label @label (t messages.appShellAsideLabel)}}
110
+ data-jn-app-shell-aside
111
+ ...attributes
112
+ >{{yield}}</As>
113
+ </template>
114
+
115
+ const Main: TOC<AppShellMainSignature> = <template>
116
+ <main id={{@mainId}} tabindex={{if @scrolls "0" "-1"}} data-jn-app-shell-main ...attributes>
117
+ {{yield}}
118
+ </main>
119
+ </template>
120
+
121
+ /** What an app shell yields: its regions. */
122
+ export interface AppShellParts {
123
+ /** The bar across the top: a `<header>`, sticky, and a material. */
124
+ Header: typeof Header
125
+ /** The navigation beside the content: a `<nav>` named `Main`. */
126
+ Sidebar: typeof Sidebar
127
+ /** The content: the page's `<main>`, which the skip link goes to. */
128
+ Main: WithBoundArgs<typeof Main, 'mainId' | 'scrolls'>
129
+ /** A pane after the content: an `<aside>` named `Details`. */
130
+ Aside: typeof Aside
131
+ /** The bar across the bottom: a `<footer>`, sticky, and a material. A phone's tab bar goes here. */
132
+ Footer: typeof Footer
133
+ /** The id of `Main`, for a link of your own to it. */
134
+ mainId: string
135
+ }
136
+
137
+ export interface AppShellSignature {
138
+ Args: {
139
+ /** Default `default`: the header over the sidebar. `alt` runs the sidebar the full height. */
140
+ layout?: AppShellLayout
141
+ /**
142
+ * Whether it fills the window and only its content scrolls, under its bars, as an installed
143
+ * app's does. Default `false`: the page scrolls, and the bars stick.
144
+ */
145
+ fullscreen?: boolean
146
+ /** Whether it starts with a link that skips to the content. Default `true`. */
147
+ skipLink?: boolean
148
+ /** The skip link's text. Default `Skip to main content`. */
149
+ skipLinkLabel?: string
150
+ /** Its name, for `AppShellHarness` (`data-test-jn-name`). */
151
+ name?: string
152
+ }
153
+ Blocks: { default: [AppShellParts] }
154
+ Element: HTMLDivElement
155
+ }
156
+
157
+ /**
158
+ * The frame of an app: a header, a sidebar, the content, an aside and a footer, each a landmark,
159
+ * in a grid. Joinery's own (shadcn/ui has no shell): Saas UI's and Mantine's `AppShell`, in
160
+ * Joinery's terms. Render only the regions the app has.
161
+ *
162
+ * <AppShell as |shell|>
163
+ * <shell.Header>Acme</shell.Header>
164
+ * <shell.Sidebar>…</shell.Sidebar>
165
+ * <shell.Main>{{outlet}}</shell.Main>
166
+ * </AppShell>
167
+ *
168
+ * Its first element is a link that skips to `Main`, shown when it has focus. Its bars keep clear
169
+ * of the device's safe areas (`--jn-safe-top` and the rest), and are materials. It wraps the
170
+ * app, so it is a wrapper for the harnesses (`data-test-jn-wrapper`), and its elements are
171
+ * styled by `data-jn-app-shell-*` attributes. `--app-shell-header-height` and
172
+ * `--app-shell-footer-height` (3.5rem each) set the bars' heights.
173
+ */
174
+ export default class AppShell extends Component<AppShellSignature> {
175
+ get mainId(): string {
176
+ return idFor(this, 'main')
177
+ }
178
+
179
+ /** Moves focus to the content, as the link's fragment would in a page with no router. */
180
+ skip = (event: Event): void => {
181
+ const main = (event.currentTarget as HTMLElement).ownerDocument.getElementById(this.mainId)
182
+ if (!main) return
183
+ event.preventDefault()
184
+ main.focus()
185
+ main.scrollIntoView({ block: 'start' })
186
+ }
187
+
188
+ <template>
189
+ <div
190
+ data-jn-app-shell
191
+ data-layout={{if @layout @layout "default"}}
192
+ data-fullscreen={{if @fullscreen ""}}
193
+ data-test-jn="app-shell"
194
+ data-test-jn-wrapper
195
+ data-test-jn-name={{@name}}
196
+ ...attributes
197
+ >
198
+ {{#unless (isFalse @skipLink)}}
199
+ <a href="#{{this.mainId}}" data-jn-app-shell-skip-link {{on "click" this.skip}}>{{if
200
+ @skipLinkLabel
201
+ @skipLinkLabel
202
+ (t messages.appShellSkipToMain)
203
+ }}</a>
204
+ {{/unless}}
205
+ {{yield
206
+ (hash
207
+ Header=Header
208
+ Sidebar=Sidebar
209
+ Main=(component Main mainId=this.mainId scrolls=@fullscreen)
210
+ Aside=Aside
211
+ Footer=Footer
212
+ mainId=this.mainId
213
+ )
214
+ }}
215
+ </div>
216
+ </template>
217
+ }
218
+
219
+ function isFalse(value: unknown): boolean {
220
+ return value === false
221
+ }