Skip to content

Commit

Permalink
Move to Tailwind
Browse files Browse the repository at this point in the history
  • Loading branch information
woofers committed Jul 16, 2024
1 parent f6e42a0 commit 8138ec3
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ lib/react-wavify.module.dev.js
lib/react-wavify.module.js
/lib/index.d.ts
/demo/yarn.lock
test.css
138 changes: 138 additions & 0 deletions packages/react-wavify/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@


# React Wavify

[![img](https://github.com/woofers/react-wavify/workflows/build/badge.svg)](https://github.com/woofers/react-wavify/actions) [![img](https://badge.fury.io/js/react-wavify.svg)](https://www.npmjs.com/package/react-wavify) [![img](https://img.shields.io/npm/dt/react-wavify.svg)](https://www.npmjs.com/package/react-wavify) [![img](https://badgen.net/bundlephobia/minzip/react-wavify)](https://bundlephobia.com/result?p=react-wavify) [![img](https://img.shields.io/npm/l/react-wavify.svg)](https://github.com/woofers/react-wavify/blob/main/LICENSE)

A simple React component which creates an animated wave.

**[Live Demo](https://jaxs.onl/react-wavify/)**

This component is heavily adapted from [Mikołaj Stolarski](https://github.com/grimor)'s awesome [Codepen](https://codepen.io/grimor/pen/qbXLdN)
and is functionally similar to [Benjamin Grauwin](http://benjamin.grauwin.me/)'s [Wavify](https://github.com/peacepostman/wavify) plug-in.

![img](./screenshots/wave.gif "Wave")


# Installation

**Yarn**

```yarn
yarn add react-wavify
```

**npm**

```npm
npm install react-wavify
```

# Usage

```jsx
import React from 'react'
import Wave from 'react-wavify'

const App = () => (
<Wave fill='#f79902'
paused={false}
style={{ display: 'flex' }}
options={{
height: 20,
amplitude: 20,
speed: 0.15,
points: 3
}}
/>
)
```

Simply add the Wave component to the React application using JSX.

The wave's width will scale to fit the parent container.


## Props


### Fill

The `fill` property can be set to anything that a SVG path can accept (usually gradients or colors). **Default:** `#FFF`


### Paused

The `paused` property controls the play state of the animation. **Default:** `false`

If set to `true` the wave animation will pause.


### Options

The component supports a variety of options to affect how the wave is rendered.

Any omitted options will be set to the default value.

- `height` - Height of the wave relative to the SVG element. **Default:** `20`
- `amplitude` - Amplitude of the rendered wave. **Default:** `20`
- `speed` - Speed that the wave animation plays at. **Default:** `0.15`
- `points` - Amount of points used to form the wave.
Can not be less than `1`. **Default:** `3`


### Pass Through Props

Any other props such as `id`, `className` or `style` will be passed through to the root of the component.

Other props such as `opacity` or `stroke` will be passed to the SVG path element.

Any other elements can be passed inside the SVG component itself.

Inner `<defs>` elements can be used to add gradients, clipping paths, or masks.

##### Using a Gradient

```jsx
<Wave fill="url(#gradient)">
<defs>
<linearGradient id="gradient" gradientTransform="rotate(90)">
<stop offset="10%" stopColor="#d4af37" />
<stop offset="90%" stopColor="#f00" />
</linearGradient>
</defs>
</Wave>
```

![img](./screenshots/wave-grad.gif "Gradient Wave")

##### Using a Clipping Path

```jsx
<Wave fill="#e62315" mask="url(#mask)" options={{ points: 20, speed: 0.2, amplitude: 40 }}>
{/* Example adapted from https://developer.mozilla.org/en-US/docs/Web/SVG/Element/mask */}
<mask id="mask">
<path d="M10,35 A20,20,0,0,1,50,35 A20,20,0,0,1,90,35 Q90,65,50,95 Q10,65,10,35 Z" fill="white" />
</mask>
</Wave>
```

![img](./screenshots/wave-heart.gif "Clipping Path Wave")

##### Using a Mask

```jsx
<Wave mask="url(#mask)" fill="#1277b0" >
<defs>
<linearGradient id="gradient" gradientTransform="rotate(90)">
<stop offset="0" stopColor="white" />
<stop offset="0.5" stopColor="black" />
</linearGradient>
<mask id="mask">
<rect x="0" y="0" width="2000" height="200" fill="url(#gradient)" />
</mask>
</defs>
</Wave>
```

![img](./screenshots/wave-mask.gif "Mask Wave")
8 changes: 5 additions & 3 deletions packages/react-wavify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
"README.md"
],
"scripts": {
"start": "yarn watch",
"build:module": "microbundle --no-pkg-main --no-sourcemap --no-generateTypes --jsx React.createElement --define __isDev__=false -i src/index.js -o lib/react-wavify.module.js -f es",
"build:umd": "microbundle --no-pkg-main --no-sourcemap --no-generateTypes --jsx React.createElement --define __isDev__=false -i src/index.js -o lib/react-wavify.js -f umd",
"build:dev:module": "microbundle --no-pkg-main --no-sourcemap --no-generateTypes --jsx React.createElement --define __isDev__=true -i src/index.js -o lib/react-wavify.module.dev.js -f es",
"build:dev:umd": "microbundle --no-pkg-main --no-sourcemap --no-generateTypes --jsx React.createElement --define __isDev__=true -i src/index.js -o lib/react-wavify.dev.js -f umd",
"build:types": "cp src/index.d.ts lib/index.d.ts",
"clean": "rimraf lib/react-wavify.dev.js lib/react-wavify.js lib/react-wavify.module.dev.js lib/react-wavify.module.js lib/index.d.ts README.md",
"build": "yarn build:dev:module && yarn build:dev:umd && yarn build:module && yarn build:umd && yarn build:types && cp ../../README.md README.md",
"build": "pnpm build:dev:module && pnpm build:dev:umd && pnpm build:module && pnpm build:umd && pnpm build:types && cp ../../README.md README.md",
"watch": "rollup -c --watch",
"test": "echo \"No tests \" && exit 0",
"package": "pnpm publish --no-git-checks --access public"
Expand Down Expand Up @@ -55,5 +54,8 @@
"microbundle": "^0.15.1",
"rimraf": "^5.0.7"
},
"dependencies": {}
"dependencies": {
"clsx": "^2.1.1",
"tailwindcss": "4.0.0-alpha.17"
}
}
33 changes: 33 additions & 0 deletions packages/website/src/app/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@import "tailwindcss";

@theme {
--color-*: initial;

--color-accent: #ffd4bd;
--color-background: #111110;
--color-secondary: #dbdbdb;
--color-black: #000000;
--color-white: #ffffff;
--color-code: #030202;
--color-textcode: #aaaaca;

--color-inherit: inherit;
--color-current: currentColor;
--color-transparent: transparent;
--color-primary: #bf8855;
--color-primaryHover: #bf8855e6;
--color-secondary: #fadc96;
--color-blue: #5e9ef1;
--color-darkBlue: #3268ce;
--color-selection: #fff9cc;
--fonts-title: 'Quicksand', sans-serif;
}

@layer utilities {
.feature-list {
list-style-type: none;
}
.feature-list > li:before {
content: "- ";
}
}
1 change: 1 addition & 0 deletions packages/website/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Providers from './providers'
import StitchesRegistry from './registry'
import './globals.css'

const RootLayout: React.FC<{ children: React.ReactNode }> = ({ children }) => (
<html lang="en">
Expand Down
7 changes: 5 additions & 2 deletions packages/website/src/components/pause.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { styled } from 'stitches'
import { PlayIcon, PauseIcon } from 'icons'
import clsx from 'clsx'

const Button = styled('button', {
WebkitTapHighlightColor: 'rgba(0, 0, 0, 0)',
Expand All @@ -21,9 +22,10 @@ type PauseProps = {
color?: string
paused?: boolean
onClick: () => void
className?: string
}

const Pause: React.FC<PauseProps> = ({ color, paused, onClick, ...rest }) => {
const Pause: React.FC<PauseProps> = ({ color, paused, onClick, className, ...rest }) => {
const handleClick = () => {
onClick()
}
Expand All @@ -41,9 +43,10 @@ const Pause: React.FC<PauseProps> = ({ color, paused, onClick, ...rest }) => {
onMouseUp={handleClick}
title={label}
aria-label={label}
className={clsx("text-[75px] border-0 text-[var(--color-primary)] bg-transparent [-webkit-tap-highlight-color:rgba(0,0,0,0)] hover:bg-[var(--color-primaryHover)]", className)}
{...rest}
>
{paused ? <PlayIcon /> : <PauseIcon />}
{paused ? <PlayIcon className="w-[14px]" /> : <PauseIcon className="w-[14px]" />}
</Button>
)
}
Expand Down
14 changes: 7 additions & 7 deletions packages/website/src/components/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ const Link = styled('a', {
})

const App: React.FC<Nothing> = () => (
<Fullscreen>
<WaveWrapper>
<Center>
<Link href="https://github.com/woofers/react-wavify">
<Text>react-wavify</Text>
<Fullscreen className="fixed top-0 bottom-0 left-0 right-0 opacity-100 bg-[var(--color-blue)]">
<WaveWrapper className="w-full absolute bg-[var(--color-secondary)] [z-index:-1] h-[300px] xs:h-[400px]">
<Center className="flex justify-center mt-[56px] mb-[25.6px] xs:mt-[88px] xs:mb-[40px]">
<Link href="https://github.com/woofers/react-wavify" className="no-underline text-[8px] text-[var(--color-primary)] hover:text-[var(--color-primaryHover)] xs:text-base xxs:text-xs">
<Text className="font-bold mt-0 mb-0 text-[88px] [font-family:var(--fonts-title)] [letter-spacing:-0.3px]">react-wavify</Text>
</Link>
</Center>
<Wave />
<BodyWrapper>
<BodyContainer></BodyContainer>
<BodyWrapper className="relative">
<BodyContainer className="absolute w-full flex justify-center items-center text-xl top-[-80px]" />
</BodyWrapper>
</WaveWrapper>
</Fullscreen>
Expand Down
2 changes: 1 addition & 1 deletion packages/website/src/components/wave.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const WaveSection: React.FC<Nothing> = () => {
const togglePaused = () => setPause(!isPaused)
return (
<>
<PauseWrapper>
<PauseWrapper className="flex justify-center">
<Pause onClick={togglePaused} paused={isPaused} />
</PauseWrapper>
<Wave
Expand Down
35 changes: 26 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8138ec3

Please sign in to comment.