maverick-wave-astro 1.36.0 → 1.37.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.
@@ -1,7 +1,10 @@
1
1
  ---
2
2
  // A quote with its source. featured stands above the grid, the rest go into
3
- // mw-columns-3. A date ages the quote - only where the voices stay fresh.
3
+ // mw-columns-3. A date ages the quote - only where the voices stay fresh. With
4
+ // `more` a long quote folds at a sentence end and the rest opens on a click;
5
+ // the featured one always stays whole.
4
6
  import { siteLocale } from '../dist/config.js';
7
+ import { cutAtSentence, slug } from '../dist/text.js';
5
8
 
6
9
  interface Props {
7
10
  quote: string;
@@ -11,6 +14,10 @@ interface Props {
11
14
  date?: string;
12
15
  locale?: string;
13
16
  featured?: boolean;
17
+ // The toggle's label - without it the quote stays whole
18
+ more?: string;
19
+ // The label once open; without it the toggle keeps saying `more`
20
+ less?: string;
14
21
  class?: string;
15
22
  }
16
23
 
@@ -21,6 +28,8 @@ const {
21
28
  date,
22
29
  locale = siteLocale,
23
30
  featured = false,
31
+ more,
32
+ less,
24
33
  class: className,
25
34
  } = Astro.props;
26
35
 
@@ -31,16 +40,50 @@ const dateText = date
31
40
  year: 'numeric',
32
41
  })
33
42
  : null;
43
+
44
+ const { preview, rest } =
45
+ more && !featured ? cutAtSentence(quote) : { preview: quote, rest: '' };
46
+ // Two voices with the same name tell apart by the length of what they said.
47
+ const bodyId = `quote-${slug(name)}-${quote.length}`;
34
48
  ---
35
49
 
36
50
  <figure
37
51
  class:list={[
38
52
  'mw-testimonial',
39
53
  featured && 'mw-testimonial-featured',
54
+ rest && 'mw-foldout',
40
55
  className,
41
56
  ]}
42
57
  >
43
- <blockquote>{quote}</blockquote>
58
+ <blockquote>
59
+ {preview}
60
+ {
61
+ rest && (
62
+ <div class="mw-foldout-body" id={bodyId}>
63
+ <div class="mw-foldout-body-inner">{rest}</div>
64
+ </div>
65
+ )
66
+ }
67
+ </blockquote>
68
+ {
69
+ rest && (
70
+ <button
71
+ type="button"
72
+ class="mw-link mw-foldout-toggle"
73
+ aria-expanded="false"
74
+ aria-controls={bodyId}
75
+ >
76
+ {less ? (
77
+ <>
78
+ <span class="mw-foldout-more">{more}</span>
79
+ <span class="mw-foldout-less">{less}</span>
80
+ </>
81
+ ) : (
82
+ more
83
+ )}
84
+ </button>
85
+ )
86
+ }
44
87
  <figcaption class="mw-testimonial-source">
45
88
  {name}{
46
89
  detail && (
package/dist/text.d.ts CHANGED
@@ -7,3 +7,11 @@ export declare const priceParts: (amount: number, locale: string) => {
7
7
  whole: string;
8
8
  fraction: string;
9
9
  };
10
+ export declare const cutAtSentence: (text: string, { from, to, leftover }?: {
11
+ from?: number | undefined;
12
+ to?: number | undefined;
13
+ leftover?: number | undefined;
14
+ }) => {
15
+ preview: string;
16
+ rest: string;
17
+ };
package/dist/text.js CHANGED
@@ -99,3 +99,17 @@ export const priceParts = (amount, locale) => {
99
99
  fraction: join(parts.slice(decimal)),
100
100
  };
101
101
  };
102
+ // The cut sits on a sentence end inside the window, so the preview reads as a
103
+ // whole thought and the fold-out starts a new one. Too little left over, and
104
+ // the text stays whole - a toggle for one line is not worth the click.
105
+ export const cutAtSentence = (text, { from = 140, to = 280, leftover = 80 } = {}) => {
106
+ let cut = 0;
107
+ for (const match of text.matchAll(/[.!?]["“”]?(?=\s)/g)) {
108
+ const end = match.index + match[0].length;
109
+ if (end >= from && end <= to)
110
+ cut = end;
111
+ }
112
+ if (!cut || text.length - cut < leftover)
113
+ return { preview: text, rest: '' };
114
+ return { preview: text.slice(0, cut), rest: text.slice(cut).trim() };
115
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maverick-wave-astro",
3
- "version": "1.36.0",
3
+ "version": "1.37.0",
4
4
  "description": "Shared frame for static Astro homepages built with MaverickWave: layout, SEO, design variants, schedule, building blocks.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -53,7 +53,7 @@
53
53
  },
54
54
  "peerDependencies": {
55
55
  "astro": "^7.2.0",
56
- "maverick-wave": "^6.21.0",
56
+ "maverick-wave": "^6.22.0",
57
57
  "vite": "^8.0.0"
58
58
  },
59
59
  "dependencies": {
@@ -69,7 +69,7 @@
69
69
  "eslint-plugin-astro": "^1.5.0",
70
70
  "eslint-plugin-simple-import-sort": "^12.1.1",
71
71
  "globals": "^16.5.0",
72
- "maverick-wave": "^6.21.0",
72
+ "maverick-wave": "^6.22.0",
73
73
  "playwright-core": "^1.64.0",
74
74
  "prettier": "^3.6.2",
75
75
  "prettier-plugin-astro": "^0.14.1",