From 86823dcb15b6bdf02fbad43dcc705ce36fd563f3 Mon Sep 17 00:00:00 2001 From: mackt <1033530438@qq.com> Date: Sat, 27 Apr 2024 11:31:54 +0800 Subject: [PATCH] update(CollectButton): Add color prop --- src/components/AudioPlayer/PlayerControl.tsx | 4 ++- src/components/Button/CollectButton.tsx | 32 ++++--------------- src/components/Icon/Heart.tsx | 30 +++++++++++++++++ .../heart.module.css} | 28 ++++++++++------ src/components/index.ts | 1 + 5 files changed, 58 insertions(+), 37 deletions(-) create mode 100644 src/components/Icon/Heart.tsx rename src/components/{Button/collect.module.css => Icon/heart.module.css} (73%) diff --git a/src/components/AudioPlayer/PlayerControl.tsx b/src/components/AudioPlayer/PlayerControl.tsx index ba27b6c..67e6f05 100644 --- a/src/components/AudioPlayer/PlayerControl.tsx +++ b/src/components/AudioPlayer/PlayerControl.tsx @@ -105,7 +105,9 @@ export default function AudioPlayer({ {/* control */}
{/* 收藏歌曲 */} - {!!audio?.id && } + {!!audio?.id && ( + + )} {/* 播放顺序 */} {showOrder && orderList.map((item) => ( diff --git a/src/components/Button/CollectButton.tsx b/src/components/Button/CollectButton.tsx index 79f4fb8..3073c46 100644 --- a/src/components/Button/CollectButton.tsx +++ b/src/components/Button/CollectButton.tsx @@ -6,8 +6,7 @@ import { useEffect, useState } from 'react'; import { useShallow } from 'zustand/react/shallow'; -import styles from './collect.module.css'; - +import { IconHeart } from '@/components'; import { apiCollect } from '@/services'; import { useAudioStore } from '@/store'; @@ -26,6 +25,7 @@ interface Props { textClassName?: string; /** 文字跟图标之间的间隔 单位px */ gap?: number; + color?: string; } export default function CollectButton({ @@ -39,6 +39,7 @@ export default function CollectButton({ className = '', textClassName = '', showText = false, + color, }: Props) { const { playList, playQueue, updatePlayList, setPlayQueue } = useAudioStore( useShallow((state) => { @@ -122,38 +123,17 @@ export default function CollectButton({ className={`flex flex-row items-center gap-[${gap}px] w-fit h-fit cursor-pointer group ${className}`} onClick={handleCollect} > - {iconPosition === 'left' && } + {iconPosition === 'left' && } {/* 文案 */} {!!(showText && currentCount > 0) && (

{`${currentCount || ''}${text || ''}`}

)} {/* 图标 */} - {iconPosition === 'right' && } -
- ); -} - -function Icon({ haveCollect, animate }: { haveCollect: boolean; animate: boolean }) { - return ( -
- - - - - + {iconPosition === 'right' && }
); } diff --git a/src/components/Icon/Heart.tsx b/src/components/Icon/Heart.tsx new file mode 100644 index 0000000..24a9a35 --- /dev/null +++ b/src/components/Icon/Heart.tsx @@ -0,0 +1,30 @@ +import styles from './heart.module.css'; + +export default function Heart({ + active, + animateState, + color = 'default', +}: { + active: boolean; + animateState: boolean; + color?: string; +}) { + return ( +
+ + + + + +
+ ); +} diff --git a/src/components/Button/collect.module.css b/src/components/Icon/heart.module.css similarity index 73% rename from src/components/Button/collect.module.css rename to src/components/Icon/heart.module.css index 5e7d2e2..a4556e7 100644 --- a/src/components/Button/collect.module.css +++ b/src/components/Icon/heart.module.css @@ -2,13 +2,21 @@ width: var(--size); position: relative; - --gray-color: rgb(197, 197, 197); --no-color: rgba(244, 244, 244, 0); - --skin-color: #c43737; --size: 24px; --path-dasharray: 120; } +.color-default { + --default-color: rgb(197, 197, 197); + --active-color: #c43737; +} + +.color-dark { + --default-color: rgba(0, 0, 0, 0.95); + --active-color: #c43737; +} + .heart-svg { width: 100%; position: relative; @@ -17,7 +25,7 @@ .heart-path { fill: var(--no-color); - stroke: var(--gray-color); + stroke: var(--default-color); stroke-dasharray: var(--path-dasharray); stroke-width: 1.5px; stroke-linecap: round; @@ -35,12 +43,12 @@ } .checkbox[type='checkbox']:checked + svg .heart-path { - stroke: var(--skin-color); - fill: var(--skin-color); + stroke: var(--active-color); + fill: var(--active-color); } .checkbox[type='checkbox']:hover + svg .heart-path { - stroke: var(--skin-color); + stroke: var(--active-color); transition: stroke 0.2s ease-in-out; } @@ -57,19 +65,19 @@ /* 填充 */ @keyframes run { 0% { - stroke: var(--skin-color); + stroke: var(--active-color); stroke-dashoffset: var(--path-dasharray); fill: var(--no-color); } 80% { stroke-dashoffset: 0; - fill: var(--skin-color); + fill: var(--active-color); } 100% { stroke-dashoffset: 0; - stroke: var(--skin-color); - fill: var(--skin-color); + stroke: var(--active-color); + fill: var(--active-color); } } diff --git a/src/components/index.ts b/src/components/index.ts index 0db9676..f217bd5 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -7,6 +7,7 @@ export { default as MiniFooter } from './Footer/MiniFooter'; export { default as IconEqualizer } from './Icon/Equalizer'; export { default as IconComment } from './Icon/Comment'; export { default as IconClose } from './Icon/Close'; +export { default as IconHeart } from './Icon/Heart'; export { default as IconPlayAll } from './Icon/PlayAll'; // Home