@ledvance/ui-biz-bundle 1.1.70 → 1.1.72

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