From b8a2247406e5be90057ffd0cc147c9722279002b Mon Sep 17 00:00:00 2001 From: Haoyu Xu Date: Mon, 23 Oct 2023 16:47:09 -0400 Subject: [PATCH] feat(directory): added animated cursor --- directory/src/App.scss | 2 ++ directory/src/component/dropdown.jsx | 14 +++++++- directory/src/component/popup.jsx | 2 +- directory/src/component/return_button.jsx | 1 + .../src/component/scss/dropdown.module.scss | 5 --- .../src/component/scss/popup.module.scss | 4 --- .../component/scss/return_button.module.scss | 1 - .../src/component/scss/search_box.module.scss | 1 - .../src/component/scss/switch.module.scss | 1 - .../component/scss/totop_button.module.scss | 1 - directory/src/component/switch.jsx | 1 + directory/src/component/totop_button.jsx | 1 + directory/src/routes/Error.jsx | 20 +++++++++++ directory/src/routes/Root.jsx | 33 +++++++++++++++---- directory/src/routes/path/Changelogs.jsx | 1 + directory/src/routes/path/Home.jsx | 15 +++++++-- directory/src/routes/path/Operator.jsx | 3 +- directory/src/scss/_page_base.scss | 3 +- directory/src/scss/root/Root.module.scss | 5 +-- directory/src/scss/root/header.module.scss | 1 - package.json | 1 + pnpm-lock.yaml | 13 ++++++++ 22 files changed, 100 insertions(+), 29 deletions(-) diff --git a/directory/src/App.scss b/directory/src/App.scss index a171714..8e73976 100644 --- a/directory/src/App.scss +++ b/directory/src/App.scss @@ -15,6 +15,7 @@ --home-item-background-linear-gradient-color: rgba(0, 0, 0, 10%); --home-item-outline-color: rgba(41, 41, 41, 30%); --button-color: #999; + --cursor-color: var(--text-color); } @mixin dark-theme() { @@ -30,6 +31,7 @@ --home-item-background-linear-gradient-color: rgba(255, 255, 255, 10%); --home-item-outline-color: rgba(214, 214, 214, 30%); --button-color: #666; + --cursor-color: var(--text-color); } @media (prefers-color-scheme: dark) { diff --git a/directory/src/component/dropdown.jsx b/directory/src/component/dropdown.jsx index 08ffdb0..b6ca5e7 100644 --- a/directory/src/component/dropdown.jsx +++ b/directory/src/component/dropdown.jsx @@ -1,5 +1,6 @@ import React, { useState, + useCallback } from 'react' import PropTypes from 'prop-types'; import classes from './scss/dropdown.module.scss' @@ -11,9 +12,17 @@ export default function Dropdown(props) { setHidden(!hidden) } + const onMouseEnter = useCallback((item) => { + document.documentElement.style.setProperty('--cursor-color', item.color); + }, []) + + const onMouseLeave = useCallback(() => { + document.documentElement.style.setProperty('--cursor-color', 'var(--text-color)'); + }, []) + return ( <> -
+
toggleDropdown()} @@ -56,6 +65,9 @@ export default function Dropdown(props) { toggleDropdown() }} style={item.color ? { color: item.color } : {}} + data-type="clickable" + onMouseEnter={() => onMouseEnter(item)} + onMouseLeave={() => onMouseLeave()} > { item.icon ? ( diff --git a/directory/src/component/popup.jsx b/directory/src/component/popup.jsx index d1e081c..a937682 100644 --- a/directory/src/component/popup.jsx +++ b/directory/src/component/popup.jsx @@ -26,7 +26,7 @@ export default function Popup(props) {
toggle()} /> + onClick={() => toggle()} data-type="clickable"/>
props.onClick()} + data-type="clickable" >
diff --git a/directory/src/component/scss/dropdown.module.scss b/directory/src/component/scss/dropdown.module.scss index 7661f91..38757ea 100644 --- a/directory/src/component/scss/dropdown.module.scss +++ b/directory/src/component/scss/dropdown.module.scss @@ -4,7 +4,6 @@ user-select: none; z-index: 2; padding: 0.5em; - cursor: pointer; &.left { .popup, .menu { @@ -37,7 +36,6 @@ z-index: -1; top: 2em; right: 0; - cursor: auto; transition: all cubic-bezier(0.65, 0.05, 0.36, 1) 0.3s; overflow: auto; padding: 0.5rem; @@ -92,7 +90,6 @@ border: 1px solid var(--border-color); visibility: hidden; color: var(--link-highlight-color); - cursor: auto; &.left { left: 0; @@ -120,7 +117,6 @@ } .item { - cursor: pointer; padding: 0.5rem; font-size: 1rem; display: flex; @@ -161,7 +157,6 @@ bottom: 0; width: 100vw; height: 100vh; - cursor: auto; } &.active, diff --git a/directory/src/component/scss/popup.module.scss b/directory/src/component/scss/popup.module.scss index 7aaf2a8..a4c0d91 100644 --- a/directory/src/component/scss/popup.module.scss +++ b/directory/src/component/scss/popup.module.scss @@ -1,7 +1,3 @@ -.entry-text { - cursor: pointer; -} - .popup { position: fixed; left: 0; diff --git a/directory/src/component/scss/return_button.module.scss b/directory/src/component/scss/return_button.module.scss index a4f3b3f..0422523 100644 --- a/directory/src/component/scss/return_button.module.scss +++ b/directory/src/component/scss/return_button.module.scss @@ -9,7 +9,6 @@ align-items: flex-start; padding: 0.6rem 0; width: 3rem; - cursor: pointer; .wrapper { display: flex; diff --git a/directory/src/component/scss/search_box.module.scss b/directory/src/component/scss/search_box.module.scss index 7e72f59..401daee 100644 --- a/directory/src/component/scss/search_box.module.scss +++ b/directory/src/component/scss/search_box.module.scss @@ -49,7 +49,6 @@ right: 1rem; width: 2rem; height: 2rem; - cursor: pointer; opacity: 0; transition: all cubic-bezier(0.65, 0.05, 0.36, 1) 0.3s; visibility: hidden; diff --git a/directory/src/component/scss/switch.module.scss b/directory/src/component/scss/switch.module.scss index 621bff1..5dcab84 100644 --- a/directory/src/component/scss/switch.module.scss +++ b/directory/src/component/scss/switch.module.scss @@ -3,7 +3,6 @@ user-select: none; z-index: 2; padding: 8px 36px 8px 8px; - cursor: pointer; display: flex; flex-direction: row; align-items: center; diff --git a/directory/src/component/scss/totop_button.module.scss b/directory/src/component/scss/totop_button.module.scss index eb0f760..2468f13 100644 --- a/directory/src/component/scss/totop_button.module.scss +++ b/directory/src/component/scss/totop_button.module.scss @@ -2,7 +2,6 @@ position: fixed; user-select: none; z-index: 2; - cursor: pointer; height: 2rem; right: 2rem; bottom: 1rem; diff --git a/directory/src/component/switch.jsx b/directory/src/component/switch.jsx index e3998e5..93f7645 100644 --- a/directory/src/component/switch.jsx +++ b/directory/src/component/switch.jsx @@ -21,6 +21,7 @@ export default function Switch(props) { props.handleOnClick(!on) } }} + data-type="clickable" > {i18n(props.text)}
diff --git a/directory/src/component/totop_button.jsx b/directory/src/component/totop_button.jsx index 8db38c7..30a796d 100644 --- a/directory/src/component/totop_button.jsx +++ b/directory/src/component/totop_button.jsx @@ -52,6 +52,7 @@ export default function ToTopButton(props) { <>
{ smoothScroll("#root") }} + data-type="clickable" >
diff --git a/directory/src/routes/Error.jsx b/directory/src/routes/Error.jsx index 7577447..0076eed 100644 --- a/directory/src/routes/Error.jsx +++ b/directory/src/routes/Error.jsx @@ -20,6 +20,7 @@ import { useHeader } from '@/state/header'; import VoiceElement from '@/component/voice'; import spine from '!/libs/spine-player' import '!/libs/spine-player.css' +import AnimatedCursor from "react-animated-cursor" import useUmami from '@/state/insights'; const voiceOnAtom = atomWithStorage('voiceOn', false) @@ -186,6 +187,25 @@ export default function Error() { handleAduioStateChange={handleAduioStateChange} /> +
); } \ No newline at end of file diff --git a/directory/src/routes/Root.jsx b/directory/src/routes/Root.jsx index 81987f8..519df95 100644 --- a/directory/src/routes/Root.jsx +++ b/directory/src/routes/Root.jsx @@ -2,7 +2,7 @@ import React, { useState, useEffect, useMemo, - useCallback + useCallback, } from 'react' import PropTypes from 'prop-types'; import { @@ -29,6 +29,7 @@ import Popup from '@/component/popup'; import Border from '@/component/border'; import CharIcon from '@/component/char_icon'; import ToTopButton from '@/component/totop_button'; +import AnimatedCursor from "react-animated-cursor" const currentYear = new Date().getFullYear() @@ -79,8 +80,7 @@ export default function Root() { setTimeout(() => { document.querySelector('.loader').style.display = 'none' }, 500) - } - , []) + }, []) return ( <> @@ -88,6 +88,7 @@ export default function Root() {
toggleDrawer()} + data-type="clickable" >
@@ -138,6 +139,25 @@ export default function Root() { + ) } @@ -150,7 +170,7 @@ function FooterElement() { return (