UNPKG

@lobehub/ui

Version:

Lobe UI is an open-source UI component library for building AIGC web apps

1 lines • 2.22 kB
{"version":3,"file":"RouteProgress.mjs","names":[],"sources":["../../../src/dashboard/RouteProgress/RouteProgress.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useState } from 'react';\n\nimport { styles } from './style';\nimport type { RouteProgressProps } from './type';\n\nconst FADE_MS = 200;\nconst CREEP_MS = 120;\n\nfunction RouteProgress({ loading = false }: RouteProgressProps) {\n const [progress, setProgress] = useState<number | null>(null);\n\n useEffect(() => {\n if (loading) {\n const creep = window.setInterval(() => {\n setProgress((value) => {\n const from = value ?? 0;\n return from >= 0.9 ? from : from + (0.9 - from) * 0.2;\n });\n }, CREEP_MS);\n return () => window.clearInterval(creep);\n }\n\n const settle = window.setTimeout(() => {\n setProgress((value) => (value === null ? null : 1));\n }, 0);\n const hide = window.setTimeout(() => setProgress(null), FADE_MS);\n return () => {\n window.clearTimeout(settle);\n window.clearTimeout(hide);\n };\n }, [loading]);\n\n if (progress === null) return null;\n return (\n <div\n aria-hidden\n className={styles.bar}\n style={{\n opacity: progress >= 1 ? 0 : 1,\n transform: `scaleX(${progress})`,\n transition: `transform ${FADE_MS}ms ease-out, opacity ${FADE_MS}ms ease-in`,\n }}\n />\n );\n}\n\nRouteProgress.displayName = 'RouteProgress';\n\nexport default RouteProgress;\n"],"mappings":";;;;;AAOA,MAAM,UAAU;AAChB,MAAM,WAAW;AAEjB,SAAS,cAAc,EAAE,UAAU,SAA6B;CAC9D,MAAM,CAAC,UAAU,eAAe,SAAwB,IAAI;CAE5D,gBAAgB;EACd,IAAI,SAAS;GACX,MAAM,QAAQ,OAAO,kBAAkB;IACrC,aAAa,UAAU;KACrB,MAAM,OAAO,SAAS;KACtB,OAAO,QAAQ,KAAM,OAAO,QAAQ,KAAM,QAAQ;IACpD,CAAC;GACH,GAAG,QAAQ;GACX,aAAa,OAAO,cAAc,KAAK;EACzC;EAEA,MAAM,SAAS,OAAO,iBAAiB;GACrC,aAAa,UAAW,UAAU,OAAO,OAAO,CAAE;EACpD,GAAG,CAAC;EACJ,MAAM,OAAO,OAAO,iBAAiB,YAAY,IAAI,GAAG,OAAO;EAC/D,aAAa;GACX,OAAO,aAAa,MAAM;GAC1B,OAAO,aAAa,IAAI;EAC1B;CACF,GAAG,CAAC,OAAO,CAAC;CAEZ,IAAI,aAAa,MAAM,OAAO;CAC9B,OACE,oBAAC,OAAD;EACE,eAAA;EACA,WAAW,OAAO;EAClB,OAAO;GACL,SAAS,YAAY,IAAI,IAAI;GAC7B,WAAW,UAAU,SAAS;GAC9B,YAAY,aAAa,QAAQ,uBAAuB,QAAQ;EAClE;CACD,CAAA;AAEL;AAEA,cAAc,cAAc"}