-
Notifications
You must be signed in to change notification settings - Fork 25
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
docs(overview): add neon gradient card to hero page #227
Merged
MFarabi619
merged 1 commit into
cuhacking:main
from
anakafeel:anakafeel/docs/225-add-neon-gradient-card
Jan 1, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
import { NeonGradientCard } from './neon-gradient-card' | ||
|
||
const defaultChildren = ( | ||
<div className="w-full h-auto overflow-hidden rounded-[calc(19px-3px)] bg-transparent"> | ||
<img | ||
className="block w-full h-full object-cover m-0 p-0" | ||
src="https://github.com/user-attachments/assets/1a0a5cb7-95fd-49ce-a8b5-4742cccb1cc8" | ||
alt="2025 Docs Site Cover" | ||
/> | ||
</div> | ||
) | ||
|
||
const meta: Meta<typeof NeonGradientCard> = { | ||
title: '📚 Docs Site/Neon Gradient Card', | ||
component: NeonGradientCard, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
tags: ['autodocs'], | ||
args: { | ||
children: defaultChildren, | ||
borderSize: 5, | ||
borderRadius: 20, | ||
neonColors: { | ||
firstColor: '#ff00aa', | ||
secondColor: '#00FFF1', | ||
}, | ||
className: '', | ||
}, | ||
argTypes: { | ||
'children': { | ||
control: false, // Disable control for this prop | ||
}, | ||
'borderSize': { | ||
control: { type: 'number', min: 1, max: 20 }, | ||
}, | ||
'borderRadius': { | ||
control: { type: 'number', min: 0, max: 50 }, | ||
}, | ||
'neonColors': { | ||
control: 'object', | ||
}, | ||
'neonColors.firstColor': { | ||
control: 'color', | ||
}, | ||
'neonColors.secondColor': { | ||
control: 'color', | ||
}, | ||
'className': { | ||
control: 'text', | ||
}, | ||
}, | ||
} | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof NeonGradientCard> | ||
|
||
export const Default: Story = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
'use client' | ||
|
||
import type { | ||
CSSProperties, | ||
ReactElement, | ||
ReactNode, | ||
} from 'react' | ||
import { cn } from '@cuhacking/shared/utils/cn' | ||
|
||
import { | ||
useEffect, | ||
useRef, | ||
useState, | ||
} from 'react' | ||
|
||
interface NeonColorsProps { | ||
firstColor: string | ||
secondColor: string | ||
} | ||
|
||
interface NeonGradientCardProps { | ||
/** | ||
* @default <div/> | ||
* @type ReactElement | ||
* @description | ||
* The component to be rendered as the card | ||
*/ | ||
as?: ReactElement | ||
/** | ||
* @default "" | ||
* @type string | ||
* @description | ||
* The className of the card | ||
*/ | ||
className?: string | ||
|
||
/** | ||
* @default "" | ||
* @type ReactNode | ||
* @description | ||
* The children of the card | ||
*/ | ||
children?: ReactNode | ||
|
||
/** | ||
* @default 5 | ||
* @type number | ||
* @description | ||
* The size of the border in pixels | ||
*/ | ||
borderSize?: number | ||
|
||
/** | ||
* @default 20 | ||
* @type number | ||
* @description | ||
* The size of the radius in pixels | ||
*/ | ||
borderRadius?: number | ||
|
||
/** | ||
* @default "{ firstColor: '#ff00aa', secondColor: '#00FFF1' }" | ||
* @type NeonColorsProps | ||
* @description | ||
* The colors of the neon gradient | ||
*/ | ||
neonColors?: NeonColorsProps | ||
|
||
[key: string]: any | ||
} | ||
|
||
// Define the default neon colors outside the component to avoid passing an object expression directly as a default prop | ||
const defaultNeonColors: NeonColorsProps = { | ||
firstColor: '#84cc16', | ||
secondColor: '#f97316', | ||
} | ||
|
||
const NeonGradientCard: React.FC<NeonGradientCardProps> = ({ | ||
className, | ||
children, | ||
borderSize = 2, | ||
borderRadius = 20, | ||
neonColors = defaultNeonColors, | ||
...props | ||
}) => { | ||
const containerRef = useRef<HTMLDivElement>(null) | ||
const [dimensions, setDimensions] = useState({ width: 0, height: 0 }) | ||
|
||
useEffect(() => { | ||
const updateDimensions = () => { | ||
if (containerRef.current) { | ||
const { offsetWidth, offsetHeight } = containerRef.current | ||
setDimensions({ width: offsetWidth, height: offsetHeight }) | ||
} | ||
} | ||
|
||
updateDimensions() | ||
window.addEventListener('resize', updateDimensions) | ||
|
||
return () => { | ||
window.removeEventListener('resize', updateDimensions) | ||
} | ||
}, []) | ||
|
||
useEffect(() => { | ||
if (containerRef.current) { | ||
const { offsetWidth, offsetHeight } = containerRef.current | ||
setDimensions({ width: offsetWidth, height: offsetHeight }) | ||
} | ||
}, [children]) | ||
|
||
return ( | ||
<div | ||
ref={containerRef} | ||
style={ | ||
{ | ||
'--border-size': `${borderSize}px`, | ||
'--border-radius': `${borderRadius}px`, | ||
'--neon-first-color': neonColors.firstColor, | ||
'--neon-second-color': neonColors.secondColor, | ||
'--card-width': `${dimensions.width}px`, | ||
'--card-height': `${dimensions.height}px`, | ||
'--card-content-radius': `${borderRadius - borderSize}px`, | ||
'--pseudo-element-background-image': `linear-gradient(0deg, ${neonColors.firstColor}, ${neonColors.secondColor})`, | ||
'--pseudo-element-width': `${dimensions.width + borderSize * 2}px`, | ||
'--pseudo-element-height': `${dimensions.height + borderSize * 2}px`, | ||
'--after-blur': `${dimensions.width / 3}px`, | ||
} as CSSProperties | ||
} | ||
className={cn( | ||
'relative z-10 size-full rounded-[var(--border-radius)]', | ||
className, | ||
)} | ||
{...props} | ||
> | ||
<div | ||
className={cn( | ||
'relative size-full min-h-[100%] rounded-[var(--card-content-radius)] bg-gray-100 ', | ||
'before:absolute before:-left-[var(--border-size)] before:-top-[var(--border-size)] before:-z-10 before:block', | ||
'before:h-[var(--pseudo-element-height)] before:w-[var(--pseudo-element-width)] before:rounded-[var(--border-radius)] before:content-[\'\']', | ||
'before:bg-[linear-gradient(0deg,var(--neon-first-color),var(--neon-second-color))] before:bg-[length:100%_200%]', | ||
'before:animate-background-position-spin', | ||
'after:absolute after:-left-[var(--border-size)] after:-top-[var(--border-size)] after:-z-10 after:block', | ||
'after:h-[var(--pseudo-element-height)] after:w-[var(--pseudo-element-width)] after:rounded-[var(--border-radius)] after:blur-[var(--after-blur)] after:content-[\'\']', | ||
'after:bg-[linear-gradient(0deg,var(--neon-first-color),var(--neon-second-color))] after:bg-[length:100%_200%] after:opacity-80', | ||
'after:animate-background-position-spin', | ||
'dark:bg-neutral-900', | ||
)} | ||
> | ||
{children} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export { NeonGradientCard } |
60 changes: 60 additions & 0 deletions
60
libs/external/magic-ui/components/ui/neon-gradient-card.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
import { NeonGradientCard } from './neon-gradient-card' | ||
|
||
const defaultChildren = ( | ||
<div className="w-full h-auto overflow-hidden rounded-[calc(19px-3px)] bg-transparent"> | ||
<img | ||
className="block w-full h-full object-cover m-0 p-0" | ||
src="https://github.com/user-attachments/assets/1a0a5cb7-95fd-49ce-a8b5-4742cccb1cc8" | ||
alt="2025 Docs Site Cover" | ||
/> | ||
</div> | ||
) | ||
|
||
const meta: Meta<typeof NeonGradientCard> = { | ||
title: '🪄 Magic UI/Neon Gradient Card', | ||
component: NeonGradientCard, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
tags: ['autodocs'], | ||
args: { | ||
children: defaultChildren, | ||
borderSize: 5, | ||
borderRadius: 20, | ||
neonColors: { | ||
firstColor: '#ff00aa', | ||
secondColor: '#00FFF1', | ||
}, | ||
className: '', | ||
}, | ||
argTypes: { | ||
'children': { | ||
control: false, // Disable control for this prop | ||
}, | ||
'borderSize': { | ||
control: { type: 'number', min: 1, max: 20 }, | ||
}, | ||
'borderRadius': { | ||
control: { type: 'number', min: 0, max: 50 }, | ||
}, | ||
'neonColors': { | ||
control: 'object', | ||
}, | ||
'neonColors.firstColor': { | ||
control: 'color', | ||
}, | ||
'neonColors.secondColor': { | ||
control: 'color', | ||
}, | ||
'className': { | ||
control: 'text', | ||
}, | ||
}, | ||
} | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof NeonGradientCard> | ||
|
||
export const Default: Story = {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Several improvements needed for the NeonGradientCard implementation
The image source URL points to a GitHub user attachment which might not be permanent. Consider moving it to a more stable location within your project's assets.
The border radius calculation (
calc(19px-3px)
) in the className seems brittle. Consider using Tailwind's built-in border radius classes or defining a custom theme value.The
z-5
class seems arbitrary and might cause stacking context issues. Consider if this z-index is really necessary.The alt text could be more descriptive to improve accessibility.
Here's a suggested improvement:
🧰 Tools
🪛 LanguageTool
[uncategorized] ~31-~31: A determiner appears to be missing. Consider inserting it.
Context: ...) hackathon platform. <NeonGradientCard className="animate-background-position-s...
(AI_EN_LECTOR_MISSING_DETERMINER)