@windstream/react-shared-components 0.2.88 → 0.2.90

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.
Files changed (29) hide show
  1. package/dist/contentful/index.d.ts +14 -0
  2. package/dist/contentful/index.esm.js +4 -4
  3. package/dist/contentful/index.esm.js.map +1 -1
  4. package/dist/contentful/index.js +4 -4
  5. package/dist/contentful/index.js.map +1 -1
  6. package/dist/index.d.ts +1 -1
  7. package/dist/utils/index.esm.js.map +1 -1
  8. package/dist/utils/index.js.map +1 -1
  9. package/package.json +1 -1
  10. package/src/contentful/blocks/anchored-bottom-banner/index.test.tsx +55 -0
  11. package/src/contentful/blocks/anchored-bottom-banner/index.tsx +15 -2
  12. package/src/contentful/blocks/anchored-bottom-banner/types.ts +5 -0
  13. package/src/contentful/blocks/award-marquee/index.test.tsx +75 -0
  14. package/src/contentful/blocks/award-marquee/index.tsx +40 -19
  15. package/src/contentful/blocks/award-marquee/types.ts +6 -0
  16. package/src/contentful/blocks/cart-retention-banner/index.test.tsx +63 -3
  17. package/src/contentful/blocks/cart-retention-banner/index.tsx +21 -8
  18. package/src/contentful/blocks/cart-retention-banner/types.ts +4 -0
  19. package/src/contentful/blocks/floating-banner/index.test.tsx +54 -2
  20. package/src/contentful/blocks/floating-banner/index.tsx +13 -2
  21. package/src/contentful/blocks/floating-banner/types.ts +6 -0
  22. package/src/contentful/blocks/image-promo-bar/index.test.tsx +176 -18
  23. package/src/contentful/blocks/image-promo-bar/index.tsx +45 -27
  24. package/src/contentful/blocks/image-promo-bar/types.ts +19 -1
  25. package/src/contentful/blocks/primary-hero/index.test.tsx +263 -4
  26. package/src/contentful/blocks/primary-hero/index.tsx +48 -4
  27. package/src/contentful/blocks/primary-hero/primary-hero.stories.tsx +22 -1
  28. package/src/utils/replace-tokens.test.ts +34 -0
  29. package/src/utils/replace-tokens.ts +4 -0
@@ -6,6 +6,27 @@ import { NextImage } from "@shared/components/next-image";
6
6
  import { Text } from "@shared/components/text";
7
7
  import { Button } from "@shared/contentful/blocks/button";
8
8
  import { cx } from "@shared/utils";
9
+ import { hasUnresolvedTokens } from "@shared/utils/replace-tokens";
10
+
11
+ const DECIMAL_PRICE_PATTERN = /^(\d[\d,]*)\.(\d+)$/;
12
+
13
+ const splitPrice = (price?: string, priceSuffix?: string) => {
14
+ const match = price ? DECIMAL_PRICE_PATTERN.exec(price.trim()) : null;
15
+ if (!match) return { dollars: price, cents: "", accessiblePrice: "" };
16
+ const [, dollars, cents] = match;
17
+ const suffix = priceSuffix?.trimStart() ?? "";
18
+ const suffixLeadsWithCents =
19
+ suffix.startsWith(cents) && !/^\d/.test(suffix.slice(cents.length));
20
+ const unit = suffixLeadsWithCents
21
+ ? suffix.slice(cents.length)
22
+ : (priceSuffix ?? "");
23
+ const unitSeparator = /^\d/.test(unit) ? " " : "";
24
+ return {
25
+ dollars,
26
+ cents: suffixLeadsWithCents ? "" : cents,
27
+ accessiblePrice: `$${dollars}.${cents}${unitSeparator}${unit}`,
28
+ };
29
+ };
9
30
 
10
31
  export const PrimaryHero: React.FC<PrimaryHeroProps> = props => {
11
32
  const {
@@ -59,6 +80,18 @@ export const PrimaryHero: React.FC<PrimaryHeroProps> = props => {
59
80
  const badgeImageUrl = normalizeImageUrl(badgeImage);
60
81
  const heroImageUrl = normalizeImageUrl(carouselImages?.[0]);
61
82
  const bottomLinkLabel = bottomLink?.buttonLabel ?? bottomLink?.label;
83
+ const {
84
+ dollars: priceDollars,
85
+ cents: priceCents,
86
+ accessiblePrice,
87
+ } = splitPrice(price, priceSuffix);
88
+ // An unresolved `${token}` (e.g. a missing token source) hides the lockup
89
+ // instead of rendering the raw placeholder.
90
+ const showPrice =
91
+ !!price &&
92
+ ![price, priceSuffix, priceCallout].some(value =>
93
+ hasUnresolvedTokens(value)
94
+ );
62
95
  const baseTextColorClass = textColor === "dark" ? "text-text" : "text-white";
63
96
  const textColorClass =
64
97
  hasDesktopVideo && textColor === "dark"
@@ -123,7 +156,7 @@ export const PrimaryHero: React.FC<PrimaryHeroProps> = props => {
123
156
  )}
124
157
 
125
158
  {/* price callout */}
126
- {price ? (
159
+ {showPrice ? (
127
160
  <div className="flex sm:justify-center sm:text-left lg:justify-start">
128
161
  <div className="mr-2 mt-0.5" {...fieldProps?.priceCallout}>
129
162
  {priceCallout
@@ -134,19 +167,30 @@ export const PrimaryHero: React.FC<PrimaryHeroProps> = props => {
134
167
  ))
135
168
  : null}
136
169
  </div>
137
- <div className="flex">
170
+ {accessiblePrice ? (
171
+ <Text as="p" className="sr-only">
172
+ {accessiblePrice}
173
+ </Text>
174
+ ) : null}
175
+ <div
176
+ className="flex"
177
+ aria-hidden={accessiblePrice ? true : undefined}
178
+ >
138
179
  <Text as="p" className="subheading1 mt-0.5">
139
180
  $
140
181
  </Text>
141
182
  <Text as="p" className="subheading5" {...fieldProps?.price}>
142
- {price}
183
+ {priceDollars}
143
184
  </Text>
144
- {priceSuffix ? (
185
+ {priceCents || priceSuffix ? (
145
186
  <Text
146
187
  as="p"
147
188
  className="subheading1 mt-0.5"
148
189
  {...fieldProps?.priceSuffix}
149
190
  >
191
+ {priceCents ? (
192
+ <span {...fieldProps?.price}>{priceCents}</span>
193
+ ) : null}
150
194
  {priceSuffix}
151
195
  </Text>
152
196
  ) : null}
@@ -45,7 +45,8 @@ const argTypes: ArgTypes<PrimaryHeroProps> = {
45
45
  },
46
46
  price: {
47
47
  control: { type: "text" as const },
48
- description: "Price value (e.g. '24')",
48
+ description:
49
+ "Price value (e.g. '24'). Decimal prices such as a resolved price token ('19.99') render the cents with the suffix, without repeating cents the suffix already starts with. The lockup is hidden while any price field still contains an unresolved `${token}`.",
49
50
  },
50
51
  priceSuffix: {
51
52
  control: { type: "text" as const },
@@ -324,3 +325,23 @@ export const BundleOffer: Story = {
324
325
  checklist: undefined,
325
326
  },
326
327
  };
328
+
329
+ /** Tokenized price: a resolved price token ("19.99") renders the same lockup as an authored "19" + "99/mo*". */
330
+ export const TokenizedPrice: Story = {
331
+ parameters: {
332
+ docs: {
333
+ description: {
334
+ story:
335
+ "When the Price field holds a price token (e.g. `${price_fiber_300}`) the consuming app resolves it with `replaceTokens` to a decimal value such as `19.99`. The dollars render large and the cents render with the suffix, matching production heroes authored as Price `19` + Price Suffix `99/mo*`.",
336
+ },
337
+ },
338
+ },
339
+ args: {
340
+ title: "switch and save this season",
341
+ subTitle: "Make it festive with fast 100% fiber from Kinetic.",
342
+ price: "19.99",
343
+ priceSuffix: "/mo*",
344
+ priceCallout: "fiber plans|start at ",
345
+ textColor: "dark",
346
+ },
347
+ };
@@ -1,4 +1,5 @@
1
1
  import {
2
+ hasUnresolvedTokens,
2
3
  replaceTokens,
3
4
  type RichTextDocument,
4
5
  type TokenEntry,
@@ -195,3 +196,36 @@ describe("replaceTokens - rich text", () => {
195
196
  expect((result.content[1] as any).content[0].value).toBe("50");
196
197
  });
197
198
  });
199
+
200
+ describe("hasUnresolvedTokens", () => {
201
+ it.each([
202
+ ["${price_tier3_2gig}", true],
203
+ ["From $${price_tier1_300mbps}/mo", true],
204
+ ["39.99", false],
205
+ ["plain text", false],
206
+ ["${}", false],
207
+ ["", false],
208
+ [null, false],
209
+ [undefined, false],
210
+ ])("returns %p -> %p", (input, expected) => {
211
+ expect(hasUnresolvedTokens(input)).toBe(expected);
212
+ });
213
+
214
+ it("is false once every token resolves and true for unknown tokens", () => {
215
+ expect(hasUnresolvedTokens(replaceTokens("${reward_50}", tokens))).toBe(
216
+ false
217
+ );
218
+ expect(hasUnresolvedTokens(replaceTokens("${not_a_token}", tokens))).toBe(
219
+ true
220
+ );
221
+ });
222
+
223
+ it("returns the same result on repeated calls", () => {
224
+ const value = "${price_tier1_300mbps}";
225
+ expect([1, 2, 3].map(() => hasUnresolvedTokens(value))).toEqual([
226
+ true,
227
+ true,
228
+ true,
229
+ ]);
230
+ });
231
+ });
@@ -15,6 +15,10 @@ export type RichTextDocument = {
15
15
  export type ReplaceTokensResult<T> = T extends string ? string : T;
16
16
 
17
17
  const TOKEN_PATTERN = /\$\{([^${}]+)\}/g;
18
+ const UNRESOLVED_TOKEN_PATTERN = new RegExp(TOKEN_PATTERN.source);
19
+
20
+ export const hasUnresolvedTokens = (input?: string | null): boolean =>
21
+ typeof input === "string" && UNRESOLVED_TOKEN_PATTERN.test(input);
18
22
 
19
23
  const normalizeEntries = (tokens: TokenSource): TokenEntry[] => {
20
24
  if (Array.isArray(tokens)) return tokens;