diff --git a/apps/desktop/layer/renderer/src/lib/parse-html.ts b/apps/desktop/layer/renderer/src/lib/parse-html.ts index 610e9e65b..66e32d454 100644 --- a/apps/desktop/layer/renderer/src/lib/parse-html.ts +++ b/apps/desktop/layer/renderer/src/lib/parse-html.ts @@ -98,6 +98,7 @@ export const parseHtml = ( }), input: ({ node, ...props }) => { if (props.type === "checkbox") { + // @ts-expect-error return createElement(Checkbox, { ...props, disabled: false, diff --git a/apps/desktop/layer/renderer/src/modules/action/feed-filter.tsx b/apps/desktop/layer/renderer/src/modules/action/feed-filter.tsx index b03f0d1b9..43885fe72 100644 --- a/apps/desktop/layer/renderer/src/modules/action/feed-filter.tsx +++ b/apps/desktop/layer/renderer/src/modules/action/feed-filter.tsx @@ -1,6 +1,6 @@ import { Button } from "@follow/components/ui/button/index.js" import { Input } from "@follow/components/ui/input/index.js" -import { Radio, RadioGroup } from "@follow/components/ui/radio-group/index.js" +import { RadioGroup, RadioGroupItem } from "@follow/components/ui/radio-group/motion.js" import { Select, SelectContent, @@ -100,8 +100,8 @@ export const FeedFilter = ({ index }: { index: number }) => { }) }} > - - + - - - diff --git a/apps/desktop/layer/renderer/src/modules/settings/tabs/data-control.tsx b/apps/desktop/layer/renderer/src/modules/settings/tabs/data-control.tsx index ffd4dfcbd..ce64eb261 100644 --- a/apps/desktop/layer/renderer/src/modules/settings/tabs/data-control.tsx +++ b/apps/desktop/layer/renderer/src/modules/settings/tabs/data-control.tsx @@ -11,7 +11,7 @@ import { } from "@follow/components/ui/form/index.js" import { Input } from "@follow/components/ui/input/Input.js" import { Label } from "@follow/components/ui/label/index.jsx" -import { Radio, RadioGroup } from "@follow/components/ui/radio-group/index.js" +import { RadioGroup, RadioGroupItem } from "@follow/components/ui/radio-group/motion.js" import { Slider } from "@follow/components/ui/slider/index.js" import { ELECTRON_BUILD } from "@follow/shared/constants" import { env } from "@follow/shared/env.desktop" @@ -184,8 +184,11 @@ const ExportFeedsForm = () => { }} >
- - + diff --git a/apps/desktop/layer/renderer/src/modules/timeline-column/FeedList.electron.tsx b/apps/desktop/layer/renderer/src/modules/timeline-column/FeedList.electron.tsx index bc9da71f8..97cee63cd 100644 --- a/apps/desktop/layer/renderer/src/modules/timeline-column/FeedList.electron.tsx +++ b/apps/desktop/layer/renderer/src/modules/timeline-column/FeedList.electron.tsx @@ -1,4 +1,5 @@ import { useDraggable } from "@dnd-kit/core" +import { Checkbox } from "@follow/components/ui/checkbox/index.js" import { ScrollArea } from "@follow/components/ui/scroll-area/index.js" import { cn, isKeyForMultiSelectPressed } from "@follow/utils/utils" import { forwardRef, memo, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react" @@ -229,6 +230,7 @@ const FeedListImpl = forwardRef )} + {(hasListData || hasInboxData) && (
& { - onCheckedChange?: (checked: boolean) => void - } ->(({ className, onCheckedChange, ...props }, ref) => ( - { - onCheckedChange?.(event.target.checked) - props.onChange?.(event) - }} - /> -)) +type CheckboxProps = React.ComponentProps & HTMLMotionProps<"button"> + +function Checkbox({ className, onCheckedChange, ...props }: CheckboxProps) { + const [isChecked, setIsChecked] = React.useState(props?.checked ?? props?.defaultChecked ?? false) + + React.useEffect(() => { + if (props?.checked !== undefined) setIsChecked(props.checked) + }, [props?.checked]) + + const handleCheckedChange = React.useCallback( + (checked: boolean) => { + setIsChecked(checked) + onCheckedChange?.(checked) + }, + [onCheckedChange], + ) + + return ( + + + + + + + + + + ) +} + Checkbox.displayName = CheckboxPrimitive.Root.displayName + +export { Checkbox, type CheckboxProps } diff --git a/packages/internal/components/src/ui/radio-group/Radio.tsx b/packages/internal/components/src/ui/radio-group/Radio.tsx deleted file mode 100644 index d60419045..000000000 --- a/packages/internal/components/src/ui/radio-group/Radio.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import { cn } from "@follow/utils/utils" -import type { FC, ReactNode } from "react" -import { useId } from "react" -import { useEventCallback } from "usehooks-ts" - -import { useRadioContext, useRadioGroupValue } from "./context" - -export const Radio: FC< - React.DetailedHTMLProps, HTMLInputElement> & { - label: ReactNode - wrapperClassName?: string - labelClassName?: string - } -> = (props) => { - const { id, label, className, wrapperClassName, labelClassName, value, onChange, ...rest } = props - const { onChange: ctxOnChange } = useRadioContext() || {} - const fallbackId = useId() - - const ctxValue = useRadioGroupValue() - - const handleChange: React.ChangeEventHandler = useEventCallback((e) => { - ctxOnChange?.(e.target.value) - onChange?.(e) - }) - return ( - - ) -} diff --git a/packages/internal/components/src/ui/radio-group/index.ts b/packages/internal/components/src/ui/radio-group/index.ts index d1e49febe..754e44fc2 100644 --- a/packages/internal/components/src/ui/radio-group/index.ts +++ b/packages/internal/components/src/ui/radio-group/index.ts @@ -1,3 +1,4 @@ export * from "./context" -export * from "./Radio" +export * as MotionRadio from "./motion" +export * from "./RadioCard" export * from "./RadioGroup" diff --git a/packages/internal/components/src/ui/radio-group/motion.tsx b/packages/internal/components/src/ui/radio-group/motion.tsx new file mode 100644 index 000000000..8e0f27fee --- /dev/null +++ b/packages/internal/components/src/ui/radio-group/motion.tsx @@ -0,0 +1,99 @@ +"use client" + +import { Spring } from "@follow/components/constants/spring" +import { cn } from "@follow/utils/utils" +import * as RadioGroupPrimitive from "@radix-ui/react-radio-group" +import type { HTMLMotionProps, Transition } from "motion/react" +import { AnimatePresence, m } from "motion/react" +import * as React from "react" + +type RadioGroupProps = React.ComponentProps & { + transition?: Transition +} + +function RadioGroup({ className, ...props }: RadioGroupProps) { + return ( + + ) +} + +type RadioGroupIndicatorProps = React.ComponentProps & { + transition: Transition +} + +function RadioGroupIndicator({ className, transition, ...props }: RadioGroupIndicatorProps) { + return ( + + + + + + + + + + ) +} + +type RadioGroupItemProps = React.ComponentProps & + HTMLMotionProps<"button"> & { + transition?: Transition + label?: string + } + +function RadioGroupItem({ + className, + transition = Spring.presets.smooth, + label, + ...props +}: RadioGroupItemProps) { + const id = React.useId() + return ( + +
+ + + + {label && } +
+
+ ) +} + +export { RadioGroup, RadioGroupItem, type RadioGroupItemProps, type RadioGroupProps } diff --git a/packages/internal/components/src/ui/switch/index.tsx b/packages/internal/components/src/ui/switch/index.tsx index d9e6fd07a..491493a8f 100644 --- a/packages/internal/components/src/ui/switch/index.tsx +++ b/packages/internal/components/src/ui/switch/index.tsx @@ -1,24 +1,110 @@ +"use client" + import { cn } from "@follow/utils/utils" -import * as SwitchPrimitives from "@radix-ui/react-switch" +import type { SwitchProps as SwitchPrimitiveProps } from "@headlessui/react" +import { Switch as SwitchPrimitive } from "@headlessui/react" +import type { HTMLMotionProps } from "motion/react" +import { m as motion } from "motion/react" import * as React from "react" -export const Switch = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - - - -)) -Switch.displayName = SwitchPrimitives.Root.displayName +type SwitchProps = + SwitchPrimitiveProps & + Omit, "children"> & { + leftIcon?: React.ReactNode + rightIcon?: React.ReactNode + thumbIcon?: React.ReactNode + onCheckedChange?: (checked: boolean) => void + as?: TTag + } + +function Switch({ + className, + leftIcon, + rightIcon, + thumbIcon, + onChange, + onCheckedChange, + as = motion.button, + ...props +}: SwitchProps) { + const [isChecked, setIsChecked] = React.useState(props.checked ?? props.defaultChecked ?? false) + const [isTapped, setIsTapped] = React.useState(false) + + React.useEffect(() => { + setIsChecked(props.checked ?? props.defaultChecked ?? false) + }, [props.checked, props.defaultChecked]) + + const handleChange = React.useCallback( + (checked: boolean) => { + setIsChecked(checked) + onCheckedChange?.(checked) + onChange?.(checked) + }, + [onCheckedChange, onChange], + ) + + return ( + // @ts-expect-error + setIsTapped(true)} + onTapCancel={() => setIsTapped(false)} + onTap={() => setIsTapped(false)} + {...props} + > + {leftIcon && ( + + {typeof leftIcon !== "string" ? leftIcon : null} + + )} + + {rightIcon && ( + + {typeof rightIcon !== "string" ? rightIcon : null} + + )} + + + {thumbIcon && typeof thumbIcon !== "string" ? thumbIcon : null} + + + ) +} + +export { Switch, type SwitchProps }