Skip to content

Commit c0eed81

Browse files
allow appearance to be set on session (#1208)
* allow appearance to be set on session * add changeset for react bump * access session directly from props * check format of override variables for kebab or camel * increase button and total amount sizes
1 parent a5ae09f commit c0eed81

File tree

15 files changed

+8492
-7836
lines changed

15 files changed

+8492
-7836
lines changed

.changeset/nasty-maps-bathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@godaddy/react": patch
3+
---
4+
5+
Add optional appearance to checkout session

packages/react/src/components/checkout/checkout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ export function Checkout(props: CheckoutProps) {
226226
>(undefined);
227227
const { t } = useGoDaddyContext();
228228

229-
useTheme();
230-
useVariables(props?.appearance?.variables);
229+
useTheme(session?.appearance?.theme);
230+
useVariables(session?.appearance?.variables || props?.appearance?.variables);
231231

232232
const formSchema = React.useMemo(() => {
233233
const extendedSchema = checkoutFormSchema

packages/react/src/components/checkout/express-checkout/express-checkout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ export function DraftOrderExpressCheckout(props: ExpressCheckoutProps) {
9494
paypalConfig,
9595
} = props;
9696

97-
useTheme();
98-
useVariables(props?.appearance?.variables);
97+
useTheme(session?.appearance?.theme);
98+
useVariables(session?.appearance?.variables || props?.appearance?.variables);
9999

100100
const [isConfirmingCheckout, setIsConfirmingCheckout] = React.useState(false);
101101
const [checkoutErrors, setCheckoutErrors] = React.useState<

packages/react/src/components/checkout/payment/checkout-buttons/express/godaddy.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ export function ExpressCheckoutButton() {
412412
buttonOptions: {
413413
type: 'plain',
414414
margin: '0',
415-
height: '48px',
415+
height: '50px',
416416
width: '100%',
417417
justifyContent: 'flex-start',
418418
onClick: handleExpressPayClick,

packages/react/src/components/checkout/payment/checkout-buttons/paypal/paypal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function PayPalButtonsWrapper() {
8787
};
8888

8989
if (isPending || !isResolved) {
90-
return <Skeleton className='h-10 w-full' />;
90+
return <Skeleton className='h-13 w-full' />;
9191
}
9292

9393
return (
@@ -97,7 +97,7 @@ function PayPalButtonsWrapper() {
9797
label: 'pay',
9898
shape: 'rect',
9999
borderRadius: 8,
100-
height: 40,
100+
height: 50,
101101
}}
102102
disabled={isPaypalDisabled || isPaymentDisabled}
103103
onClick={handleClick}

packages/react/src/components/checkout/payment/checkout-buttons/paze/godaddy.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export function PazeCheckoutButton() {
7676
buttonOptions: {
7777
type: 'plain',
7878
margin: '0',
79-
height: '48px',
79+
height: '50px',
8080
width: '100%',
8181
justifyContent: 'flex-start',
8282
onClick: handlePazeClick,

packages/react/src/components/checkout/payment/payment-form.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ export function PaymentForm(
263263
return (
264264
<Button
265265
type='button'
266-
className='w-full flex items-center justify-center gap-2 px-8 h-10'
266+
size='lg'
267+
className='w-full flex items-center justify-center gap-2 px-8 h-13'
267268
disabled
268269
>
269270
<LoaderCircle className='h-5 w-5 animate-spin' />

packages/react/src/components/checkout/totals/totals.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export function DraftOrderTotals({
142142
<span className='text-xs text-muted-foreground'>
143143
{currencyCode}{' '}
144144
</span>
145-
<span className='font-medium'>
145+
<span className='font-bold text-lg'>
146146
{new Intl.NumberFormat('en-us', {
147147
style: 'currency',
148148
currency: currencyCode,
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import type { CSSVariables } from '@/godaddy-provider';
2+
3+
/**
4+
* Convert kebab-case string to camelCase
5+
* @example kebabToCamel('font-sans') // 'fontSans'
6+
*/
7+
export function kebabToCamel(str: string): string {
8+
return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
9+
}
10+
11+
/**
12+
* Convert camelCase string to kebab-case
13+
* @example camelToKebab('fontSans') // 'font-sans'
14+
*/
15+
export function camelToKebab(str: string): string {
16+
return str.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);
17+
}
18+
19+
/**
20+
* Convert kebab-case CSS variables object to camelCase for GraphQL
21+
* @param variables - Object with kebab-case keys
22+
* @returns Object with camelCase keys
23+
* @example
24+
* convertCSSVariablesToCamelCase({ 'font-sans': 'Arial', 'secondary-background': '#fff' })
25+
* // { fontSans: 'Arial', secondaryBackground: '#fff' }
26+
*/
27+
export function convertCSSVariablesToCamelCase(
28+
variables: CSSVariables
29+
): Record<string, string> {
30+
const result: Record<string, string> = {};
31+
for (const [key, value] of Object.entries(variables)) {
32+
if (value !== undefined) {
33+
result[kebabToCamel(key)] = value;
34+
}
35+
}
36+
return result;
37+
}
38+
39+
/**
40+
* Convert camelCase object keys to kebab-case (for GraphQL response to CSS variables)
41+
* @param obj - Object with camelCase keys
42+
* @returns Object with kebab-case keys typed as CSSVariables
43+
* @example
44+
* convertCamelCaseToKebabCase({ fontSans: 'Arial', secondaryBackground: '#fff' })
45+
* // { 'font-sans': 'Arial', 'secondary-background': '#fff' }
46+
*/
47+
export function convertCamelCaseToKebabCase(
48+
obj: Record<string, string>
49+
): CSSVariables {
50+
const result: Record<string, string> = {};
51+
for (const [key, value] of Object.entries(obj)) {
52+
if (value !== undefined) {
53+
result[camelToKebab(key)] = value;
54+
}
55+
}
56+
return result as CSSVariables;
57+
}

packages/react/src/components/ui/button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const buttonVariants = cva(
2424
size: {
2525
default: 'h-9 px-4 py-2',
2626
sm: 'h-8 rounded-md px-3 text-xs',
27-
lg: 'h-10 rounded-md px-8',
27+
lg: 'h-13 rounded-md px-8',
2828
icon: 'h-9 w-9',
2929
},
3030
},

0 commit comments

Comments
 (0)