@codeleap/mobile 5.8.8 → 5.8.10
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/dist/components/Avatar/components/Badge.d.ts +3 -0
- package/dist/components/Avatar/components/Badge.js +13 -0
- package/dist/components/Avatar/components/Badge.js.map +1 -0
- package/dist/components/Avatar/components/Content.d.ts +2 -0
- package/dist/components/Avatar/components/Content.js +19 -0
- package/dist/components/Avatar/components/Content.js.map +1 -0
- package/dist/components/Avatar/components/Illustration.d.ts +3 -0
- package/dist/components/Avatar/components/Illustration.js +14 -0
- package/dist/components/Avatar/components/Illustration.js.map +1 -0
- package/dist/components/Avatar/components/OverlayIcon.d.ts +3 -0
- package/dist/components/Avatar/components/OverlayIcon.js +12 -0
- package/dist/components/Avatar/components/OverlayIcon.js.map +1 -0
- package/dist/components/Avatar/components/Text.d.ts +3 -0
- package/dist/components/Avatar/components/Text.js +18 -0
- package/dist/components/Avatar/components/Text.js.map +1 -0
- package/dist/components/Avatar/components/Wrapper.d.ts +4 -0
- package/dist/components/Avatar/components/Wrapper.js +28 -0
- package/dist/components/Avatar/components/Wrapper.js.map +1 -0
- package/dist/components/Avatar/context.d.ts +134 -0
- package/dist/components/Avatar/context.js +13 -0
- package/dist/components/Avatar/context.js.map +1 -0
- package/dist/components/Avatar/index.d.ts +6 -2
- package/dist/components/Avatar/index.js +18 -52
- package/dist/components/Avatar/index.js.map +1 -1
- package/dist/components/Avatar/styles.d.ts +1 -1
- package/dist/components/Avatar/types.d.ts +21 -16
- package/package.json +17 -17
- package/package.json.bak +1 -1
- package/src/components/Avatar/components/Badge.tsx +16 -0
- package/src/components/Avatar/components/Content.tsx +25 -0
- package/src/components/Avatar/components/Illustration.tsx +17 -0
- package/src/components/Avatar/components/OverlayIcon.tsx +22 -0
- package/src/components/Avatar/components/Text.tsx +24 -0
- package/src/components/Avatar/components/Wrapper.tsx +44 -0
- package/src/components/Avatar/context.ts +19 -0
- package/src/components/Avatar/index.tsx +23 -87
- package/src/components/Avatar/styles.ts +3 -7
- package/src/components/Avatar/types.ts +26 -18
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useAvatarContext } from '../context';
|
|
3
|
+
import { Badge } from '../../Badge';
|
|
4
|
+
import { useCompositionStyles } from '@codeleap/styles';
|
|
5
|
+
import { TypeGuards } from '@codeleap/types';
|
|
6
|
+
export const AvatarBadge = (props) => {
|
|
7
|
+
const { badge, styles, ...badgeProps } = useAvatarContext(props);
|
|
8
|
+
const compositionsStyles = useCompositionStyles('badge', styles);
|
|
9
|
+
if (TypeGuards.isNil(badge))
|
|
10
|
+
return null;
|
|
11
|
+
return <Badge badge={badge} {...badgeProps} style={compositionsStyles.badge}/>;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=Badge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Badge.js","sourceRoot":"","sources":["../../../../src/components/Avatar/components/Badge.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAuB,EAAE,EAAE;IACrD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAA;IAEhE,MAAM,kBAAkB,GAAG,oBAAoB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IAEhE,IAAI,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IAExC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAG,CAAA;AACjF,CAAC,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useAvatarContext } from '../context';
|
|
3
|
+
import { AvatarBadge } from './Badge';
|
|
4
|
+
import { AvatarIllustration } from './Illustration';
|
|
5
|
+
import { AvatarText } from './Text';
|
|
6
|
+
import { AvatarOverlayIcon } from './OverlayIcon';
|
|
7
|
+
import { AvatarWrapper } from './Wrapper';
|
|
8
|
+
export const AvatarContent = ({ children }) => {
|
|
9
|
+
const { icon, image } = useAvatarContext();
|
|
10
|
+
if (children) {
|
|
11
|
+
return (<AvatarWrapper>{children}</AvatarWrapper>);
|
|
12
|
+
}
|
|
13
|
+
return (<AvatarWrapper>
|
|
14
|
+
{(!!icon || !!image) ? <AvatarIllustration /> : <AvatarText />}
|
|
15
|
+
<AvatarBadge />
|
|
16
|
+
<AvatarOverlayIcon />
|
|
17
|
+
</AvatarWrapper>);
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=Content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Content.js","sourceRoot":"","sources":["../../../../src/components/Avatar/components/Content.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACrC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAEzC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAAE,QAAQ,EAA2B,EAAE,EAAE;IACrE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,gBAAgB,EAAE,CAAA;IAE1C,IAAI,QAAQ,EAAE;QACZ,OAAO,CACL,CAAC,aAAa,CAAC,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAC,CAC1C,CAAA;KACF;IAED,OAAO,CACL,CAAC,aAAa,CACZ;MAAA,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,AAAD,EAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,AAAD,EAAG,CAC9D;MAAA,CAAC,WAAW,CAAC,AAAD,EACZ;MAAA,CAAC,iBAAiB,CAAC,AAAD,EACpB;IAAA,EAAE,aAAa,CAAC,CACjB,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Icon } from '../../Icon';
|
|
3
|
+
import { Image } from '../../Image';
|
|
4
|
+
import { useAvatarContext } from '../context';
|
|
5
|
+
import { TypeGuards } from '@codeleap/types';
|
|
6
|
+
export const AvatarIllustration = (props) => {
|
|
7
|
+
const { icon, image, styles } = useAvatarContext(props);
|
|
8
|
+
const source = TypeGuards.isString(image) ? { uri: image } : image;
|
|
9
|
+
return <>
|
|
10
|
+
{icon ? <Icon name={icon} style={styles.icon}/> : null}
|
|
11
|
+
{image ? <Image source={source} style={styles.image}/> : null}
|
|
12
|
+
</>;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=Illustration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Illustration.js","sourceRoot":"","sources":["../../../../src/components/Avatar/components/Illustration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEjC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAA8B,EAAE,EAAE;IACnE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAA;IAEvD,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAA;IAElE,OAAO,EACL;IAAA,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAG,CAAC,CAAC,CAAC,IAAI,CACvD;IAAA,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAG,CAAC,CAAC,CAAC,IAAI,CAChE;EAAA,GAAG,CAAA;AACL,CAAC,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useAvatarContext } from '../context';
|
|
2
|
+
import { Touchable } from '../../Touchable';
|
|
3
|
+
import { Icon } from '../../Icon';
|
|
4
|
+
export const AvatarOverlayIcon = (props) => {
|
|
5
|
+
const { overlayIcon, styles, onPressOverlayIcon, ...touchableProps } = useAvatarContext(props);
|
|
6
|
+
if (!overlayIcon)
|
|
7
|
+
return null;
|
|
8
|
+
return (<Touchable debugName='avatar:overlayIcon' onPress={onPressOverlayIcon} noFeedback {...touchableProps} style={styles.overlayIconWrapper}>
|
|
9
|
+
<Icon name={overlayIcon} style={styles.overlayIcon}/>
|
|
10
|
+
</Touchable>);
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=OverlayIcon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OverlayIcon.js","sourceRoot":"","sources":["../../../../src/components/Avatar/components/OverlayIcon.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE7C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEjC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAA6B,EAAE,EAAE;IACjE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,kBAAkB,EAAE,GAAG,cAAc,EAAE,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAA;IAE9F,IAAI,CAAC,WAAW;QAAE,OAAO,IAAI,CAAA;IAE7B,OAAO,CACL,CAAC,SAAS,CACR,SAAS,CAAC,oBAAoB,CAC9B,OAAO,CAAC,CAAC,kBAAkB,CAAC,CAC5B,UAAU,CACV,IAAI,cAAc,CAAC,CACnB,KAAK,CAAC,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAEjC;MAAA,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,EACrD;IAAA,EAAE,SAAS,CAAC,CACb,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useAvatarContext } from '../context';
|
|
2
|
+
import { Text } from '../../Text';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { TypeGuards } from '@codeleap/types';
|
|
5
|
+
export const AvatarText = (props) => {
|
|
6
|
+
const { text, name, firstNameOnly, styles } = useAvatarContext(props);
|
|
7
|
+
const initials = useMemo(() => {
|
|
8
|
+
const [first = '', last = ''] = TypeGuards.isString(name) ? name.split(' ') : name ?? [];
|
|
9
|
+
const initials = [first[0]];
|
|
10
|
+
if (!firstNameOnly)
|
|
11
|
+
initials.push(last[0]);
|
|
12
|
+
return initials?.join('');
|
|
13
|
+
}, [name, firstNameOnly]);
|
|
14
|
+
if (!text && !initials)
|
|
15
|
+
return null;
|
|
16
|
+
return (<Text text={text || initials} style={styles.text}/>);
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=Text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Text.js","sourceRoot":"","sources":["../../../../src/components/Avatar/components/Text.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAsB,EAAE,EAAE;IACnD,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAA;IAErE,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE;QAC5B,MAAM,CAAC,KAAK,GAAG,EAAE,EAAE,IAAI,GAAG,EAAE,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAA;QACxF,MAAM,QAAQ,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;QAE3B,IAAI,CAAC,aAAa;YAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;QAE1C,OAAO,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,CAAA;IAC3B,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAA;IAEzB,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAA;IAEnC,OAAO,CACL,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAG,CACrD,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TypeGuards } from '@codeleap/types';
|
|
2
|
+
import { useAvatarContext } from '../context';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { matchInitialToColor, memoBy } from '@codeleap/utils';
|
|
5
|
+
import { Touchable } from '../../Touchable';
|
|
6
|
+
import { View } from '../../View';
|
|
7
|
+
const UnMemoizedAvatarWrapper = ({ children }) => {
|
|
8
|
+
const { styles, onPress, name, icon, image, ...wrapperProps } = useAvatarContext();
|
|
9
|
+
// @ts-expect-error ICSS
|
|
10
|
+
const bgColor = styles?.touchable?.backgroundColor;
|
|
11
|
+
const randomBgColor = useMemo(() => {
|
|
12
|
+
if (!!bgColor)
|
|
13
|
+
return bgColor;
|
|
14
|
+
const firstLetter = TypeGuards.isString(name) ? name[0] : name?.[0]?.[0];
|
|
15
|
+
return matchInitialToColor(firstLetter);
|
|
16
|
+
}, [bgColor, name]);
|
|
17
|
+
const isPressable = TypeGuards.isFunction(onPress);
|
|
18
|
+
if (isPressable) {
|
|
19
|
+
return (<Touchable debugName='avatar' {...wrapperProps} onPress={onPress} style={[styles.wrapper, { backgroundColor: randomBgColor }]}>
|
|
20
|
+
{children}
|
|
21
|
+
</Touchable>);
|
|
22
|
+
}
|
|
23
|
+
return (<View {...wrapperProps} style={[styles.wrapper, { backgroundColor: randomBgColor }]}>
|
|
24
|
+
{children}
|
|
25
|
+
</View>);
|
|
26
|
+
};
|
|
27
|
+
export const AvatarWrapper = memoBy(UnMemoizedAvatarWrapper, 'children');
|
|
28
|
+
//# sourceMappingURL=Wrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Wrapper.js","sourceRoot":"","sources":["../../../../src/components/Avatar/components/Wrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEjC,MAAM,uBAAuB,GAAG,CAAC,EAAE,QAAQ,EAA2B,EAAE,EAAE;IACxE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,YAAY,EAAE,GAAG,gBAAgB,EAAE,CAAA;IAElF,wBAAwB;IACxB,MAAM,OAAO,GAAG,MAAM,EAAE,SAAS,EAAE,eAAe,CAAA;IAElD,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,EAAE;QACjC,IAAI,CAAC,CAAC,OAAO;YAAE,OAAO,OAAO,CAAA;QAE7B,MAAM,WAAW,GAAG,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAExE,OAAO,mBAAmB,CAAC,WAAW,CAAC,CAAA;IACzC,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAA;IAEnB,MAAM,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;IAElD,IAAI,WAAW,EAAE;QACf,OAAO,CACL,CAAC,SAAS,CACR,SAAS,CAAC,QAAQ,CAClB,IAAI,YAAY,CAAC,CACjB,OAAO,CAAC,CAAC,OAAO,CAAC,CACjB,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,eAAe,EAAE,aAAa,EAAE,CAAC,CAAC,CAE5D;QAAA,CAAC,QAAQ,CACX;MAAA,EAAE,SAAS,CAAC,CACb,CAAA;KACF;IAED,OAAO,CACL,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,eAAe,EAAE,aAAa,EAAE,CAAC,CAAC,CAClF;MAAA,CAAC,QAAQ,CACX;IAAA,EAAE,IAAI,CAAC,CACR,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,uBAAuB,EAAE,UAAU,CAAC,CAAA"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { AvatarCtxValue } from './types';
|
|
3
|
+
export declare const AvatarContext: import("react").Context<AvatarCtxValue>;
|
|
4
|
+
export declare const useAvatarContext: <T = AvatarCtxValue>(providedProps?: Partial<T>) => {
|
|
5
|
+
name?: string | string[];
|
|
6
|
+
hitSlop?: number | import("react-native/types").Insets;
|
|
7
|
+
id?: string;
|
|
8
|
+
needsOffscreenAlphaCompositing?: boolean;
|
|
9
|
+
onLayout?: (event: import("react-native/types").LayoutChangeEvent) => void;
|
|
10
|
+
pointerEvents?: "none" | "auto" | "box-none" | "box-only";
|
|
11
|
+
removeClippedSubviews?: boolean;
|
|
12
|
+
testID?: string;
|
|
13
|
+
nativeID?: string;
|
|
14
|
+
experimental_layoutConformance?: "strict" | "classic";
|
|
15
|
+
collapsable?: boolean;
|
|
16
|
+
collapsableChildren?: boolean;
|
|
17
|
+
renderToHardwareTextureAndroid?: boolean;
|
|
18
|
+
focusable?: boolean;
|
|
19
|
+
tabIndex?: 0 | -1;
|
|
20
|
+
shouldRasterizeIOS?: boolean;
|
|
21
|
+
isTVSelectable?: boolean;
|
|
22
|
+
hasTVPreferredFocus?: boolean;
|
|
23
|
+
tvParallaxShiftDistanceX?: number;
|
|
24
|
+
tvParallaxShiftDistanceY?: number;
|
|
25
|
+
tvParallaxTiltAngle?: number;
|
|
26
|
+
tvParallaxMagnification?: number;
|
|
27
|
+
onStartShouldSetResponder?: (event: import("react-native/types").GestureResponderEvent) => boolean;
|
|
28
|
+
onMoveShouldSetResponder?: (event: import("react-native/types").GestureResponderEvent) => boolean;
|
|
29
|
+
onResponderEnd?: (event: import("react-native/types").GestureResponderEvent) => void;
|
|
30
|
+
onResponderGrant?: (event: import("react-native/types").GestureResponderEvent) => void;
|
|
31
|
+
onResponderReject?: (event: import("react-native/types").GestureResponderEvent) => void;
|
|
32
|
+
onResponderMove?: (event: import("react-native/types").GestureResponderEvent) => void;
|
|
33
|
+
onResponderRelease?: (event: import("react-native/types").GestureResponderEvent) => void;
|
|
34
|
+
onResponderStart?: (event: import("react-native/types").GestureResponderEvent) => void;
|
|
35
|
+
onResponderTerminationRequest?: (event: import("react-native/types").GestureResponderEvent) => boolean;
|
|
36
|
+
onResponderTerminate?: (event: import("react-native/types").GestureResponderEvent) => void;
|
|
37
|
+
onStartShouldSetResponderCapture?: (event: import("react-native/types").GestureResponderEvent) => boolean;
|
|
38
|
+
onMoveShouldSetResponderCapture?: (event: import("react-native/types").GestureResponderEvent) => boolean;
|
|
39
|
+
onTouchStart?: (event: import("react-native/types").GestureResponderEvent) => void;
|
|
40
|
+
onTouchMove?: (event: import("react-native/types").GestureResponderEvent) => void;
|
|
41
|
+
onTouchEnd?: (event: import("react-native/types").GestureResponderEvent) => void;
|
|
42
|
+
onTouchCancel?: (event: import("react-native/types").GestureResponderEvent) => void;
|
|
43
|
+
onTouchEndCapture?: (event: import("react-native/types").GestureResponderEvent) => void;
|
|
44
|
+
onPointerEnter?: (event: import("react-native/types").PointerEvent) => void;
|
|
45
|
+
onPointerEnterCapture?: (event: import("react-native/types").PointerEvent) => void;
|
|
46
|
+
onPointerLeave?: (event: import("react-native/types").PointerEvent) => void;
|
|
47
|
+
onPointerLeaveCapture?: (event: import("react-native/types").PointerEvent) => void;
|
|
48
|
+
onPointerMove?: (event: import("react-native/types").PointerEvent) => void;
|
|
49
|
+
onPointerMoveCapture?: (event: import("react-native/types").PointerEvent) => void;
|
|
50
|
+
onPointerCancel?: (event: import("react-native/types").PointerEvent) => void;
|
|
51
|
+
onPointerCancelCapture?: (event: import("react-native/types").PointerEvent) => void;
|
|
52
|
+
onPointerDown?: (event: import("react-native/types").PointerEvent) => void;
|
|
53
|
+
onPointerDownCapture?: (event: import("react-native/types").PointerEvent) => void;
|
|
54
|
+
onPointerUp?: (event: import("react-native/types").PointerEvent) => void;
|
|
55
|
+
onPointerUpCapture?: (event: import("react-native/types").PointerEvent) => void;
|
|
56
|
+
accessible?: boolean;
|
|
57
|
+
accessibilityActions?: readonly Readonly<{
|
|
58
|
+
name: string;
|
|
59
|
+
label?: string;
|
|
60
|
+
}>[];
|
|
61
|
+
accessibilityLabel?: string;
|
|
62
|
+
'aria-label'?: string;
|
|
63
|
+
accessibilityRole?: import("react-native/types").AccessibilityRole;
|
|
64
|
+
accessibilityState?: import("react-native/types").AccessibilityState;
|
|
65
|
+
'aria-busy'?: boolean;
|
|
66
|
+
'aria-checked'?: boolean | "mixed";
|
|
67
|
+
'aria-disabled'?: boolean;
|
|
68
|
+
'aria-expanded'?: boolean;
|
|
69
|
+
'aria-selected'?: boolean;
|
|
70
|
+
accessibilityHint?: string;
|
|
71
|
+
accessibilityValue?: import("react-native/types").AccessibilityValue;
|
|
72
|
+
'aria-valuemax'?: number;
|
|
73
|
+
'aria-valuemin'?: number;
|
|
74
|
+
'aria-valuenow'?: number;
|
|
75
|
+
'aria-valuetext'?: string;
|
|
76
|
+
onAccessibilityAction?: (event: import("react-native/types").AccessibilityActionEvent) => void;
|
|
77
|
+
importantForAccessibility?: "auto" | "yes" | "no" | "no-hide-descendants";
|
|
78
|
+
'aria-hidden'?: boolean;
|
|
79
|
+
'aria-modal'?: boolean;
|
|
80
|
+
role?: import("react-native/types").Role;
|
|
81
|
+
accessibilityLabelledBy?: string | string[];
|
|
82
|
+
'aria-labelledby'?: string;
|
|
83
|
+
accessibilityLiveRegion?: "none" | "polite" | "assertive";
|
|
84
|
+
'aria-live'?: "polite" | "assertive" | "off";
|
|
85
|
+
accessibilityElementsHidden?: boolean;
|
|
86
|
+
accessibilityViewIsModal?: boolean;
|
|
87
|
+
onAccessibilityEscape?: () => void;
|
|
88
|
+
onAccessibilityTap?: () => void;
|
|
89
|
+
onMagicTap?: () => void;
|
|
90
|
+
accessibilityIgnoresInvertColors?: boolean;
|
|
91
|
+
accessibilityLanguage?: string;
|
|
92
|
+
accessibilityShowsLargeContentViewer?: boolean;
|
|
93
|
+
accessibilityLargeContentTitle?: string;
|
|
94
|
+
debounce?: number;
|
|
95
|
+
onPress?: import("@codeleap/types").AnyFunction;
|
|
96
|
+
debugName?: string;
|
|
97
|
+
ref?: import("react").Ref<import("react-native/types").View>;
|
|
98
|
+
image?: string | number;
|
|
99
|
+
text?: string;
|
|
100
|
+
disabled?: boolean;
|
|
101
|
+
onBlur?: (event: import("react-native/types").NativeSyntheticEvent<import("react-native/types").TargetedEvent>) => void;
|
|
102
|
+
onPressIn?: (event: import("react-native/types").GestureResponderEvent) => void;
|
|
103
|
+
onPressOut?: (event: import("react-native/types").GestureResponderEvent) => void;
|
|
104
|
+
onFocus?: (event: import("react-native/types").NativeSyntheticEvent<import("react-native/types").TargetedEvent>) => void;
|
|
105
|
+
onLongPress?: (event: import("react-native/types").GestureResponderEvent) => void;
|
|
106
|
+
setPressed?: (param: boolean) => void;
|
|
107
|
+
badge?: number | boolean;
|
|
108
|
+
icon?: never;
|
|
109
|
+
delayLongPress?: number;
|
|
110
|
+
pressRetentionOffset?: number | import("react-native/types").Insets;
|
|
111
|
+
onHoverIn?: (event: import("react-native/types").MouseEvent) => void;
|
|
112
|
+
onHoverOut?: (event: import("react-native/types").MouseEvent) => void;
|
|
113
|
+
cancelable?: boolean;
|
|
114
|
+
delayHoverIn?: number;
|
|
115
|
+
delayHoverOut?: number;
|
|
116
|
+
android_disableSound?: boolean;
|
|
117
|
+
android_ripple?: import("react-native/types").PressableAndroidRippleConfig;
|
|
118
|
+
testOnly_pressed?: boolean;
|
|
119
|
+
unstable_pressDelay?: number;
|
|
120
|
+
component?: any;
|
|
121
|
+
activeOpacity?: number;
|
|
122
|
+
debugComponent?: string;
|
|
123
|
+
noFeedback?: boolean;
|
|
124
|
+
leadingDebounce?: boolean;
|
|
125
|
+
rippleDisabled?: boolean;
|
|
126
|
+
analyticsEnabled?: boolean;
|
|
127
|
+
analyticsName?: string;
|
|
128
|
+
analyticsData?: Record<string, any>;
|
|
129
|
+
dismissKeyboard?: boolean;
|
|
130
|
+
overlayIcon?: never;
|
|
131
|
+
firstNameOnly?: boolean;
|
|
132
|
+
onPressOverlayIcon?: import("@codeleap/types").AnyFunction;
|
|
133
|
+
styles: import("@codeleap/styles").StyleRecord<import("./styles").AvatarComposition>;
|
|
134
|
+
} & Partial<T>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
export const AvatarContext = createContext({});
|
|
3
|
+
export const useAvatarContext = (providedProps = {}) => {
|
|
4
|
+
const ctx = useContext(AvatarContext);
|
|
5
|
+
if (!ctx) {
|
|
6
|
+
throw new Error('[Avatar] useAvatarContext must be used within an Avatar component.');
|
|
7
|
+
}
|
|
8
|
+
return {
|
|
9
|
+
...ctx,
|
|
10
|
+
...providedProps,
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/components/Avatar/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAGjD,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC,EAAoB,CAAC,CAAA;AAEhE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAqB,gBAA4B,EAAE,EAAE,EAAE;IACrF,MAAM,GAAG,GAAG,UAAU,CAAC,aAAa,CAAC,CAAA;IAErC,IAAI,CAAC,GAAG,EAAE;QACR,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAA;KACF;IAED,OAAO;QACL,GAAG,GAAG;QACN,GAAG,aAAa;KACjB,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -8,6 +8,10 @@ export declare const Avatar: {
|
|
|
8
8
|
styleRegistryName: string;
|
|
9
9
|
elements: string[];
|
|
10
10
|
rootElement: string;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
Illustration: (props: import("./types").AvatarIllustrationProps) => JSX.Element;
|
|
12
|
+
Text: (props: import("./types").AvatarTextProps) => JSX.Element;
|
|
13
|
+
Badge: (props: import("./types").AvatarBadgeProps) => JSX.Element;
|
|
14
|
+
OverlayIcon: (props: import("./types").AvatarOverlayIconProps) => JSX.Element;
|
|
15
|
+
withVariantTypes<S extends AnyRecord>(styles: S): ((props: StyledComponentProps<AvatarProps, S>) => IJSX) & Pick<any, "Text" | "Badge" | "Illustration" | "OverlayIcon">;
|
|
16
|
+
defaultProps: Partial<AvatarProps>;
|
|
13
17
|
};
|
|
@@ -1,73 +1,39 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { TypeGuards } from '@codeleap/types';
|
|
3
|
-
import { useMemo } from '@codeleap/hooks';
|
|
4
|
-
import { matchInitialToColor } from '@codeleap/utils';
|
|
5
|
-
import { Image } from '../Image';
|
|
6
|
-
import { Touchable } from '../Touchable';
|
|
7
|
-
import { Text } from '../Text';
|
|
8
|
-
import { View } from '../View';
|
|
9
|
-
import { Icon } from '../Icon';
|
|
10
|
-
import { Badge } from '../Badge';
|
|
11
2
|
import { MobileStyleRegistry } from '../../Registry';
|
|
12
|
-
import {
|
|
3
|
+
import { AvatarContext } from './context';
|
|
4
|
+
import { AvatarContent } from './components/Content';
|
|
13
5
|
import { useStylesFor } from '../../hooks';
|
|
6
|
+
import { AvatarIllustration } from './components/Illustration';
|
|
7
|
+
import { AvatarText } from './components/Text';
|
|
8
|
+
import { AvatarBadge } from './components/Badge';
|
|
9
|
+
import { AvatarOverlayIcon } from './components/OverlayIcon';
|
|
14
10
|
export * from './styles';
|
|
15
11
|
export * from './types';
|
|
16
12
|
export const Avatar = (props) => {
|
|
17
|
-
const {
|
|
13
|
+
const { children, style, ...contextValue } = {
|
|
18
14
|
...Avatar.defaultProps,
|
|
19
15
|
...props,
|
|
20
16
|
};
|
|
21
17
|
const styles = useStylesFor(Avatar.styleRegistryName, style);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
initials.push(last[0]);
|
|
28
|
-
return {
|
|
29
|
-
initials: initials?.join(' '),
|
|
30
|
-
randomColor: matchInitialToColor(first[0]),
|
|
31
|
-
};
|
|
32
|
-
}, [name, firstNameOnly]);
|
|
33
|
-
const renderContent = () => {
|
|
34
|
-
if (hasImage)
|
|
35
|
-
return <Image source={image} {...imageProps} style={styles.image}/>;
|
|
36
|
-
if (icon)
|
|
37
|
-
return <Icon name={icon} style={styles.icon}/>;
|
|
38
|
-
return <Text text={text || initials} style={styles.initials}/>;
|
|
39
|
-
};
|
|
40
|
-
// @ts-expect-error icss type
|
|
41
|
-
const hasBackgroundColor = !!styles?.touchable?.backgroundColor;
|
|
42
|
-
const badgeStyles = useNestedStylesByKey('badge', styles);
|
|
43
|
-
return (<View {...viewProps} style={styles.wrapper}>
|
|
44
|
-
<Touchable debugName={'Avatar:' + debugName} onPress={() => onPress?.()} style={[
|
|
45
|
-
styles.touchable,
|
|
46
|
-
!hasBackgroundColor && { backgroundColor: randomColor },
|
|
47
|
-
]} noFeedback={noFeedback || !onPress}>
|
|
48
|
-
{renderContent()}
|
|
49
|
-
|
|
50
|
-
{!!description ? (<View style={styles.descriptionOverlay}>
|
|
51
|
-
<Text text={description} style={styles.description}/>
|
|
52
|
-
</View>) : null}
|
|
53
|
-
|
|
54
|
-
<Badge badge={badge} {...badgeProps} style={badgeStyles}/>
|
|
55
|
-
</Touchable>
|
|
56
|
-
|
|
57
|
-
{badgeIcon ? (<Touchable onPress={() => onPress?.()} noFeedback {...badgeIconTouchProps} debugName={`AvatarBadge:${debugName}`} style={styles.badgeIconWrapper}>
|
|
58
|
-
<Icon name={badgeIcon} style={styles.badgeIcon}/>
|
|
59
|
-
</Touchable>) : null}
|
|
60
|
-
</View>);
|
|
18
|
+
return (<AvatarContext.Provider value={{ ...contextValue, styles }}>
|
|
19
|
+
<AvatarContent>
|
|
20
|
+
{children}
|
|
21
|
+
</AvatarContent>
|
|
22
|
+
</AvatarContext.Provider>);
|
|
61
23
|
};
|
|
62
24
|
Avatar.styleRegistryName = 'Avatar';
|
|
63
|
-
Avatar.elements = ['wrapper', '
|
|
25
|
+
Avatar.elements = ['wrapper', 'text', 'image', 'icon', 'overlayIcon', 'badge'];
|
|
64
26
|
Avatar.rootElement = 'wrapper';
|
|
27
|
+
Avatar.Illustration = AvatarIllustration;
|
|
28
|
+
Avatar.Text = AvatarText;
|
|
29
|
+
Avatar.Badge = AvatarBadge;
|
|
30
|
+
Avatar.OverlayIcon = AvatarOverlayIcon;
|
|
65
31
|
Avatar.withVariantTypes = (styles) => {
|
|
66
32
|
return Avatar;
|
|
67
33
|
};
|
|
68
34
|
Avatar.defaultProps = {
|
|
69
35
|
badge: false,
|
|
70
|
-
firstNameOnly:
|
|
36
|
+
firstNameOnly: false,
|
|
71
37
|
};
|
|
72
38
|
MobileStyleRegistry.registerComponent(Avatar);
|
|
73
39
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/Avatar/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/Avatar/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAE5D,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AAEvB,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAkB,EAAE,EAAE;IAC3C,MAAM,EACJ,QAAQ,EACR,KAAK,EACL,GAAG,YAAY,EAChB,GAAG;QACF,GAAG,MAAM,CAAC,YAAY;QACtB,GAAG,KAAK;KACT,CAAA;IAED,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAA;IAE5D,OAAO,CACL,CAAC,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,YAAY,EAAE,MAAM,EAAE,CAAC,CACzD;MAAA,CAAC,aAAa,CACZ;QAAA,CAAC,QAAQ,CACX;MAAA,EAAE,aAAa,CACjB;IAAA,EAAE,aAAa,CAAC,QAAQ,CAAC,CAC1B,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,iBAAiB,GAAG,QAAQ,CAAA;AACnC,MAAM,CAAC,QAAQ,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,CAAC,CAAA;AAC9E,MAAM,CAAC,WAAW,GAAG,SAAS,CAAA;AAE9B,MAAM,CAAC,YAAY,GAAG,kBAAkB,CAAA;AACxC,MAAM,CAAC,IAAI,GAAG,UAAU,CAAA;AACxB,MAAM,CAAC,KAAK,GAAG,WAAW,CAAA;AAC1B,MAAM,CAAC,WAAW,GAAG,iBAAiB,CAAA;AAEtC,MAAM,CAAC,gBAAgB,GAAG,CAAsB,MAAS,EAAE,EAAE;IAC3D,OAAO,MAAsJ,CAAA;AAC/J,CAAC,CAAA;AAED,MAAM,CAAC,YAAY,GAAG;IACpB,KAAK,EAAE,KAAK;IACZ,aAAa,EAAE,KAAK;CACG,CAAA;AAEzB,mBAAmB,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { BadgeComposition } from '../Badge';
|
|
2
|
-
export type AvatarComposition = 'wrapper' | '
|
|
2
|
+
export type AvatarComposition = 'wrapper' | 'text' | 'image' | 'icon' | 'overlayIconWrapper' | 'overlayIcon' | `badge${Capitalize<BadgeComposition>}`;
|
|
@@ -1,22 +1,27 @@
|
|
|
1
|
-
import { StyledProp } from '@codeleap/styles';
|
|
2
|
-
import {
|
|
3
|
-
import { IconProps } from '../Icon';
|
|
4
|
-
import { ImageProps } from '../Image';
|
|
5
|
-
import { ViewProps } from '../View';
|
|
1
|
+
import { AppIcon, StyledProp, StyleRecord } from '@codeleap/styles';
|
|
2
|
+
import { BadgeProps } from '../Badge';
|
|
6
3
|
import { AvatarComposition } from './styles';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
7
5
|
import { TouchableProps } from '../Touchable';
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
import { AnyFunction } from '@codeleap/types';
|
|
7
|
+
import { ImageRequireSource } from 'react-native/types';
|
|
8
|
+
export type AvatarProps = Omit<TouchableProps, 'debugName' | 'style'> & {
|
|
9
|
+
text?: string;
|
|
10
|
+
image?: ImageRequireSource | string;
|
|
11
|
+
icon?: AppIcon;
|
|
12
|
+
badge?: BadgeProps['badge'];
|
|
10
13
|
name?: string | string[];
|
|
11
|
-
debugName: string;
|
|
12
14
|
firstNameOnly?: boolean;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
badgeIcon?: IconProps['name'];
|
|
17
|
-
badgeIconTouchProps?: Partial<TouchableProps>;
|
|
15
|
+
overlayIcon?: AppIcon;
|
|
16
|
+
onPressOverlayIcon?: AnyFunction;
|
|
17
|
+
debugName?: string;
|
|
18
18
|
style?: StyledProp<AvatarComposition>;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
children?: ReactNode;
|
|
20
|
+
};
|
|
21
|
+
export type AvatarTextProps = Pick<AvatarProps, 'text' | 'firstNameOnly' | 'name'>;
|
|
22
|
+
export type AvatarIllustrationProps = Pick<AvatarProps, 'image' | 'icon'>;
|
|
23
|
+
export type AvatarBadgeProps = Pick<AvatarProps, 'badge'> & Omit<BadgeProps, 'badge' | 'style'>;
|
|
24
|
+
export type AvatarOverlayIconProps = Pick<AvatarProps, 'overlayIcon'> & Omit<TouchableProps, 'onPress' | 'style' | 'debugName'>;
|
|
25
|
+
export type AvatarCtxValue = Omit<AvatarProps, 'style' | 'children'> & {
|
|
26
|
+
styles: StyleRecord<AvatarComposition>;
|
|
22
27
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/mobile",
|
|
3
|
-
"version": "5.8.
|
|
3
|
+
"version": "5.8.10",
|
|
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.
|
|
13
|
-
"@codeleap/utils": "5.8.
|
|
14
|
-
"@codeleap/hooks": "5.8.
|
|
15
|
-
"@codeleap/form": "5.8.
|
|
16
|
-
"@codeleap/query": "5.8.
|
|
17
|
-
"@codeleap/logger": "5.8.
|
|
18
|
-
"@codeleap/config": "5.8.
|
|
19
|
-
"@codeleap/modals": "5.8.
|
|
12
|
+
"@codeleap/types": "5.8.10",
|
|
13
|
+
"@codeleap/utils": "5.8.10",
|
|
14
|
+
"@codeleap/hooks": "5.8.10",
|
|
15
|
+
"@codeleap/form": "5.8.10",
|
|
16
|
+
"@codeleap/query": "5.8.10",
|
|
17
|
+
"@codeleap/logger": "5.8.10",
|
|
18
|
+
"@codeleap/config": "5.8.10",
|
|
19
|
+
"@codeleap/modals": "5.8.10"
|
|
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.
|
|
27
|
-
"@codeleap/utils": "5.8.
|
|
28
|
-
"@codeleap/hooks": "5.8.
|
|
29
|
-
"@codeleap/form": "5.8.
|
|
30
|
-
"@codeleap/query": "5.8.
|
|
31
|
-
"@codeleap/logger": "5.8.
|
|
32
|
-
"@codeleap/styles": "5.8.
|
|
33
|
-
"@codeleap/modals": "5.8.
|
|
26
|
+
"@codeleap/types": "5.8.10",
|
|
27
|
+
"@codeleap/utils": "5.8.10",
|
|
28
|
+
"@codeleap/hooks": "5.8.10",
|
|
29
|
+
"@codeleap/form": "5.8.10",
|
|
30
|
+
"@codeleap/query": "5.8.10",
|
|
31
|
+
"@codeleap/logger": "5.8.10",
|
|
32
|
+
"@codeleap/styles": "5.8.10",
|
|
33
|
+
"@codeleap/modals": "5.8.10",
|
|
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
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { useAvatarContext } from '../context'
|
|
3
|
+
import { Badge } from '../../Badge'
|
|
4
|
+
import { useCompositionStyles } from '@codeleap/styles'
|
|
5
|
+
import { AvatarBadgeProps } from '../types'
|
|
6
|
+
import { TypeGuards } from '@codeleap/types'
|
|
7
|
+
|
|
8
|
+
export const AvatarBadge = (props: AvatarBadgeProps) => {
|
|
9
|
+
const { badge, styles, ...badgeProps } = useAvatarContext(props)
|
|
10
|
+
|
|
11
|
+
const compositionsStyles = useCompositionStyles('badge', styles)
|
|
12
|
+
|
|
13
|
+
if (TypeGuards.isNil(badge)) return null
|
|
14
|
+
|
|
15
|
+
return <Badge badge={badge} {...badgeProps} style={compositionsStyles.badge} />
|
|
16
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { useAvatarContext } from '../context'
|
|
3
|
+
import { AvatarBadge } from './Badge'
|
|
4
|
+
import { AvatarIllustration } from './Illustration'
|
|
5
|
+
import { AvatarText } from './Text'
|
|
6
|
+
import { AvatarOverlayIcon } from './OverlayIcon'
|
|
7
|
+
import { AvatarWrapper } from './Wrapper'
|
|
8
|
+
|
|
9
|
+
export const AvatarContent = ({ children }: React.PropsWithChildren) => {
|
|
10
|
+
const { icon, image } = useAvatarContext()
|
|
11
|
+
|
|
12
|
+
if (children) {
|
|
13
|
+
return (
|
|
14
|
+
<AvatarWrapper>{children}</AvatarWrapper>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<AvatarWrapper>
|
|
20
|
+
{(!!icon || !!image) ? <AvatarIllustration /> : <AvatarText />}
|
|
21
|
+
<AvatarBadge />
|
|
22
|
+
<AvatarOverlayIcon />
|
|
23
|
+
</AvatarWrapper>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { Icon } from '../../Icon'
|
|
3
|
+
import { AvatarIllustrationProps } from '../types'
|
|
4
|
+
import { Image } from '../../Image'
|
|
5
|
+
import { useAvatarContext } from '../context'
|
|
6
|
+
import { TypeGuards } from '@codeleap/types'
|
|
7
|
+
|
|
8
|
+
export const AvatarIllustration = (props: AvatarIllustrationProps) => {
|
|
9
|
+
const { icon, image, styles } = useAvatarContext(props)
|
|
10
|
+
|
|
11
|
+
const source = TypeGuards.isString(image) ? { uri: image } : image
|
|
12
|
+
|
|
13
|
+
return <>
|
|
14
|
+
{icon ? <Icon name={icon} style={styles.icon} /> : null}
|
|
15
|
+
{image ? <Image source={source} style={styles.image} /> : null}
|
|
16
|
+
</>
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useAvatarContext } from '../context'
|
|
2
|
+
import { AvatarOverlayIconProps } from '../types'
|
|
3
|
+
import { Touchable } from '../../Touchable'
|
|
4
|
+
import { Icon } from '../../Icon'
|
|
5
|
+
|
|
6
|
+
export const AvatarOverlayIcon = (props: AvatarOverlayIconProps) => {
|
|
7
|
+
const { overlayIcon, styles, onPressOverlayIcon, ...touchableProps } = useAvatarContext(props)
|
|
8
|
+
|
|
9
|
+
if (!overlayIcon) return null
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<Touchable
|
|
13
|
+
debugName='avatar:overlayIcon'
|
|
14
|
+
onPress={onPressOverlayIcon}
|
|
15
|
+
noFeedback
|
|
16
|
+
{...touchableProps}
|
|
17
|
+
style={styles.overlayIconWrapper}
|
|
18
|
+
>
|
|
19
|
+
<Icon name={overlayIcon} style={styles.overlayIcon} />
|
|
20
|
+
</Touchable>
|
|
21
|
+
)
|
|
22
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useAvatarContext } from '../context'
|
|
2
|
+
import { AvatarTextProps } from '../types'
|
|
3
|
+
import { Text } from '../../Text'
|
|
4
|
+
import { useMemo } from 'react'
|
|
5
|
+
import { TypeGuards } from '@codeleap/types'
|
|
6
|
+
|
|
7
|
+
export const AvatarText = (props: AvatarTextProps) => {
|
|
8
|
+
const { text, name, firstNameOnly, styles } = useAvatarContext(props)
|
|
9
|
+
|
|
10
|
+
const initials = useMemo(() => {
|
|
11
|
+
const [first = '', last = ''] = TypeGuards.isString(name) ? name.split(' ') : name ?? []
|
|
12
|
+
const initials = [first[0]]
|
|
13
|
+
|
|
14
|
+
if (!firstNameOnly) initials.push(last[0])
|
|
15
|
+
|
|
16
|
+
return initials?.join('')
|
|
17
|
+
}, [name, firstNameOnly])
|
|
18
|
+
|
|
19
|
+
if (!text && !initials) return null
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<Text text={text || initials} style={styles.text} />
|
|
23
|
+
)
|
|
24
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { TypeGuards } from '@codeleap/types'
|
|
2
|
+
import { useAvatarContext } from '../context'
|
|
3
|
+
import { useMemo } from 'react'
|
|
4
|
+
import { matchInitialToColor, memoBy } from '@codeleap/utils'
|
|
5
|
+
import { Touchable } from '../../Touchable'
|
|
6
|
+
import { View } from '../../View'
|
|
7
|
+
|
|
8
|
+
const UnMemoizedAvatarWrapper = ({ children }: React.PropsWithChildren) => {
|
|
9
|
+
const { styles, onPress, name, icon, image, ...wrapperProps } = useAvatarContext()
|
|
10
|
+
|
|
11
|
+
// @ts-expect-error ICSS
|
|
12
|
+
const bgColor = styles?.touchable?.backgroundColor
|
|
13
|
+
|
|
14
|
+
const randomBgColor = useMemo(() => {
|
|
15
|
+
if (!!bgColor) return bgColor
|
|
16
|
+
|
|
17
|
+
const firstLetter = TypeGuards.isString(name) ? name[0] : name?.[0]?.[0]
|
|
18
|
+
|
|
19
|
+
return matchInitialToColor(firstLetter)
|
|
20
|
+
}, [bgColor, name])
|
|
21
|
+
|
|
22
|
+
const isPressable = TypeGuards.isFunction(onPress)
|
|
23
|
+
|
|
24
|
+
if (isPressable) {
|
|
25
|
+
return (
|
|
26
|
+
<Touchable
|
|
27
|
+
debugName='avatar'
|
|
28
|
+
{...wrapperProps}
|
|
29
|
+
onPress={onPress}
|
|
30
|
+
style={[styles.wrapper, { backgroundColor: randomBgColor }]}
|
|
31
|
+
>
|
|
32
|
+
{children}
|
|
33
|
+
</Touchable>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<View {...wrapperProps} style={[styles.wrapper, { backgroundColor: randomBgColor }]}>
|
|
39
|
+
{children}
|
|
40
|
+
</View>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const AvatarWrapper = memoBy(UnMemoizedAvatarWrapper, 'children')
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react'
|
|
2
|
+
import { AvatarCtxValue } from './types'
|
|
3
|
+
|
|
4
|
+
export const AvatarContext = createContext({} as AvatarCtxValue)
|
|
5
|
+
|
|
6
|
+
export const useAvatarContext = <T = AvatarCtxValue>(providedProps: Partial<T> = {}) => {
|
|
7
|
+
const ctx = useContext(AvatarContext)
|
|
8
|
+
|
|
9
|
+
if (!ctx) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
'[Avatar] useAvatarContext must be used within an Avatar component.',
|
|
12
|
+
)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
...ctx,
|
|
17
|
+
...providedProps,
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,39 +1,23 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import { TypeGuards } from '@codeleap/types'
|
|
3
|
-
import { useMemo } from '@codeleap/hooks'
|
|
4
|
-
import { matchInitialToColor } from '@codeleap/utils'
|
|
5
|
-
import { Image } from '../Image'
|
|
6
|
-
import { Touchable } from '../Touchable'
|
|
7
|
-
import { Text } from '../Text'
|
|
8
|
-
import { View, ViewProps } from '../View'
|
|
9
|
-
import { Icon } from '../Icon'
|
|
10
|
-
import { Badge } from '../Badge'
|
|
11
2
|
import { AvatarProps } from './types'
|
|
12
3
|
import { MobileStyleRegistry } from '../../Registry'
|
|
13
|
-
import { AnyRecord,
|
|
4
|
+
import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
|
|
5
|
+
import { AvatarContext } from './context'
|
|
6
|
+
import { AvatarContent } from './components/Content'
|
|
14
7
|
import { useStylesFor } from '../../hooks'
|
|
8
|
+
import { AvatarIllustration } from './components/Illustration'
|
|
9
|
+
import { AvatarText } from './components/Text'
|
|
10
|
+
import { AvatarBadge } from './components/Badge'
|
|
11
|
+
import { AvatarOverlayIcon } from './components/OverlayIcon'
|
|
15
12
|
|
|
16
13
|
export * from './styles'
|
|
17
14
|
export * from './types'
|
|
18
15
|
|
|
19
16
|
export const Avatar = (props: AvatarProps) => {
|
|
20
17
|
const {
|
|
21
|
-
|
|
22
|
-
name = '',
|
|
23
|
-
firstNameOnly,
|
|
24
|
-
image,
|
|
25
|
-
icon,
|
|
26
|
-
badgeIcon,
|
|
27
|
-
text,
|
|
28
|
-
description,
|
|
29
|
-
onPress,
|
|
30
|
-
noFeedback,
|
|
31
|
-
badge,
|
|
32
|
-
badgeProps = {},
|
|
33
|
-
imageProps,
|
|
34
|
-
badgeIconTouchProps,
|
|
18
|
+
children,
|
|
35
19
|
style,
|
|
36
|
-
...
|
|
20
|
+
...contextValue
|
|
37
21
|
} = {
|
|
38
22
|
...Avatar.defaultProps,
|
|
39
23
|
...props,
|
|
@@ -41,79 +25,31 @@ export const Avatar = (props: AvatarProps) => {
|
|
|
41
25
|
|
|
42
26
|
const styles = useStylesFor(Avatar.styleRegistryName, style)
|
|
43
27
|
|
|
44
|
-
const hasImage = !!image
|
|
45
|
-
|
|
46
|
-
const { initials, randomColor } = useMemo(() => {
|
|
47
|
-
const [first = '', last = ''] = TypeGuards.isString(name) ? name.split(' ') : name
|
|
48
|
-
const initials = [first[0]]
|
|
49
|
-
|
|
50
|
-
if (!firstNameOnly) initials.push(last[0])
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
initials: initials?.join(' '),
|
|
54
|
-
randomColor: matchInitialToColor(first[0]),
|
|
55
|
-
}
|
|
56
|
-
}, [name, firstNameOnly])
|
|
57
|
-
|
|
58
|
-
const renderContent = () => {
|
|
59
|
-
if (hasImage) return <Image source={image} {...imageProps} style={styles.image} />
|
|
60
|
-
if (icon) return <Icon name={icon} style={styles.icon} />
|
|
61
|
-
return <Text text={text || initials} style={styles.initials} />
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// @ts-expect-error icss type
|
|
65
|
-
const hasBackgroundColor = !!styles?.touchable?.backgroundColor
|
|
66
|
-
|
|
67
|
-
const badgeStyles = useNestedStylesByKey('badge', styles)
|
|
68
|
-
|
|
69
28
|
return (
|
|
70
|
-
<
|
|
71
|
-
<
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
styles.touchable,
|
|
76
|
-
!hasBackgroundColor && { backgroundColor: randomColor },
|
|
77
|
-
]}
|
|
78
|
-
noFeedback={noFeedback || !onPress}
|
|
79
|
-
>
|
|
80
|
-
{renderContent()}
|
|
81
|
-
|
|
82
|
-
{!!description ? (
|
|
83
|
-
<View style={styles.descriptionOverlay}>
|
|
84
|
-
<Text text={description} style={styles.description} />
|
|
85
|
-
</View>
|
|
86
|
-
) : null}
|
|
87
|
-
|
|
88
|
-
<Badge badge={badge} {...badgeProps} style={badgeStyles} />
|
|
89
|
-
</Touchable>
|
|
90
|
-
|
|
91
|
-
{badgeIcon ? (
|
|
92
|
-
<Touchable
|
|
93
|
-
onPress={() => onPress?.()}
|
|
94
|
-
noFeedback
|
|
95
|
-
{...badgeIconTouchProps}
|
|
96
|
-
debugName={`AvatarBadge:${debugName}`}
|
|
97
|
-
style={styles.badgeIconWrapper}
|
|
98
|
-
>
|
|
99
|
-
<Icon name={badgeIcon} style={styles.badgeIcon} />
|
|
100
|
-
</Touchable>
|
|
101
|
-
) : null}
|
|
102
|
-
</View>
|
|
29
|
+
<AvatarContext.Provider value={{ ...contextValue, styles }}>
|
|
30
|
+
<AvatarContent>
|
|
31
|
+
{children}
|
|
32
|
+
</AvatarContent>
|
|
33
|
+
</AvatarContext.Provider>
|
|
103
34
|
)
|
|
104
35
|
}
|
|
105
36
|
|
|
106
37
|
Avatar.styleRegistryName = 'Avatar'
|
|
107
|
-
Avatar.elements = ['wrapper', '
|
|
38
|
+
Avatar.elements = ['wrapper', 'text', 'image', 'icon', 'overlayIcon', 'badge']
|
|
108
39
|
Avatar.rootElement = 'wrapper'
|
|
109
40
|
|
|
41
|
+
Avatar.Illustration = AvatarIllustration
|
|
42
|
+
Avatar.Text = AvatarText
|
|
43
|
+
Avatar.Badge = AvatarBadge
|
|
44
|
+
Avatar.OverlayIcon = AvatarOverlayIcon
|
|
45
|
+
|
|
110
46
|
Avatar.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
111
|
-
return Avatar as (props: StyledComponentProps<AvatarProps, typeof styles>) => IJSX
|
|
47
|
+
return Avatar as ((props: StyledComponentProps<AvatarProps, typeof styles>) => IJSX) & Pick<typeof Avatar, 'Text' | 'Illustration' | 'Badge' | 'OverlayIcon'>
|
|
112
48
|
}
|
|
113
49
|
|
|
114
50
|
Avatar.defaultProps = {
|
|
115
51
|
badge: false,
|
|
116
|
-
firstNameOnly:
|
|
117
|
-
} as AvatarProps
|
|
52
|
+
firstNameOnly: false,
|
|
53
|
+
} as Partial<AvatarProps>
|
|
118
54
|
|
|
119
55
|
MobileStyleRegistry.registerComponent(Avatar)
|
|
@@ -2,13 +2,9 @@ import { BadgeComposition } from '../Badge'
|
|
|
2
2
|
|
|
3
3
|
export type AvatarComposition =
|
|
4
4
|
| 'wrapper'
|
|
5
|
-
| '
|
|
6
|
-
| 'initials'
|
|
5
|
+
| 'text'
|
|
7
6
|
| 'image'
|
|
8
7
|
| 'icon'
|
|
9
|
-
| '
|
|
10
|
-
| '
|
|
11
|
-
| 'descriptionOverlay'
|
|
12
|
-
| 'badgeIconWrapper'
|
|
13
|
-
| 'badgeIcon'
|
|
8
|
+
| 'overlayIconWrapper'
|
|
9
|
+
| 'overlayIcon'
|
|
14
10
|
| `badge${Capitalize<BadgeComposition>}`
|
|
@@ -1,26 +1,34 @@
|
|
|
1
|
-
import { StyledProp } from '@codeleap/styles'
|
|
2
|
-
import {
|
|
3
|
-
import { IconProps } from '../Icon'
|
|
4
|
-
import { ImageProps } from '../Image'
|
|
5
|
-
import { ViewProps } from '../View'
|
|
1
|
+
import { AppIcon, StyledProp, StyleRecord } from '@codeleap/styles'
|
|
2
|
+
import { BadgeProps } from '../Badge'
|
|
6
3
|
import { AvatarComposition } from './styles'
|
|
4
|
+
import { ReactNode } from 'react'
|
|
7
5
|
import { TouchableProps } from '../Touchable'
|
|
6
|
+
import { AnyFunction } from '@codeleap/types'
|
|
7
|
+
import { ImageRequireSource } from 'react-native/types'
|
|
8
8
|
|
|
9
|
-
export type AvatarProps =
|
|
10
|
-
Omit<ViewProps, 'style'> &
|
|
11
|
-
BadgeComponentProps &
|
|
9
|
+
export type AvatarProps = Omit<TouchableProps, 'debugName' | 'style'> &
|
|
12
10
|
{
|
|
13
|
-
|
|
11
|
+
text?: string
|
|
12
|
+
image?: ImageRequireSource | string
|
|
13
|
+
icon?: AppIcon
|
|
14
|
+
badge?: BadgeProps['badge']
|
|
14
15
|
name?: string | string[]
|
|
15
|
-
debugName: string
|
|
16
16
|
firstNameOnly?: boolean
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
badgeIcon?: IconProps['name']
|
|
21
|
-
badgeIconTouchProps?: Partial<TouchableProps>
|
|
17
|
+
overlayIcon?: AppIcon
|
|
18
|
+
onPressOverlayIcon?: AnyFunction
|
|
19
|
+
debugName?: string
|
|
22
20
|
style?: StyledProp<AvatarComposition>
|
|
23
|
-
|
|
24
|
-
noFeedback?: boolean
|
|
25
|
-
imageProps?: Partial<ImageProps>
|
|
21
|
+
children?: ReactNode
|
|
26
22
|
}
|
|
23
|
+
|
|
24
|
+
export type AvatarTextProps = Pick<AvatarProps, 'text' | 'firstNameOnly' | 'name'>
|
|
25
|
+
|
|
26
|
+
export type AvatarIllustrationProps = Pick<AvatarProps, 'image' | 'icon'>
|
|
27
|
+
|
|
28
|
+
export type AvatarBadgeProps = Pick<AvatarProps, 'badge'> & Omit<BadgeProps, 'badge' | 'style'>
|
|
29
|
+
|
|
30
|
+
export type AvatarOverlayIconProps = Pick<AvatarProps, 'overlayIcon'> & Omit<TouchableProps, 'onPress' | 'style' | 'debugName'>
|
|
31
|
+
|
|
32
|
+
export type AvatarCtxValue = Omit<AvatarProps, 'style' | 'children'> & {
|
|
33
|
+
styles: StyleRecord<AvatarComposition>
|
|
34
|
+
}
|