-
Notifications
You must be signed in to change notification settings - Fork 366
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
Showing
64 changed files
with
1,747 additions
and
452 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,133 @@ | ||
import { Button } from '../Button'; | ||
import { Checkbox } from '../Checkbox'; | ||
import { Stack, XStack } from '../Stack'; | ||
|
||
import type { GetProps } from 'tamagui'; | ||
|
||
type ModalButtonGroupProps = { | ||
onConfirm?: () => void | Promise<boolean>; | ||
onCancel?: () => void; | ||
confirmButtonProps?: GetProps<typeof Button>; | ||
cancelButtonProps?: GetProps<typeof Button>; | ||
confirmButtonTextProps?: GetProps<typeof Button.Text>; | ||
cancelButtonTextProps?: GetProps<typeof Button.Text>; | ||
}; | ||
|
||
function ModalButtonGroup({ | ||
onCancel, | ||
onConfirm, | ||
confirmButtonProps, | ||
cancelButtonProps, | ||
confirmButtonTextProps, | ||
cancelButtonTextProps, | ||
}: ModalButtonGroupProps) { | ||
return ( | ||
<XStack | ||
$sm={{ | ||
width: '100%', | ||
justifyContent: 'center', | ||
gap: '$5', | ||
}} | ||
$gtSm={{ | ||
justifyContent: 'flex-end', | ||
gap: '$2', | ||
}} | ||
> | ||
{(!!cancelButtonProps || !!onCancel) && ( | ||
<Button | ||
buttonVariant="secondary" | ||
$sm={{ | ||
flex: 1, | ||
size: 'large', | ||
}} | ||
$gtSm={{ | ||
size: 'medium', | ||
}} | ||
onPress={onCancel} | ||
{...cancelButtonProps} | ||
> | ||
<Button.Text paddingHorizontal="$3" {...cancelButtonTextProps}> | ||
Cancel | ||
</Button.Text> | ||
</Button> | ||
)} | ||
{(!!confirmButtonProps || !!onConfirm) && ( | ||
<Button | ||
buttonVariant="primary" | ||
$sm={{ | ||
flex: 1, | ||
size: 'large', | ||
}} | ||
$gtSm={{ | ||
size: 'medium', | ||
}} | ||
onPress={onConfirm} | ||
{...confirmButtonProps} | ||
> | ||
<Button.Text paddingHorizontal="$3" {...confirmButtonTextProps}> | ||
Confirm | ||
</Button.Text> | ||
</Button> | ||
)} | ||
</XStack> | ||
); | ||
} | ||
|
||
type ModalContainerProps = { | ||
children: React.ReactNode; | ||
checkboxProps?: GetProps<typeof Checkbox>; | ||
} & ModalButtonGroupProps; | ||
|
||
export function ModalContainer({ | ||
children, | ||
checkboxProps, | ||
onCancel, | ||
onConfirm, | ||
confirmButtonProps, | ||
cancelButtonProps, | ||
confirmButtonTextProps, | ||
cancelButtonTextProps, | ||
}: ModalContainerProps) { | ||
return ( | ||
<Stack flex={1}> | ||
<Stack flex={1}>{children}</Stack> | ||
|
||
<Stack | ||
bg="$bg" | ||
padding="$5" | ||
$sm={{ | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
}} | ||
$gtSm={{ | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
}} | ||
> | ||
{!!checkboxProps && ( | ||
<Stack | ||
$sm={{ | ||
width: '100%', | ||
alignItems: 'flex-start', | ||
mb: '$2.5', | ||
}} | ||
$gtSm={{ | ||
justifyContent: 'center', | ||
}} | ||
> | ||
<Checkbox {...checkboxProps} /> | ||
</Stack> | ||
)} | ||
<ModalButtonGroup | ||
onCancel={onCancel} | ||
onConfirm={onConfirm} | ||
confirmButtonProps={confirmButtonProps} | ||
cancelButtonProps={cancelButtonProps} | ||
confirmButtonTextProps={confirmButtonTextProps} | ||
cancelButtonTextProps={cancelButtonTextProps} | ||
/> | ||
</Stack> | ||
</Stack> | ||
); | ||
} |
93 changes: 93 additions & 0 deletions
93
packages/components/src/Navigation/Header/HeaderSearchBar.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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { useCallback } from 'react'; | ||
|
||
import { useMedia } from 'tamagui'; | ||
|
||
import { SearchBar } from '../../SearchBar'; | ||
|
||
import type { | ||
NativeSyntheticEvent, | ||
TargetedEvent, | ||
TextInputFocusEventData, | ||
TextInputSubmitEditingEventData, | ||
} from 'react-native'; | ||
|
||
type HeaderSearchBarProps = { | ||
height?: string; | ||
/** | ||
* A callback that gets called when search bar has lost focus | ||
*/ | ||
onBlur?: (e: NativeSyntheticEvent<TargetedEvent>) => void; | ||
/** | ||
* A callback that gets called when the text changes. It receives the current text value of the search bar. | ||
*/ | ||
onChangeText?: (e: NativeSyntheticEvent<TextInputFocusEventData>) => void; | ||
/** | ||
* A callback that gets called when search bar has received focus | ||
*/ | ||
onFocus?: (e: NativeSyntheticEvent<TargetedEvent>) => void; | ||
/** | ||
* A callback that gets called when the search button is pressed. It receives the current text value of the search bar. | ||
*/ | ||
onSearchButtonPress?: ( | ||
e: NativeSyntheticEvent<TextInputFocusEventData>, | ||
) => void; | ||
/** | ||
* Text displayed when search field is empty | ||
*/ | ||
placeholder?: string; | ||
}; | ||
|
||
function HeaderSearchBar({ | ||
onBlur, | ||
onFocus, | ||
onChangeText, | ||
onSearchButtonPress, | ||
placeholder, | ||
}: HeaderSearchBarProps) { | ||
const media = useMedia(); | ||
|
||
const handleChangeCallback = useCallback( | ||
(value: string) => { | ||
onChangeText?.({ | ||
nativeEvent: { | ||
text: value, | ||
}, | ||
} as NativeSyntheticEvent<TextInputFocusEventData>); | ||
}, | ||
[onChangeText], | ||
); | ||
|
||
const onBlurCallback = useCallback( | ||
(e: NativeSyntheticEvent<TextInputFocusEventData>) => { | ||
onBlur?.(e); | ||
}, | ||
[onBlur], | ||
); | ||
|
||
const onFocusCallback = useCallback( | ||
(e: NativeSyntheticEvent<TextInputFocusEventData>) => { | ||
onFocus?.(e); // Stub event object | ||
}, | ||
[onFocus], | ||
); | ||
|
||
const onSubmitEditingCallback = useCallback( | ||
(e: NativeSyntheticEvent<TextInputSubmitEditingEventData>) => { | ||
onSearchButtonPress?.(e as NativeSyntheticEvent<TextInputFocusEventData>); | ||
}, | ||
[onSearchButtonPress], | ||
); | ||
|
||
return ( | ||
<SearchBar | ||
height={media.gtMd ? '$8' : '$9'} | ||
onBlur={onBlurCallback} | ||
onFocus={onFocusCallback} | ||
onChange={handleChangeCallback} | ||
onSubmitEditing={onSubmitEditingCallback} | ||
placeholder={placeholder} | ||
/> | ||
); | ||
} | ||
|
||
export default HeaderSearchBar; |
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
Oops, something went wrong.