-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
Added bookmarklink component for headings and link sharing #602
Conversation
Warning Rate limit exceeded@impirios has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 0 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe pull request introduces several modifications to the Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (2)
docs/components/layout/Documentation/Documentation.js (2)
7-10
: Consider using path aliases for importsThe absolute imports are good for maintainability, but consider using path aliases to make them more concise.
Example configuration in your build tool:
// jsconfig.json or tsconfig.json { "compilerOptions": { "baseUrl": ".", "paths": { "@docs/*": ["docs/*"], "@components/*": ["components/*"] } } }Then imports could be simplified:
- import CodeBlock from "@/components/layout/Documentation/helpers/CodeBlock" + import CodeBlock from "@docs/components/CodeBlock"
Line range hint
1-90
: Consider migrating to TypeScriptGiven the complexity of the Documentation component and its subcomponents, consider migrating to TypeScript for better type safety and developer experience.
Would you like me to help create a GitHub issue to track this enhancement?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
docs/components/layout/Documentation/Documentation.js
(2 hunks)docs/components/layout/Documentation/helpers/ComponentFeatures/ComponentFeatures.js
(1 hunks)docs/components/layout/Documentation/utils.js
(1 hunks)
export const BookMarkLink = ({ children, id }) => { | ||
return <div id={id}><a href={`#${id}`}>{children}</a></div> | ||
} |
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.
🛠️ Refactor suggestion
Enhance accessibility and user experience of BookMarkLink component
The component needs improvements in several areas:
- Add ARIA attributes for better screen reader support
- Add visual feedback for clickable links
- Sanitize the id prop to ensure valid HTML
Consider this enhanced implementation:
- export const BookMarkLink = ({ children, id }) => {
- return <div id={id}><a href={`#${id}`}>{children}</a></div>
- }
+ export const BookMarkLink = ({ children, id }) => {
+ const sanitizedId = id.toLowerCase().replace(/[^a-z0-9-]/g, '-');
+ return (
+ <div id={sanitizedId}>
+ <a
+ href={`#${sanitizedId}`}
+ aria-label={`Direct link to ${id}`}
+ className="group relative"
+ >
+ {children}
+ <span className="ml-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ #
+ </span>
+ </a>
+ </div>
+ );
+ }
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export const BookMarkLink = ({ children, id }) => { | |
return <div id={id}><a href={`#${id}`}>{children}</a></div> | |
} | |
export const BookMarkLink = ({ children, id }) => { | |
const sanitizedId = id.toLowerCase().replace(/[^a-z0-9-]/g, '-'); | |
return ( | |
<div id={sanitizedId}> | |
<a | |
href={`#${sanitizedId}`} | |
aria-label={`Direct link to ${id}`} | |
className="group relative" | |
> | |
{children} | |
<span className="ml-2 opacity-0 group-hover:opacity-100 transition-opacity"> | |
# | |
</span> | |
</a> | |
</div> | |
); | |
} |
<BookMarkLink id="features"> | ||
<Heading as="h6" className="mb-2 text-gray-1000 font-bold"> | ||
Features | ||
Features | ||
</Heading> | ||
<div className='mb-10'> | ||
<ul className='list-disc list-inside'> | ||
{ | ||
features.map((feature, index) => <li key={index}>{feature}</li>) | ||
} | ||
</ul> | ||
</div> | ||
</BookMarkLink> |
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.
Avoid hardcoded IDs in BookMarkLink
Using a static "features" ID could cause conflicts if multiple ComponentFeatures components are rendered on the same page.
Consider passing a unique ID based on the component context:
- <BookMarkLink id="features">
+ <BookMarkLink id={`${title?.toLowerCase?.() || 'component'}-features`}>
Also, consider adding PropTypes validation:
import PropTypes from 'prop-types';
ComponentFeatures.propTypes = {
features: PropTypes.arrayOf(PropTypes.string).isRequired,
title: PropTypes.string
};
@@ -49,7 +48,7 @@ const DocsTable = ({ children , columns=[], data=[]}) => { | |||
|
|||
|
|||
return <div className='mb-20'> | |||
<Heading as="h6" className="mb-4">API Documentation</Heading> | |||
<BookMarkLink id="api-documentation"> <Heading as="h6" className="mb-4">API Documentation</Heading> </BookMarkLink> |
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.
🛠️ Refactor suggestion
Improve heading hierarchy and accessibility
The current implementation has several concerns:
- Using h6 directly might not follow proper document outline
- "api-documentation" ID could conflict with multiple instances
Consider this improvement:
- <BookMarkLink id="api-documentation">
- <Heading as="h6" className="mb-4">API Documentation</Heading>
- </BookMarkLink>
+ <BookMarkLink id={`${title?.toLowerCase?.() || 'component'}-api`}>
+ <Heading
+ as={headingLevel || "h2"}
+ className="mb-4"
+ >
+ API Documentation
+ </Heading>
+ </BookMarkLink>
Also, consider adding a prop for the heading level to maintain proper document outline:
DocsTable.propTypes = {
headingLevel: PropTypes.oneOf(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']),
// ... other props
};
closes #475
Have added a BookmarkLink util component for documentation that takes id as a param and it will create a bookmark link out of the children we pass it to.
Summary by CodeRabbit
New Features
BookMarkLink
component for creating bookmark links in the documentation layout.DocsTable
component to wrap headings withBookMarkLink
for improved navigation.Bug Fixes
Style
ComponentFeatures
component's JSX.