From cb39e71b3b53c4fbaa13227ae484f0790318d095 Mon Sep 17 00:00:00 2001 From: MTG2000 Date: Tue, 17 May 2022 12:23:17 +0300 Subject: [PATCH] style: vote button shake effect, radial fill --- src/Components/VoteButton/VoteButton.tsx | 50 ++++++++++----- src/Components/VoteButton/styles.module.css | 68 +++++++++++++++++++-- 2 files changed, 98 insertions(+), 20 deletions(-) diff --git a/src/Components/VoteButton/VoteButton.tsx b/src/Components/VoteButton/VoteButton.tsx index 8880e0f..1cb1c20 100644 --- a/src/Components/VoteButton/VoteButton.tsx +++ b/src/Components/VoteButton/VoteButton.tsx @@ -1,7 +1,6 @@ import { MdLocalFireDepartment } from 'react-icons/md' import Button from 'src/Components/Button/Button' import { useAppSelector, usePressHolder } from 'src/utils/hooks' -import _throttle from 'lodash.throttle' import { ComponentProps, useRef, useState } from 'react' import styles from './styles.module.css' import { random, randomItem } from 'src/utils/helperFunctions' @@ -21,8 +20,9 @@ interface Particle { type Props = { initVotes: number, onVote: (Vote: number) => void, - fillType: 'leftRight' | 'upDown' | "background" + fillType: 'leftRight' | 'upDown' | "background" | 'radial' disableCounter?: boolean + disableShake?: boolean } & Omit, 'children'> export default function VoteButton({ @@ -123,29 +123,47 @@ export default function VoteButton({ onTouchStart={handlePressDown} onTouchEnd={handlePressUp} - color='none' - className={`p-10 rounded-lg text-gray-600 !border-0 bg-white hover:bg-gray-50 relative noselect active:scale-95`} + className={`${styles.vote_button} relative noselect border-0`} + style={{ + "--increments": incrementsCount, + "--offset": `${(incrementsCount ? (incrementsCount % 5 === 0 ? 5 : incrementsCount % 5) : 0) * 20}%`, + "--bg-color": fillType !== 'background' ? + 'hsl(0deg 86% max(calc((93 - var(--increments) / 3) * 1%), 68%))' + : + "hsl(0deg 86% max(calc((100 - var(--increments) / 2) * 1%), 68%))", + } as any} {...props} > +
{ + const btn = e.currentTarget + if (btn.classList.contains(styles.clicked_2)) { + btn.classList.remove(styles.clicked_2) + btn.classList.add(styles.clicked_1) + } else { + btn.classList.remove(styles.clicked_1) + btn.classList.add(styles.clicked_2) + } + }} + > +
-
-
- {initVotes + voteCnt} + > +
+
+ {initVotes + voteCnt} +
{increments.map(increment => "; /* <- defined as type number for the transition to work */ + initial-value: 0%; + inherits: false; +} + +.color_overlay__radial::before { + top: 0; + right: 0; + background: radial-gradient( + circle at center, + var(--bg-color) var(--offset), + transparent calc(var(--offset) * 1.1) + ); +} + @keyframes fly_value { 0% { transform: translate(-50%, 0) scale(0.5);