@revenuecat/purchases-ui-js 0.0.15 → 0.0.17
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/components/button/Button.svelte.d.ts +4 -2
- package/dist/components/button/ButtonNode.stories.svelte +2 -4
- package/dist/components/button/ButtonNode.svelte.d.ts +1 -0
- package/dist/components/footer/Footer.stories.svelte +46 -156
- package/dist/components/footer/Footer.stories.svelte.d.ts +1 -2
- package/dist/components/footer/Footer.svelte +9 -0
- package/dist/components/footer/Footer.svelte.d.ts +1 -0
- package/dist/components/image/Image.stories.svelte +9 -7
- package/dist/components/image/Image.svelte +18 -3
- package/dist/components/image/Image.svelte.d.ts +1 -0
- package/dist/components/image/image-utils.js +5 -4
- package/dist/components/package/Package.stories.svelte +0 -2
- package/dist/components/package/Package.svelte.d.ts +1 -0
- package/dist/components/paywall/Node.svelte +8 -1
- package/dist/components/paywall/Node.svelte.d.ts +4 -2
- package/dist/components/paywall/Paywall.stories.svelte +79 -15
- package/dist/components/paywall/Paywall.svelte +41 -22
- package/dist/components/paywall/Paywall.svelte.d.ts +4 -0
- package/dist/components/purchase-button/PurchaseButton.stories.svelte +0 -2
- package/dist/components/purchase-button/PurchaseButton.svelte.d.ts +1 -0
- package/dist/components/stack/Stack.stories.svelte +0 -2
- package/dist/components/stack/Stack.svelte +3 -0
- package/dist/components/stack/Stack.svelte.d.ts +1 -0
- package/dist/components/stack/stack-utils.js +3 -3
- package/dist/components/text/Text.svelte.d.ts +4 -2
- package/dist/components/text/TextNode.stories.svelte +1 -2
- package/dist/components/text/TextNode.svelte +5 -12
- package/dist/components/text/TextNode.svelte.d.ts +1 -0
- package/dist/components/text/text-utils.d.ts +5 -2
- package/dist/components/text/text-utils.js +9 -9
- package/dist/components/timeline/Timeline.stories.svelte +640 -0
- package/dist/components/timeline/Timeline.stories.svelte.d.ts +19 -0
- package/dist/components/timeline/Timeline.svelte +40 -0
- package/dist/components/timeline/Timeline.svelte.d.ts +4 -0
- package/dist/components/timeline/TimelineItem.svelte +100 -0
- package/dist/components/timeline/TimelineItem.svelte.d.ts +4 -0
- package/dist/components/timeline/timeline-utils.d.ts +25 -0
- package/dist/components/timeline/timeline-utils.js +93 -0
- package/dist/data/entities.d.ts +62 -21
- package/dist/data/state.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/stories/fixtures.d.ts +5 -0
- package/dist/stories/fixtures.js +4716 -33
- package/dist/stories/meta-templates.d.ts +0 -1
- package/dist/stories/meta-templates.js +0 -5
- package/dist/types.d.ts +12 -4
- package/dist/types.js +7 -0
- package/dist/utils/style-utils.d.ts +36 -4
- package/dist/utils/style-utils.js +82 -13
- package/package.json +27 -25
|
@@ -12,8 +12,14 @@
|
|
|
12
12
|
variablesPastaPaywallData,
|
|
13
13
|
stateTemplate,
|
|
14
14
|
posterMakerTemplate,
|
|
15
|
+
e2eTestTemplate,
|
|
16
|
+
zStackTemplate,
|
|
17
|
+
colorModeOverrideTemplate,
|
|
18
|
+
errorPaywallData,
|
|
19
|
+
paywallWithFooter,
|
|
15
20
|
} from "../../stories/fixtures";
|
|
16
21
|
import { fn } from "@storybook/test";
|
|
22
|
+
import type { VariableDictionary } from "../../utils/variable-utils";
|
|
17
23
|
|
|
18
24
|
const { Story } = defineMeta({
|
|
19
25
|
title: "Example/Paywall",
|
|
@@ -31,7 +37,7 @@
|
|
|
31
37
|
paywallData: paywallData,
|
|
32
38
|
onPurchaseClicked: fn(),
|
|
33
39
|
onBackClicked: fn(),
|
|
34
|
-
|
|
40
|
+
onNavigateToUrlClicked: fn(),
|
|
35
41
|
onRestorePurchasesClicked: fn(),
|
|
36
42
|
}}
|
|
37
43
|
/>
|
|
@@ -43,7 +49,7 @@
|
|
|
43
49
|
selectedLocale: "it_IT",
|
|
44
50
|
onPurchaseClicked: fn(),
|
|
45
51
|
onBackClicked: fn(),
|
|
46
|
-
|
|
52
|
+
onNavigateToUrlClicked: fn(),
|
|
47
53
|
onRestorePurchasesClicked: fn(),
|
|
48
54
|
}}
|
|
49
55
|
/>
|
|
@@ -55,7 +61,7 @@
|
|
|
55
61
|
selectedLocale: "en_US",
|
|
56
62
|
onPurchaseClicked: fn(),
|
|
57
63
|
onBackClicked: fn(),
|
|
58
|
-
|
|
64
|
+
onNavigateToUrlClicked: fn(),
|
|
59
65
|
onRestorePurchasesClicked: fn(),
|
|
60
66
|
}}
|
|
61
67
|
/>
|
|
@@ -67,7 +73,7 @@
|
|
|
67
73
|
selectedLocale: "en_US",
|
|
68
74
|
onPurchaseClicked: fn(),
|
|
69
75
|
onBackClicked: fn(),
|
|
70
|
-
|
|
76
|
+
onNavigateToUrlClicked: fn(),
|
|
71
77
|
onRestorePurchasesClicked: fn(),
|
|
72
78
|
}}
|
|
73
79
|
/>
|
|
@@ -79,7 +85,7 @@
|
|
|
79
85
|
selectedLocale: "en_US",
|
|
80
86
|
onPurchaseClicked: fn(),
|
|
81
87
|
onBackClicked: fn(),
|
|
82
|
-
|
|
88
|
+
onNavigateToUrlClicked: fn(),
|
|
83
89
|
onRestorePurchasesClicked: fn(),
|
|
84
90
|
}}
|
|
85
91
|
/>
|
|
@@ -90,24 +96,24 @@
|
|
|
90
96
|
selectedLocale: "en_US",
|
|
91
97
|
onPurchaseClicked: fn(),
|
|
92
98
|
onBackClicked: fn(),
|
|
93
|
-
|
|
99
|
+
onNavigateToUrlClicked: fn(),
|
|
94
100
|
onRestorePurchasesClicked: fn(),
|
|
95
101
|
variablesPerPackage: {
|
|
96
102
|
trial: {
|
|
97
103
|
product_name: "This was a variable: Product A",
|
|
98
104
|
price: "$19.99",
|
|
99
105
|
price_per_period: "$19.99/yr",
|
|
100
|
-
},
|
|
106
|
+
} as VariableDictionary,
|
|
101
107
|
$rc_weekly: {
|
|
102
108
|
product_name: "This was a variable: Product B",
|
|
103
109
|
price: "$29.99",
|
|
104
110
|
price_per_period: "$29.99/yr",
|
|
105
|
-
},
|
|
111
|
+
} as VariableDictionary,
|
|
106
112
|
$rc_daily: {
|
|
107
113
|
product_name: "This was a variable: Product C",
|
|
108
114
|
price: "$39.99",
|
|
109
|
-
price_per_period: "$
|
|
110
|
-
},
|
|
115
|
+
price_per_period: "$19.99/yr",
|
|
116
|
+
} as VariableDictionary,
|
|
111
117
|
},
|
|
112
118
|
}}
|
|
113
119
|
/>
|
|
@@ -119,7 +125,7 @@
|
|
|
119
125
|
selectedLocale: "en_US",
|
|
120
126
|
onPurchaseClicked: fn(),
|
|
121
127
|
onBackClicked: fn(),
|
|
122
|
-
|
|
128
|
+
onNavigateToUrlClicked: fn(),
|
|
123
129
|
onRestorePurchasesClicked: fn(),
|
|
124
130
|
}}
|
|
125
131
|
/>
|
|
@@ -130,7 +136,7 @@
|
|
|
130
136
|
paywallData: gradientPaywallData,
|
|
131
137
|
onPurchaseClicked: fn(),
|
|
132
138
|
onBackClicked: fn(),
|
|
133
|
-
|
|
139
|
+
onNavigateToUrlClicked: fn(),
|
|
134
140
|
onRestorePurchasesClicked: fn(),
|
|
135
141
|
}}
|
|
136
142
|
/>
|
|
@@ -141,7 +147,7 @@
|
|
|
141
147
|
paywallData: stateTemplate,
|
|
142
148
|
onPurchaseClicked: fn(),
|
|
143
149
|
onBackClicked: fn(),
|
|
144
|
-
|
|
150
|
+
onNavigateToUrlClicked: fn(),
|
|
145
151
|
onRestorePurchasesClicked: fn(),
|
|
146
152
|
}}
|
|
147
153
|
/>
|
|
@@ -174,7 +180,7 @@
|
|
|
174
180
|
},
|
|
175
181
|
onPurchaseClicked: fn(),
|
|
176
182
|
onBackClicked: fn(),
|
|
177
|
-
|
|
183
|
+
onNavigateToUrlClicked: fn(),
|
|
178
184
|
onRestorePurchasesClicked: fn(),
|
|
179
185
|
}}
|
|
180
186
|
/>
|
|
@@ -185,7 +191,65 @@
|
|
|
185
191
|
paywallData: posterMakerTemplate,
|
|
186
192
|
onPurchaseClicked: fn(),
|
|
187
193
|
onBackClicked: fn(),
|
|
188
|
-
|
|
194
|
+
onNavigateToUrlClicked: fn(),
|
|
195
|
+
onRestorePurchasesClicked: fn(),
|
|
196
|
+
}}
|
|
197
|
+
/>
|
|
198
|
+
|
|
199
|
+
<Story
|
|
200
|
+
name="E2E Test with variables"
|
|
201
|
+
args={{
|
|
202
|
+
paywallData: e2eTestTemplate,
|
|
203
|
+
onPurchaseClicked: fn(),
|
|
204
|
+
onBackClicked: fn(),
|
|
205
|
+
onNavigateToUrlClicked: fn(),
|
|
206
|
+
onRestorePurchasesClicked: fn(),
|
|
207
|
+
}}
|
|
208
|
+
/>
|
|
209
|
+
|
|
210
|
+
<Story
|
|
211
|
+
name="Z Stack"
|
|
212
|
+
args={{
|
|
213
|
+
paywallData: zStackTemplate,
|
|
214
|
+
onPurchaseClicked: fn(),
|
|
215
|
+
onBackClicked: fn(),
|
|
216
|
+
onNavigateToUrlClicked: fn(),
|
|
217
|
+
onRestorePurchasesClicked: fn(),
|
|
218
|
+
}}
|
|
219
|
+
/>
|
|
220
|
+
|
|
221
|
+
<Story
|
|
222
|
+
name="Color Mode Override"
|
|
223
|
+
args={{
|
|
224
|
+
paywallData: colorModeOverrideTemplate,
|
|
225
|
+
onPurchaseClicked: fn(),
|
|
226
|
+
onBackClicked: fn(),
|
|
227
|
+
onNavigateToUrlClicked: fn(),
|
|
228
|
+
onRestorePurchasesClicked: fn(),
|
|
229
|
+
preferredColorMode: "dark",
|
|
230
|
+
}}
|
|
231
|
+
/>
|
|
232
|
+
|
|
233
|
+
<Story
|
|
234
|
+
name="Invalid component type"
|
|
235
|
+
args={{
|
|
236
|
+
paywallData: errorPaywallData,
|
|
237
|
+
onPurchaseClicked: fn(),
|
|
238
|
+
onBackClicked: fn(),
|
|
239
|
+
onNavigateToUrlClicked: fn(),
|
|
240
|
+
onRestorePurchasesClicked: fn(),
|
|
241
|
+
preferredColorMode: "dark",
|
|
242
|
+
onError: (error: unknown) => alert(`Error - ${error}`),
|
|
243
|
+
}}
|
|
244
|
+
/>
|
|
245
|
+
|
|
246
|
+
<Story
|
|
247
|
+
name="Sticky Footer"
|
|
248
|
+
args={{
|
|
249
|
+
paywallData: paywallWithFooter,
|
|
250
|
+
onPurchaseClicked: fn(),
|
|
251
|
+
onBackClicked: fn(),
|
|
252
|
+
onNavigateToUrlClicked: fn(),
|
|
189
253
|
onRestorePurchasesClicked: fn(),
|
|
190
254
|
}}
|
|
191
255
|
/>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type {
|
|
3
|
-
BaseNodeBackgroundImage,
|
|
4
3
|
Extra,
|
|
5
4
|
NavigateToAction,
|
|
6
5
|
PaywallData,
|
|
6
|
+
StackProps,
|
|
7
7
|
SupportedActions,
|
|
8
8
|
} from "../../data/entities";
|
|
9
9
|
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
getBackgroundStyles,
|
|
17
17
|
} from "./paywall-utils";
|
|
18
18
|
import { prefersDarkMode } from "../../stores/theme";
|
|
19
|
+
import type { ColorMode } from "../../types";
|
|
20
|
+
import Footer from "../footer/Footer.svelte";
|
|
19
21
|
|
|
20
22
|
interface Props {
|
|
21
23
|
paywallData: PaywallData;
|
|
@@ -26,6 +28,8 @@
|
|
|
26
28
|
onNavigateToUrlClicked?: (url: string) => void;
|
|
27
29
|
selectedLocale?: string;
|
|
28
30
|
variablesPerPackage?: Record<string, VariableDictionary>;
|
|
31
|
+
preferredColorMode?: ColorMode;
|
|
32
|
+
onError?: (error: unknown) => void;
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
const {
|
|
@@ -37,6 +41,8 @@
|
|
|
37
41
|
onVisitCustomerCenterClicked,
|
|
38
42
|
selectedLocale,
|
|
39
43
|
variablesPerPackage = {},
|
|
44
|
+
preferredColorMode,
|
|
45
|
+
onError,
|
|
40
46
|
}: Props = $props();
|
|
41
47
|
|
|
42
48
|
let purchaseState: PurchaseState = $state({
|
|
@@ -44,6 +50,7 @@
|
|
|
44
50
|
locale: selectedLocale || paywallData.default_locale,
|
|
45
51
|
defaultLocale: paywallData.default_locale,
|
|
46
52
|
variablesPerPackage,
|
|
53
|
+
colorMode: preferredColorMode || ($prefersDarkMode ? "dark" : "light"),
|
|
47
54
|
});
|
|
48
55
|
|
|
49
56
|
let variableDictionary = $state(
|
|
@@ -81,9 +88,9 @@
|
|
|
81
88
|
};
|
|
82
89
|
|
|
83
90
|
const onSelectPackageAction = (_: SupportedActions, data?: Extra) => {
|
|
84
|
-
purchaseState.selectedPackageId = data?.packageId;
|
|
91
|
+
purchaseState.selectedPackageId = data?.packageId as string | undefined;
|
|
85
92
|
if (data?.packageId) {
|
|
86
|
-
variableDictionary = variablesPerPackage[data.packageId];
|
|
93
|
+
variableDictionary = variablesPerPackage[data.packageId as string];
|
|
87
94
|
}
|
|
88
95
|
};
|
|
89
96
|
|
|
@@ -113,35 +120,47 @@
|
|
|
113
120
|
break;
|
|
114
121
|
}
|
|
115
122
|
};
|
|
116
|
-
const colorMode = $derived($prefersDarkMode ? "dark" : "light");
|
|
117
123
|
|
|
118
124
|
const backgroundStyles = $derived(
|
|
119
125
|
getBackgroundStyles({
|
|
120
126
|
background: paywallData.components_config.base?.background,
|
|
121
|
-
colorMode,
|
|
127
|
+
colorMode: purchaseState.colorMode,
|
|
122
128
|
}),
|
|
123
129
|
);
|
|
124
130
|
const backgroundImgSource = $derived(
|
|
125
|
-
getBackgroundImageSource(paywallData,
|
|
131
|
+
getBackgroundImageSource(paywallData, purchaseState.colorMode),
|
|
126
132
|
);
|
|
127
133
|
</script>
|
|
128
134
|
|
|
129
|
-
<
|
|
130
|
-
<
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
135
|
+
<svelte:boundary onerror={onError}>
|
|
136
|
+
<div class="paywall">
|
|
137
|
+
<Node
|
|
138
|
+
{onAction}
|
|
139
|
+
nodeData={paywallData.components_config.base.stack}
|
|
140
|
+
labels={paywallData.components_localizations}
|
|
141
|
+
{purchaseState}
|
|
142
|
+
{variableDictionary}
|
|
143
|
+
/>
|
|
144
|
+
|
|
145
|
+
{#if paywallData.components_config.base.sticky_footer}
|
|
146
|
+
<Footer
|
|
147
|
+
{...paywallData.components_config.base.sticky_footer}
|
|
148
|
+
stack={paywallData.components_config.base.sticky_footer
|
|
149
|
+
.stack as StackProps}
|
|
150
|
+
labels={paywallData.components_localizations}
|
|
151
|
+
{purchaseState}
|
|
152
|
+
{variableDictionary}
|
|
153
|
+
/>
|
|
154
|
+
{/if}
|
|
155
|
+
{#if paywallData.components_config.base.background?.type === "color"}
|
|
156
|
+
<div class="paywall-background" style={backgroundStyles}></div>
|
|
157
|
+
{:else if paywallData.components_config.base.background?.type === "image"}
|
|
158
|
+
<div class="paywall-background image-container">
|
|
159
|
+
<img class="image" src={backgroundImgSource} alt="" />
|
|
160
|
+
</div>
|
|
161
|
+
{/if}
|
|
162
|
+
</div>
|
|
163
|
+
</svelte:boundary>
|
|
145
164
|
|
|
146
165
|
<style>
|
|
147
166
|
/* 1. Use a more-intuitive box-sizing model */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PaywallData } from "../../data/entities";
|
|
2
2
|
import { type VariableDictionary } from "../../utils/variable-utils";
|
|
3
|
+
import type { ColorMode } from "../../types";
|
|
3
4
|
declare const Paywall: import("svelte").Component<{
|
|
4
5
|
paywallData: PaywallData;
|
|
5
6
|
onPurchaseClicked?: (selectedPackageId: string) => void;
|
|
@@ -9,5 +10,8 @@ declare const Paywall: import("svelte").Component<{
|
|
|
9
10
|
onNavigateToUrlClicked?: (url: string) => void;
|
|
10
11
|
selectedLocale?: string;
|
|
11
12
|
variablesPerPackage?: Record<string, VariableDictionary>;
|
|
13
|
+
preferredColorMode?: ColorMode;
|
|
14
|
+
onError?: (error: unknown) => void;
|
|
12
15
|
}, {}, "">;
|
|
16
|
+
type Paywall = ReturnType<typeof Paywall>;
|
|
13
17
|
export default Paywall;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
<script module lang="ts">
|
|
2
2
|
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
3
3
|
import PurchaseButton from "./PurchaseButton.svelte";
|
|
4
|
-
import { colorModeStoryMeta } from "../../stories/meta-templates";
|
|
5
4
|
|
|
6
5
|
const { Story } = defineMeta({
|
|
7
6
|
title: "Components/PurchaseButton",
|
|
8
7
|
component: PurchaseButton,
|
|
9
8
|
tags: ["autodocs"],
|
|
10
9
|
argTypes: {
|
|
11
|
-
colorMode: colorModeStoryMeta,
|
|
12
10
|
stack: {
|
|
13
11
|
control: { type: "object" },
|
|
14
12
|
description: "Stack configuration for button content",
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import Stack from "./Stack.svelte";
|
|
4
4
|
import {
|
|
5
5
|
borderStoryMeta,
|
|
6
|
-
colorModeStoryMeta,
|
|
7
6
|
getColorStoryMeta,
|
|
8
7
|
getSpacingStoryMeta,
|
|
9
8
|
shadowStoryMeta,
|
|
@@ -22,7 +21,6 @@
|
|
|
22
21
|
control: { type: "number" },
|
|
23
22
|
description: "Space between stack items in pixels",
|
|
24
23
|
},
|
|
25
|
-
colorMode: colorModeStoryMeta,
|
|
26
24
|
shadow: shadowStoryMeta,
|
|
27
25
|
background_color: getColorStoryMeta("Background color object"),
|
|
28
26
|
padding: getSpacingStoryMeta("Padding values in pixels"),
|
|
@@ -63,5 +63,8 @@
|
|
|
63
63
|
margin-block-end: var(--margin-block-end, 0);
|
|
64
64
|
margin-inline-start: var(--margin-inline-start, 0);
|
|
65
65
|
flex: var(--flex, 0 1 auto);
|
|
66
|
+
position: var(--position, relative);
|
|
67
|
+
inset: var(--inset, initial);
|
|
68
|
+
transform: var(--transform, initial);
|
|
66
69
|
}
|
|
67
70
|
</style>
|
|
@@ -5,14 +5,14 @@ import { getActiveStateProps, getComponentStyles, getDimensionStyle, getSizeStyl
|
|
|
5
5
|
* @returns CSS style variables object with all stack-specific styles
|
|
6
6
|
*/
|
|
7
7
|
export const getStackComponentStyles = (props) => {
|
|
8
|
-
const { background_color, margin, padding, spacing, size, border, shape,
|
|
8
|
+
const { background_color, margin, padding, spacing, size, border, shape, shadow, dimension, componentState, overrides, purchaseState, } = props;
|
|
9
9
|
const activeStateProps = getActiveStateProps(overrides, componentState);
|
|
10
10
|
const componentStyles = getComponentStyles({
|
|
11
11
|
backgroundColor: background_color,
|
|
12
12
|
margin,
|
|
13
13
|
padding,
|
|
14
14
|
border,
|
|
15
|
-
colorMode,
|
|
15
|
+
colorMode: purchaseState.colorMode,
|
|
16
16
|
shape,
|
|
17
17
|
shadow,
|
|
18
18
|
...activeStateProps,
|
|
@@ -21,7 +21,7 @@ export const getStackComponentStyles = (props) => {
|
|
|
21
21
|
...dimension,
|
|
22
22
|
...activeStateProps,
|
|
23
23
|
});
|
|
24
|
-
const sizeStyles = getSizeStyle({ ...size, ...activeStateProps });
|
|
24
|
+
const sizeStyles = getSizeStyle({ ...size, ...activeStateProps }, dimension.type === "zlayer");
|
|
25
25
|
return {
|
|
26
26
|
...sizeStyles,
|
|
27
27
|
...dimensionStyles,
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Snippet } from "svelte";
|
|
2
|
-
|
|
2
|
+
interface TextProps {
|
|
3
3
|
component?: string;
|
|
4
4
|
styleVariables?: string;
|
|
5
5
|
id?: string;
|
|
6
6
|
children?: Snippet;
|
|
7
|
-
}
|
|
7
|
+
}
|
|
8
|
+
declare const Text: import("svelte").Component<TextProps, {}, "">;
|
|
9
|
+
type Text = ReturnType<typeof Text>;
|
|
8
10
|
export default Text;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
3
3
|
import TextNode from "./TextNode.svelte";
|
|
4
4
|
import {
|
|
5
|
-
colorModeStoryMeta,
|
|
6
5
|
fontSizeStoryMeta,
|
|
7
6
|
fontWeightStoryMeta,
|
|
8
7
|
getColorStoryMeta,
|
|
@@ -25,7 +24,6 @@
|
|
|
25
24
|
"Font family to be used, uses GoogleFonts API",
|
|
26
25
|
),
|
|
27
26
|
font_weight: fontWeightStoryMeta,
|
|
28
|
-
colorMode: colorModeStoryMeta,
|
|
29
27
|
font_size: fontSizeStoryMeta,
|
|
30
28
|
color: getColorStoryMeta("Text color object"),
|
|
31
29
|
background_color: getColorStoryMeta("Background color object"),
|
|
@@ -53,6 +51,7 @@
|
|
|
53
51
|
purchaseState: {
|
|
54
52
|
locale: "en_US",
|
|
55
53
|
defaultLocale: "en_US",
|
|
54
|
+
colorMode: "light",
|
|
56
55
|
},
|
|
57
56
|
},
|
|
58
57
|
});
|
|
@@ -4,11 +4,10 @@
|
|
|
4
4
|
import type { TextNodeProps } from "../../data/entities";
|
|
5
5
|
import {
|
|
6
6
|
getComponentStyles,
|
|
7
|
-
|
|
7
|
+
getLabelAndReplaceVariables,
|
|
8
8
|
getSizeStyle,
|
|
9
9
|
stringifyStyles,
|
|
10
10
|
} from "../../utils/style-utils";
|
|
11
|
-
import { replaceVariables } from "../../utils/variable-utils";
|
|
12
11
|
|
|
13
12
|
const {
|
|
14
13
|
id,
|
|
@@ -20,7 +19,6 @@
|
|
|
20
19
|
size,
|
|
21
20
|
...restProps
|
|
22
21
|
}: TextNodeProps = $props();
|
|
23
|
-
|
|
24
22
|
const { tagToRender, textStyles } = $derived(
|
|
25
23
|
getTextComponentStyles({
|
|
26
24
|
id,
|
|
@@ -43,17 +41,12 @@
|
|
|
43
41
|
);
|
|
44
42
|
const styles = $derived(stringifyStyles(textStyles));
|
|
45
43
|
|
|
46
|
-
const
|
|
47
|
-
|
|
44
|
+
const parsedLabel = $derived(
|
|
45
|
+
getLabelAndReplaceVariables({
|
|
48
46
|
text_lid,
|
|
49
|
-
purchaseState.locale,
|
|
50
|
-
purchaseState.defaultLocale,
|
|
47
|
+
locale: purchaseState.locale,
|
|
48
|
+
defaultLocale: purchaseState.defaultLocale,
|
|
51
49
|
labels,
|
|
52
|
-
),
|
|
53
|
-
);
|
|
54
|
-
const parsedLabel = $derived(
|
|
55
|
-
replaceVariables({
|
|
56
|
-
value: label,
|
|
57
50
|
variableDictionary,
|
|
58
51
|
}),
|
|
59
52
|
);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type TextComponentTags } from "../../utils/style-utils";
|
|
2
2
|
import type { TextNodeProps } from "../../data/entities";
|
|
3
|
+
import type { ColorType } from "../../types";
|
|
3
4
|
type TextStyleVariables = {
|
|
4
5
|
"--width": string;
|
|
5
6
|
"--height": string;
|
|
@@ -10,13 +11,15 @@ type TextStyleVariables = {
|
|
|
10
11
|
"--background-clip": string;
|
|
11
12
|
"--text-fill-color": string;
|
|
12
13
|
};
|
|
14
|
+
export declare const defaultColor: ColorType;
|
|
15
|
+
export declare const defaultBackgroundColor: ColorType;
|
|
13
16
|
/**
|
|
14
17
|
* Generates comprehensive styles for text components by combining text, component and size styles
|
|
15
18
|
* @param props - Text component properties including font, color, background, spacing etc.
|
|
16
19
|
* @returns Object containing text style variables and the appropriate HTML tag to render
|
|
17
20
|
*/
|
|
18
21
|
export declare const getTextComponentStyles: (props: TextNodeProps) => {
|
|
19
|
-
textStyles: TextStyleVariables
|
|
20
|
-
tagToRender: TextComponentTags
|
|
22
|
+
textStyles: Partial<TextStyleVariables>;
|
|
23
|
+
tagToRender: Partial<TextComponentTags>;
|
|
21
24
|
};
|
|
22
25
|
export {};
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import { getActiveStateProps, getComponentStyles, getSizeStyle, getTextComponentTag, getTextStyles, } from "../../utils/style-utils";
|
|
2
|
+
export const defaultColor = {
|
|
3
|
+
light: { type: "hex", value: "#000000" },
|
|
4
|
+
};
|
|
5
|
+
export const defaultBackgroundColor = {
|
|
6
|
+
light: { type: "hex", value: "#FFFFFF" },
|
|
7
|
+
};
|
|
2
8
|
/**
|
|
3
9
|
* Generates comprehensive styles for text components by combining text, component and size styles
|
|
4
10
|
* @param props - Text component properties including font, color, background, spacing etc.
|
|
5
11
|
* @returns Object containing text style variables and the appropriate HTML tag to render
|
|
6
12
|
*/
|
|
7
13
|
export const getTextComponentStyles = (props) => {
|
|
8
|
-
const { font_size = "body_m", color =
|
|
9
|
-
dark: { type: "hex", value: "#000000" },
|
|
10
|
-
light: { type: "hex", value: "#000000" },
|
|
11
|
-
}, background_color = {
|
|
12
|
-
dark: { type: "hex", value: "#FFFFFF" },
|
|
13
|
-
light: { type: "hex", value: "#FFFFFF" },
|
|
14
|
-
}, padding, margin, colorMode, size, } = props;
|
|
14
|
+
const { font_size = "body_m", color = defaultColor, background_color = defaultBackgroundColor, padding, margin, size, purchaseState, } = props;
|
|
15
15
|
const activeStateProps = getActiveStateProps(props.overrides, props.componentState);
|
|
16
16
|
const tagToRender = getTextComponentTag(font_size);
|
|
17
|
-
const textStyles = getTextStyles({ ...props, ...activeStateProps }, colorMode);
|
|
17
|
+
const textStyles = getTextStyles({ ...props, ...activeStateProps }, purchaseState.colorMode);
|
|
18
18
|
const componentStyles = getComponentStyles({
|
|
19
19
|
backgroundColor: background_color,
|
|
20
20
|
textColor: color,
|
|
21
21
|
margin,
|
|
22
22
|
padding,
|
|
23
|
-
colorMode,
|
|
23
|
+
colorMode: purchaseState.colorMode,
|
|
24
24
|
...activeStateProps,
|
|
25
25
|
});
|
|
26
26
|
const sizeStyles = getSizeStyle({ ...size, ...activeStateProps });
|