@codeleap/mobile 5.8.1 → 5.8.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.
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import { EmptyPlaceholderButtonProps, EmptyPlaceholderIllustrationProps, EmptyPlaceholderInfoProps } from './types';
3
+ export declare const EmptyPlaceholderInfo: (props: EmptyPlaceholderInfoProps) => JSX.Element;
4
+ export declare const EmptyPlaceholderIllustration: (props: EmptyPlaceholderIllustrationProps) => JSX.Element;
5
+ export declare const EmptyPlaceholderButton: (props: EmptyPlaceholderButtonProps) => JSX.Element;
6
+ export declare const EmptyPlaceholderLoading: () => JSX.Element;
7
+ export declare const EmptyPlaceholderContent: ({ children }: React.PropsWithChildren) => JSX.Element;
@@ -0,0 +1,60 @@
1
+ import React from 'react';
2
+ import { useCompositionStyles } from '@codeleap/styles';
3
+ import { Icon } from '../Icon';
4
+ import { Text } from '../Text';
5
+ import { Image } from '../Image';
6
+ import { useEmptyPlaceholderContext } from './context';
7
+ import { Button } from '../Button';
8
+ import { View } from '../View';
9
+ import { ActivityIndicator } from '../ActivityIndicator';
10
+ import { TypeGuards } from '@codeleap/types';
11
+ export const EmptyPlaceholderInfo = (props) => {
12
+ const { title, description, styles, itemName } = useEmptyPlaceholderContext(props);
13
+ const emptyText = title || (itemName && `No ${itemName} found.`);
14
+ return <>
15
+ {title || itemName ? <Text text={emptyText} style={styles.title}/> : null}
16
+ {description ? <Text text={description} style={styles.description}/> : null}
17
+ </>;
18
+ };
19
+ export const EmptyPlaceholderIllustration = (props) => {
20
+ const { icon, image, styles } = useEmptyPlaceholderContext(props);
21
+ return <>
22
+ {icon ? <Icon name={icon} style={styles.icon}/> : null}
23
+ {image ? <Image source={image} style={styles.image}/> : null}
24
+ </>;
25
+ };
26
+ export const EmptyPlaceholderButton = (props) => {
27
+ const { styles, buttonText, text, onPress, ...buttonProps } = useEmptyPlaceholderContext(props);
28
+ const buttonStyles = useCompositionStyles('button', styles);
29
+ const displayText = text || buttonText;
30
+ if (!TypeGuards.isFunction(onPress))
31
+ return null;
32
+ return (<Button {...buttonProps} onPress={onPress} debugName={`emptyPlaceholderButton:${buttonText}`} style={buttonStyles} text={displayText}/>);
33
+ };
34
+ export const EmptyPlaceholderLoading = () => {
35
+ const { styles, loading, LoadingComponent } = useEmptyPlaceholderContext();
36
+ const activityIndicatorStyles = useCompositionStyles('loader', styles);
37
+ if (!loading)
38
+ return null;
39
+ if (React.isValidElement(LoadingComponent)) {
40
+ return <>{LoadingComponent}</>;
41
+ }
42
+ return (<View style={[styles.wrapper, styles['wrapper:loading']]}>
43
+ <ActivityIndicator style={activityIndicatorStyles}/>
44
+ </View>);
45
+ };
46
+ export const EmptyPlaceholderContent = ({ children }) => {
47
+ const { loading, styles } = useEmptyPlaceholderContext();
48
+ if (loading) {
49
+ return <EmptyPlaceholderLoading />;
50
+ }
51
+ if (children) {
52
+ return <View style={styles.wrapper}>{children}</View>;
53
+ }
54
+ return (<View style={styles.wrapper}>
55
+ <EmptyPlaceholderIllustration />
56
+ <EmptyPlaceholderInfo />
57
+ <EmptyPlaceholderButton />
58
+ </View>);
59
+ };
60
+ //# sourceMappingURL=Components.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Components.js","sourceRoot":"","sources":["../../../src/components/EmptyPlaceholder/Components.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAW,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAE9B,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM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CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,uBAAuB,CAAC,EACpD;IAAA,EAAE,IAAI,CAAC,CACR,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,EAAE,QAAQ,EAA2B,EAAE,EAAE;IAC/E,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,0BAA0B,EAAE,CAAA;IAExD,IAAI,OAAO,EAAE;QACX,OAAO,CAAC,uBAAuB,CAAC,AAAD,EAAG,CAAA;KACnC;IAED,IAAI,QAAQ,EAAE;QACZ,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAA;KACtD;IAED,OAAO,CACL,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAC1B;MAAA,CAAC,4BAA4B,CAAC,AAAD,EAC7B;MAAA,CAAC,oBAAoB,CAAC,AAAD,EACrB;MAAA,CAAC,sBAAsB,CAAC,AAAD,EACzB;IAAA,EAAE,IAAI,CAAC,CACR,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,15 @@
1
+ /// <reference types="react" />
2
+ import { EmptyPlaceholderCtxValue } from './types';
3
+ export declare const EmptyPlaceholderContext: import("react").Context<EmptyPlaceholderCtxValue>;
4
+ export declare const useEmptyPlaceholderContext: <T = EmptyPlaceholderCtxValue>(args?: Partial<T>) => {
5
+ description?: string;
6
+ onPress?: import("@codeleap/types").AnyFunction;
7
+ loading?: boolean;
8
+ title?: string;
9
+ image?: number | import("@d11/react-native-fast-image").Source;
10
+ icon?: never;
11
+ buttonText?: string;
12
+ itemName?: string;
13
+ LoadingComponent?: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
14
+ styles: import("@codeleap/styles").StyleRecord<import("./styles").EmptyPlaceholderComposition>;
15
+ } & Partial<T>;
@@ -0,0 +1,13 @@
1
+ import { createContext, useContext } from 'react';
2
+ export const EmptyPlaceholderContext = createContext({});
3
+ export const useEmptyPlaceholderContext = (args = {}) => {
4
+ const ctx = useContext(EmptyPlaceholderContext);
5
+ if (!ctx) {
6
+ throw new Error('useEmptyPlaceholderContext must be used within an EmptyPlaceholder component.');
7
+ }
8
+ return {
9
+ ...ctx,
10
+ ...args,
11
+ };
12
+ };
13
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/components/EmptyPlaceholder/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAGjD,MAAM,CAAC,MAAM,uBAAuB,GAAG,aAAa,CAAC,EAA8B,CAAC,CAAA;AAEpF,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAA+B,OAAmB,EAAE,EAAE,EAAE;IAChG,MAAM,GAAG,GAAG,UAAU,CAAC,uBAAuB,CAAC,CAAA;IAE/C,IAAI,CAAC,GAAG,EAAE;QACR,MAAM,IAAI,KAAK,CACb,+EAA+E,CAChF,CAAA;KACF;IAED,OAAO;QACL,GAAG,GAAG;QACN,GAAG,IAAI;KACR,CAAA;AACH,CAAC,CAAA"}
@@ -8,6 +8,9 @@ export declare const EmptyPlaceholder: {
8
8
  styleRegistryName: string;
9
9
  elements: string[];
10
10
  rootElement: string;
11
- withVariantTypes<S extends AnyRecord>(styles: S): (props: StyledComponentProps<EmptyPlaceholderProps, S>) => IJSX;
11
+ Info: (props: import("./types").EmptyPlaceholderInfoProps) => JSX.Element;
12
+ Button: (props: import("./types").EmptyPlaceholderButtonProps) => JSX.Element;
13
+ Illustration: (props: import("./types").EmptyPlaceholderIllustrationProps) => JSX.Element;
14
+ withVariantTypes<S extends AnyRecord>(styles: S): ((props: StyledComponentProps<EmptyPlaceholderProps, S>) => IJSX) & Pick<any, "Button" | "Illustration" | "Info">;
12
15
  defaultProps: Partial<EmptyPlaceholderProps>;
13
16
  };
@@ -1,55 +1,28 @@
1
1
  import React from 'react';
2
- import { Icon } from '../Icon';
3
- import { View } from '../View';
4
- import { Text } from '../Text';
5
- import { ActivityIndicator } from '../ActivityIndicator';
6
- import { Image } from '../Image';
7
- import { useNestedStylesByKey } from '@codeleap/styles';
8
2
  import { MobileStyleRegistry } from '../../Registry';
9
3
  import { useStylesFor } from '../../hooks';
4
+ import { EmptyPlaceholderContext } from './context';
5
+ import { EmptyPlaceholderContent, EmptyPlaceholderButton, EmptyPlaceholderIllustration, EmptyPlaceholderInfo } from './Components';
10
6
  export * from './styles';
11
7
  export * from './types';
12
8
  export const EmptyPlaceholder = (props) => {
13
- const { itemName, title, loading, description, image, icon = null, renderEmpty, style, } = {
9
+ const { children, style, ...contextValue } = {
14
10
  ...EmptyPlaceholder.defaultProps,
15
11
  ...props,
16
12
  };
17
- const emptyText = title || (itemName && `No ${itemName} found.`) || 'No items.';
18
13
  const styles = useStylesFor(EmptyPlaceholder.styleRegistryName, style);
19
- const activityIndicatorStyles = useNestedStylesByKey('loader', styles);
20
- if (loading) {
21
- return (<View style={[styles.wrapper, styles['wrapper:loading']]}>
22
- <ActivityIndicator style={activityIndicatorStyles}/>
23
- </View>);
24
- }
25
- if (renderEmpty) {
26
- return (<View style={styles.wrapper}>
27
- {renderEmpty({
28
- emptyText,
29
- emptyIconName: icon,
30
- style: styles,
31
- })}
32
- </View>);
33
- }
34
- let _image = null;
35
- if (icon) {
36
- _image = <Icon name={icon} style={styles.icon}/>;
37
- }
38
- else if (image) {
39
- _image = <Image source={image} style={styles.image}/>;
40
- }
41
- return (<View style={styles.wrapper}>
42
- {React.isValidElement(_image) ? (<View style={styles.imageWrapper}>
43
- {_image}
44
- </View>) : null}
45
-
46
- {React.isValidElement(emptyText) ? emptyText : <Text text={emptyText} style={styles.title}/>}
47
- {React.isValidElement(description) ? description : <Text text={description} style={styles.description}/>}
48
- </View>);
14
+ return (<EmptyPlaceholderContext.Provider value={{ ...contextValue, styles }}>
15
+ <EmptyPlaceholderContent>
16
+ {children}
17
+ </EmptyPlaceholderContent>
18
+ </EmptyPlaceholderContext.Provider>);
49
19
  };
50
20
  EmptyPlaceholder.styleRegistryName = 'EmptyPlaceholder';
51
21
  EmptyPlaceholder.elements = ['wrapper', 'loader', 'title', 'description', 'image', 'icon'];
52
22
  EmptyPlaceholder.rootElement = 'wrapper';
23
+ EmptyPlaceholder.Info = EmptyPlaceholderInfo;
24
+ EmptyPlaceholder.Button = EmptyPlaceholderButton;
25
+ EmptyPlaceholder.Illustration = EmptyPlaceholderIllustration;
53
26
  EmptyPlaceholder.withVariantTypes = (styles) => {
54
27
  return EmptyPlaceholder;
55
28
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/EmptyPlaceholder/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAEhC,OAAO,EAAsB,oBAAoB,EAA8B,MAAM,kBAAkB,CAAA;AACvG,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AAEvB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAA4B,EAAE,EAAE;IAC/D,MAAM,EACJ,QAAQ,EACR,KAAK,EACL,OAAO,EACP,WAAW,EACX,KAAK,EACL,IAAI,GAAG,IAAI,EACX,WAAW,EACX,KAAK,GACN,GAAG;QACF,GAAG,gBAAgB,CAAC,YAAY;QA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AqK,CAAA;AAC9K,CAAC,CAAA;AAED,gBAAgB,CAAC,YAAY,GAAG,EAAoC,CAAA;AAEpE,mBAAmB,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAA"}
@@ -1,2 +1,3 @@
1
1
  import { ActivityIndicatorComposition } from '../ActivityIndicator';
2
- export type EmptyPlaceholderComposition = 'wrapper:loading' | `loader${Capitalize<ActivityIndicatorComposition>}` | 'wrapper' | 'title' | 'description' | 'image' | 'imageWrapper' | 'icon';
2
+ import { ButtonComposition } from '../Button';
3
+ export type EmptyPlaceholderComposition = 'wrapper' | 'wrapper:loading' | 'title' | 'description' | 'image' | 'icon' | `button${Capitalize<ButtonComposition>}` | `loader${Capitalize<ActivityIndicatorComposition>}`;
@@ -1,20 +1,25 @@
1
- import { AppIcon, StyledProp } from '@codeleap/styles';
2
- import { ReactElement } from 'react';
1
+ import { AppIcon, StyleRecord, StyledProp } from '@codeleap/styles';
3
2
  import { ImageProps } from '../Image';
4
3
  import { EmptyPlaceholderComposition } from './styles';
5
- type RenderEmpty = (props: {
6
- emptyText: string | ReactElement;
7
- emptyIconName?: AppIcon;
8
- style?: StyledProp<EmptyPlaceholderComposition>;
9
- }) => ReactElement;
4
+ import { ReactElement, ReactNode } from 'react';
5
+ import { AnyFunction } from '@codeleap/types';
6
+ import { ButtonProps } from '../Button';
10
7
  export type EmptyPlaceholderProps = {
11
8
  itemName?: string;
12
- title?: ReactElement | string;
13
- description?: ReactElement | string;
9
+ title?: string;
10
+ description?: string;
14
11
  image?: ImageProps['source'];
15
12
  icon?: AppIcon;
16
13
  loading?: boolean;
17
14
  style?: StyledProp<EmptyPlaceholderComposition>;
18
- renderEmpty?: RenderEmpty;
15
+ LoadingComponent?: ReactElement;
16
+ children?: ReactNode;
17
+ onPress?: AnyFunction;
18
+ buttonText?: string;
19
+ };
20
+ export type EmptyPlaceholderInfoProps = Pick<EmptyPlaceholderProps, 'title' | 'description'>;
21
+ export type EmptyPlaceholderIllustrationProps = Pick<EmptyPlaceholderProps, 'image' | 'icon'>;
22
+ export type EmptyPlaceholderButtonProps = Pick<EmptyPlaceholderProps, 'onPress'> & Omit<ButtonProps, 'style' | 'debugName'>;
23
+ export type EmptyPlaceholderCtxValue = Omit<EmptyPlaceholderProps, 'style' | 'children'> & {
24
+ styles: StyleRecord<EmptyPlaceholderComposition>;
19
25
  };
20
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/mobile",
3
- "version": "5.8.1",
3
+ "version": "5.8.2",
4
4
  "main": "src/index.ts",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -9,28 +9,28 @@
9
9
  "directory": "packages/mobile"
10
10
  },
11
11
  "devDependencies": {
12
- "@codeleap/types": "5.8.1",
13
- "@codeleap/utils": "5.8.1",
14
- "@codeleap/hooks": "5.8.1",
15
- "@codeleap/form": "5.8.1",
16
- "@codeleap/query": "5.8.1",
17
- "@codeleap/logger": "5.8.1",
18
- "@codeleap/config": "5.8.1",
19
- "@codeleap/modals": "5.8.1"
12
+ "@codeleap/types": "5.8.2",
13
+ "@codeleap/utils": "5.8.2",
14
+ "@codeleap/hooks": "5.8.2",
15
+ "@codeleap/form": "5.8.2",
16
+ "@codeleap/query": "5.8.2",
17
+ "@codeleap/logger": "5.8.2",
18
+ "@codeleap/config": "5.8.2",
19
+ "@codeleap/modals": "5.8.2"
20
20
  },
21
21
  "scripts": {
22
22
  "build": "tsc --build",
23
23
  "lint": "eslint -c .eslintrc.js --fix \"./src/**/*.{ts,tsx,js,jsx}\""
24
24
  },
25
25
  "peerDependencies": {
26
- "@codeleap/types": "5.8.1",
27
- "@codeleap/utils": "5.8.1",
28
- "@codeleap/hooks": "5.8.1",
29
- "@codeleap/form": "5.8.1",
30
- "@codeleap/query": "5.8.1",
31
- "@codeleap/logger": "5.8.1",
32
- "@codeleap/styles": "5.8.1",
33
- "@codeleap/modals": "5.8.1",
26
+ "@codeleap/types": "5.8.2",
27
+ "@codeleap/utils": "5.8.2",
28
+ "@codeleap/hooks": "5.8.2",
29
+ "@codeleap/form": "5.8.2",
30
+ "@codeleap/query": "5.8.2",
31
+ "@codeleap/logger": "5.8.2",
32
+ "@codeleap/styles": "5.8.2",
33
+ "@codeleap/modals": "5.8.2",
34
34
  "@d11/react-native-fast-image": "8.9.2",
35
35
  "@react-native-firebase/messaging": "21.12.0",
36
36
  "@react-navigation/bottom-tabs": "7.3.10",
package/package.json.bak CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/mobile",
3
- "version": "5.8.1",
3
+ "version": "5.8.2",
4
4
  "main": "src/index.ts",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -0,0 +1,89 @@
1
+ import React from 'react'
2
+ import { AppIcon, useCompositionStyles } from '@codeleap/styles'
3
+ import { Icon } from '../Icon'
4
+ import { Text } from '../Text'
5
+ import { EmptyPlaceholderButtonProps, EmptyPlaceholderIllustrationProps, EmptyPlaceholderInfoProps } from './types'
6
+ import { Image } from '../Image'
7
+ import { useEmptyPlaceholderContext } from './context'
8
+ import { Button } from '../Button'
9
+ import { View } from '../View'
10
+ import { ActivityIndicator } from '../ActivityIndicator'
11
+ import { TypeGuards } from '@codeleap/types'
12
+
13
+ export const EmptyPlaceholderInfo = (props: EmptyPlaceholderInfoProps) => {
14
+ const { title, description, styles, itemName } = useEmptyPlaceholderContext(props)
15
+
16
+ const emptyText = title || (itemName && `No ${itemName} found.`)
17
+
18
+ return <>
19
+ {title || itemName ? <Text text={emptyText} style={styles.title} /> : null}
20
+ {description ? <Text text={description} style={styles.description} /> : null}
21
+ </>
22
+ }
23
+
24
+ export const EmptyPlaceholderIllustration = (props: EmptyPlaceholderIllustrationProps) => {
25
+ const { icon, image, styles } = useEmptyPlaceholderContext(props)
26
+
27
+ return <>
28
+ {icon ? <Icon name={icon as AppIcon} style={styles.icon} /> : null}
29
+ {image ? <Image source={image} style={styles.image} /> : null}
30
+ </>
31
+ }
32
+
33
+ export const EmptyPlaceholderButton = (props: EmptyPlaceholderButtonProps) => {
34
+ const { styles, buttonText, text, onPress, ...buttonProps } = useEmptyPlaceholderContext(props)
35
+
36
+ const buttonStyles = useCompositionStyles('button', styles)
37
+
38
+ const displayText = text || buttonText
39
+
40
+ if (!TypeGuards.isFunction(onPress)) return null
41
+
42
+ return (
43
+ <Button
44
+ {...buttonProps}
45
+ onPress={onPress}
46
+ debugName={`emptyPlaceholderButton:${buttonText}`}
47
+ style={buttonStyles}
48
+ text={displayText}
49
+ />
50
+ )
51
+ }
52
+
53
+ export const EmptyPlaceholderLoading = () => {
54
+ const { styles, loading, LoadingComponent } = useEmptyPlaceholderContext()
55
+
56
+ const activityIndicatorStyles = useCompositionStyles('loader', styles)
57
+
58
+ if (!loading) return null
59
+
60
+ if (React.isValidElement(LoadingComponent)) {
61
+ return <>{LoadingComponent}</>
62
+ }
63
+
64
+ return (
65
+ <View style={[styles.wrapper, styles['wrapper:loading']]} >
66
+ <ActivityIndicator style={activityIndicatorStyles} />
67
+ </View>
68
+ )
69
+ }
70
+
71
+ export const EmptyPlaceholderContent = ({ children }: React.PropsWithChildren) => {
72
+ const { loading, styles } = useEmptyPlaceholderContext()
73
+
74
+ if (loading) {
75
+ return <EmptyPlaceholderLoading />
76
+ }
77
+
78
+ if (children) {
79
+ return <View style={styles.wrapper}>{children}</View>
80
+ }
81
+
82
+ return (
83
+ <View style={styles.wrapper}>
84
+ <EmptyPlaceholderIllustration />
85
+ <EmptyPlaceholderInfo />
86
+ <EmptyPlaceholderButton />
87
+ </View>
88
+ )
89
+ }
@@ -0,0 +1,19 @@
1
+ import { createContext, useContext } from 'react'
2
+ import { EmptyPlaceholderCtxValue } from './types'
3
+
4
+ export const EmptyPlaceholderContext = createContext({} as EmptyPlaceholderCtxValue)
5
+
6
+ export const useEmptyPlaceholderContext = <T = EmptyPlaceholderCtxValue>(args: Partial<T> = {}) => {
7
+ const ctx = useContext(EmptyPlaceholderContext)
8
+
9
+ if (!ctx) {
10
+ throw new Error(
11
+ 'useEmptyPlaceholderContext must be used within an EmptyPlaceholder component.'
12
+ )
13
+ }
14
+
15
+ return {
16
+ ...ctx,
17
+ ...args,
18
+ }
19
+ }
@@ -1,77 +1,32 @@
1
1
  import React from 'react'
2
- import { Icon } from '../Icon'
3
- import { View } from '../View'
4
- import { Text } from '../Text'
5
- import { ActivityIndicator } from '../ActivityIndicator'
6
- import { Image } from '../Image'
7
2
  import { EmptyPlaceholderProps } from './types'
8
- import { AnyRecord, AppIcon, useNestedStylesByKey, IJSX, StyledComponentProps } from '@codeleap/styles'
3
+ import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
9
4
  import { MobileStyleRegistry } from '../../Registry'
10
5
  import { useStylesFor } from '../../hooks'
6
+ import { EmptyPlaceholderContext } from './context'
7
+ import { EmptyPlaceholderContent, EmptyPlaceholderButton, EmptyPlaceholderIllustration, EmptyPlaceholderInfo } from './Components'
11
8
 
12
9
  export * from './styles'
13
10
  export * from './types'
14
11
 
15
12
  export const EmptyPlaceholder = (props: EmptyPlaceholderProps) => {
16
13
  const {
17
- itemName,
18
- title,
19
- loading,
20
- description,
21
- image,
22
- icon = null,
23
- renderEmpty,
14
+ children,
24
15
  style,
16
+ ...contextValue
25
17
  } = {
26
18
  ...EmptyPlaceholder.defaultProps,
27
19
  ...props,
28
20
  }
29
21
 
30
- const emptyText = title || (itemName && `No ${itemName} found.`) || 'No items.'
31
-
32
22
  const styles = useStylesFor(EmptyPlaceholder.styleRegistryName, style)
33
23
 
34
- const activityIndicatorStyles = useNestedStylesByKey('loader', styles)
35
-
36
- if (loading) {
37
- return (
38
- <View style={[styles.wrapper, styles['wrapper:loading']]} >
39
- <ActivityIndicator style={activityIndicatorStyles} />
40
- </View>
41
- )
42
- }
43
-
44
- if (renderEmpty) {
45
- return (
46
- <View style={styles.wrapper}>
47
- {renderEmpty({
48
- emptyText,
49
- emptyIconName: icon as AppIcon,
50
- style: styles,
51
- })}
52
- </View>
53
- )
54
- }
55
-
56
- let _image = null
57
-
58
- if (icon) {
59
- _image = <Icon name={icon as AppIcon} style={styles.icon} />
60
- } else if (image) {
61
- _image = <Image source={image} style={styles.image} />
62
- }
63
-
64
24
  return (
65
- <View style={styles.wrapper}>
66
- {React.isValidElement(_image) ? (
67
- <View style={styles.imageWrapper}>
68
- {_image}
69
- </View>
70
- ) : null}
71
-
72
- {React.isValidElement(emptyText) ? emptyText : <Text text={emptyText} style={styles.title} />}
73
- {React.isValidElement(description) ? description : <Text text={description} style={styles.description} />}
74
- </View>
25
+ <EmptyPlaceholderContext.Provider value={{ ...contextValue, styles }}>
26
+ <EmptyPlaceholderContent>
27
+ {children}
28
+ </EmptyPlaceholderContent>
29
+ </EmptyPlaceholderContext.Provider>
75
30
  )
76
31
  }
77
32
 
@@ -79,8 +34,12 @@ EmptyPlaceholder.styleRegistryName = 'EmptyPlaceholder'
79
34
  EmptyPlaceholder.elements = ['wrapper', 'loader', 'title', 'description', 'image', 'icon']
80
35
  EmptyPlaceholder.rootElement = 'wrapper'
81
36
 
37
+ EmptyPlaceholder.Info = EmptyPlaceholderInfo
38
+ EmptyPlaceholder.Button = EmptyPlaceholderButton
39
+ EmptyPlaceholder.Illustration = EmptyPlaceholderIllustration
40
+
82
41
  EmptyPlaceholder.withVariantTypes = <S extends AnyRecord>(styles: S) => {
83
- return EmptyPlaceholder as (props: StyledComponentProps<EmptyPlaceholderProps, typeof styles>) => IJSX
42
+ return EmptyPlaceholder as ((props: StyledComponentProps<EmptyPlaceholderProps, typeof styles>) => IJSX) & Pick<typeof EmptyPlaceholder, 'Button' | 'Illustration' | 'Info'>
84
43
  }
85
44
 
86
45
  EmptyPlaceholder.defaultProps = {} as Partial<EmptyPlaceholderProps>
@@ -1,11 +1,12 @@
1
1
  import { ActivityIndicatorComposition } from '../ActivityIndicator'
2
+ import { ButtonComposition } from '../Button'
2
3
 
3
4
  export type EmptyPlaceholderComposition =
4
- | 'wrapper:loading'
5
- | `loader${Capitalize<ActivityIndicatorComposition>}`
6
5
  | 'wrapper'
6
+ | 'wrapper:loading'
7
7
  | 'title'
8
8
  | 'description'
9
9
  | 'image'
10
- | 'imageWrapper'
11
10
  | 'icon'
11
+ | `button${Capitalize<ButtonComposition>}`
12
+ | `loader${Capitalize<ActivityIndicatorComposition>}`
@@ -1,21 +1,30 @@
1
- import { AppIcon, StyledProp } from '@codeleap/styles'
2
- import { ReactElement } from 'react'
1
+ import { AppIcon, StyleRecord, StyledProp } from '@codeleap/styles'
3
2
  import { ImageProps } from '../Image'
4
3
  import { EmptyPlaceholderComposition } from './styles'
5
-
6
- type RenderEmpty = (props: {
7
- emptyText: string | ReactElement
8
- emptyIconName?: AppIcon
9
- style?: StyledProp<EmptyPlaceholderComposition>
10
- }) => ReactElement
4
+ import { ReactElement, ReactNode } from 'react'
5
+ import { AnyFunction } from '@codeleap/types'
6
+ import { ButtonProps } from '../Button'
11
7
 
12
8
  export type EmptyPlaceholderProps = {
13
9
  itemName?: string
14
- title?: ReactElement | string
15
- description?: ReactElement | string
10
+ title?: string
11
+ description?: string
16
12
  image?: ImageProps['source']
17
13
  icon?: AppIcon
18
14
  loading?: boolean
19
15
  style?: StyledProp<EmptyPlaceholderComposition>
20
- renderEmpty?: RenderEmpty
16
+ LoadingComponent?: ReactElement
17
+ children?: ReactNode
18
+ onPress?: AnyFunction
19
+ buttonText?: string
21
20
  }
21
+
22
+ export type EmptyPlaceholderInfoProps = Pick<EmptyPlaceholderProps, 'title' | 'description'>
23
+
24
+ export type EmptyPlaceholderIllustrationProps = Pick<EmptyPlaceholderProps, 'image' | 'icon'>
25
+
26
+ export type EmptyPlaceholderButtonProps = Pick<EmptyPlaceholderProps, 'onPress'> & Omit<ButtonProps, 'style' | 'debugName'>
27
+
28
+ export type EmptyPlaceholderCtxValue = Omit<EmptyPlaceholderProps, 'style' | 'children'> & {
29
+ styles: StyleRecord<EmptyPlaceholderComposition>
30
+ }