Skip to content

Commit

Permalink
fix(clerk-js): Add keys targeting avatar buttons
Browse files Browse the repository at this point in the history
Enables the ability to target the Avatar upload and remove action
buttons. Fixes USR-98
  • Loading branch information
tmilewski committed Jul 11, 2023
1 parent 090bab6 commit b4658b4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/clerk-js/src/ui/customizables/elementDescriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export const APPEARANCE_KEYS = containsAllElementsConfigKeys([

'avatarBox',
'avatarImage',
'avatarImageActions',
'avatarImageActionsUpload',
'avatarImageActionsReset',

'userButtonBox',
'userButtonOuterIdentifier',
Expand Down
9 changes: 7 additions & 2 deletions packages/clerk-js/src/ui/elements/AvatarUploader.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';

import type { LocalizationKey } from '../customizables';
import { Button, Col, Flex, localizationKeys, Text } from '../customizables';
import { Button, Col, descriptors, Flex, localizationKeys, Text } from '../customizables';
import { handleError } from '../utils';
import { useCardState } from './contexts';
import { FileDropArea } from './FileDropArea';
Expand Down Expand Up @@ -67,8 +67,12 @@ export const AvatarUploader = (props: AvatarUploaderProps) => {
localizationKey={title}
variant='regularMedium'
/>
<Flex gap={4}>
<Flex
elementDescriptor={descriptors.avatarImageActions}
gap={4}
>
<Button
elementDescriptor={descriptors.avatarImageActionsUpload}
localizationKey={
!showUpload
? localizationKeys('userProfile.profilePage.imageFormSubtitle')
Expand All @@ -84,6 +88,7 @@ export const AvatarUploader = (props: AvatarUploaderProps) => {

{!!onAvatarRemove && !showUpload && (
<Button
elementDescriptor={descriptors.avatarImageActionsReset}
localizationKey={localizationKeys('userProfile.profilePage.imageFormDestructiveActionSubtitle')}
isDisabled={card.isLoading}
sx={t => ({ color: t.colors.$danger500 })}
Expand Down
3 changes: 3 additions & 0 deletions packages/types/src/appearance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ export type ElementsConfig = {

avatarBox: WithOptions<never, never, never>;
avatarImage: WithOptions<never, never, never>;
avatarImageActions: WithOptions<never, never, never>;
avatarImageActionsUpload: WithOptions<never, never, never>;
avatarImageActionsReset: WithOptions<never, never, never>;

// TODO: We can remove "Popover" from these:
userButtonBox: WithOptions<never, 'open', never>;
Expand Down

0 comments on commit b4658b4

Please sign in to comment.