@ledvance/ui-biz-bundle 1.1.146 → 1.1.148

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.
@@ -1,166 +1,172 @@
1
- import React, { useMemo } from 'react';
2
- import { StyleSheet, Text, View, ViewProps, ViewStyle, Image } from 'react-native';
3
- import { SwitchButton, Utils } from 'tuya-panel-kit';
4
- import { hsv2Hex } from '@ledvance/base/src/utils';
5
- import { cctToColor } from '@ledvance/base/src/utils/cctUtils';
6
- import { mapFloatToRange } from '@ledvance/base/src/utils';
7
- import Card from '@ledvance/base/src/components/Card';
8
- import Spacer from '@ledvance/base/src/components/Spacer';
9
- import MoodColorsLine from '@ledvance/base/src/components/MoodColorsLine';
10
- import { MoodJumpGradientMode, MoodLampInfo, MoodUIInfo } from './Interface';
11
- import I18n from '@ledvance/base/src/i18n';
12
- import res from '@ledvance/base/src/res';
13
- import ThemeType from '@ledvance/base/src/config/themeType'
14
-
15
- const cx = Utils.RatioUtils.convertX;
16
- const { withTheme } = Utils.ThemeUtils
17
-
18
- interface LightCategory {
19
- isMixLight?: boolean
20
- isStripLight?: boolean
21
- isStringLight?: boolean
22
- isCeilingLight?: boolean
23
- }
24
-
25
- interface MoodItemProps extends ViewProps {
26
- theme?: ThemeType
27
- enable: boolean;
28
- isMix: boolean;
29
- mood: MoodUIInfo;
30
- style?: ViewStyle;
31
- deviceTypeOption?: LightCategory
32
- onPress?: () => void;
33
- onSwitch: (enable: boolean) => void;
34
- }
35
-
36
- const MoodItem = (props: MoodItemProps) => {
37
- const { mood, isMix, deviceTypeOption } = props;
38
- const isDynamic = useMemo(() => {
39
- return mood.mainLamp.nodes?.length > 1 || mood.secondaryLamp.nodes?.length > 1;
40
- }, [mood.mainLamp.nodes, mood.secondaryLamp.nodes]);
41
-
42
- const gradientMode = useMemo(() => (
43
- deviceTypeOption?.isStringLight ? MoodJumpGradientMode.StringGradient : deviceTypeOption?.isStripLight ? MoodJumpGradientMode.StripGradient : MoodJumpGradientMode.SourceGradient
44
- ), [MoodJumpGradientMode, deviceTypeOption])
45
-
46
-
47
- const styles = StyleSheet.create({
48
- card: {
49
- marginHorizontal: cx(24),
50
- },
51
- headline: {
52
- flexDirection: 'row',
53
- marginHorizontal: cx(16),
54
- },
55
- headText: {
56
- flex: 1,
57
- color: props.theme?.global.fontColor,
58
- fontSize: cx(16),
59
- fontFamily: 'helvetica_neue_lt_std_bd',
60
- lineHeight: cx(20),
61
- },
62
- moodTypeItem: {
63
- flexDirection: 'row',
64
- },
65
- moodTypeLabel: {
66
- marginStart: cx(16),
67
- paddingHorizontal: cx(12.5),
68
- backgroundColor: props.theme?.tag.background,
69
- borderRadius: cx(8),
70
- },
71
- moodTypeLabelText: {
72
- height: cx(16),
73
- color: props.theme?.tag.fontColor,
74
- fontSize: cx(10),
75
- textAlignVertical: 'center',
76
- fontFamily: 'helvetica_neue_lt_std_roman',
77
- lineHeight: cx(16),
78
- },
79
- })
80
-
81
- return (
82
- <Card style={[styles.card, props.style]} onPress={props.onPress}>
83
- <View>
84
- <Spacer height={cx(16)} />
85
- <View style={styles.headline}>
86
- <Text style={styles.headText}>{mood.name}</Text>
87
- <SwitchButton
88
- thumbStyle={{ elevation: 0 }}
89
- value={props.enable}
90
- onValueChange={props.onSwitch}
91
- />
92
- </View>
93
- <Spacer />
94
- <MixMoodColorsLine mixSubLight={mood.mainLamp} isMix={isMix} type={(mood.mainLamp.mode === gradientMode && !deviceTypeOption?.isCeilingLight) ? 'gradient' : 'separate'}/>
95
- {(deviceTypeOption?.isMixLight || (isMix && !!mood.secondaryLamp.nodes.length)) && (
96
- <>
97
- <Spacer height={cx(7)} />
98
- <MixMoodColorsLine mixSubLight={mood.secondaryLamp} isMix={isMix} type={mood.secondaryLamp.mode === (deviceTypeOption?.isMixLight ? MoodJumpGradientMode.SourceGradient : MoodJumpGradientMode.StripGradient) ? 'gradient' : 'separate'}/>
99
- </>
100
- )}
101
- <Spacer height={cx(12)} />
102
- <View style={styles.moodTypeItem}>
103
- <View style={styles.moodTypeLabel}>
104
- <Text style={styles.moodTypeLabelText}>
105
- {I18n.getLang(
106
- isDynamic ? 'mood_overview_field_chip_2' : 'mood_overview_field_chip_text'
107
- )}
108
- </Text>
109
- </View>
110
- </View>
111
- <Spacer height={cx(16)} />
112
- </View>
113
- </Card>
114
- );
115
- };
116
-
117
- export default withTheme(MoodItem)
118
-
119
- export function MixMoodColorsLine(props: { mixSubLight: MoodLampInfo; isMix: boolean, type: 'gradient' | 'separate' }) {
120
- const { mixSubLight, isMix } = props;
121
- const lightColors = !!(mixSubLight.enable && mixSubLight.nodes.length) ? mixSubLight.nodes?.map(n => {
122
- const s = Math.round(mapFloatToRange(n.s / 100, 30, 100));
123
- return n.isColorNode
124
- ? hsv2Hex(n.h, s, Math.round(mapFloatToRange(n.v / 100, 50, 100)))
125
- : cctToColor(n.colorTemp.toFixed());
126
- }) : ['#eee'];
127
-
128
- const styles = StyleSheet.create({
129
- gradientItem: {
130
- flexDirection: 'row',
131
- },
132
- gradientItemIconView: {
133
- width: cx(24),
134
- height: cx(24),
135
- justifyContent: 'center',
136
- alignItems: 'center',
137
- backgroundColor: '#aaa',
138
- borderRadius: cx(8),
139
- },
140
- gradientItemIcon: {
141
- width: cx(16),
142
- height: cx(16),
143
- tintColor: '#fff',
144
- },
145
- })
146
-
147
- return (
148
- <View style={styles.gradientItem}>
149
- <Spacer height={0} width={cx(16)} />
150
- <MoodColorsLine
151
- nodeStyle={{ borderColor: '#ccc', borderWidth: 1 }}
152
- width={isMix ? cx(264) : undefined}
153
- type={props.type}
154
- colors={lightColors}
155
- />
156
- {isMix && (
157
- <>
158
- <Spacer height={0} width={cx(7)} />
159
- <View style={styles.gradientItemIconView}>
160
- <Image style={styles.gradientItemIcon} source={{uri: mixSubLight.enable ? res.light_on : res.light_off}} />
161
- </View>
162
- </>
163
- )}
164
- </View>
165
- );
166
- }
1
+ import React, { useMemo } from 'react';
2
+ import { StyleSheet, Text, View, ViewProps, ViewStyle, Image, TouchableOpacity } from 'react-native';
3
+ import { Utils } from 'tuya-panel-kit';
4
+ import { hsv2Hex } from '@ledvance/base/src/utils';
5
+ import { cctToColor } from '@ledvance/base/src/utils/cctUtils';
6
+ import { mapFloatToRange } from '@ledvance/base/src/utils';
7
+ import Card from '@ledvance/base/src/components/Card';
8
+ import Spacer from '@ledvance/base/src/components/Spacer';
9
+ import MoodColorsLine from '@ledvance/base/src/components/MoodColorsLine';
10
+ import { MoodJumpGradientMode, MoodLampInfo, MoodUIInfo } from './Interface';
11
+ import I18n from '@ledvance/base/src/i18n';
12
+ import res from '@ledvance/base/src/res';
13
+ import ThemeType from '@ledvance/base/src/config/themeType'
14
+
15
+ const cx = Utils.RatioUtils.convertX;
16
+ const { withTheme } = Utils.ThemeUtils
17
+
18
+ interface LightCategory {
19
+ isMixLight?: boolean
20
+ isStripLight?: boolean
21
+ isStringLight?: boolean
22
+ isCeilingLight?: boolean
23
+ }
24
+
25
+ interface MoodItemProps extends ViewProps {
26
+ theme?: ThemeType
27
+ enable: boolean;
28
+ isMix: boolean;
29
+ mood: MoodUIInfo;
30
+ style?: ViewStyle;
31
+ deviceTypeOption?: LightCategory
32
+ onPress?: () => void;
33
+ onSwitch: (enable: boolean) => void;
34
+ }
35
+
36
+ const MoodItem = (props: MoodItemProps) => {
37
+ const { mood, isMix, deviceTypeOption } = props;
38
+ const isDynamic = useMemo(() => {
39
+ return mood.mainLamp.nodes?.length > 1 || mood.secondaryLamp.nodes?.length > 1;
40
+ }, [mood.mainLamp.nodes, mood.secondaryLamp.nodes]);
41
+
42
+ const gradientMode = useMemo(() => (
43
+ deviceTypeOption?.isStringLight ? MoodJumpGradientMode.StringGradient : deviceTypeOption?.isStripLight ? MoodJumpGradientMode.StripGradient : MoodJumpGradientMode.SourceGradient
44
+ ), [MoodJumpGradientMode, deviceTypeOption])
45
+
46
+
47
+ const styles = StyleSheet.create({
48
+ card: {
49
+ marginHorizontal: cx(24),
50
+ },
51
+ headline: {
52
+ flexDirection: 'row',
53
+ marginHorizontal: cx(16),
54
+ alignItems: 'center',
55
+ },
56
+ headText: {
57
+ flex: 1,
58
+ color: props.theme?.global.fontColor,
59
+ fontSize: cx(16),
60
+ fontFamily: 'helvetica_neue_lt_std_bd',
61
+ lineHeight: cx(20),
62
+ },
63
+ checkbox: {
64
+ width: cx(45),
65
+ height: cx(45),
66
+ marginTop: cx(-5),
67
+ marginBottom: cx(-10),
68
+ fontWeight: 'bold',
69
+ },
70
+ moodTypeItem: {
71
+ flexDirection: 'row',
72
+ },
73
+ moodTypeLabel: {
74
+ marginStart: cx(16),
75
+ paddingHorizontal: cx(12.5),
76
+ backgroundColor: props.theme?.tag.background,
77
+ borderRadius: cx(8),
78
+ },
79
+ moodTypeLabelText: {
80
+ height: cx(16),
81
+ color: props.theme?.tag.fontColor,
82
+ fontSize: cx(10),
83
+ textAlignVertical: 'center',
84
+ fontFamily: 'helvetica_neue_lt_std_roman',
85
+ lineHeight: cx(16),
86
+ },
87
+ })
88
+
89
+ return (
90
+ <Card style={[styles.card, props.style]} onPress={props.onPress}>
91
+ <View>
92
+ <Spacer height={cx(16)} />
93
+ <View style={styles.headline}>
94
+ <Text style={styles.headText}>{mood.name}</Text>
95
+ <TouchableOpacity style={styles.checkbox} onPress={() => props.onSwitch(!props.enable)}>
96
+ <Image source={{ uri: res.ic_check}} width={cx(44)} height={cx(44)} style={[styles.checkbox, { tintColor: props.enable ? props.theme?.icon.primary : props.theme?.icon.disable}]} />
97
+ </TouchableOpacity>
98
+ </View>
99
+ <Spacer />
100
+ <MixMoodColorsLine mixSubLight={mood.mainLamp} isMix={isMix} type={(mood.mainLamp.mode === gradientMode && !deviceTypeOption?.isCeilingLight) ? 'gradient' : 'separate'}/>
101
+ {(deviceTypeOption?.isMixLight || (isMix && !!mood.secondaryLamp.nodes.length)) && (
102
+ <>
103
+ <Spacer height={cx(7)} />
104
+ <MixMoodColorsLine mixSubLight={mood.secondaryLamp} isMix={isMix} type={mood.secondaryLamp.mode === (deviceTypeOption?.isMixLight ? MoodJumpGradientMode.SourceGradient : MoodJumpGradientMode.StripGradient) ? 'gradient' : 'separate'}/>
105
+ </>
106
+ )}
107
+ <Spacer height={cx(12)} />
108
+ <View style={styles.moodTypeItem}>
109
+ <View style={styles.moodTypeLabel}>
110
+ <Text style={styles.moodTypeLabelText}>
111
+ {I18n.getLang(
112
+ isDynamic ? 'mood_overview_field_chip_2' : 'mood_overview_field_chip_text'
113
+ )}
114
+ </Text>
115
+ </View>
116
+ </View>
117
+ <Spacer height={cx(16)} />
118
+ </View>
119
+ </Card>
120
+ );
121
+ };
122
+
123
+ export default withTheme(MoodItem)
124
+
125
+ export function MixMoodColorsLine(props: { mixSubLight: MoodLampInfo; isMix: boolean, type: 'gradient' | 'separate' }) {
126
+ const { mixSubLight, isMix } = props;
127
+ const lightColors = !!(mixSubLight.enable && mixSubLight.nodes.length) ? mixSubLight.nodes?.map(n => {
128
+ const s = Math.round(mapFloatToRange(n.s / 100, 30, 100));
129
+ return n.isColorNode
130
+ ? hsv2Hex(n.h, s, Math.round(mapFloatToRange(n.v / 100, 50, 100)))
131
+ : cctToColor(n.colorTemp.toFixed());
132
+ }) : ['#eee'];
133
+
134
+ const styles = StyleSheet.create({
135
+ gradientItem: {
136
+ flexDirection: 'row',
137
+ },
138
+ gradientItemIconView: {
139
+ width: cx(24),
140
+ height: cx(24),
141
+ justifyContent: 'center',
142
+ alignItems: 'center',
143
+ backgroundColor: '#aaa',
144
+ borderRadius: cx(8),
145
+ },
146
+ gradientItemIcon: {
147
+ width: cx(16),
148
+ height: cx(16),
149
+ tintColor: '#fff',
150
+ },
151
+ })
152
+
153
+ return (
154
+ <View style={styles.gradientItem}>
155
+ <Spacer height={0} width={cx(16)} />
156
+ <MoodColorsLine
157
+ nodeStyle={{ borderColor: '#ccc', borderWidth: 1 }}
158
+ width={isMix ? cx(264) : undefined}
159
+ type={props.type}
160
+ colors={lightColors}
161
+ />
162
+ {isMix && (
163
+ <>
164
+ <Spacer height={0} width={cx(7)} />
165
+ <View style={styles.gradientItemIconView}>
166
+ <Image style={styles.gradientItemIcon} source={{uri: mixSubLight.enable ? res.light_on : res.light_off}} />
167
+ </View>
168
+ </>
169
+ )}
170
+ </View>
171
+ );
172
+ }