-
-
Notifications
You must be signed in to change notification settings - Fork 53
Added Copy component #499
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 Copy component #499
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughThe changes introduced in this pull request include the addition of a new Changes
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 (
|
| const copySvg = <svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 9.50006C1 10.3285 1.67157 11.0001 2.5 11.0001H4L4 10.0001H2.5C2.22386 10.0001 2 9.7762 2 9.50006L2 2.50006C2 2.22392 2.22386 2.00006 2.5 2.00006L9.5 2.00006C9.77614 2.00006 10 2.22392 10 2.50006V4.00002H5.5C4.67158 4.00002 4 4.67159 4 5.50002V12.5C4 13.3284 4.67158 14 5.5 14H12.5C13.3284 14 14 13.3284 14 12.5V5.50002C14 4.67159 13.3284 4.00002 12.5 4.00002H11V2.50006C11 1.67163 10.3284 1.00006 9.5 1.00006H2.5C1.67157 1.00006 1 1.67163 1 2.50006V9.50006ZM5 5.50002C5 5.22388 5.22386 5.00002 5.5 5.00002H12.5C12.7761 5.00002 13 5.22388 13 5.50002V12.5C13 12.7762 12.7761 13 12.5 13H5.5C5.22386 13 5 12.7762 5 12.5V5.50002Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"></path></svg> | ||
|
|
||
| return( | ||
| <span style={{display:"flex",alignItems:"center"}}> |
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.
you can use tailwind here
className = "flex items-center"
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.
done
| import { useState,useEffect } from "react" | ||
|
|
||
|
|
||
| function Copy(props) { |
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.
do Copy({children,...props})
|
|
||
| return( | ||
| <span style={{display:"flex",alignItems:"center"}}> | ||
| {props.children} <button onClick={handleCopy} className=" m-0.5 mr-0 ml-2 px-1.5 py-1.5 text-sm font-bold rounded shadow-md text-white bg-gray-900 backdrop-blur-xl hover:bg-gray-800 ;">{isCopied ? tickSvg : copySvg}</button> |
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.
this can just be {children} after you update https://github.com/rad-ui/ui/pull/499/files#r1824128711
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.
done
| import Heading from "@radui/ui/Heading" | ||
| import Link from "@radui/ui/Link" | ||
| import Code from "@radui/ui/Code" | ||
| import Copy from "\\docs\\app\\docs\\components\\copy-code\\page.js" |
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.
`import Copy from "@/components/Copy``
For this to work, you need to create a new component file
Let's find a home for our copy component inside components folder
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: 5
🧹 Outside diff range and nitpick comments (2)
docs/app/docs/first-steps/installation/page.js (1)
27-28: Check whitespace in Code components.The Code components appear to have extra whitespace around the Copy components which might affect the display of the installation commands.
Apply these formatting fixes:
- <Code > - <Copy>yarn add @radui/ui </Copy> + <Code> + <Copy>yarn add @radui/ui</Copy>Also applies to: 31-32
docs/app/docs/components/copy-code/page.js (1)
1-4: Fix import formatting.Add space after comma in the import statement for better readability.
-import { useState,useEffect } from "react" +import { useState, useEffect } from "react"
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
docs/app/docs/components/copy-code/page.js(1 hunks)docs/app/docs/first-steps/installation/page.js(2 hunks)
🔇 Additional comments (3)
docs/app/docs/first-steps/installation/page.js (1)
7-7: Verify Copy component implementation.
Let's ensure the Copy component is properly implemented and exported from its source file.
Also applies to: 27-28, 31-32
✅ Verification successful
Copy component is properly implemented and exported
The Copy component is correctly implemented with:
- Default export at the end of the file
- Proper React component implementation with props handling
- Copy-to-clipboard functionality
- Visual feedback with SVG icons
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Verify the Copy component implementation
echo "Checking Copy component source file..."
cat docs/app/docs/components/copy-code/page.js
echo "\nChecking for other potential usages of Copy component..."
rg -l "import.*Copy.*copy-code"
Length of output: 2600
docs/app/docs/components/copy-code/page.js (2)
14-22: LGTM! Well-implemented effect hook.
The effect hook is properly implemented with:
- Correct cleanup of timeout
- Proper dependency tracking
- Good state management
8-10: Verify secure context for clipboard operations.
The Clipboard API requires a secure context (HTTPS) in modern browsers. Ensure this component is used in a secure context.
✅ Verification successful
The previous search might have failed because the pattern was too specific. Let's broaden our search to understand:
- Where the Copy component is used
- If there are Next.js configurations enforcing HTTPS
- If there are security headers or middleware enforcing secure contexts
Clipboard operations are safe in this context
The Copy component is used in a documentation site built with Next.js, which:
- Is used only for copying package installation commands
- Is deployed as part of Next.js documentation site which defaults to HTTPS in production
- Is used in a controlled environment (documentation page) rather than processing user input
The clipboard operation is safe in this context and doesn't require additional security measures.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check if the component is used in any non-HTTPS contexts
rg -l "Copy.*component" | xargs rg "http://"
Length of output: 44
Script:
#!/bin/bash
# Let's try a more comprehensive check:
# 1. Find all files that import or use the Copy component
rg -l "import.*Copy|<Copy"
# 2. Check the Next.js configuration for force HTTPS
fd "next.config" --type f
# 3. Check if there are any security headers or CSP configurations
fd "middleware|headers" --type f
Length of output: 156
Script:
#!/bin/bash
# Let's check the content of these files to understand the security context
# Check Next.js config for any security settings
cat docs/next.config.js
# Check where and how Copy component is used
cat docs/app/docs/first-steps/installation/page.js
# Since this is a Next.js app, let's also check for any environment configuration
fd ".env" --type f
Length of output: 1346
| import Heading from "@radui/ui/Heading" | ||
| import Link from "@radui/ui/Link" | ||
| import Code from "@radui/ui/Code" | ||
| import Copy from "\\docs\\app\\docs\\components\\copy-code\\page.js" |
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.
Fix the import path format.
The current import uses Windows-style backslashes which can cause issues. Use forward slashes for path separators in import statements, and consider using a relative path for better maintainability.
Apply this fix:
-import Copy from "\\docs\\app\\docs\\components\\copy-code\\page.js"
+import Copy from "../../components/copy-code/page"📝 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.
| import Copy from "\\docs\\app\\docs\\components\\copy-code\\page.js" | |
| import Copy from "../../components/copy-code/page" |
| function Copy(props) { | ||
| const [isCopied, setIsCopied] = useState(false) | ||
|
|
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 component props handling and add type safety.
Consider these improvements:
- Destructure the
childrenprop directly - Add PropTypes or TypeScript types for better type safety
-function Copy(props) {
- const [isCopied, setIsCopied] = useState(false)
+function Copy({ children }) {
+ const [isCopied, setIsCopied] = useState(false)If using TypeScript:
interface CopyProps {
children: string;
}
function Copy({ children }: CopyProps) {| const handleCopy = () => { | ||
| navigator.clipboard.writeText(props.children) | ||
| setIsCopied(true) | ||
|
|
||
| } |
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.
Add error handling for clipboard operations.
The clipboard operation could fail due to permissions or API unavailability. Consider adding proper error handling.
const handleCopy = () => {
- navigator.clipboard.writeText(props.children)
- setIsCopied(true)
+ try {
+ if (!navigator.clipboard) {
+ throw new Error('Clipboard API not available');
+ }
+ navigator.clipboard.writeText(props.children)
+ .then(() => setIsCopied(true))
+ .catch((error) => {
+ console.error('Failed to copy:', error);
+ // Optionally show error to user
+ });
+ } catch (error) {
+ console.error('Failed to copy:', error);
+ // Optionally show error to user
+ }
}📝 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.
| const handleCopy = () => { | |
| navigator.clipboard.writeText(props.children) | |
| setIsCopied(true) | |
| } | |
| const handleCopy = () => { | |
| try { | |
| if (!navigator.clipboard) { | |
| throw new Error('Clipboard API not available'); | |
| } | |
| navigator.clipboard.writeText(props.children) | |
| .then(() => setIsCopied(true)) | |
| .catch((error) => { | |
| console.error('Failed to copy:', error); | |
| // Optionally show error to user | |
| }); | |
| } catch (error) { | |
| console.error('Failed to copy:', error); | |
| // Optionally show error to user | |
| } | |
| } |
| const tickSvg = <svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M11.4669 3.72684C11.7558 3.91574 11.8369 4.30308 11.648 4.59198L7.39799 11.092C7.29783 11.2452 7.13556 11.3467 6.95402 11.3699C6.77247 11.3931 6.58989 11.3355 6.45446 11.2124L3.70446 8.71241C3.44905 8.48022 3.43023 8.08494 3.66242 7.82953C3.89461 7.57412 4.28989 7.55529 4.5453 7.78749L6.75292 9.79441L10.6018 3.90792C10.7907 3.61902 11.178 3.53795 11.4669 3.72684Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"></path></svg> | ||
| const copySvg = <svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 9.50006C1 10.3285 1.67157 11.0001 2.5 11.0001H4L4 10.0001H2.5C2.22386 10.0001 2 9.7762 2 9.50006L2 2.50006C2 2.22392 2.22386 2.00006 2.5 2.00006L9.5 2.00006C9.77614 2.00006 10 2.22392 10 2.50006V4.00002H5.5C4.67158 4.00002 4 4.67159 4 5.50002V12.5C4 13.3284 4.67158 14 5.5 14H12.5C13.3284 14 14 13.3284 14 12.5V5.50002C14 4.67159 13.3284 4.00002 12.5 4.00002H11V2.50006C11 1.67163 10.3284 1.00006 9.5 1.00006H2.5C1.67157 1.00006 1 1.67163 1 2.50006V9.50006ZM5 5.50002C5 5.22388 5.22386 5.00002 5.5 5.00002H12.5C12.7761 5.00002 13 5.22388 13 5.50002V12.5C13 12.7762 12.7761 13 12.5 13H5.5C5.22386 13 5 12.7762 5 12.5V5.50002Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"></path></svg> |
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
Optimize SVG handling.
Move SVG definitions outside the component to prevent recreation on each render. Consider moving them to a separate file for better maintainability.
+// icons.js
+export const tickSvg = <svg>...</svg>
+export const copySvg = <svg>...</svg>
+// Copy.js
+import { tickSvg, copySvg } from './icons'
function Copy(props) {
- const tickSvg = <svg>...</svg>
- const copySvg = <svg>...</svg>Committable suggestion was skipped due to low confidence.
| return( | ||
| <span style={{display:"flex",alignItems:"center"}}> | ||
| {props.children} <button onClick={handleCopy} className=" m-0.5 mr-0 ml-2 px-1.5 py-1.5 text-sm font-bold rounded shadow-md text-white bg-gray-900 backdrop-blur-xl hover:bg-gray-800 ;">{isCopied ? tickSvg : copySvg}</button> | ||
| </span> | ||
|
|
||
| ) |
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 styling and accessibility.
- Replace inline styles with Tailwind classes
- Add ARIA labels for better accessibility
- Format className string for better readability
- <span style={{display:"flex",alignItems:"center"}}>
- {props.children} <button onClick={handleCopy} className=" m-0.5 mr-0 ml-2 px-1.5 py-1.5 text-sm font-bold rounded shadow-md text-white bg-gray-900 backdrop-blur-xl hover:bg-gray-800 ;">{isCopied ? tickSvg : copySvg}</button>
+ <span className="flex items-center">
+ {children}
+ <button
+ onClick={handleCopy}
+ className="m-0.5 mr-0 ml-2 px-1.5 py-1.5 text-sm font-bold rounded shadow-md text-white bg-gray-900 backdrop-blur-xl hover:bg-gray-800"
+ aria-label={isCopied ? "Copied" : "Copy to clipboard"}
+ >
+ {isCopied ? tickSvg : copySvg}
+ </button>
</span>📝 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.
| return( | |
| <span style={{display:"flex",alignItems:"center"}}> | |
| {props.children} <button onClick={handleCopy} className=" m-0.5 mr-0 ml-2 px-1.5 py-1.5 text-sm font-bold rounded shadow-md text-white bg-gray-900 backdrop-blur-xl hover:bg-gray-800 ;">{isCopied ? tickSvg : copySvg}</button> | |
| </span> | |
| ) | |
| return( | |
| <span className="flex items-center"> | |
| {children} | |
| <button | |
| onClick={handleCopy} | |
| className="m-0.5 mr-0 ml-2 px-1.5 py-1.5 text-sm font-bold rounded shadow-md text-white bg-gray-900 backdrop-blur-xl hover:bg-gray-800" | |
| aria-label={isCopied ? "Copied" : "Copy to clipboard"} | |
| > | |
| {isCopied ? tickSvg : copySvg} | |
| </button> | |
| </span> | |
| ) |
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: 6
🧹 Outside diff range and nitpick comments (1)
docs/components/Copy.js (1)
1-2: Fix import formatting and consider adding TypeScript.The import statement needs proper spacing after the comma. Also, consider adding TypeScript for better type safety.
-import { useState,useEffect } from "react" +import { useState, useEffect } from "react"
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
docs/app/docs/first-steps/installation/page.js(2 hunks)docs/components/Copy.js(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- docs/app/docs/first-steps/installation/page.js
🔇 Additional comments (1)
docs/components/Copy.js (1)
34-34: LGTM!
The export statement follows common practice.
docs/components/Copy.js
Outdated
| const tickSvg = <svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M11.4669 3.72684C11.7558 3.91574 11.8369 4.30308 11.648 4.59198L7.39799 11.092C7.29783 11.2452 7.13556 11.3467 6.95402 11.3699C6.77247 11.3931 6.58989 11.3355 6.45446 11.2124L3.70446 8.71241C3.44905 8.48022 3.43023 8.08494 3.66242 7.82953C3.89461 7.57412 4.28989 7.55529 4.5453 7.78749L6.75292 9.79441L10.6018 3.90792C10.7907 3.61902 11.178 3.53795 11.4669 3.72684Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"></path></svg> | ||
| const copySvg = <svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 9.50006C1 10.3285 1.67157 11.0001 2.5 11.0001H4L4 10.0001H2.5C2.22386 10.0001 2 9.7762 2 9.50006L2 2.50006C2 2.22392 2.22386 2.00006 2.5 2.00006L9.5 2.00006C9.77614 2.00006 10 2.22392 10 2.50006V4.00002H5.5C4.67158 4.00002 4 4.67159 4 5.50002V12.5C4 13.3284 4.67158 14 5.5 14H12.5C13.3284 14 14 13.3284 14 12.5V5.50002C14 4.67159 13.3284 4.00002 12.5 4.00002H11V2.50006C11 1.67163 10.3284 1.00006 9.5 1.00006H2.5C1.67157 1.00006 1 1.67163 1 2.50006V9.50006ZM5 5.50002C5 5.22388 5.22386 5.00002 5.5 5.00002H12.5C12.7761 5.00002 13 5.22388 13 5.50002V12.5C13 12.7762 12.7761 13 12.5 13H5.5C5.22386 13 5 12.7762 5 12.5V5.50002Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"></path></svg> |
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 SVG accessibility and maintainability.
The SVGs should have proper accessibility attributes and could be extracted into separate components for better maintainability.
Consider creating separate components:
const TickIcon = () => (
<svg
width="15"
height="15"
viewBox="0 0 15 15"
aria-hidden="true"
role="img"
aria-label="Success tick"
// ... rest of the SVG
/>
);
const CopyIcon = () => (
<svg
width="15"
height="15"
viewBox="0 0 15 15"
aria-hidden="true"
role="img"
aria-label="Copy to clipboard"
// ... rest of the SVG
/>
);| function Copy({ children }) { | ||
| const [isCopied, setIsCopied] = useState(false) |
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
Add prop validation for better reliability.
Consider adding PropTypes or TypeScript interfaces to validate the children prop.
+import PropTypes from 'prop-types';
function Copy({ children }) {
const [isCopied, setIsCopied] = useState(false)
}
+
+Copy.propTypes = {
+ children: PropTypes.node.isRequired,
+};📝 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.
| function Copy({ children }) { | |
| const [isCopied, setIsCopied] = useState(false) | |
| import PropTypes from 'prop-types'; | |
| function Copy({ children }) { | |
| const [isCopied, setIsCopied] = useState(false) | |
| } | |
| Copy.propTypes = { | |
| children: PropTypes.node.isRequired, | |
| }; |
| const handleCopy = () => { | ||
| navigator.clipboard.writeText(children) | ||
| setIsCopied(true) | ||
|
|
||
| } |
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.
Add error handling for clipboard operations.
The clipboard operation could fail and should be handled appropriately. Also, check for clipboard API availability.
const handleCopy = () => {
- navigator.clipboard.writeText(children)
- setIsCopied(true)
+ if (!navigator?.clipboard) {
+ console.warn('Clipboard API not available');
+ return;
+ }
+ navigator.clipboard.writeText(children)
+ .then(() => setIsCopied(true))
+ .catch(err => {
+ console.error('Failed to copy:', err);
+ });
}📝 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.
| const handleCopy = () => { | |
| navigator.clipboard.writeText(children) | |
| setIsCopied(true) | |
| } | |
| const handleCopy = () => { | |
| if (!navigator?.clipboard) { | |
| console.warn('Clipboard API not available'); | |
| return; | |
| } | |
| navigator.clipboard.writeText(children) | |
| .then(() => setIsCopied(true)) | |
| .catch(err => { | |
| console.error('Failed to copy:', err); | |
| }); | |
| } |
| useEffect(() => { | ||
| let timeout; | ||
| if (isCopied) { | ||
| timeout = setTimeout(() => { | ||
| setIsCopied(false); | ||
| }, 2000); | ||
| } | ||
| return () => clearTimeout(timeout); | ||
| }, [isCopied]); |
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
Consider making the timeout duration configurable.
The timeout duration is hardcoded to 2000ms. Consider making it a prop for better flexibility.
-function Copy({ children }) {
+function Copy({ children, copyTimeout = 2000 }) {
// ...
if (isCopied) {
timeout = setTimeout(() => {
setIsCopied(false);
- }, 2000);
+ }, copyTimeout);
}
// ...
}Committable suggestion was skipped due to low confidence.
| "use client"; | ||
| import { useState,useEffect } from "react" | ||
|
|
||
|
|
||
| function Copy({ children }) { | ||
| const [isCopied, setIsCopied] = useState(false) | ||
|
|
||
| const handleCopy = () => { | ||
| navigator.clipboard.writeText(children) | ||
| setIsCopied(true) | ||
|
|
||
| } | ||
|
|
||
| useEffect(() => { | ||
| let timeout; | ||
| if (isCopied) { | ||
| timeout = setTimeout(() => { | ||
| setIsCopied(false); | ||
| }, 2000); | ||
| } | ||
| return () => clearTimeout(timeout); | ||
| }, [isCopied]); | ||
| const tickSvg = <svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M11.4669 3.72684C11.7558 3.91574 11.8369 4.30308 11.648 4.59198L7.39799 11.092C7.29783 11.2452 7.13556 11.3467 6.95402 11.3699C6.77247 11.3931 6.58989 11.3355 6.45446 11.2124L3.70446 8.71241C3.44905 8.48022 3.43023 8.08494 3.66242 7.82953C3.89461 7.57412 4.28989 7.55529 4.5453 7.78749L6.75292 9.79441L10.6018 3.90792C10.7907 3.61902 11.178 3.53795 11.4669 3.72684Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"></path></svg> | ||
| const copySvg = <svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 9.50006C1 10.3285 1.67157 11.0001 2.5 11.0001H4L4 10.0001H2.5C2.22386 10.0001 2 9.7762 2 9.50006L2 2.50006C2 2.22392 2.22386 2.00006 2.5 2.00006L9.5 2.00006C9.77614 2.00006 10 2.22392 10 2.50006V4.00002H5.5C4.67158 4.00002 4 4.67159 4 5.50002V12.5C4 13.3284 4.67158 14 5.5 14H12.5C13.3284 14 14 13.3284 14 12.5V5.50002C14 4.67159 13.3284 4.00002 12.5 4.00002H11V2.50006C11 1.67163 10.3284 1.00006 9.5 1.00006H2.5C1.67157 1.00006 1 1.67163 1 2.50006V9.50006ZM5 5.50002C5 5.22388 5.22386 5.00002 5.5 5.00002H12.5C12.7761 5.00002 13 5.22388 13 5.50002V12.5C13 12.7762 12.7761 13 12.5 13H5.5C5.22386 13 5 12.7762 5 12.5V5.50002Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"></path></svg> | ||
|
|
||
| return( | ||
| <span className = "flex items-center"> | ||
| {children} <button onClick={handleCopy} className=" m-0.5 mr-0 ml-2 px-1.5 py-1.5 text-sm font-bold rounded shadow-md text-white bg-gray-900 backdrop-blur-xl hover:bg-gray-800 ;">{isCopied ? tickSvg : copySvg}</button> | ||
| </span> | ||
|
|
||
| ) | ||
| } | ||
|
|
||
| export default Copy No newline at end of 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.
💡 Codebase verification
Add aria-label to Copy button for better accessibility
The Copy component is correctly used in the installation page for copying package installation commands. However, the button in the Copy component lacks proper accessibility attributes.
- Add
aria-labelto the button indocs/components/Copy.js:
<button
onClick={handleCopy}
aria-label={isCopied ? "Copied" : "Copy to clipboard"}
className="m-0.5 mr-0 ml-2 px-1.5 py-1.5 text-sm font-bold rounded shadow-md text-white bg-gray-900 backdrop-blur-xl hover:bg-gray-800"
>
{isCopied ? tickSvg : copySvg}
</button>🔗 Analysis chain
Verify component usage and accessibility.
Let's verify the component usage and check for potential accessibility issues in the codebase.
Let me gather more context about the component usage to provide a comprehensive response.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify Copy component usage and accessibility
# Test 1: Check Copy component usage
echo "Checking Copy component usage..."
rg -l "import.*Copy.*from" --type js
# Test 2: Check for potential accessibility issues with buttons
echo "Checking for buttons without aria-label..."
ast-grep --pattern 'button[!@aria-label]'
Length of output: 299
Script:
#!/bin/bash
# Check the actual implementation in the installation page
echo "Checking Copy component implementation in installation page..."
rg -A 5 -B 5 "<Copy" docs/app/docs/first-steps/installation/page.js
# Check if there are any other buttons without aria labels in the codebase
echo "Checking other button implementations..."
rg -A 2 "<button" --type js
Length of output: 2054
| return( | ||
| <span className = "flex items-center"> | ||
| {children} <button onClick={handleCopy} className=" m-0.5 mr-0 ml-2 px-1.5 py-1.5 text-sm font-bold rounded shadow-md text-white bg-gray-900 backdrop-blur-xl hover:bg-gray-800 ;">{isCopied ? tickSvg : copySvg}</button> | ||
| </span> | ||
|
|
||
| ) |
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.
Improve button accessibility and code formatting.
The button needs proper accessibility attributes, and the className string contains an unnecessary semicolon.
return(
<span className="flex items-center">
- {children} <button onClick={handleCopy} className=" m-0.5 mr-0 ml-2 px-1.5 py-1.5 text-sm font-bold rounded shadow-md text-white bg-gray-900 backdrop-blur-xl hover:bg-gray-800 ;">{isCopied ? tickSvg : copySvg}</button>
+ {children}
+ <button
+ onClick={handleCopy}
+ className="m-0.5 mr-0 ml-2 px-1.5 py-1.5 text-sm font-bold rounded shadow-md text-white bg-gray-900 backdrop-blur-xl hover:bg-gray-800"
+ aria-label={isCopied ? "Copied!" : "Copy to clipboard"}
+ title="Copy to clipboard"
+ >
+ {isCopied ? tickSvg : copySvg}
+ </button>
</span>
)📝 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.
| return( | |
| <span className = "flex items-center"> | |
| {children} <button onClick={handleCopy} className=" m-0.5 mr-0 ml-2 px-1.5 py-1.5 text-sm font-bold rounded shadow-md text-white bg-gray-900 backdrop-blur-xl hover:bg-gray-800 ;">{isCopied ? tickSvg : copySvg}</button> | |
| </span> | |
| ) | |
| return( | |
| <span className="flex items-center"> | |
| {children} | |
| <button | |
| onClick={handleCopy} | |
| className="m-0.5 mr-0 ml-2 px-1.5 py-1.5 text-sm font-bold rounded shadow-md text-white bg-gray-900 backdrop-blur-xl hover:bg-gray-800" | |
| aria-label={isCopied ? "Copied!" : "Copy to clipboard"} | |
| title="Copy to clipboard" | |
| > | |
| {isCopied ? tickSvg : copySvg} | |
| </button> | |
| </span> | |
| ) |
docs/app/docs/components/copy-code/page.jslocation of copy componentFix needed -
docs/app/docs/first-steps/installation/page.jslocation of importSummary by CodeRabbit
New Features
Copycomponent that allows users to easily copy installation commands for Yarn and npm directly from the documentation.Documentation
Copycomponent for better command accessibility.