werewolf-ui 0.1.0-beta.2 → 0.1.0-beta.4

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.
Files changed (210) hide show
  1. package/README.md +15 -5
  2. package/data/manifest.json +16077 -6044
  3. package/data/native/android/WerewolfAccordion.kt +256 -0
  4. package/data/native/android/WerewolfAlert.kt +4 -4
  5. package/data/native/android/WerewolfAlertDialog.kt +156 -0
  6. package/data/native/android/WerewolfAttachmentPreview.kt +273 -0
  7. package/data/native/android/WerewolfAvatar.kt +393 -0
  8. package/data/native/android/WerewolfAvatarStack.kt +178 -0
  9. package/data/native/android/WerewolfBackdropBlur.kt +89 -0
  10. package/data/native/android/WerewolfBadge.kt +71 -3
  11. package/data/native/android/WerewolfBottomNav.kt +354 -0
  12. package/data/native/android/WerewolfBreadcrumb.kt +22 -0
  13. package/data/native/android/WerewolfBreadcrumbRuntime.kt +177 -0
  14. package/data/native/android/WerewolfButton.kt +12 -3
  15. package/data/native/android/WerewolfButtonGroup.kt +54 -0
  16. package/data/native/android/WerewolfCalendar.kt +85 -0
  17. package/data/native/android/WerewolfCalendarGrid.kt +412 -0
  18. package/data/native/android/WerewolfCalendarMath.kt +252 -0
  19. package/data/native/android/WerewolfCard.kt +3 -3
  20. package/data/native/android/WerewolfCarousel.kt +177 -0
  21. package/data/native/android/WerewolfChart.kt +200 -0
  22. package/data/native/android/WerewolfChartAccessibility.kt +69 -0
  23. package/data/native/android/WerewolfChartFormat.kt +18 -0
  24. package/data/native/android/WerewolfChartGeometry.kt +397 -0
  25. package/data/native/android/WerewolfChartInteraction.kt +106 -0
  26. package/data/native/android/WerewolfChartModel.kt +238 -0
  27. package/data/native/android/WerewolfChartPalette.kt +34 -0
  28. package/data/native/android/WerewolfChatRuntime.kt +242 -0
  29. package/data/native/android/WerewolfCheckbox.kt +387 -0
  30. package/data/native/android/WerewolfChecklist.kt +249 -0
  31. package/data/native/android/WerewolfCodeBlock.kt +353 -0
  32. package/data/native/android/WerewolfColorPicker.kt +84 -0
  33. package/data/native/android/WerewolfColorPickerRuntime.kt +592 -0
  34. package/data/native/android/WerewolfCombobox.kt +371 -0
  35. package/data/native/android/WerewolfComposer.kt +300 -0
  36. package/data/native/android/WerewolfContextMenu.kt +26 -0
  37. package/data/native/android/WerewolfContextMenuRuntime.kt +116 -0
  38. package/data/native/android/WerewolfConversationList.kt +182 -0
  39. package/data/native/android/WerewolfCounter.kt +640 -0
  40. package/data/native/android/WerewolfDataTrend.kt +245 -0
  41. package/data/native/android/WerewolfDatePicker.kt +334 -0
  42. package/data/native/android/WerewolfDialog.kt +131 -0
  43. package/data/native/android/WerewolfDropdownMenu.kt +30 -0
  44. package/data/native/android/WerewolfEmojiData.kt +594 -0
  45. package/data/native/android/WerewolfEmojiPicker.kt +67 -0
  46. package/data/native/android/WerewolfEmojiPickerRuntime.kt +627 -0
  47. package/data/native/android/WerewolfEmptyState.kt +1 -1
  48. package/data/native/android/WerewolfField.kt +66 -0
  49. package/data/native/android/WerewolfGroupAvatar.kt +126 -0
  50. package/data/native/android/WerewolfIcons.kt +448 -1
  51. package/data/native/android/WerewolfImage.kt +82 -0
  52. package/data/native/android/WerewolfInput.kt +3 -3
  53. package/data/native/android/WerewolfKbd.kt +3 -3
  54. package/data/native/android/WerewolfLabel.kt +2 -2
  55. package/data/native/android/WerewolfLayers.kt +1173 -0
  56. package/data/native/android/WerewolfLink.kt +163 -0
  57. package/data/native/android/WerewolfList.kt +504 -0
  58. package/data/native/android/WerewolfListRuntime.kt +383 -0
  59. package/data/native/android/WerewolfMessageActions.kt +86 -0
  60. package/data/native/android/WerewolfMessageActionsRuntime.kt +568 -0
  61. package/data/native/android/WerewolfMessageBubble.kt +402 -0
  62. package/data/native/android/WerewolfMessageList.kt +133 -0
  63. package/data/native/android/WerewolfMetadata.kt +180 -0
  64. package/data/native/android/WerewolfMeter.kt +189 -0
  65. package/data/native/android/WerewolfModifiers.kt +309 -4
  66. package/data/native/android/WerewolfNumberInput.kt +665 -0
  67. package/data/native/android/WerewolfOtpInput.kt +246 -0
  68. package/data/native/android/WerewolfPageRuntime.kt +83 -0
  69. package/data/native/android/WerewolfPagination.kt +29 -0
  70. package/data/native/android/WerewolfPaginationRuntime.kt +245 -0
  71. package/data/native/android/WerewolfPlot.kt +1129 -0
  72. package/data/native/android/WerewolfPopover.kt +92 -0
  73. package/data/native/android/WerewolfProgress.kt +281 -0
  74. package/data/native/android/WerewolfRadioGroup.kt +382 -0
  75. package/data/native/android/WerewolfRangeMath.kt +80 -0
  76. package/data/native/android/WerewolfRating.kt +44 -0
  77. package/data/native/android/WerewolfRatingRuntime.kt +113 -0
  78. package/data/native/android/WerewolfSelect.kt +330 -0
  79. package/data/native/android/WerewolfSeparator.kt +1 -1
  80. package/data/native/android/WerewolfSheet.kt +204 -0
  81. package/data/native/android/WerewolfSkeleton.kt +4 -4
  82. package/data/native/android/WerewolfSlider.kt +214 -0
  83. package/data/native/android/WerewolfSliderRuntime.kt +307 -0
  84. package/data/native/android/WerewolfSortableList.kt +34 -0
  85. package/data/native/android/WerewolfSortableListRuntime.kt +232 -0
  86. package/data/native/android/WerewolfSpinner.kt +1 -1
  87. package/data/native/android/WerewolfStepper.kt +690 -0
  88. package/data/native/android/WerewolfSwitch.kt +9 -57
  89. package/data/native/android/WerewolfTable.kt +134 -0
  90. package/data/native/android/WerewolfTableRuntime.kt +55 -0
  91. package/data/native/android/WerewolfTabs.kt +591 -0
  92. package/data/native/android/WerewolfTextarea.kt +329 -0
  93. package/data/native/android/WerewolfTheme.kt +17 -3
  94. package/data/native/android/WerewolfTimeColumns.kt +333 -0
  95. package/data/native/android/WerewolfTimePicker.kt +319 -0
  96. package/data/native/android/WerewolfTimeline.kt +382 -0
  97. package/data/native/android/WerewolfToast.kt +226 -0
  98. package/data/native/android/WerewolfToaster.kt +281 -0
  99. package/data/native/android/WerewolfToggle.kt +395 -0
  100. package/data/native/android/WerewolfToggleGroup.kt +427 -0
  101. package/data/native/android/WerewolfToken.kt +1 -1
  102. package/data/native/android/WerewolfTokenizer.kt +54 -0
  103. package/data/native/android/WerewolfTokenizerRuntime.kt +221 -0
  104. package/data/native/android/WerewolfTooltip.kt +78 -0
  105. package/data/native/ios/WerewolfAccordion.swift +340 -0
  106. package/data/native/ios/WerewolfAlert.swift +3 -3
  107. package/data/native/ios/WerewolfAlertDialog.swift +187 -0
  108. package/data/native/ios/WerewolfAttachmentPreview.swift +323 -0
  109. package/data/native/ios/WerewolfAvatar.swift +552 -0
  110. package/data/native/ios/WerewolfAvatarStack.swift +214 -0
  111. package/data/native/ios/WerewolfBadge.swift +74 -22
  112. package/data/native/ios/WerewolfBottomNav.swift +463 -0
  113. package/data/native/ios/WerewolfBreadcrumb.swift +22 -0
  114. package/data/native/ios/WerewolfBreadcrumbRuntime.swift +96 -0
  115. package/data/native/ios/WerewolfButton.swift +22 -5
  116. package/data/native/ios/WerewolfButtonGroup.swift +62 -0
  117. package/data/native/ios/WerewolfCalendar.swift +98 -0
  118. package/data/native/ios/WerewolfCalendarGrid.swift +453 -0
  119. package/data/native/ios/WerewolfCalendarMath.swift +321 -0
  120. package/data/native/ios/WerewolfCard.swift +2 -2
  121. package/data/native/ios/WerewolfCarousel.swift +168 -0
  122. package/data/native/ios/WerewolfChart.swift +206 -0
  123. package/data/native/ios/WerewolfChartAccessibility.swift +59 -0
  124. package/data/native/ios/WerewolfChartFormat.swift +14 -0
  125. package/data/native/ios/WerewolfChartGeometry.swift +479 -0
  126. package/data/native/ios/WerewolfChartInteraction.swift +113 -0
  127. package/data/native/ios/WerewolfChartModel.swift +337 -0
  128. package/data/native/ios/WerewolfChartPalette.swift +37 -0
  129. package/data/native/ios/WerewolfChatRuntime.swift +216 -0
  130. package/data/native/ios/WerewolfCheckbox.swift +623 -0
  131. package/data/native/ios/WerewolfChecklist.swift +276 -0
  132. package/data/native/ios/WerewolfCodeBlock.swift +405 -0
  133. package/data/native/ios/WerewolfColorPicker.swift +136 -0
  134. package/data/native/ios/WerewolfColorPickerRuntime.swift +469 -0
  135. package/data/native/ios/WerewolfCombobox.swift +469 -0
  136. package/data/native/ios/WerewolfComposer.swift +269 -0
  137. package/data/native/ios/WerewolfContextMenu.swift +21 -0
  138. package/data/native/ios/WerewolfConversationList.swift +141 -0
  139. package/data/native/ios/WerewolfCounter.swift +770 -0
  140. package/data/native/ios/WerewolfDataTrend.swift +292 -0
  141. package/data/native/ios/WerewolfDatePicker.swift +388 -0
  142. package/data/native/ios/WerewolfDialog.swift +172 -0
  143. package/data/native/ios/WerewolfDropdownMenu.swift +35 -0
  144. package/data/native/ios/WerewolfEmojiData.swift +600 -0
  145. package/data/native/ios/WerewolfEmojiPicker.swift +74 -0
  146. package/data/native/ios/WerewolfEmojiPickerRuntime.swift +361 -0
  147. package/data/native/ios/WerewolfEmptyState.swift +1 -1
  148. package/data/native/ios/WerewolfField.swift +103 -0
  149. package/data/native/ios/WerewolfGroupAvatar.swift +165 -0
  150. package/data/native/ios/WerewolfIcons.swift +85 -1
  151. package/data/native/ios/WerewolfImage.swift +118 -0
  152. package/data/native/ios/WerewolfInput.swift +5 -3
  153. package/data/native/ios/WerewolfKbd.swift +2 -2
  154. package/data/native/ios/WerewolfLabel.swift +2 -2
  155. package/data/native/ios/WerewolfLayers.swift +929 -0
  156. package/data/native/ios/WerewolfLink.swift +188 -0
  157. package/data/native/ios/WerewolfList.swift +603 -0
  158. package/data/native/ios/WerewolfListRuntime.swift +414 -0
  159. package/data/native/ios/WerewolfMessageActions.swift +99 -0
  160. package/data/native/ios/WerewolfMessageActionsRuntime.swift +218 -0
  161. package/data/native/ios/WerewolfMessageBubble.swift +474 -0
  162. package/data/native/ios/WerewolfMessageList.swift +123 -0
  163. package/data/native/ios/WerewolfMetadata.swift +205 -0
  164. package/data/native/ios/WerewolfMeter.swift +186 -0
  165. package/data/native/ios/WerewolfModifiers.swift +205 -1
  166. package/data/native/ios/WerewolfNumberInput.swift +808 -0
  167. package/data/native/ios/WerewolfOtpInput.swift +326 -0
  168. package/data/native/ios/WerewolfPageRuntime.swift +98 -0
  169. package/data/native/ios/WerewolfPagination.swift +34 -0
  170. package/data/native/ios/WerewolfPaginationRuntime.swift +165 -0
  171. package/data/native/ios/WerewolfPlot.swift +1249 -0
  172. package/data/native/ios/WerewolfPopover.swift +132 -0
  173. package/data/native/ios/WerewolfProgress.swift +338 -0
  174. package/data/native/ios/WerewolfRadioGroup.swift +485 -0
  175. package/data/native/ios/WerewolfRangeMath.swift +87 -0
  176. package/data/native/ios/WerewolfRating.swift +52 -0
  177. package/data/native/ios/WerewolfRatingRuntime.swift +100 -0
  178. package/data/native/ios/WerewolfSelect.swift +420 -0
  179. package/data/native/ios/WerewolfSeparator.swift +1 -1
  180. package/data/native/ios/WerewolfSheet.swift +208 -0
  181. package/data/native/ios/WerewolfSkeleton.swift +3 -3
  182. package/data/native/ios/WerewolfSlider.swift +330 -0
  183. package/data/native/ios/WerewolfSliderRuntime.swift +260 -0
  184. package/data/native/ios/WerewolfSortableList.swift +40 -0
  185. package/data/native/ios/WerewolfSortableListRuntime.swift +192 -0
  186. package/data/native/ios/WerewolfSpinner.swift +1 -1
  187. package/data/native/ios/WerewolfStepper.swift +802 -0
  188. package/data/native/ios/WerewolfSwitch.swift +21 -78
  189. package/data/native/ios/WerewolfTable.swift +185 -0
  190. package/data/native/ios/WerewolfTableRuntime.swift +47 -0
  191. package/data/native/ios/WerewolfTabs.swift +758 -0
  192. package/data/native/ios/WerewolfTextarea.swift +405 -0
  193. package/data/native/ios/WerewolfTheme.swift +17 -2
  194. package/data/native/ios/WerewolfTimeColumns.swift +134 -0
  195. package/data/native/ios/WerewolfTimePicker.swift +365 -0
  196. package/data/native/ios/WerewolfTimeline.swift +526 -0
  197. package/data/native/ios/WerewolfToast.swift +280 -0
  198. package/data/native/ios/WerewolfToaster.swift +269 -0
  199. package/data/native/ios/WerewolfToggle.swift +647 -0
  200. package/data/native/ios/WerewolfToggleGroup.swift +511 -0
  201. package/data/native/ios/WerewolfToken.swift +1 -1
  202. package/data/native/ios/WerewolfTokenizer.swift +77 -0
  203. package/data/native/ios/WerewolfTokenizerRuntime.swift +214 -0
  204. package/data/native/ios/WerewolfTooltip.swift +106 -0
  205. package/dist/cli.mjs +8573 -672
  206. package/dist/core.mjs +8279 -566
  207. package/dist/lint.mjs +205 -21
  208. package/dist/paths.mjs +2 -1
  209. package/dist/project.mjs +56 -10
  210. package/package.json +1 -1
@@ -0,0 +1,273 @@
1
+ // Generated file, must not be edited by hand. Source: components/attachment-preview.spec.json (werewolf-ui 0.1.0-beta.4).
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.Image
9
+ import androidx.compose.foundation.background
10
+ import androidx.compose.foundation.border
11
+ import androidx.compose.foundation.clickable
12
+ import androidx.compose.foundation.layout.Arrangement
13
+ import androidx.compose.foundation.layout.Box
14
+ import androidx.compose.foundation.layout.Column
15
+ import androidx.compose.foundation.layout.Row
16
+ import androidx.compose.foundation.layout.fillMaxWidth
17
+ import androidx.compose.foundation.layout.padding
18
+ import androidx.compose.foundation.layout.size
19
+ import androidx.compose.foundation.layout.widthIn
20
+ import androidx.compose.foundation.text.BasicText
21
+ import androidx.compose.runtime.Composable
22
+ import androidx.compose.runtime.LaunchedEffect
23
+ import androidx.compose.runtime.getValue
24
+ import androidx.compose.runtime.mutableStateOf
25
+ import androidx.compose.runtime.remember
26
+ import androidx.compose.runtime.setValue
27
+ import androidx.compose.ui.Alignment
28
+ import androidx.compose.ui.Modifier
29
+ import androidx.compose.ui.draw.alpha
30
+ import androidx.compose.ui.draw.clip
31
+ import androidx.compose.ui.graphics.Color
32
+ import androidx.compose.ui.graphics.ColorFilter
33
+ import androidx.compose.ui.graphics.vector.ImageVector
34
+ import androidx.compose.ui.semantics.Role
35
+ import androidx.compose.ui.semantics.contentDescription
36
+ import androidx.compose.ui.semantics.semantics
37
+ import androidx.compose.ui.text.TextStyle
38
+ import androidx.compose.ui.text.style.TextOverflow
39
+ import androidx.compose.ui.unit.Dp
40
+ import androidx.compose.ui.unit.TextUnit
41
+ import dev.werewolfui.runtime.LocalWerewolf
42
+ import dev.werewolfui.runtime.LocalWerewolfFonts
43
+ import dev.werewolfui.runtime.LocalWerewolfIcons
44
+ import dev.werewolfui.runtime.LocalWerewolfTextStyle
45
+ import dev.werewolfui.runtime.WerewolfFontRole
46
+ import dev.werewolfui.runtime.rememberReduceMotion
47
+ import dev.werewolfui.runtime.toCubicBezierEasing
48
+ import dev.werewolfui.runtime.werewolfCornerShape
49
+ import dev.werewolfui.runtime.werewolfFontWeight
50
+ import dev.werewolfui.runtime.werewolfHitArea
51
+ import dev.werewolfui.tokens.WerewolfEasing
52
+
53
+
54
+ @Composable
55
+ fun WerewolfAttachmentPreview(
56
+ name: String,
57
+ modifier: Modifier = Modifier,
58
+ type: String? = null,
59
+ sizeLabel: String? = null,
60
+ thumbnail: (@Composable () -> Unit)? = null,
61
+ progress: Float? = null,
62
+ indeterminate: Boolean = false,
63
+ error: String? = null,
64
+ removeLabel: String = "Remove {name}",
65
+ uploadingLabel: String = "Uploading {name}",
66
+ onRemove: (() -> Unit)? = null,
67
+ onClick: (() -> Unit)? = null,
68
+ ) {
69
+ val t = LocalWerewolf.current
70
+ val fonts = LocalWerewolfFonts.current
71
+ val icons = LocalWerewolfIcons.current
72
+ val reduced = rememberReduceMotion()
73
+ val invalid = !error.isNullOrEmpty()
74
+ val loading = (progress != null || indeterminate) && !invalid
75
+ // werewolf:property=root.background-color
76
+ val rootBackgroundColor = t.colorBackgroundSurface
77
+ // werewolf:property=root.border-color
78
+ val rootBorderColor: Color = run {
79
+ // werewolf:state=invalid
80
+ if (invalid) {
81
+ return@run t.colorBorderDanger
82
+ }
83
+ // werewolf:state=default
84
+ t.colorBorder
85
+ }
86
+ // werewolf:property=root.border-radius
87
+ val rootBorderRadius = t.radiusContainer
88
+ // werewolf:property=root.border-width
89
+ val rootBorderWidth = t.borderWidth
90
+ // werewolf:property=root.font-family
91
+ val rootFontFamily = t.fontFamilySans
92
+ // werewolf:property=root.gap
93
+ val rootGap = t.spacingSm
94
+ // werewolf:property=root.padding
95
+ val rootPadding = t.spacingSm
96
+ // werewolf:property=root.transition-duration
97
+ val rootTransitionDuration = t.durationMediumMs
98
+ // werewolf:property=root.transition-timing-function
99
+ val rootTransitionTimingFunction = t.easeEnter
100
+ // werewolf:property=root.width
101
+ val rootWidth = t.spacing4xl * 4
102
+ // werewolf:property=thumbnail.background-color
103
+ val thumbnailBackgroundColor = t.colorBackgroundSunken
104
+ // werewolf:property=thumbnail.border-radius
105
+ val thumbnailBorderRadius = t.radiusInner
106
+ // werewolf:property=thumbnail.color
107
+ val thumbnailColor = t.colorIconSecondary
108
+ // werewolf:property=thumbnail.height
109
+ val thumbnailHeight = t.spacing2xl + t.spacingSm
110
+ // werewolf:property=thumbnail.width
111
+ val thumbnailWidth = t.spacing2xl + t.spacingSm
112
+ // werewolf:property=image.opacity
113
+ val imageOpacity: Float? = run {
114
+ // werewolf:state=loading
115
+ if (loading) {
116
+ return@run t.opacityPending
117
+ }
118
+ // werewolf:state=default
119
+ null
120
+ }
121
+ // werewolf:property=image.transition-timing-function
122
+ val imageTransitionTimingFunction = t.easeStandard
123
+ // werewolf:property=icon.height
124
+ val iconHeight = t.sizeIconMd
125
+ // werewolf:property=icon.width
126
+ val iconWidth = t.sizeIconMd
127
+ // werewolf:property=body.gap
128
+ val bodyGap = t.spacingXs
129
+ // werewolf:property=name.color
130
+ val nameColor = t.colorTextPrimary
131
+ // werewolf:property=name.font-size
132
+ val nameFontSize = t.fontSizeSm
133
+ // werewolf:property=name.font-weight
134
+ val nameFontWeight = t.fontWeightMedium
135
+ // werewolf:property=error.color
136
+ val errorColor = t.colorTextDanger
137
+ // werewolf:property=error.font-size
138
+ val errorFontSize = t.fontSizeXs
139
+ // werewolf:property=meta.color
140
+ val metaColor = t.colorTextSecondary
141
+ // werewolf:property=meta.font-size
142
+ val metaFontSize = t.fontSizeXs
143
+ // werewolf:property=remove.height
144
+ val removeHeight = t.sizeIconSm
145
+ // werewolf:property=remove.width
146
+ val removeWidth = t.sizeIconSm
147
+ val rootShape = werewolfCornerShape(rootBorderRadius)
148
+ val thumbnailShape = werewolfCornerShape(thumbnailBorderRadius)
149
+ var appeared by remember { mutableStateOf(false) }
150
+ LaunchedEffect(Unit) { appeared = true }
151
+ val enterDuration = rootTransitionDuration ?: t.durationMediumMs
152
+ val enterEasing = (rootTransitionTimingFunction ?: t.easeEnter).toCubicBezierEasing()
153
+ val tileAlpha by animateFloatAsState(
154
+ targetValue = if (appeared) 1f else 0f,
155
+ animationSpec = if (reduced) snap() else tween(durationMillis = enterDuration, easing = enterEasing),
156
+ label = "attachment-preview-enter",
157
+ )
158
+ val animatedBorderColor by animateColorAsState(
159
+ targetValue = rootBorderColor ?: t.colorBorder,
160
+ animationSpec = if (reduced) snap() else tween(durationMillis = enterDuration, easing = enterEasing),
161
+ label = "attachment-preview-border",
162
+ )
163
+ val animatedImageAlpha by animateFloatAsState(
164
+ targetValue = imageOpacity ?: 1f,
165
+ animationSpec = if (reduced) snap() else tween(durationMillis = enterDuration, easing = (imageTransitionTimingFunction ?: t.easeStandard).toCubicBezierEasing()),
166
+ label = "attachment-preview-image-opacity",
167
+ )
168
+ val resolvedRemoveLabel = removeLabel.replace("{name}", name)
169
+ val resolvedUploadingLabel = uploadingLabel.replace("{name}", name)
170
+ val nameStyle = LocalWerewolfTextStyle.current.merge(
171
+ TextStyle(
172
+ color = nameColor ?: t.colorTextPrimary,
173
+ fontFamily = fonts.resolve(WerewolfFontRole.Sans),
174
+ fontSize = nameFontSize ?: t.fontSizeSm,
175
+ fontWeight = werewolfFontWeight(nameFontWeight ?: t.fontWeightMedium),
176
+ )
177
+ )
178
+ val metaStyle = LocalWerewolfTextStyle.current.merge(
179
+ TextStyle(
180
+ color = metaColor ?: t.colorTextSecondary,
181
+ fontFamily = fonts.resolve(WerewolfFontRole.Sans),
182
+ fontSize = metaFontSize ?: t.fontSizeXs,
183
+ )
184
+ )
185
+ val errorStyle = LocalWerewolfTextStyle.current.merge(
186
+ TextStyle(
187
+ color = errorColor ?: t.colorTextDanger,
188
+ fontFamily = fonts.resolve(WerewolfFontRole.Sans),
189
+ fontSize = errorFontSize ?: t.fontSizeXs,
190
+ )
191
+ )
192
+ val tileModifier = modifier
193
+ .widthIn(max = rootWidth ?: (t.spacing4xl * (1 + 1 + 1 + 1)))
194
+ .fillMaxWidth()
195
+ .alpha(tileAlpha)
196
+ .clip(rootShape)
197
+ .background(rootBackgroundColor ?: t.colorBackgroundSurface, rootShape)
198
+ .border(rootBorderWidth ?: t.borderWidth, animatedBorderColor, rootShape)
199
+ .then(if (onClick != null) Modifier.werewolfHitArea().clickable(role = Role.Button, onClick = onClick) else Modifier)
200
+ .padding(rootPadding ?: t.spacingSm)
201
+ Row(
202
+ modifier = tileModifier,
203
+ verticalAlignment = Alignment.CenterVertically,
204
+ horizontalArrangement = Arrangement.spacedBy(rootGap ?: t.spacingSm),
205
+ ) {
206
+ Box(
207
+ modifier = Modifier
208
+ .size(thumbnailWidth ?: (t.spacing2xl + t.spacingSm), thumbnailHeight ?: (t.spacing2xl + t.spacingSm))
209
+ .clip(thumbnailShape)
210
+ .background(thumbnailBackgroundColor ?: t.colorBackgroundSunken),
211
+ contentAlignment = Alignment.Center,
212
+ ) {
213
+ if (thumbnail != null) {
214
+ Box(modifier = Modifier.alpha(animatedImageAlpha)) {
215
+ thumbnail()
216
+ }
217
+ } else {
218
+ Image(
219
+ imageVector = attachmentPreviewIconFor(icons, type, name),
220
+ contentDescription = null,
221
+ colorFilter = ColorFilter.tint(thumbnailColor ?: t.colorIconSecondary),
222
+ modifier = Modifier.size(iconWidth ?: t.sizeIconMd, iconHeight ?: t.sizeIconMd),
223
+ )
224
+ }
225
+ }
226
+ Column(
227
+ modifier = Modifier.weight(1f),
228
+ verticalArrangement = Arrangement.spacedBy(bodyGap ?: t.spacingXs),
229
+ ) {
230
+ BasicText(text = name, style = nameStyle, maxLines = 1, overflow = TextOverflow.Ellipsis)
231
+ when {
232
+ invalid && error != null -> BasicText(text = error, style = errorStyle, maxLines = 1, overflow = TextOverflow.Ellipsis)
233
+ loading -> WerewolfProgress(
234
+ value = if (indeterminate) null else progress,
235
+ size = WerewolfProgressSize.Sm,
236
+ variant = WerewolfProgressVariant.Bar,
237
+ modifier = Modifier.fillMaxWidth().semantics { contentDescription = resolvedUploadingLabel },
238
+ )
239
+ !sizeLabel.isNullOrEmpty() -> BasicText(text = sizeLabel, style = metaStyle, maxLines = 1, overflow = TextOverflow.Ellipsis)
240
+ }
241
+ }
242
+ if (onRemove != null) {
243
+ WerewolfButton(
244
+ onClick = onRemove,
245
+ iconOnly = true,
246
+ accessibilityLabel = resolvedRemoveLabel,
247
+ size = WerewolfButtonSize.Sm,
248
+ variant = WerewolfButtonVariant.Ghost,
249
+ ) {
250
+ Image(
251
+ imageVector = icons.x,
252
+ contentDescription = null,
253
+ colorFilter = ColorFilter.tint(LocalWerewolfTextStyle.current.color),
254
+ modifier = Modifier.size(removeWidth ?: t.sizeIconSm, removeHeight ?: t.sizeIconSm),
255
+ )
256
+ }
257
+ }
258
+ }
259
+ }
260
+
261
+ private fun attachmentPreviewIconFor(icons: dev.werewolfui.runtime.WerewolfIcons, type: String?, name: String): ImageVector {
262
+ val mime = (type ?: "").lowercase()
263
+ val extension = name.lowercase().substringAfterLast('.', "")
264
+ return when {
265
+ mime.startsWith("image/") -> icons.photo
266
+ mime.startsWith("video/") -> icons.video
267
+ mime.startsWith("audio/") -> icons.music
268
+ mime == "application/pdf" || extension == "pdf" -> icons.filePdf
269
+ mime.contains("zip") || mime.contains("compressed") || mime.contains("tar") || mime.contains("gzip") || extension in setOf("zip", "gz", "tar", "rar", "7z") -> icons.fileZip
270
+ mime.startsWith("text/") || extension in setOf("txt", "md", "csv", "json", "doc", "docx") -> icons.fileText
271
+ else -> icons.file
272
+ }
273
+ }
@@ -0,0 +1,393 @@
1
+ // Generated file, must not be edited by hand. Source: components/avatar.spec.json (werewolf-ui 0.1.0-beta.4).
2
+ package dev.werewolfui
3
+
4
+ import androidx.compose.foundation.background
5
+ import androidx.compose.foundation.layout.Box
6
+ import androidx.compose.foundation.layout.height
7
+ import androidx.compose.foundation.layout.width
8
+ import androidx.compose.runtime.Composable
9
+ import androidx.compose.runtime.CompositionLocalProvider
10
+ import androidx.compose.ui.Alignment
11
+ import androidx.compose.ui.Modifier
12
+ import androidx.compose.ui.draw.clip
13
+ import androidx.compose.ui.graphics.Color
14
+ import androidx.compose.ui.semantics.Role
15
+ import androidx.compose.ui.semantics.contentDescription
16
+ import androidx.compose.ui.semantics.hideFromAccessibility
17
+ import androidx.compose.ui.semantics.role
18
+ import androidx.compose.ui.semantics.semantics
19
+ import androidx.compose.ui.unit.Dp
20
+ import androidx.compose.ui.unit.TextUnit
21
+ import dev.werewolfui.runtime.LocalWerewolf
22
+ import dev.werewolfui.runtime.LocalWerewolfContentColor
23
+ import dev.werewolfui.runtime.LocalWerewolfFonts
24
+ import dev.werewolfui.runtime.LocalWerewolfTextStyle
25
+ import dev.werewolfui.runtime.WerewolfFontRole
26
+ import dev.werewolfui.runtime.werewolfCornerShape
27
+ import dev.werewolfui.tokens.WerewolfEasing
28
+
29
+ enum class WerewolfAvatarColor {
30
+ Gray,
31
+ Red,
32
+ Orange,
33
+ Yellow,
34
+ Green,
35
+ Teal,
36
+ Blue,
37
+ Purple,
38
+ Pink,
39
+ }
40
+
41
+ enum class WerewolfAvatarShape {
42
+ Circle,
43
+ Square,
44
+ }
45
+
46
+ enum class WerewolfAvatarSize {
47
+ Xs,
48
+ Sm,
49
+ Md,
50
+ Lg,
51
+ Xl,
52
+ }
53
+
54
+ enum class WerewolfAvatarVariant {
55
+ Soft,
56
+ Solid,
57
+ }
58
+
59
+ @Composable
60
+ fun WerewolfAvatar(
61
+ alt: String,
62
+ modifier: Modifier = Modifier,
63
+ color: WerewolfAvatarColor = WerewolfAvatarColor.Gray,
64
+ shape: WerewolfAvatarShape = WerewolfAvatarShape.Circle,
65
+ size: WerewolfAvatarSize = WerewolfAvatarSize.Md,
66
+ variant: WerewolfAvatarVariant = WerewolfAvatarVariant.Soft,
67
+ icon: (@Composable () -> Unit)? = null,
68
+ image: (@Composable () -> Unit)? = null,
69
+ fallback: @Composable () -> Unit,
70
+ ) {
71
+ val t = LocalWerewolf.current
72
+ // werewolf:property=root.background-color
73
+ val rootBackgroundColor: Color = when (color) {
74
+ // werewolf:color=gray
75
+ WerewolfAvatarColor.Gray -> when (variant) {
76
+ // werewolf:variant=soft
77
+ WerewolfAvatarVariant.Soft -> t.colorBackgroundGray
78
+ // werewolf:variant=solid
79
+ WerewolfAvatarVariant.Solid -> t.colorGray
80
+ }
81
+ // werewolf:color=red
82
+ WerewolfAvatarColor.Red -> when (variant) {
83
+ // werewolf:variant=soft
84
+ WerewolfAvatarVariant.Soft -> t.colorBackgroundRed
85
+ // werewolf:variant=solid
86
+ WerewolfAvatarVariant.Solid -> t.colorRed
87
+ }
88
+ // werewolf:color=orange
89
+ WerewolfAvatarColor.Orange -> when (variant) {
90
+ // werewolf:variant=soft
91
+ WerewolfAvatarVariant.Soft -> t.colorBackgroundOrange
92
+ // werewolf:variant=solid
93
+ WerewolfAvatarVariant.Solid -> t.colorOrange
94
+ }
95
+ // werewolf:color=yellow
96
+ WerewolfAvatarColor.Yellow -> when (variant) {
97
+ // werewolf:variant=soft
98
+ WerewolfAvatarVariant.Soft -> t.colorBackgroundYellow
99
+ // werewolf:variant=solid
100
+ WerewolfAvatarVariant.Solid -> t.colorYellow
101
+ }
102
+ // werewolf:color=green
103
+ WerewolfAvatarColor.Green -> when (variant) {
104
+ // werewolf:variant=soft
105
+ WerewolfAvatarVariant.Soft -> t.colorBackgroundGreen
106
+ // werewolf:variant=solid
107
+ WerewolfAvatarVariant.Solid -> t.colorGreen
108
+ }
109
+ // werewolf:color=teal
110
+ WerewolfAvatarColor.Teal -> when (variant) {
111
+ // werewolf:variant=soft
112
+ WerewolfAvatarVariant.Soft -> t.colorBackgroundTeal
113
+ // werewolf:variant=solid
114
+ WerewolfAvatarVariant.Solid -> t.colorTeal
115
+ }
116
+ // werewolf:color=blue
117
+ WerewolfAvatarColor.Blue -> when (variant) {
118
+ // werewolf:variant=soft
119
+ WerewolfAvatarVariant.Soft -> t.colorBackgroundBlue
120
+ // werewolf:variant=solid
121
+ WerewolfAvatarVariant.Solid -> t.colorBlue
122
+ }
123
+ // werewolf:color=purple
124
+ WerewolfAvatarColor.Purple -> when (variant) {
125
+ // werewolf:variant=soft
126
+ WerewolfAvatarVariant.Soft -> t.colorBackgroundPurple
127
+ // werewolf:variant=solid
128
+ WerewolfAvatarVariant.Solid -> t.colorPurple
129
+ }
130
+ // werewolf:color=pink
131
+ WerewolfAvatarColor.Pink -> when (variant) {
132
+ // werewolf:variant=soft
133
+ WerewolfAvatarVariant.Soft -> t.colorBackgroundPink
134
+ // werewolf:variant=solid
135
+ WerewolfAvatarVariant.Solid -> t.colorPink
136
+ }
137
+ }
138
+ // werewolf:property=root.border-radius
139
+ val rootBorderRadius: Dp = when (shape) {
140
+ // werewolf:shape=circle
141
+ WerewolfAvatarShape.Circle -> t.radiusFull
142
+ // werewolf:shape=square
143
+ WerewolfAvatarShape.Square -> t.radiusElement
144
+ }
145
+ // werewolf:property=root.color
146
+ val rootColor: Color = when (color) {
147
+ // werewolf:color=gray
148
+ WerewolfAvatarColor.Gray -> when (variant) {
149
+ // werewolf:variant=soft
150
+ WerewolfAvatarVariant.Soft -> t.colorTextGray
151
+ // werewolf:variant=solid
152
+ WerewolfAvatarVariant.Solid -> t.colorTextOnGray
153
+ }
154
+ // werewolf:color=red
155
+ WerewolfAvatarColor.Red -> when (variant) {
156
+ // werewolf:variant=soft
157
+ WerewolfAvatarVariant.Soft -> t.colorTextRed
158
+ // werewolf:variant=solid
159
+ WerewolfAvatarVariant.Solid -> t.colorTextOnRed
160
+ }
161
+ // werewolf:color=orange
162
+ WerewolfAvatarColor.Orange -> when (variant) {
163
+ // werewolf:variant=soft
164
+ WerewolfAvatarVariant.Soft -> t.colorTextOrange
165
+ // werewolf:variant=solid
166
+ WerewolfAvatarVariant.Solid -> t.colorTextOnOrange
167
+ }
168
+ // werewolf:color=yellow
169
+ WerewolfAvatarColor.Yellow -> when (variant) {
170
+ // werewolf:variant=soft
171
+ WerewolfAvatarVariant.Soft -> t.colorTextYellow
172
+ // werewolf:variant=solid
173
+ WerewolfAvatarVariant.Solid -> t.colorTextOnYellow
174
+ }
175
+ // werewolf:color=green
176
+ WerewolfAvatarColor.Green -> when (variant) {
177
+ // werewolf:variant=soft
178
+ WerewolfAvatarVariant.Soft -> t.colorTextGreen
179
+ // werewolf:variant=solid
180
+ WerewolfAvatarVariant.Solid -> t.colorTextOnGreen
181
+ }
182
+ // werewolf:color=teal
183
+ WerewolfAvatarColor.Teal -> when (variant) {
184
+ // werewolf:variant=soft
185
+ WerewolfAvatarVariant.Soft -> t.colorTextTeal
186
+ // werewolf:variant=solid
187
+ WerewolfAvatarVariant.Solid -> t.colorTextOnTeal
188
+ }
189
+ // werewolf:color=blue
190
+ WerewolfAvatarColor.Blue -> when (variant) {
191
+ // werewolf:variant=soft
192
+ WerewolfAvatarVariant.Soft -> t.colorTextBlue
193
+ // werewolf:variant=solid
194
+ WerewolfAvatarVariant.Solid -> t.colorTextOnBlue
195
+ }
196
+ // werewolf:color=purple
197
+ WerewolfAvatarColor.Purple -> when (variant) {
198
+ // werewolf:variant=soft
199
+ WerewolfAvatarVariant.Soft -> t.colorTextPurple
200
+ // werewolf:variant=solid
201
+ WerewolfAvatarVariant.Solid -> t.colorTextOnPurple
202
+ }
203
+ // werewolf:color=pink
204
+ WerewolfAvatarColor.Pink -> when (variant) {
205
+ // werewolf:variant=soft
206
+ WerewolfAvatarVariant.Soft -> t.colorTextPink
207
+ // werewolf:variant=solid
208
+ WerewolfAvatarVariant.Solid -> t.colorTextOnPink
209
+ }
210
+ }
211
+ // werewolf:property=root.font-family
212
+ val rootFontFamily = t.fontFamilySans
213
+ // werewolf:property=root.font-size
214
+ val rootFontSize: TextUnit = when (size) {
215
+ // werewolf:size=xs
216
+ WerewolfAvatarSize.Xs -> t.fontSizeXs
217
+ // werewolf:size=sm
218
+ WerewolfAvatarSize.Sm -> t.fontSizeXs
219
+ // werewolf:size=md
220
+ WerewolfAvatarSize.Md -> t.fontSizeSm
221
+ // werewolf:size=lg
222
+ WerewolfAvatarSize.Lg -> t.fontSizeMd
223
+ // werewolf:size=xl
224
+ WerewolfAvatarSize.Xl -> t.fontSizeLg
225
+ }
226
+ // werewolf:property=root.font-weight
227
+ val rootFontWeight = t.fontWeightMedium
228
+ // werewolf:property=root.height
229
+ val rootHeight: Dp = when (size) {
230
+ // werewolf:size=xs
231
+ WerewolfAvatarSize.Xs -> t.spacingLg + t.spacingXs
232
+ // werewolf:size=sm
233
+ WerewolfAvatarSize.Sm -> t.spacingXl
234
+ // werewolf:size=md
235
+ WerewolfAvatarSize.Md -> t.spacing2xl
236
+ // werewolf:size=lg
237
+ WerewolfAvatarSize.Lg -> t.spacing2xl + t.spacingSm
238
+ // werewolf:size=xl
239
+ WerewolfAvatarSize.Xl -> t.spacing3xl
240
+ }
241
+ // werewolf:property=root.width
242
+ val rootWidth: Dp = when (size) {
243
+ // werewolf:size=xs
244
+ WerewolfAvatarSize.Xs -> t.spacingLg + t.spacingXs
245
+ // werewolf:size=sm
246
+ WerewolfAvatarSize.Sm -> t.spacingXl
247
+ // werewolf:size=md
248
+ WerewolfAvatarSize.Md -> t.spacing2xl
249
+ // werewolf:size=lg
250
+ WerewolfAvatarSize.Lg -> t.spacing2xl + t.spacingSm
251
+ // werewolf:size=xl
252
+ WerewolfAvatarSize.Xl -> t.spacing3xl
253
+ }
254
+ // werewolf:property=icon.color
255
+ val iconColor: Color? = when (color) {
256
+ // werewolf:color=gray
257
+ WerewolfAvatarColor.Gray -> when (variant) {
258
+ // werewolf:variant=soft
259
+ WerewolfAvatarVariant.Soft -> t.colorTextGray
260
+ // werewolf:variant=solid
261
+ WerewolfAvatarVariant.Solid -> null
262
+ }
263
+ // werewolf:color=red
264
+ WerewolfAvatarColor.Red -> when (variant) {
265
+ // werewolf:variant=soft
266
+ WerewolfAvatarVariant.Soft -> t.colorTextRed
267
+ // werewolf:variant=solid
268
+ WerewolfAvatarVariant.Solid -> null
269
+ }
270
+ // werewolf:color=orange
271
+ WerewolfAvatarColor.Orange -> when (variant) {
272
+ // werewolf:variant=soft
273
+ WerewolfAvatarVariant.Soft -> t.colorTextOrange
274
+ // werewolf:variant=solid
275
+ WerewolfAvatarVariant.Solid -> null
276
+ }
277
+ // werewolf:color=yellow
278
+ WerewolfAvatarColor.Yellow -> when (variant) {
279
+ // werewolf:variant=soft
280
+ WerewolfAvatarVariant.Soft -> t.colorTextYellow
281
+ // werewolf:variant=solid
282
+ WerewolfAvatarVariant.Solid -> null
283
+ }
284
+ // werewolf:color=green
285
+ WerewolfAvatarColor.Green -> when (variant) {
286
+ // werewolf:variant=soft
287
+ WerewolfAvatarVariant.Soft -> t.colorTextGreen
288
+ // werewolf:variant=solid
289
+ WerewolfAvatarVariant.Solid -> null
290
+ }
291
+ // werewolf:color=teal
292
+ WerewolfAvatarColor.Teal -> when (variant) {
293
+ // werewolf:variant=soft
294
+ WerewolfAvatarVariant.Soft -> t.colorTextTeal
295
+ // werewolf:variant=solid
296
+ WerewolfAvatarVariant.Solid -> null
297
+ }
298
+ // werewolf:color=blue
299
+ WerewolfAvatarColor.Blue -> when (variant) {
300
+ // werewolf:variant=soft
301
+ WerewolfAvatarVariant.Soft -> t.colorTextBlue
302
+ // werewolf:variant=solid
303
+ WerewolfAvatarVariant.Solid -> null
304
+ }
305
+ // werewolf:color=purple
306
+ WerewolfAvatarColor.Purple -> when (variant) {
307
+ // werewolf:variant=soft
308
+ WerewolfAvatarVariant.Soft -> t.colorTextPurple
309
+ // werewolf:variant=solid
310
+ WerewolfAvatarVariant.Solid -> null
311
+ }
312
+ // werewolf:color=pink
313
+ WerewolfAvatarColor.Pink -> when (variant) {
314
+ // werewolf:variant=soft
315
+ WerewolfAvatarVariant.Soft -> t.colorTextPink
316
+ // werewolf:variant=solid
317
+ WerewolfAvatarVariant.Solid -> null
318
+ }
319
+ }
320
+ // werewolf:property=icon.height
321
+ val iconHeight: Dp = when (size) {
322
+ // werewolf:size=xs
323
+ WerewolfAvatarSize.Xs -> t.sizeIconSm
324
+ // werewolf:size=sm
325
+ WerewolfAvatarSize.Sm -> t.sizeIconSm
326
+ // werewolf:size=md
327
+ WerewolfAvatarSize.Md -> t.sizeIconMd
328
+ // werewolf:size=lg
329
+ WerewolfAvatarSize.Lg -> t.sizeIconLg
330
+ // werewolf:size=xl
331
+ WerewolfAvatarSize.Xl -> t.sizeIconLg
332
+ }
333
+ // werewolf:property=icon.width
334
+ val iconWidth: Dp = when (size) {
335
+ // werewolf:size=xs
336
+ WerewolfAvatarSize.Xs -> t.sizeIconSm
337
+ // werewolf:size=sm
338
+ WerewolfAvatarSize.Sm -> t.sizeIconSm
339
+ // werewolf:size=md
340
+ WerewolfAvatarSize.Md -> t.sizeIconMd
341
+ // werewolf:size=lg
342
+ WerewolfAvatarSize.Lg -> t.sizeIconLg
343
+ // werewolf:size=xl
344
+ WerewolfAvatarSize.Xl -> t.sizeIconLg
345
+ }
346
+ // werewolf:property=image.transition-duration
347
+ val imageTransitionDuration = t.durationMediumMs
348
+ // werewolf:property=image.transition-timing-function
349
+ val imageTransitionTimingFunction = t.easeStandard
350
+ val rootShape = werewolfCornerShape(rootBorderRadius)
351
+ val rootTextStyle = LocalWerewolfFonts.current.textStyle(
352
+ when (rootFontFamily) {
353
+ t.fontFamilySans -> WerewolfFontRole.Sans
354
+ else -> WerewolfFontRole.Mono
355
+ },
356
+ rootFontSize,
357
+ rootFontWeight,
358
+ TextUnit.Unspecified,
359
+ )
360
+ CompositionLocalProvider(
361
+ LocalWerewolfContentColor provides rootColor,
362
+ LocalWerewolfTextStyle provides rootTextStyle,
363
+ ) {
364
+ Box(
365
+ modifier = modifier
366
+ .semantics {
367
+ role = Role.Image
368
+ if (alt.isEmpty()) hideFromAccessibility() else contentDescription = alt
369
+ }
370
+ .width(rootWidth)
371
+ .height(rootHeight)
372
+ .background(rootBackgroundColor, rootShape)
373
+ .clip(rootShape),
374
+ contentAlignment = Alignment.Center,
375
+ ) {
376
+ fallback()
377
+ if (icon != null) {
378
+ Box(
379
+ modifier = Modifier
380
+ .width(iconWidth)
381
+ .height(iconHeight),
382
+ ) {
383
+ CompositionLocalProvider(LocalWerewolfContentColor provides (iconColor ?: Color.Transparent)) {
384
+ icon()
385
+ }
386
+ }
387
+ }
388
+ if (image != null) {
389
+ image?.invoke()
390
+ }
391
+ }
392
+ }
393
+ }