Skip to content

Commit

Permalink
fix: flex container
Browse files Browse the repository at this point in the history
  • Loading branch information
3lang3 committed Jul 29, 2021
1 parent 4a126cf commit 874cccc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-vant",
"version": "0.0.25",
"version": "0.0.26",
"description": "React Mobile UI Components base on Vant UI",
"repository": "https://github.com/3lang3/react-vant.git",
"main": "lib/index.js",
Expand Down
4 changes: 2 additions & 2 deletions src/flex/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
&-end {
justify-content: flex-end;
}
&-space-between {
&-between {
justify-content: space-between;
}
&-space-around {
&-around {
justify-content: space-around;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/image/PropsType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface ImageProps extends BaseTypeProps {
alt?: string;
fit?: ImageFit;
round?: boolean;
block?: boolean;
width?: number | string;
height?: number | string;
radius?: number | string;
Expand Down
17 changes: 9 additions & 8 deletions src/image/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ const Image: React.FC<ImageProps> = (props) => {
loadingIcon = 'photo',
showError = true,
showLoading = true,
block = true,
} = props;
const [status, setStatus] = useState({ loading: true, error: false });
const mountedRef = useRef(false)
const mountedRef = useRef(false);

const style = useMemo(() => {
// eslint-disable-next-line @typescript-eslint/no-shadow
Expand All @@ -39,24 +40,24 @@ const Image: React.FC<ImageProps> = (props) => {

useEffect(() => {
if (!mountedRef.current) {
mountedRef.current = true
return
mountedRef.current = true;
return;
}
setStatus({ error: false, loading: false });
}, [props.src]);

const onLoad = (e) => {
setStatus((v) => ({ ...v, loading: false }));
props.onLoad?.(e)
props.onLoad?.(e);
};

const onError = (e) => {
setStatus({ error: true, loading: false });
props.onLoad?.(e)
props.onLoad?.(e);
};

const renderLoadingIcon = () => {
if (typeof loadingIcon !== 'string') return loadingIcon
if (typeof loadingIcon !== 'string') return loadingIcon;
return (
<Icon
size={props.iconSize}
Expand All @@ -68,7 +69,7 @@ const Image: React.FC<ImageProps> = (props) => {
};

const renderErrorIcon = () => {
if (typeof errorIcon !== 'string') return errorIcon
if (typeof errorIcon !== 'string') return errorIcon;
return (
<Icon
size={props.iconSize}
Expand Down Expand Up @@ -107,7 +108,7 @@ const Image: React.FC<ImageProps> = (props) => {
};

return (
<div className={classnames(bem({ round: props.round }))} style={style}>
<div className={classnames(bem({ block, round: props.round }))} style={style}>
{renderImage()}
{renderPlaceholder()}
{props.children}
Expand Down
6 changes: 6 additions & 0 deletions src/image/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
position: relative;
display: inline-block;

&--block {
display: block;
width: 100%;
height: 100%;
}

&--round {
overflow: hidden;
border-radius: 50%;
Expand Down

0 comments on commit 874cccc

Please sign in to comment.