bootstrap-rn 0.3.1 → 0.3.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.
Files changed (71) hide show
  1. package/lib/commonjs/Provider.js +3 -0
  2. package/lib/commonjs/Provider.js.map +1 -1
  3. package/lib/commonjs/components/Caret.js +1 -1
  4. package/lib/commonjs/components/badge/Badge.js +1 -1
  5. package/lib/commonjs/components/buttons/Button.js +3 -3
  6. package/lib/commonjs/components/close/CloseButton.js +2 -2
  7. package/lib/commonjs/components/dropdown/DropdownItem.js +1 -1
  8. package/lib/commonjs/components/dropdown/useToggleDropdown.js +1 -0
  9. package/lib/commonjs/components/dropdown/useToggleDropdown.js.map +1 -1
  10. package/lib/commonjs/components/forms/FormCheckInput.js +1 -1
  11. package/lib/commonjs/components/list-group/ListGroupItem.js +1 -1
  12. package/lib/commonjs/components/modal/Modal.js +3 -8
  13. package/lib/commonjs/components/modal/Modal.js.map +1 -1
  14. package/lib/commonjs/components/modal/useModal.js +13 -1
  15. package/lib/commonjs/components/modal/useModal.js.map +1 -1
  16. package/lib/commonjs/components/navbar/NavbarToggler.js +1 -1
  17. package/lib/commonjs/components/offcanvas/Offcanvas.js +1 -6
  18. package/lib/commonjs/components/offcanvas/Offcanvas.js.map +1 -1
  19. package/lib/commonjs/components/offcanvas/useOffcanvas.js +13 -1
  20. package/lib/commonjs/components/offcanvas/useOffcanvas.js.map +1 -1
  21. package/lib/commonjs/components/toasts/Toast.js +1 -1
  22. package/lib/commonjs/components/toasts/ToastContainer.js +1 -1
  23. package/lib/commonjs/hooks/useScrollbarEffects.js +48 -41
  24. package/lib/commonjs/hooks/useScrollbarEffects.js.map +1 -1
  25. package/lib/commonjs/theme/utilities.js +8 -8
  26. package/lib/commonjs/theme/utilities.js.map +1 -1
  27. package/lib/module/Provider.js +3 -0
  28. package/lib/module/Provider.js.map +1 -1
  29. package/lib/module/components/Caret.js +1 -1
  30. package/lib/module/components/badge/Badge.js +1 -1
  31. package/lib/module/components/buttons/Button.js +3 -3
  32. package/lib/module/components/close/CloseButton.js +2 -2
  33. package/lib/module/components/dropdown/DropdownItem.js +1 -1
  34. package/lib/module/components/dropdown/useToggleDropdown.js +1 -0
  35. package/lib/module/components/dropdown/useToggleDropdown.js.map +1 -1
  36. package/lib/module/components/forms/FormCheckInput.js +1 -1
  37. package/lib/module/components/list-group/ListGroupItem.js +1 -1
  38. package/lib/module/components/modal/Modal.js +3 -8
  39. package/lib/module/components/modal/Modal.js.map +1 -1
  40. package/lib/module/components/modal/useModal.js +13 -2
  41. package/lib/module/components/modal/useModal.js.map +1 -1
  42. package/lib/module/components/navbar/NavbarToggler.js +1 -1
  43. package/lib/module/components/offcanvas/Offcanvas.js +1 -6
  44. package/lib/module/components/offcanvas/Offcanvas.js.map +1 -1
  45. package/lib/module/components/offcanvas/useOffcanvas.js +13 -2
  46. package/lib/module/components/offcanvas/useOffcanvas.js.map +1 -1
  47. package/lib/module/components/toasts/Toast.js +1 -1
  48. package/lib/module/components/toasts/ToastContainer.js +1 -1
  49. package/lib/module/hooks/useScrollbarEffects.js +49 -41
  50. package/lib/module/hooks/useScrollbarEffects.js.map +1 -1
  51. package/lib/module/theme/utilities.js +8 -8
  52. package/lib/module/theme/utilities.js.map +1 -1
  53. package/package.json +69 -69
  54. package/src/Provider.js +63 -59
  55. package/src/components/Caret.js +127 -127
  56. package/src/components/badge/Badge.js +52 -52
  57. package/src/components/buttons/Button.js +381 -381
  58. package/src/components/close/CloseButton.js +146 -146
  59. package/src/components/dropdown/DropdownItem.js +151 -151
  60. package/src/components/dropdown/useToggleDropdown.js +1 -0
  61. package/src/components/forms/FormCheckInput.js +247 -247
  62. package/src/components/list-group/ListGroupItem.js +1 -1
  63. package/src/components/modal/Modal.js +235 -241
  64. package/src/components/modal/useModal.js +25 -10
  65. package/src/components/navbar/NavbarToggler.js +132 -132
  66. package/src/components/offcanvas/Offcanvas.js +252 -258
  67. package/src/components/offcanvas/useOffcanvas.js +20 -5
  68. package/src/components/toasts/Toast.js +1 -1
  69. package/src/components/toasts/ToastContainer.js +43 -43
  70. package/src/hooks/useScrollbarEffects.js +82 -62
  71. package/src/theme/utilities.js +4 -4
@@ -1,241 +1,235 @@
1
- import React, { useRef } from 'react';
2
- import { Modal as BaseModal, SafeAreaView } from 'react-native';
3
- import PropTypes from 'prop-types';
4
- import { OverlayProvider } from '@react-native-aria/overlays';
5
- import StyleSheet from '../../style/StyleSheet';
6
- import { getStyles } from '../../utils';
7
- import css from '../../style/css';
8
- import ScrollView from '../ScrollView';
9
- import View from '../View';
10
- import BackdropHandler from '../helpers/BackdropHandler';
11
- import useScrollbarEffects from '../../hooks/useScrollbarEffects';
12
- import useModal from './useModal';
13
- import ModalContext from './ModalContext';
14
- import ModalHeader from './ModalHeader';
15
- import ModalTitle from './ModalTitle';
16
- import ModalBody from './ModalBody';
17
- import ModalFooter from './ModalFooter';
18
-
19
- const MODAL_SIZES = ['sm', 'lg', 'xl'];
20
-
21
- const propTypes = {
22
- children: PropTypes.node.isRequired,
23
- visible: PropTypes.bool.isRequired,
24
- size: PropTypes.oneOf(MODAL_SIZES),
25
- backdrop: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['static'])]),
26
- scrollable: PropTypes.bool,
27
- centered: PropTypes.bool,
28
- onToggle: PropTypes.func.isRequired,
29
- // eslint-disable-next-line react/forbid-prop-types
30
- style: PropTypes.any,
31
- // eslint-disable-next-line react/forbid-prop-types
32
- contentContainerStyle: PropTypes.any,
33
- // eslint-disable-next-line react/forbid-prop-types
34
- dialogStyle: PropTypes.any,
35
- // eslint-disable-next-line react/forbid-prop-types
36
- contentStyle: PropTypes.any,
37
- // eslint-disable-next-line react/forbid-prop-types
38
- textStyle: PropTypes.any,
39
- // eslint-disable-next-line react/forbid-prop-types
40
- dialogTextStyle: PropTypes.any,
41
- // eslint-disable-next-line react/forbid-prop-types
42
- contentTextStyle: PropTypes.any,
43
- };
44
-
45
- const styles = StyleSheet.create({
46
- '.modal': css`
47
- position: absolute; // fixed;
48
- top: 0;
49
- left: 0;
50
- z-index: $zindex-modal;
51
- // display: none;
52
- width: 100%;
53
- height: 100%;
54
- // overflow-x: hidden;
55
- // overflow-y: auto;
56
- // Prevent Chrome on Windows from adding a focus outline. For details, see
57
- // https://github.com/twbs/bootstrap/pull/10951.
58
- @include platform(web) {
59
- outline-width: 0; // outline: 0;
60
- }
61
- // We deliberately don't use "-webkit-overflow-scrolling: touch;" due to a
62
- // gnarly iOS Safari bug: https://bugs.webkit.org/show_bug.cgi?id=158342
63
- // See also https://github.com/twbs/bootstrap/issues/17695
64
- `,
65
- '.modal-dialog': css`
66
- position: relative;
67
- width: auto;
68
- margin: $modal-dialog-margin;
69
- // allow clicks to pass through for custom click handling to close modal
70
- // pointer-events: none;
71
-
72
- @include media-breakpoint-up(sm) {
73
- width: 100%; // added for bootstrap-rn
74
- max-width: $modal-md;
75
- margin: $modal-dialog-margin-y-sm-up auto;
76
- }
77
- `,
78
- '.modal-dialog-scrollable': css`
79
- flex-shrink: 1; // added for bootstrap-rn
80
- // height: calc(100% - var(--#{$prefix}modal-margin) * 2);
81
- `,
82
- '.modal-dialog-scrollable .modal-content': css`
83
- max-height: 100%;
84
- overflow: hidden;
85
- `,
86
- '.modal-dialog-centered': css`
87
- display: flex;
88
- // align-items: center;
89
- // min-height: calc(100% - var(--#{$prefix}modal-margin) * 2);
90
- `,
91
- '.modal-content': css`
92
- position: relative;
93
- display: flex;
94
- flex-direction: column;
95
- width: 100%; // Ensure ".modal-content" extends the full width of the parent ".modal-dialog"
96
- // counteract the pointer-events: none; in the .modal-dialog
97
- // pointer-events: auto;
98
- background-color: $modal-content-bg;
99
- // background-clip: padding-box;
100
- border: $modal-content-border-width solid $modal-content-border-color;
101
- border-radius: $modal-content-border-radius;
102
- // @include box-shadow($modal-content-box-shadow-xs);
103
- // Remove focus outline from opened modal
104
- // outline: 0;
105
-
106
- @include media-breakpoint-up(sm) {
107
- // @include box-shadow($modal-content-box-shadow-sm-up);
108
- }
109
- `,
110
- '.modal-content --text': css`
111
- color: $modal-content-color;
112
- `,
113
- '.modal-backdrop': css`
114
- position: absolute;
115
- top: 0;
116
- left: 0;
117
- z-index: $zindex-modal-backdrop;
118
- width: 100%;
119
- height: 100%;
120
- background-color: $modal-backdrop-bg;
121
- opacity: $modal-backdrop-opacity;
122
- `,
123
- '.modal-sm': css`
124
- @include media-breakpoint-up(sm) {
125
- max-width: $modal-sm;
126
- }
127
- `,
128
- '.modal-lg': css`
129
- @include media-breakpoint-up(lg) {
130
- max-width: $modal-lg;
131
- }
132
- `,
133
- '.modal-xl': css`
134
- @include media-breakpoint-up(lg) {
135
- max-width: $modal-lg;
136
- }
137
- @include media-breakpoint-up(xl) {
138
- max-width: $modal-xl;
139
- }
140
- `,
141
- });
142
-
143
- const Modal = React.forwardRef((props, ref) => {
144
- const {
145
- children,
146
- visible,
147
- size,
148
- backdrop = true,
149
- scrollable = false,
150
- centered = false,
151
- onToggle: handleToggle,
152
- style,
153
- contentContainerStyle,
154
- dialogStyle,
155
- contentStyle,
156
- textStyle,
157
- dialogTextStyle,
158
- contentTextStyle,
159
- ...elementProps
160
- } = props;
161
-
162
- const dialogRef = useRef();
163
-
164
- const modal = useModal(scrollable);
165
-
166
- useScrollbarEffects({
167
- keepBodyScroll: false,
168
- visible,
169
- });
170
-
171
- const backdropClasses = getStyles(styles, ['.modal-backdrop']);
172
- const classes = getStyles(styles, ['.modal']);
173
- const dialogClasses = getStyles(styles, [
174
- '.modal-dialog',
175
- size === 'sm' && '.modal-sm',
176
- size === 'lg' && '.modal-lg',
177
- size === 'xl' && '.modal-xl',
178
- scrollable && '.modal-dialog-scrollable',
179
- centered && '.modal-dialog-centered',
180
- ]);
181
- const contentClasses = getStyles(styles, [
182
- '.modal-content',
183
- scrollable && '.modal-dialog-scrollable .modal-content',
184
- ]);
185
- const contentTextClasses = getStyles(styles, ['.modal-content --text']);
186
-
187
- // If scrollable we use a ScrollView in ModalBody, so we can use a View here.
188
- const FlexView = scrollable ? View : ScrollView;
189
-
190
- const centeredStyle = centered && { justifyContent: 'center' };
191
-
192
- return (
193
- <BaseModal transparent visible={visible} onRequestClose={handleToggle}>
194
- {backdrop && <View style={backdropClasses} />}
195
- <FlexView
196
- {...elementProps}
197
- ref={ref}
198
- style={[classes, scrollable && centeredStyle, style]}
199
- textStyle={textStyle}
200
- contentContainerStyle={
201
- scrollable
202
- ? undefined
203
- : [{ flexGrow: 1 }, centeredStyle, contentContainerStyle]
204
- }
205
- >
206
- <BackdropHandler
207
- dialogRef={dialogRef}
208
- onClose={handleToggle}
209
- backdrop={backdrop}
210
- />
211
- <SafeAreaView style={{ flexShrink: 1 }}>
212
- <View
213
- ref={dialogRef}
214
- style={[dialogClasses, dialogStyle]}
215
- textStyle={dialogTextStyle}
216
- >
217
- <View
218
- style={[contentClasses, contentStyle]}
219
- textStyle={[contentTextClasses, contentTextStyle]}
220
- >
221
- <ModalContext.Provider value={modal}>
222
- <OverlayProvider>{children}</OverlayProvider>
223
- </ModalContext.Provider>
224
- </View>
225
- </View>
226
- </SafeAreaView>
227
- </FlexView>
228
- </BaseModal>
229
- );
230
- });
231
-
232
- Modal.displayName = 'Modal';
233
- Modal.propTypes = propTypes;
234
-
235
- Modal.Context = ModalContext;
236
- Modal.Header = ModalHeader;
237
- Modal.Title = ModalTitle;
238
- Modal.Body = ModalBody;
239
- Modal.Footer = ModalFooter;
240
-
241
- export default Modal;
1
+ import React, { useRef } from 'react';
2
+ import { Modal as BaseModal, SafeAreaView } from 'react-native';
3
+ import PropTypes from 'prop-types';
4
+ import { OverlayProvider } from '@react-native-aria/overlays';
5
+ import StyleSheet from '../../style/StyleSheet';
6
+ import { getStyles } from '../../utils';
7
+ import css from '../../style/css';
8
+ import ScrollView from '../ScrollView';
9
+ import View from '../View';
10
+ import BackdropHandler from '../helpers/BackdropHandler';
11
+ import useModal from './useModal';
12
+ import ModalContext from './ModalContext';
13
+ import ModalHeader from './ModalHeader';
14
+ import ModalTitle from './ModalTitle';
15
+ import ModalBody from './ModalBody';
16
+ import ModalFooter from './ModalFooter';
17
+
18
+ const MODAL_SIZES = ['sm', 'lg', 'xl'];
19
+
20
+ const propTypes = {
21
+ children: PropTypes.node.isRequired,
22
+ visible: PropTypes.bool.isRequired,
23
+ size: PropTypes.oneOf(MODAL_SIZES),
24
+ backdrop: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['static'])]),
25
+ scrollable: PropTypes.bool,
26
+ centered: PropTypes.bool,
27
+ onToggle: PropTypes.func.isRequired,
28
+ // eslint-disable-next-line react/forbid-prop-types
29
+ style: PropTypes.any,
30
+ // eslint-disable-next-line react/forbid-prop-types
31
+ contentContainerStyle: PropTypes.any,
32
+ // eslint-disable-next-line react/forbid-prop-types
33
+ dialogStyle: PropTypes.any,
34
+ // eslint-disable-next-line react/forbid-prop-types
35
+ contentStyle: PropTypes.any,
36
+ // eslint-disable-next-line react/forbid-prop-types
37
+ textStyle: PropTypes.any,
38
+ // eslint-disable-next-line react/forbid-prop-types
39
+ dialogTextStyle: PropTypes.any,
40
+ // eslint-disable-next-line react/forbid-prop-types
41
+ contentTextStyle: PropTypes.any,
42
+ };
43
+
44
+ const styles = StyleSheet.create({
45
+ '.modal': css`
46
+ position: absolute; // fixed;
47
+ top: 0;
48
+ left: 0;
49
+ z-index: $zindex-modal;
50
+ // display: none;
51
+ width: 100%;
52
+ height: 100%;
53
+ // overflow-x: hidden;
54
+ // overflow-y: auto;
55
+ // Prevent Chrome on Windows from adding a focus outline. For details, see
56
+ // https://github.com/twbs/bootstrap/pull/10951.
57
+ @include platform(web) {
58
+ outline-width: 0; // outline: 0;
59
+ }
60
+ // We deliberately don't use "-webkit-overflow-scrolling: touch;" due to a
61
+ // gnarly iOS Safari bug: https://bugs.webkit.org/show_bug.cgi?id=158342
62
+ // See also https://github.com/twbs/bootstrap/issues/17695
63
+ `,
64
+ '.modal-dialog': css`
65
+ position: relative;
66
+ width: auto;
67
+ margin: $modal-dialog-margin;
68
+ // allow clicks to pass through for custom click handling to close modal
69
+ pointer-events: none;
70
+
71
+ @include media-breakpoint-up(sm) {
72
+ width: 100%; // added for bootstrap-rn
73
+ max-width: $modal-md;
74
+ margin: $modal-dialog-margin-y-sm-up auto;
75
+ }
76
+ `,
77
+ '.modal-dialog-scrollable': css`
78
+ flex-shrink: 1; // added for bootstrap-rn
79
+ // height: calc(100% - var(--#{$prefix}modal-margin) * 2);
80
+ `,
81
+ '.modal-dialog-scrollable .modal-content': css`
82
+ max-height: 100%;
83
+ overflow: hidden;
84
+ `,
85
+ '.modal-dialog-centered': css`
86
+ display: flex;
87
+ // align-items: center;
88
+ // min-height: calc(100% - var(--#{$prefix}modal-margin) * 2);
89
+ `,
90
+ '.modal-content': css`
91
+ position: relative;
92
+ display: flex;
93
+ flex-direction: column;
94
+ width: 100%; // Ensure ".modal-content" extends the full width of the parent ".modal-dialog"
95
+ // counteract the pointer-events: none; in the .modal-dialog
96
+ pointer-events: auto;
97
+ background-color: $modal-content-bg;
98
+ // background-clip: padding-box;
99
+ border: $modal-content-border-width solid $modal-content-border-color;
100
+ border-radius: $modal-content-border-radius;
101
+ // @include box-shadow($modal-content-box-shadow-xs);
102
+ // Remove focus outline from opened modal
103
+ // outline: 0;
104
+
105
+ @include media-breakpoint-up(sm) {
106
+ // @include box-shadow($modal-content-box-shadow-sm-up);
107
+ }
108
+ `,
109
+ '.modal-content --text': css`
110
+ color: $modal-content-color;
111
+ `,
112
+ '.modal-backdrop': css`
113
+ position: absolute;
114
+ top: 0;
115
+ left: 0;
116
+ z-index: $zindex-modal-backdrop;
117
+ width: 100%;
118
+ height: 100%;
119
+ background-color: $modal-backdrop-bg;
120
+ opacity: $modal-backdrop-opacity;
121
+ `,
122
+ '.modal-sm': css`
123
+ @include media-breakpoint-up(sm) {
124
+ max-width: $modal-sm;
125
+ }
126
+ `,
127
+ '.modal-lg': css`
128
+ @include media-breakpoint-up(lg) {
129
+ max-width: $modal-lg;
130
+ }
131
+ `,
132
+ '.modal-xl': css`
133
+ @include media-breakpoint-up(lg) {
134
+ max-width: $modal-lg;
135
+ }
136
+ @include media-breakpoint-up(xl) {
137
+ max-width: $modal-xl;
138
+ }
139
+ `,
140
+ });
141
+
142
+ const Modal = React.forwardRef((props, ref) => {
143
+ const {
144
+ children,
145
+ visible,
146
+ size,
147
+ backdrop = true,
148
+ scrollable = false,
149
+ centered = false,
150
+ onToggle: handleToggle,
151
+ style,
152
+ contentContainerStyle,
153
+ dialogStyle,
154
+ contentStyle,
155
+ textStyle,
156
+ dialogTextStyle,
157
+ contentTextStyle,
158
+ ...elementProps
159
+ } = props;
160
+
161
+ const dialogRef = useRef();
162
+
163
+ const modal = useModal(visible, scrollable);
164
+
165
+ const backdropClasses = getStyles(styles, ['.modal-backdrop']);
166
+ const classes = getStyles(styles, ['.modal']);
167
+ const dialogClasses = getStyles(styles, [
168
+ '.modal-dialog',
169
+ size === 'sm' && '.modal-sm',
170
+ size === 'lg' && '.modal-lg',
171
+ size === 'xl' && '.modal-xl',
172
+ scrollable && '.modal-dialog-scrollable',
173
+ centered && '.modal-dialog-centered',
174
+ ]);
175
+ const contentClasses = getStyles(styles, [
176
+ '.modal-content',
177
+ scrollable && '.modal-dialog-scrollable .modal-content',
178
+ ]);
179
+ const contentTextClasses = getStyles(styles, ['.modal-content --text']);
180
+
181
+ // If scrollable we use a ScrollView in ModalBody, so we can use a View here.
182
+ const FlexView = scrollable ? View : ScrollView;
183
+
184
+ const centeredStyle = centered && { justifyContent: 'center' };
185
+
186
+ return (
187
+ <BaseModal transparent visible={visible} onRequestClose={handleToggle}>
188
+ {backdrop && <View style={backdropClasses} />}
189
+ <FlexView
190
+ {...elementProps}
191
+ ref={ref}
192
+ style={[classes, scrollable && centeredStyle, style]}
193
+ textStyle={textStyle}
194
+ contentContainerStyle={
195
+ scrollable
196
+ ? undefined
197
+ : [{ flexGrow: 1 }, centeredStyle, contentContainerStyle]
198
+ }
199
+ >
200
+ <BackdropHandler
201
+ dialogRef={dialogRef}
202
+ onClose={handleToggle}
203
+ backdrop={backdrop}
204
+ />
205
+ <SafeAreaView style={{ flexShrink: 1 }}>
206
+ <View
207
+ ref={dialogRef}
208
+ style={[dialogClasses, dialogStyle]}
209
+ textStyle={dialogTextStyle}
210
+ >
211
+ <View
212
+ style={[contentClasses, contentStyle]}
213
+ textStyle={[contentTextClasses, contentTextStyle]}
214
+ >
215
+ <ModalContext.Provider value={modal}>
216
+ <OverlayProvider>{children}</OverlayProvider>
217
+ </ModalContext.Provider>
218
+ </View>
219
+ </View>
220
+ </SafeAreaView>
221
+ </FlexView>
222
+ </BaseModal>
223
+ );
224
+ });
225
+
226
+ Modal.displayName = 'Modal';
227
+ Modal.propTypes = propTypes;
228
+
229
+ Modal.Context = ModalContext;
230
+ Modal.Header = ModalHeader;
231
+ Modal.Title = ModalTitle;
232
+ Modal.Body = ModalBody;
233
+ Modal.Footer = ModalFooter;
234
+
235
+ export default Modal;
@@ -1,10 +1,25 @@
1
- import { useMemo } from 'react';
2
-
3
- export default function useModal(scrollable) {
4
- return useMemo(
5
- () => ({
6
- scrollable,
7
- }),
8
- [scrollable],
9
- );
10
- }
1
+ import { useContext, useEffect, useMemo } from 'react';
2
+ import Context from '../../Context';
3
+
4
+ export default function useModal(visible, scrollable) {
5
+ const context = useContext(Context);
6
+
7
+ useEffect(() => {
8
+ if (!visible) {
9
+ return undefined;
10
+ }
11
+
12
+ context.scrollbars.hide();
13
+
14
+ return () => {
15
+ context.scrollbars.show();
16
+ };
17
+ }, [visible]);
18
+
19
+ return useMemo(
20
+ () => ({
21
+ scrollable,
22
+ }),
23
+ [scrollable],
24
+ );
25
+ }