@revenuecat/purchases-ui-js 2.0.0 → 2.0.1

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 (93) hide show
  1. package/dist/components/button/Button.svelte +1 -5
  2. package/dist/components/button/ButtonNode.stories.svelte +62 -70
  3. package/dist/components/button/ButtonNode.stories.svelte.d.ts +0 -8
  4. package/dist/components/button/ButtonNode.svelte +11 -19
  5. package/dist/components/button/ButtonNode.svelte.d.ts +2 -2
  6. package/dist/components/button/button-utils.d.ts +2 -2
  7. package/dist/components/footer/Footer.stories.svelte +30 -22
  8. package/dist/components/footer/Footer.stories.svelte.d.ts +0 -5
  9. package/dist/components/footer/Footer.svelte +3 -10
  10. package/dist/components/footer/Footer.svelte.d.ts +1 -1
  11. package/dist/components/image/Image.stories.svelte +26 -7
  12. package/dist/components/image/Image.svelte +17 -15
  13. package/dist/components/image/image-utils.d.ts +2 -1
  14. package/dist/components/image/image-utils.js +2 -2
  15. package/dist/components/package/Package.stories.svelte +31 -27
  16. package/dist/components/package/Package.stories.svelte.d.ts +0 -6
  17. package/dist/components/package/Package.svelte +18 -22
  18. package/dist/components/package/Package.svelte.d.ts +1 -1
  19. package/dist/components/paywall/Node.svelte +12 -39
  20. package/dist/components/paywall/Node.svelte.d.ts +4 -8
  21. package/dist/components/paywall/Paywall.stories.svelte +21 -78
  22. package/dist/components/paywall/Paywall.svelte +71 -98
  23. package/dist/components/paywall/Paywall.svelte.d.ts +4 -4
  24. package/dist/components/paywall/paywall-utils.d.ts +3 -2
  25. package/dist/components/paywall/paywall-utils.js +5 -5
  26. package/dist/components/purchase-button/PurchaseButton.stories.svelte +32 -26
  27. package/dist/components/purchase-button/PurchaseButton.stories.svelte.d.ts +0 -5
  28. package/dist/components/purchase-button/PurchaseButton.svelte +7 -11
  29. package/dist/components/purchase-button/PurchaseButton.svelte.d.ts +1 -1
  30. package/dist/components/purchase-button/purchase-button-utils.d.ts +1 -1
  31. package/dist/components/stack/Stack.stories.svelte +34 -79
  32. package/dist/components/stack/Stack.svelte +15 -25
  33. package/dist/components/stack/stack-utils.d.ts +4 -3
  34. package/dist/components/stack/stack-utils.js +7 -8
  35. package/dist/components/text/TextNode.stories.svelte +46 -141
  36. package/dist/components/text/TextNode.svelte +13 -12
  37. package/dist/components/text/text-utils.d.ts +7 -6
  38. package/dist/components/text/text-utils.js +7 -7
  39. package/dist/components/timeline/Timeline.stories.svelte +41 -47
  40. package/dist/components/timeline/TimelineItem.svelte +28 -11
  41. package/dist/components/timeline/timeline-utils.d.ts +3 -3
  42. package/dist/components/timeline/timeline-utils.js +7 -16
  43. package/dist/data/entities.d.ts +59 -120
  44. package/dist/data/state.d.ts +0 -5
  45. package/dist/stores/color-mode.d.ts +6 -0
  46. package/dist/stores/color-mode.js +15 -0
  47. package/dist/stores/localization.d.ts +13 -0
  48. package/dist/stores/localization.js +25 -0
  49. package/dist/stores/paywall.d.ts +10 -0
  50. package/dist/stores/paywall.js +13 -0
  51. package/dist/stores/variables.d.ts +6 -0
  52. package/dist/stores/variables.js +14 -0
  53. package/dist/stories/fixtures.js +7 -76
  54. package/dist/stories/localization-decorator.d.ts +3 -0
  55. package/dist/stories/localization-decorator.js +7 -0
  56. package/dist/stories/paywall-decorator.d.ts +2 -0
  57. package/dist/stories/paywall-decorator.js +18 -0
  58. package/dist/stories/variables-decorator.d.ts +3 -0
  59. package/dist/stories/variables-decorator.js +9 -0
  60. package/dist/stories/with-layout.svelte +1 -1
  61. package/dist/types/alignment.d.ts +19 -0
  62. package/dist/types/alignment.js +1 -0
  63. package/dist/types/background.d.ts +18 -0
  64. package/dist/types/background.js +1 -0
  65. package/dist/types/colors.d.ts +34 -0
  66. package/dist/types/colors.js +1 -0
  67. package/dist/types/components/button.d.ts +36 -0
  68. package/dist/types/components/button.js +1 -0
  69. package/dist/types/components/footer.d.ts +5 -0
  70. package/dist/types/components/footer.js +1 -0
  71. package/dist/types/components/package.d.ts +8 -0
  72. package/dist/types/components/package.js +1 -0
  73. package/dist/types/components/purchase-button.d.ts +5 -0
  74. package/dist/types/components/purchase-button.js +1 -0
  75. package/dist/types/localization.d.ts +4 -0
  76. package/dist/types/localization.js +1 -0
  77. package/dist/types/media.d.ts +18 -0
  78. package/dist/types/media.js +1 -0
  79. package/dist/types.d.ts +5 -35
  80. package/dist/ui/atoms/typography.stories.svelte +8 -14
  81. package/dist/ui/atoms/typography.svelte +1 -1
  82. package/dist/ui/molecules/button.stories.svelte +8 -15
  83. package/dist/ui/molecules/button.svelte +2 -1
  84. package/dist/ui/molecules/button.svelte.d.ts +2 -26
  85. package/dist/ui/molecules/types.d.ts +2 -1
  86. package/dist/utils/style-utils.d.ts +13 -11
  87. package/dist/utils/style-utils.js +8 -15
  88. package/dist/utils/variable-utils.d.ts +1 -38
  89. package/dist/utils/variable-utils.js +6 -48
  90. package/dist/web-components/index.js +519 -566
  91. package/package.json +33 -36
  92. package/dist/stores/theme.d.ts +0 -1
  93. package/dist/stores/theme.js +0 -17
@@ -1,6 +1,6 @@
1
1
  <script module lang="ts">
2
- import { defineMeta } from "@storybook/addon-svelte-csf";
3
2
  import TextNode from "./TextNode.svelte";
3
+ import { localizationDecorator } from "../../stories/localization-decorator";
4
4
  import {
5
5
  fontSizeStoryMeta,
6
6
  fontWeightStoryMeta,
@@ -9,17 +9,39 @@
9
9
  getTextControlStoryMeta,
10
10
  horizontalAlignmentStoryMeta,
11
11
  } from "../../stories/meta-templates";
12
+ import { variablesDecorator } from "../../stories/variables-decorator";
13
+ import type { Localizations } from "../../types/localization";
12
14
  import type { VariableDictionary } from "../../utils/variable-utils";
13
- import { DEFAULT_COLOR_MODE, DEFAULT_TEXT_COLOR } from "../../utils/constants";
15
+ import { defineMeta } from "@storybook/addon-svelte-csf";
14
16
 
15
17
  /*
16
18
  * Documentation for this component can be found in https://www.notion.so/revenuecat/Text-e257cb046e104351861f8364ede617be?pvs=4
17
19
  */
18
20
 
21
+ const defaultLocale = "en_US";
22
+ const text_lid = "lb123";
23
+
19
24
  const { Story } = defineMeta({
20
25
  title: "Components/Text",
21
26
  component: TextNode,
22
27
  tags: ["autodocs"],
28
+ decorators: [
29
+ (Story, context) => {
30
+ const localizations = context.parameters.localizations as Localizations;
31
+ return localizationDecorator({
32
+ defaultLocale: Object.keys(localizations)[0],
33
+ localizations,
34
+ })(Story, context);
35
+ },
36
+ ],
37
+ args: {
38
+ text_lid,
39
+ size: {
40
+ width: { type: "fill" },
41
+ height: { type: "fill" },
42
+ },
43
+ purchaseState: {},
44
+ },
23
45
  argTypes: {
24
46
  name: getTextControlStoryMeta("Content of the text to render"),
25
47
  font_name: getTextControlStoryMeta(
@@ -38,23 +60,13 @@
38
60
  defaultValue: {},
39
61
  },
40
62
  },
41
- args: {
42
- labels: {
43
- en_US: {
44
- lb123:
63
+ parameters: {
64
+ localizations: {
65
+ [defaultLocale]: {
66
+ [text_lid]:
45
67
  "Do not allow people to dim your shine because they are blinded. Tell them to put some sunglasses on.",
46
68
  },
47
- },
48
- text_lid: "lb123",
49
- size: {
50
- width: { type: "fill" },
51
- height: { type: "fill" },
52
- },
53
- purchaseState: {
54
- locale: "en_US",
55
- defaultLocale: "en_US",
56
- colorMode: DEFAULT_COLOR_MODE,
57
- },
69
+ } satisfies Localizations,
58
70
  },
59
71
  });
60
72
 
@@ -62,7 +74,7 @@
62
74
  product_name: "CatGPT",
63
75
  price: "$39.99",
64
76
  price_per_period: "$39.99/yr",
65
- };
77
+ } as VariableDictionary;
66
78
  </script>
67
79
 
68
80
  <!-- Default story -->
@@ -109,117 +121,6 @@
109
121
  }}
110
122
  />
111
123
 
112
- <!-- Linear Gradient Color text story -->
113
- <Story
114
- name="LinearGradientColor"
115
- args={{
116
- font_weight: "regular",
117
- text_style: "normal",
118
- horizontal_alignment: "leading",
119
- size: { width: { type: "fixed", value: 200 }, height: { type: "fit" } },
120
- padding: { top: 20, trailing: 20, bottom: 20, leading: 20 },
121
- color: {
122
- dark: {
123
- degrees: 90,
124
- points: [
125
- {
126
- color: "#9f009f",
127
- percent: 100,
128
- },
129
- {
130
- color: "#090979ff",
131
- percent: 35,
132
- },
133
- {
134
- color: "#53d6ec",
135
- percent: 0,
136
- },
137
- ],
138
- type: "linear",
139
- },
140
- light: {
141
- degrees: 45,
142
- points: [
143
- {
144
- color: "#9f009f",
145
- percent: 0,
146
- },
147
- {
148
- color: "#090979ff",
149
- percent: 50,
150
- },
151
-
152
- {
153
- color: "#53d6ec",
154
- percent: 100,
155
- },
156
- ],
157
- type: "linear",
158
- },
159
- },
160
- background_color: {
161
- dark: { type: "hex", value: DEFAULT_TEXT_COLOR },
162
- light: { type: "hex", value: DEFAULT_TEXT_COLOR },
163
- },
164
- name: "hello world!",
165
- }}
166
- />
167
-
168
- <!-- Radial Gradient Color text story -->
169
- <Story
170
- name="RadialGradientColor"
171
- args={{
172
- font_weight: "regular",
173
- text_style: "normal",
174
- horizontal_alignment: "leading",
175
- size: { width: { type: "fixed", value: 200 }, height: { type: "fit" } },
176
- padding: { top: 20, trailing: 20, bottom: 20, leading: 20 },
177
- color: {
178
- dark: {
179
- degrees: 90,
180
- points: [
181
- {
182
- color: "#9f009f",
183
- percent: 100,
184
- },
185
- {
186
- color: "#090979ff",
187
- percent: 35,
188
- },
189
- {
190
- color: "#53d6ec",
191
- percent: 0,
192
- },
193
- ],
194
- type: "radial",
195
- },
196
- light: {
197
- points: [
198
- {
199
- color: "#53d6ec",
200
- percent: 0,
201
- },
202
- {
203
- color: "#090979ff",
204
- percent: 30,
205
- },
206
-
207
- {
208
- color: "#9f009f",
209
- percent: 50,
210
- },
211
- ],
212
- type: "radial",
213
- },
214
- },
215
- background_color: {
216
- dark: { type: "hex", value: DEFAULT_TEXT_COLOR },
217
- light: { type: "hex", value: DEFAULT_TEXT_COLOR },
218
- },
219
- name: "hello world!",
220
- }}
221
- />
222
-
223
124
  <!-- Text with spacing story -->
224
125
  <Story
225
126
  name="With Spacing"
@@ -243,14 +144,16 @@
243
144
  padding: { top: 16, trailing: 24, bottom: 16, leading: 24 },
244
145
  margin: { top: 8, trailing: 0, bottom: 8, leading: 0 },
245
146
  name: "hello world!",
246
- variableDictionary: mockVariableDictionary as VariableDictionary,
247
- labels: {
248
- en_US: {
249
- lb123:
147
+ text_lid,
148
+ }}
149
+ decorators={[variablesDecorator(mockVariableDictionary)]}
150
+ parameters={{
151
+ localizations: {
152
+ [defaultLocale]: {
153
+ [text_lid]:
250
154
  "This is a text that contains variables: {{ product_name }} for {{ price }} per {{ price_per_period }}",
251
155
  },
252
- },
253
- text_lid: "lb123",
156
+ } satisfies Localizations,
254
157
  }}
255
158
  />
256
159
  <!-- Text with missing variable in dictionary story -->
@@ -263,13 +166,15 @@
263
166
  padding: { top: 16, trailing: 24, bottom: 16, leading: 24 },
264
167
  margin: { top: 8, trailing: 0, bottom: 8, leading: 0 },
265
168
  name: "hello world!",
266
- variableDictionary: mockVariableDictionary as VariableDictionary,
267
- labels: {
268
- en_US: {
269
- lb123:
169
+ text_lid,
170
+ }}
171
+ decorators={[variablesDecorator(mockVariableDictionary)]}
172
+ parameters={{
173
+ localizations: {
174
+ [defaultLocale]: {
175
+ [text_lid]:
270
176
  "This is a text with variables: {{ product_name }} for {{ price }} per {{ price_per_period }} and a missing variable: {{ sub_period_abbreviated }}",
271
177
  },
272
- },
273
- text_lid: "lb123",
178
+ } satisfies Localizations,
274
179
  }}
275
180
  />
@@ -6,21 +6,26 @@
6
6
  } from "./text-utils";
7
7
  import Text from "./Text.svelte";
8
8
  import type { TextNodeProps } from "../../data/entities";
9
- import { getLabelAndReplaceVariables } from "../../utils/variable-utils";
9
+ import { getColorModeContext } from "../../stores/color-mode";
10
+ import { getLocalizationContext } from "../../stores/localization";
11
+ import { getVariablesContext } from "../../stores/variables";
12
+ import { replaceVariables } from "../../utils/variable-utils";
10
13
 
11
14
  const {
12
15
  id,
13
16
  labels,
14
17
  text_lid,
15
18
  purchaseState,
16
- variableDictionary,
17
19
  background_color,
18
20
  size,
19
21
  ...restProps
20
22
  }: TextNodeProps = $props();
21
23
 
24
+ const getColorMode = getColorModeContext();
25
+ const colorMode = $derived(getColorMode());
26
+
22
27
  const { tagToRender, textStyles } = $derived(
23
- getTextNodeStyles({
28
+ getTextNodeStyles(colorMode, {
24
29
  id,
25
30
  labels,
26
31
  text_lid,
@@ -35,16 +40,12 @@
35
40
  getTextWrapperStyles(restProps, size, background_color),
36
41
  );
37
42
 
38
- const parsedLabel = $derived(
39
- getLabelAndReplaceVariables({
40
- text_lid,
41
- locale: purchaseState.locale,
42
- defaultLocale: purchaseState.defaultLocale,
43
- labels,
44
- variableDictionary,
45
- }),
43
+ const variables = getVariablesContext();
44
+ const { getLocalizedString } = getLocalizationContext();
45
+ const label = $derived(
46
+ replaceVariables(getLocalizedString(text_lid), $variables),
46
47
  );
47
- const markdownParsed = $derived(getHtmlFromMarkdown(parsedLabel));
48
+ const markdownParsed = $derived(getHtmlFromMarkdown(label));
48
49
  </script>
49
50
 
50
51
  <span style={wrapperStyles} class="rc-pw-text-wrapper">
@@ -1,18 +1,19 @@
1
1
  import type { TextNodeProps } from "../../data/entities";
2
- import type { ColorType, SizeType } from "../../types";
3
- export declare const defaultColor: ColorType;
4
- export declare const defaultBackgroundColor: ColorType;
2
+ import type { ColorMode, SizeType } from "../../types";
3
+ import type { ColorGradientScheme, ColorScheme } from "../../types/colors";
4
+ export declare const defaultColor: ColorScheme;
5
+ export declare const defaultBackgroundColor: ColorGradientScheme;
5
6
  /**
6
7
  * Generates comprehensive styles for text components by combining text, component and size styles
7
8
  * @param props - Text component properties including font, color, background, spacing etc.
8
9
  * @returns Object containing text style variables and the appropriate HTML tag to render
9
10
  */
10
- export declare const getTextComponentStyles: (props: TextNodeProps) => {
11
+ export declare const getTextComponentStyles: (colorMode: ColorMode, props: TextNodeProps) => {
11
12
  textStyles: Record<string, string | number>;
12
13
  tagToRender: import("../../utils/style-utils").TextComponentTags;
13
14
  };
14
- export declare function getTextWrapperStyles(restProps: Partial<TextNodeProps>, size: SizeType, background_color?: ColorType): string;
15
- export declare function getTextNodeStyles(props: TextNodeProps): {
15
+ export declare function getTextWrapperStyles(restProps: Partial<TextNodeProps>, size: SizeType, background_color?: ColorGradientScheme): string;
16
+ export declare function getTextNodeStyles(colorMode: ColorMode, props: TextNodeProps): {
16
17
  tagToRender: import("../../utils/style-utils").TextComponentTags;
17
18
  textStyles: string;
18
19
  };
@@ -1,5 +1,5 @@
1
- import { getActiveStateProps, getComponentStyles, getSizeStyle, getTextComponentTag, getTextStyles, prefixObject, stringifyStyles, } from "../../utils/style-utils";
2
1
  import { DEFAULT_BACKGROUND_COLOR, DEFAULT_TEXT_COLOR, } from "../../utils/constants";
2
+ import { getActiveStateProps, getComponentStyles, getSizeStyle, getTextComponentTag, getTextStyles, prefixObject, stringifyStyles, } from "../../utils/style-utils";
3
3
  export const defaultColor = {
4
4
  light: { type: "hex", value: DEFAULT_TEXT_COLOR },
5
5
  };
@@ -11,8 +11,8 @@ export const defaultBackgroundColor = {
11
11
  * @param props - Text component properties including font, color, background, spacing etc.
12
12
  * @returns Object containing text style variables and the appropriate HTML tag to render
13
13
  */
14
- export const getTextComponentStyles = (props) => {
15
- const { font_size = "body_m", color = defaultColor, background_color = defaultBackgroundColor, padding, margin, size, purchaseState, } = props;
14
+ export const getTextComponentStyles = (colorMode, props) => {
15
+ const { font_size = "body_m", color = defaultColor, background_color = defaultBackgroundColor, padding, margin, size, } = props;
16
16
  const styles = {
17
17
  "--width": "unset",
18
18
  "--height": "unset",
@@ -42,13 +42,13 @@ export const getTextComponentStyles = (props) => {
42
42
  };
43
43
  const activeStateProps = getActiveStateProps(props.overrides, props.componentState);
44
44
  const tagToRender = getTextComponentTag(font_size);
45
- const textStyles = getTextStyles({ ...props, ...activeStateProps }, purchaseState.colorMode);
45
+ const textStyles = getTextStyles({ ...props, ...activeStateProps });
46
46
  const componentStyles = getComponentStyles({
47
47
  background_color,
48
48
  color,
49
49
  margin,
50
50
  padding,
51
- colorMode: purchaseState.colorMode,
51
+ colorMode,
52
52
  ...activeStateProps,
53
53
  });
54
54
  const sizeStyles = getSizeStyle({ ...size, ...activeStateProps });
@@ -96,7 +96,7 @@ export function getTextWrapperStyles(restProps, size, background_color) {
96
96
  const prefixedStyles = prefixObject(styles, "text");
97
97
  return stringifyStyles(prefixedStyles);
98
98
  }
99
- export function getTextNodeStyles(props) {
99
+ export function getTextNodeStyles(colorMode, props) {
100
100
  const styles = {
101
101
  "--text-margin-block-start": "0px",
102
102
  "--text-margin-inline-end": "0px",
@@ -124,7 +124,7 @@ export function getTextNodeStyles(props) {
124
124
  "--text-height": "unset",
125
125
  "--text-flex": "0 1 auto",
126
126
  };
127
- const { tagToRender, textStyles } = getTextComponentStyles(props);
127
+ const { tagToRender, textStyles } = getTextComponentStyles(colorMode, props);
128
128
  Object.assign(styles, textStyles);
129
129
  return { tagToRender, textStyles: stringifyStyles(styles) };
130
130
  }
@@ -1,48 +1,50 @@
1
1
  <script module lang="ts">
2
- import { defineMeta } from "@storybook/addon-svelte-csf";
3
2
  import { Timeline } from "../..";
4
- import type { PurchaseState } from "../../data/state";
5
3
  import { defaultColor } from "../text/text-utils";
6
- import { type TimelineProps } from "../../data/entities";
7
- import { DEFAULT_COLOR_MODE } from "../../utils/constants";
4
+ import type { PurchaseState } from "../../data/state";
5
+ import { localizationDecorator } from "../../stories/localization-decorator";
6
+ import { defineMeta } from "@storybook/addon-svelte-csf";
7
+
8
+ const defaultLocale = "en_US";
9
+
10
+ const purchaseState: PurchaseState = {};
8
11
 
9
12
  const { Story } = defineMeta({
10
13
  title: "Components/Timeline",
11
14
  component: Timeline,
12
15
  tags: ["autodocs"],
16
+ decorators: [
17
+ localizationDecorator({
18
+ defaultLocale,
19
+ localizations: {
20
+ [defaultLocale]: {
21
+ asd123: "Item 1",
22
+ asd123d: "description 1",
23
+ qwe123: "Item 2",
24
+ qwe123d: "description 2",
25
+ zxc123: "Item 3",
26
+ zxc123d: "description 3",
27
+ rty123: "Item 4",
28
+ rty123d: "description 4",
29
+ fgh123: "Item 5",
30
+ fgh123d: "description 5",
31
+ case1: "Case 1",
32
+ case1d: "No spacing between connector and item",
33
+ case2: "Case 2",
34
+ case2d: "Spacing between connector and item",
35
+ case3: "Case 3",
36
+ case3d: "Spacing at bottom of connector",
37
+ case4: "Case 4",
38
+ case4d: "Spacing at top of connector",
39
+ case5: "Case 5",
40
+ case5d: "No Connector",
41
+ },
42
+ },
43
+ }),
44
+ ],
45
+ args: { purchaseState },
13
46
  argTypes: {},
14
47
  });
15
-
16
- const purchaseState: PurchaseState = {
17
- locale: "en_US",
18
- defaultLocale: "en_US",
19
- colorMode: DEFAULT_COLOR_MODE,
20
- };
21
-
22
- const labels = {
23
- en_US: {
24
- asd123: "Item 1",
25
- asd123d: "description 1",
26
- qwe123: "Item 2",
27
- qwe123d: "description 2",
28
- zxc123: "Item 3",
29
- zxc123d: "description 3",
30
- rty123: "Item 4",
31
- rty123d: "description 4",
32
- fgh123: "Item 5",
33
- fgh123d: "description 5",
34
- case1: "Case 1",
35
- case1d: "No spacing between connector and item",
36
- case2: "Case 2",
37
- case2d: "Spacing between connector and item",
38
- case3: "Case 3",
39
- case3d: "Spacing at bottom of connector",
40
- case4: "Case 4",
41
- case4d: "Spacing at top of connector",
42
- case5: "Case 5",
43
- case5d: "No Connector",
44
- },
45
- };
46
48
  </script>
47
49
 
48
50
  <!-- Timeline -->
@@ -50,8 +52,6 @@
50
52
  name="Round icon"
51
53
  args={{
52
54
  type: "timeline",
53
- labels,
54
- purchaseState,
55
55
  item_spacing: 32,
56
56
  text_spacing: 16,
57
57
  size: { width: { type: "fill" }, height: { type: "fit" } },
@@ -157,15 +157,13 @@
157
157
  },
158
158
  },
159
159
  ],
160
- } satisfies TimelineProps}
160
+ }}
161
161
  />
162
162
 
163
163
  <Story
164
164
  name="Square icon"
165
165
  args={{
166
166
  type: "timeline",
167
- labels,
168
- purchaseState,
169
167
  item_spacing: 32,
170
168
  text_spacing: 16,
171
169
  size: { width: { type: "fill" }, height: { type: "fit" } },
@@ -295,14 +293,12 @@
295
293
  },
296
294
  },
297
295
  ],
298
- } satisfies TimelineProps}
296
+ }}
299
297
  />
300
298
  <Story
301
299
  name="With connector"
302
300
  args={{
303
301
  type: "timeline",
304
- labels,
305
- purchaseState,
306
302
  item_spacing: 32,
307
303
  text_spacing: 16,
308
304
  size: { width: { type: "fill" }, height: { type: "fit" } },
@@ -439,15 +435,13 @@
439
435
  },
440
436
  },
441
437
  ],
442
- } satisfies TimelineProps}
438
+ }}
443
439
  />
444
440
 
445
441
  <Story
446
442
  name="Connector possibilities"
447
443
  args={{
448
444
  type: "timeline",
449
- labels,
450
- purchaseState,
451
445
  item_spacing: 64,
452
446
  text_spacing: 8,
453
447
  size: { width: { type: "fill" }, height: { type: "fit" } },
@@ -637,5 +631,5 @@
637
631
  },
638
632
  },
639
633
  ],
640
- } satisfies TimelineProps}
634
+ }}
641
635
  />
@@ -4,21 +4,38 @@
4
4
  getTimelineItemTextStyles,
5
5
  } from "./timeline-utils";
6
6
  import type { TimelineItemProps } from "../../data/entities";
7
+ import { getColorModeContext } from "../../stores/color-mode";
8
+ import { getLocalizationContext } from "../../stores/localization";
9
+ import { getVariablesContext } from "../../stores/variables";
10
+ import { replaceVariables } from "../../utils/variable-utils";
7
11
 
8
12
  const props: TimelineItemProps = $props();
9
- const styles = $derived(getTimelineItemStyles(props));
10
13
 
11
- const {
12
- tagToRender: titleTagToRender,
13
- textStyles: titleStyles,
14
- textLabel: titleLabel,
15
- } = $derived(getTimelineItemTextStyles(props, "title"));
14
+ const getColorMode = getColorModeContext();
15
+ const colorMode = $derived(getColorMode());
16
16
 
17
- const {
18
- tagToRender: descriptionTagToRender,
19
- textStyles: descriptionStyles,
20
- textLabel: descriptionLabel,
21
- } = $derived(getTimelineItemTextStyles(props, "description"));
17
+ const styles = $derived(getTimelineItemStyles(colorMode, props));
18
+
19
+ const { getLocalizedString } = getLocalizationContext();
20
+
21
+ const variables = getVariablesContext();
22
+ const titleLabel = $derived(
23
+ replaceVariables(getLocalizedString(props.title.text_lid), $variables),
24
+ );
25
+
26
+ const descriptionLabel = $derived(
27
+ replaceVariables(
28
+ getLocalizedString(props.description?.text_lid),
29
+ $variables,
30
+ ),
31
+ );
32
+
33
+ const { tagToRender: titleTagToRender, textStyles: titleStyles } = $derived(
34
+ getTimelineItemTextStyles(colorMode, props, "title"),
35
+ );
36
+
37
+ const { tagToRender: descriptionTagToRender, textStyles: descriptionStyles } =
38
+ $derived(getTimelineItemTextStyles(colorMode, props, "description"));
22
39
  // TODO: Object mapping icon name to icon component
23
40
  </script>
24
41
 
@@ -1,8 +1,8 @@
1
1
  import type { TimelineItemProps, TimelineProps } from "../../data/entities";
2
+ import type { ColorMode } from "../../types";
2
3
  export declare function getTimelineStyles(props: TimelineProps): string;
3
- export declare function getTimelineItemStyles(props: TimelineItemProps): string;
4
- export declare function getTimelineItemTextStyles(props: TimelineItemProps, kind?: "title" | "description"): {
4
+ export declare function getTimelineItemStyles(colorMode: ColorMode, props: TimelineItemProps): string;
5
+ export declare function getTimelineItemTextStyles(colorMode: ColorMode, props: TimelineItemProps, kind?: "title" | "description"): {
5
6
  textStyles: string;
6
7
  tagToRender: import("../../utils/style-utils").TextComponentTags;
7
- textLabel: string | undefined;
8
8
  };
@@ -1,6 +1,5 @@
1
1
  import { defaultColor, getTextComponentStyles, } from "../text/text-utils";
2
2
  import { getBorderStyle, getColor, getCornerRadiusStyle, getSizeStyle, prefixObject, stringifyStyles, } from "../../utils/style-utils";
3
- import { getLabelAndReplaceVariables } from "../../utils/variable-utils";
4
3
  export function getTimelineStyles(props) {
5
4
  const styles = {
6
5
  "--item-spacing": `${props.item_spacing}px`,
@@ -16,19 +15,19 @@ export function getTimelineStyles(props) {
16
15
  const prefixedStyles = prefixObject(styles, "timeline");
17
16
  return stringifyStyles(prefixedStyles);
18
17
  }
19
- export function getTimelineItemStyles(props) {
18
+ export function getTimelineItemStyles(colorMode, props) {
20
19
  const styles = {
21
20
  "--icon-size": `${props.icon.width_and_height}px`,
22
21
  "--icon-padding": `${props.icon.padding}px`,
23
22
  "--icon-color": getColor({
24
23
  colorMap: props.icon.color,
25
- colorMode: props.purchaseState?.colorMode,
24
+ colorMode,
26
25
  }),
27
26
  "--icon-background-color": getColor({
28
27
  colorMap: props.icon_background?.color,
29
- colorMode: props.purchaseState.colorMode,
28
+ colorMode,
30
29
  }),
31
- "--icon-border": getBorderStyle(props.icon_background?.border, props.purchaseState?.colorMode),
30
+ "--icon-border": getBorderStyle(props.icon_background?.border, colorMode),
32
31
  "--text-spacing": `${props.text_spacing}px`,
33
32
  "--border-start-start-radius": `0px`,
34
33
  "--border-start-end-radius": `0px`,
@@ -36,7 +35,7 @@ export function getTimelineItemStyles(props) {
36
35
  "--border-end-end-radius": `0px`,
37
36
  "--connector-color": getColor({
38
37
  colorMap: props.connector?.color,
39
- colorMode: props.purchaseState.colorMode,
38
+ colorMode,
40
39
  }),
41
40
  "--connector-width": `${props.connector?.width || 0}px`,
42
41
  "--connector-top": "0px",
@@ -80,7 +79,7 @@ export function getTimelineItemStyles(props) {
80
79
  const prefixedStyles = prefixObject(styles, "timeline-item");
81
80
  return stringifyStyles(prefixedStyles);
82
81
  }
83
- export function getTimelineItemTextStyles(props, kind = "title") {
82
+ export function getTimelineItemTextStyles(colorMode, props, kind = "title") {
84
83
  const styles = {
85
84
  "--text-color": "inherit",
86
85
  "--text-font-size": "initial",
@@ -101,7 +100,7 @@ export function getTimelineItemTextStyles(props, kind = "title") {
101
100
  font_weight: props[kind]?.font_weight || "regular",
102
101
  horizontal_alignment: props[kind]?.horizontal_alignment || "leading",
103
102
  };
104
- const { tagToRender, textStyles } = getTextComponentStyles({
103
+ const { tagToRender, textStyles } = getTextComponentStyles(colorMode, {
105
104
  ...props,
106
105
  components: [],
107
106
  ...textProps,
@@ -113,16 +112,8 @@ export function getTimelineItemTextStyles(props, kind = "title") {
113
112
  });
114
113
  Object.assign(styles, textStyles);
115
114
  const stringifiedStyles = stringifyStyles(prefixObject(styles, "timeline-item"));
116
- const textLabel = getLabelAndReplaceVariables({
117
- text_lid: props[kind]?.text_lid,
118
- locale: props.purchaseState.locale,
119
- defaultLocale: props.purchaseState.defaultLocale,
120
- labels: props.labels,
121
- variableDictionary: props.variableDictionary,
122
- });
123
115
  return {
124
116
  textStyles: stringifiedStyles,
125
117
  tagToRender,
126
- textLabel,
127
118
  };
128
119
  }