Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(clerk-js,types,clerk-react): Add internal open/close checkout methods #5481

Conversation

alexcarpenter
Copy link
Member

Description

Introduce clerk.__internal_openCheckout() and clerk.__internal_closeCheckout() methods, and move <Checkout /> component out of the <PricingTable /> component.

Resolves COM-257

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Copy link

changeset-bot bot commented Mar 28, 2025

🦋 Changeset detected

Latest commit: d29bf85

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 22 packages
Name Type
@clerk/clerk-js Patch
@clerk/clerk-react Patch
@clerk/types Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch
@clerk/elements Patch
@clerk/nextjs Patch
@clerk/react-router Patch
@clerk/remix Patch
@clerk/tanstack-react-start Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/expo-passkeys Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/localizations Patch
@clerk/nuxt Patch
@clerk/shared Patch
@clerk/testing Patch
@clerk/themes Patch
@clerk/vue Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Mar 28, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 3, 2025 6:07pm

@alexcarpenter alexcarpenter changed the title feat(clerk-js,types): Add internal open/close checkout methods feat(clerk-js,types,clerk-react): Add internal open/close checkout methods Mar 28, 2025
Comment on lines +347 to +365
componentsControls.openDrawer = (name, props) => {
setState(s => ({
...s,
[`${name}Drawer`]: {
open: true,
props,
},
}));
};

componentsControls.closeDrawer = name => {
setState(s => ({
...s,
[`${name}Drawer`]: {
...s[`${name}Drawer`],
open: false,
},
}));
};
Copy link
Member Author

Choose a reason for hiding this comment

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

Introducing new drawer specific methods as we want to have an exit animation for the drawers, and removing all the props causes issues with portaling into the profile components.

Copy link
Member

Choose a reason for hiding this comment

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

It would be great to consolidate the modal/drawer handling at some point in the future. I would expect them to function the same, just be a different flavor of UI. Maybe there's a good reason to keep them separate though? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

If we want modals to have an exit animation, we'd need to follow this updated drawer pattern, currently all modals are removed immediately but wiping out the props.

Copy link
Member

@brkalow brkalow left a comment

Choose a reason for hiding this comment

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

👍 works good, I like the idea here. Main comment is I'm not sure the drawer/modal distinction is valuable in the low level component plumbing, but we can consolidate later if we want.

Nice job

planPeriod,
orgId: subscriberType === 'org' ? organization?.id : undefined,
onSubscriptionComplete: onSubscriptionChange,
portalId: mode === 'modal' ? PROFILE_CARD_SCROLLBOX_ID : undefined,
Copy link
Member

Choose a reason for hiding this comment

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

does mode indicate the context PricingTable is rendered in? I feel like I would expect mode to dictate how PricingTable behaves itself, but not necessarily how it behaves depending on where it's rendered.

As a semi-related nit, I might rename mode to context.

Copy link
Member Author

Choose a reason for hiding this comment

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

Mode is set on the PricingTable and I think was originally adding following the other components, but there is no modal mode for PricingTable, so yeah, it is confusing, as its only a mounted component. Will refactor naming approach in a follow up PR.

Comment on lines +40 to +45
clerk.__internal_openCheckout({
planId: plan.id,
planPeriod,
orgId: subscriberType === 'org' ? organization?.id : undefined,
onSubscriptionComplete: onSubscriptionChange,
portalId: mode === 'modal' ? PROFILE_CARD_SCROLLBOX_ID : undefined,
Copy link
Member

Choose a reason for hiding this comment

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

This is much cleaner!

Comment on lines +347 to +365
componentsControls.openDrawer = (name, props) => {
setState(s => ({
...s,
[`${name}Drawer`]: {
open: true,
props,
},
}));
};

componentsControls.closeDrawer = name => {
setState(s => ({
...s,
[`${name}Drawer`]: {
...s[`${name}Drawer`],
open: false,
},
}));
};
Copy link
Member

Choose a reason for hiding this comment

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

It would be great to consolidate the modal/drawer handling at some point in the future. I would expect them to function the same, just be a different flavor of UI. Maybe there's a good reason to keep them separate though? 🤔

@alexcarpenter alexcarpenter enabled auto-merge (squash) April 3, 2025 18:10
@alexcarpenter alexcarpenter merged commit bebb6d8 into main Apr 3, 2025
30 checks passed
@alexcarpenter alexcarpenter deleted the alexcarpenter/com-257-add-clerkopencheckout-and-clerkclosecheckout-methods-to branch April 3, 2025 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants