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

Refactor VisuallyHidden component to use ChakraUI #7724

Merged
merged 3 commits into from
Nov 14, 2022

Conversation

minimalsm
Copy link
Contributor

Description

Migrate VisuallyHidden from styled component to ChakraUI

Related Issue

#6374

@minimalsm minimalsm added the refactor ♻️ Changes which don't affect functionality label Sep 6, 2022
@vercel
Copy link

vercel bot commented Sep 6, 2022

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

Name Status Preview Updated
ethereum-org-website ❌ Failed (Inspect) Sep 6, 2022 at 4:38PM (UTC)

@@ -1,43 +1,18 @@
import React from "react"
import styled from "@emotion/styled"
import { VisuallyHidden as VisuallyHiddenSpan } from "@chakra-ui/react"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alias here as conflicted with component name

Copy link
Member

Choose a reason for hiding this comment

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

One thing on this, can you call it ChakraVisuallyHidden? since we are calling those aliases with the Chakra prefix in other files

z-index: 100000;
}
`
// Todo: Refactor to from isHidden boolean
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Obviously out of scope for this refactor, but I disagree with how this component is architected.

If we wrap something as VisuallyHidden, we shouldn't also need to pass a boolean to hide the item we're wrapping.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

&& we might not even need a component for this at all if all we're doing is importing Chakra's primitive 🤔?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this one is one of those components that we should remove completely and replace with the Chakra one.

My personal approach to this would be to use this PR to remove it and refactor the usage of this component in the entire codebase in favor of the Chakra one.

I'm fine as well if you want to take this middle ground approach. We could do the refactor later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can do, the only place we use it is in Layout.tsx.

Are we fine with just conditionally rendering, or is there a smarter way to go about it 🤔

{isZenMode ? (
  <VisuallyHidden>
    <Nav path={path} />
    {shouldShowSideNav && <SideNavMobile path={path} />}
  </VisuallyHidden>
) : (
  <React.Fragment>
    <Nav path={path} />
    {shouldShowSideNav && <SideNavMobile path={path} />}
  </React.Fragment>
)}

Copy link
Member

@pettinarip pettinarip Sep 7, 2022

Choose a reason for hiding this comment

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

Hmm looking into the code, I think it would be worth abstracting the zen mode state in its own component.

<ZenMode>
  <Nav />
  ...
</ZenMode>

Inside ZenMode, you will have all of the logic

function ZenMode({children}) {
  const [isZenMode, setIsZenMode] = useState(false)

  ...

  if(isZenMode) {
    return (
      <VisuallyHidden>{children}</VisuallyHidden>
    )
  }

  return chilren
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I will get to this when I have some free evening time this week.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is easier said than done given the handleZenModeChange in Layout.tsx is passed to a provider. Will do some thinking here today.

Copy link
Member

Choose a reason for hiding this comment

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

I think we can just import this context though instead of this. Still ways to clean it up.

@minimalsm minimalsm mentioned this pull request Sep 6, 2022
80 tasks
@gatsby-cloud
Copy link

gatsby-cloud bot commented Sep 6, 2022

✅ ethereum-org-website-dev deploy preview ready

@@ -1,43 +1,18 @@
import React from "react"
import styled from "@emotion/styled"
import { VisuallyHidden as VisuallyHiddenSpan } from "@chakra-ui/react"
Copy link
Member

Choose a reason for hiding this comment

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

One thing on this, can you call it ChakraVisuallyHidden? since we are calling those aliases with the Chakra prefix in other files

@corwintines
Copy link
Member

@minimalsm to update this

Copy link
Member

@pettinarip pettinarip left a comment

Choose a reason for hiding this comment

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

lgtm!

}

const VisuallyHidden: React.FC<IProps> = ({ isHidden = false, children }) =>
isHidden ? <Container>{children}</Container> : <>{children}</>
const VisuallyHidden: React.FC<IProps> = ({ children }) => {
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to change the name of this component. This is not a generic component anymore. This is strictly related to zen mode. Would suggest calling this component ZenMode.

Copy link
Member

Choose a reason for hiding this comment

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

Agree... just pushed a commit for this. I think this should be good to go now.

Copy link
Member

@pettinarip pettinarip left a comment

Choose a reason for hiding this comment

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

🚀

@corwintines corwintines merged commit 0a53dc1 into dev Nov 14, 2022
@corwintines corwintines deleted the migrateVisuallyHiddenToChakra branch November 14, 2022 20:44
@corwintines corwintines mentioned this pull request Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
archived: chakra-migration refactor ♻️ Changes which don't affect functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants