-
Notifications
You must be signed in to change notification settings - Fork 326
/
Copy pathmount-clerk-astro-js-components.ts
32 lines (29 loc) · 1.17 KB
/
mount-clerk-astro-js-components.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { $clerk } from '../stores/internal';
/**
* Loop through any Astro component that has requested to mount a UI component and mount it with its respective props.
*/
const mountAllClerkAstroJSComponents = () => {
const mountFns = {
'organization-list': 'mountOrganizationList',
'organization-profile': 'mountOrganizationProfile',
'organization-switcher': 'mountOrganizationSwitcher',
'user-button': 'mountUserButton',
'user-profile': 'mountUserProfile',
'sign-in': 'mountSignIn',
'sign-up': 'mountSignUp',
'google-one-tap': 'openGoogleOneTap',
waitlist: 'mountWaitlist',
} as const;
Object.entries(mountFns).forEach(([category, mountFn]) => {
const elementsOfCategory = document.querySelectorAll(`[data-clerk-id^="clerk-${category}"]`);
elementsOfCategory.forEach(el => {
const clerkId = el.getAttribute('data-clerk-id');
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const props = window.__astro_clerk_component_props?.get(category)?.get(clerkId!);
if (el) {
$clerk.get()?.[mountFn](el as HTMLDivElement, props);
}
});
});
};
export { mountAllClerkAstroJSComponents };