@revenuecat/purchases-ui-js 0.0.17 → 0.0.18
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 +0 -13
- package/dist/components/button/ButtonNode.stories.svelte +16 -9
- package/dist/components/button/ButtonNode.svelte +26 -1
- package/dist/components/button/button-utils.d.ts +2 -0
- package/dist/components/button/button-utils.js +19 -0
- package/dist/components/footer/Footer.stories.svelte +2 -0
- package/dist/components/footer/Footer.svelte +5 -5
- package/dist/components/image/Image.stories.svelte +6 -2
- package/dist/components/image/Image.svelte +20 -17
- package/dist/components/image/image-utils.d.ts +2 -12
- package/dist/components/image/image-utils.js +27 -10
- package/dist/components/package/Package.stories.svelte +5 -3
- package/dist/components/package/Package.svelte +15 -6
- package/dist/components/paywall/Node.svelte +72 -19
- package/dist/components/paywall/Node.svelte.d.ts +18 -1
- package/dist/components/paywall/Paywall.stories.svelte +14 -0
- package/dist/components/paywall/Paywall.svelte +73 -70
- package/dist/components/paywall/paywall-utils.d.ts +1 -1
- package/dist/components/paywall/paywall-utils.js +11 -9
- package/dist/components/purchase-button/PurchaseButton.stories.svelte +7 -6
- package/dist/components/purchase-button/PurchaseButton.svelte +24 -10
- package/dist/components/purchase-button/purchase-button-utils.d.ts +2 -0
- package/dist/components/purchase-button/purchase-button-utils.js +20 -0
- package/dist/components/stack/Stack.stories.svelte +1138 -4
- package/dist/components/stack/Stack.svelte +160 -45
- package/dist/components/stack/stack-utils.d.ts +24 -24
- package/dist/components/stack/stack-utils.js +244 -11
- package/dist/components/text/Text.svelte +24 -19
- package/dist/components/text/TextNode.stories.svelte +12 -11
- package/dist/components/text/TextNode.svelte +21 -24
- package/dist/components/text/text-utils.d.ts +9 -15
- package/dist/components/text/text-utils.js +121 -6
- package/dist/components/timeline/Timeline.svelte +10 -10
- package/dist/components/timeline/TimelineItem.svelte +45 -33
- package/dist/components/timeline/timeline-utils.d.ts +3 -20
- package/dist/components/timeline/timeline-utils.js +46 -11
- package/dist/data/entities.d.ts +33 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/stories/fixtures.d.ts +2 -0
- package/dist/stories/fixtures.js +5346 -1412
- package/dist/types.d.ts +4 -3
- package/dist/utils/style-utils.d.ts +66 -59
- package/dist/utils/style-utils.js +114 -96
- package/dist/utils/variable-utils.d.ts +27 -0
- package/dist/utils/variable-utils.js +37 -0
- package/package.json +3 -2
- package/dist/components/paywall/global-styles.css +0 -9
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { StackProps } from "../../data/entities";
|
|
3
3
|
import Node from "../paywall/Node.svelte";
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
getBadgeStyles,
|
|
6
|
+
getStackBadgeTextStyles,
|
|
7
|
+
getStackComponentStyles,
|
|
8
|
+
getZStackChildStyles,
|
|
9
|
+
} from "./stack-utils";
|
|
10
|
+
import Text from "../text/Text.svelte";
|
|
11
|
+
import { getLabelAndReplaceVariables } from "../../utils/variable-utils";
|
|
6
12
|
|
|
7
13
|
const {
|
|
8
14
|
id,
|
|
@@ -11,60 +17,169 @@
|
|
|
11
17
|
onAction,
|
|
12
18
|
purchaseState,
|
|
13
19
|
variableDictionary,
|
|
20
|
+
badge,
|
|
21
|
+
zStackChildStyles,
|
|
14
22
|
...restProps
|
|
15
23
|
}: StackProps = $props();
|
|
16
24
|
|
|
17
25
|
const stackStyles = $derived(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
getStackComponentStyles({
|
|
27
|
+
id,
|
|
28
|
+
components,
|
|
29
|
+
labels,
|
|
30
|
+
onAction,
|
|
31
|
+
purchaseState,
|
|
32
|
+
zStackChildStyles,
|
|
33
|
+
...restProps,
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
36
|
+
const badgeStyles = $derived(
|
|
37
|
+
getBadgeStyles({
|
|
38
|
+
id,
|
|
39
|
+
components,
|
|
40
|
+
labels,
|
|
41
|
+
onAction,
|
|
42
|
+
purchaseState,
|
|
43
|
+
badge,
|
|
44
|
+
...restProps,
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const zStackChildrenStyles = $derived(
|
|
49
|
+
getZStackChildStyles({
|
|
50
|
+
id,
|
|
51
|
+
components,
|
|
52
|
+
labels,
|
|
53
|
+
onAction,
|
|
54
|
+
purchaseState,
|
|
55
|
+
...restProps,
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
const label = $derived(
|
|
59
|
+
getLabelAndReplaceVariables({
|
|
60
|
+
defaultLocale: purchaseState.defaultLocale,
|
|
61
|
+
locale: purchaseState.locale,
|
|
62
|
+
labels,
|
|
63
|
+
variableDictionary,
|
|
64
|
+
text_lid: badge?.text_lid,
|
|
65
|
+
}),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const { tagToRender, textStyles } = $derived(
|
|
69
|
+
getStackBadgeTextStyles({
|
|
70
|
+
id,
|
|
71
|
+
components,
|
|
72
|
+
labels,
|
|
73
|
+
onAction,
|
|
74
|
+
purchaseState,
|
|
75
|
+
variableDictionary,
|
|
76
|
+
badge,
|
|
77
|
+
...restProps,
|
|
78
|
+
}),
|
|
28
79
|
);
|
|
29
80
|
</script>
|
|
30
81
|
|
|
31
|
-
<div {id} style={stackStyles}
|
|
32
|
-
{#
|
|
33
|
-
<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
82
|
+
<div {id} class="rc-pw-stack-wrapper" style={stackStyles}>
|
|
83
|
+
{#if badge}
|
|
84
|
+
<span class="rc-pw-badge" style={badgeStyles}>
|
|
85
|
+
<Text styleVariables={textStyles} component={tagToRender}>
|
|
86
|
+
{label}
|
|
87
|
+
</Text>
|
|
88
|
+
</span>
|
|
89
|
+
{/if}
|
|
90
|
+
<div class="rc-pw-stack">
|
|
91
|
+
{#each components as component, index}
|
|
92
|
+
{#if zStackChildrenStyles}
|
|
93
|
+
<Node
|
|
94
|
+
nodeData={component}
|
|
95
|
+
{labels}
|
|
96
|
+
{onAction}
|
|
97
|
+
{purchaseState}
|
|
98
|
+
{variableDictionary}
|
|
99
|
+
zStackChildStyles={index > 0 ? zStackChildrenStyles : undefined}
|
|
100
|
+
/>
|
|
101
|
+
{:else}
|
|
102
|
+
<Node
|
|
103
|
+
nodeData={component}
|
|
104
|
+
{labels}
|
|
105
|
+
{onAction}
|
|
106
|
+
{purchaseState}
|
|
107
|
+
{variableDictionary}
|
|
108
|
+
/>
|
|
109
|
+
{/if}
|
|
110
|
+
{/each}
|
|
111
|
+
</div>
|
|
41
112
|
</div>
|
|
42
113
|
|
|
43
114
|
<style>
|
|
44
|
-
.stack {
|
|
115
|
+
.rc-pw-stack-wrapper {
|
|
116
|
+
display: block;
|
|
117
|
+
box-sizing: border-box;
|
|
118
|
+
width: var(--stack-width, unset);
|
|
119
|
+
height: var(--stack-height, unset);
|
|
120
|
+
box-shadow: var(--stack-shadow, none);
|
|
121
|
+
background: var(--stack-background, unset);
|
|
122
|
+
position: var(--stack-position, relative);
|
|
123
|
+
transform: var(--stack-transform, initial);
|
|
124
|
+
inset: var(--stack-inset, initial);
|
|
125
|
+
margin-block-start: var(--stack-margin-block-start, 0);
|
|
126
|
+
margin-inline-end: var(--stack-margin-inline-end, 0);
|
|
127
|
+
margin-block-end: var(--stack-margin-block-end, 0);
|
|
128
|
+
margin-inline-start: var(--stack-margin-inline-start, 0);
|
|
129
|
+
border: var(--stack-border, none);
|
|
130
|
+
border-end-start-radius: var(--stack-border-end-start-radius, 0px);
|
|
131
|
+
border-end-end-radius: var(--stack-border-end-end-radius, 0px);
|
|
132
|
+
border-start-start-radius: var(--stack-border-start-start-radius, 0px);
|
|
133
|
+
border-start-end-radius: var(--stack-border-start-end-radius, 0px);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.rc-pw-stack {
|
|
137
|
+
background: none;
|
|
138
|
+
overflow: hidden;
|
|
139
|
+
box-sizing: border-box;
|
|
140
|
+
width: 100%;
|
|
141
|
+
height: 100%;
|
|
142
|
+
display: flex;
|
|
143
|
+
gap: var(--stack-spacing, 0);
|
|
144
|
+
flex: var(--stack-flex, 0 1 auto);
|
|
145
|
+
flex-direction: var(--stack-direction, unset);
|
|
146
|
+
justify-content: var(--stack-distribution, flex-start);
|
|
147
|
+
align-items: var(--stack-alignment, flex-start);
|
|
148
|
+
padding-block-start: var(--stack-padding-block-start, 0);
|
|
149
|
+
padding-inline-end: var(--stack-padding-inline-end, 0);
|
|
150
|
+
padding-block-end: var(--stack-padding-block-end, 0);
|
|
151
|
+
padding-inline-start: var(--stack-padding-inline-start, 0);
|
|
152
|
+
}
|
|
153
|
+
.rc-pw-badge {
|
|
45
154
|
box-sizing: border-box;
|
|
155
|
+
font-family: var(--stack-badge-font-family, sans-serif);
|
|
156
|
+
position: absolute;
|
|
157
|
+
inset: var(--stack-badge-inset, unset);
|
|
158
|
+
transform: var(--stack-badge-transform, initial);
|
|
159
|
+
margin-block-start: var(--stack-badge-margin-block-start, 0px);
|
|
160
|
+
margin-inline-end: var(--stack-badge-margin-inline-end, 0px);
|
|
161
|
+
margin-block-end: var(--stack-badge-margin-block-end, 0px);
|
|
162
|
+
margin-inline-start: var(--stack-badge-margin-inline-start, 0px);
|
|
163
|
+
padding-block-start: var(--stack-badge-padding-block-start, 0px);
|
|
164
|
+
padding-inline-end: var(--stack-badge-padding-inline-end, 0px);
|
|
165
|
+
padding-block-end: var(--stack-badge-padding-block-end, 0px);
|
|
166
|
+
padding-inline-start: var(--stack-badge-padding-inline-start, 0px);
|
|
167
|
+
background: var(--stack-badge-background, initial);
|
|
168
|
+
color: var(--stack-badge-text-color, inherit);
|
|
169
|
+
border: var(--stack-badge-border, none);
|
|
170
|
+
border-end-start-radius: var(--stack-badge-border-end-start-radius, 0px);
|
|
171
|
+
border-end-end-radius: var(--stack-badge-border-end-end-radius, 0px);
|
|
172
|
+
border-start-start-radius: var(
|
|
173
|
+
--stack-badge-border-start-start-radius,
|
|
174
|
+
0px
|
|
175
|
+
);
|
|
176
|
+
border-start-end-radius: var(--stack-badge-border-start-end-radius, 0px);
|
|
177
|
+
box-shadow: var(--stack-badge-shadow, none);
|
|
46
178
|
display: flex;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
border: var(--border, none);
|
|
53
|
-
border-radius: var(--border-radius, 0);
|
|
54
|
-
box-shadow: var(--shadow, none);
|
|
55
|
-
justify-content: var(--distribution, flex-start);
|
|
56
|
-
align-items: var(--alignment, flex-start);
|
|
57
|
-
padding-block-start: var(--padding-block-start, 0);
|
|
58
|
-
padding-inline-end: var(--padding-inline-end, 0);
|
|
59
|
-
padding-block-end: var(--padding-block-end, 0);
|
|
60
|
-
padding-inline-start: var(--padding-inline-start, 0);
|
|
61
|
-
margin-block-start: var(--margin-block-start, 0);
|
|
62
|
-
margin-inline-end: var(--margin-inline-end, 0);
|
|
63
|
-
margin-block-end: var(--margin-block-end, 0);
|
|
64
|
-
margin-inline-start: var(--margin-inline-start, 0);
|
|
65
|
-
flex: var(--flex, 0 1 auto);
|
|
66
|
-
position: var(--position, relative);
|
|
67
|
-
inset: var(--inset, initial);
|
|
68
|
-
transform: var(--transform, initial);
|
|
179
|
+
align-items: center;
|
|
180
|
+
justify-content: center;
|
|
181
|
+
width: var(--stack-badge-badge-width, max-content);
|
|
182
|
+
height: var(--stack-badge-badge-height, max-content);
|
|
183
|
+
z-index: var(--stack-badge-z-index, 1);
|
|
69
184
|
}
|
|
70
185
|
</style>
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import type { StackProps } from "../../data/entities";
|
|
2
|
-
type StackStyleVariables = {
|
|
3
|
-
"--flex": string;
|
|
4
|
-
"--height": string;
|
|
5
|
-
"--width": string;
|
|
6
|
-
"--spacing": string;
|
|
7
|
-
"--direction": string;
|
|
8
|
-
"--alignment": string;
|
|
9
|
-
"--distribution": string;
|
|
10
|
-
"--margin-block-start": string;
|
|
11
|
-
"--margin-inline-end": string;
|
|
12
|
-
"--margin-block-end": string;
|
|
13
|
-
"--margin-inline-start": string;
|
|
14
|
-
"--padding-block-start": string;
|
|
15
|
-
"--padding-inline-end": string;
|
|
16
|
-
"--padding-block-end": string;
|
|
17
|
-
"--padding-inline-start": string;
|
|
18
|
-
"--background": string;
|
|
19
|
-
"--text-color": string;
|
|
20
|
-
"--border": string;
|
|
21
|
-
"--border-radius": string;
|
|
22
|
-
"--shadow": string;
|
|
23
|
-
};
|
|
24
2
|
/**
|
|
25
3
|
* Generates comprehensive styles for stack components by combining component, dimension and size styles
|
|
26
4
|
* @param props - Stack component properties including background, spacing, size, border etc.
|
|
27
5
|
* @returns CSS style variables object with all stack-specific styles
|
|
28
6
|
*/
|
|
29
|
-
export declare const getStackComponentStyles: (props: StackProps) =>
|
|
30
|
-
|
|
7
|
+
export declare const getStackComponentStyles: (props: StackProps) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Generates styles for badge component within a stack
|
|
10
|
+
* @param props - Stack component properties containing badge configuration
|
|
11
|
+
* @returns CSS style object with badge-specific styles including positioning, dimensions and appearance
|
|
12
|
+
*/
|
|
13
|
+
export declare function getBadgeStyles(props: StackProps): string;
|
|
14
|
+
/**
|
|
15
|
+
* Generates text styles and HTML tag for a stack's badge component
|
|
16
|
+
* @param props - Stack component properties containing badge configuration
|
|
17
|
+
* @returns Object containing:
|
|
18
|
+
* - tagToRender: HTML tag to use for the badge text
|
|
19
|
+
* - textStyles: CSS styles string for the badge text
|
|
20
|
+
*/
|
|
21
|
+
export declare function getStackBadgeTextStyles(props: StackProps): {
|
|
22
|
+
tagToRender: string;
|
|
23
|
+
textStyles: string;
|
|
24
|
+
};
|
|
25
|
+
export type ZStackChildStyles = {
|
|
26
|
+
"--inset": string;
|
|
27
|
+
"--transform": string;
|
|
28
|
+
"--position": string;
|
|
29
|
+
};
|
|
30
|
+
export declare function getZStackChildStyles(props: StackProps): ZStackChildStyles | undefined;
|
|
@@ -1,13 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getTextComponentStyles } from "../text/text-utils";
|
|
2
|
+
import { getActiveStateProps, getComponentStyles, getDimensionStyle, getInsetStyles, getSizeStyle, prefixObject, stringifyStyles, } from "../../utils/style-utils";
|
|
2
3
|
/**
|
|
3
4
|
* Generates comprehensive styles for stack components by combining component, dimension and size styles
|
|
4
5
|
* @param props - Stack component properties including background, spacing, size, border etc.
|
|
5
6
|
* @returns CSS style variables object with all stack-specific styles
|
|
6
7
|
*/
|
|
7
8
|
export const getStackComponentStyles = (props) => {
|
|
8
|
-
const { background_color, margin, padding, spacing, size, border, shape, shadow, dimension, componentState, overrides, purchaseState, } = props;
|
|
9
|
+
const { background_color, margin, padding, spacing, size, border, shape, shadow, dimension, componentState, overrides, purchaseState, zStackChildStyles, } = props;
|
|
10
|
+
const stackStyles = {
|
|
11
|
+
"--flex": "0 1 auto",
|
|
12
|
+
"--height": "initial",
|
|
13
|
+
"--width": "initial",
|
|
14
|
+
"--spacing": `${spacing || 0}px`,
|
|
15
|
+
"--direction": "unset",
|
|
16
|
+
"--alignment": "unset",
|
|
17
|
+
"--distribution": "flex-start",
|
|
18
|
+
"--margin-block-start": "0px",
|
|
19
|
+
"--margin-inline-end": "0px",
|
|
20
|
+
"--margin-block-end": "0px",
|
|
21
|
+
"--margin-inline-start": "0px",
|
|
22
|
+
"--padding-block-start": "0px",
|
|
23
|
+
"--padding-inline-end": "0px",
|
|
24
|
+
"--padding-block-end": "0px",
|
|
25
|
+
"--padding-inline-start": "0px",
|
|
26
|
+
"--background": "unset",
|
|
27
|
+
"--text-color": "inherit",
|
|
28
|
+
"--border": "none",
|
|
29
|
+
"--border-end-start-radius": "0px",
|
|
30
|
+
"--border-end-end-radius": "0px",
|
|
31
|
+
"--border-start-start-radius": "0px",
|
|
32
|
+
"--border-start-end-radius": "0px",
|
|
33
|
+
"--shadow": "none",
|
|
34
|
+
"--position": "relative",
|
|
35
|
+
"--transform": "initial",
|
|
36
|
+
"--inset": "initial",
|
|
37
|
+
};
|
|
9
38
|
const activeStateProps = getActiveStateProps(overrides, componentState);
|
|
10
|
-
|
|
39
|
+
Object.assign(stackStyles, getComponentStyles({
|
|
11
40
|
backgroundColor: background_color,
|
|
12
41
|
margin,
|
|
13
42
|
padding,
|
|
@@ -16,16 +45,220 @@ export const getStackComponentStyles = (props) => {
|
|
|
16
45
|
shape,
|
|
17
46
|
shadow,
|
|
18
47
|
...activeStateProps,
|
|
19
|
-
})
|
|
20
|
-
const dimensionStyles = getDimensionStyle({
|
|
48
|
+
}), getDimensionStyle({
|
|
21
49
|
...dimension,
|
|
22
50
|
...activeStateProps,
|
|
51
|
+
}), getSizeStyle({ ...size, ...activeStateProps }));
|
|
52
|
+
Object.assign(stackStyles, zStackChildStyles);
|
|
53
|
+
const prefixedStyles = prefixObject(stackStyles, "stack");
|
|
54
|
+
return stringifyStyles(prefixedStyles);
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Generates styles for badge component within a stack
|
|
58
|
+
* @param props - Stack component properties containing badge configuration
|
|
59
|
+
* @returns CSS style object with badge-specific styles including positioning, dimensions and appearance
|
|
60
|
+
*/
|
|
61
|
+
export function getBadgeStyles(props) {
|
|
62
|
+
const { badge } = props;
|
|
63
|
+
if (!badge)
|
|
64
|
+
return "";
|
|
65
|
+
const styles = {
|
|
66
|
+
"--inset": "unset",
|
|
67
|
+
"--transform": "unset",
|
|
68
|
+
"--margin-block-start": "0px",
|
|
69
|
+
"--margin-inline-end": "0px",
|
|
70
|
+
"--margin-block-end": "0px",
|
|
71
|
+
"--margin-inline-start": "0px",
|
|
72
|
+
"--padding-block-start": "0px",
|
|
73
|
+
"--padding-inline-end": "0px",
|
|
74
|
+
"--padding-block-end": "0px",
|
|
75
|
+
"--padding-inline-start": "0px",
|
|
76
|
+
"--background": "unset",
|
|
77
|
+
"--text-color": "inherit",
|
|
78
|
+
"--border": "none",
|
|
79
|
+
"--border-end-start-radius": "0px",
|
|
80
|
+
"--border-end-end-radius": "0px",
|
|
81
|
+
"--border-start-start-radius": "0px",
|
|
82
|
+
"--border-start-end-radius": "0px",
|
|
83
|
+
"--shadow": "none",
|
|
84
|
+
"--badge-width": "unset",
|
|
85
|
+
"--z-index": "unset",
|
|
86
|
+
};
|
|
87
|
+
// Calculating this as a zIndex alignment since it behaves in the same way
|
|
88
|
+
// except there's no center alignment
|
|
89
|
+
Object.assign(styles, getInsetStyles({
|
|
90
|
+
type: "zlayer",
|
|
91
|
+
alignment: badge.alignment,
|
|
92
|
+
}), getComponentStyles({
|
|
93
|
+
...badge,
|
|
94
|
+
backgroundColor: badge.background_color,
|
|
95
|
+
textColor: badge.color,
|
|
96
|
+
colorMode: props.purchaseState.colorMode,
|
|
97
|
+
}));
|
|
98
|
+
if (badge.style === "overlay") {
|
|
99
|
+
// Disable vertical margin for nested & center aligned badges
|
|
100
|
+
styles["--margin-block-start"] = "0px";
|
|
101
|
+
styles["--margin-block-end"] = "0px";
|
|
102
|
+
// Vertically center the badge to the edge of the stack
|
|
103
|
+
styles["--transform"] = getBadgeTransformStyles(badge, 0, -(props.border?.width || 0));
|
|
104
|
+
}
|
|
105
|
+
if (badge.style === "edge_to_edge") {
|
|
106
|
+
styles["--margin-block-start"] = "0px";
|
|
107
|
+
styles["--margin-block-end"] = "0px";
|
|
108
|
+
styles["--margin-inline-start"] = "0px";
|
|
109
|
+
styles["--margin-inline-end"] = "0px";
|
|
110
|
+
// Shared props between top and bottom
|
|
111
|
+
if (badge.alignment === "top" || badge.alignment === "bottom") {
|
|
112
|
+
styles["--badge-width"] =
|
|
113
|
+
`calc(100% + ${(props.border?.width || 0) * 2}px)`;
|
|
114
|
+
styles["--z-index"] = "-1";
|
|
115
|
+
const highestRadius = Math.max(props.shape?.corners?.top_leading || 0, props.shape?.corners?.top_trailing || 0);
|
|
116
|
+
// one offs for top and bottom
|
|
117
|
+
if (badge.alignment === "top") {
|
|
118
|
+
styles["--padding-block-end"] =
|
|
119
|
+
`${highestRadius + badge.padding.bottom}px`;
|
|
120
|
+
styles["--transform"] = getBadgeTransformStyles(badge, highestRadius);
|
|
121
|
+
}
|
|
122
|
+
if (badge.alignment === "bottom") {
|
|
123
|
+
styles["--padding-block-start"] =
|
|
124
|
+
`${highestRadius + badge.padding.top}px`;
|
|
125
|
+
styles["--transform"] = getBadgeTransformStyles(badge, -highestRadius);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
styles["--transform"] = getBadgeTransformStyles(badge);
|
|
130
|
+
Object.assign(styles, getBadgeBorderRadiusStyles(props));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const prefixedStyles = prefixObject(styles, "stack-badge");
|
|
134
|
+
return stringifyStyles(prefixedStyles);
|
|
135
|
+
}
|
|
136
|
+
const oppositeCornerDictionary = {
|
|
137
|
+
top_leading: "bottom_trailing",
|
|
138
|
+
top_trailing: "bottom_leading",
|
|
139
|
+
bottom_leading: "top_trailing",
|
|
140
|
+
bottom_trailing: "top_leading",
|
|
141
|
+
};
|
|
142
|
+
const propToCssPropDictionary = {
|
|
143
|
+
top_leading: "--border-start-start-radius",
|
|
144
|
+
top_trailing: "--border-start-end-radius",
|
|
145
|
+
bottom_leading: "--border-end-start-radius",
|
|
146
|
+
bottom_trailing: "--border-end-end-radius",
|
|
147
|
+
};
|
|
148
|
+
function getBadgeBorderRadiusStyles(props) {
|
|
149
|
+
const styles = {
|
|
150
|
+
"--border-end-start-radius": "0px",
|
|
151
|
+
"--border-end-end-radius": "0px",
|
|
152
|
+
"--border-start-start-radius": "0px",
|
|
153
|
+
"--border-start-end-radius": "0px",
|
|
154
|
+
};
|
|
155
|
+
const { badge } = props;
|
|
156
|
+
if (!badge)
|
|
157
|
+
return styles;
|
|
158
|
+
const borderWidth = props.border?.width || 0;
|
|
159
|
+
const badgeAlignment = badge.alignment;
|
|
160
|
+
// badge inner radius
|
|
161
|
+
styles[propToCssPropDictionary[oppositeCornerDictionary[badgeAlignment]]] =
|
|
162
|
+
`${badge.shape?.corners[oppositeCornerDictionary[badgeAlignment]]}px`;
|
|
163
|
+
// badge outer radius
|
|
164
|
+
styles[propToCssPropDictionary[badgeAlignment]] =
|
|
165
|
+
`${props.shape?.corners[badgeAlignment] - borderWidth}px`;
|
|
166
|
+
return styles;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Generates CSS transform styles for badge positioning
|
|
170
|
+
* @param badge - Badge configuration from StackProps
|
|
171
|
+
* @param verticalOffset - Optional vertical offset in pixels for edge-to-edge badges
|
|
172
|
+
* @returns CSS transform string for badge positioning
|
|
173
|
+
*/
|
|
174
|
+
function getBadgeTransformStyles(badge, verticalOffset = 0, horizontalOffset = 0) {
|
|
175
|
+
if (!badge)
|
|
176
|
+
return "";
|
|
177
|
+
if (badge.style === "overlay") {
|
|
178
|
+
if (badge.alignment === "top_leading") {
|
|
179
|
+
return `translate(${horizontalOffset}px, calc(-50% + ${verticalOffset}px))`;
|
|
180
|
+
}
|
|
181
|
+
if (badge.alignment === "top_trailing") {
|
|
182
|
+
return `translate(calc(0% - ${horizontalOffset}px), calc(-50% + ${verticalOffset}px))`;
|
|
183
|
+
}
|
|
184
|
+
if (badge.alignment === "bottom_leading") {
|
|
185
|
+
return `translate(${horizontalOffset}px, calc(50% + ${verticalOffset}px))`;
|
|
186
|
+
}
|
|
187
|
+
if (badge.alignment === "bottom_trailing") {
|
|
188
|
+
return `translate(calc(0% - ${horizontalOffset}px), calc(50% + ${verticalOffset}px))`;
|
|
189
|
+
}
|
|
190
|
+
if (badge.alignment === "top") {
|
|
191
|
+
return `translate(calc(-50% + ${horizontalOffset}px), calc(-50% + ${verticalOffset}px))`;
|
|
192
|
+
}
|
|
193
|
+
if (badge.alignment === "bottom") {
|
|
194
|
+
return `translate(calc(50% + ${horizontalOffset}px), calc(50% + ${verticalOffset}px))`;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (badge.style === "edge_to_edge") {
|
|
198
|
+
if (badge.alignment === "top") {
|
|
199
|
+
return `translate(calc(-50% + ${horizontalOffset}px), calc(-100% - ${verticalOffset}px + 16px))`;
|
|
200
|
+
}
|
|
201
|
+
else if (badge.alignment === "bottom") {
|
|
202
|
+
return `translate(calc(50% + ${horizontalOffset}px), calc(100% + ${verticalOffset}px))`;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return "";
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Generates text styles and HTML tag for a stack's badge component
|
|
209
|
+
* @param props - Stack component properties containing badge configuration
|
|
210
|
+
* @returns Object containing:
|
|
211
|
+
* - tagToRender: HTML tag to use for the badge text
|
|
212
|
+
* - textStyles: CSS styles string for the badge text
|
|
213
|
+
*/
|
|
214
|
+
export function getStackBadgeTextStyles(props) {
|
|
215
|
+
const { badge } = props;
|
|
216
|
+
if (!badge)
|
|
217
|
+
return { tagToRender: "", textStyles: "" };
|
|
218
|
+
const { tagToRender, textStyles } = getTextComponentStyles({
|
|
219
|
+
id: props.id,
|
|
220
|
+
labels: props.labels,
|
|
221
|
+
purchaseState: props.purchaseState,
|
|
222
|
+
...badge,
|
|
223
|
+
components: [],
|
|
224
|
+
type: "text",
|
|
225
|
+
size: {
|
|
226
|
+
width: { type: "fit" },
|
|
227
|
+
height: { type: "fit" },
|
|
228
|
+
},
|
|
229
|
+
color: badge?.color,
|
|
230
|
+
name: props.name,
|
|
23
231
|
});
|
|
24
|
-
const
|
|
232
|
+
const resetSpacing = {
|
|
233
|
+
"--text-margin-block-start": "0px",
|
|
234
|
+
"--text-margin-inline-end": "0px",
|
|
235
|
+
"--text-margin-block-end": "0px",
|
|
236
|
+
"--text-margin-inline-start": "0px",
|
|
237
|
+
"--text-padding-block-start": "0px",
|
|
238
|
+
"--text-padding-inline-end": "0px",
|
|
239
|
+
"--text-padding-block-end": "0px",
|
|
240
|
+
"--text-padding-inline-start": "0px",
|
|
241
|
+
};
|
|
242
|
+
const stylesObject = {
|
|
243
|
+
...textStyles,
|
|
244
|
+
...resetSpacing,
|
|
245
|
+
};
|
|
246
|
+
const stringifiedStyles = stringifyStyles(stylesObject);
|
|
25
247
|
return {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
...componentStyles,
|
|
29
|
-
"--spacing": `${spacing || 0}px`,
|
|
248
|
+
tagToRender,
|
|
249
|
+
textStyles: stringifiedStyles,
|
|
30
250
|
};
|
|
31
|
-
}
|
|
251
|
+
}
|
|
252
|
+
export function getZStackChildStyles(props) {
|
|
253
|
+
const { dimension } = props;
|
|
254
|
+
const baseStyles = {
|
|
255
|
+
"--inset": "initial",
|
|
256
|
+
"--transform": "initial",
|
|
257
|
+
"--position": "relative",
|
|
258
|
+
};
|
|
259
|
+
if (dimension.type !== "zlayer")
|
|
260
|
+
return;
|
|
261
|
+
const insetStyles = getInsetStyles({ ...dimension, type: "zlayer" });
|
|
262
|
+
Object.assign(baseStyles, { ...insetStyles, "--position": "absolute" });
|
|
263
|
+
return baseStyles;
|
|
264
|
+
}
|
|
@@ -16,29 +16,34 @@
|
|
|
16
16
|
}: TextProps = $props();
|
|
17
17
|
</script>
|
|
18
18
|
|
|
19
|
-
<svelte:element
|
|
19
|
+
<svelte:element
|
|
20
|
+
this={component}
|
|
21
|
+
{id}
|
|
22
|
+
style={styleVariables}
|
|
23
|
+
class="rc-pw-text-block"
|
|
24
|
+
>
|
|
20
25
|
{@render children?.()}
|
|
21
26
|
</svelte:element>
|
|
22
27
|
|
|
23
28
|
<style>
|
|
24
|
-
.text-block {
|
|
29
|
+
.rc-pw-text-block {
|
|
25
30
|
display: block;
|
|
26
|
-
padding-block-start: var(--padding-block-start,
|
|
27
|
-
padding-inline-end: var(--padding-inline-end,
|
|
28
|
-
padding-block-end: var(--padding-block-end,
|
|
29
|
-
padding-inline-start: var(--padding-inline-start,
|
|
30
|
-
margin-block-start: var(--margin-block-start,
|
|
31
|
-
margin-inline-end: var(--margin-inline-end,
|
|
32
|
-
margin-block-end: var(--margin-block-end,
|
|
33
|
-
margin-inline-start: var(--margin-inline-start,
|
|
34
|
-
color: var(--text-color, #ffffff);
|
|
35
|
-
background: var(--background, none);
|
|
36
|
-
font-size: var(--font-size, 1rem);
|
|
37
|
-
font-weight: var(--font-weight, normal);
|
|
38
|
-
text-align: var(--text-align, center);
|
|
39
|
-
font-family: var(--font-family, sans-serif);
|
|
40
|
-
-webkit-background-clip: var(--background-clip, initial);
|
|
41
|
-
background-clip: var(--background-clip, initial);
|
|
42
|
-
-webkit-text-fill-color: var(--text-fill-color, initial);
|
|
31
|
+
padding-block-start: var(--text-padding-block-start, initial);
|
|
32
|
+
padding-inline-end: var(--text-padding-inline-end, initial);
|
|
33
|
+
padding-block-end: var(--text-padding-block-end, initial);
|
|
34
|
+
padding-inline-start: var(--text-padding-inline-start, initial);
|
|
35
|
+
margin-block-start: var(--text-margin-block-start, initial);
|
|
36
|
+
margin-inline-end: var(--text-margin-inline-end, initial);
|
|
37
|
+
margin-block-end: var(--text-margin-block-end, initial);
|
|
38
|
+
margin-inline-start: var(--text-margin-inline-start, initial);
|
|
39
|
+
color: var(--text-text-color, #ffffff);
|
|
40
|
+
background: var(--text-background, none);
|
|
41
|
+
font-size: var(--text-font-size, 1rem);
|
|
42
|
+
font-weight: var(--text-font-weight, normal);
|
|
43
|
+
text-align: var(--text-text-align, center);
|
|
44
|
+
font-family: var(--text-font-family, sans-serif);
|
|
45
|
+
-webkit-background-clip: var(--text-background-clip, initial);
|
|
46
|
+
background-clip: var(--text-background-clip, initial);
|
|
47
|
+
-webkit-text-fill-color: var(--text-text-fill-color, initial);
|
|
43
48
|
}
|
|
44
49
|
</style>
|