-
Notifications
You must be signed in to change notification settings - Fork 4
Leaderboard image optimizations - Media type Badge #1751
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
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9e4c082
Leaderboard media badge
prxt6529 b5cd1de
Leaderboard media badge
prxt6529 d0215e5
Merge branch 'main' into leaderboard-image-optimizations
prxt6529 3f14ad2
WIP
prxt6529 9f4d267
Merge branch 'main' into leaderboard-image-optimizations
prxt6529 1f1766d
WIP
prxt6529 a4be668
WIP
prxt6529 7022000
WIP
prxt6529 7550a6c
Merge branch 'main' into leaderboard-image-optimizations
prxt6529 c9c88c3
WIP
prxt6529 fd0330a
Merge branch 'main' into leaderboard-image-optimizations
prxt6529 b3e984c
WIP
prxt6529 53f6316
WIP
prxt6529 42cd4e3
Merge branch 'main' into leaderboard-image-optimizations
prxt6529 24d26ba
WIP
prxt6529 27c9cf9
Merge branch 'main' into leaderboard-image-optimizations
prxt6529 3eec138
WIP
prxt6529 09e82b1
Merge branch 'main' into leaderboard-image-optimizations
prxt6529 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
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,89 @@ | ||
| "use client"; | ||
|
|
||
| import { getMediaTypeInfo, type MediaCategory } from "@/helpers/file.helpers"; | ||
| import { useControlledTooltip } from "@/hooks/useControlledTooltip"; | ||
| import { Tooltip } from "react-tooltip"; | ||
|
|
||
| const FORMAT_ICONS: Record<MediaCategory, { viewBox: string; path: string }> = { | ||
| image: { | ||
| viewBox: "0 0 512 512", | ||
| path: "M0 96C0 60.7 28.7 32 64 32l384 0c35.3 0 64 28.7 64 64l0 320c0 35.3-28.7 64-64 64L64 480c-35.3 0-64-28.7-64-64L0 96zM323.8 202.5c-4.5-6.6-11.9-10.5-19.8-10.5s-15.4 3.9-19.8 10.5l-87 127.6L170.7 297c-4.6-5.7-11.5-9-18.7-9s-14.2 3.3-18.7 9l-64 80c-5.8 7.2-6.9 17.1-2.9 25.4s12.4 13.6 21.6 13.6l96 0 32 0 208 0c8.9 0 17.1-4.9 21.2-12.8s3.6-17.4-1.4-24.7l-120-176zM112 192a48 48 0 1 0 0-96 48 48 0 1 0 0 96z", | ||
| }, | ||
| video: { | ||
| viewBox: "0 0 576 512", | ||
| path: "M0 128C0 92.7 28.7 64 64 64l256 0c35.3 0 64 28.7 64 64l0 256c0 35.3-28.7 64-64 64L64 448c-35.3 0-64-28.7-64-64L0 128zM559.1 99.8c10.4 5.6 16.9 16.4 16.9 28.2l0 256c0 11.8-6.5 22.6-16.9 28.2s-23 5-32.9-1.6l-96-64L416 336l0-48 0-64 0-48 14.2-9.5 96-64c9.8-6.5 22.4-7.2 32.9-1.6z", | ||
| }, | ||
| interactive: { | ||
| viewBox: "45 15 170 230", | ||
| path: "M195.4,107.9c-2.6,0-5,0.4-7.4,1.2c-0.2-0.1-0.5-0.2-0.8-0.3c-4.4-7.1-12-11.4-20.4-11.4c-2.9,0-5.7,0.5-8.4,1.4c-4.4-7.4-12.1-11.9-20.8-11.9c-1.6,0-3.1,0.1-4.6,0.4V73.9c0-14-10.7-24.9-24.4-24.9c-13.8,0-25,11.2-25,24.9v65.8l-3.9-3.9c-4.5-4.4-10.7-6.9-17.5-6.9c-6.9,0-13.6,2.6-17.9,6.9c-9.4,9.4-12.5,25.7-1.5,36.7l56.2,55.9c1.3,1.3,2.8,2.4,4.4,3.4c10.5,8.6,23.1,14.2,49.7,14.2c61.8,0,66.9-36.2,66.9-73.3v-40C220.1,118.8,209.4,107.9,195.4,107.9L195.4,107.9z M210.3,172.8c0,36-4.2,63.5-57.1,63.5c-24,0-34.5-4.7-43.7-12.2l-0.6-0.4c-1.1-0.7-2-1.4-2.9-2.2l-56.2-55.8c-7.3-7.3-3.5-17.8,1.5-22.8c2.5-2.5,6.7-4,10.9-4c4.2,0,8,1.4,10.6,4l20.6,20.5V73.8c0-8.3,6.8-15.1,15.2-15.1c8.2,0,14.6,6.6,14.6,15.1v28.5l0.1-0.1v29.3c0,2.7,2.2,4.9,4.9,4.9c2.7,0,4.9-2.2,4.9-4.9V97.4c1.4-0.4,2.9-0.7,4.5-0.7c6.3,0,11.6,3.9,13.8,10.2l0.6,1.8v32.1c0,2.7,2.2,4.9,4.9,4.9c2.7,0,4.9-2.2,4.9-4.9V108c1.6-0.5,3.3-0.9,4.9-0.9c6.3,0,11.6,3.9,13.8,10.2l0.3,1v32.1c0,2.7,2.2,4.9,4.9,4.9c2.7,0,4.9-2.2,4.9-4.9v-31.8c1.6-0.6,3.2-1,5.2-1c8.2,0,14.4,6.5,14.4,15.1V172.8L210.3,172.8z M68.4,120.1c0.9,0.7,1.9,1,2.9,1c1.5,0,3-0.7,4-2c1.6-2.2,1.2-5.3-1-6.9C61.1,102.4,53.5,87.4,53.5,71c0-28.3,23-51.2,51.2-51.2S156,42.8,156,71c0,3.4-0.3,6.9-1,10.2c-0.5,2.6,1.2,5.3,3.9,5.8c2.6,0.5,5.3-1.2,5.8-3.9c0.8-4,1.2-8.1,1.2-12.1c0-33.6-27.4-61-61-61S43.7,37.4,43.7,71.1C43.7,90.3,52.9,108.6,68.4,120.1L68.4,120.1z", | ||
| }, | ||
| }; | ||
|
|
||
| interface MediaTypeBadgeProps { | ||
| readonly mimeType: string | undefined; | ||
| readonly dropId: string; | ||
| readonly size?: "sm" | "md" | "lg"; | ||
| } | ||
|
|
||
| const SIZE_CLASSES = { | ||
| sm: "tw-size-6", | ||
| md: "tw-size-8", | ||
| lg: "tw-size-10", | ||
| }; | ||
|
|
||
| const ICON_SIZE_CLASSES = { | ||
| sm: "tw-size-3", | ||
| md: "tw-size-4", | ||
| lg: "tw-size-5", | ||
| }; | ||
|
|
||
| export default function MediaTypeBadge({ | ||
| mimeType, | ||
| dropId, | ||
| size = "sm", | ||
| }: MediaTypeBadgeProps) { | ||
| const mediaInfo = getMediaTypeInfo(mimeType); | ||
| const tooltipId = `format-badge-${dropId}`; | ||
| const { isOpen, setIsOpen, triggerProps } = useControlledTooltip(); | ||
|
|
||
| return ( | ||
| <div className="tw-flex tw-flex-shrink-0"> | ||
| <div | ||
| data-tooltip-id={tooltipId} | ||
| data-tooltip-content={mediaInfo.label} | ||
| aria-label={mediaInfo.label} | ||
| {...triggerProps} | ||
| className={`tw-flex tw-cursor-pointer tw-items-center tw-justify-center tw-rounded tw-border tw-border-solid tw-grayscale tw-transition-all tw-duration-300 desktop-hover:hover:tw-grayscale-0 ${SIZE_CLASSES[size]}`} | ||
| style={{ | ||
| color: mediaInfo.styles.text, | ||
| backgroundColor: mediaInfo.styles.bg, | ||
| borderColor: mediaInfo.styles.border, | ||
| }} | ||
| > | ||
| <svg | ||
| className={ICON_SIZE_CLASSES[size]} | ||
| fill="currentColor" | ||
| viewBox={FORMAT_ICONS[mediaInfo.category].viewBox} | ||
| > | ||
| <path d={FORMAT_ICONS[mediaInfo.category].path} /> | ||
| </svg> | ||
| </div> | ||
| <Tooltip | ||
| id={tooltipId} | ||
| place="top" | ||
| opacity={1} | ||
| delayShow={300} | ||
| isOpen={isOpen} | ||
| setIsOpen={setIsOpen} | ||
| style={{ | ||
| padding: "4px 8px", | ||
| background: "#37373E", | ||
| color: "white", | ||
| fontSize: "12px", | ||
| borderRadius: "6px", | ||
| zIndex: 9999, | ||
| }} | ||
| /> | ||
| </div> | ||
| ); | ||
| } | ||
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
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.
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.