Skip to content
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

[v4] simplify the class-name of the sidebar file item #3444

Conversation

87xie
Copy link
Contributor

@87xie 87xie commented Oct 14, 2024

Why:

Closes: N/A

This PR aims to simplify the class name of the sidebar file item. Since the file item only needs _flex _flex-col _gap-1 when active && props.anchors.length > 0, I added _mt-1 to the anchor list to achieve the same effect.

image

What's being changed (if available, include any code snippets, screenshots, or gifs):

sidebar

image

mobile nav

image

Check off the following:

  • I have reviewed my changes in staging, available via the View
    deployment
    link in this PR's timeline (this link will be available after
    opening the PR).

Copy link

changeset-bot bot commented Oct 14, 2024

🦋 Changeset detected

Latest commit: ddab631

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Oct 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nextra-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 14, 2024 2:37pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
nextra ⬜️ Ignored (Inspect) Visit Preview Oct 14, 2024 2:37pm

Copy link

vercel bot commented Oct 14, 2024

@87xie is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Collaborator

@dimaMachina dimaMachina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First blood for v4 from you! Thanks a lot Oscar 😅 I did some improvements, will push directly on your branch

border: cn(
'_relative before:_absolute before:_inset-y-1',
'before:_w-px before:_bg-gray-200 before:_content-[""] dark:before:_bg-neutral-800',
'_ps-3 before:_start-0'
'_ps-3 before:_start-0 _pt-1 _ms-3'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of your _mt-1, let's use _pt-1 which we already used here
image

Comment on lines -166 to +167
if (isLink) {
// If it's focused, we toggle it. Otherwise, always open it.
if (active || clickedToggleIcon) {
TreeState[item.route] = !open
} else {
TreeState[item.route] = true
}
rerender({})
return
}
if (active) return
TreeState[item.route] = !open
// If it's focused, we toggle it. Otherwise, always open it.
TreeState[item.route] = active || clickedToggleIcon ? !open : true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fix bug when <button> can't be closed 😅 (we have similar issue in v3 btw)

Screen.Recording.2024-10-14.at.17.29.36.mov

Comment on lines +63 to +67
// Add inner <div> only if children.length != 1
const newChildren = useMemo(
() => (Children.count(children) === 1 ? children : <div>{children}</div>),
[children]
)
Copy link
Collaborator

@dimaMachina dimaMachina Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this to use for 1 inner div less in (div in screenshot will be removed)
image
and
image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, I guess it produces Uncaught Error: Minified React error #425 🧐
image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://react.dev/errors/425 Text content does not match server-rendered HTML. 🧐

@87xie
Copy link
Contributor Author

87xie commented Oct 14, 2024

Thanks for the update!

@dimaMachina dimaMachina merged commit 73726ec into shuding:v4-v2 Oct 14, 2024
6 of 9 checks passed
@87xie
Copy link
Contributor Author

87xie commented Oct 14, 2024

Additionally, I’d like to ask if it’s preferable to place the condition for anchors inside useMemo in <Sidebar>, like this:

export function Sidebar({ toc }: { toc: Heading[] }): ReactElement {
  const themeConfig = useThemeConfig()
  const anchors = useMemo(() => (
    return themeConfig.toc.float ? [] : toc.filter(v => v.depth === 2)
  ), [themeConfig.toc.float, toc])
  // ...
}

This change doesn’t bring any significant benefit, but it might help avoid missing the ternary operator in the JSX when searching for anchors.

@87xie 87xie deleted the simplify-the-class-name-of-the-sidebar-file-item branch October 14, 2024 14:58
@dimaMachina
Copy link
Collaborator

Additionally, I’d like to ask if it’s preferable to place the condition for anchors inside useMemo in <Sidebar>, like this:

export function Sidebar({ toc }: { toc: Heading[] }): ReactElement {
  const themeConfig = useThemeConfig()
  const anchors = useMemo(() => (
    return themeConfig.toc.float ? [] : toc.filter(v => v.depth === 2)
  ), [themeConfig.toc.float, toc])
  // ...
}

This change doesn’t bring any significant benefit, but it might help avoid missing the ternary operator in the JSX when searching for anchors.

lgtm, you can add this change in some of your future contributions 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants