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,85 @@
1
+ // Generated file, must not be edited by hand. Source: components/calendar.spec.json (werewolf-ui 0.1.0-beta.4).
2
+ package dev.werewolfui
3
+
4
+ import androidx.compose.runtime.Composable
5
+ import androidx.compose.runtime.getValue
6
+ import androidx.compose.runtime.mutableStateOf
7
+ import androidx.compose.runtime.remember
8
+ import androidx.compose.runtime.setValue
9
+ import androidx.compose.ui.Modifier
10
+ import dev.werewolfui.runtime.LocalWerewolf
11
+ import dev.werewolfui.runtime.WerewolfCalendarGrid
12
+ import dev.werewolfui.runtime.WerewolfCalendarStyle
13
+ import dev.werewolfui.runtime.WerewolfDatePickerValue
14
+ import dev.werewolfui.runtime.rememberReduceMotion
15
+ import dev.werewolfui.runtime.werewolfHitArea
16
+
17
+ enum class WerewolfCalendarMode {
18
+ Single,
19
+ Range,
20
+ }
21
+
22
+ @Composable
23
+ fun WerewolfCalendar(
24
+ modifier: Modifier = Modifier,
25
+ mode: WerewolfCalendarMode = WerewolfCalendarMode.Single,
26
+ value: WerewolfDatePickerValue? = null,
27
+ defaultValue: WerewolfDatePickerValue? = null,
28
+ onValueChange: ((WerewolfDatePickerValue?) -> Unit)? = null,
29
+ minDate: String? = null,
30
+ maxDate: String? = null,
31
+ weekStartsOn: Int? = null,
32
+ enabled: Boolean = true,
33
+ rangeStartLabel: String = "start of range",
34
+ rangeEndLabel: String = "end of range",
35
+ ) {
36
+ val t = LocalWerewolf.current
37
+ val reduced = rememberReduceMotion()
38
+ var current by remember { mutableStateOf(defaultValue) }
39
+ val style = WerewolfCalendarStyle(
40
+ rootFontFamily = t.fontFamilySans,
41
+ rootColor = t.colorTextPrimary,
42
+ rootPadding = t.spacingMd,
43
+ labelFontSize = t.fontSizeSm,
44
+ labelFontWeight = t.fontWeightMedium,
45
+ labelHeight = t.sizeElementMd,
46
+ headFontSize = t.fontSizeXs,
47
+ headFontWeight = t.fontWeightMedium,
48
+ headColor = t.colorTextSecondary,
49
+ itemHeight = t.sizeElementMd,
50
+ itemBorderWidth = t.borderWidth,
51
+ itemRadius = t.radiusElement,
52
+ itemFontSize = t.fontSizeSm,
53
+ itemFontWeight = t.fontWeightMedium,
54
+ itemHoverOverlay = t.colorOverlayHover,
55
+ itemPressedOverlay = t.colorOverlayPressed,
56
+ itemDisabledColor = t.colorTextDisabled,
57
+ selectedBackgroundColor = t.colorAccent,
58
+ selectedColor = t.colorTextOnAccent,
59
+ iconColor = t.colorIconSecondary,
60
+ rangeBackgroundColor = t.colorAccentMuted,
61
+ rangeColor = t.colorTextOnMuted,
62
+ focusRingColor = t.colorFocusRing,
63
+ focusRingWidth = t.outlineWidthFocusRing,
64
+ focusRingOffset = t.outlineOffsetFocusRing,
65
+ itemTransitionDurationMs = t.durationFastMs,
66
+ itemTransitionEasing = t.easeStandard,
67
+ itemScalePressed = t.scalePressed,
68
+ )
69
+ WerewolfCalendarGrid(
70
+ isRange = mode == WerewolfCalendarMode.Range,
71
+ value = value ?: current,
72
+ minDate = minDate,
73
+ maxDate = maxDate,
74
+ weekStartsOn = weekStartsOn,
75
+ rangeStartLabel = rangeStartLabel,
76
+ rangeEndLabel = rangeEndLabel,
77
+ enabled = enabled,
78
+ style = style,
79
+ onChange = { next ->
80
+ if (value == null) current = next
81
+ onValueChange?.invoke(next)
82
+ },
83
+ modifier = modifier.werewolfHitArea(),
84
+ )
85
+ }
@@ -0,0 +1,412 @@
1
+ // Werewolf native runtime. Hand-written, independent of the seed.
2
+ package dev.werewolfui.runtime
3
+
4
+ import androidx.compose.foundation.Image
5
+ import androidx.compose.foundation.background
6
+ import androidx.compose.foundation.border
7
+ import androidx.compose.foundation.clickable
8
+ import androidx.compose.foundation.interaction.MutableInteractionSource
9
+ import androidx.compose.foundation.interaction.collectIsPressedAsState
10
+ import androidx.compose.foundation.layout.Arrangement
11
+ import androidx.compose.foundation.layout.Box
12
+ import androidx.compose.foundation.layout.Column
13
+ import androidx.compose.foundation.layout.Row
14
+ import androidx.compose.foundation.layout.Spacer
15
+ import androidx.compose.foundation.layout.defaultMinSize
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.text.BasicText
20
+ import androidx.compose.runtime.Composable
21
+ import androidx.compose.runtime.getValue
22
+ import androidx.compose.runtime.mutableStateOf
23
+ import androidx.compose.runtime.remember
24
+ import androidx.compose.runtime.setValue
25
+ import androidx.compose.ui.Alignment
26
+ import androidx.compose.ui.Modifier
27
+ import androidx.compose.ui.draw.clip
28
+ import androidx.compose.ui.graphics.Color
29
+ import androidx.compose.ui.graphics.ColorFilter
30
+ import androidx.compose.ui.graphics.graphicsLayer
31
+ import androidx.compose.ui.semantics.LiveRegionMode
32
+ import androidx.compose.ui.semantics.Role
33
+ import androidx.compose.ui.semantics.clearAndSetSemantics
34
+ import androidx.compose.ui.semantics.contentDescription
35
+ import androidx.compose.ui.semantics.disabled
36
+ import androidx.compose.ui.semantics.heading
37
+ import androidx.compose.ui.semantics.liveRegion
38
+ import androidx.compose.ui.semantics.selected
39
+ import androidx.compose.ui.semantics.semantics
40
+ import androidx.compose.ui.text.TextStyle
41
+ import androidx.compose.ui.text.style.TextAlign
42
+ import androidx.compose.ui.unit.Dp
43
+ import androidx.compose.ui.unit.TextUnit
44
+ import androidx.compose.ui.unit.dp
45
+ import dev.werewolfui.tokens.WerewolfEasing
46
+
47
+ internal class WerewolfCalendarStyle(
48
+ val rootFontFamily: String,
49
+ val rootColor: Color,
50
+ val rootPadding: Dp,
51
+ val labelFontSize: TextUnit,
52
+ val labelFontWeight: Float,
53
+ val labelHeight: Dp,
54
+ val headFontSize: TextUnit,
55
+ val headFontWeight: Float,
56
+ val headColor: Color,
57
+ val itemHeight: Dp,
58
+ val itemBorderWidth: Dp,
59
+ val itemRadius: Dp,
60
+ val itemFontSize: TextUnit,
61
+ val itemFontWeight: Float,
62
+ val itemHoverOverlay: Color,
63
+ val itemPressedOverlay: Color,
64
+ val itemDisabledColor: Color,
65
+ val selectedBackgroundColor: Color,
66
+ val selectedColor: Color,
67
+ val iconColor: Color,
68
+ val rangeBackgroundColor: Color,
69
+ val rangeColor: Color,
70
+ val focusRingColor: Color,
71
+ val focusRingWidth: Dp,
72
+ val focusRingOffset: Dp,
73
+ val itemTransitionDurationMs: Int,
74
+ val itemTransitionEasing: WerewolfEasing,
75
+ val itemScalePressed: Float,
76
+ )
77
+
78
+ private data class DaySelectionState(
79
+ val isSelected: Boolean,
80
+ val isSolidEnd: Boolean,
81
+ val isRangeMiddle: Boolean,
82
+ val isStart: Boolean,
83
+ val isEnd: Boolean,
84
+ val roundStart: Boolean,
85
+ val roundEnd: Boolean,
86
+ )
87
+
88
+ /** Token-driven 7-column month grid for single and range date picking on Android API 24+. */
89
+ @Composable
90
+ internal fun WerewolfCalendarGrid(
91
+ isRange: Boolean,
92
+ value: WerewolfDatePickerValue?,
93
+ minDate: String?,
94
+ maxDate: String?,
95
+ weekStartsOn: Int?,
96
+ rangeStartLabel: String,
97
+ rangeEndLabel: String,
98
+ enabled: Boolean,
99
+ style: WerewolfCalendarStyle,
100
+ onChange: (WerewolfDatePickerValue?) -> Unit,
101
+ modifier: Modifier = Modifier,
102
+ ) {
103
+ val t = LocalWerewolf.current
104
+ val icons = LocalWerewolfIcons.current
105
+ val fonts = LocalWerewolfFonts.current
106
+ val reduced = rememberReduceMotion()
107
+ val todayIso = remember { WerewolfCalendarMath.todayIsoDate() }
108
+ val resolvedWeekStart = weekStartsOn ?: remember { WerewolfCalendarMath.defaultWeekStartsOn() }
109
+ var displayedMonth by remember {
110
+ mutableStateOf(WerewolfCalendarMath.initialMonth(value, todayIso, minDate, maxDate))
111
+ }
112
+
113
+ val canPrev = enabled && WerewolfCalendarMath.canNavigateMonth(displayedMonth.year, displayedMonth.month, -1, minDate, maxDate)
114
+ val canNext = enabled && WerewolfCalendarMath.canNavigateMonth(displayedMonth.year, displayedMonth.month, 1, minDate, maxDate)
115
+ val cells = WerewolfCalendarMath.monthGridDays(displayedMonth.year, displayedMonth.month, resolvedWeekStart)
116
+ val rows = cells.chunked(7)
117
+ val weekdays = WerewolfCalendarMath.weekdaySymbols(resolvedWeekStart)
118
+ val monthTitle = WerewolfCalendarMath.monthYearTitle(displayedMonth.year, displayedMonth.month)
119
+
120
+ Column(
121
+ verticalArrangement = Arrangement.spacedBy(t.spacingSm),
122
+ modifier = modifier.padding(style.rootPadding),
123
+ ) {
124
+ Row(
125
+ verticalAlignment = Alignment.CenterVertically,
126
+ horizontalArrangement = Arrangement.spacedBy(t.spacingXs),
127
+ modifier = Modifier
128
+ .fillMaxWidth()
129
+ .defaultMinSize(minHeight = style.labelHeight),
130
+ ) {
131
+ CalendarNavButton(
132
+ icon = icons.chevronEnd,
133
+ flip = true,
134
+ enabled = canPrev,
135
+ iconColor = style.iconColor,
136
+ disabledColor = style.itemDisabledColor,
137
+ pressedOverlay = style.itemPressedOverlay,
138
+ radius = style.itemRadius,
139
+ reduced = reduced,
140
+ contentDescription = "Go to the Previous Month",
141
+ onClick = {
142
+ displayedMonth = WerewolfCalendarMath.shiftMonth(displayedMonth.year, displayedMonth.month, -1)
143
+ },
144
+ )
145
+ BasicText(
146
+ text = monthTitle,
147
+ style = TextStyle(
148
+ fontFamily = fonts.resolve(WerewolfFontRole.Sans),
149
+ fontSize = style.labelFontSize,
150
+ fontWeight = werewolfFontWeight(style.labelFontWeight),
151
+ color = style.rootColor,
152
+ textAlign = TextAlign.Center,
153
+ ),
154
+ modifier = Modifier
155
+ .weight(1f)
156
+ .semantics {
157
+ heading()
158
+ liveRegion = LiveRegionMode.Polite
159
+ },
160
+ )
161
+ CalendarNavButton(
162
+ icon = icons.chevronEnd,
163
+ flip = false,
164
+ enabled = canNext,
165
+ iconColor = style.iconColor,
166
+ disabledColor = style.itemDisabledColor,
167
+ pressedOverlay = style.itemPressedOverlay,
168
+ radius = style.itemRadius,
169
+ reduced = reduced,
170
+ contentDescription = "Go to the Next Month",
171
+ onClick = {
172
+ displayedMonth = WerewolfCalendarMath.shiftMonth(displayedMonth.year, displayedMonth.month, 1)
173
+ },
174
+ )
175
+ }
176
+
177
+ Row(modifier = Modifier.fillMaxWidth()) {
178
+ for (weekday in weekdays) {
179
+ BasicText(
180
+ text = weekday,
181
+ style = TextStyle(
182
+ fontFamily = fonts.resolve(WerewolfFontRole.Sans),
183
+ fontSize = style.headFontSize,
184
+ fontWeight = werewolfFontWeight(style.headFontWeight),
185
+ color = style.headColor,
186
+ textAlign = TextAlign.Center,
187
+ ),
188
+ modifier = Modifier
189
+ .weight(1f)
190
+ .padding(bottom = t.spacingXs)
191
+ .clearAndSetSemantics {},
192
+ )
193
+ }
194
+ }
195
+
196
+ Column(verticalArrangement = Arrangement.spacedBy(t.spacing2xs)) {
197
+ for (row in rows) {
198
+ Row(modifier = Modifier.fillMaxWidth()) {
199
+ for (cell in row) {
200
+ val cellMinHeight = maxOf(style.itemHeight, t.sizeTargetMin)
201
+ if (!cell.inMonth) {
202
+ Spacer(
203
+ modifier = Modifier
204
+ .weight(1f)
205
+ .defaultMinSize(minHeight = cellMinHeight),
206
+ )
207
+ } else {
208
+ val cellDisabled = WerewolfCalendarMath.isDateDisabled(cell.iso, minDate, maxDate, !enabled)
209
+ val state = selectionState(isRange = isRange, value = value, iso = cell.iso)
210
+ val isToday = cell.iso == todayIso
211
+ val textColor = when {
212
+ cellDisabled -> style.itemDisabledColor
213
+ state.isSolidEnd -> style.selectedColor
214
+ state.isRangeMiddle -> style.rangeColor
215
+ else -> style.rootColor
216
+ }
217
+ val fill = when {
218
+ state.isSolidEnd -> style.selectedBackgroundColor
219
+ state.isRangeMiddle -> style.rangeBackgroundColor
220
+ else -> Color.Transparent
221
+ }
222
+ val startRadius = if (state.roundStart) style.itemRadius else 0.dp
223
+ val endRadius = if (state.roundEnd) style.itemRadius else 0.dp
224
+ val cellShape = werewolfCornerShape(startRadius, endRadius, endRadius, startRadius)
225
+ val interaction = remember { MutableInteractionSource() }
226
+ val pressed by interaction.collectIsPressedAsState()
227
+ val overlay = when {
228
+ !pressed || cellDisabled -> Color.Transparent
229
+ state.isSolidEnd -> t.colorOverlayPressedOnAccent
230
+ else -> style.itemPressedOverlay
231
+ }
232
+ val a11yLabel = WerewolfCalendarMath.dayAccessibilityLabel(
233
+ year = cell.year,
234
+ month = cell.month,
235
+ day = cell.day,
236
+ isSelected = state.isSelected,
237
+ isRangeStart = state.isStart,
238
+ isRangeEnd = state.isEnd,
239
+ rangeStartLabel = rangeStartLabel,
240
+ rangeEndLabel = rangeEndLabel,
241
+ )
242
+
243
+ Box(
244
+ contentAlignment = Alignment.Center,
245
+ modifier = Modifier
246
+ .weight(1f)
247
+ .defaultMinSize(minHeight = cellMinHeight)
248
+ .graphicsLayer {
249
+ if (!reduced && pressed && !cellDisabled) {
250
+ scaleX = t.scalePressed
251
+ scaleY = t.scalePressed
252
+ }
253
+ }
254
+ .semantics(mergeDescendants = true) {
255
+ contentDescription = a11yLabel
256
+ selected = state.isSelected
257
+ if (cellDisabled) disabled()
258
+ }
259
+ .clickable(
260
+ interactionSource = interaction,
261
+ indication = null,
262
+ enabled = !cellDisabled,
263
+ role = Role.Button,
264
+ onClick = {
265
+ if (isRange) {
266
+ val current = (value as? WerewolfDatePickerValue.Range)?.let {
267
+ WerewolfDateRange(it.from, it.to)
268
+ }
269
+ val next = WerewolfCalendarMath.selectRange(current, cell.iso, minDate, maxDate, !enabled)
270
+ onChange(next?.let { WerewolfDatePickerValue.Range(it.from, it.to) })
271
+ } else {
272
+ val current = (value as? WerewolfDatePickerValue.Single)?.date
273
+ val next = WerewolfCalendarMath.selectSingle(current, cell.iso, minDate, maxDate, !enabled)
274
+ onChange(next?.let { WerewolfDatePickerValue.Single(it) })
275
+ }
276
+ },
277
+ ),
278
+ ) {
279
+ Box(
280
+ contentAlignment = Alignment.Center,
281
+ modifier = Modifier
282
+ .fillMaxWidth()
283
+ .defaultMinSize(minHeight = style.itemHeight)
284
+ .clip(cellShape)
285
+ .background(fill)
286
+ .background(overlay)
287
+ .then(
288
+ if (isToday) {
289
+ Modifier.border(
290
+ style.itemBorderWidth,
291
+ textColor,
292
+ werewolfCornerShape(style.itemRadius),
293
+ )
294
+ } else {
295
+ Modifier
296
+ },
297
+ )
298
+ .padding(vertical = t.spacing2xs),
299
+ ) {
300
+ BasicText(
301
+ text = cell.day.toString(),
302
+ style = TextStyle(
303
+ fontFamily = fonts.resolve(WerewolfFontRole.Sans),
304
+ fontSize = style.itemFontSize,
305
+ fontWeight = werewolfFontWeight(style.itemFontWeight),
306
+ color = textColor,
307
+ fontFeatureSettings = "tnum",
308
+ textAlign = TextAlign.Center,
309
+ ),
310
+ )
311
+ }
312
+ }
313
+ }
314
+ }
315
+ }
316
+ }
317
+ }
318
+ }
319
+ }
320
+
321
+ @Composable
322
+ private fun CalendarNavButton(
323
+ icon: androidx.compose.ui.graphics.vector.ImageVector,
324
+ flip: Boolean,
325
+ enabled: Boolean,
326
+ iconColor: Color,
327
+ disabledColor: Color,
328
+ pressedOverlay: Color,
329
+ radius: Dp,
330
+ reduced: Boolean,
331
+ contentDescription: String,
332
+ onClick: () -> Unit,
333
+ ) {
334
+ val t = LocalWerewolf.current
335
+ val interaction = remember { MutableInteractionSource() }
336
+ val pressed by interaction.collectIsPressedAsState()
337
+ val shape = werewolfCornerShape(radius)
338
+
339
+ Box(
340
+ contentAlignment = Alignment.Center,
341
+ modifier = Modifier
342
+ .werewolfHitArea()
343
+ .size(t.sizeElementSm)
344
+ .graphicsLayer {
345
+ if (!reduced && pressed && enabled) {
346
+ scaleX = t.scalePressed
347
+ scaleY = t.scalePressed
348
+ }
349
+ }
350
+ .clip(shape)
351
+ .background(if (pressed && enabled) pressedOverlay else Color.Transparent)
352
+ .semantics {
353
+ this.contentDescription = contentDescription
354
+ if (!enabled) disabled()
355
+ }
356
+ .clickable(
357
+ interactionSource = interaction,
358
+ indication = null,
359
+ enabled = enabled,
360
+ role = Role.Button,
361
+ onClick = onClick,
362
+ ),
363
+ ) {
364
+ Image(
365
+ imageVector = icon,
366
+ contentDescription = null,
367
+ colorFilter = ColorFilter.tint(if (enabled) iconColor else disabledColor),
368
+ modifier = Modifier
369
+ .size(t.sizeIconMd)
370
+ .then(if (flip) Modifier.graphicsLayer { scaleX = -1f } else Modifier),
371
+ )
372
+ }
373
+ }
374
+
375
+ private fun selectionState(
376
+ isRange: Boolean,
377
+ value: WerewolfDatePickerValue?,
378
+ iso: String,
379
+ ): DaySelectionState {
380
+ if (!isRange) {
381
+ val picked = (value as? WerewolfDatePickerValue.Single)?.date == iso
382
+ return DaySelectionState(
383
+ isSelected = picked,
384
+ isSolidEnd = picked,
385
+ isRangeMiddle = false,
386
+ isStart = false,
387
+ isEnd = false,
388
+ roundStart = true,
389
+ roundEnd = true,
390
+ )
391
+ }
392
+ val range = value as? WerewolfDatePickerValue.Range
393
+ ?: return DaySelectionState(false, false, false, false, false, true, true)
394
+ val to = range.to
395
+ if (to != null) {
396
+ if (range.from == to && iso == range.from) {
397
+ return DaySelectionState(true, true, false, true, true, true, true)
398
+ }
399
+ if (iso == range.from) {
400
+ return DaySelectionState(true, true, false, true, false, true, false)
401
+ }
402
+ if (iso == to) {
403
+ return DaySelectionState(true, true, false, false, true, false, true)
404
+ }
405
+ if (iso > range.from && iso < to) {
406
+ return DaySelectionState(true, false, true, false, false, false, false)
407
+ }
408
+ return DaySelectionState(false, false, false, false, false, true, true)
409
+ }
410
+ val isAnchor = iso == range.from
411
+ return DaySelectionState(isAnchor, isAnchor, false, isAnchor, false, true, true)
412
+ }