Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fair-bars-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/shared': patch
---

wip
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { handleError } from '@/ui/utils/errorHandler';
import { useSubscriberTypeContext, useSubscriberTypeLocalizationRoot } from '../../contexts';
import { descriptors, Flex, localizationKeys, Spinner, useAppearance, useLocalizations } from '../../customizables';
import type { LocalizationKey } from '../../localization';
import { PaymentElementSkeleton } from './PaymentElementSkeleton';

const useStripeAppearance = (node: HTMLElement | null) => {
const theme = useAppearance().parsedInternalTheme;
Expand Down Expand Up @@ -231,7 +232,7 @@ const AddPaymentSourceForm = ({ children }: PropsWithChildren) => {
})}
>
{children}
<PaymentElement />
<PaymentElement fallback={<PaymentElementSkeleton />} />
<Card.Alert>{card.error}</Card.Alert>
<FormButtons
isDisabled={!isFormReady}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import type { PropsWithChildren } from 'react';

import { Box, Flex, Grid } from '@/ui/customizables';

const SkeletonLine = (props: Parameters<typeof Box>[0]) => {
return (
<Box
sx={[
t => ({
height: t.space.$2,
width: '100%',
borderRadius: t.radii.$md,
background: t.colors.$neutralAlpha100,
}),
props.sx,
]}
/>
);
};

const SkeletonInput = () => {
return (
<SkeletonLine
sx={t => ({
height: t.space.$10,
width: '100%',
})}
/>
);
};

const LineGroup = (props: PropsWithChildren) => {
return (
<Flex
direction='col'
gap={2}
>
{props.children}
</Flex>
);
};

const PaymentElementSkeleton = () => {
return (
<Box

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcarpenter Do you think we need descriptors here ? Theming is already using, and I feel like it's ok to be opinionated about the layout of a skeleton.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree, I don't see why you'd modify the layout as they wouldn't change based on your configuration.

sx={{
position: 'relative',
minHeight: 0,
flex: 1,
overflowY: 'auto',
}}
>
<Flex
direction='col'
gap={5}
>
<LineGroup>
<SkeletonLine
sx={t => ({
height: t.space.$3,
width: t.sizes.$24,
})}
/>
<SkeletonInput />
</LineGroup>

<Grid
columns={2}
gap={4}
>
<LineGroup>
<SkeletonLine
sx={t => ({
height: t.space.$3,
width: t.sizes.$20,
})}
/>

<SkeletonInput />
</LineGroup>
<LineGroup>
<SkeletonLine
sx={t => ({
height: t.space.$3,
width: t.sizes.$24,
})}
/>

<SkeletonInput />
</LineGroup>
</Grid>

<LineGroup>
<SkeletonLine
sx={t => ({
height: t.space.$3,
width: t.sizes.$16,
})}
/>

<SkeletonInput />
</LineGroup>

<LineGroup>
<SkeletonLine />
<SkeletonLine />
<SkeletonLine sx={{ width: '66.666667%' }} />
</LineGroup>
</Flex>
</Box>
);
};

export { PaymentElementSkeleton };
1 change: 1 addition & 0 deletions packages/shared/src/react/commerce.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ const PaymentElementInternalRoot = (props: PropsWithChildren) => {
key={externalClientSecret}
stripe={stripe}
options={{
loader: 'never',
clientSecret: externalClientSecret,
appearance: {
variables: stripeAppearance,
Expand Down
5 changes: 5 additions & 0 deletions packages/shared/src/react/stripe-react/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@ const createElementComponent = (type: StripeElementType, isServer: boolean): Fun
{!isReady && fallback}
<div
id={id}
data-clerk='true'
style={{
height: isReady ? 'unset' : '0px',
visibility: isReady ? 'visible' : 'hidden',
}}
className={className}
ref={domNode}
/>
Expand Down
Loading