@@ -21,62 +21,46 @@ export interface ButtonGroupProps
21
21
export const ButtonGroup = ( {
22
22
options,
23
23
selected,
24
- fillWidth,
24
+ fillWidth = false ,
25
25
onClick,
26
- type,
26
+ type = "default" ,
27
27
...props
28
28
} : ButtonGroupProps ) => {
29
- const lastIndex = options . length - 1 ;
30
- const btns = options . map ( ( { value, label, ...props } , index ) => {
31
- const position : ButtonPosition =
32
- index === 0 ? "left" : index === lastIndex ? "right" : "center" ;
33
- return (
34
- < Button
35
- key = { value }
36
- $active = { value === selected }
37
- $position = { position }
38
- $fillWidth = { fillWidth }
39
- $type = { type }
40
- onClick = { ( ) => onClick ?.( value ) }
41
- role = "button"
42
- { ...props }
43
- >
44
- { label }
45
- </ Button >
46
- ) ;
47
- } ) ;
29
+ const buttons = options . map ( ( { value, label, ...props } ) => (
30
+ < Button
31
+ key = { value }
32
+ $active = { value === selected }
33
+ $fillWidth = { fillWidth }
34
+ $type = { type }
35
+ onClick = { ( ) => onClick ?.( value ) }
36
+ role = "button"
37
+ { ...props }
38
+ >
39
+ { label }
40
+ </ Button >
41
+ ) ) ;
42
+
48
43
return (
49
44
< ButtonGroupWrapper
50
45
$fillWidth = { fillWidth }
51
46
$type = { type }
52
47
{ ...props }
53
48
>
54
- { btns }
49
+ { buttons }
55
50
</ ButtonGroupWrapper >
56
51
) ;
57
52
} ;
58
53
59
- type ButtonPosition = "left" | "center" | "right" ;
60
-
61
- interface ButtonProps {
62
- $active : boolean ;
63
- $position : ButtonPosition ;
64
- theme : DefaultTheme ;
65
- $fillWidth ?: boolean ;
66
- $type ?: ButtonGroupType ;
67
- }
68
-
69
- const ButtonGroupWrapper = styled . div < { $fillWidth ?: boolean ; $type ?: ButtonGroupType } > `
54
+ const ButtonGroupWrapper = styled . div < { $fillWidth : boolean ; $type : ButtonGroupType } > `
70
55
display: inline-flex;
71
56
box-sizing: border-box;
72
57
flex-direction: row;
73
58
justify-content: center;
74
59
align-items: center;
75
- padding: ${ ( { theme, $type = "default" } ) =>
60
+ padding: ${ ( { theme, $type } ) =>
76
61
`${ theme . click . button . group . space . panel [ $type ] . x } ${ theme . click . button . group . space . panel [ $type ] . y } ` } ;
77
- gap: ${ ( { theme, $type = "default" } ) =>
78
- theme . click . button . group . space . panel [ $type ] . gap } ;
79
- border: ${ ( { theme, $type = "default" } ) =>
62
+ gap: ${ ( { theme, $type } ) => theme . click . button . group . space . panel [ $type ] . gap } ;
63
+ border: ${ ( { theme, $type } ) =>
80
64
$type === "default"
81
65
? `1px solid ${ theme . click . button . group . color . panel . stroke [ $type ] } `
82
66
: "none" } ;
@@ -85,6 +69,13 @@ const ButtonGroupWrapper = styled.div<{ $fillWidth?: boolean; $type?: ButtonGrou
85
69
width: ${ ( { $fillWidth } ) => ( $fillWidth ? "100%" : "auto" ) } ;
86
70
` ;
87
71
72
+ interface ButtonProps {
73
+ $active : boolean ;
74
+ theme : DefaultTheme ;
75
+ $fillWidth : boolean ;
76
+ $type : ButtonGroupType ;
77
+ }
78
+
88
79
const Button = styled . button . attrs < ButtonProps > ( ( props : ButtonProps ) => ( {
89
80
"aria-pressed" : props . $active ,
90
81
} ) ) `
@@ -99,10 +90,10 @@ const Button = styled.button.attrs<ButtonProps>((props: ButtonProps) => ({
99
90
: theme . click . button . group . color . background . default } ;
100
91
color: ${ ( { theme } ) => theme . click . button . group . color . text . default } ;
101
92
font: ${ ( { theme } ) => theme . click . button . group . typography . label . default } ;
102
- padding: ${ ( { theme, $type = "default" } ) =>
93
+ padding: ${ ( { theme, $type } ) =>
103
94
`${ theme . click . button . group . space . button [ $type ] . y } ${ theme . click . button . group . space . button [ $type ] . x } ` } ;
104
- ${ ( { $fillWidth = false } ) => ( $fillWidth ? "flex: 1;" : "" ) } ;
105
- border-radius: ${ ( { theme, $type = "default" } ) =>
95
+ ${ ( { $fillWidth } ) => ( $fillWidth ? "flex: 1;" : "" ) } ;
96
+ border-radius: ${ ( { theme, $type } ) =>
106
97
theme . click . button . group . radii . button [ $type ] . all } ;
107
98
cursor: pointer;
108
99
border: none;
0 commit comments