@@ -11,6 +11,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
11
11
import androidx.compose.material3.Button
12
12
import androidx.compose.material3.ButtonColors
13
13
import androidx.compose.material3.ButtonDefaults
14
+ import androidx.compose.material3.ProvideTextStyle
14
15
import androidx.compose.material3.Text
15
16
import androidx.compose.runtime.Composable
16
17
import androidx.compose.ui.Alignment
@@ -39,9 +40,7 @@ fun ButtonDefaults.camstudyTextButtonColors(
39
40
@Composable
40
41
internal fun RawButton (
41
42
modifier : Modifier = Modifier ,
42
- label : String ,
43
- enableLabelSizeAnimation : Boolean = false,
44
- leadingIcon : CamstudyIcon ? = null,
43
+ leading : @Composable (() -> Unit )? = null,
45
44
shape : Shape = RoundedCornerShape (8.dp),
46
45
colors : ButtonColors = ButtonDefaults .buttonColors(
47
46
containerColor = CamstudyTheme .colorScheme.primary,
@@ -51,7 +50,8 @@ internal fun RawButton(
51
50
),
52
51
enabled : Boolean = true,
53
52
border : BorderStroke ? = null,
54
- onClick : () -> Unit
53
+ onClick : () -> Unit ,
54
+ content : @Composable () -> Unit ,
55
55
) {
56
56
Button (
57
57
modifier = modifier,
@@ -66,29 +66,42 @@ internal fun RawButton(
66
66
)
67
67
) {
68
68
Row (verticalAlignment = Alignment .CenterVertically ) {
69
- if (leadingIcon != null ) {
70
- CamstudyIcon (
71
- modifier = Modifier .size(20 .dp),
72
- icon = leadingIcon,
73
- contentDescription = null ,
74
- )
69
+ if (leading != null ) {
70
+ leading()
75
71
Spacer (modifier = Modifier .width(10 .dp))
76
72
}
77
- Text (
78
- modifier = if (enableLabelSizeAnimation) {
79
- Modifier .animateContentSize()
80
- } else {
81
- Modifier
82
- },
83
- text = label,
84
- style = CamstudyTheme .typography.titleMedium.copy(
73
+ ProvideTextStyle (
74
+ value = CamstudyTheme .typography.titleMedium.copy(
85
75
fontWeight = FontWeight .Medium
86
76
)
87
- )
77
+ ) {
78
+ content()
79
+ }
88
80
}
89
81
}
90
82
}
91
83
84
+ @Composable
85
+ private fun DefaultContentText (text : String , enableLabelSizeAnimation : Boolean = false) {
86
+ Text (
87
+ modifier = if (enableLabelSizeAnimation) {
88
+ Modifier .animateContentSize()
89
+ } else {
90
+ Modifier
91
+ },
92
+ text = text,
93
+ )
94
+ }
95
+
96
+ @Composable
97
+ private fun DefaultLeadingIcon (icon : CamstudyIcon ) {
98
+ CamstudyIcon (
99
+ modifier = Modifier .size(20 .dp),
100
+ icon = icon,
101
+ contentDescription = null ,
102
+ )
103
+ }
104
+
92
105
@Composable
93
106
fun CamstudyOutlinedButton (
94
107
modifier : Modifier = Modifier ,
@@ -110,19 +123,21 @@ fun CamstudyOutlinedButton(
110
123
RawButton (
111
124
modifier = modifier,
112
125
onClick = onClick,
113
- label = label,
114
126
shape = shape,
115
127
enabled = enabled,
116
- enableLabelSizeAnimation = enableLabelSizeAnimation,
117
- leadingIcon = leadingIcon,
128
+ leading = if (leadingIcon != null ) {
129
+ { DefaultLeadingIcon (icon = leadingIcon) }
130
+ } else null ,
118
131
border = BorderStroke (width = 1 .dp, color = borderColor),
119
132
colors = ButtonDefaults .buttonColors(
120
133
containerColor = containerColor,
121
134
contentColor = contentColor,
122
135
disabledContainerColor = colorScheme.systemBackground,
123
136
disabledContentColor = colorScheme.systemUi04
124
137
),
125
- )
138
+ ) {
139
+ DefaultContentText (text = label, enableLabelSizeAnimation = enableLabelSizeAnimation)
140
+ }
126
141
}
127
142
128
143
@Composable
@@ -139,18 +154,20 @@ fun CamstudyContainedButton(
139
154
RawButton (
140
155
modifier = modifier,
141
156
onClick = onClick,
142
- label = label,
143
157
shape = shape,
144
- enableLabelSizeAnimation = enableLabelSizeAnimation,
145
- leadingIcon = leadingIcon,
158
+ leading = if (leadingIcon != null ) {
159
+ { DefaultLeadingIcon (icon = leadingIcon) }
160
+ } else null ,
146
161
enabled = enabled,
147
162
colors = ButtonDefaults .buttonColors(
148
163
containerColor = colorScheme.primary,
149
164
contentColor = colorScheme.systemBackground,
150
165
disabledContainerColor = colorScheme.systemUi02,
151
166
disabledContentColor = colorScheme.systemUi05
152
167
),
153
- )
168
+ ) {
169
+ DefaultContentText (text = label, enableLabelSizeAnimation = enableLabelSizeAnimation)
170
+ }
154
171
}
155
172
156
173
@Composable
@@ -166,12 +183,15 @@ fun CamstudyTextButton(
166
183
RawButton (
167
184
modifier = modifier,
168
185
onClick = onClick,
169
- label = label,
170
186
shape = shape,
171
- leadingIcon = leadingIcon,
187
+ leading = if (leadingIcon != null ) {
188
+ { DefaultLeadingIcon (icon = leadingIcon) }
189
+ } else null ,
172
190
enabled = enabled,
173
191
colors = colors,
174
- )
192
+ ) {
193
+ DefaultContentText (text = label)
194
+ }
175
195
}
176
196
177
197
@Preview
0 commit comments