-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
三少
committed
Sep 16, 2021
1 parent
1726967
commit cebaf0a
Showing
6 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import Taro from '@tarojs/taro' | ||
import { useState, useEffect } from 'react' | ||
import { View } from '@tarojs/components' | ||
import * as utils from '../wxs/utils' | ||
import { SkeletonProps } from '../../../types/skeleton' | ||
|
||
export default function Index(props: SkeletonProps) { | ||
const [state, setState] = useState({ | ||
isArray: false, | ||
rowArray: [], | ||
}) | ||
const { isArray, rowArray } = state | ||
const { | ||
row = 0, | ||
animate = true, | ||
avatar, | ||
avatarShape = 'round', | ||
avatarSize = Taro.pxTransform(64), | ||
titleWidth = '40%', | ||
title, | ||
rowWidth = '100%', | ||
loading = true, | ||
children, | ||
style, | ||
className, | ||
...others | ||
} = props | ||
|
||
useEffect( | ||
function () { | ||
setState((pre: any) => { | ||
return { ...pre, rowArray: Array.from({ length: row }) } | ||
}) | ||
}, | ||
[row], | ||
) | ||
|
||
useEffect( | ||
function () { | ||
setState((pre: any) => { | ||
return { ...pre, isArray: (rowWidth as any) instanceof Array } | ||
}) | ||
}, | ||
[rowWidth], | ||
) | ||
|
||
return loading ? ( | ||
<View | ||
className={ | ||
'custom-class ' + | ||
utils.bem('skeleton', [ | ||
{ | ||
animate, | ||
}, | ||
]) + | ||
` ${className}` | ||
} | ||
style={style} | ||
{...others} | ||
> | ||
{avatar && ( | ||
<View | ||
className={ | ||
'avatar-class ' + utils.bem('skeleton__avatar', [avatarShape]) | ||
} | ||
style={'width:' + avatarSize + ';height:' + avatarSize} | ||
></View> | ||
)} | ||
<View className={utils.bem('skeleton__content')}> | ||
{title && ( | ||
<View | ||
className={'title-class ' + utils.bem('skeleton__title')} | ||
style={'width:' + titleWidth} | ||
></View> | ||
)} | ||
{rowArray.map((_item, index) => { | ||
return ( | ||
<View | ||
key={index} | ||
className={'row-class ' + utils.bem('skeleton__row')} | ||
style={'width:' + (isArray ? rowWidth[index] : rowWidth)} | ||
></View> | ||
) | ||
})} | ||
</View> | ||
</View> | ||
) : ( | ||
<View className={utils.bem('skeleton__content')}>{children}</View> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ComponentClass, ReactNode } from 'react' | ||
import { StandardProps } from '@tarojs/components' | ||
|
||
export interface SkeletonProps extends StandardProps { | ||
row?: number | ||
title?: boolean | ||
avatar?: boolean | ||
loading?: boolean | ||
animate?: boolean | ||
avatarSize?: string | ||
avatarShape?: 'square' | 'round' | ||
titleWidth?: string | string[] | ||
rowWidth?: string | ||
children?: ReactNode | ||
} | ||
|
||
declare const Skeleton: ComponentClass<SkeletonProps> | ||
|
||
export { Skeleton } |