Skip to content

Commit

Permalink
feat(clerk-js): Add open sign-in/up to sandbox (#4666)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcarpenter authored Nov 28, 2024
1 parent b0d165a commit c02e208
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .changeset/quiet-mails-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
24 changes: 24 additions & 0 deletions packages/clerk-js/sandbox/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ function mountIndex(element: HTMLDivElement) {
element.innerHTML = `<pre><code>${JSON.stringify({ user }, null, 2)}</code></pre>`;
}

function mountOpenSignInButton(element: HTMLDivElement, props) {
const button = document.createElement('button');
button.textContent = 'Open Sign In';
button.onclick = () => {
Clerk?.openSignUp(props);
};
element.appendChild(button);
}

function mountOpenSignUpButton(element: HTMLDivElement, props) {
const button = document.createElement('button');
button.textContent = 'Open Sign Up';
button.onclick = () => {
Clerk?.openSignUp(props);
};
element.appendChild(button);
}

function addCurrentRouteIndicator(currentRoute: string) {
const link = document.querySelector(`a[href="${currentRoute}"]`);
if (!link) {
Expand Down Expand Up @@ -144,6 +162,12 @@ function addCurrentRouteIndicator(currentRoute: string) {
'/accountless': () => {
Clerk.__unstable__updateProps({ options: { __internal_claimAccountlessKeysUrl: '/test-url' } });
},
'/open-sign-in': () => {
mountOpenSignInButton(app, componentControls.signIn.getProps() ?? {});
},
'/open-sign-up': () => {
mountOpenSignUpButton(app, componentControls.signUp.getProps() ?? {});
},
};

const route = window.location.pathname;
Expand Down
18 changes: 17 additions & 1 deletion packages/clerk-js/sandbox/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
></path>
</svg>
<div
class="bg-gray-25 mt-0.5 rounded-full px-2 py-1 text-[0.625rem]/3 font-medium text-gray-600 ring-1 ring-inset ring-gray-100 dark:bg-gray-900 dark:text-gray-400 dark:ring-gray-700"
class="bg-gray-25 mt-0.5 rounded-full px-2 py-1 text-[0.625rem]/3 font-medium text-gray-600 ring-1 ring-inset ring-gray-100"
>
Sandbox
</div>
Expand Down Expand Up @@ -244,6 +244,22 @@
Accountless
</a>
</li>
<li class="relative">
<a
class="relative isolate flex w-full rounded-md border border-white px-2 py-[0.4375rem] text-sm hover:bg-gray-50 aria-[current]:bg-gray-50"
href="/open-sign-in"
>
Open sign in
</a>
</li>
<li class="relative">
<a
class="relative isolate flex w-full rounded-md border border-white px-2 py-[0.4375rem] text-sm hover:bg-gray-50 aria-[current]:bg-gray-50"
href="/open-sign-up"
>
Open sign up
</a>
</li>
</ul>
</nav>
</div>
Expand Down

0 comments on commit c02e208

Please sign in to comment.