nomadro/apps/miniprogram/h5/src/components/ProgressRing.tsx
eric 3e5b7c2098 Monorepo super-optimize: src layout, workspace scripts, docs.
Collapse portal under src/, unify pnpm workspace/scripts, thin VIP topic re-exports, drop orphan vip scaffolds and one-shot scripts, ignore xhs/release, document root commands.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-01 00:34:04 +08:00

44 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { H5Box, H5Txt } from './H5Box'
/** 对齐 Next ProgressRing:圆环进度(多端同 SVG) */
export function ProgressRing({
progress,
size = 52,
ringId = 'ring',
}: {
progress: number
size?: number
ringId?: string
}) {
const stroke = 4
const radius = (size - stroke) / 2
const circumference = 2 * Math.PI * radius
const pct = Math.max(0, Math.min(100, progress))
const offset = circumference - (pct / 100) * circumference
const c = size / 2
const gid = `rg-${ringId}`
const html = `<svg width="${size}" height="${size}" viewBox="0 0 ${size} ${size}" aria-hidden="true" style="display:block">
<circle cx="${c}" cy="${c}" r="${radius}" fill="none" stroke="rgba(255,255,255,0.08)" stroke-width="${stroke}"/>
<circle cx="${c}" cy="${c}" r="${radius}" fill="none" stroke="url(#${gid})" stroke-width="${stroke}" stroke-linecap="round"
stroke-dasharray="${circumference.toFixed(2)}" stroke-dashoffset="${offset.toFixed(2)}"
transform="rotate(-90 ${c} ${c})"/>
<defs>
<linearGradient id="${gid}" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" stop-color="#4ecdc4"/>
<stop offset="100%" stop-color="#ff6b6b"/>
</linearGradient>
</defs>
<text x="50%" y="50%" dominant-baseline="central" text-anchor="middle"
fill="#94a3b8" font-size="11" font-weight="600" font-family="ui-sans-serif,system-ui,sans-serif">${pct}%</text>
</svg>`
return (
<H5Box
className="progress-ring"
style={{ width: size, height: size, flexShrink: 0, lineHeight: 0 }}
html={html}
/>
)
}