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

feat: added the toggle button so that reader can read the whole docs … #3328

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mohdshubair313
Copy link

@mohdshubair313 mohdshubair313 commented Oct 25, 2024

…in full view

Description

  • ...
  • ...
  • ...

Related issue(s)
#3325 fixes the not viewing the content in full view but instead I add a toggle button so that when needed users can uses that sidebar

Summary by CodeRabbit

  • New Features

    • Introduced HideIcon and ShowIcon components for enhanced visual representation.
    • Added a sidebar toggle feature in the documentation layout, allowing users to show or hide the sidebar dynamically.
  • Style

    • Implemented new styles for the sidebar toggle button, improving visual feedback based on the sidebar's state.

Copy link

coderabbitai bot commented Oct 25, 2024

Walkthrough

This pull request introduces two new functional components, HideIcon and ShowIcon, which render SVG icons for toggling a sidebar. The DocsLayout component is modified to include these icons and manage the sidebar's visibility through a new state variable and a toggle function. Additionally, styling for a sidebar toggle button is added in the global CSS, enhancing the user interface and interaction with the sidebar.

Changes

File Change Summary
components/icons/HideIcon.tsx Added a new functional component HideIcon that renders an SVG icon.
components/icons/ShowIcon.tsx Added a new functional component ShowIcon that renders an SVG icon.
components/layout/DocsLayout.tsx Modified to include HideIcon and ShowIcon, added state variable isSidebarVisible, and a toggle function.
styles/globals.css Introduced new styles for the sidebar toggle button, including dimensions and background color changes.

Possibly related PRs

Suggested labels

ready-to-merge, bounty

Suggested reviewers

  • derberg
  • magicmatatjahu
  • anshgoyalevil
  • sambhavgupta0705
  • asyncapi-bot-eve

Poem

🐰 In the layout where icons play,
A toggle button brightens the day.
Hide or show, the sidebar's cheer,
With a click, it’s always near!
So hop along, let’s make it right,
With new icons, our UI's a delight! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0574475 and da00379.

📒 Files selected for processing (2)
  • components/icons/HideIcon.tsx (1 hunks)
  • styles/globals.css (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/icons/HideIcon.tsx
🧰 Additional context used
🪛 Biome
styles/globals.css

[error] 359-359: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 363-363: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)

🔇 Additional comments (2)
styles/globals.css (2)

355-360: Previous review comment is still applicable.

The previous review comment suggesting UX improvements for the button styling is still valid for this implementation.

🧰 Tools
🪛 Biome

[error] 359-359: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


355-364: ⚠️ Potential issue

Fix CSS syntax errors and enhance accessibility.

There are several issues with the current implementation:

  1. CSS property names are incorrect:
    • backgroundColor should be background-color
    • backgroundcolor should be background-color
  2. Missing important accessibility and UX features

Apply this diff to fix the issues and enhance the implementation:

 button#sidebarToggle {
   width: 50px;
   height: 50px;
   display: inline-block;
-  backgroundColor: white;
+  background-color: white;
+  border: 1px solid #e4e4e4;
+  border-radius: 4px;
+  cursor: pointer;
+  transition: all 0.2s ease;
+  position: relative;
+  
+  /* Ensure the button is accessible */
+  &:focus-visible {
+    outline: 2px solid #4b79cf;
+    outline-offset: 2px;
+  }
+  
+  &:hover {
+    background-color: #f5f5f5;
+  }
 }

 button#sidebarToggle.open {
-  backgroundcolor: black;
+  background-color: #f5f5f5;
 }

This implementation:

  • Fixes the CSS property name syntax
  • Adds smooth transitions to prevent visual jarring
  • Improves accessibility with proper focus states
  • Enhances user experience with hover effects
  • Uses a more subtle color scheme that aligns with the existing design
✅ Verification successful

Fix CSS syntax errors and enhance accessibility in styles/globals.css

The verification confirms that the incorrect CSS property names (backgroundColor and backgroundcolor) only exist in the reviewed file styles/globals.css. The proposed changes are valid and necessary:

  1. The CSS syntax errors need to be fixed:
    • Line 355: backgroundColor: whitebackground-color: white
    • Line 362: backgroundcolor: blackbackground-color: black

The suggested improvements for accessibility and UX (transitions, focus states, hover effects) will enhance the implementation without affecting other parts of the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify if there are any other instances of incorrect CSS property names
rg -i 'backgroundColor|backgroundcolor' '*.css'

Length of output: 95


Script:

#!/bin/bash
# First, let's find all CSS files in the repository
fd -e css

# Then search for incorrect CSS property names in those files
fd -e css --exec rg -i 'backgroundColor|backgroundcolor' {}

Length of output: 194

🧰 Tools
🪛 Biome

[error] 359-359: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


[error] 363-363: Unknown property is not allowed.

See CSS Specifications and browser specific properties for more details.
To resolve this issue, replace the unknown property with a valid CSS property.

(lint/correctness/noUnknownProperty)


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

Copy link

netlify bot commented Oct 25, 2024

Deploy Preview for asyncapi-website failed.

Built without sensitive environment variables

Name Link
🔨 Latest commit da00379
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/672080fe6ac50d0008dd877a

@asyncapi-bot
Copy link
Contributor

asyncapi-bot commented Oct 25, 2024

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 42
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-3328--asyncapi-website.netlify.app/

@mohdshubair313 mohdshubair313 changed the title feat: Added the toggle button so that reader can read the whole docs … feat: added the toggle button so that reader can read the whole docs … Oct 25, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Outside diff range and nitpick comments (4)
styles/globals.css (1)

354-364: Consider performance optimizations for the toggle button.

Given the low Lighthouse performance score (47), we should optimize the button's rendering performance:

  1. Use transform instead of background-color for animations
  2. Add will-change hint when appropriate
  3. Consider using @layer to better organize styles
+@layer components {
+  .sidebar-toggle {
+    /* ... existing styles ... */
+    transform: translateZ(0);
+  }
+
+  .sidebar-toggle--open {
+    /* ... existing styles ... */
+  }
+
+  /* Add will-change only when the button is about to animate */
+  .sidebar-toggle--animating {
+    will-change: transform, background-color;
+  }
+}

This optimization aligns with the PR's goal of improving the documentation viewing experience while addressing the performance concerns highlighted in the Lighthouse report.

components/layout/DocsLayout.tsx (3)

83-89: Improve state variable naming convention.

The state management implementation is correct, but the setter function name setisSidebarVisible should follow camelCase convention.

-const [isSidebarVisible, setisSidebarVisible] = useState(true);
+const [isSidebarVisible, setIsSidebarVisible] = useState(true);

Line range hint 144-237: Refactor layout structure to avoid code duplication.

The current implementation duplicates the main content markup when the sidebar is hidden. This can lead to maintenance issues and potential inconsistencies.

Consider refactoring to use CSS classes for controlling the layout instead:

-{!isSidebarVisible && (
-  <div className='flex flex-row' id='main-content'>
-    <!-- duplicated content -->
-  </div>
-)}
+<div className={`flex flex-row transition-all duration-200 ${isSidebarVisible ? 'ml-64' : 'ml-0'}`}>
+  <!-- single instance of content -->
+</div>

This approach:

  1. Eliminates code duplication
  2. Provides smooth transitions
  3. Maintains consistent structure

129-143: Address performance implications of sidebar toggle.

Given the low performance score (47) in the Lighthouse report, consider these optimizations:

  1. Add width and height attributes to the icon components to prevent layout shifts
  2. Use CSS transform instead of conditional rendering for smoother transitions
  3. Consider using React.memo() for the sidebar component to prevent unnecessary re-renders

Example optimization:

+const MemoizedSidebar = React.memo(DocsNavWrapper);

 <div className='flex flex-row' id='main-content'>
   <button id='sidebarToggle' /* ... */ >
     {isSidebarVisible ? <HideIcon width={24} height={24} /> : <ShowIcon width={24} height={24} />}
   </button>
-  {isSidebarVisible && (
-    <div className='lg:flex lg:shrink-0'>
-      {sidebar}
-    </div>
-  )}
+  <div className={`lg:flex lg:shrink-0 transform transition-transform duration-200 ${
+    isSidebarVisible ? 'translate-x-0' : '-translate-x-full'
+  }`}>
+    <MemoizedSidebar setShowMenu={setShowMenu} navigation={navigation} post={post} />
+  </div>
 </div>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bb69a47 and 0574475.

📒 Files selected for processing (4)
  • components/icons/HideIcon.tsx (1 hunks)
  • components/icons/ShowIcon.tsx (1 hunks)
  • components/layout/DocsLayout.tsx (4 hunks)
  • styles/globals.css (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • components/icons/ShowIcon.tsx
🔇 Additional comments (3)
components/icons/HideIcon.tsx (1)

1-9: Verify the icon's usage in the sidebar toggle functionality.

The icon appears to be part of the sidebar toggle feature mentioned in the PR objectives.

Let's verify its implementation:

✅ Verification successful

HideIcon is correctly implemented in the sidebar toggle functionality

The verification confirms that:

  • HideIcon is properly imported and used in DocsLayout.tsx
  • It's correctly integrated into the sidebar toggle button, switching between HideIcon and ShowIcon based on the isSidebarVisible state
  • The toggle functionality is properly implemented with state management and conditional rendering
  • The button has appropriate accessibility attributes
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check how the HideIcon is imported and used in the DocsLayout component
# and if there are any other components using it

# Search for HideIcon imports and usage
rg -l "HideIcon"

# Check the DocsLayout component implementation
ast-grep --pattern 'import $_ from "./icons/HideIcon"'

Length of output: 136


Script:

#!/bin/bash
# Let's check how HideIcon is used in DocsLayout.tsx
rg "HideIcon" components/layout/DocsLayout.tsx -B 2 -A 2

# Also check for any sidebar toggle related state or functionality
ast-grep --pattern 'const [$_] = useState<boolean>'  components/layout/DocsLayout.tsx

Length of output: 542


Script:

#!/bin/bash
# Let's check for the sidebar toggle state and function implementation
rg "toggleSidebar|isSidebarVisible" components/layout/DocsLayout.tsx -B 2 -A 2

# Also check if there are any related accessibility attributes or aria labels
rg "aria-|role" components/layout/DocsLayout.tsx

Length of output: 1119

styles/globals.css (1)

362-364: ⚠️ Potential issue

Improve color contrast and consider using CSS classes instead of IDs.

  1. The stark contrast between white and black states might be jarring. Consider using softer colors.
  2. Using IDs for styling creates high specificity and can lead to maintainability issues.
-button#sidebarToggle.open {
-  background-color: black;
+.sidebar-toggle {
+  background-color: var(--sidebar-toggle-bg, white);
+}
+
+.sidebar-toggle--open {
+  background-color: var(--sidebar-toggle-active-bg, #2d2d2d);
}

Let's verify the color contrast ratios for accessibility:

✅ Verification successful

Let me gather more context about the color-related styles for this button.


Let me check if there are any CSS custom properties (variables) defined in the codebase that we could leverage.


Confirmed: Color contrast and specificity improvements needed

The current implementation has several issues:

  • Uses high-specificity ID selector (button#sidebarToggle)
  • Has a harsh white-to-black color transition
  • Lacks CSS custom properties for maintainable theming

Recommended changes:

  • Replace ID with BEM-style classes as suggested
  • Use #2d2d2d instead of pure black for better visual comfort
  • Introduce CSS custom properties for colors
  • Consider adding hover/focus states for better interactivity

The original review comment's suggestions are valid and would improve both maintainability and user experience.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if there are any other color-related styles for the sidebar toggle
# that might affect contrast ratios

rg -i "sidebarToggle" --type css

Length of output: 121


Script:

#!/bin/bash
# Get the complete style definitions for the sidebar toggle button
rg -A 5 "button#sidebarToggle" styles/globals.css

Length of output: 289


Script:

#!/bin/bash
# Search for CSS custom properties related to colors or sidebar
rg -i "(:root|--.*color|--.*sidebar)" --type css

Length of output: 112

components/layout/DocsLayout.tsx (1)

23-24: LGTM: Icon imports are properly organized.

The new icon imports are correctly placed alongside other icon imports.

components/icons/HideIcon.tsx Outdated Show resolved Hide resolved
components/icons/HideIcon.tsx Outdated Show resolved Hide resolved
components/icons/HideIcon.tsx Outdated Show resolved Hide resolved
styles/globals.css Outdated Show resolved Hide resolved
components/layout/DocsLayout.tsx Show resolved Hide resolved
@anshgoyalevil
Copy link
Member

@mohdshubair313 Have you checked this PR's deployment. Seems like the changes you made aren't working.

@Manancode
Copy link

@mohdshubair313 it is not working locally
this approach conflicts with the existing responsive design
toggle button (HideIcon/ShowIcon) completely removes content from the page instead of just moving it aside

@mohdshubair313
Copy link
Author

@mohdshubair313 it is not working locally this approach conflicts with the existing responsive design toggle button (HideIcon/ShowIcon) completely removes content from the page instead of just moving it aside

Yeah because I think the content should be visible in full view to the users If this is the issue so what should I do

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.

4 participants