@proximus/lavender-switch-native 0.1.0-alpha.0 → 0.1.0-alpha.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 +12 -0
- package/dist/PxSwitch.d.ts +2 -12
- package/dist/PxSwitch.d.ts.map +1 -1
- package/package.json +6 -7
- package/src/PxSwitch.tsx +50 -131
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.1.0-alpha.2](https://github.com/Pxs-Corporate/react-native-lavender/compare/@proximus/lavender-switch-native@0.1.0-alpha.1...@proximus/lavender-switch-native@0.1.0-alpha.2) (2025-09-05)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **BCRI-4279213:** update token architecture and component styles ([#18](https://github.com/Pxs-Corporate/react-native-lavender/issues/18)) ([2fabf41](https://github.com/Pxs-Corporate/react-native-lavender/commit/2fabf416ce069e9756daa868c3012181db87e7f5))
|
|
11
|
+
|
|
12
|
+
# [0.1.0-alpha.1](https://github.com/Pxs-Corporate/react-native-lavender/compare/@proximus/lavender-switch-native@0.1.0-alpha.0...@proximus/lavender-switch-native@0.1.0-alpha.1) (2025-08-13)
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
- **BCRI-4210372:** fix types field in modules ([68ac126](https://github.com/Pxs-Corporate/react-native-lavender/commit/68ac12657112473ae9e0e683076b1d9172be9ce6))
|
|
17
|
+
|
|
6
18
|
# 0.1.0-alpha.0 (2025-08-13)
|
|
7
19
|
|
|
8
20
|
### Bug Fixes
|
package/dist/PxSwitch.d.ts
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import React, { Component } from 'react';
|
|
2
2
|
import { AccessibilityProps, Animated, StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
import { IThemeContext } from '@proximus/lavender-styling-native';
|
|
3
4
|
export interface ISwitchProps extends AccessibilityProps {
|
|
4
5
|
onValueChange: (value: boolean) => void;
|
|
5
6
|
disabled?: boolean;
|
|
6
7
|
lookOnlyProps?: boolean;
|
|
7
8
|
value?: boolean;
|
|
8
|
-
isPending?: boolean;
|
|
9
|
-
circleColors?: Array<string>;
|
|
10
|
-
circleStyle?: StyleProp<ViewStyle>;
|
|
11
|
-
trackColors?: Array<string>;
|
|
12
|
-
trackStyle?: StyleProp<ViewStyle>;
|
|
13
|
-
disabledStyle?: StyleProp<ViewStyle>;
|
|
14
9
|
testID?: string;
|
|
15
|
-
height?: number;
|
|
16
|
-
type?: 'order' | 'primary';
|
|
17
10
|
labelAccessibilityProp?: AccessibilityProps;
|
|
18
11
|
containerStyle?: StyleProp<ViewStyle>;
|
|
19
12
|
hasLabel?: boolean;
|
|
@@ -22,9 +15,6 @@ interface IState {
|
|
|
22
15
|
value: boolean;
|
|
23
16
|
transformSwitch: Animated.Value;
|
|
24
17
|
containerBackgroundColor: Animated.Value;
|
|
25
|
-
yesLabelOpacity: Animated.Value;
|
|
26
|
-
pendingOpacity: Animated.Value;
|
|
27
|
-
noLabelOpacity: Animated.Value;
|
|
28
18
|
}
|
|
29
19
|
export declare class PxSwitch extends Component<ISwitchProps, IState> {
|
|
30
20
|
static defaultProps: {
|
|
@@ -32,7 +22,7 @@ export declare class PxSwitch extends Component<ISwitchProps, IState> {
|
|
|
32
22
|
value: boolean;
|
|
33
23
|
type: string;
|
|
34
24
|
};
|
|
35
|
-
static contextType: React.Context<
|
|
25
|
+
static contextType: React.Context<IThemeContext>;
|
|
36
26
|
constructor(props: ISwitchProps);
|
|
37
27
|
componentDidUpdate(prevProps: ISwitchProps): void;
|
|
38
28
|
_handleSwitch: (activate?: boolean) => void;
|
package/dist/PxSwitch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PxSw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OAAO,UAkBjC;IAEF,cAAc,GAAI,OAAO,OAAO,UAc9B;IAEF,MAAM;CA6GP"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proximus/lavender-switch-native",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.2",
|
|
4
4
|
"description": "Lavender react native switch component",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
7
|
"type": "module",
|
|
9
8
|
"scripts": {
|
|
10
9
|
"clean": "rm -rf dist",
|
|
@@ -19,10 +18,10 @@
|
|
|
19
18
|
"react-native-gesture-handler": "*"
|
|
20
19
|
},
|
|
21
20
|
"devDependencies": {
|
|
22
|
-
"@proximus/lavender-common-native": "0.1.0-alpha.
|
|
23
|
-
"@proximus/lavender-icon-native": "0.1.0-alpha.
|
|
24
|
-
"@proximus/lavender-styling-native": "0.1.0-alpha.
|
|
25
|
-
"@proximus/lavender-texts-native": "0.1.0-alpha.
|
|
21
|
+
"@proximus/lavender-common-native": "0.1.0-alpha.2",
|
|
22
|
+
"@proximus/lavender-icon-native": "0.1.0-alpha.2",
|
|
23
|
+
"@proximus/lavender-styling-native": "0.1.0-alpha.2",
|
|
24
|
+
"@proximus/lavender-texts-native": "0.1.0-alpha.2"
|
|
26
25
|
},
|
|
27
26
|
"publishConfig": {
|
|
28
27
|
"access": "public"
|
|
@@ -38,5 +37,5 @@
|
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
},
|
|
41
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "38a67765befa2567a3f5f57976b7933cf5b85a24"
|
|
42
41
|
}
|
package/src/PxSwitch.tsx
CHANGED
|
@@ -16,22 +16,18 @@ import {
|
|
|
16
16
|
|
|
17
17
|
import { a11y, e2eID } from '@proximus/lavender-common-native';
|
|
18
18
|
|
|
19
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
ITheme,
|
|
21
|
+
IThemeContext,
|
|
22
|
+
ThemeContext,
|
|
23
|
+
} from '@proximus/lavender-styling-native';
|
|
20
24
|
|
|
21
25
|
export interface ISwitchProps extends AccessibilityProps {
|
|
22
26
|
onValueChange: (value: boolean) => void;
|
|
23
27
|
disabled?: boolean;
|
|
24
28
|
lookOnlyProps?: boolean;
|
|
25
29
|
value?: boolean;
|
|
26
|
-
isPending?: boolean;
|
|
27
|
-
circleColors?: Array<string>; // Deprecated
|
|
28
|
-
circleStyle?: StyleProp<ViewStyle>; // Deprecated
|
|
29
|
-
trackColors?: Array<string>;
|
|
30
|
-
trackStyle?: StyleProp<ViewStyle>;
|
|
31
|
-
disabledStyle?: StyleProp<ViewStyle>;
|
|
32
30
|
testID?: string;
|
|
33
|
-
height?: number;
|
|
34
|
-
type?: 'order' | 'primary';
|
|
35
31
|
labelAccessibilityProp?: AccessibilityProps;
|
|
36
32
|
containerStyle?: StyleProp<ViewStyle>;
|
|
37
33
|
hasLabel?: boolean;
|
|
@@ -41,9 +37,6 @@ interface IState {
|
|
|
41
37
|
value: boolean;
|
|
42
38
|
transformSwitch: Animated.Value;
|
|
43
39
|
containerBackgroundColor: Animated.Value;
|
|
44
|
-
yesLabelOpacity: Animated.Value;
|
|
45
|
-
pendingOpacity: Animated.Value;
|
|
46
|
-
noLabelOpacity: Animated.Value;
|
|
47
40
|
}
|
|
48
41
|
|
|
49
42
|
const defaults = {
|
|
@@ -64,24 +57,13 @@ export class PxSwitch extends Component<ISwitchProps, IState> {
|
|
|
64
57
|
constructor(props: ISwitchProps) {
|
|
65
58
|
super(props);
|
|
66
59
|
|
|
67
|
-
const { value
|
|
60
|
+
const { value } = props;
|
|
68
61
|
this.state = {
|
|
69
62
|
containerBackgroundColor: new Animated.Value(
|
|
70
|
-
value
|
|
71
|
-
? defaults.interpolationRange
|
|
72
|
-
: -defaults.interpolationRange
|
|
63
|
+
value ? defaults.interpolationRange : -defaults.interpolationRange
|
|
73
64
|
),
|
|
74
65
|
transformSwitch: new Animated.Value(
|
|
75
|
-
value
|
|
76
|
-
? defaults.circleSize - 10
|
|
77
|
-
: -defaults.circleSize + 10
|
|
78
|
-
),
|
|
79
|
-
yesLabelOpacity: new Animated.Value(
|
|
80
|
-
disabled || !props.value || isPending ? 0 : 1
|
|
81
|
-
),
|
|
82
|
-
pendingOpacity: new Animated.Value(isPending && !disabled ? 1 : 0),
|
|
83
|
-
noLabelOpacity: new Animated.Value(
|
|
84
|
-
disabled || value || isPending ? 0 : 1
|
|
66
|
+
value ? defaults.circleSize - 10 : -defaults.circleSize + 10
|
|
85
67
|
),
|
|
86
68
|
value: value || false,
|
|
87
69
|
};
|
|
@@ -117,34 +99,17 @@ export class PxSwitch extends Component<ISwitchProps, IState> {
|
|
|
117
99
|
};
|
|
118
100
|
|
|
119
101
|
_animateSwitch = (value: boolean) => {
|
|
120
|
-
const { isPending } = this.props;
|
|
121
102
|
Animated.parallel([
|
|
122
103
|
Animated.spring(this.state.transformSwitch, {
|
|
123
|
-
useNativeDriver:
|
|
124
|
-
toValue:
|
|
125
|
-
value || isPending
|
|
126
|
-
? defaults.circleSize - 10
|
|
127
|
-
: -defaults.circleSize + 10,
|
|
104
|
+
useNativeDriver: true,
|
|
105
|
+
toValue: value ? defaults.circleSize - 10 : -defaults.circleSize + 10,
|
|
128
106
|
}),
|
|
129
107
|
Animated.timing(this.state.containerBackgroundColor, {
|
|
130
108
|
duration: defaults.duration,
|
|
131
|
-
useNativeDriver:
|
|
132
|
-
toValue:
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
: -defaults.interpolationRange,
|
|
136
|
-
}),
|
|
137
|
-
Animated.spring(this.state.yesLabelOpacity, {
|
|
138
|
-
useNativeDriver: false,
|
|
139
|
-
toValue: value && !isPending ? 1 : 0,
|
|
140
|
-
}),
|
|
141
|
-
Animated.spring(this.state.noLabelOpacity, {
|
|
142
|
-
useNativeDriver: false,
|
|
143
|
-
toValue: value || isPending ? 0 : 1,
|
|
144
|
-
}),
|
|
145
|
-
Animated.spring(this.state.pendingOpacity, {
|
|
146
|
-
useNativeDriver: false,
|
|
147
|
-
toValue: isPending ? 1 : 0,
|
|
109
|
+
useNativeDriver: true,
|
|
110
|
+
toValue: value
|
|
111
|
+
? defaults.interpolationRange
|
|
112
|
+
: -defaults.interpolationRange,
|
|
148
113
|
}),
|
|
149
114
|
]).start();
|
|
150
115
|
};
|
|
@@ -152,33 +117,21 @@ export class PxSwitch extends Component<ISwitchProps, IState> {
|
|
|
152
117
|
render() {
|
|
153
118
|
const { containerBackgroundColor, value } = this.state;
|
|
154
119
|
|
|
155
|
-
const {
|
|
156
|
-
circleStyle,
|
|
157
|
-
trackColors,
|
|
158
|
-
trackStyle,
|
|
159
|
-
testID,
|
|
160
|
-
disabled,
|
|
161
|
-
isPending,
|
|
162
|
-
height = 28,
|
|
163
|
-
type,
|
|
164
|
-
...accessibilityProps
|
|
165
|
-
} = this.props;
|
|
120
|
+
const { testID, disabled, ...accessibilityProps } = this.props;
|
|
166
121
|
|
|
167
122
|
const containerBackground = containerBackgroundColor.interpolate({
|
|
168
123
|
inputRange: [-defaults.interpolationRange, defaults.interpolationRange],
|
|
169
|
-
outputRange:
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
this.context?.theme?.t('BackgroundColorPurposeSuccessDefault'),
|
|
124
|
+
outputRange: [
|
|
125
|
+
((this.context as IThemeContext)?.theme as ITheme)?.t(
|
|
126
|
+
'ColorBackgroundContainerStrongDefault'
|
|
127
|
+
),
|
|
128
|
+
((this.context as IThemeContext)?.theme as ITheme)?.t(
|
|
129
|
+
'ColorBackgroundPurposeSuccessDefault'
|
|
130
|
+
),
|
|
177
131
|
],
|
|
178
132
|
});
|
|
179
133
|
|
|
180
134
|
return (
|
|
181
|
-
// @ts-ignore
|
|
182
135
|
<FlingGestureHandler
|
|
183
136
|
direction={Directions.LEFT}
|
|
184
137
|
numberOfPointers={1}
|
|
@@ -188,8 +141,6 @@ export class PxSwitch extends Component<ISwitchProps, IState> {
|
|
|
188
141
|
}
|
|
189
142
|
}}
|
|
190
143
|
>
|
|
191
|
-
{/*
|
|
192
|
-
// @ts-ignore */}
|
|
193
144
|
<FlingGestureHandler
|
|
194
145
|
direction={Directions.RIGHT}
|
|
195
146
|
numberOfPointers={1}
|
|
@@ -199,7 +150,7 @@ export class PxSwitch extends Component<ISwitchProps, IState> {
|
|
|
199
150
|
}
|
|
200
151
|
}}
|
|
201
152
|
>
|
|
202
|
-
<View style={[
|
|
153
|
+
<View style={[this.props.containerStyle]}>
|
|
203
154
|
<TouchableWithoutFeedback
|
|
204
155
|
disabled={disabled}
|
|
205
156
|
onPress={() => this._handleSwitch()}
|
|
@@ -224,60 +175,47 @@ export class PxSwitch extends Component<ISwitchProps, IState> {
|
|
|
224
175
|
styles.track,
|
|
225
176
|
{
|
|
226
177
|
backgroundColor: containerBackground,
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
178
|
+
borderRadius: (
|
|
179
|
+
(this.context as IThemeContext)?.theme as ITheme
|
|
180
|
+
)?.t('RadiusPill').number,
|
|
181
|
+
width: (
|
|
182
|
+
(this.context as IThemeContext)?.theme as ITheme
|
|
183
|
+
)?.t('SizeActionInputSwitchWidth').number,
|
|
184
|
+
padding: (
|
|
185
|
+
(this.context as IThemeContext)?.theme as ITheme
|
|
186
|
+
)?.t('Padding3xsMobile').number,
|
|
232
187
|
},
|
|
233
188
|
disabled && {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
),
|
|
189
|
+
backgroundColor: (
|
|
190
|
+
(this.context as IThemeContext)?.theme as ITheme
|
|
191
|
+
)?.t('ColorBackgroundStateDisabledDefault'),
|
|
238
192
|
},
|
|
239
193
|
]}
|
|
240
194
|
>
|
|
241
195
|
<Animated.View
|
|
242
196
|
style={[
|
|
243
|
-
styles.circle,
|
|
244
197
|
{
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
height:
|
|
249
|
-
|
|
250
|
-
|
|
198
|
+
width: (
|
|
199
|
+
(this.context as IThemeContext)?.theme as ITheme
|
|
200
|
+
)?.t('SizeIconM').number,
|
|
201
|
+
height: (
|
|
202
|
+
(this.context as IThemeContext)?.theme as ITheme
|
|
203
|
+
)?.t('SizeIconM').number,
|
|
204
|
+
|
|
205
|
+
borderRadius: (
|
|
206
|
+
(this.context as IThemeContext)?.theme as ITheme
|
|
207
|
+
)?.t('RadiusPill').number,
|
|
251
208
|
backgroundColor: disabled
|
|
252
|
-
?
|
|
253
|
-
|
|
254
|
-
'BackgroundColorActionDisabledDefault'
|
|
209
|
+
? ((this.context as IThemeContext)?.theme as ITheme)?.t(
|
|
210
|
+
'ColorBackgroundStateDisabledDefault'
|
|
255
211
|
)
|
|
256
|
-
:
|
|
257
|
-
|
|
258
|
-
'BackgroundColorContainerNeutralBareDefault'
|
|
212
|
+
: ((this.context as IThemeContext)?.theme as ITheme)?.t(
|
|
213
|
+
'ColorBackgroundContainerLightDefault'
|
|
259
214
|
),
|
|
260
|
-
|
|
215
|
+
transform: [{ translateX: this.state.transformSwitch }],
|
|
261
216
|
},
|
|
262
|
-
circleStyle,
|
|
263
217
|
]}
|
|
264
218
|
></Animated.View>
|
|
265
|
-
<Animated.View
|
|
266
|
-
style={{
|
|
267
|
-
position: 'absolute',
|
|
268
|
-
opacity: this.state.yesLabelOpacity,
|
|
269
|
-
left: 9,
|
|
270
|
-
}}
|
|
271
|
-
></Animated.View>
|
|
272
|
-
{!disabled && (
|
|
273
|
-
<Animated.View
|
|
274
|
-
style={{
|
|
275
|
-
position: 'absolute',
|
|
276
|
-
opacity: this.state.noLabelOpacity,
|
|
277
|
-
right: 6,
|
|
278
|
-
}}
|
|
279
|
-
></Animated.View>
|
|
280
|
-
)}
|
|
281
219
|
</Animated.View>
|
|
282
220
|
</TouchableWithoutFeedback>
|
|
283
221
|
</View>
|
|
@@ -288,27 +226,8 @@ export class PxSwitch extends Component<ISwitchProps, IState> {
|
|
|
288
226
|
}
|
|
289
227
|
|
|
290
228
|
const styles = StyleSheet.create({
|
|
291
|
-
circle: {
|
|
292
|
-
borderRadius: 14,
|
|
293
|
-
alignItems: 'center',
|
|
294
|
-
// height: defaults.circleSize,
|
|
295
|
-
// width: defaults.circleSize,
|
|
296
|
-
},
|
|
297
|
-
disabled: {
|
|
298
|
-
bottom: 0,
|
|
299
|
-
left: 0,
|
|
300
|
-
opacity: 0.5,
|
|
301
|
-
position: 'absolute',
|
|
302
|
-
right: 0,
|
|
303
|
-
top: 0,
|
|
304
|
-
},
|
|
305
229
|
track: {
|
|
306
|
-
alignItems: 'center',
|
|
307
|
-
borderRadius: 14,
|
|
308
|
-
flex: 1,
|
|
309
230
|
flexDirection: 'row',
|
|
310
|
-
height: 30,
|
|
311
231
|
justifyContent: 'center',
|
|
312
|
-
width: 48,
|
|
313
232
|
},
|
|
314
233
|
});
|