@draftbit/core 46.8.1-d78af9.2 → 46.8.1-eb4f7f.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 (41) hide show
  1. package/lib/commonjs/components/BottomSheet/BottomSheet.js +89 -0
  2. package/lib/commonjs/components/BottomSheet/BottomSheetComponent.js +464 -0
  3. package/lib/commonjs/components/BottomSheet/index.js +13 -0
  4. package/lib/commonjs/components/DeckSwiper/DeckSwiper.js +4 -38
  5. package/lib/commonjs/index.js +7 -0
  6. package/lib/commonjs/mappings/BottomSheet.js +75 -0
  7. package/lib/module/components/BottomSheet/BottomSheet.js +81 -0
  8. package/lib/module/components/BottomSheet/BottomSheetComponent.js +470 -0
  9. package/lib/module/components/BottomSheet/index.js +1 -0
  10. package/lib/module/components/DeckSwiper/DeckSwiper.js +4 -38
  11. package/lib/module/index.js +1 -0
  12. package/lib/module/mappings/BottomSheet.js +68 -0
  13. package/lib/typescript/src/components/BottomSheet/BottomSheet.d.ts +20 -0
  14. package/lib/typescript/src/components/BottomSheet/BottomSheet.d.ts.map +1 -0
  15. package/lib/typescript/src/components/BottomSheet/BottomSheetComponent.d.ts +170 -0
  16. package/lib/typescript/src/components/BottomSheet/BottomSheetComponent.d.ts.map +1 -0
  17. package/lib/typescript/src/components/BottomSheet/index.d.ts +2 -0
  18. package/lib/typescript/src/components/BottomSheet/index.d.ts.map +1 -0
  19. package/lib/typescript/src/components/DeckSwiper/DeckSwiper.d.ts +2 -8
  20. package/lib/typescript/src/components/DeckSwiper/DeckSwiper.d.ts.map +1 -1
  21. package/lib/typescript/src/components/DeckSwiper/DeckSwiperCard.d.ts +3 -2
  22. package/lib/typescript/src/components/DeckSwiper/DeckSwiperCard.d.ts.map +1 -1
  23. package/lib/typescript/src/index.d.ts +1 -0
  24. package/lib/typescript/src/index.d.ts.map +1 -1
  25. package/lib/typescript/src/mappings/BottomSheet.d.ts +120 -0
  26. package/lib/typescript/src/mappings/BottomSheet.d.ts.map +1 -0
  27. package/package.json +3 -3
  28. package/src/components/BottomSheet/BottomSheet.js +57 -0
  29. package/src/components/BottomSheet/BottomSheet.tsx +121 -0
  30. package/src/components/BottomSheet/BottomSheetComponent.js +437 -0
  31. package/src/components/BottomSheet/BottomSheetComponent.tsx +895 -0
  32. package/src/components/BottomSheet/index.js +1 -0
  33. package/src/components/BottomSheet/index.ts +1 -0
  34. package/src/components/DeckSwiper/DeckSwiper.js +3 -33
  35. package/src/components/DeckSwiper/DeckSwiper.tsx +9 -51
  36. package/src/components/DeckSwiper/DeckSwiperCard.js +1 -1
  37. package/src/components/DeckSwiper/DeckSwiperCard.tsx +6 -3
  38. package/src/index.js +1 -0
  39. package/src/index.tsx +2 -0
  40. package/src/mappings/BottomSheet.js +64 -0
  41. package/src/mappings/BottomSheet.ts +78 -0
@@ -0,0 +1 @@
1
+ export { default as BottomSheet } from "./BottomSheet";
@@ -0,0 +1 @@
1
+ export { default as BottomSheet } from "./BottomSheet";
@@ -1,40 +1,10 @@
1
1
  import React from "react";
2
2
  import { StyleSheet, View } from "react-native";
3
3
  import DeckSwiperComponent from "react-native-deck-swiper";
4
- const DeckSwiper = ({ onIndexChanged, onEndReached, startCardIndex = 0, infiniteSwiping = false, verticalEnabled = true, horizontalEnabled = true, visibleCardCount = 1, data, keyExtractor, renderItem, style, children, }) => {
5
- //Both 'renderItem' and 'data' are optional to allow direct children. But if one is included, both need to be included
6
- if ((data && !renderItem) || (renderItem && !data)) {
7
- throw new Error("'renderItem' and 'data' need to both be provided to lazily render. Either remove them entirley or include both");
8
- }
9
- if (data && renderItem && children) {
10
- console.warn("'children' of DeckSwiper ignored due to usage of 'data' and 'renderItem'");
11
- }
4
+ const DeckSwiper = ({ onIndexChanged, onEndReached, startCardIndex = 0, infiniteSwiping = false, verticalEnabled = true, horizontalEnabled = true, visibleCardCount = 1, style, children, }) => {
12
5
  const childrenArray = React.useMemo(() => React.Children.toArray(children), [children]);
13
6
  // an array of indices based on children count
14
7
  const cardsFillerData = React.useMemo(() => Array.from(Array(childrenArray.length).keys()), [childrenArray]);
15
- const cardsData = data || cardsFillerData;
16
- const renderCard = (card, index) => {
17
- if (renderItem) {
18
- return renderItem({ item: card, index });
19
- }
20
- else {
21
- return React.createElement(React.Fragment, null, childrenArray[index]);
22
- }
23
- };
24
- const renderFirstCard = () => {
25
- if (cardsData.length) {
26
- return renderCard(cardsData[0], 0);
27
- }
28
- return undefined;
29
- };
30
- const cardKeyExtractor = (card) => {
31
- if (keyExtractor) {
32
- return keyExtractor(card);
33
- }
34
- else {
35
- return card.toString();
36
- }
37
- };
38
8
  /**
39
9
  * By default react-native-deck-swiper positions everything with absolute position.
40
10
  * To overcome this, it is wrapped in a View to be able to add the component in any layout structure.
@@ -45,8 +15,8 @@ const DeckSwiper = ({ onIndexChanged, onEndReached, startCardIndex = 0, infinite
45
15
  * This effectivley makes the default height of the container be the height of the first card.
46
16
  */
47
17
  return (React.createElement(View, null,
48
- React.createElement(View, { style: styles.containerHeightFiller }, renderFirstCard()),
49
- React.createElement(DeckSwiperComponent, { cards: cardsData, renderCard: renderCard, keyExtractor: cardKeyExtractor, containerStyle: StyleSheet.flatten([styles.cardsContainer, style]), cardStyle: styles.card, onSwiped: onIndexChanged, onSwipedAll: onEndReached, cardIndex: startCardIndex, infinite: infiniteSwiping, verticalSwipe: verticalEnabled, horizontalSwipe: horizontalEnabled, showSecondCard: visibleCardCount > 1, stackSize: visibleCardCount, backgroundColor: "transparent", cardVerticalMargin: 0, cardHorizontalMargin: 0 })));
18
+ React.createElement(View, { style: styles.containerHeightFiller }, childrenArray.length && childrenArray[0]),
19
+ React.createElement(DeckSwiperComponent, { cards: cardsFillerData, renderCard: (_, i) => React.createElement(React.Fragment, null, childrenArray[i]), keyExtractor: (card) => card === null || card === void 0 ? void 0 : card.toString(), containerStyle: StyleSheet.flatten([styles.cardsContainer, style]), cardStyle: styles.card, onSwiped: onIndexChanged, onSwipedAll: onEndReached, cardIndex: startCardIndex, infinite: infiniteSwiping, verticalSwipe: verticalEnabled, horizontalSwipe: horizontalEnabled, showSecondCard: visibleCardCount > 1, stackSize: visibleCardCount, backgroundColor: "transparent", cardVerticalMargin: 0, cardHorizontalMargin: 0 })));
50
20
  };
51
21
  const styles = StyleSheet.create({
52
22
  cardsContainer: {
@@ -2,7 +2,7 @@ import React from "react";
2
2
  import { StyleProp, ViewStyle, StyleSheet, View } from "react-native";
3
3
  import DeckSwiperComponent from "react-native-deck-swiper";
4
4
 
5
- export interface DeckSwiperProps<T> {
5
+ export interface DeckSwiperProps {
6
6
  onIndexChanged?: (index: number) => void;
7
7
  onEndReached?: () => void;
8
8
  startCardIndex?: number;
@@ -10,13 +10,10 @@ export interface DeckSwiperProps<T> {
10
10
  verticalEnabled?: boolean;
11
11
  horizontalEnabled?: boolean;
12
12
  visibleCardCount?: number;
13
- data?: Array<T>;
14
- keyExtractor?: (item: T) => string;
15
- renderItem?: ({ item, index }: { item: T; index: number }) => JSX.Element;
16
13
  style?: StyleProp<ViewStyle>;
17
14
  }
18
15
 
19
- const DeckSwiper = <T extends object>({
16
+ const DeckSwiper: React.FC<React.PropsWithChildren<DeckSwiperProps>> = ({
20
17
  onIndexChanged,
21
18
  onEndReached,
22
19
  startCardIndex = 0,
@@ -24,25 +21,9 @@ const DeckSwiper = <T extends object>({
24
21
  verticalEnabled = true,
25
22
  horizontalEnabled = true,
26
23
  visibleCardCount = 1,
27
- data,
28
- keyExtractor,
29
- renderItem,
30
24
  style,
31
25
  children,
32
- }: React.PropsWithChildren<DeckSwiperProps<T>>) => {
33
- //Both 'renderItem' and 'data' are optional to allow direct children. But if one is included, both need to be included
34
- if ((data && !renderItem) || (renderItem && !data)) {
35
- throw new Error(
36
- "'renderItem' and 'data' need to both be provided to lazily render. Either remove them entirley or include both"
37
- );
38
- }
39
-
40
- if (data && renderItem && children) {
41
- console.warn(
42
- "'children' of DeckSwiper ignored due to usage of 'data' and 'renderItem'"
43
- );
44
- }
45
-
26
+ }) => {
46
27
  const childrenArray = React.useMemo(
47
28
  () => React.Children.toArray(children),
48
29
  [children]
@@ -54,31 +35,6 @@ const DeckSwiper = <T extends object>({
54
35
  [childrenArray]
55
36
  );
56
37
 
57
- const cardsData = data || cardsFillerData;
58
-
59
- const renderCard = (card: any, index: number): JSX.Element => {
60
- if (renderItem) {
61
- return renderItem({ item: card, index });
62
- } else {
63
- return <>{childrenArray[index]}</>;
64
- }
65
- };
66
-
67
- const renderFirstCard = (): JSX.Element | undefined => {
68
- if (cardsData.length) {
69
- return renderCard(cardsData[0], 0);
70
- }
71
- return undefined;
72
- };
73
-
74
- const cardKeyExtractor = (card: any) => {
75
- if (keyExtractor) {
76
- return keyExtractor(card);
77
- } else {
78
- return card.toString();
79
- }
80
- };
81
-
82
38
  /**
83
39
  * By default react-native-deck-swiper positions everything with absolute position.
84
40
  * To overcome this, it is wrapped in a View to be able to add the component in any layout structure.
@@ -91,11 +47,13 @@ const DeckSwiper = <T extends object>({
91
47
 
92
48
  return (
93
49
  <View>
94
- <View style={styles.containerHeightFiller}>{renderFirstCard()}</View>
50
+ <View style={styles.containerHeightFiller}>
51
+ {childrenArray.length && childrenArray[0]}
52
+ </View>
95
53
  <DeckSwiperComponent
96
- cards={cardsData as any[]}
97
- renderCard={renderCard}
98
- keyExtractor={cardKeyExtractor}
54
+ cards={cardsFillerData}
55
+ renderCard={(_, i) => <>{childrenArray[i]}</>}
56
+ keyExtractor={(card) => card?.toString()}
99
57
  containerStyle={
100
58
  StyleSheet.flatten([styles.cardsContainer, style]) as
101
59
  | object
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import { View, StyleSheet } from "react-native";
3
3
  import { withTheme } from "../../theming";
4
- const DeckSwiperCard = ({ style, children, theme }) => (React.createElement(View, { style: [
4
+ const DeckSwiperCard = ({ style, children, theme, }) => (React.createElement(View, { style: [
5
5
  styles.card,
6
6
  {
7
7
  backgroundColor: theme.colors.background,
@@ -5,12 +5,15 @@ import { withTheme } from "../../theming";
5
5
 
6
6
  export interface DeckSwiperCardProps {
7
7
  style?: StyleProp<ViewStyle>;
8
+ children: React.ReactNode;
8
9
  theme: Theme;
9
10
  }
10
11
 
11
- const DeckSwiperCard: React.FC<
12
- React.PropsWithChildren<DeckSwiperCardProps>
13
- > = ({ style, children, theme }) => (
12
+ const DeckSwiperCard: React.FC<DeckSwiperCardProps> = ({
13
+ style,
14
+ children,
15
+ theme,
16
+ }) => (
14
17
  <View
15
18
  style={[
16
19
  styles.card,
package/src/index.js CHANGED
@@ -32,6 +32,7 @@ export { Swiper, SwiperItem } from "./components/Swiper";
32
32
  export { Center, Circle, Square, Row, Stack, Spacer, } from "./components/Layout";
33
33
  export { RadioButton, RadioButtonGroup, RadioButtonRow, RadioButtonFieldGroup, } from "./components/RadioButton/index";
34
34
  export { DeckSwiper, DeckSwiperCard } from "./components/DeckSwiper";
35
+ export { BottomSheet } from "./components/BottomSheet";
35
36
  /* Deprecated: Fix or Delete! */
36
37
  export { default as DatePicker } from "./components/DatePicker/DatePicker";
37
38
  export { default as Picker } from "./components/Picker/Picker";
package/src/index.tsx CHANGED
@@ -53,6 +53,8 @@ export {
53
53
 
54
54
  export { DeckSwiper, DeckSwiperCard } from "./components/DeckSwiper";
55
55
 
56
+ export { BottomSheet } from "./components/BottomSheet";
57
+
56
58
  /* Deprecated: Fix or Delete! */
57
59
  export { default as DatePicker } from "./components/DatePicker/DatePicker";
58
60
  export { default as Picker } from "./components/Picker/Picker";
@@ -0,0 +1,64 @@
1
+ import { COMPONENT_TYPES, createStaticBoolProp, CONTAINER_COMPONENT_STYLES_SECTIONS, Triggers, createActionProp, createColorProp, createStaticArrayProp, createStaticNumberProp, } from "@draftbit/types";
2
+ export const SEED_DATA = {
3
+ name: "Bottom Sheet",
4
+ tag: "BottomSheet",
5
+ description: "A draggable Bottom sheet that snaps to specific points. Renders children in ScrollView",
6
+ category: COMPONENT_TYPES.bottomsheet,
7
+ stylesPanelSections: CONTAINER_COMPONENT_STYLES_SECTIONS,
8
+ layout: { paddingHorizontal: 16, paddingVertical: 10, flex: 1 },
9
+ triggers: [Triggers.OnSettle],
10
+ props: {
11
+ onSettle: createActionProp({
12
+ label: "On settle",
13
+ description: "Action to execute when sheet settles on a snap point",
14
+ }),
15
+ snapPoints: createStaticArrayProp({
16
+ label: "Snap points",
17
+ description: "An array of numerical values (that represent distance from the top) where bottom sheet can snap to place. Accepts numbers and percentages (minimum 2 snap points)",
18
+ defaultValue: ["10%", "50%", "80%"],
19
+ }),
20
+ initialSnapIndex: createStaticNumberProp({
21
+ label: "Initial snap index",
22
+ description: "Index of the snap point to be used as the initial point",
23
+ defaultValue: 0,
24
+ required: false,
25
+ }),
26
+ showHandle: createStaticBoolProp({
27
+ label: "Show handle",
28
+ description: "Whether to show the top handle or not",
29
+ defaultValue: true,
30
+ }),
31
+ handleColor: createColorProp({
32
+ label: "Handle color",
33
+ description: "Color of the top handle",
34
+ defaultValue: "divider",
35
+ }),
36
+ topBorderRadius: createStaticNumberProp({
37
+ label: "Top border radius",
38
+ description: "Border radius of top corners",
39
+ defaultValue: 20,
40
+ required: false,
41
+ }),
42
+ borderWidth: createStaticNumberProp({
43
+ label: "Border width",
44
+ description: "Width of bottom sheet borders",
45
+ defaultValue: 1,
46
+ required: false,
47
+ }),
48
+ borderColor: createColorProp({
49
+ label: "Border color",
50
+ description: "Color of bottom sheet borders",
51
+ defaultValue: "divider",
52
+ }),
53
+ showsVerticalScrollIndicator: createStaticBoolProp({
54
+ label: "Show Vertical Scroll Indicator",
55
+ description: "When true, shows a vertical scroll indicator. The default value is true.",
56
+ defaultValue: true,
57
+ }),
58
+ bounces: createStaticBoolProp({
59
+ label: "Bounce",
60
+ description: "When true, the scroll view bounces when it reaches the end of the content if the content is larger then the scroll view along the axis of the scroll direction.",
61
+ defaultValue: true,
62
+ }),
63
+ },
64
+ };
@@ -0,0 +1,78 @@
1
+ import {
2
+ COMPONENT_TYPES,
3
+ createStaticBoolProp,
4
+ CONTAINER_COMPONENT_STYLES_SECTIONS,
5
+ Triggers,
6
+ createActionProp,
7
+ createColorProp,
8
+ createStaticArrayProp,
9
+ createStaticNumberProp,
10
+ } from "@draftbit/types";
11
+
12
+ export const SEED_DATA = {
13
+ name: "Bottom Sheet",
14
+ tag: "BottomSheet",
15
+ description:
16
+ "A draggable Bottom sheet that snaps to specific points. Renders children in ScrollView",
17
+ category: COMPONENT_TYPES.bottomsheet,
18
+ stylesPanelSections: CONTAINER_COMPONENT_STYLES_SECTIONS,
19
+ layout: { paddingHorizontal: 16, paddingVertical: 10, flex: 1 },
20
+ triggers: [Triggers.OnSettle],
21
+ props: {
22
+ onSettle: createActionProp({
23
+ label: "On settle",
24
+ description: "Action to execute when sheet settles on a snap point",
25
+ }),
26
+ snapPoints: createStaticArrayProp({
27
+ label: "Snap points",
28
+ description:
29
+ "An array of numerical values (that represent distance from the top) where bottom sheet can snap to place. Accepts numbers and percentages (minimum 2 snap points)",
30
+ defaultValue: ["10%", "50%", "80%"],
31
+ }),
32
+ initialSnapIndex: createStaticNumberProp({
33
+ label: "Initial snap index",
34
+ description: "Index of the snap point to be used as the initial point",
35
+ defaultValue: 0,
36
+ required: false,
37
+ }),
38
+ showHandle: createStaticBoolProp({
39
+ label: "Show handle",
40
+ description: "Whether to show the top handle or not",
41
+ defaultValue: true,
42
+ }),
43
+ handleColor: createColorProp({
44
+ label: "Handle color",
45
+ description: "Color of the top handle",
46
+ defaultValue: "divider",
47
+ }),
48
+ topBorderRadius: createStaticNumberProp({
49
+ label: "Top border radius",
50
+ description: "Border radius of top corners",
51
+ defaultValue: 20,
52
+ required: false,
53
+ }),
54
+ borderWidth: createStaticNumberProp({
55
+ label: "Border width",
56
+ description: "Width of bottom sheet borders",
57
+ defaultValue: 1,
58
+ required: false,
59
+ }),
60
+ borderColor: createColorProp({
61
+ label: "Border color",
62
+ description: "Color of bottom sheet borders",
63
+ defaultValue: "divider",
64
+ }),
65
+ showsVerticalScrollIndicator: createStaticBoolProp({
66
+ label: "Show Vertical Scroll Indicator",
67
+ description:
68
+ "When true, shows a vertical scroll indicator. The default value is true.",
69
+ defaultValue: true,
70
+ }),
71
+ bounces: createStaticBoolProp({
72
+ label: "Bounce",
73
+ description:
74
+ "When true, the scroll view bounces when it reaches the end of the content if the content is larger then the scroll view along the axis of the scroll direction.",
75
+ defaultValue: true,
76
+ }),
77
+ },
78
+ };