@revenuecat/purchases-ui-js 0.0.12 → 0.0.14

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 (36) hide show
  1. package/dist/components/button/Button.svelte +1 -1
  2. package/dist/components/button/ButtonNode.stories.svelte +1 -1
  3. package/dist/components/button/ButtonNode.svelte +9 -3
  4. package/dist/components/footer/Footer.svelte +3 -3
  5. package/dist/components/image/Image.svelte +6 -3
  6. package/dist/components/image/image-utils.js +1 -1
  7. package/dist/components/package/Package.svelte +23 -7
  8. package/dist/components/paywall/Node.svelte +20 -14
  9. package/dist/components/paywall/Node.svelte.d.ts +2 -2
  10. package/dist/components/paywall/Paywall.stories.svelte +96 -1
  11. package/dist/components/paywall/Paywall.svelte +14 -2
  12. package/dist/components/paywall/Paywall.svelte.d.ts +2 -0
  13. package/dist/components/purchase-button/PurchaseButton.svelte +9 -4
  14. package/dist/components/stack/Stack.svelte +10 -4
  15. package/dist/components/stack/stack-utils.d.ts +2 -1
  16. package/dist/components/stack/stack-utils.js +1 -1
  17. package/dist/components/text/Text.svelte +17 -27
  18. package/dist/components/text/Text.svelte.d.ts +7 -2
  19. package/dist/components/text/{Text.stories.svelte → TextNode.stories.svelte} +55 -3
  20. package/dist/components/text/{Text.stories.svelte.d.ts → TextNode.stories.svelte.d.ts} +4 -4
  21. package/dist/components/text/TextNode.svelte +46 -0
  22. package/dist/components/text/TextNode.svelte.d.ts +3 -0
  23. package/dist/components/text/text-utils.d.ts +3 -3
  24. package/dist/components/text/text-utils.js +2 -2
  25. package/dist/data/entities.d.ts +4 -1
  26. package/dist/data/state.d.ts +2 -0
  27. package/dist/index.d.ts +1 -0
  28. package/dist/index.js +1 -0
  29. package/dist/stories/fixtures.d.ts +3 -0
  30. package/dist/stories/fixtures.js +5331 -0
  31. package/dist/types.d.ts +8 -2
  32. package/dist/{utils.d.ts → utils/style-utils.d.ts} +14 -4
  33. package/dist/{utils.js → utils/style-utils.js} +33 -12
  34. package/dist/utils/variable-utils.d.ts +33 -0
  35. package/dist/utils/variable-utils.js +34 -0
  36. package/package.json +3 -2
@@ -23,7 +23,7 @@
23
23
  button {
24
24
  border: none;
25
25
  cursor: pointer;
26
- background-color: transparent;
26
+ background: transparent;
27
27
  padding: 0;
28
28
  width: 100%;
29
29
  display: flex;
@@ -2,7 +2,7 @@
2
2
  import { defineMeta } from "@storybook/addon-svelte-csf";
3
3
  import ButtonNode from "./ButtonNode.svelte";
4
4
  import { colorModeStoryMeta } from "../../stories/meta-templates";
5
- import type { SupportedActions, TextProps } from "../../data/entities";
5
+ import type { SupportedActions, TextNodeProps } from "../../data/entities";
6
6
 
7
7
  const onAction = (action: SupportedActions) => {
8
8
  alert(action.type);
@@ -3,13 +3,19 @@
3
3
  import type { ButtonNodeProps } from "../../data/entities";
4
4
  import Stack from "../stack/Stack.svelte";
5
5
 
6
- const { stack, action, labels, onAction, purchaseState }: ButtonNodeProps =
7
- $props();
6
+ const {
7
+ stack,
8
+ action,
9
+ onAction,
10
+ labels,
11
+ purchaseState,
12
+ variableDictionary,
13
+ }: ButtonNodeProps = $props();
8
14
  const onClick = () => {
9
15
  onAction && onAction(action);
10
16
  };
11
17
  </script>
12
18
 
13
19
  <Button onclick={onClick}>
14
- <Stack {...stack} {labels} {purchaseState} />
20
+ <Stack {...stack} {labels} {purchaseState} {variableDictionary} />
15
21
  </Button>
@@ -2,10 +2,10 @@
2
2
  import type { FooterProps } from "../../data/entities";
3
3
  import Stack from "../stack/Stack.svelte";
4
4
 
5
- const props: FooterProps = $props();
6
- const { stack, labels, id } = $derived(props);
5
+ const { stack, id, labels, purchaseState, variableDictionary }: FooterProps =
6
+ $props();
7
7
  </script>
8
8
 
9
9
  <div class="footer" {id}>
10
- <Stack {...stack} {labels} />
10
+ <Stack {...stack} {labels} {purchaseState} {variableDictionary} />
11
11
  </div>
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import { getImageComponentStyles } from "./image-utils";
3
- import { stringifyStyles } from "../../utils";
3
+ import { stringifyStyles } from "../../utils/style-utils";
4
4
  import type { ImageProps } from "../../data/entities";
5
5
 
6
6
  const { id, colorMode, source, ...restProps }: ImageProps = $props();
@@ -30,16 +30,19 @@
30
30
  border-radius: var(--corner-radius, unset);
31
31
  clip-path: var(--clip-path, unset);
32
32
  display: flex;
33
- flex: 1 0 auto;
33
+ flex: var(--flex, 1 0 auto);
34
34
  }
35
+
35
36
  .image {
36
37
  width: 100%;
37
38
  height: 100%;
38
39
  object-fit: cover;
40
+ display: block;
39
41
  }
42
+
40
43
  .image-overlay {
41
44
  position: absolute;
42
45
  inset: 0;
43
- background: var(--background, unset);
46
+ background: var(--background, none);
44
47
  }
45
48
  </style>
@@ -1,4 +1,4 @@
1
- import { getGradientStyle, getMaskStyle, getSizeStyle } from "../../utils";
1
+ import { getGradientStyle, getMaskStyle, getSizeStyle, } from "../../utils/style-utils";
2
2
  /**
3
3
  * Generates comprehensive styles for image components by combining gradient and size styles
4
4
  * @param props - Image component properties including gradient, mask and size
@@ -9,6 +9,7 @@
9
9
  id,
10
10
  onAction,
11
11
  purchaseState,
12
+ variableDictionary,
12
13
  }: PackageProps = $props();
13
14
 
14
15
  const onPackageClick = (evt: MouseEvent) => {
@@ -20,20 +21,35 @@
20
21
  });
21
22
  };
22
23
 
24
+ const packageVariables = $derived(
25
+ purchaseState.variablesPerPackage?.[package_id] || variableDictionary,
26
+ );
23
27
  const isSelected = $derived(purchaseState?.selectedPackageId === package_id);
24
28
  </script>
25
29
 
26
- <div class="package" class:selected={isSelected} {id} onclick={onPackageClick}>
27
- <Stack {...stack} {labels} {onAction} {purchaseState} />
28
- </div>
30
+ <button
31
+ class="package"
32
+ class:selected={isSelected}
33
+ {id}
34
+ onclick={onPackageClick}
35
+ >
36
+ <Stack
37
+ {...stack}
38
+ {labels}
39
+ {onAction}
40
+ {purchaseState}
41
+ variableDictionary={packageVariables}
42
+ />
43
+ </button>
29
44
 
30
45
  <style>
31
46
  .package {
32
47
  width: 100%;
33
48
  display: flex;
34
- cursor: pointer;
35
- }
36
-
37
- .selected {
49
+ margin: 0;
50
+ padding: 0;
51
+ background: unset;
52
+ border: unset;
53
+ text-align: unset;
38
54
  }
39
55
  </style>
@@ -1,13 +1,5 @@
1
1
  <script lang="ts">
2
- import {
3
- Stack,
4
- Text,
5
- Button,
6
- Image,
7
- PurchaseButton,
8
- Package,
9
- Footer,
10
- } from "../..";
2
+ import { Stack, Image, PurchaseButton, Package, Footer } from "../..";
11
3
  import Self from "./Node.svelte";
12
4
  import {
13
5
  type ActionsProps,
@@ -19,19 +11,26 @@
19
11
  } from "../../data/entities";
20
12
  import { prefersDarkMode } from "../../stores/theme";
21
13
  import ButtonNode from "../button/ButtonNode.svelte";
22
- import type { PurchaseState } from "../../data/state";
14
+ import TextNode from "../text/TextNode.svelte";
15
+ import type { VariableDictionary } from "../../utils/variable-utils";
23
16
 
24
17
  interface Props extends ActionsProps, PurchaseStateProps {
25
18
  nodeData: PaywallComponent;
26
19
  labels: ComponentLocalizations;
27
20
  onAction?: (action: SupportedActions, data?: Extra) => void;
28
- purchaseState?: PurchaseState;
21
+ variableDictionary?: VariableDictionary;
29
22
  }
30
23
 
31
- const { nodeData, labels, onAction, purchaseState }: Props = $props();
24
+ const {
25
+ nodeData,
26
+ labels,
27
+ onAction,
28
+ purchaseState,
29
+ variableDictionary,
30
+ }: Props = $props();
32
31
 
33
32
  const ComponentTypes = {
34
- text: Text,
33
+ text: TextNode,
35
34
  stack: Stack,
36
35
  image: Image,
37
36
  button: ButtonNode,
@@ -48,8 +47,15 @@
48
47
  prefersDarkMode={$prefersDarkMode}
49
48
  {onAction}
50
49
  {purchaseState}
50
+ {variableDictionary}
51
51
  >
52
52
  {#each nodeData.components as childData}
53
- <Self nodeData={childData} {labels} {onAction} {purchaseState} />
53
+ <Self
54
+ nodeData={childData}
55
+ {labels}
56
+ {onAction}
57
+ {purchaseState}
58
+ {variableDictionary}
59
+ />
54
60
  {/each}
55
61
  </MyComponent>
@@ -1,9 +1,9 @@
1
1
  import { type ActionsProps, type ComponentLocalizations, type Extra, type PaywallComponent, type PurchaseStateProps, type SupportedActions } from "../../data/entities";
2
- import type { PurchaseState } from "../../data/state";
2
+ import type { VariableDictionary } from "../../utils/variable-utils";
3
3
  declare const Node: import("svelte").Component<ActionsProps & PurchaseStateProps & {
4
4
  nodeData: PaywallComponent;
5
5
  labels: ComponentLocalizations;
6
6
  onAction?: (action: SupportedActions, data?: Extra) => void;
7
- purchaseState?: PurchaseState;
7
+ variableDictionary?: VariableDictionary;
8
8
  }, {}, "">;
9
9
  export default Node;
@@ -2,7 +2,15 @@
2
2
  import { defineMeta } from "@storybook/addon-svelte-csf";
3
3
 
4
4
  import Paywall from "./Paywall.svelte";
5
- import { paywallData } from "../../stories/fixtures";
5
+ import {
6
+ alignmentPaywallData,
7
+ calmPaywallData,
8
+ fontsPaywallData,
9
+ pastaPaywallData,
10
+ paywallData,
11
+ gradientPaywallData,
12
+ variablesPastaPaywallData,
13
+ } from "../../stories/fixtures";
6
14
  import { fn } from "@storybook/test";
7
15
 
8
16
  const { Story } = defineMeta({
@@ -37,3 +45,90 @@
37
45
  onRestorePurchasesClicked: fn(),
38
46
  }}
39
47
  />
48
+
49
+ <Story
50
+ name="Alignment paywall example"
51
+ args={{
52
+ paywallData: alignmentPaywallData,
53
+ selectedLocale: "en_US",
54
+ onPurchaseClicked: fn(),
55
+ onBackClicked: fn(),
56
+ onNavigateToClicked: fn(),
57
+ onRestorePurchasesClicked: fn(),
58
+ }}
59
+ />
60
+
61
+ <Story
62
+ name="Fonts paywall example"
63
+ args={{
64
+ paywallData: fontsPaywallData,
65
+ selectedLocale: "en_US",
66
+ onPurchaseClicked: fn(),
67
+ onBackClicked: fn(),
68
+ onNavigateToClicked: fn(),
69
+ onRestorePurchasesClicked: fn(),
70
+ }}
71
+ />
72
+
73
+ <Story
74
+ name="Pasta paywall example"
75
+ args={{
76
+ paywallData: pastaPaywallData,
77
+ selectedLocale: "en_US",
78
+ onPurchaseClicked: fn(),
79
+ onBackClicked: fn(),
80
+ onNavigateToClicked: fn(),
81
+ onRestorePurchasesClicked: fn(),
82
+ }}
83
+ />
84
+ <Story
85
+ name="Pasta paywall example(with variables)"
86
+ args={{
87
+ paywallData: variablesPastaPaywallData,
88
+ selectedLocale: "en_US",
89
+ onPurchaseClicked: fn(),
90
+ onBackClicked: fn(),
91
+ onNavigateToClicked: fn(),
92
+ onRestorePurchasesClicked: fn(),
93
+ variablesPerPackage: {
94
+ trial: {
95
+ product_name: "This was a variable: Product A",
96
+ price: "$19.99",
97
+ price_per_period: "$19.99/yr",
98
+ },
99
+ $rc_weekly: {
100
+ product_name: "This was a variable: Product B",
101
+ price: "$29.99",
102
+ price_per_period: "$29.99/yr",
103
+ },
104
+ $rc_daily: {
105
+ product_name: "This was a variable: Product C",
106
+ price: "$39.99",
107
+ price_per_period: "$39.99/yr",
108
+ },
109
+ },
110
+ }}
111
+ />
112
+
113
+ <Story
114
+ name="Calm paywall example"
115
+ args={{
116
+ paywallData: calmPaywallData,
117
+ selectedLocale: "en_US",
118
+ onPurchaseClicked: fn(),
119
+ onBackClicked: fn(),
120
+ onNavigateToClicked: fn(),
121
+ onRestorePurchasesClicked: fn(),
122
+ }}
123
+ />
124
+
125
+ <Story
126
+ name="Healthy Cat (Gradient)"
127
+ args={{
128
+ paywallData: gradientPaywallData,
129
+ onPurchaseClicked: fn(),
130
+ onBackClicked: fn(),
131
+ onNavigateToClicked: fn(),
132
+ onRestorePurchasesClicked: fn(),
133
+ }}
134
+ />
@@ -8,7 +8,8 @@
8
8
 
9
9
  import Node from "./Node.svelte";
10
10
  import type { PurchaseState } from "../../data/state";
11
- import { findSelectedPackageId, getLabelById } from "../../utils";
11
+ import { findSelectedPackageId, getLabelById } from "../../utils/style-utils";
12
+ import { type VariableDictionary } from "../../utils/variable-utils";
12
13
 
13
14
  interface Props {
14
15
  paywallData: PaywallData;
@@ -18,6 +19,7 @@
18
19
  onRestorePurchasesClicked?: () => void;
19
20
  onNavigateToUrlClicked?: (url: string) => void;
20
21
  selectedLocale?: string;
22
+ variablesPerPackage?: Record<string, VariableDictionary>;
21
23
  }
22
24
 
23
25
  const {
@@ -28,14 +30,20 @@
28
30
  onBackClicked,
29
31
  onVisitCustomerCenterClicked,
30
32
  selectedLocale,
33
+ variablesPerPackage = {},
31
34
  }: Props = $props();
32
35
 
33
36
  let purchaseState: PurchaseState = $state({
34
37
  selectedPackageId: findSelectedPackageId(paywallData),
35
38
  locale: selectedLocale || paywallData.default_locale,
36
39
  defaultLocale: paywallData.default_locale,
40
+ variablesPerPackage,
37
41
  });
38
42
 
43
+ let variableDictionary = $state(
44
+ variablesPerPackage[purchaseState.selectedPackageId || ""],
45
+ );
46
+
39
47
  const onRestorePurchasesAction = (_: SupportedActions, _2?: Extra) => {
40
48
  onRestorePurchasesClicked?.();
41
49
  };
@@ -68,6 +76,9 @@
68
76
 
69
77
  const onSelectPackageAction = (_: SupportedActions, data?: Extra) => {
70
78
  purchaseState.selectedPackageId = data?.packageId;
79
+ if (data?.packageId) {
80
+ variableDictionary = variablesPerPackage[data.packageId];
81
+ }
71
82
  };
72
83
 
73
84
  const onPurchaseAction = (_: SupportedActions, _2?: Extra) => {
@@ -98,12 +109,13 @@
98
109
  };
99
110
  </script>
100
111
 
101
- <div>
112
+ <div class="paywall">
102
113
  <Node
103
114
  {onAction}
104
115
  nodeData={paywallData.components_config.base.stack}
105
116
  labels={paywallData.components_localizations}
106
117
  {purchaseState}
118
+ {variableDictionary}
107
119
  />
108
120
  </div>
109
121
 
@@ -1,4 +1,5 @@
1
1
  import type { PaywallData } from "../../data/entities";
2
+ import { type VariableDictionary } from "../../utils/variable-utils";
2
3
  declare const Paywall: import("svelte").Component<{
3
4
  paywallData: PaywallData;
4
5
  onPurchaseClicked?: (selectedPackageId: string) => void;
@@ -7,5 +8,6 @@ declare const Paywall: import("svelte").Component<{
7
8
  onRestorePurchasesClicked?: () => void;
8
9
  onNavigateToUrlClicked?: (url: string) => void;
9
10
  selectedLocale?: string;
11
+ variablesPerPackage?: Record<string, VariableDictionary>;
10
12
  }, {}, "">;
11
13
  export default Paywall;
@@ -3,22 +3,27 @@
3
3
  import Stack from "../stack/Stack.svelte";
4
4
  import { Button } from "../../index";
5
5
 
6
- const { stack, labels, onAction, purchaseState }: PurchaseButtonProps =
7
- $props();
6
+ const {
7
+ stack,
8
+ labels,
9
+ onAction,
10
+ purchaseState,
11
+ variableDictionary,
12
+ }: PurchaseButtonProps = $props();
8
13
  const handleClick = () => {
9
14
  onAction && onAction({ type: "purchase" });
10
15
  };
11
16
  </script>
12
17
 
13
18
  <Button onclick={handleClick} class="purchase-button">
14
- <Stack {...stack} {labels} {purchaseState} />
19
+ <Stack {...stack} {labels} {purchaseState} {variableDictionary} />
15
20
  </Button>
16
21
 
17
22
  <style>
18
23
  .purchase-button {
19
24
  border: none;
20
25
  cursor: pointer;
21
- background-color: transparent;
26
+ background: transparent;
22
27
  padding: 0;
23
28
  width: 100%;
24
29
  display: flex;
@@ -2,7 +2,7 @@
2
2
  import type { StackProps } from "../../data/entities";
3
3
  import Node from "../paywall/Node.svelte";
4
4
  import { getStackComponentStyles } from "./stack-utils";
5
- import { stringifyStyles } from "../../utils";
5
+ import { stringifyStyles } from "../../utils/style-utils";
6
6
 
7
7
  const {
8
8
  id,
@@ -10,6 +10,7 @@
10
10
  labels,
11
11
  onAction,
12
12
  purchaseState,
13
+ variableDictionary,
13
14
  ...restProps
14
15
  }: StackProps = $props();
15
16
 
@@ -29,7 +30,13 @@
29
30
 
30
31
  <div {id} style={stackStyles} class="stack">
31
32
  {#each components as component}
32
- <Node nodeData={component} {labels} {onAction} {purchaseState} />
33
+ <Node
34
+ nodeData={component}
35
+ {labels}
36
+ {onAction}
37
+ {purchaseState}
38
+ {variableDictionary}
39
+ />
33
40
  {/each}
34
41
  </div>
35
42
 
@@ -41,7 +48,7 @@
41
48
  width: var(--width, unset);
42
49
  height: var(--height, unset);
43
50
  gap: var(--spacing, 0);
44
- background-color: var(--background-color, unset);
51
+ background: var(--background, none);
45
52
  border: var(--border, none);
46
53
  border-radius: var(--border-radius, 0);
47
54
  box-shadow: var(--shadow, none);
@@ -56,6 +63,5 @@
56
63
  margin-block-end: var(--margin-block-end, 0);
57
64
  margin-inline-start: var(--margin-inline-start, 0);
58
65
  flex: var(--flex, 0 1 auto);
59
- align-self: center;
60
66
  }
61
67
  </style>
@@ -1,5 +1,6 @@
1
1
  import type { StackProps } from "../../data/entities";
2
2
  type StackStyleVariables = {
3
+ "--flex": string;
3
4
  "--height": string;
4
5
  "--width": string;
5
6
  "--spacing": string;
@@ -14,7 +15,7 @@ type StackStyleVariables = {
14
15
  "--padding-inline-end": string;
15
16
  "--padding-block-end": string;
16
17
  "--padding-inline-start": string;
17
- "--background-color": string;
18
+ "--background": string;
18
19
  "--text-color": string;
19
20
  "--border": string;
20
21
  "--border-radius": string;
@@ -1,4 +1,4 @@
1
- import { getComponentStyles, getDimensionStyle, getSizeStyle, } from "../../utils";
1
+ import { getComponentStyles, getDimensionStyle, getSizeStyle, } from "../../utils/style-utils";
2
2
  /**
3
3
  * Generates comprehensive styles for stack components by combining component, dimension and size styles
4
4
  * @param props - Stack component properties including background, spacing, size, border etc.
@@ -1,38 +1,28 @@
1
1
  <script lang="ts">
2
- import { getTextComponentStyles } from "./text-utils";
3
- import type { TextProps } from "../../data/entities";
4
- import { getLabelById, stringifyStyles } from "../../utils";
2
+ import type { Snippet } from "svelte";
5
3
 
6
- const { id, labels, text_lid, purchaseState, ...restProps }: TextProps =
7
- $props();
8
-
9
- const { tagToRender, textStyles } = $derived(
10
- getTextComponentStyles({
11
- id,
12
- labels,
13
- text_lid,
14
- purchaseState,
15
- ...restProps,
16
- }),
17
- );
18
- const stylesString = $derived(stringifyStyles(textStyles));
4
+ interface TextProps {
5
+ component?: string;
6
+ styleVariables?: string;
7
+ id?: string;
8
+ children?: Snippet;
9
+ }
19
10
 
20
- const label = $derived(
21
- getLabelById(
22
- text_lid,
23
- purchaseState.locale,
24
- purchaseState.defaultLocale,
25
- labels,
26
- ),
27
- );
11
+ const {
12
+ children,
13
+ styleVariables = "",
14
+ component = "p",
15
+ id,
16
+ }: TextProps = $props();
28
17
  </script>
29
18
 
30
- <svelte:element this={tagToRender} {id} style={stylesString} class="text-block">
31
- {label}
19
+ <svelte:element this={component} {id} style={styleVariables} class="text-block">
20
+ {@render children?.()}
32
21
  </svelte:element>
33
22
 
34
23
  <style>
35
24
  .text-block {
25
+ display: block;
36
26
  padding-block-start: var(--padding-block-start, unset);
37
27
  padding-inline-end: var(--padding-inline-end, unset);
38
28
  padding-block-end: var(--padding-block-end, unset);
@@ -42,7 +32,7 @@
42
32
  margin-block-end: var(--margin-block-end, unset);
43
33
  margin-inline-start: var(--margin-inline-start, unset);
44
34
  color: var(--text-color, #ffffff);
45
- background-color: var(--background-color, #ffffff);
35
+ background: var(--background, none);
46
36
  font-size: var(--font-size, 1rem);
47
37
  font-weight: var(--font-weight, normal);
48
38
  text-align: var(--text-align, center);
@@ -1,3 +1,8 @@
1
- import type { TextProps } from "../../data/entities";
2
- declare const Text: import("svelte").Component<TextProps, {}, "">;
1
+ import type { Snippet } from "svelte";
2
+ declare const Text: import("svelte").Component<{
3
+ component?: string;
4
+ styleVariables?: string;
5
+ id?: string;
6
+ children?: Snippet;
7
+ }, {}, "">;
3
8
  export default Text;
@@ -1,6 +1,6 @@
1
1
  <script module lang="ts">
2
2
  import { defineMeta } from "@storybook/addon-svelte-csf";
3
- import Text from "./Text.svelte";
3
+ import TextNode from "./TextNode.svelte";
4
4
  import {
5
5
  colorModeStoryMeta,
6
6
  fontSizeStoryMeta,
@@ -12,12 +12,12 @@
12
12
  } from "../../stories/meta-templates";
13
13
 
14
14
  /*
15
- * Documentatino for this component can be found in https://www.notion.so/revenuecat/Text-e257cb046e104351861f8364ede617be?pvs=4
15
+ * Documentation for this component can be found in https://www.notion.so/revenuecat/Text-e257cb046e104351861f8364ede617be?pvs=4
16
16
  */
17
17
 
18
18
  const { Story } = defineMeta({
19
19
  title: "Components/Text",
20
- component: Text,
20
+ component: TextNode,
21
21
  tags: ["autodocs"],
22
22
  argTypes: {
23
23
  name: getTextControlStoryMeta("Content of the text to render"),
@@ -32,6 +32,11 @@
32
32
  horizontal_alignment: horizontalAlignmentStoryMeta,
33
33
  padding: getSpacingStoryMeta("Padding values in pixels"),
34
34
  margin: getSpacingStoryMeta("Margin values in pixels"),
35
+ variableDictionary: {
36
+ description: "Dictionary containing the values for the variables",
37
+ control: { type: "object" },
38
+ defaultValue: {},
39
+ },
35
40
  },
36
41
  args: {
37
42
  labels: { en_US: { lb123: "Test text" } },
@@ -46,6 +51,12 @@
46
51
  },
47
52
  },
48
53
  });
54
+
55
+ const mockVariableDictionary = {
56
+ product_name: "CatGPT",
57
+ price: "$39.99",
58
+ price_per_period: "$39.99/yr",
59
+ };
49
60
  </script>
50
61
 
51
62
  <!-- Default story -->
@@ -103,3 +114,44 @@
103
114
  name: "hello world!",
104
115
  }}
105
116
  />
117
+
118
+ <!-- Text with variable dictionary story -->
119
+ <Story
120
+ name="With variable dictionary"
121
+ args={{
122
+ font_weight: "regular",
123
+ text_style: "normal",
124
+ horizontal_alignment: "start",
125
+ padding: { top: 16, trailing: 24, bottom: 16, leading: 24 },
126
+ margin: { top: 8, trailing: 0, bottom: 8, leading: 0 },
127
+ name: "hello world!",
128
+ variableDictionary: mockVariableDictionary,
129
+ labels: {
130
+ en_US: {
131
+ lb123:
132
+ "This is a text that contains variables: {{ product_name }} for {{ price }} per {{ price_per_period }}",
133
+ },
134
+ },
135
+ text_lid: "lb123",
136
+ }}
137
+ />
138
+ <!-- Text with missing variable in dictionary story -->
139
+ <Story
140
+ name="With missing variable in dictionary"
141
+ args={{
142
+ font_weight: "regular",
143
+ text_style: "normal",
144
+ horizontal_alignment: "start",
145
+ padding: { top: 16, trailing: 24, bottom: 16, leading: 24 },
146
+ margin: { top: 8, trailing: 0, bottom: 8, leading: 0 },
147
+ name: "hello world!",
148
+ variableDictionary: mockVariableDictionary,
149
+ labels: {
150
+ en_US: {
151
+ lb123:
152
+ "This is a text with variables: {{ product_name }} for {{ price }} per {{ price_per_period }} and a missing variable: {{ sub_period_abbreviated }}",
153
+ },
154
+ },
155
+ text_lid: "lb123",
156
+ }}
157
+ />