Repository navigation
feat(mosaic): drag to upload the profile picture and organization logo #10601
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@clerk/mosaic': patch | ||
| --- | ||
|
|
||
| Drop an image onto the profile picture row in `UserProfile` or the logo row in `OrganizationProfile` to upload it. While a file is dragged over the row, the avatar darkens and shows an upload icon. `FileUpload.Dropzone` now ignores drags that carry no files, such as selected text or links. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { act } from '@testing-library/react'; | ||
|
|
||
| export function dragFilesOver(target: Element, ...files: File[]) { | ||
| dispatchDrag(target, 'dragenter', files); | ||
| } | ||
|
|
||
| export function dropFiles(target: Element, ...files: File[]) { | ||
| dispatchDrag(target, 'drop', files); | ||
| } | ||
|
|
||
| function dispatchDrag(target: Element, type: 'dragenter' | 'drop', files: File[]) { | ||
| const dataTransfer = new DataTransfer(); | ||
| for (const file of files) { | ||
| dataTransfer.items.add(file); | ||
| } | ||
| act(() => { | ||
| target.dispatchEvent(new DragEvent(type, { bubbles: true, cancelable: true, dataTransfer })); | ||
| }); | ||
| } |
3 changes: 3 additions & 0 deletions
3
packages/mosaic/src/components/avatar-dropzone/avatar-dropzone.markers.stylex.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import * as stylex from '@stylexjs/stylex'; | ||
|
|
||
| export const avatarDropzoneScope = stylex.defineMarker(); |
31 changes: 31 additions & 0 deletions
31
packages/mosaic/src/components/avatar-dropzone/avatar-dropzone.styles.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import * as stylex from '@stylexjs/stylex'; | ||
|
|
||
| import { durationVars, easingVars } from '../../tokens.stylex'; | ||
| import { avatarDropzoneScope } from './avatar-dropzone.markers.stylex'; | ||
|
|
||
| export const styles = stylex.create({ | ||
| overlay: { | ||
| inset: 0, | ||
| borderRadius: 'inherit', | ||
| alignItems: 'center', | ||
| backgroundColor: 'color-mix(in oklab, oklch(0 0 0) 50%, transparent)', | ||
| color: 'oklch(1 0 0)', | ||
| display: 'flex', | ||
| justifyContent: 'center', | ||
| opacity: { | ||
| default: 0, | ||
| [stylex.when.ancestor('[data-dragging]', avatarDropzoneScope)]: 1, | ||
| }, | ||
| pointerEvents: 'none', | ||
| position: 'absolute', | ||
| transitionDuration: { | ||
| default: durationVars['--cl-duration-fast'], | ||
| [stylex.when.ancestor('[data-dragging]', avatarDropzoneScope)]: durationVars['--cl-duration-base'], | ||
| }, | ||
| transitionProperty: 'opacity', | ||
| transitionTimingFunction: { | ||
| default: easingVars['--cl-ease-exit'], | ||
| [stylex.when.ancestor('[data-dragging]', avatarDropzoneScope)]: easingVars['--cl-ease-enter'], | ||
| }, | ||
| }, | ||
| }); |
50 changes: 50 additions & 0 deletions
50
packages/mosaic/src/components/avatar-dropzone/avatar-dropzone.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import * as stylex from '@stylexjs/stylex'; | ||
| import React from 'react'; | ||
|
|
||
| import { ArrowUp } from '../../icons/glyphs/arrow-up'; | ||
| import { FileUpload } from '../../primitives/file-upload'; | ||
| import type { MosaicComponentProps, MosaicElementProps } from '../../props'; | ||
| import { mergeStyleProps, themeProps } from '../../props'; | ||
| import { reset } from '../../styles/reset.styles'; | ||
| import { Icon } from '../icon'; | ||
| import { avatarDropzoneScope } from './avatar-dropzone.markers.stylex'; | ||
| import { styles } from './avatar-dropzone.styles'; | ||
|
|
||
| export type AvatarDropzoneProps = MosaicComponentProps<'div'>; | ||
|
|
||
| const AvatarDropzoneRoot = React.forwardRef<HTMLDivElement, AvatarDropzoneProps>(function MosaicAvatarDropzoneRoot( | ||
| { xstyle, ...rest }, | ||
| ref, | ||
| ) { | ||
| return ( | ||
| <FileUpload.Dropzone | ||
| ref={ref} | ||
| {...mergeStyleProps(themeProps('avatar-dropzone'), stylex.props(avatarDropzoneScope, xstyle), rest)} | ||
| /> | ||
| ); | ||
| }); | ||
|
|
||
| export type AvatarDropzoneOverlayProps = MosaicElementProps<'span'>; | ||
|
|
||
| const AvatarDropzoneOverlay = React.forwardRef<HTMLSpanElement, AvatarDropzoneOverlayProps>( | ||
| function MosaicAvatarDropzoneOverlay({ xstyle, ...rest }, ref) { | ||
| return ( | ||
| <span | ||
| ref={ref} | ||
| aria-hidden | ||
| {...mergeStyleProps( | ||
| themeProps('avatar-dropzone-overlay'), | ||
| stylex.props(reset.base, styles.overlay, xstyle), | ||
| rest, | ||
| )} | ||
| > | ||
| <Icon glyph={ArrowUp} /> | ||
| </span> | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| export const AvatarDropzone = { | ||
| Root: AvatarDropzoneRoot, | ||
| Overlay: AvatarDropzoneOverlay, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { AvatarDropzone } from './avatar-dropzone'; | ||
| export type { AvatarDropzoneOverlayProps, AvatarDropzoneProps } from './avatar-dropzone'; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.