@lilydesignsystem/nunjucks-picker-bar 0.1.0 → 0.2.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/dist/index.d.ts +25 -10
- package/dist/index.js +15 -1
- package/dist/picker-bar.njk +36 -9
- package/index.md +34 -12
- package/package.json +8 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { initSearchPicker } from '@lilydesignsystem/nunjucks-search-picker';
|
|
2
|
+
export { autoInit as autoInitSearchPicker } from '@lilydesignsystem/nunjucks-search-picker';
|
|
1
3
|
import { initThemePicker } from '@lilydesignsystem/nunjucks-theme-picker';
|
|
2
4
|
export { autoInit as autoInitThemePicker } from '@lilydesignsystem/nunjucks-theme-picker';
|
|
3
5
|
import { initLocalePicker } from '@lilydesignsystem/nunjucks-locale-picker';
|
|
@@ -10,13 +12,14 @@ export { autoInit as autoInitSharePicker } from '@lilydesignsystem/nunjucks-shar
|
|
|
10
12
|
// PickerBar client-side runtime.
|
|
11
13
|
//
|
|
12
14
|
// Pairs with picker-bar.njk. Unlike every other helper in this catalog,
|
|
13
|
-
// this module owns NO lifecycle of its own:
|
|
14
|
-
//
|
|
15
|
-
// share-picker.client.js already own
|
|
15
|
+
// this module owns NO lifecycle of its own: search-picker.client.js,
|
|
16
|
+
// theme-picker.client.js, locale-picker.client.js,
|
|
17
|
+
// text-size-picker.client.js, and share-picker.client.js already own
|
|
18
|
+
// theirs, in full, independently of
|
|
16
19
|
// nesting (each scans the document for its own `data-lily-*-picker-root`
|
|
17
|
-
// hook). This module is a convenience wrapper that wires all
|
|
20
|
+
// hook). This module is a convenience wrapper that wires all five at
|
|
18
21
|
// once, scoped to one `picker-bar` root, instead of requiring the
|
|
19
|
-
// consumer to call
|
|
22
|
+
// consumer to call five separate `init*Picker` functions.
|
|
20
23
|
//
|
|
21
24
|
// See spec/index.md §4.3 (client.js exports), §5 (behaviour).
|
|
22
25
|
|
|
@@ -89,25 +92,36 @@ const DEFAULT_SIZES = [
|
|
|
89
92
|
];
|
|
90
93
|
|
|
91
94
|
/**
|
|
92
|
-
* Wire the
|
|
95
|
+
* Wire the five pickers inside one `[data-lily-picker-bar-root]`
|
|
93
96
|
* element. Each nested picker root is found and handed to its own
|
|
94
97
|
* sibling package's `init*Picker(root, opts)` — no different from
|
|
95
|
-
* calling all
|
|
98
|
+
* calling all five by hand, just in one call. `searchProps` is where
|
|
99
|
+
* search-picker's function-valued options (`navigate`, `onSearch`) go,
|
|
100
|
+
* since a macro cannot carry a function; `action` here overrides the
|
|
101
|
+
* rendered one.
|
|
96
102
|
*
|
|
97
103
|
* @param {HTMLElement} root
|
|
98
|
-
* @param {{themeProps?: object, localeProps?: object, textSizeProps?: object, shareProps?: object}=} opts
|
|
104
|
+
* @param {{searchProps?: object, themeProps?: object, localeProps?: object, textSizeProps?: object, shareProps?: object}=} opts
|
|
99
105
|
*/
|
|
100
106
|
function initPickerBar(root, opts = {}) {
|
|
101
107
|
if (!root) {
|
|
102
|
-
return {
|
|
108
|
+
return {
|
|
109
|
+
search: null,
|
|
110
|
+
theme: null,
|
|
111
|
+
locale: null,
|
|
112
|
+
textSize: null,
|
|
113
|
+
share: null,
|
|
114
|
+
};
|
|
103
115
|
}
|
|
104
116
|
const {
|
|
117
|
+
searchProps = {},
|
|
105
118
|
themeProps = {},
|
|
106
119
|
localeProps = {},
|
|
107
120
|
textSizeProps = {},
|
|
108
121
|
shareProps = {},
|
|
109
122
|
} = opts;
|
|
110
123
|
|
|
124
|
+
const searchRoot = root.querySelector("[data-lily-search-picker-root]");
|
|
111
125
|
const themeRoot = root.querySelector("[data-lily-theme-picker-root]");
|
|
112
126
|
const localeRoot = root.querySelector("[data-lily-locale-picker-root]");
|
|
113
127
|
const textSizeRoot = root.querySelector(
|
|
@@ -116,6 +130,7 @@ function initPickerBar(root, opts = {}) {
|
|
|
116
130
|
const shareRoot = root.querySelector("[data-lily-share-picker-root]");
|
|
117
131
|
|
|
118
132
|
return {
|
|
133
|
+
search: searchRoot ? initSearchPicker(searchRoot, searchProps) : null,
|
|
119
134
|
theme: themeRoot ? initThemePicker(themeRoot, themeProps) : null,
|
|
120
135
|
locale: localeRoot ? initLocalePicker(localeRoot, localeProps) : null,
|
|
121
136
|
textSize: textSizeRoot
|
|
@@ -128,7 +143,7 @@ function initPickerBar(root, opts = {}) {
|
|
|
128
143
|
/**
|
|
129
144
|
* Find every `[data-lily-picker-bar-root]` and wire it.
|
|
130
145
|
*
|
|
131
|
-
* @param {{themeProps?: object, localeProps?: object, textSizeProps?: object, shareProps?: object}=} opts
|
|
146
|
+
* @param {{searchProps?: object, themeProps?: object, localeProps?: object, textSizeProps?: object, shareProps?: object}=} opts
|
|
132
147
|
* @returns {Array<ReturnType<typeof initPickerBar>>}
|
|
133
148
|
*/
|
|
134
149
|
function autoInit(opts = {}) {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
// lily-design-system-nunjucks-picker-bar/picker-bar.client.js
|
|
2
|
+
import {
|
|
3
|
+
initSearchPicker,
|
|
4
|
+
autoInit as autoInitSearchPicker
|
|
5
|
+
} from "@lilydesignsystem/nunjucks-search-picker";
|
|
2
6
|
import {
|
|
3
7
|
initThemePicker,
|
|
4
8
|
autoInit as autoInitThemePicker
|
|
@@ -73,14 +77,22 @@ var DEFAULT_SIZES = [
|
|
|
73
77
|
];
|
|
74
78
|
function initPickerBar(root, opts = {}) {
|
|
75
79
|
if (!root) {
|
|
76
|
-
return {
|
|
80
|
+
return {
|
|
81
|
+
search: null,
|
|
82
|
+
theme: null,
|
|
83
|
+
locale: null,
|
|
84
|
+
textSize: null,
|
|
85
|
+
share: null
|
|
86
|
+
};
|
|
77
87
|
}
|
|
78
88
|
const {
|
|
89
|
+
searchProps = {},
|
|
79
90
|
themeProps = {},
|
|
80
91
|
localeProps = {},
|
|
81
92
|
textSizeProps = {},
|
|
82
93
|
shareProps = {}
|
|
83
94
|
} = opts;
|
|
95
|
+
const searchRoot = root.querySelector("[data-lily-search-picker-root]");
|
|
84
96
|
const themeRoot = root.querySelector("[data-lily-theme-picker-root]");
|
|
85
97
|
const localeRoot = root.querySelector("[data-lily-locale-picker-root]");
|
|
86
98
|
const textSizeRoot = root.querySelector(
|
|
@@ -88,6 +100,7 @@ function initPickerBar(root, opts = {}) {
|
|
|
88
100
|
);
|
|
89
101
|
const shareRoot = root.querySelector("[data-lily-share-picker-root]");
|
|
90
102
|
return {
|
|
103
|
+
search: searchRoot ? initSearchPicker(searchRoot, searchProps) : null,
|
|
91
104
|
theme: themeRoot ? initThemePicker(themeRoot, themeProps) : null,
|
|
92
105
|
locale: localeRoot ? initLocalePicker(localeRoot, localeProps) : null,
|
|
93
106
|
textSize: textSizeRoot ? initTextSizePicker(textSizeRoot, textSizeProps) : null,
|
|
@@ -106,6 +119,7 @@ export {
|
|
|
106
119
|
DEFAULT_THEMES,
|
|
107
120
|
autoInit,
|
|
108
121
|
autoInitLocalePicker,
|
|
122
|
+
autoInitSearchPicker,
|
|
109
123
|
autoInitSharePicker,
|
|
110
124
|
autoInitTextSizePicker,
|
|
111
125
|
autoInitThemePicker,
|
package/dist/picker-bar.njk
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{#
|
|
2
|
-
PickerBar macro — composes
|
|
3
|
-
text-size-picker, and share-picker
|
|
2
|
+
PickerBar macro — composes search-picker, theme-picker,
|
|
3
|
+
locale-picker, text-size-picker, and share-picker (in that order)
|
|
4
|
+
into one page-header row.
|
|
4
5
|
|
|
5
|
-
HTML tag: <div> (root) wrapping the
|
|
6
|
+
HTML tag: <div> (root) wrapping the five picker roots, unmodified.
|
|
6
7
|
CSS class: picker-bar
|
|
7
8
|
Companion runtime: picker-bar.client.js (a convenience `autoInit`
|
|
8
|
-
wrapping the
|
|
9
|
+
wrapping the five siblings' own `autoInit` — see that file; there is
|
|
9
10
|
no picker-bar-owned lifecycle of its own).
|
|
10
11
|
|
|
11
12
|
This macro owns no preference, action, or form value itself. It is a
|
|
12
|
-
composition: each of the
|
|
13
|
+
composition: each of the five picker macros below is imported from
|
|
13
14
|
its own sibling PACKAGE (a real npm `dependency` declared in this
|
|
14
15
|
package's package.json — not vendored source), and rendered with its
|
|
15
16
|
own unmodified contract. `motion-picker` and `date-time-picker` are
|
|
@@ -24,6 +25,7 @@
|
|
|
24
25
|
relative to the catalog root, exactly where `node_modules` would
|
|
25
26
|
place it after a real install.
|
|
26
27
|
#}
|
|
28
|
+
{% from "lily-design-system-nunjucks-search-picker/dist/search-picker.njk" import searchPicker %}
|
|
27
29
|
{% from "lily-design-system-nunjucks-theme-picker/dist/theme-picker.njk" import themePicker %}
|
|
28
30
|
{% from "lily-design-system-nunjucks-locale-picker/dist/locale-picker.njk" import localePicker %}
|
|
29
31
|
{% from "lily-design-system-nunjucks-text-size-picker/dist/text-size-picker.njk" import textSizePicker %}
|
|
@@ -66,8 +68,12 @@
|
|
|
66
68
|
] -%}
|
|
67
69
|
{#
|
|
68
70
|
Params (single `opts` object):
|
|
69
|
-
labels — object, required: {
|
|
70
|
-
|
|
71
|
+
labels — object, required: { search, searchInput,
|
|
72
|
+
searchSubmit, theme, locale, textSize, share }.
|
|
73
|
+
The seven accessible names: `search` names the
|
|
74
|
+
search picker's button and search landmark,
|
|
75
|
+
`searchInput` its field, `searchSubmit` its ⏎
|
|
76
|
+
button. No English default — a
|
|
71
77
|
nav row this catalog invented is exactly what the
|
|
72
78
|
i18n rule exists to prevent hardcoding.
|
|
73
79
|
themesUrl — string, required. Forwarded to theme-picker.
|
|
@@ -79,6 +85,11 @@
|
|
|
79
85
|
(default []). See share-picker.njk for the object
|
|
80
86
|
shape — `href` is an already-resolved string, not a
|
|
81
87
|
function, per that package's documented deviation.
|
|
88
|
+
searchProps — object. Extra search-picker opts (placeholder,
|
|
89
|
+
value, action, name, id, classes, attributes).
|
|
90
|
+
Its function-valued options (navigate, onSearch)
|
|
91
|
+
cannot pass through a macro — hand them to
|
|
92
|
+
picker-bar.client.js's `searchProps` instead.
|
|
82
93
|
themeProps — object. Extra theme-picker opts (value, defaultValue,
|
|
83
94
|
storageKey, detectFromSystem, name, extension,
|
|
84
95
|
themeLabels, id, classes, attributes) — anything NOT
|
|
@@ -100,13 +111,16 @@
|
|
|
100
111
|
Unlike the Svelte canonical's `children` snippet passthrough, a
|
|
101
112
|
Nunjucks macro call accepts at most one `{% call %}` block, so
|
|
102
113
|
picker-bar cannot route a custom glyph to one specific nested picker.
|
|
103
|
-
Compose the
|
|
114
|
+
Compose the five macros directly if you need a custom glyph on just
|
|
104
115
|
one of them — see spec/index.md §4.4.
|
|
105
116
|
|
|
106
117
|
Usage:
|
|
107
118
|
{% from "lily-design-system-nunjucks-picker-bar/dist/picker-bar.njk" import pickerBar %}
|
|
108
119
|
{{ pickerBar({
|
|
109
|
-
labels: {
|
|
120
|
+
labels: {
|
|
121
|
+
search: "Search this site", searchInput: "Search terms", searchSubmit: "Search",
|
|
122
|
+
theme: "Theme", locale: "Language", textSize: "Text size", share: "Share"
|
|
123
|
+
},
|
|
110
124
|
themesUrl: "/assets/themes/",
|
|
111
125
|
locales: ["en", "cy"]
|
|
112
126
|
}) }}
|
|
@@ -116,6 +130,7 @@
|
|
|
116
130
|
{%- macro pickerBar(opts) -%}
|
|
117
131
|
{%- set themes = opts.themes | default(DEFAULT_THEMES) -%}
|
|
118
132
|
{%- set sizes = opts.sizes | default(DEFAULT_SIZES) -%}
|
|
133
|
+
{%- set searchProps = opts.searchProps | default({}) -%}
|
|
119
134
|
{%- set themeProps = opts.themeProps | default({}) -%}
|
|
120
135
|
{%- set localeProps = opts.localeProps | default({}) -%}
|
|
121
136
|
{%- set textSizeProps = opts.textSizeProps | default({}) -%}
|
|
@@ -125,6 +140,18 @@
|
|
|
125
140
|
data-lily-picker-bar-root
|
|
126
141
|
{%- if opts.attributes %}{% for k, v in opts.attributes %} {{ k }}="{{ v }}"{% endfor %}{% endif %}
|
|
127
142
|
>
|
|
143
|
+
{{ searchPicker({
|
|
144
|
+
label: opts.labels.search,
|
|
145
|
+
inputLabel: opts.labels.searchInput,
|
|
146
|
+
submitLabel: opts.labels.searchSubmit,
|
|
147
|
+
placeholder: searchProps.placeholder,
|
|
148
|
+
value: searchProps.value,
|
|
149
|
+
action: searchProps.action,
|
|
150
|
+
name: searchProps.name,
|
|
151
|
+
id: searchProps.id,
|
|
152
|
+
classes: searchProps.classes,
|
|
153
|
+
attributes: searchProps.attributes
|
|
154
|
+
}) }}
|
|
128
155
|
{{ themePicker({
|
|
129
156
|
label: opts.labels.theme,
|
|
130
157
|
themesUrl: opts.themesUrl,
|
package/index.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# Lily Design System™ — Nunjucks PickerBar
|
|
2
2
|
|
|
3
|
-
A single page-header macro that composes
|
|
4
|
-
[`*-picker` helpers](../index.md) in this catalog —
|
|
5
|
-
text size, and share — with two catalog-wide
|
|
6
|
-
you can call one macro instead of assembling
|
|
3
|
+
A single page-header macro that composes five of the Lily
|
|
4
|
+
[`*-picker` helpers](../index.md) in this catalog — search, theme,
|
|
5
|
+
locale, text size, and share, in that order — with two catalog-wide
|
|
6
|
+
defaults pre-wired, so you can call one macro instead of assembling
|
|
7
|
+
and configuring five.
|
|
7
8
|
|
|
8
9
|
`motion-picker` and `date-time-picker` are not part of the bar: motion
|
|
9
10
|
has no natural spot next to the other three header preferences, and
|
|
@@ -15,8 +16,9 @@ has no natural spot next to the other three header preferences, and
|
|
|
15
16
|
npm install @lilydesignsystem/nunjucks-picker-bar
|
|
16
17
|
```
|
|
17
18
|
|
|
18
|
-
`@lilydesignsystem/nunjucks-
|
|
19
|
-
`-text-size-picker`, and `-share-picker` install
|
|
19
|
+
`@lilydesignsystem/nunjucks-search-picker`, `-theme-picker`,
|
|
20
|
+
`-locale-picker`, `-text-size-picker`, and `-share-picker` install
|
|
21
|
+
automatically as
|
|
20
22
|
regular dependencies — `pickerBar` is a thin wrapper around them, not
|
|
21
23
|
a reimplementation.
|
|
22
24
|
|
|
@@ -35,6 +37,9 @@ const env = nunjucks.configure(["views", "node_modules"], { autoescape: true });
|
|
|
35
37
|
|
|
36
38
|
{{ pickerBar({
|
|
37
39
|
labels: {
|
|
40
|
+
search: "Search this site",
|
|
41
|
+
searchInput: "Search terms",
|
|
42
|
+
searchSubmit: "Search",
|
|
38
43
|
theme: "Theme",
|
|
39
44
|
locale: "Language",
|
|
40
45
|
textSize: "Text size",
|
|
@@ -57,7 +62,8 @@ Then load `picker-bar.client.js` once and call `autoInit()`:
|
|
|
57
62
|
</script>
|
|
58
63
|
```
|
|
59
64
|
|
|
60
|
-
That's a complete, working header row:
|
|
65
|
+
That's a complete, working header row: a site search (a search for
|
|
66
|
+
`foo` goes to `/?foo`), 45 themes, four locales, the
|
|
61
67
|
seven-step text-size scale, and one share destination plus copy-to-URL
|
|
62
68
|
if you add `shareProps: { copyLabel: "Copy link" }`.
|
|
63
69
|
|
|
@@ -91,9 +97,13 @@ detection, a `*Labels` override map, an `id`:
|
|
|
91
97
|
|
|
92
98
|
```njk
|
|
93
99
|
{{ pickerBar({
|
|
94
|
-
labels: {
|
|
100
|
+
labels: {
|
|
101
|
+
search: "Search this site", searchInput: "Search terms", searchSubmit: "Search",
|
|
102
|
+
theme: "Theme", locale: "Language", textSize: "Text size", share: "Share"
|
|
103
|
+
},
|
|
95
104
|
themesUrl: "/assets/themes/",
|
|
96
105
|
locales: ["en", "cy"],
|
|
106
|
+
searchProps: { action: "/search", placeholder: "Search…" },
|
|
97
107
|
themeProps: { storageKey: "lily-theme", detectFromSystem: true },
|
|
98
108
|
localeProps: { storageKey: "lily-locale", detectFromNavigator: true },
|
|
99
109
|
textSizeProps: { storageKey: "lily-text-size" },
|
|
@@ -101,16 +111,25 @@ detection, a `*Labels` override map, an `id`:
|
|
|
101
111
|
}) }}
|
|
102
112
|
```
|
|
103
113
|
|
|
114
|
+
`search-picker`'s function-valued options — `navigate` (default
|
|
115
|
+
`location.assign`) and `onSearch` — cannot pass through a macro, so
|
|
116
|
+
hand them to the client instead:
|
|
117
|
+
|
|
118
|
+
```js
|
|
119
|
+
autoInit({ searchProps: { navigate: (href) => router.go(href) } });
|
|
120
|
+
```
|
|
121
|
+
|
|
104
122
|
Unlike the Svelte canonical, `pickerBar` cannot route a custom glyph to
|
|
105
123
|
one specific picker (a Nunjucks macro call accepts only one
|
|
106
|
-
`{% call %}` block) — compose the
|
|
124
|
+
`{% call %}` block) — compose the five macros directly if you need
|
|
107
125
|
that.
|
|
108
126
|
|
|
109
127
|
## Styling
|
|
110
128
|
|
|
111
129
|
`pickerBar` renders no CSS of its own beyond the `picker-bar` root
|
|
112
130
|
wrapper — style each child through its own package's class hooks
|
|
113
|
-
(`theme-picker`, `locale-picker`, `text-size-picker`,
|
|
131
|
+
(`search-picker`, `theme-picker`, `locale-picker`, `text-size-picker`,
|
|
132
|
+
`share-picker`;
|
|
114
133
|
see each package's own `index.md`). A typical header layout:
|
|
115
134
|
|
|
116
135
|
```css
|
|
@@ -123,11 +142,14 @@ see each package's own `index.md`). A typical header layout:
|
|
|
123
142
|
|
|
124
143
|
## Accessibility
|
|
125
144
|
|
|
126
|
-
Every accessible name comes from `labels` —
|
|
145
|
+
Every accessible name comes from `labels` — `search`, `searchInput`,
|
|
146
|
+
and `searchSubmit` name the search picker's button and landmark, field,
|
|
147
|
+
and `⏎` button; `theme`, `locale`, `textSize`, `share` the others —
|
|
148
|
+
and there is no English
|
|
127
149
|
default, because a set of names this catalog invented is exactly the
|
|
128
150
|
case the rest of Lily's i18n rule exists for. Each wrapped picker keeps
|
|
129
151
|
its own WAI-ARIA APG contract unchanged; see that picker's own
|
|
130
|
-
`index.md`. As with every helper in this catalog, none of the
|
|
152
|
+
`index.md`. As with every helper in this catalog, none of the five is
|
|
131
153
|
operable until its client.js has run — see each package's own
|
|
132
154
|
`docs/ssr.md`.
|
|
133
155
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lilydesignsystem/nunjucks-picker-bar",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": "=26"
|
|
6
6
|
},
|
|
7
|
-
"description": "Lily Design System Nunjucks picker bar: composes theme-picker, locale-picker, text-size-picker, and share-picker into one page-header row. Headless, SSR-safe, no CSS.",
|
|
7
|
+
"description": "Lily Design System Nunjucks picker bar: composes search-picker, theme-picker, locale-picker, text-size-picker, and share-picker into one page-header row. Headless, SSR-safe, no CSS.",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "./dist/index.js",
|
|
10
10
|
"module": "./dist/index.js",
|
|
@@ -25,10 +25,11 @@
|
|
|
25
25
|
"prepublishOnly": "cd .. && npm run build"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@lilydesignsystem/nunjucks-
|
|
29
|
-
"@lilydesignsystem/nunjucks-
|
|
30
|
-
"@lilydesignsystem/nunjucks-
|
|
31
|
-
"@lilydesignsystem/nunjucks-
|
|
28
|
+
"@lilydesignsystem/nunjucks-search-picker": "^0.1.0",
|
|
29
|
+
"@lilydesignsystem/nunjucks-theme-picker": "^0.2.0",
|
|
30
|
+
"@lilydesignsystem/nunjucks-locale-picker": "^0.2.0",
|
|
31
|
+
"@lilydesignsystem/nunjucks-text-size-picker": "^0.2.0",
|
|
32
|
+
"@lilydesignsystem/nunjucks-share-picker": "^0.2.0"
|
|
32
33
|
},
|
|
33
34
|
"keywords": [
|
|
34
35
|
"lily",
|
|
@@ -37,6 +38,7 @@
|
|
|
37
38
|
"nunjucks",
|
|
38
39
|
"picker",
|
|
39
40
|
"picker-bar",
|
|
41
|
+
"search",
|
|
40
42
|
"theme",
|
|
41
43
|
"locale",
|
|
42
44
|
"text-size",
|