Skip to content

Commit

Permalink
feat(ui): Sign out of other sessions checkbox (#3801)
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-bell authored Jul 24, 2024
1 parent da21138 commit f53bf15
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .changeset/unlucky-yaks-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
42 changes: 42 additions & 0 deletions packages/ui/src/common/checkbox-field.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as Common from '@clerk/elements/common';
import React from 'react';

import * as Field from '../primitives/field';

export function CheckboxField({
label,
name,
...props
}: { name: React.ComponentProps<typeof Common.Field>['name']; label: React.ReactNode } & Omit<
React.ComponentProps<typeof Common.Input>,
'className' | 'type'
>) {
return (
<Common.Field
name={name}
asChild
>
<Field.Root>
<div className='flex gap-2'>
<Common.Input
type='checkbox'
asChild
{...props}
>
<Field.Checkbox />
</Common.Input>

<Common.Label asChild>
<Field.Label>{label}</Field.Label>
</Common.Label>
</div>

<Common.FieldError asChild>
{({ message }) => {
return <Field.Message intent='error'>{message}</Field.Message>;
}}
</Common.FieldError>
</Field.Root>
</Common.Field>
);
}
33 changes: 21 additions & 12 deletions packages/ui/src/components/sign-in/sign-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as SignIn from '@clerk/elements/sign-in';
import * as React from 'react';

import { BackupCodeField } from '~/common/backup-code-field';
import { CheckboxField } from '~/common/checkbox-field';
import { Connections } from '~/common/connections';
import { EmailField } from '~/common/email-field';
import { EmailOrPhoneNumberField } from '~/common/email-or-phone-number-field';
Expand Down Expand Up @@ -1141,28 +1142,36 @@ export function SignInComponentLoaded() {
return <Alert>{message}</Alert>;
}}
</Common.GlobalError>
<div className='flex flex-col justify-center gap-4'>
<PasswordField
validatePassword
name='password'
label={t('formFieldLabel__newPassword')}
/>
<PasswordField
name='confirmPassword'
label={t('formFieldLabel__confirmPassword')}
/>
<div className='flex flex-col justify-center gap-6'>
<div className='flex flex-col justify-center gap-4'>
<PasswordField
validatePassword
name='password'
label={t('formFieldLabel__newPassword')}
/>
<PasswordField
name='confirmPassword'
label={t('formFieldLabel__confirmPassword')}
/>

<CheckboxField
name='signOutOfOtherSessions'
label={t('formFieldLabel__signOutOfOtherSessions')}
defaultChecked
/>
</div>
<Common.Loading>
{isSubmitting => {
return (
<>
<div className='flex flex-col justify-center gap-4'>
<SignIn.Action
submit
asChild
>
<Button
busy={isSubmitting}
disabled={isGlobalLoading || isSubmitting}
spinnerWhenBusy
>
{t('signIn.resetPassword.formButtonPrimary')}
</Button>
Expand All @@ -1174,7 +1183,7 @@ export function SignInComponentLoaded() {
>
<LinkButton>{t('backButton')}</LinkButton>
</SignIn.Action>
</>
</div>
);
}}
</Common.Loading>
Expand Down
22 changes: 21 additions & 1 deletion packages/ui/src/primitives/field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const Root = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDi
ref={forwardedRef}
{...props}
className={cx(
'has-[[data-field-checkbox]]:[--cl-field-label-cursor:pointer]',
'has-[[data-field-input][disabled]]:[--cl-field-label-opacity:0.5]',
'flex flex-col gap-2',
className,
Expand All @@ -41,7 +42,11 @@ export const Label = React.forwardRef(function Label(
className={cx(
visuallyHidden
? 'sr-only'
: 'text-gray-12 flex items-center gap-x-1 text-base font-medium opacity-[--cl-field-label-opacity,1]',
: [
'text-gray-12 flex items-center gap-x-1 text-base font-medium opacity-[--cl-field-label-opacity,1]',
'cursor-[--cl-field-label-cursor,auto]',
],

className,
)}
>
Expand Down Expand Up @@ -80,6 +85,21 @@ export const Hint = React.forwardRef(function Hint(
);
});

export const Checkbox = React.forwardRef(function FieldCheckbox(
props: React.InputHTMLAttributes<HTMLInputElement>,
forwardedRef: React.ForwardedRef<HTMLInputElement>,
) {
return (
<input
ref={forwardedRef}
type='checkbox'
data-field-checkbox
className={cx('accent-accent-9 mt-[0.1875em] size-3 cursor-pointer')}
{...props}
/>
);
});

export const Input = React.forwardRef(function Input(
{
asChild,
Expand Down

0 comments on commit f53bf15

Please sign in to comment.