-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dbbb594
commit f23ae58
Showing
6 changed files
with
97 additions
and
39 deletions.
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
44 changes: 44 additions & 0 deletions
44
docs/storybook/stories/StorybookComponents/BezierCurve/BezierCurve.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,44 @@ | ||
import React, {useRef, useEffect} from 'react' | ||
|
||
export const CubicBezier = ({bezier}: {bezier: [number, number, number, number]}) => { | ||
const canvasRef = useRef(null) | ||
const padding = 20 | ||
const lineWidth = '6' | ||
const fillStart = 'purple' | ||
const fillEnd = 'blue' | ||
|
||
// Convert CSS cubic-bezier array to control points | ||
const [x1, y1, x2, y2] = bezier | ||
const p0 = {x: padding, y: 500 - padding} | ||
const p1 = { | ||
x: x1 * (500 - 2 * padding) + padding, | ||
y: 500 - (y1 * (500 - 2 * padding) + padding), | ||
} | ||
const p2 = { | ||
x: x2 * (500 - 2 * padding) + padding, | ||
y: 500 - (y2 * (500 - 2 * padding) + padding), | ||
} | ||
const p3 = {x: 500 - padding, y: padding} | ||
|
||
useEffect(() => { | ||
const canvas = canvasRef.current | ||
const ctx = canvas.getContext('2d') | ||
ctx.clearRect(0, 0, canvas.width, canvas.height) | ||
|
||
// Create gradient | ||
const gradient = ctx.createLinearGradient(p0.x, p0.y, p3.x, p3.y) | ||
gradient.addColorStop(0, fillStart) | ||
gradient.addColorStop(1, fillEnd) | ||
|
||
// Draw bezier curve | ||
ctx.strokeStyle = gradient | ||
ctx.lineWidth = lineWidth | ||
ctx.lineCap = 'round' | ||
ctx.beginPath() | ||
ctx.moveTo(p0.x, p0.y) | ||
ctx.bezierCurveTo(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y) | ||
ctx.stroke() | ||
}, [p0, p1, p2, p3]) | ||
|
||
return <canvas ref={canvasRef} width={500} height={500} /> | ||
} |
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,11 @@ | ||
.Card { | ||
border-radius: var(--borderRadius-default); | ||
border-color: var(--borderColor-default); | ||
border-width: 1px; | ||
border-style: solid; | ||
padding: 16px; | ||
|
||
* { | ||
max-width: 100%; | ||
} | ||
} |
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,15 @@ | ||
import React, {ReactNode} from 'react' | ||
import './Card.css' | ||
|
||
interface CardProps extends React.Component { | ||
children: ReactNode | ||
style: React.CSSProperties | ||
} | ||
|
||
export const Card = ({children, style}: CardProps) => { | ||
return ( | ||
<div className="Card" style={style}> | ||
{children} | ||
</div> | ||
) | ||
} |
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