-
Notifications
You must be signed in to change notification settings - Fork 23
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
Showing
11 changed files
with
243 additions
and
38 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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import ReactDOM from "react-dom"; | ||
import { ReactSpringMostBasic } from "./ReactSpringMostBasic"; | ||
import ReactDOM from 'react-dom'; | ||
import { ReactSpringTextDemo } from './ReactSpringTextDemo'; | ||
|
||
const rootElement = document.getElementById("root"); | ||
ReactDOM.render(<ReactSpringMostBasic width={800} height={300} />, rootElement); | ||
const rootElement = document.getElementById('root'); | ||
ReactDOM.render(<ReactSpringTextDemo width={800} height={300} />, rootElement); |
25 changes: 25 additions & 0 deletions
25
viz/exercise/AnimationSimpleCircleOpacitySolution/Circle.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,25 @@ | ||
import { animated, useSpring } from 'react-spring'; | ||
|
||
type CircleVizProps = { | ||
position: number; | ||
color: string; | ||
opacity: number; | ||
}; | ||
|
||
export const Circle = ({ position, color, opacity }: CircleVizProps) => { | ||
const springProps = useSpring({ | ||
to: { position, color, opacity }, | ||
}); | ||
|
||
return ( | ||
<animated.circle | ||
strokeWidth={2} | ||
fillOpacity={springProps.opacity} | ||
r={38} | ||
cy={50} | ||
cx={springProps.position} | ||
stroke={springProps.color} | ||
fill={springProps.color} | ||
/> | ||
); | ||
}; |
25 changes: 25 additions & 0 deletions
25
viz/exercise/AnimationSimpleCircleOpacitySolution/Graph.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,25 @@ | ||
import { useState } from 'react'; | ||
import { Circle } from './Circle'; | ||
|
||
const width = 500; | ||
const height = 300; | ||
|
||
export const Graph = () => { | ||
const [position, setPosition] = useState(40); | ||
|
||
return ( | ||
<svg | ||
width={width} | ||
height={height} | ||
onClick={() => { | ||
position > 100 ? setPosition(40) : setPosition(width - 50); | ||
}} | ||
> | ||
<Circle | ||
position={position} | ||
color={position > 200 ? 'red' : 'blue'} | ||
opacity={position > 200 ? 0.2 : 1} | ||
/> | ||
</svg> | ||
); | ||
}; |
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,6 @@ | ||
// File used to render something in codesandbox only | ||
import ReactDOM from 'react-dom'; | ||
import { Graph } from './Graph'; | ||
|
||
const rootElement = document.getElementById('root'); | ||
ReactDOM.render(<Graph />, rootElement); |
31 changes: 31 additions & 0 deletions
31
viz/exercise/AnimationSimpleCircleOpacitySolution/package.json
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,31 @@ | ||
{ | ||
"name": "pie-chart-basic", | ||
"version": "1.0.0", | ||
"description": "", | ||
"keywords": [], | ||
"main": "index.js", | ||
"dependencies": { | ||
"react": "17.0.2", | ||
"d3": "7.1.1", | ||
"react-dom": "17.0.2", | ||
"react-scripts": "4.0.0", | ||
"@react-spring/web": "^9.3.1", | ||
"react-spring": "9.3.2" | ||
}, | ||
"devDependencies": { | ||
"@babel/runtime": "7.13.8", | ||
"typescript": "4.1.3" | ||
}, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test --env=jsdom", | ||
"eject": "react-scripts eject" | ||
}, | ||
"browserslist": [ | ||
">0.2%", | ||
"not dead", | ||
"not ie <= 11", | ||
"not op_mini all" | ||
] | ||
} |
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,24 @@ | ||
import { animated, useSpring } from 'react-spring'; | ||
|
||
type CircleVizProps = { | ||
position: number; | ||
color: string; | ||
}; | ||
|
||
export const Circle = ({ position, color }: CircleVizProps) => { | ||
const springProps = useSpring({ | ||
to: { position, color }, | ||
}); | ||
|
||
return ( | ||
<animated.circle | ||
strokeWidth={2} | ||
fillOpacity={0.4} | ||
r={38} | ||
cy={50} | ||
cx={springProps.position} | ||
stroke={springProps.color} | ||
fill={springProps.color} | ||
/> | ||
); | ||
}; |
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,33 @@ | ||
import { useState } from 'react'; | ||
import { animated, useSpring } from 'react-spring'; | ||
|
||
const width = 500; | ||
const height = 300; | ||
|
||
export const Graph = () => { | ||
const [position, setPosition] = useState(40); | ||
|
||
const springProps = useSpring({ | ||
to: { left: position }, | ||
}); | ||
|
||
return ( | ||
<div | ||
style={{ width, height, position: 'relative' }} | ||
onClick={() => { | ||
setPosition(position > 100 ? 40 : width - 50); | ||
}} | ||
> | ||
<animated.div | ||
style={{ | ||
left: springProps.left, | ||
top: 50, | ||
position: 'absolute', | ||
width: 50, | ||
height: 50, | ||
backgroundColor: 'red', | ||
}} | ||
></animated.div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// File used to render something in codesandbox only | ||
import ReactDOM from 'react-dom'; | ||
import { Graph } from './Graph'; | ||
|
||
const rootElement = document.getElementById('root'); | ||
ReactDOM.render(<Graph />, rootElement); |
Oops, something went wrong.