@ledvance/base 1.1.73 → 1.1.74

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/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "@ledvance/base",
5
5
  "pid": [],
6
6
  "uiid": "",
7
- "version": "1.1.73",
7
+ "version": "1.1.74",
8
8
  "scripts": {},
9
9
  "dependencies": {
10
10
  "@reduxjs/toolkit": "^1.8.6",
@@ -0,0 +1,121 @@
1
+ import { exchangeNumber, localeNumber } from "@ledvance/base/src/utils/common";
2
+ import res from "@res";
3
+ import { useReactive } from "ahooks";
4
+ import React, { memo, useCallback } from "react";
5
+ import { TouchableOpacity, View, Image, TextInput, StyleSheet, StyleProp, ViewStyle } from "react-native";
6
+ import { Utils } from "tuya-panel-kit";
7
+
8
+ const { add, subtract, inMaxMin} = Utils.NumberUtils
9
+
10
+ const { convertX: cx } = Utils.RatioUtils
11
+
12
+ export interface StepperProps {
13
+ value: number | string
14
+ stepValue?: number // 1
15
+ min?: number // 0
16
+ max?: number // 99
17
+ editable?: boolean
18
+ selectionColor?: string
19
+ onValueChange?: ((value: number) => void)
20
+ disabled?: boolean
21
+ style?: StyleProp<ViewStyle>
22
+ buttonStyle?: StyleProp<ViewStyle>
23
+ inputStyle?: StyleProp<ViewStyle>
24
+ }
25
+
26
+ const Stepper = (props: StepperProps) => {
27
+ const state = useReactive({
28
+ value: localeNumber(Number(props.value), 1) ?? 0,
29
+ stepValue: props.stepValue ?? 1,
30
+ min: props.min ?? 0,
31
+ max: props.max ?? 99
32
+ })
33
+
34
+ const handlePress = useCallback((isAdd: boolean) => {
35
+ const v = inMaxMin(state.min, state.max, isAdd ? add(Number(exchangeNumber(state.value)), state.stepValue) : subtract(Number(exchangeNumber(state.value)), state.stepValue))
36
+ state.value = localeNumber(v, 1)
37
+ props.onValueChange && props.onValueChange(v)
38
+ }, [])
39
+
40
+
41
+ const handleChangeText = useCallback((v: string) =>{
42
+ const newValue = exchangeNumber(v)
43
+ const idx = newValue.indexOf('.')
44
+ if(newValue[0] === '.' ||
45
+ (newValue.length === 2 && newValue[0] === '0' && newValue[1] !== '.') ||
46
+ newValue.split('').filter(item => item === '.').length > 1 ||
47
+ Number(newValue) > state.max || Number(newValue) < state.min ||
48
+ (idx !== -1 && newValue.length > idx + 2)){
49
+ return
50
+ }
51
+ state.value = v
52
+ }, [])
53
+
54
+ const handleEndText = useCallback(() =>{
55
+ if (typeof state.value === 'string' && !state.value.length) {
56
+ props.onValueChange && props.onValueChange(state.min)
57
+ state.value = state.min.toString()
58
+ }else{
59
+ props.onValueChange && props.onValueChange(Number(exchangeNumber(state.value)))
60
+ }
61
+
62
+ }, [])
63
+
64
+ return (
65
+ <View style={[styles.stepperContainer, props.style]}>
66
+ <TouchableOpacity
67
+ style={[styles.stepperButton, props.buttonStyle]}
68
+ onPress={() => handlePress(false)}
69
+ >
70
+ <Image width={cx(16)} height={cx(16)} source={res.ic_minus} />
71
+ </TouchableOpacity>
72
+ <TextInput
73
+ style={[styles.stepperInput, props.inputStyle]}
74
+ value={state.value.toString()}
75
+ keyboardType="numeric"
76
+ onChangeText={handleChangeText}
77
+ maxLength={4}
78
+ enablesReturnKeyAutomatically={true}
79
+ onEndEditing={handleEndText}
80
+ editable={props.editable || props.disabled}
81
+ />
82
+ <TouchableOpacity
83
+ style={[styles.stepperButton, props.buttonStyle]}
84
+ onPress={() => handlePress(true)}
85
+ >
86
+ <Image style={{ width: cx(20), height: cx(20) }} source={res.ic_plus} />
87
+ </TouchableOpacity>
88
+ </View>
89
+ )
90
+ }
91
+
92
+ const styles = StyleSheet.create({
93
+ stepperContainer: {
94
+ flexDirection: 'row',
95
+ alignItems: 'center',
96
+ backgroundColor: '#f5f5f5',
97
+ padding: cx(2),
98
+ borderRadius: cx(12),
99
+ width: cx(150),
100
+ },
101
+ stepperButton: {
102
+ width: cx(52),
103
+ height: cx(28),
104
+ backgroundColor: '#fff',
105
+ borderRadius: cx(10),
106
+ alignItems: 'center',
107
+ justifyContent: 'center',
108
+ },
109
+ stepperInput: {
110
+ width: cx(42),
111
+ height: cx(22),
112
+ color: '#333',
113
+ fontSize: cx(16),
114
+ padding: 0,
115
+ alignItems: 'center',
116
+ justifyContent: 'center',
117
+ textAlign: 'center',
118
+ }
119
+ })
120
+
121
+ export default memo(Stepper)
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/src/res/index.ts CHANGED
@@ -61,5 +61,7 @@ export default {
61
61
  ic_colorize: require('./ic_colorize.png'),
62
62
  ic_mood_del: require('./ic_mood_del.png'),
63
63
  ic_paint_bucket: require('./ic_paint_bucket.png'),
64
- ic_text_field_input_error: require('./ic_text_field_input_error.png')
64
+ ic_text_field_input_error: require('./ic_text_field_input_error.png'),
65
+ ic_minus: require('./ic_minus.png'),
66
+ ic_plus: require('./ic_plus.png')
65
67
  }