1- import React , { useState } from 'react' ;
2- import { Radio , Dropdown , Button , Space } from 'antd' ;
3- import { DownOutlined } from '@ant-design/icons' ;
4- import type { MenuProps } from 'antd' ;
1+ import React from 'react' ;
2+ import { Radio } from 'antd' ;
53import styled from 'styled-components' ;
64
7- export type TimeRange = '1day' | '1week' | '1month' | '1year' | '2year' | '3year' | '5year' | 'all' ;
5+ export type TimeRange = '1day' | '1week' | '1month' | '1year' ;
86
97interface TimeRangeSelectorProps {
108 value : TimeRange ;
@@ -13,15 +11,14 @@ interface TimeRangeSelectorProps {
1311
1412const Container = styled . div `
1513 display: flex;
16- gap: 0.5rem;
17- flex-wrap: wrap;
18- margin-bottom: 1rem;
14+ justify-content: center;
15+ margin-top: 0.5rem;
1916` ;
2017
2118const StyledRadioGroup = styled ( Radio . Group ) `
2219 display: flex;
2320 gap: 0.5rem;
24-
21+
2522 .ant-radio-button-wrapper {
2623 background: rgba(0, 255, 255, 0.05);
2724 border: 1px solid rgba(0, 255, 255, 0.2);
@@ -31,24 +28,24 @@ const StyledRadioGroup = styled(Radio.Group)`
3128 height: auto;
3229 line-height: 1.2;
3330 transition: all 0.3s ease;
34-
31+
3532 &:hover {
3633 background: rgba(0, 255, 255, 0.1);
3734 border-color: rgba(0, 255, 255, 0.4);
3835 color: rgba(0, 255, 255, 1);
3936 }
40-
37+
4138 &.ant-radio-button-wrapper-checked {
4239 background: rgba(0, 255, 255, 0.15);
4340 border-color: rgba(0, 255, 255, 0.6);
4441 color: #00ffff;
4542 box-shadow: 0 0 10px rgba(0, 255, 255, 0.3);
46-
43+
4744 &::before {
4845 background-color: rgba(0, 255, 255, 0.6);
4946 }
5047 }
51-
48+
5249 &:not(:first-child)::before {
5350 background-color: rgba(0, 255, 255, 0.2);
5451 }
@@ -62,97 +59,24 @@ const StyledRadioGroup = styled(Radio.Group)`
6259 }
6360` ;
6461
65- const StyledDropdownButton = styled ( Dropdown . Button ) `
66- .ant-btn {
67- background: rgba(0, 255, 255, 0.05);
68- border: 1px solid rgba(0, 255, 255, 0.2);
69- color: rgba(0, 255, 255, 0.8);
70- font-size: 0.75rem;
71- padding: 0.25rem 0.75rem;
72- height: auto;
73- line-height: 1.2;
74- transition: all 0.3s ease;
75-
76- &:hover {
77- background: rgba(0, 255, 255, 0.1);
78- border-color: rgba(0, 255, 255, 0.4);
79- color: rgba(0, 255, 255, 1);
80- }
81-
82- &.active {
83- background: rgba(0, 255, 255, 0.15);
84- border-color: rgba(0, 255, 255, 0.6);
85- color: #00ffff;
86- box-shadow: 0 0 10px rgba(0, 255, 255, 0.3);
87- }
88- }
89-
90- .ant-dropdown-trigger {
91- padding: 0 8px;
92- }
93-
94- @media (max-width: 768px) {
95- .ant-btn {
96- font-size: 0.7rem;
97- padding: 0.2rem 0.5rem;
98- }
99- }
100- ` ;
101-
102- const yearOptions = [
103- { label : '1 Year' , value : '1year' } ,
104- { label : '2 Years' , value : '2year' } ,
105- { label : '3 Years' , value : '3year' } ,
106- { label : '5 Years' , value : '5year' } ,
107- { label : 'All Time' , value : 'all' } ,
108- ] ;
109-
11062export const TimeRangeSelector : React . FC < TimeRangeSelectorProps > = ( { value, onChange } ) => {
111- const isYearRange = [ '1year' , '2year' , '3year' , '5year' , 'all' ] . includes ( value ) ;
112- const nonYearValue = ! isYearRange ? value : undefined ;
113-
114- const [ selectedYearLabel , setSelectedYearLabel ] = useState ( ( ) => {
115- const option = yearOptions . find ( opt => opt . value === value ) ;
116- return option ? option . label : '1 Year' ;
117- } ) ;
118-
119- const handleYearSelect : MenuProps [ 'onClick' ] = ( { key } ) => {
120- const option = yearOptions . find ( opt => opt . value === key ) ;
121- if ( option ) {
122- setSelectedYearLabel ( option . label ) ;
123- onChange ( key as TimeRange ) ;
124- }
125- } ;
126-
127- const yearMenuItems : MenuProps [ 'items' ] = yearOptions . map ( option => ( {
128- key : option . value ,
129- label : option . label ,
130- } ) ) ;
131-
132- const handleNonYearChange = ( e : any ) => {
63+ const handleChange = ( e : any ) => {
13364 onChange ( e . target . value as TimeRange ) ;
13465 } ;
13566
13667 return (
13768 < Container >
13869 < StyledRadioGroup
139- value = { nonYearValue }
140- onChange = { handleNonYearChange }
70+ value = { value }
71+ onChange = { handleChange }
14172 optionType = "button"
14273 buttonStyle = "solid"
14374 >
144- < Radio . Button value = "1day" > 1 Day</ Radio . Button >
145- < Radio . Button value = "1week" > 1 Week</ Radio . Button >
146- < Radio . Button value = "1month" > 1 Month</ Radio . Button >
75+ < Radio . Button value = "1day" > 24H</ Radio . Button >
76+ < Radio . Button value = "1week" > 1W</ Radio . Button >
77+ < Radio . Button value = "1month" > 1M</ Radio . Button >
78+ < Radio . Button value = "1year" > 1Y</ Radio . Button >
14779 </ StyledRadioGroup >
148-
149- < StyledDropdownButton
150- menu = { { items : yearMenuItems , onClick : handleYearSelect } }
151- className = { isYearRange ? 'active' : '' }
152- icon = { < DownOutlined /> }
153- >
154- { selectedYearLabel }
155- </ StyledDropdownButton >
15680 </ Container >
15781 ) ;
15882} ;
0 commit comments