diff --git a/README.md b/README.md index bddfe01..19b53e3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # react-swim-button +![version](https://img.shields.io/github/package-json/v/happy-func/react-swim-button/main) ![typescript](https://img.shields.io/npm/types/react-swim-button) ![esm](https://img.shields.io/static/v1?label=build&message=esm&color=blue) ![npm bundle size (version)](https://img.shields.io/bundlephobia/min/react-swim-button/latest) ![GitHub Repo stars](https://img.shields.io/github/stars/happy-func/sudoku.js?style=social) + +Zero dependencies + ## Getting Started Install dependencies, @@ -18,6 +22,7 @@ $ yarn add react-swim-button ```tsx import React, { useState } from 'react'; import ReactSwimButton from 'react-swim-button'; +import 'react-swim-button/es/style'; const texts = ['React', 'Swim', 'Button']; @@ -46,6 +51,7 @@ export default () => { ```tsx import React, { useState } from 'react'; import ReactSwimButton from 'react-swim-button'; +import 'react-swim-button/es/style'; export default () => { const [activeAt, setActiveAt] = useState(0); @@ -71,6 +77,7 @@ export default () => { ```tsx import React, { useState } from 'react'; import ReactSwimButton from 'react-swim-button'; +import 'react-swim-button/es/style'; const texts = [ { diff --git a/docs/demo/plainbutton.less b/docs/demo/plainbutton.less index 300420f..3a8d4ff 100644 --- a/docs/demo/plainbutton.less +++ b/docs/demo/plainbutton.less @@ -15,29 +15,20 @@ box-shadow: none; &:before { + background-color: var(--primary-color); + } + + &:after { border-color: rgba(188, 193, 205, 0.5); + opacity: 1; } &:hover { color: #fff; - .swim-button-wave { - opacity: 1; - } - &:before { + &:after { border-color: #2b65f4; } } - - &-active { - .swim-button-wave { - background-color: #2b65f4; - opacity: 0; - transition-delay: 50ms; - transition-timing-function: ease-in-out; - transition-duration: 150ms; - transition-property: opacity; - } - } } } } diff --git a/package.json b/package.json index fbddc92..e1a2b3d 100644 --- a/package.json +++ b/package.json @@ -30,9 +30,6 @@ "react": ">=16.8.0", "react-dom": ">=16.8.0" }, - "dependencies": { - "@tweenjs/tween.js": "^18.6.4" - }, "devDependencies": { "@testing-library/jest-dom": "^5.15.1", "@testing-library/react": "^12.1.2", diff --git a/src/index.tsx b/src/index.tsx index 2deb300..408c376 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,5 +1,4 @@ -import TWEEN from '@tweenjs/tween.js'; -import React, { CSSProperties, ReactElement, useEffect, useRef } from 'react'; +import React, { CSSProperties, ReactElement } from 'react'; function clsx(...classnames: (string | undefined | boolean)[]) { return classnames.filter((item) => !!item).join(' '); @@ -17,58 +16,17 @@ function ReactSwimButton(props: ReactSwimButtonProps) { loading, duration = 250, } = props; - const waveRef = useRef(null); - function animate(time: number | undefined) { - requestAnimationFrame(animate); - TWEEN.update(time); - } - function updateProperty(coords: { width: number }) { - if (waveRef.current) { - // @ts-ignore - waveRef.current.style.setProperty('width', `${coords.width}%`); - } - } - function _onMouseEnter() { - const coords = { width: 0 }; - const tween = new TWEEN.Tween(coords) - .to({ width: 100 }, duration) - .easing(TWEEN.Easing.Cubic.InOut) // Use an easing function to make the animation smooth. - .onUpdate(updateProperty); - // @ts-ignore - waveRef.current.style.removeProperty('right'); - // @ts-ignore - waveRef.current.style.setProperty('left', `0px`); - tween.start(); - } - function _onMouseLeave() { - const coords = { width: 100 }; - const tween = new TWEEN.Tween(coords) - .to({ width: 0 }, duration) - .easing(TWEEN.Easing.Cubic.InOut) // Use an easing function to make the animation smooth. - .onUpdate(updateProperty); - // @ts-ignore - waveRef.current.style.removeProperty('left'); - // @ts-ignore - waveRef.current.style.setProperty('right', `0px`); - tween.start(); - } function _onClick() { if (loading) return; onClick && onClick(); } - useEffect(() => { - requestAnimationFrame(animate); - }, []); return (