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