|
| 1 | +import styled from 'styled-components'; |
| 2 | +import { useTranslation } from 'react-i18next'; |
| 3 | +import { DatabaseOutlined, FireOutlined, StarOutlined } from '@ant-design/icons'; |
| 4 | + |
| 5 | +const HeroCard = styled.div` |
| 6 | + display: flex; |
| 7 | + justify-content: center; |
| 8 | + margin-bottom: 64px; |
| 9 | + padding: 48px; |
| 10 | + border-radius: var(--radius-xl); |
| 11 | + border: 1px solid var(--border-color); |
| 12 | + background: linear-gradient(145deg, var(--bg-elevated), var(--bg-primary)); |
| 13 | + box-shadow: var(--shadow-sm); |
| 14 | + position: relative; |
| 15 | + overflow: hidden; |
| 16 | +
|
| 17 | + &::before { |
| 18 | + content: ''; |
| 19 | + position: absolute; |
| 20 | + top: 0; |
| 21 | + left: 0; |
| 22 | + right: 0; |
| 23 | + height: 6px; |
| 24 | + background: var(--gradient-accent); |
| 25 | + opacity: 0.8; |
| 26 | + } |
| 27 | +
|
| 28 | + @media (min-width: 900px) { |
| 29 | + align-items: center; |
| 30 | + } |
| 31 | +
|
| 32 | + @media (max-width: 768px) { |
| 33 | + padding: 32px 24px; |
| 34 | + } |
| 35 | +`; |
| 36 | + |
| 37 | +const MetaGrid = styled.div` |
| 38 | + display: flex; |
| 39 | + justify-content: center; |
| 40 | + gap: 48px; |
| 41 | + flex-wrap: wrap; |
| 42 | +
|
| 43 | + @media (max-width: 640px) { |
| 44 | + width: 100%; |
| 45 | + flex-direction: column; |
| 46 | + justify-content: center; |
| 47 | + gap: 24px; |
| 48 | + } |
| 49 | +`; |
| 50 | + |
| 51 | +const MetaCard = styled.div` |
| 52 | + display: flex; |
| 53 | + flex-direction: column; |
| 54 | + align-items: center; |
| 55 | + gap: 12px; |
| 56 | + padding: 24px 40px; |
| 57 | + border-radius: var(--radius-lg); |
| 58 | + background: var(--bg-secondary); |
| 59 | + border: 1px solid transparent; |
| 60 | + transition: all 0.3s ease; |
| 61 | +
|
| 62 | + &:hover { |
| 63 | + transform: translateY(-4px); |
| 64 | + box-shadow: var(--shadow-md); |
| 65 | + border-color: var(--border-color); |
| 66 | + background: var(--bg-elevated); |
| 67 | + |
| 68 | + .anticon { |
| 69 | + color: var(--color-accent); |
| 70 | + transform: scale(1.1); |
| 71 | + } |
| 72 | + } |
| 73 | +
|
| 74 | + @media (max-width: 640px) { |
| 75 | + width: 100%; |
| 76 | + padding: 24px; |
| 77 | + } |
| 78 | +`; |
| 79 | + |
| 80 | +const MetaLabel = styled.div` |
| 81 | + display: flex; |
| 82 | + align-items: center; |
| 83 | + gap: 8px; |
| 84 | + color: var(--text-tertiary); |
| 85 | + font-size: 0.95rem; |
| 86 | + font-weight: 600; |
| 87 | + text-transform: uppercase; |
| 88 | + letter-spacing: 0.1em; |
| 89 | +
|
| 90 | + .anticon { |
| 91 | + font-size: 1.1rem; |
| 92 | + transition: all 0.3s ease; |
| 93 | + } |
| 94 | +`; |
| 95 | + |
| 96 | +const MetaValue = styled.div` |
| 97 | + font-family: var(--font-heading); |
| 98 | + font-size: 3.2rem; |
| 99 | + font-weight: 800; |
| 100 | + color: var(--text-primary); |
| 101 | + line-height: 1; |
| 102 | + text-shadow: 0 2px 10px rgba(0, 0, 0, 0.05); |
| 103 | +`; |
| 104 | + |
| 105 | +interface HeroSectionProps { |
| 106 | + loading: boolean; |
| 107 | + stats: { |
| 108 | + totalCount: number; |
| 109 | + activeCount: number; |
| 110 | + totalStars: number; |
| 111 | + }; |
| 112 | +} |
| 113 | + |
| 114 | +const getNumberLocale = (language: string) => { |
| 115 | + const normalizedLocale = language.replace('_', '-'); |
| 116 | + |
| 117 | + return Intl.NumberFormat.supportedLocalesOf([normalizedLocale])[0] ?? 'en-US'; |
| 118 | +}; |
| 119 | + |
| 120 | +const HeroSection = ({ loading, stats }: HeroSectionProps) => { |
| 121 | + const { t, i18n } = useTranslation(); |
| 122 | + const numberLocale = getNumberLocale(i18n.resolvedLanguage ?? i18n.language); |
| 123 | + |
| 124 | + const formatValue = (value: number) => { |
| 125 | + if (loading) { |
| 126 | + return '--'; |
| 127 | + } |
| 128 | + |
| 129 | + return value.toLocaleString(numberLocale); |
| 130 | + }; |
| 131 | + |
| 132 | + return ( |
| 133 | + <HeroCard> |
| 134 | + <MetaGrid> |
| 135 | + <MetaCard> |
| 136 | + <MetaLabel> |
| 137 | + <DatabaseOutlined /> {t('opensource.stats.total')} |
| 138 | + </MetaLabel> |
| 139 | + <MetaValue>{formatValue(stats.totalCount)}</MetaValue> |
| 140 | + </MetaCard> |
| 141 | + <MetaCard> |
| 142 | + <MetaLabel> |
| 143 | + <FireOutlined /> {t('opensource.stats.active')} |
| 144 | + </MetaLabel> |
| 145 | + <MetaValue>{formatValue(stats.activeCount)}</MetaValue> |
| 146 | + </MetaCard> |
| 147 | + <MetaCard> |
| 148 | + <MetaLabel> |
| 149 | + <StarOutlined /> {t('opensource.stats.stars')} |
| 150 | + </MetaLabel> |
| 151 | + <MetaValue>{formatValue(stats.totalStars)}</MetaValue> |
| 152 | + </MetaCard> |
| 153 | + </MetaGrid> |
| 154 | + </HeroCard> |
| 155 | + ); |
| 156 | +}; |
| 157 | + |
| 158 | +export default HeroSection; |
0 commit comments