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,178 @@
1
+ // Generated file, must not be edited by hand. Source: components/avatar-stack.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.clickable
6
+ import androidx.compose.foundation.interaction.MutableInteractionSource
7
+ import androidx.compose.foundation.interaction.collectIsPressedAsState
8
+ import androidx.compose.foundation.layout.Arrangement
9
+ import androidx.compose.foundation.layout.Box
10
+ import androidx.compose.foundation.layout.Row
11
+ import androidx.compose.foundation.layout.height
12
+ import androidx.compose.foundation.layout.padding
13
+ import androidx.compose.foundation.layout.width
14
+ import androidx.compose.foundation.shape.CircleShape
15
+ import androidx.compose.foundation.text.BasicText
16
+ import androidx.compose.runtime.Composable
17
+ import androidx.compose.runtime.getValue
18
+ import androidx.compose.runtime.remember
19
+ import androidx.compose.ui.Alignment
20
+ import androidx.compose.ui.Modifier
21
+ import androidx.compose.ui.graphics.Color
22
+ import androidx.compose.ui.semantics.Role
23
+ import androidx.compose.ui.semantics.clearAndSetSemantics
24
+ import androidx.compose.ui.semantics.contentDescription
25
+ import androidx.compose.ui.semantics.hideFromAccessibility
26
+ import androidx.compose.ui.semantics.role
27
+ import androidx.compose.ui.semantics.semantics
28
+ import androidx.compose.ui.text.TextStyle
29
+ import androidx.compose.ui.unit.Dp
30
+ import androidx.compose.ui.unit.TextUnit
31
+ import androidx.compose.ui.unit.times
32
+ import androidx.compose.ui.zIndex
33
+ import dev.werewolfui.runtime.LocalWerewolf
34
+ import dev.werewolfui.runtime.LocalWerewolfFonts
35
+ import dev.werewolfui.runtime.WerewolfFontRole
36
+ import dev.werewolfui.runtime.werewolfFontWeight
37
+ import dev.werewolfui.runtime.werewolfHitArea
38
+ import dev.werewolfui.runtime.werewolfPressScale
39
+
40
+ enum class WerewolfAvatarStackSize {
41
+ Sm,
42
+ Md,
43
+ Lg,
44
+ }
45
+
46
+ @Composable
47
+ fun WerewolfAvatarStack(
48
+ count: Int,
49
+ modifier: Modifier = Modifier,
50
+ label: String = "",
51
+ max: Int = 3,
52
+ onClick: (() -> Unit)? = null,
53
+ size: WerewolfAvatarStackSize = WerewolfAvatarStackSize.Md,
54
+ avatar: @Composable (Int) -> Unit,
55
+ ) {
56
+ val t = LocalWerewolf.current
57
+ // werewolf:property=root.gap
58
+ val rootGap: Dp = when (size) {
59
+ // werewolf:size=sm
60
+ WerewolfAvatarStackSize.Sm -> (-t.spacingXs) - 2 * t.spacing2xs
61
+ // werewolf:size=md
62
+ WerewolfAvatarStackSize.Md -> (-t.spacingSm) - 2 * t.spacing2xs
63
+ // werewolf:size=lg
64
+ WerewolfAvatarStackSize.Lg -> (-t.spacingSm) - 2 * t.spacing2xs
65
+ }
66
+ // werewolf:property=ring.background-color
67
+ val ringBackgroundColor = t.colorBackgroundPage
68
+ // werewolf:property=ring.border-radius
69
+ val ringBorderRadius = t.radiusFull
70
+ // werewolf:property=ring.padding
71
+ val ringPadding = t.spacing2xs
72
+ // werewolf:property=more.background-color
73
+ val moreBackgroundColor = t.colorBackgroundGray
74
+ // werewolf:property=more.border-radius
75
+ val moreBorderRadius = t.radiusFull
76
+ // werewolf:property=more.color
77
+ val moreColor = t.colorTextGray
78
+ // werewolf:property=more.font-family
79
+ val moreFontFamily = t.fontFamilySans
80
+ // werewolf:property=more.font-size
81
+ val moreFontSize: TextUnit = when (size) {
82
+ // werewolf:size=sm
83
+ WerewolfAvatarStackSize.Sm -> t.fontSizeXs
84
+ // werewolf:size=md
85
+ WerewolfAvatarStackSize.Md -> t.fontSizeSm
86
+ // werewolf:size=lg
87
+ WerewolfAvatarStackSize.Lg -> t.fontSizeMd
88
+ }
89
+ // werewolf:property=more.font-weight
90
+ val moreFontWeight = t.fontWeightMedium
91
+ // werewolf:property=more.height
92
+ val moreHeight: Dp = when (size) {
93
+ // werewolf:size=sm
94
+ WerewolfAvatarStackSize.Sm -> t.spacingXl
95
+ // werewolf:size=md
96
+ WerewolfAvatarStackSize.Md -> t.spacing2xl
97
+ // werewolf:size=lg
98
+ WerewolfAvatarStackSize.Lg -> t.spacing2xl + t.spacingSm
99
+ }
100
+ // werewolf:property=more.width
101
+ val moreWidth: Dp = when (size) {
102
+ // werewolf:size=sm
103
+ WerewolfAvatarStackSize.Sm -> t.spacingXl
104
+ // werewolf:size=md
105
+ WerewolfAvatarStackSize.Md -> t.spacing2xl
106
+ // werewolf:size=lg
107
+ WerewolfAvatarStackSize.Lg -> t.spacing2xl + t.spacingSm
108
+ }
109
+ val ringShape = CircleShape
110
+ val moreShape = CircleShape
111
+ val shownCount = minOf(maxOf(1, max), count)
112
+ val overflow = maxOf(0, count - shownCount)
113
+ val interactionSource = remember { MutableInteractionSource() }
114
+ val pressed by interactionSource.collectIsPressedAsState()
115
+ val stackModifier = if (onClick != null) {
116
+ modifier
117
+ .werewolfPressScale(pressed)
118
+ .werewolfHitArea()
119
+ .clickable(interactionSource = interactionSource, indication = null, role = Role.Button, onClick = onClick)
120
+ .semantics(mergeDescendants = true) { if (label.isNotEmpty()) contentDescription = label }
121
+ } else {
122
+ modifier.clearAndSetSemantics {
123
+ if (label.isEmpty()) hideFromAccessibility() else {
124
+ contentDescription = label
125
+ role = Role.Image
126
+ }
127
+ }
128
+ }
129
+ Row(
130
+ modifier = stackModifier,
131
+ horizontalArrangement = Arrangement.spacedBy(rootGap),
132
+ verticalAlignment = Alignment.CenterVertically,
133
+ ) {
134
+ repeat(shownCount) { index ->
135
+ Box(
136
+ modifier = Modifier
137
+ .zIndex((shownCount - index).toFloat())
138
+ .background(ringBackgroundColor, ringShape)
139
+ .padding(ringPadding),
140
+ contentAlignment = Alignment.Center,
141
+ ) {
142
+ avatar(index)
143
+ }
144
+ }
145
+ if (overflow > 0) {
146
+ Box(
147
+ modifier = Modifier
148
+ .background(ringBackgroundColor, ringShape)
149
+ .padding(ringPadding),
150
+ contentAlignment = Alignment.Center,
151
+ ) {
152
+ Box(
153
+ modifier = Modifier
154
+ .width(moreWidth)
155
+ .height(moreHeight)
156
+ .background(moreBackgroundColor, moreShape),
157
+ contentAlignment = Alignment.Center,
158
+ ) {
159
+ BasicText(
160
+ text = "+$overflow",
161
+ style = TextStyle(
162
+ fontFeatureSettings = "tnum",
163
+ color = moreColor,
164
+ fontFamily = LocalWerewolfFonts.current.resolve(
165
+ when (moreFontFamily) {
166
+ t.fontFamilySans -> WerewolfFontRole.Sans
167
+ else -> WerewolfFontRole.Mono
168
+ },
169
+ ),
170
+ fontSize = moreFontSize,
171
+ fontWeight = werewolfFontWeight(moreFontWeight),
172
+ ),
173
+ )
174
+ }
175
+ }
176
+ }
177
+ }
178
+ }
@@ -0,0 +1,89 @@
1
+ // Werewolf native runtime. Hand-written, independent of the seed.
2
+ package dev.werewolfui.runtime
3
+
4
+ import android.os.Build
5
+ import androidx.compose.foundation.background
6
+ import androidx.compose.foundation.border
7
+ import androidx.compose.runtime.Composable
8
+ import androidx.compose.runtime.getValue
9
+ import androidx.compose.runtime.mutableStateOf
10
+ import androidx.compose.runtime.remember
11
+ import androidx.compose.runtime.setValue
12
+ import androidx.compose.runtime.staticCompositionLocalOf
13
+ import androidx.compose.ui.Modifier
14
+ import androidx.compose.ui.draw.clip
15
+ import androidx.compose.ui.draw.drawWithContent
16
+ import androidx.compose.ui.geometry.Offset
17
+ import androidx.compose.ui.graphics.BlurEffect
18
+ import androidx.compose.ui.graphics.ColorFilter
19
+ import androidx.compose.ui.graphics.ColorMatrix
20
+ import androidx.compose.ui.graphics.Shape
21
+ import androidx.compose.ui.graphics.TileMode
22
+ import androidx.compose.ui.graphics.drawscope.translate
23
+ import androidx.compose.ui.graphics.layer.GraphicsLayer
24
+ import androidx.compose.ui.graphics.layer.drawLayer
25
+ import androidx.compose.ui.graphics.rememberGraphicsLayer
26
+ import androidx.compose.ui.layout.onGloballyPositioned
27
+ import androidx.compose.ui.layout.positionInRoot
28
+ import androidx.compose.ui.unit.IntSize
29
+
30
+ internal object WerewolfSpike {
31
+ var backdropBlur: Boolean = false
32
+ }
33
+
34
+ internal enum class WerewolfMaterialLevel {
35
+ Thin,
36
+ }
37
+
38
+ internal class WerewolfBackdrop(val layer: GraphicsLayer) {
39
+ var origin by mutableStateOf(Offset.Zero)
40
+ }
41
+
42
+ internal val LocalWerewolfBackdrop = staticCompositionLocalOf<WerewolfBackdrop?> { null }
43
+
44
+ @Composable
45
+ internal fun WerewolfBackdropSource(content: @Composable () -> Unit) {
46
+ if (!WerewolfSpike.backdropBlur || Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
47
+ content()
48
+ return
49
+ }
50
+ val backdrop = WerewolfBackdrop(rememberGraphicsLayer())
51
+ androidx.compose.runtime.CompositionLocalProvider(LocalWerewolfBackdrop provides backdrop) {
52
+ androidx.compose.foundation.layout.Box(
53
+ Modifier
54
+ .onGloballyPositioned { backdrop.origin = it.positionInRoot() }
55
+ .drawWithContent {
56
+ backdrop.layer.record { this@drawWithContent.drawContent() }
57
+ drawLayer(backdrop.layer)
58
+ },
59
+ ) {
60
+ content()
61
+ }
62
+ }
63
+ }
64
+
65
+ @Composable
66
+ internal fun Modifier.werewolfBackdropBlur(level: WerewolfMaterialLevel = WerewolfMaterialLevel.Thin, shape: Shape): Modifier {
67
+ val theme = LocalWerewolf.current
68
+ val backdrop = LocalWerewolfBackdrop.current
69
+ val active = WerewolfSpike.backdropBlur && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && backdrop != null
70
+ if (!active || backdrop == null) return this.clip(shape).background(theme.colorBackgroundSurface, shape)
71
+ val effect = rememberGraphicsLayer()
72
+ var position by remember { mutableStateOf(Offset.Zero) }
73
+ val radius = with(androidx.compose.ui.platform.LocalDensity.current) { theme.blurMaterialThin.toPx() }
74
+ return this
75
+ .onGloballyPositioned { position = it.positionInRoot() }
76
+ .clip(shape)
77
+ .drawWithContent {
78
+ val local = position - backdrop.origin
79
+ effect.renderEffect = BlurEffect(radius, radius, TileMode.Clamp)
80
+ effect.colorFilter = ColorFilter.colorMatrix(ColorMatrix().apply { setToSaturation(theme.saturateMaterialThin) })
81
+ effect.record(this, layoutDirection, IntSize(size.width.toInt(), size.height.toInt())) {
82
+ translate(-local.x, -local.y) { drawLayer(backdrop.layer) }
83
+ }
84
+ drawLayer(effect)
85
+ drawContent()
86
+ }
87
+ .background(theme.colorBackgroundMaterialThin, shape)
88
+ .border(theme.borderWidth, theme.colorBorderMaterialEdge, shape)
89
+ }
@@ -1,4 +1,4 @@
1
- // Generated file, must not be edited by hand. Source: components/badge.spec.json (werewolf-ui 0.1.0-beta.2).
1
+ // Generated file, must not be edited by hand. Source: components/badge.spec.json (werewolf-ui 0.1.0-beta.4).
2
2
  package dev.werewolfui
3
3
 
4
4
  import androidx.compose.foundation.background
@@ -10,19 +10,22 @@ import androidx.compose.foundation.layout.height
10
10
  import androidx.compose.foundation.layout.padding
11
11
  import androidx.compose.foundation.layout.width
12
12
  import androidx.compose.foundation.shape.CircleShape
13
- import androidx.compose.foundation.shape.RoundedCornerShape
14
13
  import androidx.compose.runtime.Composable
15
14
  import androidx.compose.runtime.CompositionLocalProvider
16
15
  import androidx.compose.ui.Alignment
17
16
  import androidx.compose.ui.Modifier
18
17
  import androidx.compose.ui.graphics.Color
18
+ import androidx.compose.ui.semantics.clearAndSetSemantics
19
+ import androidx.compose.ui.semantics.contentDescription
19
20
  import androidx.compose.ui.unit.Dp
20
21
  import androidx.compose.ui.unit.TextUnit
22
+ import androidx.compose.ui.unit.dp
21
23
  import dev.werewolfui.runtime.LocalWerewolf
22
24
  import dev.werewolfui.runtime.LocalWerewolfContentColor
23
25
  import dev.werewolfui.runtime.LocalWerewolfFonts
24
26
  import dev.werewolfui.runtime.LocalWerewolfTextStyle
25
27
  import dev.werewolfui.runtime.WerewolfFontRole
28
+ import dev.werewolfui.runtime.werewolfCornerShape
26
29
 
27
30
  enum class WerewolfBadgeSize {
28
31
  Sm,
@@ -258,7 +261,7 @@ fun WerewolfBadge(
258
261
  val iconHeight = t.sizeIconSm
259
262
  // werewolf:property=icon.width
260
263
  val iconWidth = t.sizeIconSm
261
- val rootShape = RoundedCornerShape(rootBorderRadius)
264
+ val rootShape = werewolfCornerShape(rootBorderRadius)
262
265
  val dotShape = CircleShape
263
266
  val rootTextStyle = LocalWerewolfFonts.current.textStyle(
264
267
  when (rootFontFamily) {
@@ -305,3 +308,68 @@ fun WerewolfBadge(
305
308
  }
306
309
  }
307
310
  }
311
+
312
+ @Composable
313
+ fun WerewolfBadge(
314
+ accessibilityLabel: String,
315
+ modifier: Modifier = Modifier,
316
+ ring: Boolean = false,
317
+ variant: WerewolfBadgeVariant = WerewolfBadgeVariant.Default,
318
+ ) {
319
+ val t = LocalWerewolf.current
320
+ // werewolf:property=dot.background-color
321
+ val dotBackgroundColor: Color = when (variant) {
322
+ // werewolf:variant=default
323
+ WerewolfBadgeVariant.Default -> t.colorGray
324
+ // werewolf:variant=accent
325
+ WerewolfBadgeVariant.Accent -> t.colorAccent
326
+ // werewolf:variant=outline
327
+ WerewolfBadgeVariant.Outline -> t.colorGray
328
+ // werewolf:variant=destructive
329
+ WerewolfBadgeVariant.Destructive -> t.colorDanger
330
+ // werewolf:variant=success
331
+ WerewolfBadgeVariant.Success -> t.colorSuccess
332
+ // werewolf:variant=warning
333
+ WerewolfBadgeVariant.Warning -> t.colorWarning
334
+ // werewolf:variant=info
335
+ WerewolfBadgeVariant.Info -> t.colorInfo
336
+ // werewolf:variant=red
337
+ WerewolfBadgeVariant.Red -> t.colorRed
338
+ // werewolf:variant=orange
339
+ WerewolfBadgeVariant.Orange -> t.colorOrange
340
+ // werewolf:variant=yellow
341
+ WerewolfBadgeVariant.Yellow -> t.colorYellow
342
+ // werewolf:variant=green
343
+ WerewolfBadgeVariant.Green -> t.colorGreen
344
+ // werewolf:variant=teal
345
+ WerewolfBadgeVariant.Teal -> t.colorTeal
346
+ // werewolf:variant=blue
347
+ WerewolfBadgeVariant.Blue -> t.colorBlue
348
+ // werewolf:variant=purple
349
+ WerewolfBadgeVariant.Purple -> t.colorPurple
350
+ // werewolf:variant=pink
351
+ WerewolfBadgeVariant.Pink -> t.colorPink
352
+ }
353
+ // werewolf:property=dot.border-radius
354
+ val dotBorderRadius = t.radiusFull
355
+ // werewolf:property=dot.height
356
+ val dotHeight = t.spacing2xs * 3
357
+ // werewolf:property=dot.width
358
+ val dotWidth = t.spacing2xs * 3
359
+ // werewolf:property=ring.background-color
360
+ val ringBackgroundColor = t.colorBackgroundPage
361
+ // werewolf:property=ring.border-radius
362
+ val ringBorderRadius = t.radiusFull
363
+ // werewolf:property=ring.padding
364
+ val ringPadding = t.spacing2xs
365
+ val dotShape = CircleShape
366
+ val ringShape = CircleShape
367
+ Box(
368
+ modifier = modifier
369
+ .clearAndSetSemantics { contentDescription = accessibilityLabel }
370
+ .background(if (ring) ringBackgroundColor else Color.Transparent, ringShape)
371
+ .padding(if (ring) ringPadding else 0.dp),
372
+ ) {
373
+ Box(modifier = Modifier.width(dotWidth).height(dotHeight).background(dotBackgroundColor, dotShape))
374
+ }
375
+ }