werewolf-ui 0.1.0-beta.0 → 0.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -12
- package/data/manifest.json +1974 -365
- package/data/native/android/WerewolfAlert.kt +210 -0
- package/data/native/android/WerewolfBadge.kt +307 -0
- package/data/native/android/WerewolfButton.kt +692 -0
- package/data/native/android/WerewolfCard.kt +134 -0
- package/data/native/android/WerewolfEmptyState.kt +94 -0
- package/data/native/android/WerewolfFonts.kt +69 -0
- package/data/native/android/WerewolfIcons.kt +94 -0
- package/data/native/android/WerewolfInput.kt +558 -0
- package/data/native/android/WerewolfKbd.kt +103 -0
- package/data/native/android/WerewolfLabel.kt +236 -0
- package/data/native/android/WerewolfModifiers.kt +137 -0
- package/data/native/android/WerewolfSeparator.kt +90 -0
- package/data/native/android/WerewolfSkeleton.kt +170 -0
- package/data/native/android/WerewolfSpinner.kt +79 -0
- package/data/native/android/WerewolfSpinnerArc.kt +53 -0
- package/data/native/android/WerewolfSwitch.kt +485 -0
- package/data/native/android/WerewolfTheme.kt +36 -0
- package/data/native/android/WerewolfToken.kt +240 -0
- package/data/native/ios/WerewolfAlert.swift +284 -0
- package/data/native/ios/WerewolfBadge.swift +439 -0
- package/data/native/ios/WerewolfButton.swift +721 -0
- package/data/native/ios/WerewolfCard.swift +189 -0
- package/data/native/ios/WerewolfEmptyState.swift +122 -0
- package/data/native/ios/WerewolfFonts.swift +140 -0
- package/data/native/ios/WerewolfIcons.swift +35 -0
- package/data/native/ios/WerewolfInput.swift +670 -0
- package/data/native/ios/WerewolfKbd.swift +136 -0
- package/data/native/ios/WerewolfLabel.swift +270 -0
- package/data/native/ios/WerewolfModifiers.swift +108 -0
- package/data/native/ios/WerewolfSeparator.swift +120 -0
- package/data/native/ios/WerewolfSkeleton.swift +238 -0
- package/data/native/ios/WerewolfSpinner.swift +108 -0
- package/data/native/ios/WerewolfSpinnerArc.swift +24 -0
- package/data/native/ios/WerewolfSwitch.swift +737 -0
- package/data/native/ios/WerewolfTheme.swift +62 -0
- package/data/native/ios/WerewolfToken.swift +320 -0
- package/dist/cli.mjs +11634 -7280
- package/dist/core.mjs +7426 -4371
- package/dist/lint.mjs +61 -11
- package/dist/package-manager.mjs +55 -10
- package/dist/project.mjs +228 -16
- package/package.json +3 -2
|
@@ -0,0 +1,692 @@
|
|
|
1
|
+
// Generated file, must not be edited by hand. Source: components/button.spec.json (werewolf-ui 0.1.0-beta.2).
|
|
2
|
+
package dev.werewolfui
|
|
3
|
+
|
|
4
|
+
import androidx.compose.animation.animateColorAsState
|
|
5
|
+
import androidx.compose.animation.core.animateFloatAsState
|
|
6
|
+
import androidx.compose.animation.core.snap
|
|
7
|
+
import androidx.compose.animation.core.tween
|
|
8
|
+
import androidx.compose.foundation.background
|
|
9
|
+
import androidx.compose.foundation.border
|
|
10
|
+
import androidx.compose.foundation.clickable
|
|
11
|
+
import androidx.compose.foundation.focusable
|
|
12
|
+
import androidx.compose.foundation.hoverable
|
|
13
|
+
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
14
|
+
import androidx.compose.foundation.interaction.collectIsFocusedAsState
|
|
15
|
+
import androidx.compose.foundation.interaction.collectIsHoveredAsState
|
|
16
|
+
import androidx.compose.foundation.interaction.collectIsPressedAsState
|
|
17
|
+
import androidx.compose.foundation.layout.Arrangement
|
|
18
|
+
import androidx.compose.foundation.layout.Box
|
|
19
|
+
import androidx.compose.foundation.layout.Row
|
|
20
|
+
import androidx.compose.foundation.layout.fillMaxWidth
|
|
21
|
+
import androidx.compose.foundation.layout.height
|
|
22
|
+
import androidx.compose.foundation.layout.padding
|
|
23
|
+
import androidx.compose.foundation.layout.width
|
|
24
|
+
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
25
|
+
import androidx.compose.runtime.Composable
|
|
26
|
+
import androidx.compose.runtime.CompositionLocalProvider
|
|
27
|
+
import androidx.compose.runtime.getValue
|
|
28
|
+
import androidx.compose.runtime.remember
|
|
29
|
+
import androidx.compose.ui.Alignment
|
|
30
|
+
import androidx.compose.ui.Modifier
|
|
31
|
+
import androidx.compose.ui.graphics.Color
|
|
32
|
+
import androidx.compose.ui.graphics.graphicsLayer
|
|
33
|
+
import androidx.compose.ui.semantics.Role
|
|
34
|
+
import androidx.compose.ui.semantics.contentDescription
|
|
35
|
+
import androidx.compose.ui.semantics.hideFromAccessibility
|
|
36
|
+
import androidx.compose.ui.semantics.role
|
|
37
|
+
import androidx.compose.ui.semantics.semantics
|
|
38
|
+
import androidx.compose.ui.semantics.stateDescription
|
|
39
|
+
import androidx.compose.ui.unit.Dp
|
|
40
|
+
import androidx.compose.ui.unit.TextUnit
|
|
41
|
+
import androidx.compose.ui.unit.dp
|
|
42
|
+
import dev.werewolfui.runtime.LocalWerewolf
|
|
43
|
+
import dev.werewolfui.runtime.LocalWerewolfContentColor
|
|
44
|
+
import dev.werewolfui.runtime.LocalWerewolfFonts
|
|
45
|
+
import dev.werewolfui.runtime.LocalWerewolfTextStyle
|
|
46
|
+
import dev.werewolfui.runtime.WerewolfFontRole
|
|
47
|
+
import dev.werewolfui.runtime.WerewolfSpinnerArc
|
|
48
|
+
import dev.werewolfui.runtime.WerewolfText
|
|
49
|
+
import dev.werewolfui.runtime.rememberReduceMotion
|
|
50
|
+
import dev.werewolfui.runtime.toCubicBezierEasing
|
|
51
|
+
import dev.werewolfui.runtime.werewolfFocusRing
|
|
52
|
+
import dev.werewolfui.runtime.werewolfHitArea
|
|
53
|
+
import dev.werewolfui.runtime.werewolfOverlay
|
|
54
|
+
import dev.werewolfui.runtime.werewolfShadow
|
|
55
|
+
import dev.werewolfui.tokens.WerewolfEasing
|
|
56
|
+
import dev.werewolfui.tokens.WerewolfShadowLayer
|
|
57
|
+
|
|
58
|
+
enum class WerewolfButtonSize {
|
|
59
|
+
Sm,
|
|
60
|
+
Md,
|
|
61
|
+
Lg,
|
|
62
|
+
Xl,
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
enum class WerewolfButtonVariant {
|
|
66
|
+
Solid,
|
|
67
|
+
Secondary,
|
|
68
|
+
Soft,
|
|
69
|
+
Ghost,
|
|
70
|
+
Link,
|
|
71
|
+
Destructive,
|
|
72
|
+
DestructiveSoft,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@Composable
|
|
76
|
+
fun WerewolfButton(
|
|
77
|
+
onClick: () -> Unit,
|
|
78
|
+
modifier: Modifier = Modifier,
|
|
79
|
+
enabled: Boolean = true,
|
|
80
|
+
fullWidth: Boolean = false,
|
|
81
|
+
loading: Boolean = false,
|
|
82
|
+
loadingText: String = "",
|
|
83
|
+
size: WerewolfButtonSize = WerewolfButtonSize.Md,
|
|
84
|
+
variant: WerewolfButtonVariant = WerewolfButtonVariant.Solid,
|
|
85
|
+
leadingIcon: (@Composable () -> Unit)? = null,
|
|
86
|
+
trailingIcon: (@Composable () -> Unit)? = null,
|
|
87
|
+
label: @Composable () -> Unit,
|
|
88
|
+
) {
|
|
89
|
+
WerewolfButton(
|
|
90
|
+
onClick = onClick,
|
|
91
|
+
iconOnly = false,
|
|
92
|
+
accessibilityLabel = "",
|
|
93
|
+
modifier = modifier,
|
|
94
|
+
enabled = enabled,
|
|
95
|
+
fullWidth = fullWidth,
|
|
96
|
+
loading = loading,
|
|
97
|
+
loadingText = loadingText,
|
|
98
|
+
size = size,
|
|
99
|
+
variant = variant,
|
|
100
|
+
leadingIcon = leadingIcon,
|
|
101
|
+
trailingIcon = trailingIcon,
|
|
102
|
+
label = label,
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@Composable
|
|
107
|
+
fun WerewolfButton(
|
|
108
|
+
onClick: () -> Unit,
|
|
109
|
+
iconOnly: Boolean,
|
|
110
|
+
accessibilityLabel: String,
|
|
111
|
+
modifier: Modifier = Modifier,
|
|
112
|
+
enabled: Boolean = true,
|
|
113
|
+
fullWidth: Boolean = false,
|
|
114
|
+
loading: Boolean = false,
|
|
115
|
+
loadingText: String = "",
|
|
116
|
+
size: WerewolfButtonSize = WerewolfButtonSize.Md,
|
|
117
|
+
variant: WerewolfButtonVariant = WerewolfButtonVariant.Solid,
|
|
118
|
+
leadingIcon: (@Composable () -> Unit)? = null,
|
|
119
|
+
trailingIcon: (@Composable () -> Unit)? = null,
|
|
120
|
+
label: @Composable () -> Unit,
|
|
121
|
+
) {
|
|
122
|
+
val t = LocalWerewolf.current
|
|
123
|
+
val reduced = rememberReduceMotion()
|
|
124
|
+
val interactionSource = remember { MutableInteractionSource() }
|
|
125
|
+
val pressed by interactionSource.collectIsPressedAsState()
|
|
126
|
+
val hovered by interactionSource.collectIsHoveredAsState()
|
|
127
|
+
val focusVisible by interactionSource.collectIsFocusedAsState()
|
|
128
|
+
// werewolf:property=root.background-color
|
|
129
|
+
val rootBackgroundColor: Color? = when (variant) {
|
|
130
|
+
// werewolf:variant=solid
|
|
131
|
+
WerewolfButtonVariant.Solid -> run {
|
|
132
|
+
// werewolf:state=disabled
|
|
133
|
+
if (!enabled) {
|
|
134
|
+
return@run t.colorBackgroundDisabled
|
|
135
|
+
}
|
|
136
|
+
// werewolf:state=default
|
|
137
|
+
t.colorAccent
|
|
138
|
+
}
|
|
139
|
+
// werewolf:variant=secondary
|
|
140
|
+
WerewolfButtonVariant.Secondary -> run {
|
|
141
|
+
// werewolf:state=disabled
|
|
142
|
+
if (!enabled) {
|
|
143
|
+
return@run t.colorBackgroundDisabled
|
|
144
|
+
}
|
|
145
|
+
// werewolf:state=default
|
|
146
|
+
t.colorBackgroundRaised
|
|
147
|
+
}
|
|
148
|
+
// werewolf:variant=soft
|
|
149
|
+
WerewolfButtonVariant.Soft -> run {
|
|
150
|
+
// werewolf:state=disabled
|
|
151
|
+
if (!enabled) {
|
|
152
|
+
return@run t.colorBackgroundDisabled
|
|
153
|
+
}
|
|
154
|
+
// werewolf:state=default
|
|
155
|
+
t.colorAccentMuted
|
|
156
|
+
}
|
|
157
|
+
// werewolf:variant=ghost
|
|
158
|
+
WerewolfButtonVariant.Ghost -> run {
|
|
159
|
+
// werewolf:state=disabled
|
|
160
|
+
if (!enabled) {
|
|
161
|
+
return@run t.colorBackgroundDisabled
|
|
162
|
+
}
|
|
163
|
+
// werewolf:state=default
|
|
164
|
+
null
|
|
165
|
+
}
|
|
166
|
+
// werewolf:variant=link
|
|
167
|
+
WerewolfButtonVariant.Link -> run {
|
|
168
|
+
// werewolf:state=disabled
|
|
169
|
+
if (!enabled) {
|
|
170
|
+
return@run t.colorBackgroundDisabled
|
|
171
|
+
}
|
|
172
|
+
// werewolf:state=default
|
|
173
|
+
null
|
|
174
|
+
}
|
|
175
|
+
// werewolf:variant=destructive
|
|
176
|
+
WerewolfButtonVariant.Destructive -> run {
|
|
177
|
+
// werewolf:state=disabled
|
|
178
|
+
if (!enabled) {
|
|
179
|
+
return@run t.colorBackgroundDisabled
|
|
180
|
+
}
|
|
181
|
+
// werewolf:state=default
|
|
182
|
+
t.colorDanger
|
|
183
|
+
}
|
|
184
|
+
// werewolf:variant=destructive-soft
|
|
185
|
+
WerewolfButtonVariant.DestructiveSoft -> run {
|
|
186
|
+
// werewolf:state=disabled
|
|
187
|
+
if (!enabled) {
|
|
188
|
+
return@run t.colorBackgroundDisabled
|
|
189
|
+
}
|
|
190
|
+
// werewolf:state=default
|
|
191
|
+
t.colorBackgroundDanger
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// werewolf:property=root.border-color
|
|
195
|
+
val rootBorderColor: Color? = when (variant) {
|
|
196
|
+
// werewolf:variant=solid
|
|
197
|
+
WerewolfButtonVariant.Solid -> null
|
|
198
|
+
// werewolf:variant=secondary
|
|
199
|
+
WerewolfButtonVariant.Secondary -> t.colorBorder
|
|
200
|
+
// werewolf:variant=soft
|
|
201
|
+
WerewolfButtonVariant.Soft -> null
|
|
202
|
+
// werewolf:variant=ghost
|
|
203
|
+
WerewolfButtonVariant.Ghost -> null
|
|
204
|
+
// werewolf:variant=link
|
|
205
|
+
WerewolfButtonVariant.Link -> null
|
|
206
|
+
// werewolf:variant=destructive
|
|
207
|
+
WerewolfButtonVariant.Destructive -> null
|
|
208
|
+
// werewolf:variant=destructive-soft
|
|
209
|
+
WerewolfButtonVariant.DestructiveSoft -> t.colorBorderDanger
|
|
210
|
+
}
|
|
211
|
+
// werewolf:property=root.border-radius
|
|
212
|
+
val rootBorderRadius = t.radiusElement
|
|
213
|
+
// werewolf:property=root.border-width
|
|
214
|
+
val rootBorderWidth = t.borderWidth
|
|
215
|
+
// werewolf:property=root.box-shadow
|
|
216
|
+
val rootBoxShadow: List<WerewolfShadowLayer>? = when (variant) {
|
|
217
|
+
// werewolf:variant=solid
|
|
218
|
+
WerewolfButtonVariant.Solid -> t.shadowLow
|
|
219
|
+
// werewolf:variant=secondary
|
|
220
|
+
WerewolfButtonVariant.Secondary -> t.shadowLow
|
|
221
|
+
// werewolf:variant=soft
|
|
222
|
+
WerewolfButtonVariant.Soft -> null
|
|
223
|
+
// werewolf:variant=ghost
|
|
224
|
+
WerewolfButtonVariant.Ghost -> null
|
|
225
|
+
// werewolf:variant=link
|
|
226
|
+
WerewolfButtonVariant.Link -> null
|
|
227
|
+
// werewolf:variant=destructive
|
|
228
|
+
WerewolfButtonVariant.Destructive -> null
|
|
229
|
+
// werewolf:variant=destructive-soft
|
|
230
|
+
WerewolfButtonVariant.DestructiveSoft -> null
|
|
231
|
+
}
|
|
232
|
+
// werewolf:property=root.color
|
|
233
|
+
val rootColor: Color = when (variant) {
|
|
234
|
+
// werewolf:variant=solid
|
|
235
|
+
WerewolfButtonVariant.Solid -> run {
|
|
236
|
+
// werewolf:state=disabled
|
|
237
|
+
if (!enabled) {
|
|
238
|
+
return@run t.colorTextDisabled
|
|
239
|
+
}
|
|
240
|
+
// werewolf:state=default
|
|
241
|
+
t.colorTextOnAccent
|
|
242
|
+
}
|
|
243
|
+
// werewolf:variant=secondary
|
|
244
|
+
WerewolfButtonVariant.Secondary -> run {
|
|
245
|
+
// werewolf:state=disabled
|
|
246
|
+
if (!enabled) {
|
|
247
|
+
return@run t.colorTextDisabled
|
|
248
|
+
}
|
|
249
|
+
// werewolf:state=default
|
|
250
|
+
t.colorTextPrimary
|
|
251
|
+
}
|
|
252
|
+
// werewolf:variant=soft
|
|
253
|
+
WerewolfButtonVariant.Soft -> run {
|
|
254
|
+
// werewolf:state=disabled
|
|
255
|
+
if (!enabled) {
|
|
256
|
+
return@run t.colorTextDisabled
|
|
257
|
+
}
|
|
258
|
+
// werewolf:state=default
|
|
259
|
+
t.colorTextOnMuted
|
|
260
|
+
}
|
|
261
|
+
// werewolf:variant=ghost
|
|
262
|
+
WerewolfButtonVariant.Ghost -> run {
|
|
263
|
+
// werewolf:state=disabled
|
|
264
|
+
if (!enabled) {
|
|
265
|
+
return@run t.colorTextDisabled
|
|
266
|
+
}
|
|
267
|
+
// werewolf:state=hover
|
|
268
|
+
if (hovered) {
|
|
269
|
+
return@run t.colorTextPrimary
|
|
270
|
+
}
|
|
271
|
+
// werewolf:state=default
|
|
272
|
+
t.colorTextSecondary
|
|
273
|
+
}
|
|
274
|
+
// werewolf:variant=link
|
|
275
|
+
WerewolfButtonVariant.Link -> run {
|
|
276
|
+
// werewolf:state=disabled
|
|
277
|
+
if (!enabled) {
|
|
278
|
+
return@run t.colorTextDisabled
|
|
279
|
+
}
|
|
280
|
+
// werewolf:state=default
|
|
281
|
+
t.colorTextAccent
|
|
282
|
+
}
|
|
283
|
+
// werewolf:variant=destructive
|
|
284
|
+
WerewolfButtonVariant.Destructive -> run {
|
|
285
|
+
// werewolf:state=disabled
|
|
286
|
+
if (!enabled) {
|
|
287
|
+
return@run t.colorTextDisabled
|
|
288
|
+
}
|
|
289
|
+
// werewolf:state=default
|
|
290
|
+
t.colorTextOnDanger
|
|
291
|
+
}
|
|
292
|
+
// werewolf:variant=destructive-soft
|
|
293
|
+
WerewolfButtonVariant.DestructiveSoft -> run {
|
|
294
|
+
// werewolf:state=disabled
|
|
295
|
+
if (!enabled) {
|
|
296
|
+
return@run t.colorTextDisabled
|
|
297
|
+
}
|
|
298
|
+
// werewolf:state=default
|
|
299
|
+
t.colorTextDanger
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
// werewolf:property=root.font-family
|
|
303
|
+
val rootFontFamily = t.fontFamilySans
|
|
304
|
+
// werewolf:property=root.font-size
|
|
305
|
+
val rootFontSize: TextUnit = when (size) {
|
|
306
|
+
// werewolf:size=sm
|
|
307
|
+
WerewolfButtonSize.Sm -> t.fontSizeSm
|
|
308
|
+
// werewolf:size=md
|
|
309
|
+
WerewolfButtonSize.Md -> t.fontSizeSm
|
|
310
|
+
// werewolf:size=lg
|
|
311
|
+
WerewolfButtonSize.Lg -> t.fontSizeSm
|
|
312
|
+
// werewolf:size=xl
|
|
313
|
+
WerewolfButtonSize.Xl -> t.fontSizeMd
|
|
314
|
+
}
|
|
315
|
+
// werewolf:property=root.font-weight
|
|
316
|
+
val rootFontWeight = t.fontWeightMedium
|
|
317
|
+
// werewolf:property=root.gap
|
|
318
|
+
val rootGap: Dp = when (size) {
|
|
319
|
+
// werewolf:size=sm
|
|
320
|
+
WerewolfButtonSize.Sm -> t.spacingXs
|
|
321
|
+
// werewolf:size=md
|
|
322
|
+
WerewolfButtonSize.Md -> t.spacingSm
|
|
323
|
+
// werewolf:size=lg
|
|
324
|
+
WerewolfButtonSize.Lg -> t.spacingSm
|
|
325
|
+
// werewolf:size=xl
|
|
326
|
+
WerewolfButtonSize.Xl -> t.spacingSm
|
|
327
|
+
}
|
|
328
|
+
// werewolf:property=root.height
|
|
329
|
+
val rootHeight: Dp = when (size) {
|
|
330
|
+
// werewolf:size=sm
|
|
331
|
+
WerewolfButtonSize.Sm -> t.sizeElementSm
|
|
332
|
+
// werewolf:size=md
|
|
333
|
+
WerewolfButtonSize.Md -> t.sizeElementMd
|
|
334
|
+
// werewolf:size=lg
|
|
335
|
+
WerewolfButtonSize.Lg -> t.sizeElementLg
|
|
336
|
+
// werewolf:size=xl
|
|
337
|
+
WerewolfButtonSize.Xl -> t.sizeElementXl
|
|
338
|
+
}
|
|
339
|
+
// werewolf:property=root.outline-color
|
|
340
|
+
val rootOutlineColor: Color? = run {
|
|
341
|
+
// werewolf:state=focus-visible
|
|
342
|
+
if (focusVisible) {
|
|
343
|
+
return@run t.colorFocusRing
|
|
344
|
+
}
|
|
345
|
+
// werewolf:state=default
|
|
346
|
+
null
|
|
347
|
+
}
|
|
348
|
+
// werewolf:property=root.outline-offset
|
|
349
|
+
val rootOutlineOffset: Dp? = run {
|
|
350
|
+
// werewolf:state=focus-visible
|
|
351
|
+
if (focusVisible) {
|
|
352
|
+
return@run t.outlineOffsetFocusRing
|
|
353
|
+
}
|
|
354
|
+
// werewolf:state=default
|
|
355
|
+
null
|
|
356
|
+
}
|
|
357
|
+
// werewolf:property=root.outline-width
|
|
358
|
+
val rootOutlineWidth: Dp? = run {
|
|
359
|
+
// werewolf:state=focus-visible
|
|
360
|
+
if (focusVisible) {
|
|
361
|
+
return@run t.outlineWidthFocusRing
|
|
362
|
+
}
|
|
363
|
+
// werewolf:state=default
|
|
364
|
+
null
|
|
365
|
+
}
|
|
366
|
+
// werewolf:property=root.overlay
|
|
367
|
+
val rootOverlay: Color? = when (variant) {
|
|
368
|
+
// werewolf:variant=solid
|
|
369
|
+
WerewolfButtonVariant.Solid -> run {
|
|
370
|
+
// werewolf:state=pressed
|
|
371
|
+
if (pressed) {
|
|
372
|
+
return@run t.colorOverlayPressedOnAccent
|
|
373
|
+
}
|
|
374
|
+
// werewolf:state=hover
|
|
375
|
+
if (hovered) {
|
|
376
|
+
return@run t.colorOverlayHoverOnAccent
|
|
377
|
+
}
|
|
378
|
+
// werewolf:state=default
|
|
379
|
+
null
|
|
380
|
+
}
|
|
381
|
+
// werewolf:variant=secondary
|
|
382
|
+
WerewolfButtonVariant.Secondary -> run {
|
|
383
|
+
// werewolf:state=pressed
|
|
384
|
+
if (pressed) {
|
|
385
|
+
return@run t.colorOverlayPressed
|
|
386
|
+
}
|
|
387
|
+
// werewolf:state=hover
|
|
388
|
+
if (hovered) {
|
|
389
|
+
return@run t.colorOverlayHover
|
|
390
|
+
}
|
|
391
|
+
// werewolf:state=default
|
|
392
|
+
null
|
|
393
|
+
}
|
|
394
|
+
// werewolf:variant=soft
|
|
395
|
+
WerewolfButtonVariant.Soft -> run {
|
|
396
|
+
// werewolf:state=pressed
|
|
397
|
+
if (pressed) {
|
|
398
|
+
return@run t.colorOverlayPressed
|
|
399
|
+
}
|
|
400
|
+
// werewolf:state=hover
|
|
401
|
+
if (hovered) {
|
|
402
|
+
return@run t.colorOverlayHover
|
|
403
|
+
}
|
|
404
|
+
// werewolf:state=default
|
|
405
|
+
null
|
|
406
|
+
}
|
|
407
|
+
// werewolf:variant=ghost
|
|
408
|
+
WerewolfButtonVariant.Ghost -> run {
|
|
409
|
+
// werewolf:state=pressed
|
|
410
|
+
if (pressed) {
|
|
411
|
+
return@run t.colorOverlayPressed
|
|
412
|
+
}
|
|
413
|
+
// werewolf:state=hover
|
|
414
|
+
if (hovered) {
|
|
415
|
+
return@run t.colorOverlayHover
|
|
416
|
+
}
|
|
417
|
+
// werewolf:state=default
|
|
418
|
+
null
|
|
419
|
+
}
|
|
420
|
+
// werewolf:variant=link
|
|
421
|
+
WerewolfButtonVariant.Link -> null
|
|
422
|
+
// werewolf:variant=destructive
|
|
423
|
+
WerewolfButtonVariant.Destructive -> run {
|
|
424
|
+
// werewolf:state=pressed
|
|
425
|
+
if (pressed) {
|
|
426
|
+
return@run t.colorOverlayPressedOnDanger
|
|
427
|
+
}
|
|
428
|
+
// werewolf:state=hover
|
|
429
|
+
if (hovered) {
|
|
430
|
+
return@run t.colorOverlayHoverOnDanger
|
|
431
|
+
}
|
|
432
|
+
// werewolf:state=default
|
|
433
|
+
null
|
|
434
|
+
}
|
|
435
|
+
// werewolf:variant=destructive-soft
|
|
436
|
+
WerewolfButtonVariant.DestructiveSoft -> run {
|
|
437
|
+
// werewolf:state=pressed
|
|
438
|
+
if (pressed) {
|
|
439
|
+
return@run t.colorOverlayPressed
|
|
440
|
+
}
|
|
441
|
+
// werewolf:state=hover
|
|
442
|
+
if (hovered) {
|
|
443
|
+
return@run t.colorOverlayHover
|
|
444
|
+
}
|
|
445
|
+
// werewolf:state=default
|
|
446
|
+
null
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
// werewolf:property=root.padding-inline
|
|
450
|
+
val rootPaddingInline: Dp = when (size) {
|
|
451
|
+
// werewolf:size=sm
|
|
452
|
+
WerewolfButtonSize.Sm -> t.spacingMd
|
|
453
|
+
// werewolf:size=md
|
|
454
|
+
WerewolfButtonSize.Md -> t.spacingMd
|
|
455
|
+
// werewolf:size=lg
|
|
456
|
+
WerewolfButtonSize.Lg -> t.spacingLg
|
|
457
|
+
// werewolf:size=xl
|
|
458
|
+
WerewolfButtonSize.Xl -> t.spacingXl
|
|
459
|
+
}
|
|
460
|
+
// werewolf:property=root.scale
|
|
461
|
+
val rootScale: Float? = run {
|
|
462
|
+
// werewolf:state=pressed
|
|
463
|
+
if (pressed) {
|
|
464
|
+
return@run t.scalePressed
|
|
465
|
+
}
|
|
466
|
+
// werewolf:state=default
|
|
467
|
+
null
|
|
468
|
+
}
|
|
469
|
+
// werewolf:property=root.transition-duration
|
|
470
|
+
val rootTransitionDuration = t.durationFastMs
|
|
471
|
+
// werewolf:property=root.transition-timing-function
|
|
472
|
+
val rootTransitionTimingFunction = t.easeStandard
|
|
473
|
+
// werewolf:property=icon.color
|
|
474
|
+
val iconColor: Color = when (variant) {
|
|
475
|
+
// werewolf:variant=solid
|
|
476
|
+
WerewolfButtonVariant.Solid -> run {
|
|
477
|
+
// werewolf:state=disabled
|
|
478
|
+
if (!enabled) {
|
|
479
|
+
return@run t.colorIconDisabled
|
|
480
|
+
}
|
|
481
|
+
// werewolf:state=default
|
|
482
|
+
t.colorIconOnAccent
|
|
483
|
+
}
|
|
484
|
+
// werewolf:variant=secondary
|
|
485
|
+
WerewolfButtonVariant.Secondary -> run {
|
|
486
|
+
// werewolf:state=disabled
|
|
487
|
+
if (!enabled) {
|
|
488
|
+
return@run t.colorIconDisabled
|
|
489
|
+
}
|
|
490
|
+
// werewolf:state=default
|
|
491
|
+
t.colorIconSecondary
|
|
492
|
+
}
|
|
493
|
+
// werewolf:variant=soft
|
|
494
|
+
WerewolfButtonVariant.Soft -> run {
|
|
495
|
+
// werewolf:state=disabled
|
|
496
|
+
if (!enabled) {
|
|
497
|
+
return@run t.colorIconDisabled
|
|
498
|
+
}
|
|
499
|
+
// werewolf:state=default
|
|
500
|
+
t.colorTextOnMuted
|
|
501
|
+
}
|
|
502
|
+
// werewolf:variant=ghost
|
|
503
|
+
WerewolfButtonVariant.Ghost -> run {
|
|
504
|
+
// werewolf:state=disabled
|
|
505
|
+
if (!enabled) {
|
|
506
|
+
return@run t.colorIconDisabled
|
|
507
|
+
}
|
|
508
|
+
// werewolf:state=hover
|
|
509
|
+
if (hovered) {
|
|
510
|
+
return@run t.colorIconPrimary
|
|
511
|
+
}
|
|
512
|
+
// werewolf:state=default
|
|
513
|
+
t.colorIconSecondary
|
|
514
|
+
}
|
|
515
|
+
// werewolf:variant=link
|
|
516
|
+
WerewolfButtonVariant.Link -> run {
|
|
517
|
+
// werewolf:state=disabled
|
|
518
|
+
if (!enabled) {
|
|
519
|
+
return@run t.colorIconDisabled
|
|
520
|
+
}
|
|
521
|
+
// werewolf:state=default
|
|
522
|
+
t.colorIconAccent
|
|
523
|
+
}
|
|
524
|
+
// werewolf:variant=destructive
|
|
525
|
+
WerewolfButtonVariant.Destructive -> run {
|
|
526
|
+
// werewolf:state=disabled
|
|
527
|
+
if (!enabled) {
|
|
528
|
+
return@run t.colorIconDisabled
|
|
529
|
+
}
|
|
530
|
+
// werewolf:state=default
|
|
531
|
+
t.colorIconOnDanger
|
|
532
|
+
}
|
|
533
|
+
// werewolf:variant=destructive-soft
|
|
534
|
+
WerewolfButtonVariant.DestructiveSoft -> run {
|
|
535
|
+
// werewolf:state=disabled
|
|
536
|
+
if (!enabled) {
|
|
537
|
+
return@run t.colorIconDisabled
|
|
538
|
+
}
|
|
539
|
+
// werewolf:state=default
|
|
540
|
+
t.colorTextDanger
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
// werewolf:property=icon.height
|
|
544
|
+
val iconHeight: Dp = when (size) {
|
|
545
|
+
// werewolf:size=sm
|
|
546
|
+
WerewolfButtonSize.Sm -> t.sizeIconMd
|
|
547
|
+
// werewolf:size=md
|
|
548
|
+
WerewolfButtonSize.Md -> t.sizeIconMd
|
|
549
|
+
// werewolf:size=lg
|
|
550
|
+
WerewolfButtonSize.Lg -> t.sizeIconMd
|
|
551
|
+
// werewolf:size=xl
|
|
552
|
+
WerewolfButtonSize.Xl -> t.sizeIconLg
|
|
553
|
+
}
|
|
554
|
+
// werewolf:property=icon.width
|
|
555
|
+
val iconWidth: Dp = when (size) {
|
|
556
|
+
// werewolf:size=sm
|
|
557
|
+
WerewolfButtonSize.Sm -> t.sizeIconMd
|
|
558
|
+
// werewolf:size=md
|
|
559
|
+
WerewolfButtonSize.Md -> t.sizeIconMd
|
|
560
|
+
// werewolf:size=lg
|
|
561
|
+
WerewolfButtonSize.Lg -> t.sizeIconMd
|
|
562
|
+
// werewolf:size=xl
|
|
563
|
+
WerewolfButtonSize.Xl -> t.sizeIconLg
|
|
564
|
+
}
|
|
565
|
+
val rootShape = RoundedCornerShape(rootBorderRadius)
|
|
566
|
+
val animatedRootBackgroundColor by animateColorAsState(
|
|
567
|
+
targetValue = rootBackgroundColor ?: Color.Transparent,
|
|
568
|
+
animationSpec = if (reduced) snap() else tween(durationMillis = rootTransitionDuration, easing = rootTransitionTimingFunction.toCubicBezierEasing()),
|
|
569
|
+
label = "rootBackgroundColor",
|
|
570
|
+
)
|
|
571
|
+
val animatedRootColor by animateColorAsState(
|
|
572
|
+
targetValue = rootColor,
|
|
573
|
+
animationSpec = if (reduced) snap() else tween(durationMillis = rootTransitionDuration, easing = rootTransitionTimingFunction.toCubicBezierEasing()),
|
|
574
|
+
label = "rootColor",
|
|
575
|
+
)
|
|
576
|
+
val animatedIconColor by animateColorAsState(
|
|
577
|
+
targetValue = iconColor,
|
|
578
|
+
animationSpec = if (reduced) snap() else tween(durationMillis = rootTransitionDuration, easing = rootTransitionTimingFunction.toCubicBezierEasing()),
|
|
579
|
+
label = "iconColor",
|
|
580
|
+
)
|
|
581
|
+
val scale by animateFloatAsState(
|
|
582
|
+
targetValue = if (reduced || rootScale == null) 1f else rootScale,
|
|
583
|
+
animationSpec = if (reduced) snap() else tween(durationMillis = rootTransitionDuration, easing = rootTransitionTimingFunction.toCubicBezierEasing()),
|
|
584
|
+
label = "scale",
|
|
585
|
+
)
|
|
586
|
+
val rootTextStyle = LocalWerewolfFonts.current.textStyle(
|
|
587
|
+
when (rootFontFamily) {
|
|
588
|
+
t.fontFamilySans -> WerewolfFontRole.Sans
|
|
589
|
+
else -> WerewolfFontRole.Mono
|
|
590
|
+
},
|
|
591
|
+
rootFontSize,
|
|
592
|
+
rootFontWeight,
|
|
593
|
+
TextUnit.Unspecified,
|
|
594
|
+
)
|
|
595
|
+
CompositionLocalProvider(
|
|
596
|
+
LocalWerewolfContentColor provides animatedRootColor,
|
|
597
|
+
LocalWerewolfTextStyle provides rootTextStyle,
|
|
598
|
+
) {
|
|
599
|
+
Row(
|
|
600
|
+
modifier = modifier
|
|
601
|
+
.semantics {
|
|
602
|
+
role = Role.Button
|
|
603
|
+
if (accessibilityLabel.isNotEmpty()) contentDescription = accessibilityLabel
|
|
604
|
+
if (loading) stateDescription = "Busy"
|
|
605
|
+
}
|
|
606
|
+
.werewolfHitArea()
|
|
607
|
+
.clickable(
|
|
608
|
+
interactionSource = interactionSource,
|
|
609
|
+
indication = null,
|
|
610
|
+
enabled = enabled,
|
|
611
|
+
onClick = { if (!loading) onClick() },
|
|
612
|
+
)
|
|
613
|
+
.hoverable(interactionSource = interactionSource)
|
|
614
|
+
.focusable(interactionSource = interactionSource)
|
|
615
|
+
.graphicsLayer {
|
|
616
|
+
scaleX = scale
|
|
617
|
+
scaleY = scale
|
|
618
|
+
}
|
|
619
|
+
.height(rootHeight)
|
|
620
|
+
.then(if (iconOnly) Modifier.width(rootHeight) else Modifier)
|
|
621
|
+
.then(if (fullWidth) Modifier.fillMaxWidth() else Modifier)
|
|
622
|
+
.background(animatedRootBackgroundColor, rootShape)
|
|
623
|
+
.border(rootBorderWidth, rootBorderColor ?: Color.Transparent, rootShape)
|
|
624
|
+
.padding(start = if (iconOnly) 0.dp else rootPaddingInline, end = if (iconOnly) 0.dp else rootPaddingInline)
|
|
625
|
+
.werewolfShadow(rootBoxShadow)
|
|
626
|
+
.werewolfOverlay(rootOverlay ?: Color.Transparent, rootShape, rootOverlay != null)
|
|
627
|
+
.werewolfFocusRing(
|
|
628
|
+
rootOutlineColor != null,
|
|
629
|
+
rootShape,
|
|
630
|
+
),
|
|
631
|
+
horizontalArrangement = Arrangement.spacedBy(rootGap, Alignment.CenterHorizontally),
|
|
632
|
+
verticalAlignment = Alignment.CenterVertically,
|
|
633
|
+
) {
|
|
634
|
+
if (loading) {
|
|
635
|
+
CompositionLocalProvider(LocalWerewolfContentColor provides iconColor) {
|
|
636
|
+
WerewolfSpinnerArc(size = iconWidth)
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
if ((leadingIcon != null) && !loading) {
|
|
640
|
+
Box(
|
|
641
|
+
modifier = Modifier
|
|
642
|
+
.width(iconWidth)
|
|
643
|
+
.height(iconHeight),
|
|
644
|
+
) {
|
|
645
|
+
CompositionLocalProvider(LocalWerewolfContentColor provides iconColor) {
|
|
646
|
+
leadingIcon()
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
if (!(iconOnly && loading)) {
|
|
651
|
+
Box {
|
|
652
|
+
val labelAlpha by animateFloatAsState(
|
|
653
|
+
targetValue = if (loading && loadingText.isNotEmpty()) 0f else 1f,
|
|
654
|
+
animationSpec = if (reduced) snap() else tween(durationMillis = rootTransitionDuration, easing = rootTransitionTimingFunction.toCubicBezierEasing()),
|
|
655
|
+
label = "labelAlpha",
|
|
656
|
+
)
|
|
657
|
+
Box(
|
|
658
|
+
modifier = Modifier
|
|
659
|
+
.graphicsLayer { alpha = labelAlpha }
|
|
660
|
+
.semantics { if (loading && loadingText.isNotEmpty()) hideFromAccessibility() },
|
|
661
|
+
) {
|
|
662
|
+
label()
|
|
663
|
+
}
|
|
664
|
+
if (loadingText.isNotEmpty()) {
|
|
665
|
+
val loadingAlpha by animateFloatAsState(
|
|
666
|
+
targetValue = if (loading) 1f else 0f,
|
|
667
|
+
animationSpec = if (reduced) snap() else tween(durationMillis = rootTransitionDuration, easing = rootTransitionTimingFunction.toCubicBezierEasing()),
|
|
668
|
+
label = "loadingAlpha",
|
|
669
|
+
)
|
|
670
|
+
WerewolfText(
|
|
671
|
+
text = loadingText,
|
|
672
|
+
modifier = Modifier
|
|
673
|
+
.graphicsLayer { alpha = loadingAlpha }
|
|
674
|
+
.semantics { if (!loading) hideFromAccessibility() },
|
|
675
|
+
)
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
if (trailingIcon != null) {
|
|
680
|
+
Box(
|
|
681
|
+
modifier = Modifier
|
|
682
|
+
.width(iconWidth)
|
|
683
|
+
.height(iconHeight),
|
|
684
|
+
) {
|
|
685
|
+
CompositionLocalProvider(LocalWerewolfContentColor provides iconColor) {
|
|
686
|
+
trailingIcon()
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|