-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ESM): Update the published library to include file extensions for…
- Loading branch information
1 parent
9d63582
commit a5d6a8f
Showing
8 changed files
with
422 additions
and
421 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,73 +1,73 @@ | ||
import React, { useEffect, useRef } from 'react' | ||
import { SnowfallCanvas, SnowfallCanvasConfig } from './SnowfallCanvas' | ||
import { defaultConfig } from './Snowflake' | ||
import { useComponentSize, useDeepMemo, useSnowfallStyle } from './hooks' | ||
|
||
export interface SnowfallProps extends Partial<SnowfallCanvasConfig> { | ||
/** | ||
* Any style properties that will be passed to the canvas element. | ||
*/ | ||
style?: React.CSSProperties | ||
} | ||
|
||
export const Snowfall = ({ | ||
color = defaultConfig.color, | ||
changeFrequency = defaultConfig.changeFrequency, | ||
radius = defaultConfig.radius, | ||
speed = defaultConfig.speed, | ||
wind = defaultConfig.wind, | ||
rotationSpeed = defaultConfig.rotationSpeed, | ||
snowflakeCount = 150, | ||
images, | ||
style, | ||
}: SnowfallProps = {}): JSX.Element => { | ||
const mergedStyle = useSnowfallStyle(style) | ||
|
||
const canvasRef = useRef<HTMLCanvasElement>(null) | ||
const canvasSize = useComponentSize(canvasRef) | ||
|
||
const config = useDeepMemo<SnowfallCanvasConfig>({ | ||
color, | ||
changeFrequency, | ||
radius, | ||
speed, | ||
wind, | ||
rotationSpeed, | ||
images, | ||
snowflakeCount, | ||
}) | ||
|
||
// A reference to the config used for creating the initial instance | ||
const configRef = useRef(config) | ||
|
||
const snowfallCanvasRef = useRef<SnowfallCanvas>() | ||
|
||
useEffect(() => { | ||
if (!snowfallCanvasRef.current && canvasRef.current) { | ||
snowfallCanvasRef.current = new SnowfallCanvas(canvasRef.current, configRef.current) | ||
} | ||
|
||
return () => { | ||
snowfallCanvasRef.current?.pause() | ||
snowfallCanvasRef.current = undefined | ||
} | ||
}, []) | ||
|
||
useEffect(() => { | ||
if (snowfallCanvasRef.current) { | ||
snowfallCanvasRef.current.updateConfig(config) | ||
} | ||
}, [config]) | ||
|
||
return ( | ||
<canvas | ||
ref={canvasRef} | ||
height={canvasSize.height} | ||
width={canvasSize.width} | ||
style={mergedStyle} | ||
data-testid="SnowfallCanvas" | ||
/> | ||
) | ||
} | ||
|
||
export default Snowfall | ||
import React, { useEffect, useRef } from 'react' | ||
import { SnowfallCanvas, SnowfallCanvasConfig } from './SnowfallCanvas.js' | ||
import { defaultConfig } from './Snowflake.js' | ||
import { useComponentSize, useDeepMemo, useSnowfallStyle } from './hooks.js' | ||
|
||
export interface SnowfallProps extends Partial<SnowfallCanvasConfig> { | ||
/** | ||
* Any style properties that will be passed to the canvas element. | ||
*/ | ||
style?: React.CSSProperties | ||
} | ||
|
||
export const Snowfall = ({ | ||
color = defaultConfig.color, | ||
changeFrequency = defaultConfig.changeFrequency, | ||
radius = defaultConfig.radius, | ||
speed = defaultConfig.speed, | ||
wind = defaultConfig.wind, | ||
rotationSpeed = defaultConfig.rotationSpeed, | ||
snowflakeCount = 150, | ||
images, | ||
style, | ||
}: SnowfallProps = {}): JSX.Element => { | ||
const mergedStyle = useSnowfallStyle(style) | ||
|
||
const canvasRef = useRef<HTMLCanvasElement>(null) | ||
const canvasSize = useComponentSize(canvasRef) | ||
|
||
const config = useDeepMemo<SnowfallCanvasConfig>({ | ||
color, | ||
changeFrequency, | ||
radius, | ||
speed, | ||
wind, | ||
rotationSpeed, | ||
images, | ||
snowflakeCount, | ||
}) | ||
|
||
// A reference to the config used for creating the initial instance | ||
const configRef = useRef(config) | ||
|
||
const snowfallCanvasRef = useRef<SnowfallCanvas>() | ||
|
||
useEffect(() => { | ||
if (!snowfallCanvasRef.current && canvasRef.current) { | ||
snowfallCanvasRef.current = new SnowfallCanvas(canvasRef.current, configRef.current) | ||
} | ||
|
||
return () => { | ||
snowfallCanvasRef.current?.pause() | ||
snowfallCanvasRef.current = undefined | ||
} | ||
}, []) | ||
|
||
useEffect(() => { | ||
if (snowfallCanvasRef.current) { | ||
snowfallCanvasRef.current.updateConfig(config) | ||
} | ||
}, [config]) | ||
|
||
return ( | ||
<canvas | ||
ref={canvasRef} | ||
height={canvasSize.height} | ||
width={canvasSize.width} | ||
style={mergedStyle} | ||
data-testid="SnowfallCanvas" | ||
/> | ||
) | ||
} | ||
|
||
export default Snowfall |
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
Oops, something went wrong.