@niibase/uniwind 1.6.1 → 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.
- package/CHANGELOG.md +24 -0
- package/dist/common/common/utils.js +8 -0
- package/dist/common/components/native/ActivityIndicator.js +2 -1
- package/dist/common/components/native/Button.js +2 -2
- package/dist/common/components/native/FlatList.js +2 -1
- package/dist/common/components/native/Image.js +2 -1
- package/dist/common/components/native/ImageBackground.js +2 -1
- package/dist/common/components/native/InputAccessoryView.js +2 -1
- package/dist/common/components/native/Modal.js +2 -1
- package/dist/common/components/native/RefreshControl.js +5 -4
- package/dist/common/components/native/ScrollView.js +2 -1
- package/dist/common/components/native/SectionList.js +2 -1
- package/dist/common/components/native/Switch.js +5 -4
- package/dist/common/components/native/Text.js +2 -1
- package/dist/common/components/native/TextInput.js +6 -5
- package/dist/common/components/native/TouchableHighlight.js +2 -1
- package/dist/common/components/native/VirtualizedList.js +2 -1
- package/dist/common/components/native/useAccentColor.js +19 -0
- package/dist/common/components/react-native-gesture-handler/native/FlatList.js +2 -1
- package/dist/common/components/react-native-gesture-handler/native/RefreshControl.js +5 -4
- package/dist/common/components/react-native-gesture-handler/native/Text.js +2 -1
- package/dist/common/components/react-native-gesture-handler/native/TextInput.js +5 -4
- package/dist/common/components/web/ActivityIndicator.js +2 -2
- package/dist/common/components/web/Button.js +2 -2
- package/dist/common/components/web/Image.js +2 -1
- package/dist/common/components/web/ImageBackground.js +2 -2
- package/dist/common/components/web/Switch.js +4 -4
- package/dist/common/components/web/TextInput.js +2 -2
- package/dist/common/components/web/TouchableHighlight.js +2 -2
- package/dist/common/components/web/useUniwindAccent.js +20 -0
- package/dist/common/hoc/withUniwind.js +7 -0
- package/dist/common/hoc/withUniwind.native.js +7 -0
- package/dist/common/hooks/index.js +0 -11
- package/dist/metro/index.cjs +1 -1
- package/dist/metro/index.mjs +1 -1
- package/dist/metro/metro-transformer.cjs +12 -10
- package/dist/metro/metro-transformer.mjs +6 -4
- package/dist/module/common/utils.d.ts +1 -0
- package/dist/module/common/utils.js +1 -0
- package/dist/module/components/native/ActivityIndicator.js +2 -1
- package/dist/module/components/native/Button.js +2 -2
- package/dist/module/components/native/FlatList.js +2 -1
- package/dist/module/components/native/Image.js +2 -1
- package/dist/module/components/native/ImageBackground.js +2 -1
- package/dist/module/components/native/InputAccessoryView.js +2 -1
- package/dist/module/components/native/Modal.js +2 -1
- package/dist/module/components/native/RefreshControl.js +5 -4
- package/dist/module/components/native/ScrollView.js +2 -1
- package/dist/module/components/native/SectionList.js +2 -1
- package/dist/module/components/native/Switch.js +5 -4
- package/dist/module/components/native/Text.js +2 -1
- package/dist/module/components/native/TextInput.js +6 -5
- package/dist/module/components/native/TouchableHighlight.js +2 -1
- package/dist/module/components/native/VirtualizedList.js +2 -1
- package/dist/module/components/native/useAccentColor.d.ts +2 -0
- package/dist/module/components/native/useAccentColor.js +14 -0
- package/dist/module/components/react-native-gesture-handler/native/FlatList.js +2 -1
- package/dist/module/components/react-native-gesture-handler/native/RefreshControl.js +5 -4
- package/dist/module/components/react-native-gesture-handler/native/Text.js +2 -1
- package/dist/module/components/react-native-gesture-handler/native/TextInput.js +5 -4
- package/dist/module/components/web/ActivityIndicator.js +1 -1
- package/dist/module/components/web/Button.js +1 -1
- package/dist/module/components/web/Image.js +2 -1
- package/dist/module/components/web/ImageBackground.js +1 -1
- package/dist/module/components/web/Switch.js +1 -1
- package/dist/module/components/web/TextInput.js +1 -1
- package/dist/module/components/web/TouchableHighlight.js +1 -1
- package/dist/module/components/web/useUniwindAccent.js +15 -0
- package/dist/module/hoc/withUniwind.js +9 -0
- package/dist/module/hoc/withUniwind.native.js +9 -0
- package/dist/module/hooks/index.d.ts +0 -1
- package/dist/module/hooks/index.js +0 -1
- package/dist/shared/{uniwind.C-rHhHOg.mjs → uniwind.BGiqYvxb.mjs} +1 -1
- package/dist/shared/{uniwind.nl8746mK.cjs → uniwind.Cv73KtI-.cjs} +0 -2
- package/dist/shared/{uniwind.F-0-Rr--.mjs → uniwind.PtWWxxnh.mjs} +1 -2
- package/dist/shared/{uniwind.BZyFsest.cjs → uniwind.r2i22V6d.cjs} +1 -1
- package/dist/vite/index.cjs +2 -2
- package/dist/vite/index.mjs +2 -2
- package/package.json +1 -1
- package/src/common/utils.ts +1 -0
- package/src/components/native/ActivityIndicator.tsx +2 -1
- package/src/components/native/Button.tsx +2 -2
- package/src/components/native/FlatList.tsx +2 -1
- package/src/components/native/Image.tsx +2 -1
- package/src/components/native/ImageBackground.tsx +2 -1
- package/src/components/native/InputAccessoryView.tsx +2 -1
- package/src/components/native/Modal.tsx +2 -1
- package/src/components/native/RefreshControl.tsx +5 -4
- package/src/components/native/ScrollView.tsx +2 -1
- package/src/components/native/SectionList.tsx +2 -1
- package/src/components/native/Switch.tsx +5 -4
- package/src/components/native/Text.tsx +2 -1
- package/src/components/native/TextInput.tsx +6 -5
- package/src/components/native/TouchableHighlight.tsx +2 -1
- package/src/components/native/VirtualizedList.tsx +2 -1
- package/src/components/native/useAccentColor.ts +19 -0
- package/src/components/react-native-gesture-handler/native/FlatList.tsx +2 -1
- package/src/components/react-native-gesture-handler/native/RefreshControl.tsx +5 -4
- package/src/components/react-native-gesture-handler/native/Text.tsx +2 -1
- package/src/components/react-native-gesture-handler/native/TextInput.tsx +5 -4
- package/src/components/web/ActivityIndicator.tsx +1 -1
- package/src/components/web/Button.tsx +1 -1
- package/src/components/web/Image.tsx +2 -1
- package/src/components/web/ImageBackground.tsx +1 -1
- package/src/components/web/Switch.tsx +1 -1
- package/src/components/web/TextInput.tsx +1 -1
- package/src/components/web/TouchableHighlight.tsx +1 -1
- package/src/components/web/useUniwindAccent.ts +21 -0
- package/src/hoc/withUniwind.native.tsx +11 -0
- package/src/hoc/withUniwind.tsx +11 -0
- package/src/hooks/index.ts +0 -1
- package/src/metro/addMetaToStylesTemplate.ts +2 -1
- package/src/metro/metro-transformer.ts +2 -2
- package/src/metro/processor/css.ts +3 -1
- package/src/metro/processor/rn.ts +2 -1
- package/src/metro/utils/common.ts +0 -2
- package/dist/common/components/native/TextInput.android.js +0 -52
- package/dist/common/hooks/useUniwindAccent.js +0 -13
- package/dist/module/components/native/TextInput.android.d.ts +0 -3
- package/dist/module/components/native/TextInput.android.js +0 -49
- package/dist/module/hooks/useUniwindAccent.js +0 -6
- package/src/components/native/TextInput.android.tsx +0 -51
- package/src/hooks/useUniwindAccent.ts +0 -10
- /package/dist/module/{hooks → components/web}/useUniwindAccent.d.ts +0 -0
|
@@ -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,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>,
|
|
@@ -28,6 +32,13 @@ const withAutoUniwind = (Component: Component<AnyObject>) => (props: AnyObject)
|
|
|
28
32
|
|
|
29
33
|
const { styles, dependencies } = UniwindStore.getStyles(propValue, props, undefined, uniwindContext)
|
|
30
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
|
+
}
|
|
41
|
+
|
|
31
42
|
acc.dependencies.push(...dependencies)
|
|
32
43
|
acc.generatedProps[colorProp] = styles.accentColor
|
|
33
44
|
|
package/src/hoc/withUniwind.tsx
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { ComponentProps, useLayoutEffect, useReducer } from 'react'
|
|
2
|
+
import { isDefined } from '../common/utils'
|
|
2
3
|
import { generateDataSet } from '../components/web/generateDataSet'
|
|
3
4
|
import { useUniwindContext } from '../core/context'
|
|
5
|
+
import { Logger } from '../core/logger'
|
|
4
6
|
import { CSSListener, formatColor, getWebStyles } from '../core/web'
|
|
5
7
|
import { AnyObject, Component, OptionMapping, WithUniwind } from './types'
|
|
6
8
|
import { classToColor, classToStyle, isClassProperty, isColorClassProperty, isStyleProperty } from './withUniwindUtils'
|
|
7
9
|
|
|
10
|
+
let warnedOnce = false
|
|
11
|
+
|
|
8
12
|
export const withUniwind: WithUniwind = <
|
|
9
13
|
TComponent extends Component,
|
|
10
14
|
TOptions extends Record<keyof ComponentProps<TComponent>, OptionMapping>,
|
|
@@ -29,6 +33,13 @@ const withAutoUniwind = (Component: Component<AnyObject>) => (props: AnyObject)
|
|
|
29
33
|
const className = propValue
|
|
30
34
|
const color = getWebStyles(className, props, uniwindContext).accentColor
|
|
31
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
|
+
}
|
|
42
|
+
|
|
32
43
|
acc.generatedProps[colorProp] = color !== undefined
|
|
33
44
|
? formatColor(color)
|
|
34
45
|
: undefined
|
package/src/hooks/index.ts
CHANGED
|
@@ -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 {
|
|
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(
|
|
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(
|
|
78
|
+
const css = fs.readFileSync(cssPath, 'utf-8')
|
|
79
79
|
const platform = getPlatform()
|
|
80
80
|
const virtualCode = await compileVirtual({
|
|
81
81
|
css,
|
|
@@ -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,
|
|
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 {
|
|
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,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
module.exports = exports.TextInput = void 0;
|
|
7
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
-
var _react = require("react");
|
|
9
|
-
var _reactNative = require("react-native");
|
|
10
|
-
var _utils = require("../utils");
|
|
11
|
-
var _useStyle = require("./useStyle");
|
|
12
|
-
const TextInput = exports.TextInput = (0, _utils.copyComponentProperties)(_reactNative.TextInput, props => {
|
|
13
|
-
const [isFocused, setIsFocused] = (0, _react.useState)(false);
|
|
14
|
-
const [isPressed, setIsPressed] = (0, _react.useState)(false);
|
|
15
|
-
const state = {
|
|
16
|
-
isDisabled: props.editable === false,
|
|
17
|
-
isFocused,
|
|
18
|
-
isPressed
|
|
19
|
-
};
|
|
20
|
-
const style = (0, _useStyle.useStyle)(props.className, props, state);
|
|
21
|
-
const cursorColor = (0, _useStyle.useStyle)(props.cursorColorClassName, props, state).accentColor;
|
|
22
|
-
const selectionColor = (0, _useStyle.useStyle)(props.selectionColorClassName, props, state).accentColor;
|
|
23
|
-
const placeholderTextColor = (0, _useStyle.useStyle)(props.placeholderTextColorClassName, props, state).accentColor;
|
|
24
|
-
const selectionHandleColor = (0, _useStyle.useStyle)(props.selectionHandleColorClassName, props, state).accentColor;
|
|
25
|
-
const underlineColorAndroid = (0, _useStyle.useStyle)(props.underlineColorAndroidClassName, props, state).accentColor;
|
|
26
|
-
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_reactNative.TextInput, {
|
|
27
|
-
...props,
|
|
28
|
-
style: [style, props.style],
|
|
29
|
-
cursorColor: props.cursorColor ?? cursorColor,
|
|
30
|
-
selectionColor: props.selectionColor ?? selectionColor,
|
|
31
|
-
placeholderTextColor: props.placeholderTextColor ?? placeholderTextColor,
|
|
32
|
-
selectionHandleColor: props.selectionHandleColor ?? selectionHandleColor,
|
|
33
|
-
underlineColorAndroid: props.underlineColorAndroid ?? underlineColorAndroid,
|
|
34
|
-
onFocus: event => {
|
|
35
|
-
setIsFocused(true);
|
|
36
|
-
props.onFocus?.(event);
|
|
37
|
-
},
|
|
38
|
-
onBlur: event => {
|
|
39
|
-
setIsFocused(false);
|
|
40
|
-
props.onBlur?.(event);
|
|
41
|
-
},
|
|
42
|
-
onPressIn: event => {
|
|
43
|
-
setIsPressed(true);
|
|
44
|
-
props.onPressIn?.(event);
|
|
45
|
-
},
|
|
46
|
-
onPressOut: event => {
|
|
47
|
-
setIsPressed(false);
|
|
48
|
-
props.onPressOut?.(event);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
module.exports = TextInput;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useUniwindAccent = void 0;
|
|
7
|
-
var _formatColor = require("../core/web/formatColor");
|
|
8
|
-
var _useResolveClassNames = require("./useResolveClassNames");
|
|
9
|
-
const useUniwindAccent = className => {
|
|
10
|
-
const styles = (0, _useResolveClassNames.useResolveClassNames)(className ?? "");
|
|
11
|
-
return styles.accentColor !== void 0 ? (0, _formatColor.formatColor)(styles.accentColor) : void 0;
|
|
12
|
-
};
|
|
13
|
-
exports.useUniwindAccent = useUniwindAccent;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
import { TextInput as RNTextInput } from "react-native";
|
|
4
|
-
import { copyComponentProperties } from "../utils.js";
|
|
5
|
-
import { useStyle } from "./useStyle.js";
|
|
6
|
-
export const TextInput = copyComponentProperties(RNTextInput, (props) => {
|
|
7
|
-
const [isFocused, setIsFocused] = useState(false);
|
|
8
|
-
const [isPressed, setIsPressed] = useState(false);
|
|
9
|
-
const state = {
|
|
10
|
-
isDisabled: props.editable === false,
|
|
11
|
-
isFocused,
|
|
12
|
-
isPressed
|
|
13
|
-
};
|
|
14
|
-
const style = useStyle(props.className, props, state);
|
|
15
|
-
const cursorColor = useStyle(props.cursorColorClassName, props, state).accentColor;
|
|
16
|
-
const selectionColor = useStyle(props.selectionColorClassName, props, state).accentColor;
|
|
17
|
-
const placeholderTextColor = useStyle(props.placeholderTextColorClassName, props, state).accentColor;
|
|
18
|
-
const selectionHandleColor = useStyle(props.selectionHandleColorClassName, props, state).accentColor;
|
|
19
|
-
const underlineColorAndroid = useStyle(props.underlineColorAndroidClassName, props, state).accentColor;
|
|
20
|
-
return /* @__PURE__ */ jsx(
|
|
21
|
-
RNTextInput,
|
|
22
|
-
{
|
|
23
|
-
...props,
|
|
24
|
-
style: [style, props.style],
|
|
25
|
-
cursorColor: props.cursorColor ?? cursorColor,
|
|
26
|
-
selectionColor: props.selectionColor ?? selectionColor,
|
|
27
|
-
placeholderTextColor: props.placeholderTextColor ?? placeholderTextColor,
|
|
28
|
-
selectionHandleColor: props.selectionHandleColor ?? selectionHandleColor,
|
|
29
|
-
underlineColorAndroid: props.underlineColorAndroid ?? underlineColorAndroid,
|
|
30
|
-
onFocus: (event) => {
|
|
31
|
-
setIsFocused(true);
|
|
32
|
-
props.onFocus?.(event);
|
|
33
|
-
},
|
|
34
|
-
onBlur: (event) => {
|
|
35
|
-
setIsFocused(false);
|
|
36
|
-
props.onBlur?.(event);
|
|
37
|
-
},
|
|
38
|
-
onPressIn: (event) => {
|
|
39
|
-
setIsPressed(true);
|
|
40
|
-
props.onPressIn?.(event);
|
|
41
|
-
},
|
|
42
|
-
onPressOut: (event) => {
|
|
43
|
-
setIsPressed(false);
|
|
44
|
-
props.onPressOut?.(event);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
export default TextInput;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { formatColor } from "../core/web/formatColor.js";
|
|
2
|
-
import { useResolveClassNames } from "./useResolveClassNames.js";
|
|
3
|
-
export const useUniwindAccent = (className) => {
|
|
4
|
-
const styles = useResolveClassNames(className ?? "");
|
|
5
|
-
return styles.accentColor !== void 0 ? formatColor(styles.accentColor) : void 0;
|
|
6
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
2
|
-
import { TextInput as RNTextInput, TextInputProps } from 'react-native'
|
|
3
|
-
import { ComponentState } from '../../core/types'
|
|
4
|
-
import { copyComponentProperties } from '../utils'
|
|
5
|
-
import { useStyle } from './useStyle'
|
|
6
|
-
|
|
7
|
-
export const TextInput = copyComponentProperties(RNTextInput, (props: TextInputProps) => {
|
|
8
|
-
const [isFocused, setIsFocused] = useState(false)
|
|
9
|
-
const [isPressed, setIsPressed] = useState(false)
|
|
10
|
-
const state = {
|
|
11
|
-
isDisabled: props.editable === false,
|
|
12
|
-
isFocused,
|
|
13
|
-
isPressed,
|
|
14
|
-
} satisfies ComponentState
|
|
15
|
-
const style = useStyle(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
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
<RNTextInput
|
|
24
|
-
{...props}
|
|
25
|
-
style={[style, props.style]}
|
|
26
|
-
cursorColor={props.cursorColor ?? cursorColor}
|
|
27
|
-
selectionColor={props.selectionColor ?? selectionColor}
|
|
28
|
-
placeholderTextColor={props.placeholderTextColor ?? placeholderTextColor}
|
|
29
|
-
selectionHandleColor={props.selectionHandleColor ?? selectionHandleColor}
|
|
30
|
-
underlineColorAndroid={props.underlineColorAndroid ?? underlineColorAndroid}
|
|
31
|
-
onFocus={event => {
|
|
32
|
-
setIsFocused(true)
|
|
33
|
-
props.onFocus?.(event)
|
|
34
|
-
}}
|
|
35
|
-
onBlur={event => {
|
|
36
|
-
setIsFocused(false)
|
|
37
|
-
props.onBlur?.(event)
|
|
38
|
-
}}
|
|
39
|
-
onPressIn={event => {
|
|
40
|
-
setIsPressed(true)
|
|
41
|
-
props.onPressIn?.(event)
|
|
42
|
-
}}
|
|
43
|
-
onPressOut={event => {
|
|
44
|
-
setIsPressed(false)
|
|
45
|
-
props.onPressOut?.(event)
|
|
46
|
-
}}
|
|
47
|
-
/>
|
|
48
|
-
)
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
export default TextInput
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { formatColor } from '../core/web/formatColor'
|
|
2
|
-
import { useResolveClassNames } from './useResolveClassNames'
|
|
3
|
-
|
|
4
|
-
export const useUniwindAccent = (className: string | undefined) => {
|
|
5
|
-
const styles = useResolveClassNames(className ?? '')
|
|
6
|
-
|
|
7
|
-
return styles.accentColor !== undefined
|
|
8
|
-
? formatColor(styles.accentColor)
|
|
9
|
-
: undefined
|
|
10
|
-
}
|
|
File without changes
|