Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create index copy.tsx #5785

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added img/qr copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/components/basic/View/index copy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { View } from './View';
72 changes: 72 additions & 0 deletions src/components/composites/Avatar/Avatar copy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React, { memo, forwardRef } from 'react';
import { Box, Image } from '../../primitives';
import { usePropsResolution } from '../../../hooks/useThemeProps';
import type { IAvatarProps } from './types';
import { useHasResponsiveProps } from '../../../hooks/useHasResponsiveProps';
import isNil from 'lodash.isnil';
import has from 'lodash.has';

const Avatar = ({ children, ...props }: IAvatarProps, ref: any) => {
const [error, setError] = React.useState(false);
const { _image, _badgeSize, source, ...resolvedProps } = usePropsResolution(
'Avatar',
props
);

let Badge = <></>;
const remainingChildren: JSX.Element[] = [];
// Pop Badge from children
React.Children.map(children, (child) => {
if (
typeof child?.type === 'object' &&
child?.type.displayName === 'AvatarBadge'
) {
Badge = React.cloneElement(child, {
size: child?.props?.size
? child?.props?.size
: _badgeSize
? _badgeSize[0]
: undefined,
});
} else {
remainingChildren.push(child);
}
});

//TODO: refactor for responsive prop
if (useHasResponsiveProps(props)) {
return null;
}

const getSource = () => {
if (source) {
if (has(source, 'uri') && !isNil(source.uri)) {
return source;
} else if (!has(source, 'uri')) {
return source;
}
}
return null;
};
const imageSource = getSource();

return (
<Box {...resolvedProps}>
{imageSource && !error ? (
<Image
source={source}
onError={() => {
setError(true);
}}
{..._image}
ref={ref}
/>
) : (
remainingChildren.length !== 0 && remainingChildren
)}
{Badge}
</Box>
);
};

export default memo(forwardRef(Avatar));