@revenuecat/purchases-ui-js 2.0.2 → 2.0.3
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/ButtonNode.stories.svelte +66 -102
- package/dist/components/button/ButtonNode.svelte +2 -27
- package/dist/components/footer/Footer.stories.svelte +112 -102
- package/dist/components/footer/Footer.svelte +8 -4
- package/dist/components/icon/Icon.stories.svelte +100 -0
- package/dist/components/icon/Icon.stories.svelte.d.ts +19 -0
- package/dist/components/icon/Icon.svelte +73 -0
- package/dist/components/icon/Icon.svelte.d.ts +4 -0
- package/dist/components/image/ClipPath.svelte +49 -0
- package/dist/components/image/ClipPath.svelte.d.ts +9 -0
- package/dist/components/image/Image.stories.svelte +83 -188
- package/dist/components/image/Image.svelte +152 -136
- package/dist/components/image/Image.svelte.d.ts +1 -1
- package/dist/components/image/Overlay.svelte +36 -0
- package/dist/components/image/Overlay.svelte.d.ts +8 -0
- package/dist/components/package/Package.stories.svelte +10 -21
- package/dist/components/package/Package.svelte +8 -35
- package/dist/components/paywall/Node.svelte +27 -28
- package/dist/components/paywall/Node.svelte.d.ts +3 -6
- package/dist/components/paywall/Paywall.stories.svelte +36 -140
- package/dist/components/paywall/Paywall.svelte +22 -6
- package/dist/components/paywall/Paywall.svelte.d.ts +3 -2
- package/dist/components/paywall/fixtures/override-paywall.d.ts +2 -0
- package/dist/components/paywall/fixtures/override-paywall.js +1310 -0
- package/dist/components/paywall/fixtures/stack-paywall.d.ts +2 -0
- package/dist/components/paywall/fixtures/stack-paywall.js +5223 -0
- package/dist/components/paywall/fixtures/variables.d.ts +261 -0
- package/dist/components/paywall/fixtures/variables.js +262 -0
- package/dist/components/purchase-button/PurchaseButton.stories.svelte +10 -21
- package/dist/components/purchase-button/PurchaseButton.svelte +2 -27
- package/dist/components/stack/Stack.stories.svelte +2354 -978
- package/dist/components/stack/Stack.svelte +111 -134
- package/dist/components/stack/Stack.svelte.d.ts +6 -2
- package/dist/components/stack/stack-utils.d.ts +10 -30
- package/dist/components/stack/stack-utils.js +77 -255
- package/dist/components/text/Text.svelte +3 -37
- package/dist/components/text/Text.svelte.d.ts +1 -2
- package/dist/components/text/TextNode.stories.svelte +10 -36
- package/dist/components/text/TextNode.svelte +25 -28
- package/dist/components/text/TextNode.svelte.d.ts +1 -1
- package/dist/components/text/text-utils.d.ts +4 -9
- package/dist/components/text/text-utils.js +32 -117
- package/dist/components/timeline/Timeline.stories.svelte +640 -251
- package/dist/components/timeline/Timeline.svelte +42 -28
- package/dist/components/timeline/Timeline.svelte.d.ts +1 -1
- package/dist/components/timeline/TimelineItem.svelte +80 -112
- package/dist/components/timeline/TimelineItem.svelte.d.ts +6 -2
- package/dist/components/timeline/timeline-utils.d.ts +24 -6
- package/dist/components/timeline/timeline-utils.js +21 -113
- package/dist/data/entities.d.ts +19 -135
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/stores/color-mode.d.ts +1 -1
- package/dist/stores/paywall.d.ts +5 -2
- package/dist/stores/selected.d.ts +5 -0
- package/dist/stores/selected.js +12 -0
- package/dist/stores/variables.d.ts +1 -1
- package/dist/stores/variables.js +0 -1
- package/dist/stories/component-decorator.d.ts +2 -0
- package/dist/stories/component-decorator.js +12 -0
- package/dist/stories/fixtures.d.ts +5 -3
- package/dist/stories/fixtures.js +5214 -4422
- package/dist/stories/paywall-decorator.js +6 -0
- package/dist/stories/variables-decorator.d.ts +1 -1
- package/dist/stories/viewport-decorator.d.ts +2 -0
- package/dist/stories/viewport-decorator.js +8 -0
- package/dist/stories/viewport-wrapper.svelte +53 -0
- package/dist/stories/viewport-wrapper.svelte.d.ts +10 -0
- package/dist/stories/with-layout.d.ts +2 -10
- package/dist/stories/with-layout.js +3 -5
- package/dist/types/alignment.d.ts +5 -3
- package/dist/types/background.d.ts +6 -5
- package/dist/types/base.d.ts +7 -0
- package/dist/types/base.js +1 -0
- package/dist/types/colors.d.ts +4 -4
- package/dist/types/component.d.ts +6 -2
- package/dist/types/components/button.d.ts +4 -1
- package/dist/types/components/footer.d.ts +2 -1
- package/dist/types/components/icon.d.ts +28 -0
- package/dist/types/components/icon.js +1 -0
- package/dist/types/components/image.d.ts +20 -0
- package/dist/types/components/image.js +1 -0
- package/dist/types/components/package.d.ts +2 -1
- package/dist/types/components/purchase-button.d.ts +2 -1
- package/dist/types/components/stack.d.ts +32 -0
- package/dist/types/components/stack.js +1 -0
- package/dist/types/components/text.d.ts +20 -0
- package/dist/types/components/text.js +1 -0
- package/dist/types/components/timeline.d.ts +35 -0
- package/dist/types/components/timeline.js +1 -0
- package/dist/types/localization.d.ts +2 -1
- package/dist/types/media.d.ts +4 -3
- package/dist/types/overrides.d.ts +48 -0
- package/dist/types/overrides.js +1 -0
- package/dist/types/variables.d.ts +13 -0
- package/dist/types/variables.js +10 -0
- package/dist/types.d.ts +17 -9
- package/dist/ui/atoms/typography.stories.svelte +1 -27
- package/dist/ui/molecules/button.stories.svelte +3 -8
- package/dist/ui/theme/colors.d.ts +0 -6
- package/dist/ui/theme/colors.js +1 -1
- package/dist/ui/theme/text.d.ts +3 -4
- package/dist/ui/theme/utils.d.ts +0 -10
- package/dist/ui/theme/utils.js +5 -5
- package/dist/utils/background-utils.d.ts +4 -0
- package/dist/utils/background-utils.js +39 -0
- package/dist/utils/base-utils.d.ts +18 -0
- package/dist/utils/base-utils.js +124 -0
- package/dist/utils/constants.d.ts +2 -2
- package/dist/utils/constants.js +6 -1
- package/dist/utils/font-utils.d.ts +4 -0
- package/dist/utils/font-utils.js +47 -0
- package/dist/utils/style-utils.d.ts +7 -120
- package/dist/utils/style-utils.js +22 -302
- package/dist/utils/variable-utils.d.ts +1 -22
- package/dist/utils/variable-utils.js +28 -24
- package/dist/web-components/index.css +1 -1
- package/dist/web-components/index.js +1323 -895
- package/package.json +34 -24
- package/dist/components/button/button-utils.d.ts +0 -2
- package/dist/components/button/button-utils.js +0 -19
- package/dist/components/image/image-utils.d.ts +0 -19
- package/dist/components/image/image-utils.js +0 -33
- package/dist/components/purchase-button/purchase-button-utils.d.ts +0 -2
- package/dist/components/purchase-button/purchase-button-utils.js +0 -20
- package/dist/stories/meta-templates.d.ts +0 -12
- package/dist/stories/meta-templates.js +0 -155
|
@@ -1,157 +1,134 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import Node from "../paywall/Node.svelte";
|
|
3
|
-
import {
|
|
4
|
-
getBadgeStyles,
|
|
5
|
-
getStackBadgeTextStyles,
|
|
6
|
-
getStackComponentStyles,
|
|
7
|
-
getZStackChildStyles,
|
|
8
|
-
} from "./stack-utils";
|
|
9
|
-
import Text from "../text/Text.svelte";
|
|
10
|
-
import type { StackProps } from "../../data/entities";
|
|
11
3
|
import { getColorModeContext } from "../../stores/color-mode";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
4
|
+
import { getSelectedStateContext } from "../../stores/selected";
|
|
5
|
+
import type { StackProps } from "../../types/components/stack";
|
|
6
|
+
import { mapBackground } from "../../utils/background-utils";
|
|
7
|
+
import {
|
|
8
|
+
css,
|
|
9
|
+
mapBorder,
|
|
10
|
+
mapBorderRadius,
|
|
11
|
+
mapShadow,
|
|
12
|
+
mapSize,
|
|
13
|
+
mapSpacing,
|
|
14
|
+
px,
|
|
15
|
+
} from "../../utils/base-utils";
|
|
16
|
+
import { getActiveStateProps } from "../../utils/style-utils";
|
|
17
|
+
import { mapBadge, mapDimension, mapLayerAlignment } from "./stack-utils";
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
interface MiscProps {
|
|
20
|
+
onclick?: () => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const props: StackProps & MiscProps = $props();
|
|
24
|
+
const selectedState = getSelectedStateContext();
|
|
25
|
+
const {
|
|
26
|
+
components,
|
|
27
|
+
size,
|
|
28
|
+
dimension,
|
|
29
|
+
spacing,
|
|
30
|
+
margin,
|
|
31
|
+
padding,
|
|
32
|
+
background_color,
|
|
33
|
+
background,
|
|
34
|
+
border,
|
|
35
|
+
shape,
|
|
36
|
+
shadow,
|
|
37
|
+
badge,
|
|
38
|
+
onclick,
|
|
39
|
+
} = $derived.by(() => {
|
|
40
|
+
return {
|
|
41
|
+
...props,
|
|
42
|
+
...getActiveStateProps($selectedState, props.overrides),
|
|
43
|
+
};
|
|
44
|
+
});
|
|
18
45
|
|
|
19
46
|
const getColorMode = getColorModeContext();
|
|
20
47
|
const colorMode = $derived(getColorMode());
|
|
21
48
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
49
|
+
const style = $derived(
|
|
50
|
+
css({
|
|
51
|
+
display: "flex",
|
|
52
|
+
position: "relative",
|
|
53
|
+
width: mapSize(size.width),
|
|
54
|
+
height: mapSize(size.height),
|
|
55
|
+
...mapDimension(dimension),
|
|
56
|
+
gap: px(spacing),
|
|
57
|
+
margin: mapSpacing(margin),
|
|
58
|
+
padding: mapSpacing(padding),
|
|
59
|
+
...mapBackground(colorMode, background_color, background),
|
|
60
|
+
border: mapBorder(colorMode, border),
|
|
61
|
+
"border-radius": mapBorderRadius(shape),
|
|
62
|
+
"box-shadow": mapShadow(colorMode, shadow),
|
|
36
63
|
}),
|
|
37
64
|
);
|
|
38
65
|
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
...restProps,
|
|
44
|
-
}),
|
|
45
|
-
);
|
|
66
|
+
const getLayerStyle = (index: number): string => {
|
|
67
|
+
if (index === 0 || dimension.type !== "zlayer") {
|
|
68
|
+
return "";
|
|
69
|
+
}
|
|
46
70
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
71
|
+
const { justifyContent, alignItems } = mapLayerAlignment(
|
|
72
|
+
dimension.alignment,
|
|
73
|
+
);
|
|
74
|
+
return css({
|
|
75
|
+
position: "absolute",
|
|
76
|
+
inset: 0,
|
|
77
|
+
display: "flex",
|
|
78
|
+
"justify-content": justifyContent,
|
|
79
|
+
"align-items": alignItems,
|
|
80
|
+
"z-index": index + 1,
|
|
81
|
+
});
|
|
82
|
+
};
|
|
52
83
|
|
|
53
|
-
const
|
|
54
|
-
getStackBadgeTextStyles(colorMode, {
|
|
55
|
-
id,
|
|
56
|
-
components,
|
|
57
|
-
badge,
|
|
58
|
-
...restProps,
|
|
59
|
-
}),
|
|
60
|
-
);
|
|
84
|
+
const badgeStyle = $derived(css(mapBadge(badge, border?.width)));
|
|
61
85
|
</script>
|
|
62
86
|
|
|
63
|
-
<
|
|
87
|
+
<svelte:element
|
|
88
|
+
this={onclick !== undefined ? "button" : "div"}
|
|
89
|
+
role={onclick !== undefined ? "button" : undefined}
|
|
90
|
+
{onclick}
|
|
91
|
+
{style}
|
|
92
|
+
class="stack"
|
|
93
|
+
>
|
|
64
94
|
{#if badge}
|
|
65
|
-
<
|
|
66
|
-
<
|
|
67
|
-
|
|
68
|
-
</Text>
|
|
69
|
-
</span>
|
|
95
|
+
<div style={badgeStyle}>
|
|
96
|
+
<Node nodeData={badge.stack} />
|
|
97
|
+
</div>
|
|
70
98
|
{/if}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
99
|
+
|
|
100
|
+
{#if dimension.type === "zlayer"}
|
|
101
|
+
<div style="position: relative; width: 100%; height: 100%;">
|
|
102
|
+
{#each components as component, index}
|
|
103
|
+
<div style={getLayerStyle(index)}>
|
|
104
|
+
<Node nodeData={component} />
|
|
105
|
+
</div>
|
|
106
|
+
{/each}
|
|
107
|
+
</div>
|
|
108
|
+
{:else}
|
|
109
|
+
{#each components as component}
|
|
110
|
+
<Node nodeData={component} />
|
|
82
111
|
{/each}
|
|
83
|
-
|
|
84
|
-
</
|
|
112
|
+
{/if}
|
|
113
|
+
</svelte:element>
|
|
85
114
|
|
|
86
115
|
<style>
|
|
87
|
-
.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
width: var(--stack-width, unset);
|
|
91
|
-
height: var(--stack-height, unset);
|
|
92
|
-
box-shadow: var(--stack-shadow, none);
|
|
93
|
-
background: var(--stack-background, unset);
|
|
94
|
-
position: var(--stack-position, relative);
|
|
95
|
-
transform: var(--stack-transform, initial);
|
|
96
|
-
inset: var(--stack-inset, initial);
|
|
97
|
-
margin-block-start: var(--stack-margin-block-start, 0);
|
|
98
|
-
margin-inline-end: var(--stack-margin-inline-end, 0);
|
|
99
|
-
margin-block-end: var(--stack-margin-block-end, 0);
|
|
100
|
-
margin-inline-start: var(--stack-margin-inline-start, 0);
|
|
101
|
-
border: var(--stack-border, none);
|
|
102
|
-
border-end-start-radius: var(--stack-border-end-start-radius, 0px);
|
|
103
|
-
border-end-end-radius: var(--stack-border-end-end-radius, 0px);
|
|
104
|
-
border-start-start-radius: var(--stack-border-start-start-radius, 0px);
|
|
105
|
-
border-start-end-radius: var(--stack-border-start-end-radius, 0px);
|
|
106
|
-
}
|
|
116
|
+
.stack {
|
|
117
|
+
appearance: none;
|
|
118
|
+
position: relative;
|
|
107
119
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
padding-inline-end: var(--stack-padding-inline-end, 0);
|
|
122
|
-
padding-block-end: var(--stack-padding-block-end, 0);
|
|
123
|
-
padding-inline-start: var(--stack-padding-inline-start, 0);
|
|
124
|
-
}
|
|
125
|
-
.rc-pw-badge {
|
|
126
|
-
box-sizing: border-box;
|
|
127
|
-
font-family: var(--stack-badge-font-family, sans-serif);
|
|
128
|
-
position: absolute;
|
|
129
|
-
inset: var(--stack-badge-inset, unset);
|
|
130
|
-
transform: var(--stack-badge-transform, initial);
|
|
131
|
-
margin-block-start: var(--stack-badge-margin-block-start, 0px);
|
|
132
|
-
margin-inline-end: var(--stack-badge-margin-inline-end, 0px);
|
|
133
|
-
margin-block-end: var(--stack-badge-margin-block-end, 0px);
|
|
134
|
-
margin-inline-start: var(--stack-badge-margin-inline-start, 0px);
|
|
135
|
-
padding-block-start: var(--stack-badge-padding-block-start, 0px);
|
|
136
|
-
padding-inline-end: var(--stack-badge-padding-inline-end, 0px);
|
|
137
|
-
padding-block-end: var(--stack-badge-padding-block-end, 0px);
|
|
138
|
-
padding-inline-start: var(--stack-badge-padding-inline-start, 0px);
|
|
139
|
-
background: var(--stack-badge-background, initial);
|
|
140
|
-
color: var(--stack-badge-text-color, inherit);
|
|
141
|
-
border: var(--stack-badge-border, none);
|
|
142
|
-
border-end-start-radius: var(--stack-badge-border-end-start-radius, 0px);
|
|
143
|
-
border-end-end-radius: var(--stack-badge-border-end-end-radius, 0px);
|
|
144
|
-
border-start-start-radius: var(
|
|
145
|
-
--stack-badge-border-start-start-radius,
|
|
146
|
-
0px
|
|
147
|
-
);
|
|
148
|
-
border-start-end-radius: var(--stack-badge-border-start-end-radius, 0px);
|
|
149
|
-
box-shadow: var(--stack-badge-shadow, none);
|
|
150
|
-
display: flex;
|
|
151
|
-
align-items: center;
|
|
152
|
-
justify-content: center;
|
|
153
|
-
width: var(--stack-badge-badge-width, max-content);
|
|
154
|
-
height: var(--stack-badge-badge-height, max-content);
|
|
155
|
-
z-index: var(--stack-badge-z-index, 1);
|
|
120
|
+
&[role="button"] {
|
|
121
|
+
cursor: pointer;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
&::before {
|
|
125
|
+
content: "";
|
|
126
|
+
position: absolute;
|
|
127
|
+
top: 0;
|
|
128
|
+
left: 0;
|
|
129
|
+
width: 100%;
|
|
130
|
+
height: 100%;
|
|
131
|
+
background: var(--overlay);
|
|
132
|
+
}
|
|
156
133
|
}
|
|
157
134
|
</style>
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import type { StackProps } from "../../
|
|
2
|
-
|
|
1
|
+
import type { StackProps } from "../../types/components/stack";
|
|
2
|
+
interface MiscProps {
|
|
3
|
+
onclick?: () => void;
|
|
4
|
+
}
|
|
5
|
+
type $$ComponentProps = StackProps & MiscProps;
|
|
6
|
+
declare const Stack: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
3
7
|
type Stack = ReturnType<typeof Stack>;
|
|
4
8
|
export default Stack;
|
|
@@ -1,31 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export declare const getStackComponentStyles: (colorMode: ColorMode, props: StackProps) => string;
|
|
9
|
-
/**
|
|
10
|
-
* Generates styles for badge component within a stack
|
|
11
|
-
* @param props - Stack component properties containing badge configuration
|
|
12
|
-
* @returns CSS style object with badge-specific styles including positioning, dimensions and appearance
|
|
13
|
-
*/
|
|
14
|
-
export declare function getBadgeStyles(colorMode: ColorMode, props: StackProps): string;
|
|
15
|
-
/**
|
|
16
|
-
* Generates text styles and HTML tag for a stack's badge component
|
|
17
|
-
* @param props - Stack component properties containing badge configuration
|
|
18
|
-
* @returns Object containing:
|
|
19
|
-
* - tagToRender: HTML tag to use for the badge text
|
|
20
|
-
* - textStyles: CSS styles string for the badge text
|
|
21
|
-
*/
|
|
22
|
-
export declare function getStackBadgeTextStyles(colorMode: ColorMode, props: StackProps): {
|
|
23
|
-
tagToRender: string;
|
|
24
|
-
textStyles: string;
|
|
25
|
-
};
|
|
26
|
-
export declare function getZStackChildStyles(props: StackProps): ZStackChildStyles | undefined;
|
|
27
|
-
export type ZStackChildStyles = {
|
|
28
|
-
"--inset": string;
|
|
29
|
-
"--transform": string;
|
|
30
|
-
"--position": string;
|
|
1
|
+
import type { Dimension, ZAlignment } from "../../types/alignment";
|
|
2
|
+
import type { Badge } from "../../types/components/stack";
|
|
3
|
+
import { type CSS } from "../../utils/base-utils";
|
|
4
|
+
export declare function mapDimension(dimension: Dimension): Record<string, string>;
|
|
5
|
+
type JustifyAlign = {
|
|
6
|
+
justifyContent: string;
|
|
7
|
+
alignItems: string;
|
|
31
8
|
};
|
|
9
|
+
export declare function mapLayerAlignment(alignment: ZAlignment): JustifyAlign;
|
|
10
|
+
export declare function mapBadge(badge?: Badge | null, parentBorderWidth?: number): CSS;
|
|
11
|
+
export {};
|
|
@@ -1,261 +1,83 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
};
|
|
38
|
-
const activeStateProps = getActiveStateProps(overrides, componentState);
|
|
39
|
-
Object.assign(stackStyles, getComponentStyles({
|
|
40
|
-
background_color,
|
|
41
|
-
margin,
|
|
42
|
-
padding,
|
|
43
|
-
border,
|
|
44
|
-
colorMode,
|
|
45
|
-
shape,
|
|
46
|
-
shadow,
|
|
47
|
-
...activeStateProps,
|
|
48
|
-
}), getDimensionStyle({
|
|
49
|
-
...dimension,
|
|
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(colorMode, 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
|
-
background_color: badge.background_color,
|
|
95
|
-
color: badge.color,
|
|
96
|
-
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));
|
|
1
|
+
import { px } from "../../utils/base-utils";
|
|
2
|
+
const ALIGNMENT_MAP = Object.freeze({
|
|
3
|
+
leading: "flex-start",
|
|
4
|
+
top: "flex-start",
|
|
5
|
+
center: "center",
|
|
6
|
+
trailing: "flex-end",
|
|
7
|
+
bottom: "flex-end",
|
|
8
|
+
});
|
|
9
|
+
const DISTRIBUTION_MAP = Object.freeze({
|
|
10
|
+
space_between: "space-between",
|
|
11
|
+
space_around: "space-around",
|
|
12
|
+
space_evenly: "space-evenly",
|
|
13
|
+
start: "flex-start",
|
|
14
|
+
center: "center",
|
|
15
|
+
end: "flex-end",
|
|
16
|
+
});
|
|
17
|
+
export function mapDimension(dimension) {
|
|
18
|
+
if (dimension.type === "zlayer") {
|
|
19
|
+
return {};
|
|
104
20
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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",
|
|
21
|
+
const direction = dimension.type === "vertical" ? "column" : "row";
|
|
22
|
+
const justify = DISTRIBUTION_MAP[dimension.distribution] || "center";
|
|
23
|
+
const align = ALIGNMENT_MAP[dimension.alignment] || "center";
|
|
24
|
+
return {
|
|
25
|
+
"flex-direction": direction,
|
|
26
|
+
"justify-content": justify,
|
|
27
|
+
"align-items": align,
|
|
154
28
|
};
|
|
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
29
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
}
|
|
30
|
+
const Z_ALIGNMENT_MAP = Object.freeze({
|
|
31
|
+
top_leading: { justifyContent: "flex-start", alignItems: "flex-start" },
|
|
32
|
+
top: { justifyContent: "center", alignItems: "flex-start" },
|
|
33
|
+
top_trailing: { justifyContent: "flex-end", alignItems: "flex-start" },
|
|
34
|
+
leading: { justifyContent: "flex-start", alignItems: "center" },
|
|
35
|
+
center: { justifyContent: "center", alignItems: "center" },
|
|
36
|
+
trailing: { justifyContent: "flex-end", alignItems: "center" },
|
|
37
|
+
bottom_leading: { justifyContent: "flex-start", alignItems: "flex-end" },
|
|
38
|
+
bottom: { justifyContent: "center", alignItems: "flex-end" },
|
|
39
|
+
bottom_trailing: { justifyContent: "flex-end", alignItems: "flex-end" },
|
|
40
|
+
});
|
|
41
|
+
export function mapLayerAlignment(alignment) {
|
|
42
|
+
return Z_ALIGNMENT_MAP[alignment];
|
|
43
|
+
}
|
|
44
|
+
export function mapBadge(badge, parentBorderWidth) {
|
|
45
|
+
if (badge == null) {
|
|
46
|
+
return {};
|
|
196
47
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
48
|
+
const { style, alignment } = badge;
|
|
49
|
+
const isTop = alignment.startsWith("top");
|
|
50
|
+
const isLeading = alignment.endsWith("leading");
|
|
51
|
+
const isTrailing = alignment.endsWith("trailing");
|
|
52
|
+
const isCenter = !isLeading && !isTrailing;
|
|
53
|
+
const offset = parentBorderWidth ?? 0;
|
|
54
|
+
if (style === "overlay") {
|
|
55
|
+
const translateX = isCenter ? "translateX(-50%)" : "";
|
|
56
|
+
const translateY = isTop ? "translateY(-50%)" : "translateY(50%)";
|
|
57
|
+
return {
|
|
58
|
+
"z-index": 10,
|
|
59
|
+
position: "absolute",
|
|
60
|
+
width: "max-content",
|
|
61
|
+
top: isTop ? px(-offset / 2) : "initial",
|
|
62
|
+
bottom: !isTop ? px(-offset / 2) : "initial",
|
|
63
|
+
left: isLeading ? px(-offset) : isCenter ? "50%" : "initial",
|
|
64
|
+
right: isTrailing ? px(-offset) : "initial",
|
|
65
|
+
transform: `${translateX} ${translateY}`,
|
|
66
|
+
};
|
|
204
67
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
...badge,
|
|
221
|
-
type: "text",
|
|
222
|
-
size: {
|
|
223
|
-
width: { type: "fit" },
|
|
224
|
-
height: { type: "fit" },
|
|
225
|
-
},
|
|
226
|
-
color: badge?.color,
|
|
227
|
-
name: props.name,
|
|
228
|
-
});
|
|
229
|
-
const resetSpacing = {
|
|
230
|
-
"--text-margin-block-start": "0px",
|
|
231
|
-
"--text-margin-inline-end": "0px",
|
|
232
|
-
"--text-margin-block-end": "0px",
|
|
233
|
-
"--text-margin-inline-start": "0px",
|
|
234
|
-
"--text-padding-block-start": "0px",
|
|
235
|
-
"--text-padding-inline-end": "0px",
|
|
236
|
-
"--text-padding-block-end": "0px",
|
|
237
|
-
"--text-padding-inline-start": "0px",
|
|
238
|
-
};
|
|
239
|
-
const stylesObject = {
|
|
240
|
-
...textStyles,
|
|
241
|
-
...resetSpacing,
|
|
242
|
-
};
|
|
243
|
-
const stringifiedStyles = stringifyStyles(stylesObject);
|
|
244
|
-
return {
|
|
245
|
-
tagToRender,
|
|
246
|
-
textStyles: stringifiedStyles,
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
export function getZStackChildStyles(props) {
|
|
250
|
-
const { dimension } = props;
|
|
251
|
-
const baseStyles = {
|
|
252
|
-
"--inset": "initial",
|
|
253
|
-
"--transform": "initial",
|
|
254
|
-
"--position": "relative",
|
|
255
|
-
};
|
|
256
|
-
if (dimension.type !== "zlayer")
|
|
257
|
-
return;
|
|
258
|
-
const insetStyles = getInsetStyles({ ...dimension, type: "zlayer" });
|
|
259
|
-
Object.assign(baseStyles, { ...insetStyles, "--position": "absolute" });
|
|
260
|
-
return baseStyles;
|
|
68
|
+
if (style === "nested") {
|
|
69
|
+
return {
|
|
70
|
+
"z-index": 10,
|
|
71
|
+
position: "absolute",
|
|
72
|
+
inset: 0,
|
|
73
|
+
display: "flex",
|
|
74
|
+
top: isTop ? px(offset) : "initial",
|
|
75
|
+
bottom: !isTop ? px(offset) : "initial",
|
|
76
|
+
left: isLeading ? px(offset) : isCenter ? "50%" : "initial",
|
|
77
|
+
right: isTrailing ? px(offset) : "initial",
|
|
78
|
+
transform: isCenter ? "translateX(-50%)" : "initial",
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
// Not supported yet.
|
|
82
|
+
return {};
|
|
261
83
|
}
|