@niibase/uniwind 1.6.0 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/common/common/utils.js +8 -0
  3. package/dist/common/components/native/ActivityIndicator.js +2 -1
  4. package/dist/common/components/native/Button.js +2 -2
  5. package/dist/common/components/native/FlatList.js +2 -1
  6. package/dist/common/components/native/Image.js +2 -1
  7. package/dist/common/components/native/ImageBackground.js +2 -1
  8. package/dist/common/components/native/InputAccessoryView.js +2 -1
  9. package/dist/common/components/native/Modal.js +2 -1
  10. package/dist/common/components/native/RefreshControl.js +5 -4
  11. package/dist/common/components/native/ScrollView.js +2 -1
  12. package/dist/common/components/native/SectionList.js +2 -1
  13. package/dist/common/components/native/Switch.js +5 -4
  14. package/dist/common/components/native/Text.js +2 -1
  15. package/dist/common/components/native/TextInput.js +6 -5
  16. package/dist/common/components/native/TouchableHighlight.js +2 -1
  17. package/dist/common/components/native/VirtualizedList.js +2 -1
  18. package/dist/common/components/native/useAccentColor.js +19 -0
  19. package/dist/common/components/react-native-gesture-handler/native/FlatList.js +2 -1
  20. package/dist/common/components/react-native-gesture-handler/native/RefreshControl.js +5 -4
  21. package/dist/common/components/react-native-gesture-handler/native/Text.js +2 -1
  22. package/dist/common/components/react-native-gesture-handler/native/TextInput.js +5 -4
  23. package/dist/common/components/web/ActivityIndicator.js +2 -2
  24. package/dist/common/components/web/Button.js +2 -2
  25. package/dist/common/components/web/Image.js +2 -1
  26. package/dist/common/components/web/ImageBackground.js +2 -2
  27. package/dist/common/components/web/Switch.js +4 -4
  28. package/dist/common/components/web/TextInput.js +2 -2
  29. package/dist/common/components/web/TouchableHighlight.js +2 -2
  30. package/dist/common/components/web/generateDataSet.js +2 -1
  31. package/dist/common/components/web/useUniwindAccent.js +20 -0
  32. package/dist/common/core/web/getWebStyles.js +12 -1
  33. package/dist/common/hoc/withUniwind.js +14 -4
  34. package/dist/common/hoc/withUniwind.native.js +11 -4
  35. package/dist/common/hooks/index.js +0 -11
  36. package/dist/common/hooks/useResolveClassNames.js +1 -1
  37. package/dist/metro/index.cjs +1 -1
  38. package/dist/metro/index.mjs +1 -1
  39. package/dist/metro/metro-transformer.cjs +14 -11
  40. package/dist/metro/metro-transformer.mjs +8 -5
  41. package/dist/module/common/utils.d.ts +1 -0
  42. package/dist/module/common/utils.js +1 -0
  43. package/dist/module/components/native/ActivityIndicator.js +2 -1
  44. package/dist/module/components/native/Button.js +2 -2
  45. package/dist/module/components/native/FlatList.js +2 -1
  46. package/dist/module/components/native/Image.js +2 -1
  47. package/dist/module/components/native/ImageBackground.js +2 -1
  48. package/dist/module/components/native/InputAccessoryView.js +2 -1
  49. package/dist/module/components/native/Modal.js +2 -1
  50. package/dist/module/components/native/RefreshControl.js +5 -4
  51. package/dist/module/components/native/ScrollView.js +2 -1
  52. package/dist/module/components/native/SectionList.js +2 -1
  53. package/dist/module/components/native/Switch.js +5 -4
  54. package/dist/module/components/native/Text.js +2 -1
  55. package/dist/module/components/native/TextInput.js +6 -5
  56. package/dist/module/components/native/TouchableHighlight.js +2 -1
  57. package/dist/module/components/native/VirtualizedList.js +2 -1
  58. package/dist/module/components/native/useAccentColor.d.ts +2 -0
  59. package/dist/module/components/native/useAccentColor.js +14 -0
  60. package/dist/module/components/react-native-gesture-handler/native/FlatList.js +2 -1
  61. package/dist/module/components/react-native-gesture-handler/native/RefreshControl.js +5 -4
  62. package/dist/module/components/react-native-gesture-handler/native/Text.js +2 -1
  63. package/dist/module/components/react-native-gesture-handler/native/TextInput.js +5 -4
  64. package/dist/module/components/web/ActivityIndicator.js +1 -1
  65. package/dist/module/components/web/Button.js +1 -1
  66. package/dist/module/components/web/Image.js +2 -1
  67. package/dist/module/components/web/ImageBackground.js +1 -1
  68. package/dist/module/components/web/Switch.js +1 -1
  69. package/dist/module/components/web/TextInput.js +1 -1
  70. package/dist/module/components/web/TouchableHighlight.js +1 -1
  71. package/dist/module/components/web/generateDataSet.d.ts +1 -1
  72. package/dist/module/components/web/generateDataSet.js +2 -1
  73. package/dist/module/components/web/useUniwindAccent.js +15 -0
  74. package/dist/module/core/web/getWebStyles.d.ts +1 -1
  75. package/dist/module/core/web/getWebStyles.js +12 -1
  76. package/dist/module/hoc/withUniwind.js +16 -4
  77. package/dist/module/hoc/withUniwind.native.js +13 -4
  78. package/dist/module/hooks/index.d.ts +0 -1
  79. package/dist/module/hooks/index.js +0 -1
  80. package/dist/module/hooks/useResolveClassNames.js +2 -2
  81. package/dist/module/hooks/useUniwind.d.ts +2 -1
  82. package/dist/shared/{uniwind.C-rHhHOg.mjs → uniwind.BGiqYvxb.mjs} +1 -1
  83. package/dist/shared/{uniwind.nl8746mK.cjs → uniwind.Cv73KtI-.cjs} +0 -2
  84. package/dist/shared/{uniwind.F-0-Rr--.mjs → uniwind.PtWWxxnh.mjs} +1 -2
  85. package/dist/shared/{uniwind.BZyFsest.cjs → uniwind.r2i22V6d.cjs} +1 -1
  86. package/dist/vite/index.cjs +2 -2
  87. package/dist/vite/index.mjs +2 -2
  88. package/package.json +2 -1
  89. package/src/common/utils.ts +1 -0
  90. package/src/components/native/ActivityIndicator.tsx +2 -1
  91. package/src/components/native/Button.tsx +2 -2
  92. package/src/components/native/FlatList.tsx +2 -1
  93. package/src/components/native/Image.tsx +2 -1
  94. package/src/components/native/ImageBackground.tsx +2 -1
  95. package/src/components/native/InputAccessoryView.tsx +2 -1
  96. package/src/components/native/Modal.tsx +2 -1
  97. package/src/components/native/RefreshControl.tsx +5 -4
  98. package/src/components/native/ScrollView.tsx +2 -1
  99. package/src/components/native/SectionList.tsx +2 -1
  100. package/src/components/native/Switch.tsx +5 -4
  101. package/src/components/native/Text.tsx +2 -1
  102. package/src/components/native/TextInput.tsx +6 -5
  103. package/src/components/native/TouchableHighlight.tsx +2 -1
  104. package/src/components/native/VirtualizedList.tsx +2 -1
  105. package/src/components/native/useAccentColor.ts +19 -0
  106. package/src/components/react-native-gesture-handler/native/FlatList.tsx +2 -1
  107. package/src/components/react-native-gesture-handler/native/RefreshControl.tsx +5 -4
  108. package/src/components/react-native-gesture-handler/native/Text.tsx +2 -1
  109. package/src/components/react-native-gesture-handler/native/TextInput.tsx +5 -4
  110. package/src/components/web/ActivityIndicator.tsx +1 -1
  111. package/src/components/web/Button.tsx +1 -1
  112. package/src/components/web/Image.tsx +2 -1
  113. package/src/components/web/ImageBackground.tsx +1 -1
  114. package/src/components/web/Switch.tsx +1 -1
  115. package/src/components/web/TextInput.tsx +1 -1
  116. package/src/components/web/TouchableHighlight.tsx +1 -1
  117. package/src/components/web/generateDataSet.ts +4 -2
  118. package/src/components/web/useUniwindAccent.ts +21 -0
  119. package/src/core/web/getWebStyles.ts +20 -1
  120. package/src/hoc/withUniwind.native.tsx +15 -4
  121. package/src/hoc/withUniwind.tsx +16 -2
  122. package/src/hooks/index.ts +0 -1
  123. package/src/hooks/useResolveClassNames.ts +2 -2
  124. package/src/hooks/useUniwind.ts +2 -2
  125. package/src/metro/addMetaToStylesTemplate.ts +2 -1
  126. package/src/metro/metro-transformer.ts +2 -2
  127. package/src/metro/processor/color.ts +2 -1
  128. package/src/metro/processor/css.ts +3 -1
  129. package/src/metro/processor/rn.ts +2 -1
  130. package/src/metro/utils/common.ts +0 -2
  131. package/dist/common/components/native/TextInput.android.js +0 -52
  132. package/dist/common/hooks/useUniwindAccent.js +0 -13
  133. package/dist/module/components/native/TextInput.android.d.ts +0 -3
  134. package/dist/module/components/native/TextInput.android.js +0 -49
  135. package/dist/module/hooks/useUniwindAccent.js +0 -6
  136. package/src/components/native/TextInput.android.tsx +0 -51
  137. package/src/hooks/useUniwindAccent.ts +0 -10
  138. /package/dist/module/{hooks → components/web}/useUniwindAccent.d.ts +0 -0
@@ -1,5 +1,6 @@
1
1
  import { SectionList as RNSectionList, SectionListProps } from 'react-native'
2
2
  import { copyComponentProperties } from '../utils'
3
+ import { useAccentColor } from './useAccentColor'
3
4
  import { useStyle } from './useStyle'
4
5
 
5
6
  export const SectionList = copyComponentProperties(RNSectionList, (props: SectionListProps<unknown, unknown>) => {
@@ -7,7 +8,7 @@ export const SectionList = copyComponentProperties(RNSectionList, (props: Sectio
7
8
  const contentContainerStyle = useStyle(props.contentContainerClassName, props)
8
9
  const listFooterComponentStyle = useStyle(props.ListFooterComponentClassName, props)
9
10
  const listHeaderComponentStyle = useStyle(props.ListHeaderComponentClassName, props)
10
- const endFillColor = useStyle(props.endFillColorClassName, props).accentColor
11
+ const endFillColor = useAccentColor(props.endFillColorClassName, props)
11
12
 
12
13
  return (
13
14
  <Component
@@ -1,6 +1,7 @@
1
1
  import { Switch as RNSwitch, SwitchProps } from 'react-native'
2
2
  import { ComponentState } from '../../core/types'
3
3
  import { copyComponentProperties } from '../utils'
4
+ import { useAccentColor } from './useAccentColor'
4
5
  import { useStyle } from './useStyle'
5
6
 
6
7
  export const Switch = copyComponentProperties(RNSwitch, (props: SwitchProps) => {
@@ -9,10 +10,10 @@ export const Switch = copyComponentProperties(RNSwitch, (props: SwitchProps) =>
9
10
  isPressed: Boolean(props.value),
10
11
  } satisfies ComponentState
11
12
  const { Component, style } = useStyle(RNSwitch, props.className, props, state)
12
- const trackColorOn = useStyle(props.trackColorOnClassName, props, state).accentColor
13
- const trackColorOff = useStyle(props.trackColorOffClassName, props, state).accentColor
14
- const thumbColor = useStyle(props.thumbColorClassName, props, state).accentColor
15
- const ios_backgroundColor = useStyle(props.ios_backgroundColorClassName, props, state).accentColor
13
+ const trackColorOn = useAccentColor(props.trackColorOnClassName, props, state)
14
+ const trackColorOff = useAccentColor(props.trackColorOffClassName, props, state)
15
+ const thumbColor = useAccentColor(props.thumbColorClassName, props, state)
16
+ const ios_backgroundColor = useAccentColor(props.ios_backgroundColorClassName, props, state)
16
17
 
17
18
  return (
18
19
  <Component
@@ -2,6 +2,7 @@ import { useState } from 'react'
2
2
  import { Text as RNText, TextProps } from 'react-native'
3
3
  import { ComponentState } from '../../core/types'
4
4
  import { copyComponentProperties } from '../utils'
5
+ import { useAccentColor } from './useAccentColor'
5
6
  import { useStyle } from './useStyle'
6
7
 
7
8
  type StyleWithWebkitLineClamp = {
@@ -15,7 +16,7 @@ export const Text = copyComponentProperties(RNText, (props: TextProps) => {
15
16
  isDisabled: Boolean(props.disabled),
16
17
  } satisfies ComponentState
17
18
  const { Component, style } = useStyle(RNText, props.className, props, state)
18
- const selectionColor = useStyle(props.selectionColorClassName, props, state).accentColor
19
+ const selectionColor = useAccentColor(props.selectionColorClassName, props, state)
19
20
 
20
21
  return (
21
22
  <Component
@@ -2,6 +2,7 @@ import { useState } from 'react'
2
2
  import { TextInput as RNTextInput, TextInputProps } from 'react-native'
3
3
  import { ComponentState } from '../../core/types'
4
4
  import { copyComponentProperties } from '../utils'
5
+ import { useAccentColor } from './useAccentColor'
5
6
  import { useStyle } from './useStyle'
6
7
 
7
8
  export const TextInput = copyComponentProperties(RNTextInput, (props: TextInputProps) => {
@@ -13,11 +14,11 @@ export const TextInput = copyComponentProperties(RNTextInput, (props: TextInputP
13
14
  isPressed,
14
15
  } satisfies ComponentState
15
16
  const { Component, style } = useStyle(RNTextInput, props.className, props, state)
16
- const cursorColor = useStyle(props.cursorColorClassName, props, state).accentColor
17
- const selectionColor = useStyle(props.selectionColorClassName, props, state).accentColor
18
- const placeholderTextColor = useStyle(props.placeholderTextColorClassName, props, state).accentColor
19
- const selectionHandleColor = useStyle(props.selectionHandleColorClassName, props, state).accentColor
20
- const underlineColorAndroid = useStyle(props.underlineColorAndroidClassName, props, state).accentColor
17
+ const cursorColor = useAccentColor(props.cursorColorClassName, props, state)
18
+ const selectionColor = useAccentColor(props.selectionColorClassName, props, state)
19
+ const placeholderTextColor = useAccentColor(props.placeholderTextColorClassName, props, state)
20
+ const selectionHandleColor = useAccentColor(props.selectionHandleColorClassName, props, state)
21
+ const underlineColorAndroid = useAccentColor(props.underlineColorAndroidClassName, props, state)
21
22
 
22
23
  return (
23
24
  <Component
@@ -2,6 +2,7 @@ import { useState } from 'react'
2
2
  import { TouchableHighlight as RNTouchableHighlight, TouchableHighlightProps } from 'react-native'
3
3
  import { ComponentState } from '../../core/types'
4
4
  import { copyComponentProperties } from '../utils'
5
+ import { useAccentColor } from './useAccentColor'
5
6
  import { useStyle } from './useStyle'
6
7
 
7
8
  export const TouchableHighlight = copyComponentProperties(RNTouchableHighlight, (props: TouchableHighlightProps) => {
@@ -13,7 +14,7 @@ export const TouchableHighlight = copyComponentProperties(RNTouchableHighlight,
13
14
  isFocused,
14
15
  } satisfies ComponentState
15
16
  const { Component, style } = useStyle(RNTouchableHighlight, props.className, props, state)
16
- const underlayColor = useStyle(props.underlayColorClassName, props, state).accentColor
17
+ const underlayColor = useAccentColor(props.underlayColorClassName, props, state)
17
18
 
18
19
  return (
19
20
  <Component
@@ -1,5 +1,6 @@
1
1
  import { VirtualizedList as RNVirtualizedList, VirtualizedListProps } from 'react-native'
2
2
  import { copyComponentProperties } from '../utils'
3
+ import { useAccentColor } from './useAccentColor'
3
4
  import { useStyle } from './useStyle'
4
5
 
5
6
  export const VirtualizedList = copyComponentProperties(RNVirtualizedList, (props: VirtualizedListProps<unknown>) => {
@@ -7,7 +8,7 @@ export const VirtualizedList = copyComponentProperties(RNVirtualizedList, (props
7
8
  const contentContainerStyle = useStyle(props.contentContainerClassName, props)
8
9
  const listFooterComponentStyle = useStyle(props.ListFooterComponentClassName, props)
9
10
  const listHeaderComponentStyle = useStyle(props.ListHeaderComponentClassName, props)
10
- const endFillColor = useStyle(props.endFillColorClassName, props).accentColor
11
+ const endFillColor = useAccentColor(props.endFillColorClassName, props)
11
12
 
12
13
  return (
13
14
  <Component
@@ -0,0 +1,19 @@
1
+ import { isDefined } from '../../common/utils'
2
+ import { Logger } from '../../core/logger'
3
+ import { ComponentState } from '../../core/types'
4
+ import { useStyle } from './useStyle'
5
+
6
+ let warnedOnce = false
7
+
8
+ export const useAccentColor = (className: string | undefined, componentProps: Record<string, any>, state?: ComponentState) => {
9
+ const styles = useStyle(className, componentProps, state)
10
+
11
+ if (__DEV__ && !warnedOnce && isDefined(className) && className.trim() !== '' && styles.accentColor === undefined) {
12
+ warnedOnce = true
13
+ Logger.warn(
14
+ `className '${className}' was provided to extract accentColor but no color was found. Make sure the className includes a color utility (e.g., 'accent-red-500', 'accent-blue-600'). See https://docs.uniwind.dev/class-names#the-accent-prefix`,
15
+ )
16
+ }
17
+
18
+ return styles.accentColor
19
+ }
@@ -1,5 +1,6 @@
1
1
  import { FlatListProps } from 'react-native'
2
2
  import { FlatList as RNGHFlatList } from 'react-native-gesture-handler'
3
+ import { useAccentColor } from '../../native/useAccentColor'
3
4
  import { useStyle } from '../../native/useStyle'
4
5
  import { copyComponentProperties } from '../../utils'
5
6
 
@@ -9,7 +10,7 @@ export const FlatList = copyComponentProperties(RNGHFlatList, (props: FlatListPr
9
10
  const styleContentContainer = useStyle(props.contentContainerClassName, props)
10
11
  const styleListFooterComponent = useStyle(props.ListFooterComponentClassName, props)
11
12
  const styleListHeaderComponent = useStyle(props.ListHeaderComponentClassName, props)
12
- const endFillColor = useStyle(props.endFillColorClassName, props).accentColor
13
+ const endFillColor = useAccentColor(props.endFillColorClassName, props)
13
14
  const hasSingleColumn = !('numColumns' in props) || props.numColumns === 1
14
15
 
15
16
  return (
@@ -1,14 +1,15 @@
1
1
  import { RefreshControlProps } from 'react-native'
2
2
  import { RefreshControl as RNGHRefreshControl } from 'react-native-gesture-handler'
3
+ import { useAccentColor } from '../../native/useAccentColor'
3
4
  import { useStyle } from '../../native/useStyle'
4
5
  import { copyComponentProperties } from '../../utils'
5
6
 
6
7
  export const RefreshControl = copyComponentProperties(RNGHRefreshControl, (props: RefreshControlProps) => {
7
8
  const style = useStyle(props.className, props)
8
- const color = useStyle(props.colorsClassName, props).accentColor
9
- const tintColor = useStyle(props.tintColorClassName, props).accentColor
10
- const titleColor = useStyle(props.titleColorClassName, props).accentColor
11
- const progressBackgroundColor = useStyle(props.progressBackgroundColorClassName, props).accentColor
9
+ const color = useAccentColor(props.colorsClassName, props)
10
+ const tintColor = useAccentColor(props.tintColorClassName, props)
11
+ const titleColor = useAccentColor(props.titleColorClassName, props)
12
+ const progressBackgroundColor = useAccentColor(props.progressBackgroundColorClassName, props)
12
13
 
13
14
  return (
14
15
  <RNGHRefreshControl
@@ -2,6 +2,7 @@ import { useState } from 'react'
2
2
  import { TextProps } from 'react-native'
3
3
  import { Text as RNGHText } from 'react-native-gesture-handler'
4
4
  import { ComponentState } from '../../../core/types'
5
+ import { useAccentColor } from '../../native/useAccentColor'
5
6
  import { useStyle } from '../../native/useStyle'
6
7
  import { copyComponentProperties } from '../../utils'
7
8
 
@@ -16,7 +17,7 @@ export const Text = copyComponentProperties(RNGHText, (props: TextProps) => {
16
17
  isDisabled: Boolean(props.disabled),
17
18
  } satisfies ComponentState
18
19
  const style = useStyle(props.className, props, state)
19
- const selectionColor = useStyle(props.selectionColorClassName, props, state).accentColor
20
+ const selectionColor = useAccentColor(props.selectionColorClassName, props, state)
20
21
 
21
22
  return (
22
23
  <RNGHText
@@ -2,6 +2,7 @@ import { useState } from 'react'
2
2
  import { TextInputProps } from 'react-native'
3
3
  import { TextInput as RNGHTextInput } from 'react-native-gesture-handler'
4
4
  import { ComponentState } from '../../../core/types'
5
+ import { useAccentColor } from '../../native/useAccentColor'
5
6
  import { useStyle } from '../../native/useStyle'
6
7
  import { copyComponentProperties } from '../../utils'
7
8
 
@@ -15,10 +16,10 @@ export const TextInput = copyComponentProperties(RNGHTextInput, (props: TextInpu
15
16
  } satisfies ComponentState
16
17
  const style = useStyle(props.className, props, state)
17
18
  const cursorColor = useStyle(props.cursorColorClassName, props, state).accentColor
18
- const selectionColor = useStyle(props.selectionColorClassName, props, state).accentColor
19
- const placeholderTextColor = useStyle(props.placeholderTextColorClassName, props, state).accentColor
20
- const selectionHandleColor = useStyle(props.selectionHandleColorClassName, props, state).accentColor
21
- const underlineColorAndroid = useStyle(props.underlineColorAndroidClassName, props, state).accentColor
19
+ const selectionColor = useAccentColor(props.selectionColorClassName, props, state)
20
+ const placeholderTextColor = useAccentColor(props.placeholderTextColorClassName, props, state)
21
+ const selectionHandleColor = useAccentColor(props.selectionHandleColorClassName, props, state)
22
+ const underlineColorAndroid = useAccentColor(props.underlineColorAndroidClassName, props, state)
22
23
 
23
24
  return (
24
25
  <RNGHTextInput
@@ -1,8 +1,8 @@
1
1
  import { ActivityIndicator as RNActivityIndicator, ActivityIndicatorProps } from 'react-native'
2
- import { useUniwindAccent } from '../../hooks'
3
2
  import { copyComponentProperties } from '../utils'
4
3
  import { generateDataSet } from './generateDataSet'
5
4
  import { toRNWClassName } from './rnw'
5
+ import { useUniwindAccent } from './useUniwindAccent'
6
6
 
7
7
  export const ActivityIndicator = copyComponentProperties(RNActivityIndicator, (props: ActivityIndicatorProps) => {
8
8
  const color = useUniwindAccent(props.colorClassName)
@@ -1,7 +1,7 @@
1
1
  import { Button as RNButton, ButtonProps } from 'react-native'
2
- import { useUniwindAccent } from '../../hooks'
3
2
  import { copyComponentProperties } from '../utils'
4
3
  import { generateDataSet } from './generateDataSet'
4
+ import { useUniwindAccent } from './useUniwindAccent'
5
5
 
6
6
  export const Button = copyComponentProperties(RNButton, (props: ButtonProps) => {
7
7
  const color = useUniwindAccent(props.colorClassName)
@@ -1,8 +1,9 @@
1
1
  import { Image as RNImage, ImageProps } from 'react-native'
2
- import { useResolveClassNames, useUniwindAccent } from '../../hooks'
2
+ import { useResolveClassNames } from '../../hooks'
3
3
  import { copyComponentProperties } from '../utils'
4
4
  import { generateDataSet } from './generateDataSet'
5
5
  import { toRNWClassName } from './rnw'
6
+ import { useUniwindAccent } from './useUniwindAccent'
6
7
 
7
8
  export const Image = copyComponentProperties(RNImage, (props: ImageProps) => {
8
9
  const tintColor = useUniwindAccent(props.tintColorClassName)
@@ -1,8 +1,8 @@
1
1
  import { ImageBackground as RNImageBackground, ImageBackgroundProps } from 'react-native'
2
- import { useUniwindAccent } from '../../hooks'
3
2
  import { copyComponentProperties } from '../utils'
4
3
  import { generateDataSet } from './generateDataSet'
5
4
  import { toRNWClassName } from './rnw'
5
+ import { useUniwindAccent } from './useUniwindAccent'
6
6
 
7
7
  export const ImageBackground = copyComponentProperties(RNImageBackground, (props: ImageBackgroundProps) => {
8
8
  const tintColor = useUniwindAccent(props.tintColorClassName)
@@ -1,8 +1,8 @@
1
1
  import { Switch as RNSwitch, SwitchProps } from 'react-native'
2
- import { useUniwindAccent } from '../../hooks'
3
2
  import { copyComponentProperties } from '../utils'
4
3
  import { generateDataSet } from './generateDataSet'
5
4
  import { toRNWClassName } from './rnw'
5
+ import { useUniwindAccent } from './useUniwindAccent'
6
6
 
7
7
  export const Switch = copyComponentProperties(RNSwitch, (props: SwitchProps) => {
8
8
  const trackColorOn = useUniwindAccent(props.trackColorOnClassName)
@@ -1,8 +1,8 @@
1
1
  import { TextInput as RNTextInput, TextInputProps } from 'react-native'
2
- import { useUniwindAccent } from '../../hooks'
3
2
  import { copyComponentProperties } from '../utils'
4
3
  import { generateDataSet } from './generateDataSet'
5
4
  import { toRNWClassName } from './rnw'
5
+ import { useUniwindAccent } from './useUniwindAccent'
6
6
 
7
7
  export const TextInput = copyComponentProperties(RNTextInput, (props: TextInputProps) => {
8
8
  const placeholderTextColor = useUniwindAccent(props.placeholderTextColorClassName)
@@ -1,8 +1,8 @@
1
1
  import { TouchableHighlight as RNTouchableHighlight, TouchableHighlightProps } from 'react-native'
2
- import { useUniwindAccent } from '../../hooks'
3
2
  import { copyComponentProperties } from '../utils'
4
3
  import { generateDataSet } from './generateDataSet'
5
4
  import { toRNWClassName } from './rnw'
5
+ import { useUniwindAccent } from './useUniwindAccent'
6
6
 
7
7
  export const TouchableHighlight = copyComponentProperties(RNTouchableHighlight, (props: TouchableHighlightProps) => {
8
8
  const underlayColor = useUniwindAccent(props.underlayColorClassName)
@@ -1,17 +1,19 @@
1
+ const toCamelCase = (str: string) => str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())
2
+
1
3
  export const generateDataSet = (props: Record<PropertyKey, any>) => {
2
4
  const dataSet: DataSet = props.dataSet !== undefined ? { ...props.dataSet } : {}
3
5
 
4
6
  Object.entries(props).forEach(([key, value]) => {
5
7
  if (key.startsWith('data-')) {
6
8
  // Remove data- prefix
7
- dataSet[key.slice(5)] = value
9
+ dataSet[toCamelCase(key.slice(5))] = value
8
10
  }
9
11
  })
10
12
 
11
13
  return dataSet
12
14
  }
13
15
 
14
- type DataSet = Record<string, string | boolean>
16
+ type DataSet = Record<string, string | boolean | undefined>
15
17
 
16
18
  declare module 'react-native' {
17
19
  interface SwitchProps {
@@ -0,0 +1,21 @@
1
+ import { isDefined } from '../../common/utils'
2
+ import { Logger } from '../../core/logger'
3
+ import { formatColor } from '../../core/web/formatColor'
4
+ import { useResolveClassNames } from '../../hooks/useResolveClassNames'
5
+
6
+ let warnedOnce = false
7
+
8
+ export const useUniwindAccent = (className: string | undefined) => {
9
+ const styles = useResolveClassNames(className ?? '')
10
+
11
+ if (__DEV__ && !warnedOnce && isDefined(className) && className.trim() !== '' && styles.accentColor === undefined) {
12
+ warnedOnce = true
13
+ Logger.warn(
14
+ `className '${className}' was provided to extract accentColor but no color was found. Make sure the className includes a color utility (e.g., 'accent-red-500', 'accent-blue-600'). See https://docs.uniwind.dev/class-names#the-accent-prefix`,
15
+ )
16
+ }
17
+
18
+ return styles.accentColor !== undefined
19
+ ? formatColor(styles.accentColor)
20
+ : undefined
21
+ }
@@ -1,3 +1,4 @@
1
+ import { generateDataSet } from '../../components/web/generateDataSet'
1
2
  import { RNStyle, UniwindContextType } from '../types'
2
3
  import { CSSListener } from './cssListener'
3
4
  import { parseCSSValue } from './parseCSSValue'
@@ -52,7 +53,11 @@ const getActiveStylesForClass = (className: string) => {
52
53
  return extractedStyles
53
54
  }
54
55
 
55
- export const getWebStyles = (className: string | undefined, uniwindContext: UniwindContextType): RNStyle => {
56
+ export const getWebStyles = (
57
+ className: string | undefined,
58
+ componentProps: Record<string, unknown> | undefined,
59
+ uniwindContext: UniwindContextType,
60
+ ): RNStyle => {
56
61
  if (className === undefined) {
57
62
  return {}
58
63
  }
@@ -69,8 +74,22 @@ export const getWebStyles = (className: string | undefined, uniwindContext: Uniw
69
74
 
70
75
  dummy.className = className
71
76
 
77
+ const dataSet = generateDataSet(componentProps ?? {})
78
+
79
+ Object.entries(dataSet).forEach(([key, value]) => {
80
+ if (value === false || value === undefined) {
81
+ return
82
+ }
83
+
84
+ dummy.dataset[key] = String(value)
85
+ })
86
+
72
87
  const computedStyles = getActiveStylesForClass(className)
73
88
 
89
+ Object.keys(dataSet).forEach(key => {
90
+ delete dummy.dataset[key]
91
+ })
92
+
74
93
  return Object.fromEntries(
75
94
  Object.entries(computedStyles)
76
95
  .map(([key, value]) => {
@@ -1,11 +1,15 @@
1
1
  import { ComponentProps, useLayoutEffect, useReducer } from 'react'
2
+ import { isDefined } from '../common/utils'
2
3
  import { useUniwindContext } from '../core/context'
3
4
  import { UniwindListener } from '../core/listener'
5
+ import { Logger } from '../core/logger'
4
6
  import { UniwindStore } from '../core/native'
5
7
  import { StyleDependency } from '../types'
6
8
  import { AnyObject, Component, OptionMapping, WithUniwind } from './types'
7
9
  import { classToColor, classToStyle, isClassProperty, isColorClassProperty, isStyleProperty } from './withUniwindUtils'
8
10
 
11
+ let warnedOnce = false
12
+
9
13
  export const withUniwind: WithUniwind = <
10
14
  TComponent extends Component,
11
15
  TOptions extends Record<keyof ComponentProps<TComponent>, OptionMapping>,
@@ -26,7 +30,14 @@ const withAutoUniwind = (Component: Component<AnyObject>) => (props: AnyObject)
26
30
  return acc
27
31
  }
28
32
 
29
- const { styles, dependencies } = UniwindStore.getStyles(propValue, undefined, undefined, uniwindContext)
33
+ const { styles, dependencies } = UniwindStore.getStyles(propValue, props, undefined, uniwindContext)
34
+
35
+ if (__DEV__ && !warnedOnce && isDefined(propValue) && propValue.trim() !== '' && styles.accentColor === undefined) {
36
+ warnedOnce = true
37
+ Logger.warn(
38
+ `className '${propValue}' was provided to extract accentColor but no color was found. Make sure the className includes a color utility (e.g., 'accent-red-500', 'accent-blue-600'). See https://docs.uniwind.dev/class-names#the-accent-prefix`,
39
+ )
40
+ }
30
41
 
31
42
  acc.dependencies.push(...dependencies)
32
43
  acc.generatedProps[colorProp] = styles.accentColor
@@ -36,7 +47,7 @@ const withAutoUniwind = (Component: Component<AnyObject>) => (props: AnyObject)
36
47
 
37
48
  if (isClassProperty(propName)) {
38
49
  const styleProp = classToStyle(propName)
39
- const { styles, dependencies } = UniwindStore.getStyles(propValue, undefined, undefined, uniwindContext)
50
+ const { styles, dependencies } = UniwindStore.getStyles(propValue, props, undefined, uniwindContext)
40
51
 
41
52
  acc.dependencies.push(...dependencies)
42
53
  acc.generatedProps[styleProp] ??= []
@@ -90,7 +101,7 @@ const withManualUniwind = (Component: Component<AnyObject>, options: Record<Prop
90
101
  return acc
91
102
  }
92
103
 
93
- const { styles, dependencies } = UniwindStore.getStyles(className, undefined, undefined, uniwindContext)
104
+ const { styles, dependencies } = UniwindStore.getStyles(className, props, undefined, uniwindContext)
94
105
 
95
106
  acc.generatedProps[propName] = styles[option.styleProperty]
96
107
  acc.dependencies.push(...dependencies)
@@ -98,7 +109,7 @@ const withManualUniwind = (Component: Component<AnyObject>, options: Record<Prop
98
109
  return acc
99
110
  }
100
111
 
101
- const { styles, dependencies } = UniwindStore.getStyles(className, undefined, undefined, uniwindContext)
112
+ const { styles, dependencies } = UniwindStore.getStyles(className, props, undefined, uniwindContext)
102
113
  acc.dependencies.push(...dependencies)
103
114
 
104
115
  if (!isStyleProperty(propName)) {
@@ -1,9 +1,14 @@
1
1
  import { ComponentProps, useLayoutEffect, useReducer } from 'react'
2
+ import { isDefined } from '../common/utils'
3
+ import { generateDataSet } from '../components/web/generateDataSet'
2
4
  import { useUniwindContext } from '../core/context'
5
+ import { Logger } from '../core/logger'
3
6
  import { CSSListener, formatColor, getWebStyles } from '../core/web'
4
7
  import { AnyObject, Component, OptionMapping, WithUniwind } from './types'
5
8
  import { classToColor, classToStyle, isClassProperty, isColorClassProperty, isStyleProperty } from './withUniwindUtils'
6
9
 
10
+ let warnedOnce = false
11
+
7
12
  export const withUniwind: WithUniwind = <
8
13
  TComponent extends Component,
9
14
  TOptions extends Record<keyof ComponentProps<TComponent>, OptionMapping>,
@@ -26,7 +31,14 @@ const withAutoUniwind = (Component: Component<AnyObject>) => (props: AnyObject)
26
31
  }
27
32
 
28
33
  const className = propValue
29
- const color = getWebStyles(className, uniwindContext).accentColor
34
+ const color = getWebStyles(className, props, uniwindContext).accentColor
35
+
36
+ if (__DEV__ && !warnedOnce && isDefined(className) && className.trim() !== '' && color === undefined) {
37
+ warnedOnce = true
38
+ Logger.warn(
39
+ `className '${className}' was provided to extract accentColor but no color was found. Make sure the className includes a color utility (e.g., 'accent-red-500', 'accent-blue-600'). See https://docs.uniwind.dev/class-names#the-accent-prefix`,
40
+ )
41
+ }
30
42
 
31
43
  acc.generatedProps[colorProp] = color !== undefined
32
44
  ? formatColor(color)
@@ -67,6 +79,7 @@ const withAutoUniwind = (Component: Component<AnyObject>) => (props: AnyObject)
67
79
  <Component
68
80
  {...props}
69
81
  {...generatedProps}
82
+ dataSet={generateDataSet(props)}
70
83
  />
71
84
  )
72
85
  }
@@ -87,7 +100,7 @@ const withManualUniwind = (Component: Component<AnyObject>, options: Record<Prop
87
100
  return acc
88
101
  }
89
102
 
90
- const value = getWebStyles(className, uniwindContext)[option.styleProperty]
103
+ const value = getWebStyles(className, props, uniwindContext)[option.styleProperty]
91
104
  const transformedValue = value !== undefined && option.styleProperty.toLowerCase().includes('color')
92
105
  ? formatColor(value as string)
93
106
  : value
@@ -115,6 +128,7 @@ const withManualUniwind = (Component: Component<AnyObject>, options: Record<Prop
115
128
  <Component
116
129
  {...props}
117
130
  {...generatedProps}
131
+ dataSet={generateDataSet(props)}
118
132
  />
119
133
  )
120
134
  }
@@ -1,4 +1,3 @@
1
1
  export * from './useCSSVariable'
2
2
  export * from './useResolveClassNames'
3
3
  export * from './useUniwind'
4
- export * from './useUniwindAccent'
@@ -8,9 +8,9 @@ const emptyState = {} as RNStyle
8
8
  export const useResolveClassNames = (className: string) => {
9
9
  const uniwindContext = useUniwindContext()
10
10
  const [styles, recreate] = useReducer(
11
- () => className !== '' ? getWebStyles(className, uniwindContext) : emptyState,
11
+ () => className !== '' ? getWebStyles(className, undefined, uniwindContext) : emptyState,
12
12
  undefined,
13
- () => className !== '' ? getWebStyles(className, uniwindContext) : emptyState,
13
+ () => className !== '' ? getWebStyles(className, undefined, uniwindContext) : emptyState,
14
14
  )
15
15
 
16
16
  useLayoutEffect(() => {
@@ -5,7 +5,7 @@ import { UniwindListener } from '../core/listener'
5
5
  import { ThemeName } from '../core/types'
6
6
  import { StyleDependency } from '../types'
7
7
 
8
- export const useUniwind = () => {
8
+ export const useUniwind = (): { theme: ThemeName; hasAdaptiveThemes: boolean } => {
9
9
  const uniwindContext = useUniwindContext()
10
10
  const [theme, setTheme] = useState(Uniwind.currentTheme)
11
11
  const [hasAdaptiveThemes, setHasAdaptiveThemes] = useState(Uniwind.hasAdaptiveThemes)
@@ -26,7 +26,7 @@ export const useUniwind = () => {
26
26
  }, [uniwindContext])
27
27
 
28
28
  return {
29
- theme: uniwindContext.scopedTheme ?? theme as ThemeName,
29
+ theme: uniwindContext.scopedTheme ?? theme,
30
30
  hasAdaptiveThemes: uniwindContext.scopedTheme !== null ? false : hasAdaptiveThemes,
31
31
  }
32
32
  }
@@ -1,8 +1,9 @@
1
1
  import { Platform } from '../common/consts'
2
+ import { isDefined } from '../common/utils'
2
3
  import { StyleDependency } from '../types'
3
4
  import { ProcessorBuilder } from './processor'
4
5
  import { StyleSheetTemplate } from './types'
5
- import { isDefined, serialize, toCamelCase } from './utils'
6
+ import { serialize, toCamelCase } from './utils'
6
7
 
7
8
  const extractVarsFromString = (value: string) => {
8
9
  const thisIndexes = [...value.matchAll(/this\[/g)].map(m => m.index)
@@ -30,7 +30,7 @@ export const transform = async (
30
30
  data: Buffer,
31
31
  options: JsTransformOptions,
32
32
  ) => {
33
- const isCss = options.type !== 'asset' && path.join(process.cwd(), config.uniwind.cssEntryFile) === path.join(process.cwd(), filePath)
33
+ const isCss = options.type !== 'asset' && path.join(process.cwd(), config.uniwind.cssEntryFile) === path.join(projectRoot, filePath)
34
34
 
35
35
  if (filePath.endsWith('/components/web/metro-injected.js')) {
36
36
  const cssPath = path.join(process.cwd(), config.uniwind.cssEntryFile)
@@ -75,7 +75,7 @@ export const transform = async (
75
75
  themes: config.uniwind.themes,
76
76
  dtsPath: config.uniwind.dtsFile,
77
77
  })
78
- const css = fs.readFileSync(filePath, 'utf-8')
78
+ const css = fs.readFileSync(cssPath, 'utf-8')
79
79
  const platform = getPlatform()
80
80
  const virtualCode = await compileVirtual({
81
81
  css,
@@ -57,8 +57,9 @@ export class Color {
57
57
  })
58
58
  }
59
59
 
60
+ const colorType = color.type === 'display-p3' ? 'p3' : color.type
60
61
  const result = this.toRgb({
61
- mode: color.type,
62
+ mode: colorType,
62
63
  ...color,
63
64
  } as ColorType)
64
65
 
@@ -1,9 +1,11 @@
1
1
  /* eslint-disable max-lines */
2
2
 
3
3
  import { Animation, Filter, OverflowKeyword, TokenOrValue } from 'lightningcss'
4
+
5
+ import { isDefined } from '../../common/utils'
4
6
  import { Logger } from '../logger'
5
7
  import { DeclarationValues } from '../types'
6
- import { deepEqual, isDefined, pipe, roundToPrecision, shouldBeSerialized, toCamelCase } from '../utils'
8
+ import { deepEqual, pipe, roundToPrecision, shouldBeSerialized, toCamelCase } from '../utils'
7
9
  import { getProcessedAnimation, getProcessedVarAnimation } from './animation'
8
10
  import type { ProcessorBuilder } from './processor'
9
11
 
@@ -1,4 +1,5 @@
1
- import { addMissingSpaces, isDefined, pipe, removeKeys, toCamelCase } from '../utils'
1
+ import { isDefined } from '../../common/utils'
2
+ import { addMissingSpaces, pipe, removeKeys, toCamelCase } from '../utils'
2
3
  import type { ProcessorBuilder } from './processor'
3
4
 
4
5
  const transitions: Record<string, any> = { overlay: '"overlayColor"' }
@@ -1,5 +1,3 @@
1
- export const isDefined = <T>(value: T): value is NonNullable<T> => value !== null && value !== undefined
2
-
3
1
  export const toCamelCase = (str: string) => str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())
4
2
 
5
3
  type P<I, O> = (data: I) => O