import React, { type ComponentPropsWithoutRef, type FC } from 'react'; import { BiLogoChrome } from 'react-icons/bi'; import { HiMiniLanguage } from 'react-icons/hi2'; import { MdDarkMode, MdLightMode } from 'react-icons/md'; import { useMounted } from '@wener/reaction'; import { cn } from '../../utils/cn'; import { getUserAgentPreferences } from '../../utils/UserAgentPreference'; export interface UserAgentSummaryProps extends ComponentPropsWithoutRef<'small'> {} const UserAgentPrefers = () => { const { colorTheme, devicePixelRatio } = getUserAgentPreferences(); return ( <> {colorTheme === 'dark' && } {colorTheme === 'light' && } {devicePixelRatio > 1 && {devicePixelRatio}dppx} ); }; const Lang = () => { return ( {navigator.language} ); }; const Browser = () => { const { brand, version } = navigator.userAgent.match(/(?Chrom(e|ium))\/(?[0-9]+)\./)?.groups ?? {}; if (!brand) { return 请使用新版本的 Chrome 浏览器; } const old = parseInt(version) < 100; return (
{brand} {version} {old && ( 当前浏览器版本 {version} 过低,请下载使用新版本浏览器。 )}
); }; export const UserAgentSummary: FC = ({ className, ...props }) => { const mounted = useMounted(); if (!mounted) { return null; } return ( ); };