-
Notifications
You must be signed in to change notification settings - Fork 18
feat: Update component #164
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
+272
−4
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
2feba1e
init
pqoqubbw 66baeae
accordion + badge
pqoqubbw 578e9a7
remove banner
pqoqubbw 64ee67f
callout
pqoqubbw 32d4c84
card
pqoqubbw e019b03
color
pqoqubbw 0b57914
columns
pqoqubbw 6340637
frame
pqoqubbw 133b909
icon
pqoqubbw 90a1994
mermaid
pqoqubbw db1c668
panel, property
pqoqubbw 6bdb845
steps, tabs, tile
pqoqubbw e1cf8ec
rest
pqoqubbw 0a2fff4
autofix
pqoqubbw 94356c5
renames
pqoqubbw e816632
fix stoybook import
pqoqubbw d469c9e
fix cursor comment
pqoqubbw 58df402
fix cursor comment
pqoqubbw 392ce4a
add Update component
pqoqubbw edf8193
Merge branch 'main' of https://github.com/mintlify/components into dm…
pqoqubbw 42e4a0a
Merge branch 'main' of https://github.com/mintlify/components into dm…
pqoqubbw 611da6b
fix bugbot comments
pqoqubbw 99ab791
update pnpm-lock
pqoqubbw b82656a
remove isLivePreview
pqoqubbw 82494e2
fix comment
pqoqubbw bf53f6c
Merge branch 'main' of https://github.com/mintlify/components into dm…
pqoqubbw fec59fb
fix comment
pqoqubbw b7c85cc
fix tags duplication
pqoqubbw 6da4bde
fix lint
pqoqubbw eef6360
fix comments
pqoqubbw 481bfac
fix
pqoqubbw 1e05b45
fix
pqoqubbw e3a0b70
Merge branch 'main' of https://github.com/mintlify/components into dm…
pqoqubbw efb00e7
fix
pqoqubbw 6d9000f
cursor please stop
pqoqubbw 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
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 |
|---|---|---|
| @@ -1,3 +1,173 @@ | ||
| export const Update = () => { | ||
| return <div>Update</div>; | ||
| import { | ||
| type ComponentPropsWithoutRef, | ||
| forwardRef, | ||
| useCallback, | ||
| useEffect, | ||
| useMemo, | ||
| useState, | ||
| } from "react"; | ||
| import { type Rect, useRect } from "react-use-rect"; | ||
| import { LinkIcon } from "@/icons"; | ||
| import { Classes } from "@/lib/local/selectors"; | ||
| import { cn } from "@/utils/cn"; | ||
| import { copyToClipboard } from "@/utils/copy-to-clipboard"; | ||
|
|
||
| type UpdatePropsBase = { | ||
| id: string; | ||
| label: string; | ||
| description?: string; | ||
| tags?: string[]; | ||
| rss?: { | ||
| title?: string; | ||
| description?: string; | ||
| }; | ||
| onRegisterHeading?: (id: string, rect: Rect) => void; | ||
| onUnregisterHeading?: (id: string) => void; | ||
| hasContext?: boolean; | ||
| isVisible: boolean; | ||
| onCopyAnchorLink?: (id: string) => void; | ||
| }; | ||
|
|
||
| type UpdateProps = UpdatePropsBase & | ||
| Omit<ComponentPropsWithoutRef<"div">, keyof UpdatePropsBase>; | ||
|
|
||
| const Update = forwardRef<HTMLDivElement, UpdateProps>( | ||
| ( | ||
| { | ||
| children, | ||
| label, | ||
| id, | ||
| description, | ||
| tags, | ||
| className, | ||
| "aria-label": ariaLabel = "Navigate to changelog", | ||
| onRegisterHeading, | ||
| onUnregisterHeading, | ||
| hasContext, | ||
| isVisible, | ||
| onCopyAnchorLink, | ||
| ...props | ||
| }, | ||
| ref | ||
| ) => { | ||
| const [rect, setRect] = useState<Rect | null>(null); | ||
| const [rectRef] = useRect(setRect); | ||
| const tagsArray = useMemo( | ||
| () => [...new Set((tags ?? []).map((tag) => tag.trim()).filter(Boolean))], | ||
| [tags] | ||
| ); | ||
|
|
||
| const copyAnchorLink = useCallback(async () => { | ||
| if (typeof window === "undefined") { | ||
| return; | ||
| } | ||
|
|
||
| const result = await copyToClipboard( | ||
| `${window.location.href.split("#")[0]}#${encodeURIComponent(id)}` | ||
| ); | ||
|
|
||
| if (result === "success") { | ||
| window.location.hash = encodeURIComponent(id); | ||
| onCopyAnchorLink?.(id); | ||
| } | ||
| }, [id, onCopyAnchorLink]); | ||
|
pqoqubbw marked this conversation as resolved.
pqoqubbw marked this conversation as resolved.
pqoqubbw marked this conversation as resolved.
|
||
|
|
||
| useEffect(() => { | ||
| if (!(hasContext && isVisible && rect)) { | ||
| return; | ||
| } | ||
|
|
||
| onRegisterHeading?.(id, rect); | ||
|
|
||
| return () => { | ||
| onUnregisterHeading?.(id); | ||
| }; | ||
| }, [ | ||
| rect, | ||
| id, | ||
| hasContext, | ||
| isVisible, | ||
| onRegisterHeading, | ||
| onUnregisterHeading, | ||
| ]); | ||
|
pqoqubbw marked this conversation as resolved.
|
||
|
|
||
| if (!isVisible) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <div | ||
| className={cn( | ||
| Classes.Update, | ||
| "update-container relative flex w-full flex-col items-start gap-2 py-8 lg:flex-row lg:gap-6", | ||
| className | ||
| )} | ||
| id={id} | ||
| ref={ref} | ||
| {...props} | ||
| > | ||
| <div className="group top-(--scroll-mt) flex w-full shrink-0 flex-col items-start justify-start lg:sticky lg:w-[160px]"> | ||
| <div className="absolute"> | ||
| <a | ||
| aria-label={ariaLabel} | ||
| className="group/link -ml-10 flex items-center border-0 opacity-0 focus:opacity-100 focus:outline-0 group-hover:opacity-100" | ||
| href={`#${encodeURIComponent(id)}`} | ||
| > | ||
| ​ | ||
| <div className="flex h-6 w-6 items-center justify-center rounded-md bg-white text-gray-400 shadow-sm ring-1 ring-gray-400/30 hover:ring-gray-400/60 group-focus/link:border-2 group-focus/link:border-primary dark:bg-background-dark dark:text-white/50 dark:ring-1 dark:ring-gray-700/25 dark:brightness-[1.35] dark:group-focus/link:border-primary-light dark:hover:ring-white/20 dark:hover:brightness-150"> | ||
| <LinkIcon /> | ||
| </div> | ||
| </a> | ||
| </div> | ||
| {/** biome-ignore lint/a11y/noNoninteractiveElementInteractions: TODO */} | ||
| {/** biome-ignore lint/a11y/noStaticElementInteractions: TODO */} | ||
| {/** biome-ignore lint/a11y/useKeyWithClickEvents: TODO */} | ||
| <div | ||
| className="flex grow-0 cursor-pointer items-center justify-center rounded-lg bg-primary/10 px-2 py-1 font-medium text-primary text-sm dark:text-primary-light" | ||
| contentEditable={false} | ||
| data-component-part="update-label" | ||
| onClick={copyAnchorLink} | ||
| > | ||
| {label} | ||
| </div> | ||
| {tagsArray.length > 0 && ( | ||
| <div | ||
| className="mt-3 flex flex-wrap gap-2 px-1 text-secondary text-sm dark:text-secondary-light" | ||
| data-component-part="update-tag-list" | ||
| > | ||
| {tagsArray.map((tag) => ( | ||
| <span | ||
| className="inline-block rounded-lg font-medium text-sm" | ||
| data-component-part="update-tag" | ||
| key={tag} | ||
| > | ||
| {tag} | ||
| </span> | ||
| ))} | ||
|
pqoqubbw marked this conversation as resolved.
|
||
| </div> | ||
| )} | ||
| {description && ( | ||
| <div | ||
| className="wrap-break-word mt-3 max-w-[160px] px-1 text-secondary text-sm dark:text-secondary-light" | ||
| contentEditable={false} | ||
| data-component-part="update-description" | ||
| > | ||
| {description} | ||
| </div> | ||
| )} | ||
| </div> | ||
|
|
||
| <div className="max-w-full flex-1 overflow-hidden px-0.5" ref={rectRef}> | ||
| <div className="prose-sm" data-component-part="update-content"> | ||
| {children} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
| ); | ||
|
|
||
| Update.displayName = "Update"; | ||
|
|
||
| export { Update }; | ||
| export type { UpdateProps }; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Props
rssnot destructured, will pollute DOMMedium Severity
The
rssprop is defined inUpdatePropsBasebut is not destructured from props before spreading...propsonto the div element. When a consumer passes anrssobject, it will be spread onto the DOM element, causing React warnings about unknown DOM attributes and polluting the HTML with invalid attributes. Other props likeisLivePrevieware correctly destructured to prevent this issue.Additional Locations (1)
packages/components/src/components/update/update.tsx#L18-L22