Skip to content

Commit

Permalink
feat: reduce motion use fade-in and fade-out transition
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Sep 11, 2024
1 parent 0f654b9 commit 78053c1
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 7 deletions.
File renamed without changes.
11 changes: 9 additions & 2 deletions src/renderer/src/components/common/Motion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ export const m: typeof M = new Proxy(M, {
const nextProps = { ...props }
if (shouldReduceMotion) {
if (props.exit) {
delete nextProps.exit
nextProps.exit = {
opacity: 0,
}
}

if (props.initial) {
nextProps.initial = true
nextProps.initial = {
opacity: 0,
}
}
nextProps.animate = {
opacity: 1,
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/renderer/src/components/ui/list-item-hover-overlay.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { m } from "@renderer/components/common/Motion"
import { views } from "@renderer/constants"
import { useRouteParamsSelector } from "@renderer/hooks/biz/useRouteParams"
import clsx from "clsx"
import { AnimatePresence, m } from "framer-motion"
import { AnimatePresence } from "framer-motion"
import { useEffect, useRef, useState } from "react"

export const ListItemHoverOverlay = ({
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/components/ui/modal/inspire/PeekModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { m } from "framer-motion"
import { m } from "@renderer/components/common/Motion"
import type { PropsWithChildren } from "react"
import { createContext, useContext } from "react"
import { Link } from "react-router-dom"
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/src/modules/entry-content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export const EntryContentRender: Component<{ entryId: string }> = ({ entryId, cl
})

const isPeekModal = useInPeekModal()

if (!entry) return null

const content = entry?.entries.content ?? data?.entries.content
Expand Down Expand Up @@ -168,7 +169,7 @@ export const EntryContentRender: Component<{ entryId: string }> = ({ entryId, cl
}
: undefined
}
className="duration-200 ease-in-out animate-in fade-in slide-in-from-bottom-24"
className="duration-200 ease-in-out animate-in fade-in slide-in-from-bottom-24 f-motion-reduce:fade-in-0 f-motion-reduce:slide-in-from-bottom-0"
key={entry.entries.id}
>
<article
Expand Down
11 changes: 10 additions & 1 deletion src/renderer/src/providers/ui-setting-sync.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useUISettingValue } from "@renderer/atoms/settings/ui"
import { useReduceMotion } from "@renderer/hooks/biz/useReduceMotion"
import { useSyncThemeark } from "@renderer/hooks/common"
import { tipcClient } from "@renderer/lib/client"
import { feedUnreadActions } from "@renderer/store/unread"
import { useEffect, useInsertionEffect } from "react"
import { useEffect, useInsertionEffect, useLayoutEffect } from "react"

const useUISettingSync = () => {
const setting = useUISettingValue()
Expand Down Expand Up @@ -43,7 +44,15 @@ const useUISettingSync = () => {
}
}, [setting.voice])
}

const useUXSettingSync = () => {
const reduceMotion = useReduceMotion()
useLayoutEffect(() => {
document.documentElement.dataset.motionReduce = reduceMotion ? "true" : "false"
}, [reduceMotion])
}
export const SettingSync = () => {
useUISettingSync()
useUXSettingSync()
return null
}
9 changes: 8 additions & 1 deletion tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import "./cssAsPlugin"
import "./configs/tw-css-plugin"

import path from "node:path"

import { getIconCollections, iconsPlugin } from "@egoist/tailwindcss-icons"
import { cleanupSVG, importDirectorySync, isEmptyColor, parseColors, runSVGO } from "@iconify/tools"
import { compareColors, stringToColor } from "@iconify/utils/lib/colors"
import plugin from "tailwindcss/plugin"
import resolveConfig from "tailwindcss/resolveConfig"

/** @type {import('tailwindcss').Config} */
Expand Down Expand Up @@ -115,6 +116,7 @@ export default resolveConfig({
}),
},
},

plugins: [
iconsPlugin({
collections: {
Expand All @@ -126,6 +128,11 @@ export default resolveConfig({
require("@tailwindcss/container-queries"),
require("@tailwindcss/typography"),
require("./src/renderer/src/styles/tailwind-extend.css"),
plugin(({ addVariant }) => {
addVariant("f-motion-reduce", '[data-motion-reduce="true"] &')
addVariant("group-motion-reduce", ':merge(.group)[data-motion-reduce="true"] &')
addVariant("peer-motion-reduce", ':merge(.peer)[data-motion-reduce="true"] ~ &')
}),
],
})

Expand Down

0 comments on commit 78053c1

Please sign in to comment.