@widergy/mobile-ui 1.32.14 → 1.32.15

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 CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.32.15](https://github.com/widergy/mobile-ui/compare/v1.32.14...v1.32.15) (2025-01-02)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * [EVE-4361] bottom sheet actions ([#389](https://github.com/widergy/mobile-ui/issues/389)) ([97ed997](https://github.com/widergy/mobile-ui/commit/97ed997423209b0901c061abc82ea4656d210b91))
7
+
1
8
  ## [1.32.14](https://github.com/widergy/mobile-ui/compare/v1.32.13...v1.32.14) (2025-01-02)
2
9
 
3
10
 
@@ -6,15 +6,35 @@
6
6
 
7
7
  ## Props
8
8
 
9
- | Name | Type | Default | Description |
10
- | ----------- | ------ | ------- | ----------------------------------------------------------------------- |
11
- | buttonText | string | | Text for the button that appears in the top right corner of the header. |
12
- | description | string | | Description that appears below the title in the header. |
13
- | onClose | func | | Function called when the bottom sheet is closed. |
14
- | required | bool | | Indicates if the field is required, showing an asterisk in the title. |
15
- | title | string | | Title that appears in the bottom sheet header. |
16
- | visible | bool | | Controls the visibility of the bottom sheet. |
17
- | scrolleable | bool | false | Determines if the content inside the bottom sheet should be scrollable. |
9
+ | Name | Type | Default | Description |
10
+ | ------------------------- | -------- | ----------- | --------------------------------------------------------------------------- |
11
+ | `buttonText` | `string` | | Text for the button that appears in the top right corner of the header. |
12
+ | `description` | `string` | | Description that appears below the title in the header. |
13
+ | `onClose` | `func` | | Function called when the bottom sheet is closed. |
14
+ | `required` | `bool` | | Indicates if the field is required, showing an asterisk in the title. |
15
+ | `title` | `string` | | Title that appears in the bottom sheet header. |
16
+ | `visible` | `bool` | | Controls the visibility of the bottom sheet. |
17
+ | `scrolleable` | `bool` | `false` | Determines if the content inside the bottom sheet should be scrollable. |
18
+ | `actionAlignment` | `string` | | Aligns the actions. |
19
+ | `onCloseProps` | `object` | | Additional props passed to the `onClose` function (optional). |
20
+ | `primaryAction` | `func` | | Callback for the primary action button. |
21
+ | `primaryActionProps` | `object` | | Props for the primary action button. |
22
+ | `primaryActionText` | `string` | | Text for the primary action button. |
23
+ | `secondaryAction` | `func` | | Callback for the secondary action button. |
24
+ | `secondaryActionProps` | `object` | | Props for the secondary action button. |
25
+ | `secondaryActionText` | `string` | | Text for the secondary action button. |
26
+ | `tertiaryAction` | `func` | | Callback for the tertiary action button. |
27
+ | `tertiaryActionProps` | `object` | | Props for the tertiary action button . |
28
+ | `tertiaryActionText` | `string` | | Text for the tertiary action button. |
29
+
30
+ ### actionAlignment
31
+
32
+ The value of `actionAlignment` must be one of the following:
33
+
34
+ - `horizontal`
35
+ - `vertical`
36
+
37
+ By default, actions are aligned horizontally if there are two, and vertically otherwise.
18
38
 
19
39
  ## Example
20
40
 
@@ -0,0 +1,4 @@
1
+ export const ACTION_ALIGNMENTS = {
2
+ HORIZONTAL: 'horizontal',
3
+ VERTICAL: 'vertical'
4
+ };
@@ -1,7 +1,7 @@
1
1
  import React, { useRef, useState, useEffect, useCallback, useMemo } from 'react';
2
2
  import { SafeAreaView, View, PanResponder, Animated, Dimensions, ScrollView, Keyboard } from 'react-native';
3
3
  import Modal from 'react-native-modal';
4
- import { bool, func, string } from 'prop-types';
4
+ import { bool, func, object, string } from 'prop-types';
5
5
 
6
6
  import { useTheme } from '../../theming';
7
7
  import UTButton from '../UTButton';
@@ -9,16 +9,28 @@ import UTFieldLabel from '../UTFieldLabel';
9
9
  import UTLabel from '../UTLabel';
10
10
 
11
11
  import styles from './styles';
12
+ import { ACTION_ALIGNMENTS } from './constants';
12
13
 
13
14
  const screenHeight = Dimensions.get('window').height;
14
15
 
15
16
  const UTBottomSheet = ({
17
+ actionAlignment: actionAlignment_,
16
18
  buttonText,
17
19
  children,
18
20
  description,
19
21
  onClose,
22
+ onCloseProps = {},
23
+ primaryAction,
24
+ primaryActionProps = {},
25
+ primaryActionText,
20
26
  required,
21
27
  scrolleable,
28
+ secondaryAction,
29
+ secondaryActionProps = {},
30
+ secondaryActionText,
31
+ tertiaryAction,
32
+ tertiaryActionProps = {},
33
+ tertiaryActionText,
22
34
  title,
23
35
  visible
24
36
  }) => {
@@ -76,6 +88,11 @@ const UTBottomSheet = ({
76
88
 
77
89
  const ChildrenContainer = scrolleable ? ScrollView : View;
78
90
 
91
+ const actionAlignment =
92
+ actionAlignment_ || [primaryAction, secondaryAction, tertiaryAction].filter(Boolean).length === 2
93
+ ? ACTION_ALIGNMENTS.HORIZONTAL
94
+ : ACTION_ALIGNMENTS.VERTICAL;
95
+
79
96
  return (
80
97
  <Modal
81
98
  animationIn="slideInUp"
@@ -101,7 +118,12 @@ const UTBottomSheet = ({
101
118
  {title}
102
119
  </UTFieldLabel>
103
120
  {buttonText && (
104
- <UTButton colorTheme="primary" onPress={onClose} variant="semitransparent">
121
+ <UTButton
122
+ colorTheme="primary"
123
+ onPress={onClose}
124
+ variant="semitransparent"
125
+ {...onCloseProps}
126
+ >
105
127
  {buttonText}
106
128
  </UTButton>
107
129
  )}
@@ -116,6 +138,43 @@ const UTBottomSheet = ({
116
138
  {children}
117
139
  </ChildrenContainer>
118
140
  </View>
141
+ <View style={styles.actions(actionAlignment)}>
142
+ {[
143
+ {
144
+ key: 'primaryAction',
145
+ onPress: primaryAction,
146
+ text: primaryActionText,
147
+ ...primaryActionProps
148
+ },
149
+ {
150
+ key: 'secondaryAction',
151
+ onPress: secondaryAction,
152
+ text: secondaryActionText,
153
+ variant: 'semitransparent',
154
+ ...secondaryActionProps
155
+ },
156
+ {
157
+ key: 'tertiaryAction',
158
+ onPress: tertiaryAction,
159
+ text: tertiaryActionText,
160
+ variant: 'text',
161
+ ...tertiaryActionProps
162
+ }
163
+ ].map(
164
+ ({ text, key, onPress, ...actionProps }) =>
165
+ onPress && (
166
+ <UTButton
167
+ key={key}
168
+ onPress={onPress}
169
+ size="large"
170
+ style={styles.action(actionAlignment)}
171
+ {...actionProps}
172
+ >
173
+ {text}
174
+ </UTButton>
175
+ )
176
+ )}
177
+ </View>
119
178
  </SafeAreaView>
120
179
  </Animated.View>
121
180
  </Modal>
@@ -127,11 +186,22 @@ UTBottomSheet.defaultProps = {
127
186
  };
128
187
 
129
188
  UTBottomSheet.propTypes = {
189
+ actionAlignment: string,
130
190
  buttonText: string,
131
191
  description: string,
132
192
  onClose: func,
193
+ onCloseProps: object,
194
+ primaryAction: func,
195
+ primaryActionProps: object,
196
+ primaryActionText: string,
133
197
  required: bool,
134
198
  scrolleable: bool,
199
+ secondaryAction: func,
200
+ secondaryActionProps: object,
201
+ secondaryActionText: string,
202
+ tertiaryAction: func,
203
+ tertiaryActionProps: object,
204
+ tertiaryActionText: string,
135
205
  title: string,
136
206
  visible: bool
137
207
  };
@@ -1,5 +1,7 @@
1
1
  import { StyleSheet } from 'react-native';
2
2
 
3
+ import { ACTION_ALIGNMENTS } from './constants';
4
+
3
5
  const styles = StyleSheet.create({
4
6
  animatedContainer: {
5
7
  backgroundColor: 'white', // When the component is standardized, should change to palette color
@@ -44,7 +46,32 @@ const styles = StyleSheet.create({
44
46
  },
45
47
  title: {
46
48
  flex: 1
47
- }
49
+ },
50
+ action: actionAlignment => ({
51
+ root: {
52
+ display: 'flex',
53
+ alignItems: 'center',
54
+ flexGrow: 1,
55
+ borderRadius: {
56
+ [ACTION_ALIGNMENTS.VERTICAL]: 4,
57
+ [ACTION_ALIGNMENTS.HORIZONTAL]: 0
58
+ }[actionAlignment]
59
+ }
60
+ }),
61
+ actions: actionAlignment => ({
62
+ display: 'flex',
63
+ ...{
64
+ [ACTION_ALIGNMENTS.VERTICAL]: {
65
+ flexDirection: 'coloumn',
66
+ paddingHorizontal: 16,
67
+ gap: 8,
68
+ paddingBottom: 16
69
+ },
70
+ [ACTION_ALIGNMENTS.HORIZONTAL]: {
71
+ flexDirection: 'row'
72
+ }
73
+ }[actionAlignment]
74
+ })
48
75
  });
49
76
 
50
77
  export default styles;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@widergy/mobile-ui",
3
3
  "description": "Widergy Mobile Components",
4
4
  "author": "widergy",
5
- "version": "1.32.14",
5
+ "version": "1.32.15",
6
6
  "repository": "https://github.com/widergy/mobile-ui.git",
7
7
  "main": "lib/index.js",
8
8
  "files": [