@stigg/react-sdk 4.3.0-beta.0 → 4.3.0-beta.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.
- package/dist/components/checkout/CheckoutContainer.style.d.ts +0 -3
- package/dist/components/checkout/CheckoutProvider.d.ts +2 -0
- package/dist/components/checkout/hooks/useLoadCheckout.d.ts +1 -3
- package/dist/components/checkout/index.d.ts +1 -1
- package/dist/components/checkout/theme.d.ts +6 -2
- package/dist/components/common/mapExternalTheme.d.ts +2 -3
- package/dist/index.d.ts +1 -1
- package/dist/react-sdk.cjs.development.js +111 -85
- package/dist/react-sdk.cjs.development.js.map +1 -1
- package/dist/react-sdk.cjs.production.min.js +1 -1
- package/dist/react-sdk.cjs.production.min.js.map +1 -1
- package/dist/react-sdk.esm.js +113 -90
- package/dist/react-sdk.esm.js.map +1 -1
- package/dist/stories/CustomerPortal.stories.d.ts +1 -1
- package/package.json +2 -2
- package/src/components/checkout/CheckoutContainer.style.ts +3 -3
- package/src/components/checkout/CheckoutContainer.tsx +3 -7
- package/src/components/checkout/CheckoutProvider.tsx +9 -4
- package/src/components/checkout/CheckoutSummary.tsx +1 -1
- package/src/components/checkout/components/InputField.tsx +1 -2
- package/src/components/checkout/hooks/useLoadCheckout.ts +1 -1
- package/src/components/checkout/index.ts +1 -1
- package/src/components/checkout/steps/payment/stripe/StripePaymentForm.tsx +2 -2
- package/src/components/checkout/steps/plan/BillingPeriodPicker.style.tsx +1 -1
- package/src/components/checkout/theme.ts +31 -14
- package/src/components/common/mapExternalTheme.ts +22 -12
- package/src/index.ts +1 -1
- package/src/stories/Checkout.stories.tsx +4 -1
- package/src/stories/CustomerPortal.stories.tsx +1 -1
- package/dist/components/checkout/types.d.ts +0 -7
- package/src/components/checkout/types.ts +0 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const _default: import("@storybook/csf").ComponentAnnotations<import("@storybook/react").ReactFramework, import("..").
|
|
1
|
+
declare const _default: import("@storybook/csf").ComponentAnnotations<import("@storybook/react").ReactFramework, import("..").CustomerPortalProps>;
|
|
2
2
|
export default _default;
|
|
3
3
|
export declare const DefaultCustomerPortal: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, any>;
|
|
4
4
|
export declare const CustomerPortalTheming: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, any>;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "4.3.0-beta.
|
|
2
|
+
"version": "4.3.0-beta.1",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"@emotion/react": "^11.10.5",
|
|
86
86
|
"@emotion/styled": "^11.10.5",
|
|
87
87
|
"@mui/material": "^5.10.13",
|
|
88
|
-
"@stigg/js-client-sdk": "2.19.
|
|
88
|
+
"@stigg/js-client-sdk": "2.19.1",
|
|
89
89
|
"@stripe/react-stripe-js": "^2.1.1",
|
|
90
90
|
"@stripe/stripe-js": "^1.54.1",
|
|
91
91
|
"@types/styled-components": "^5.1.26",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import styled from '@emotion/styled/macro';
|
|
2
2
|
import Box from '@mui/material/Box';
|
|
3
3
|
|
|
4
|
-
export const CheckoutLayout = styled.div
|
|
4
|
+
export const CheckoutLayout = styled.div`
|
|
5
5
|
margin: auto;
|
|
6
6
|
width: 100%;
|
|
7
7
|
max-width: 920px;
|
|
@@ -11,8 +11,8 @@ export const CheckoutLayout = styled.div<{ $backgroundColor: string; $borderColo
|
|
|
11
11
|
|
|
12
12
|
padding: 16px 32px;
|
|
13
13
|
border-radius: 10px;
|
|
14
|
-
background-color: ${({
|
|
15
|
-
border: ${({
|
|
14
|
+
background-color: ${({ theme }) => theme.stigg.palette.backgroundPaper};
|
|
15
|
+
border: ${({ theme }) => `1px solid ${theme.stigg.palette.outlinedBorder}`};
|
|
16
16
|
|
|
17
17
|
& * {
|
|
18
18
|
box-sizing: border-box;
|
|
@@ -10,7 +10,7 @@ import { PaymentStep } from './steps/payment';
|
|
|
10
10
|
import { useStripeIntegration } from './steps/payment/stripe';
|
|
11
11
|
import { CheckoutPlanStep } from './steps/plan';
|
|
12
12
|
import { ApplySubscription, CheckoutStatePlan } from '@stigg/js-client-sdk';
|
|
13
|
-
import {
|
|
13
|
+
import { useCheckoutContext } from './CheckoutProvider';
|
|
14
14
|
|
|
15
15
|
// import { SurpriseStep } from './steps/surprise/SurpriseStep';
|
|
16
16
|
|
|
@@ -46,7 +46,7 @@ export type CheckoutContainerProps = {
|
|
|
46
46
|
|
|
47
47
|
export function CheckoutContainer({ onCheckout, onCheckoutCompleted, onChangePlan }: CheckoutContainerProps) {
|
|
48
48
|
const { stripePromise, setupIntentClientSecret } = useStripeIntegration();
|
|
49
|
-
const stiggTheme =
|
|
49
|
+
const [{ stiggTheme }] = useCheckoutContext();
|
|
50
50
|
const { progressBarState } = useProgressBarModel();
|
|
51
51
|
const { activeStep } = progressBarState;
|
|
52
52
|
|
|
@@ -73,11 +73,7 @@ export function CheckoutContainer({ onCheckout, onCheckoutCompleted, onChangePla
|
|
|
73
73
|
},
|
|
74
74
|
}}
|
|
75
75
|
>
|
|
76
|
-
<CheckoutLayout
|
|
77
|
-
className="stigg-checkout-layout"
|
|
78
|
-
$backgroundColor={stiggTheme.palette.backgroundPaper}
|
|
79
|
-
$borderColor={stiggTheme.palette.outlinedBorder}
|
|
80
|
-
>
|
|
76
|
+
<CheckoutLayout className="stigg-checkout-layout">
|
|
81
77
|
<CheckoutProgressBar />
|
|
82
78
|
<CheckoutContent>
|
|
83
79
|
<CheckoutPanel>
|
|
@@ -3,7 +3,7 @@ import React, { useCallback, useContext, useMemo, useState } from 'react';
|
|
|
3
3
|
|
|
4
4
|
import { BillableFeature, BillingPeriod, GetCheckoutStateResults } from '@stigg/js-client-sdk';
|
|
5
5
|
|
|
6
|
-
import { SdkThemeProvider, useStiggTheme } from '../../theme/Theme';
|
|
6
|
+
import { CustomizedTheme, SdkThemeProvider, useStiggTheme } from '../../theme/Theme';
|
|
7
7
|
import { DeepPartial } from '../../types';
|
|
8
8
|
import { mapCheckoutConfiguration } from '../common/mapExternalTheme';
|
|
9
9
|
import {
|
|
@@ -20,10 +20,12 @@ import {
|
|
|
20
20
|
} from './hooks';
|
|
21
21
|
import { CheckoutLocalization, getResolvedCheckoutLocalize } from './textOverrides';
|
|
22
22
|
import { CheckoutTheme, getResolvedCheckoutTheme } from './theme';
|
|
23
|
+
import { StiggTheme } from '../../theme/types';
|
|
23
24
|
|
|
24
25
|
export interface CheckoutContextState {
|
|
25
26
|
checkout?: GetCheckoutStateResults | null;
|
|
26
27
|
checkoutLocalization: CheckoutLocalization;
|
|
28
|
+
stiggTheme: StiggTheme;
|
|
27
29
|
theme: CheckoutTheme;
|
|
28
30
|
isLoading: boolean;
|
|
29
31
|
resourceId?: string;
|
|
@@ -90,8 +92,10 @@ export function CheckoutProvider({
|
|
|
90
92
|
children: React.ReactNode;
|
|
91
93
|
} & CheckoutProviderProps) {
|
|
92
94
|
const { checkout, isLoading } = useLoadCheckout({ resourceId, planId, billingCountryCode });
|
|
93
|
-
const configuration = checkout?.configuration
|
|
94
|
-
|
|
95
|
+
const configuration: CustomizedTheme | undefined = checkout?.configuration
|
|
96
|
+
? mapCheckoutConfiguration(checkout.configuration)
|
|
97
|
+
: undefined;
|
|
98
|
+
const globalTheme: StiggTheme = useStiggTheme(configuration);
|
|
95
99
|
const checkoutTheme = getResolvedCheckoutTheme(globalTheme, theme, checkout?.configuration);
|
|
96
100
|
const checkoutLocalization = getResolvedCheckoutLocalize(textOverrides);
|
|
97
101
|
|
|
@@ -115,6 +119,7 @@ export function CheckoutProvider({
|
|
|
115
119
|
checkout,
|
|
116
120
|
isLoading,
|
|
117
121
|
checkoutLocalization,
|
|
122
|
+
stiggTheme: globalTheme,
|
|
118
123
|
theme: checkoutTheme,
|
|
119
124
|
progressBar,
|
|
120
125
|
planStep,
|
|
@@ -125,7 +130,7 @@ export function CheckoutProvider({
|
|
|
125
130
|
};
|
|
126
131
|
|
|
127
132
|
return initialState;
|
|
128
|
-
}, [billingCountryCode, preferredBillingPeriod, checkout]);
|
|
133
|
+
}, [theme, globalTheme, billingCountryCode, preferredBillingPeriod, checkout]);
|
|
129
134
|
|
|
130
135
|
return (
|
|
131
136
|
<SdkThemeProvider key={checkout?.plan.id} componentTheme={configuration}>
|
|
@@ -3,6 +3,7 @@ import { OutlinedInputProps, TextField } from '@mui/material';
|
|
|
3
3
|
|
|
4
4
|
export const InputField = styled(TextField)<OutlinedInputProps>(({ theme }) => ({
|
|
5
5
|
'& .MuiOutlinedInput-root': {
|
|
6
|
+
height: '42px',
|
|
6
7
|
borderRadius: theme.stigg.border.radius,
|
|
7
8
|
fieldset: {
|
|
8
9
|
borderColor: theme.stigg.palette.outlinedBorder,
|
|
@@ -17,7 +18,5 @@ export const InputField = styled(TextField)<OutlinedInputProps>(({ theme }) => (
|
|
|
17
18
|
fontFamily: theme.stigg.typography.fontFamily,
|
|
18
19
|
color: theme.stigg.palette.text.primary,
|
|
19
20
|
...theme.stigg.typography.body,
|
|
20
|
-
|
|
21
|
-
height: '42px',
|
|
22
21
|
},
|
|
23
22
|
}));
|
|
@@ -12,7 +12,7 @@ type useLoadCheckoutProps = {
|
|
|
12
12
|
export function useLoadCheckout({ planId, resourceId, billingCountryCode }: useLoadCheckoutProps) {
|
|
13
13
|
const { stigg } = useStiggContext();
|
|
14
14
|
const [isLoading, setIsLoading] = useState(false);
|
|
15
|
-
const [checkout, setCheckout] = useState<
|
|
15
|
+
const [checkout, setCheckout] = useState<GetCheckoutStateResults | null>();
|
|
16
16
|
|
|
17
17
|
useEffect(() => {
|
|
18
18
|
const loadCheckout = async () => {
|
|
@@ -6,7 +6,7 @@ import { useCheckoutModel } from '../../../hooks';
|
|
|
6
6
|
|
|
7
7
|
export function StripePaymentForm() {
|
|
8
8
|
const { checkoutState, checkoutLocalization } = useCheckoutModel();
|
|
9
|
-
const { customer } = checkoutState || {};
|
|
9
|
+
const { customer, configuration } = checkoutState || {};
|
|
10
10
|
|
|
11
11
|
return (
|
|
12
12
|
<Grid flexDirection="column" container gap={3} padding="16px">
|
|
@@ -15,7 +15,7 @@ export function StripePaymentForm() {
|
|
|
15
15
|
<AddressElement
|
|
16
16
|
options={{
|
|
17
17
|
mode: 'billing',
|
|
18
|
-
fields: { phone: 'always' },
|
|
18
|
+
fields: { phone: !!configuration?.content?.collectPhoneNumber ? 'always' : 'auto' },
|
|
19
19
|
defaultValues: {
|
|
20
20
|
...(customer?.name && { name: customer.name }),
|
|
21
21
|
},
|
|
@@ -15,7 +15,7 @@ export const BillingPeriodButton = styled.button<{ $isActive?: boolean; $disable
|
|
|
15
15
|
border-radius: 10px;
|
|
16
16
|
border: ${({ theme, $isActive }) =>
|
|
17
17
|
`1px solid ${$isActive ? theme.stigg.palette.outlinedRestingBorder : theme.stigg.palette.outlinedBorder}`};
|
|
18
|
-
background: ${({ $isActive }) => ($isActive ?
|
|
18
|
+
background: ${({ theme, $isActive }) => ($isActive ? theme.stigg.palette.backgroundSection : 'transparent')};
|
|
19
19
|
text-transform: none;
|
|
20
20
|
text-align: start;
|
|
21
21
|
|
|
@@ -1,26 +1,43 @@
|
|
|
1
|
+
import { CheckoutConfiguration } from '@stigg/js-client-sdk';
|
|
1
2
|
import { StiggTheme } from '../../theme/types';
|
|
2
3
|
import { DeepPartial } from '../../types';
|
|
3
|
-
import { CheckoutConfiguration } from './types';
|
|
4
4
|
|
|
5
5
|
export type CheckoutTheme = {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
primary: string;
|
|
7
|
+
textColor: string;
|
|
8
8
|
backgroundColor: string;
|
|
9
9
|
borderColor: string;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
selectionColor: string;
|
|
11
|
+
summaryBackgroundColor: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const defaultCheckoutTheme: CheckoutTheme = {
|
|
15
|
+
primary: 'rgb(50, 126, 238)',
|
|
16
|
+
textColor: 'rgb(0, 30, 108)',
|
|
17
|
+
backgroundColor: 'rgb(255, 255, 255)',
|
|
18
|
+
borderColor: 'rgb(235, 237, 243)',
|
|
19
|
+
selectionColor: 'rgb(229, 242, 255)',
|
|
20
|
+
summaryBackgroundColor: 'rgb(109, 121, 144)',
|
|
13
21
|
};
|
|
14
22
|
|
|
15
23
|
export function getResolvedCheckoutTheme(
|
|
16
|
-
|
|
24
|
+
globalTheme: StiggTheme,
|
|
17
25
|
themeOverride?: DeepPartial<CheckoutTheme>,
|
|
18
|
-
|
|
19
|
-
) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
_remoteConfiguration?: CheckoutConfiguration | null, // all the remote colors override theme colors, no need to use them here
|
|
27
|
+
): CheckoutTheme {
|
|
28
|
+
const { palette: globalPalette } = globalTheme || {};
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
primary: themeOverride?.primary || globalPalette?.primary || defaultCheckoutTheme.primary,
|
|
32
|
+
textColor: themeOverride?.textColor || globalPalette?.text.primary || defaultCheckoutTheme.textColor,
|
|
33
|
+
backgroundColor:
|
|
34
|
+
themeOverride?.backgroundColor || globalPalette?.backgroundPaper || defaultCheckoutTheme.backgroundColor,
|
|
35
|
+
borderColor: themeOverride?.borderColor || globalPalette?.outlinedBorder || defaultCheckoutTheme.borderColor,
|
|
36
|
+
selectionColor:
|
|
37
|
+
themeOverride?.selectionColor || globalPalette?.backgroundSection || defaultCheckoutTheme.selectionColor,
|
|
38
|
+
summaryBackgroundColor:
|
|
39
|
+
themeOverride?.summaryBackgroundColor ||
|
|
40
|
+
globalPalette?.backgroundHighlight ||
|
|
41
|
+
defaultCheckoutTheme.summaryBackgroundColor,
|
|
24
42
|
};
|
|
25
|
-
return checkoutDefaultTheme;
|
|
26
43
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Alignment,
|
|
3
|
+
CheckoutConfiguration,
|
|
3
4
|
CustomerPortalConfiguration,
|
|
4
5
|
FontWeight as JSFontWeight,
|
|
5
6
|
PaywallConfiguration,
|
|
7
|
+
TypographyConfiguration,
|
|
6
8
|
} from '@stigg/js-client-sdk';
|
|
7
9
|
import { CustomizedTheme } from '../../theme/Theme';
|
|
8
10
|
import { HorizontalAlignment, FontWeight } from '../../theme/types';
|
|
9
|
-
import { CheckoutConfiguration } from '../checkout/types';
|
|
10
11
|
|
|
11
12
|
function addCssUnits(value?: number | null, unit: string = 'px') {
|
|
12
13
|
if (!value) {
|
|
@@ -30,10 +31,7 @@ function mapFontWeight(defaultValue: FontWeight, fontWeight?: JSFontWeight | nul
|
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
function mapTypography(
|
|
34
|
-
configuration: CustomerPortalConfiguration | PaywallConfiguration,
|
|
35
|
-
): CustomizedTheme['typography'] {
|
|
36
|
-
const { typography } = configuration;
|
|
34
|
+
function mapTypography(typography?: TypographyConfiguration | null): CustomizedTheme['typography'] {
|
|
37
35
|
return {
|
|
38
36
|
fontFamilyUrl: typography?.fontFamily || undefined,
|
|
39
37
|
h1: {
|
|
@@ -70,7 +68,7 @@ function mapAlignment(alignment?: Alignment | null): HorizontalAlignment | undef
|
|
|
70
68
|
}
|
|
71
69
|
|
|
72
70
|
export function mapCustomerPortalConfiguration(configuration: CustomerPortalConfiguration): CustomizedTheme {
|
|
73
|
-
const { palette } = configuration;
|
|
71
|
+
const { palette, typography } = configuration;
|
|
74
72
|
return {
|
|
75
73
|
palette: {
|
|
76
74
|
primary: palette?.primary || undefined,
|
|
@@ -81,12 +79,12 @@ export function mapCustomerPortalConfiguration(configuration: CustomerPortalConf
|
|
|
81
79
|
primary: palette?.textColor || undefined,
|
|
82
80
|
},
|
|
83
81
|
},
|
|
84
|
-
typography: mapTypography(
|
|
82
|
+
typography: mapTypography(typography),
|
|
85
83
|
};
|
|
86
84
|
}
|
|
87
85
|
|
|
88
86
|
export function mapPaywallConfiguration(paywallConfiguration: PaywallConfiguration): CustomizedTheme {
|
|
89
|
-
const { palette, layout, customCss } = paywallConfiguration;
|
|
87
|
+
const { palette, layout, customCss, typography } = paywallConfiguration;
|
|
90
88
|
return {
|
|
91
89
|
customCss: customCss || undefined,
|
|
92
90
|
palette: {
|
|
@@ -98,7 +96,7 @@ export function mapPaywallConfiguration(paywallConfiguration: PaywallConfigurati
|
|
|
98
96
|
primary: palette?.textColor || undefined,
|
|
99
97
|
},
|
|
100
98
|
},
|
|
101
|
-
typography: mapTypography(
|
|
99
|
+
typography: mapTypography(typography),
|
|
102
100
|
layout: {
|
|
103
101
|
ctaAlignment: mapAlignment(layout?.alignment),
|
|
104
102
|
headerAlignment: mapAlignment(layout?.alignment),
|
|
@@ -111,7 +109,19 @@ export function mapPaywallConfiguration(paywallConfiguration: PaywallConfigurati
|
|
|
111
109
|
};
|
|
112
110
|
}
|
|
113
111
|
|
|
114
|
-
export function mapCheckoutConfiguration(
|
|
115
|
-
|
|
116
|
-
return {
|
|
112
|
+
export function mapCheckoutConfiguration(configuration: CheckoutConfiguration): CustomizedTheme {
|
|
113
|
+
const { palette, typography } = configuration;
|
|
114
|
+
return {
|
|
115
|
+
palette: {
|
|
116
|
+
primary: palette?.primary || undefined,
|
|
117
|
+
backgroundPaper: palette?.backgroundColor || undefined,
|
|
118
|
+
outlinedBorder: palette?.borderColor || undefined,
|
|
119
|
+
text: {
|
|
120
|
+
primary: palette?.textColor || undefined,
|
|
121
|
+
},
|
|
122
|
+
backgroundHighlight: palette?.selectionColor || undefined,
|
|
123
|
+
backgroundSection: palette?.summaryBackgroundColor || undefined,
|
|
124
|
+
},
|
|
125
|
+
typography: mapTypography(typography),
|
|
126
|
+
};
|
|
117
127
|
}
|
package/src/index.ts
CHANGED
|
@@ -29,7 +29,7 @@ export {
|
|
|
29
29
|
StiggContextValue,
|
|
30
30
|
StiggContext,
|
|
31
31
|
} from './components/StiggProvider';
|
|
32
|
-
export { Checkout, CheckoutProps,
|
|
32
|
+
export { Checkout, CheckoutProps, CheckoutTheme } from './components/checkout';
|
|
33
33
|
export { useWaitForCheckoutCompleted, ProvisionStatus } from './components/hooks';
|
|
34
34
|
export { HorizontalAlignment, TextAlignment } from './theme/types';
|
|
35
35
|
export { CustomizedTheme as Theme } from './theme/Theme';
|
|
@@ -44,7 +44,6 @@ const Template: ComponentStory<any> = args => (
|
|
|
44
44
|
const { success, errorMessage } = await checkoutAction();
|
|
45
45
|
return { success, errorMessage };
|
|
46
46
|
}}
|
|
47
|
-
billableFeatures={[{ featureId: 'feature-seat', quantity: 30 }]}
|
|
48
47
|
onChangePlan={({ currentPlan }) => {
|
|
49
48
|
console.log('plan changed clicked!', { currentPlan });
|
|
50
49
|
}}
|
|
@@ -56,4 +55,8 @@ export const DefaultCheckout = Template.bind({});
|
|
|
56
55
|
DefaultCheckout.args = {
|
|
57
56
|
...defaultArgsWithCustomer,
|
|
58
57
|
planId: 'plan-revvenu-essentials',
|
|
58
|
+
baseUri: 'http://localhost:4000',
|
|
59
|
+
apiKey: 'client-72b058a6-0f22-4c86-adce-bf266d12e12e:9f356ceb-c94c-42a4-9572-10b12824da81',
|
|
60
|
+
// baseUri: 'https://api-staging.stigg.io',
|
|
61
|
+
// apiKey: 'client-79584f52-7ef9-4c58-b9ac-5080acf492e4:71f2274c-100a-4fa4-8a43-48fa3b16c627',
|
|
59
62
|
};
|