-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4891 from GeekyAnts/release/3.4.0-rc.10
Release/3.4.0 rc.10
- Loading branch information
Showing
8 changed files
with
115 additions
and
66 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
99 changes: 87 additions & 12 deletions
99
src/components/composites/Actionsheet/ActionsheetItem.tsx
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,24 +1,99 @@ | ||
import React, { memo, forwardRef } from 'react'; | ||
import { Button } from '../../primitives/Button'; | ||
import type { IActionsheetItemProps } from './types'; | ||
import { Pressable } from '../../primitives/Pressable'; | ||
import Box from '../../primitives/Box'; | ||
import { HStack } from '../../primitives/Stack'; | ||
import Spinner from '../../primitives/Spinner'; | ||
import { usePropsResolution } from '../../../hooks'; | ||
import { useHasResponsiveProps } from '../../../hooks/useHasResponsiveProps'; | ||
import type { IActionsheetItemProps } from './types'; | ||
|
||
const ActionsheetItem = (props: IActionsheetItemProps, ref?: any) => { | ||
const resolvedProps = usePropsResolution( | ||
'ActionsheetItem', | ||
props, | ||
undefined, | ||
{ | ||
cascadePseudoProps: true, | ||
} | ||
); | ||
const ActionsheetItem = ( | ||
{ | ||
//@ts-ignore | ||
children, | ||
startIcon, | ||
rightIcon, | ||
leftIcon, | ||
endIcon, | ||
spinner, | ||
isDisabled, | ||
isLoading, | ||
spinnerPlacement = 'start', | ||
...props | ||
}: IActionsheetItemProps, | ||
ref: any | ||
) => { | ||
const { | ||
_text, | ||
_stack, | ||
_icon, | ||
_spinner, | ||
isLoadingText, | ||
...resolvedProps | ||
} = usePropsResolution('ActionsheetItem', props, undefined, { | ||
cascadePseudoProps: true, | ||
}); | ||
//TODO: refactor for responsive prop | ||
if (useHasResponsiveProps(props)) { | ||
return null; | ||
} | ||
|
||
return <Button {...resolvedProps} ref={ref} />; | ||
if (leftIcon) { | ||
startIcon = leftIcon; | ||
} | ||
if (rightIcon) { | ||
endIcon = rightIcon; | ||
} | ||
if (endIcon && React.isValidElement(endIcon)) { | ||
endIcon = React.Children.map( | ||
endIcon, | ||
(child: JSX.Element, index: number) => { | ||
return React.cloneElement(child, { | ||
key: `button-end-icon-${index}`, | ||
..._icon, | ||
...child.props, | ||
}); | ||
} | ||
); | ||
} | ||
if (startIcon && React.isValidElement(startIcon)) { | ||
startIcon = React.Children.map( | ||
startIcon, | ||
(child: JSX.Element, index: number) => { | ||
return React.cloneElement(child, { | ||
key: `button-start-icon-${index}`, | ||
..._icon, | ||
...child.props, | ||
}); | ||
} | ||
); | ||
} | ||
const spinnerElement = spinner ? ( | ||
spinner | ||
) : ( | ||
<Spinner color={_text?.color} {..._spinner} /> | ||
); | ||
|
||
const boxChildren = (child: any) => { | ||
return child ? <Box _text={_text}>{child}</Box> : null; | ||
}; | ||
|
||
return ( | ||
<Pressable disabled={isDisabled || isLoading} {...resolvedProps} ref={ref}> | ||
<HStack {..._stack} test={true}> | ||
{startIcon && !isLoading ? startIcon : null} | ||
{isLoading && spinnerPlacement === 'start' ? spinnerElement : null} | ||
{isLoading | ||
? isLoadingText | ||
? boxChildren(isLoadingText) | ||
: null | ||
: boxChildren(children)} | ||
|
||
{endIcon && !isLoading ? endIcon : null} | ||
{isLoading && spinnerPlacement === 'end' ? spinnerElement : null} | ||
</HStack> | ||
</Pressable> | ||
); | ||
}; | ||
|
||
export default memo(forwardRef(ActionsheetItem)); |
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
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
a7ce27c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
native-base – ./
native-base.vercel.app
native-base-geekyants-team.vercel.app
native-base-git-master-geekyants-team.vercel.app