# solid-snowfall

> A solidjs component that creates a snowfall effect

Latest version **0.3.2** (published 2024-12-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install solid-snowfall
pnpm add solid-snowfall
yarn add solid-snowfall
bun add solid-snowfall
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2024-12-27 |
| First published | 2022-12-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 102.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | https://github.com/apollo79 |
| Maintainers | apollo79 |
| Keywords | solid, solidjs, component, snowfall, winter, christmas |

## Links

- npm: https://www.npmjs.com/package/solid-snowfall
- Repository: https://github.com/apollo79/solid-snowfall
- Homepage: https://apollo79.github.io/solid-snowfall
- Issues: https://github.com/apollo79/solid-snowfall/issues
- npm.io page: https://npm.io/package/solid-snowfall

## Dependencies (3)

- [fast-deep-equal](https://npm.io/package/fast-deep-equal.md) ^3.1.3
- [@solid-primitives/deep](https://npm.io/package/@solid-primitives/deep.md) ^0.2.10
- [@solid-primitives/resize-observer](https://npm.io/package/@solid-primitives/resize-observer.md) ^2.0.26

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.3.2 (latest) — 2024-12-27
- 0.3.1 — 2023-12-10
- 0.3.0 — 2023-01-01
- 0.2.0 — 2022-12-29
- 0.1.0 — 2022-12-28

## README

![Snowfall Demo](../assets/snowfall-demo.gif)

# Solid Snowfall

[![npm](https://img.shields.io/npm/v/solid-snowfall.svg)](https://www.npmjs.com/package/solid-snowfall)
[![GitHub stars](https://img.shields.io/github/stars/apollo79/solid-snowfall.svg)](https://github.com/apollo79/solid-snowfall/stargazers)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)

A solid component that creates a snowfall effect

- [Live Example](https://apollo79.github.io/solid-snowfall)
- [Demo Playground](https://codesandbox.io/s/github/apollo79/solid-snowfall/tree/main/apps/demo)

## Installation

With npm

```
npm i solid-snowfall
```

With yarn

```
yarn add solid-snowfall
```

Or wit pnpm

```
pnpm add solid-snowfall
```

## Usage

Basic usage requires no properties - it will grow to fill the nearest relative positioned parent element.

```tsx
import { render } from "solidjs/web";
import SnowFall from "solid-snowfall";

render(
  () => (
    <>
      <SnowFall />
  ),
  document.getElementById("root") as HTMLDivElement,
);
```

## Configuration

Optional properties can be provided to customise the animation.

```tsx
<Snowfall
  // The color of the snowflake, can be any valid CSS color.
  color="#fff"
  // Applied to the canvas element.
  style={{ background: "#fff" }}
  // Controls the number of snowflakes that are created (defaults to 150).
  snowflakeCount={200}
/>
```

All available properties are detailed below.

| Property          | Description                                                                                                                                                                                                                                                                              | Default       |
| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
| `changeFrequency` | The frequency in frames that the wind and speed values will update.                                                                                                                                                                                                                      | `200`         |
| `color`           | The color of the snowflake, can be any valid CSS color.                                                                                                                                                                                                                                  | `'#dee4fd'`   |
| `images`          | An array of images that will be rendered as the snowflakes instead of the default circle shapes.                                                                                                                                                                                         | `undefined`   |
| `radius`          | The minimum and maximum radius of the snowflake in pixels.<br/><br/>The value for each snowflake will be randomly selected within this range.                                                                                                                                            | `[0.5, 3.0]`  |
| `rotationSpeed`   | The minimum and maximum rotation speed of the snowflake (in degrees of rotation per frame).<br/><br/>The rotation speed determines how quickly the snowflake rotates when an image is being rendered.<br/><br/>The value for each snowflake will be randomly selected within this range. | `[-1.0, 1.0]` |
| `snowflakeCount`  | The number of snowflakes to be rendered.                                                                                                                                                                                                                                                 | `150`         |
| `speed`           | The minimum and maximum speed of the snowflake (in pixels per frame).<br/><br/>The speed determines how quickly the snowflake moves along the y axis (vertical speed).<br/><br/>The value for each snowflake will be randomly selected within this range.                                | `[1.0, 3.0]`  |
| `style`           | Any style properties that will be passed to the canvas element.                                                                                                                                                                                                                          | `undefined`   |
| `wind`            | The minimum and maximum wind of the snowflake (in pixels per frame).<br/><br/>The wind determines how quickly the snowflake moves along the x axis (horizontal speed).<br/><br/>The value for each snowflake will be randomly selected within this range.                                | `[-0.5, 2.0]` |

## Using Images

Instead of rendering colored circles you can instead pass in an array of image elements
that will be randomly selected and used as the snowflake instead.

> _NOTE_: If the images provided are not square they will be stretched into a 1:1 aspect ratio.

```tsx
const snowflake1 = document.createElement('img')
snowflake1.src = '/assets/snowflake-1.png'
const snowflake2 = document.createElement('img')
snowflake2.src = '/assets/snowflake-2.jpg'
const images = [snowflake1, snowflake2]
const Demo = () => {
  return (
    <Snowfall
      // Applied to the canvas element
      style={{ background: '#fff' }}
      // Controls the number of snowflakes that are created (default 150)
      snowflakeCount={200}
      // Pass in the images to be used
      images={images}
    >
  )
}
```

## Positioning

The snowfall container is absolute positioned and has the following default styles (see [the definition](https://github.com/apollo79/solid-snowfall/blob/main/packages/solid-snowfall/src/config.ts#L4-L10)):

```css
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
```

If you want the component to cover the entire screen then you can change the position to `fixed` by passing in an overriding styles object:

```tsx
<Snowfall
  style={{
    position: "fixed",
    top: 0,
    bottom: 0,
    right: 0,
    left: 0,
  }}
/>
```

---
_Source: https://npm.io/package/solid-snowfall · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
