-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(select): add useSelectWithLoading preset (#693)
- Loading branch information
Showing
7 changed files
with
101 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './Component'; | ||
export * from './components'; | ||
export * from './presets'; | ||
export * from './typings'; | ||
export * from './utils'; |
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 @@ | ||
export * from './useSelectWithLoading/hook'; |
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,38 @@ | ||
import React, { useCallback } from 'react'; | ||
import { Skeleton } from '@alfalab/core-components-skeleton'; | ||
import { Option } from '../../components/option'; | ||
import { BaseSelectProps, OptionShape } from '../../typings'; | ||
|
||
import styles from './index.module.css'; | ||
|
||
type useSelectWithLoadingProps = { | ||
loading?: boolean; | ||
visibleOptions?: BaseSelectProps['visibleOptions']; | ||
}; | ||
|
||
export function useSelectWithLoading({ | ||
loading = false, | ||
visibleOptions = 6, | ||
}: useSelectWithLoadingProps) { | ||
const renderOption = useCallback( | ||
props => ( | ||
<Option {...props} Checkmark={null} highlighted={loading ? false : props.highlighted} /> | ||
), | ||
[loading], | ||
); | ||
|
||
const options: OptionShape[] = Array(visibleOptions) | ||
.fill(0) | ||
.map((_, key) => ({ | ||
key: `loading-${key}`, | ||
disabled: true, | ||
content: <Skeleton className={styles.skeleton} visible={true} />, | ||
})); | ||
|
||
if (!loading) return null; | ||
|
||
return { | ||
Option: renderOption, | ||
options, | ||
}; | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/select/src/presets/useSelectWithLoading/index.module.css
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,7 @@ | ||
.skeleton { | ||
position: absolute; | ||
top: 50%; | ||
transform: translateY(-50%); | ||
height: 16px; | ||
width: 50%; | ||
} |
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