| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- import {
- useState
- } from "react";
- import {
- TouchableOpacity,
- Image,
- View
- } from "react-native";
- import type ISiteLogoProps from "./type";
- import stylesheet, {
- getSiteLogoSize,
- useStyles
- } from "./stylesheet";
- import {
- NCoreUIKitTheme
- } from "../../core/hooks";
- import {
- Home as HomeIcon
- } from "lucide-react-native";
- import Loading from "../loading";
- import Text from "../text";
- const SiteLogo = ({
- logoBackgroundColor = "default",
- isWorkWithFlex1 = true,
- isShowBorder = false,
- subTitleCustomColor,
- isCustomImageSize,
- isShowIcon = true,
- isWorkWithAction,
- titleCustomColor,
- image: ImageProp,
- backgroundColor,
- subTitleVariant,
- icon: IconProp,
- size = "large",
- subTitleColor,
- titleVariant,
- imageSource,
- customTheme,
- borderColor,
- imageSpace,
- isDisabled,
- titleColor,
- imageProps,
- isLoading,
- iconColor,
- imageUrl,
- subTitle,
- onPress,
- title,
- style
- }: ISiteLogoProps) => {
- const {
- borders,
- colors,
- spaces
- } = NCoreUIKitTheme.useContext(customTheme);
- const currentSize = getSiteLogoSize({
- spaces,
- size
- });
- const [
- imageLoadError,
- setImageLoadError
- ] = useState(false);
- const {
- contentContainer: contentContainerDynamicStyle,
- titlesContainer: titlesContainerDynamicStyle,
- container: containerDynamicStyle,
- image: imageDynamicStyle,
- icon: iconDynamicStyle
- } = useStyles({
- logoBackgroundColor,
- isCustomImageSize,
- image: ImageProp,
- isWorkWithFlex1,
- backgroundColor,
- isShowBorder,
- borderColor,
- currentSize,
- isDisabled,
- imageSpace,
- isLoading,
- imageUrl,
- borders,
- colors,
- spaces
- });
- const renderIcon = () => {
- if(IconProp) {
- return <IconProp
- size={currentSize.iconSize}
- customColor={iconColor}
- color="default"
- style={{
- ...iconDynamicStyle
- }}
- />;
- }
- return <HomeIcon
- color={iconColor ? iconColor : colors.content.icon.default}
- size={currentSize.iconSize}
- style={{
- ...iconDynamicStyle
- }}
- />;
- };
- const renderLoading = () => {
- let loadingColor: keyof NCoreUIKit.IconContentColors = "default";
- if(title) {
- loadingColor = "onPrimary";
- } else if(imageUrl || ImageProp) {
- loadingColor = "mid";
- }
- return <Loading
- color={loadingColor}
- />;
- };
- const renderContent = () => {
- if(isLoading) {
- return renderLoading();
- }
- if(IconProp) {
- return renderIcon();
- }
- if(!ImageProp && !imageUrl) {
- return renderIcon();
- }
- if((imageUrl || ImageProp) && imageLoadError) {
- return renderIcon();
- }
- if(ImageProp) {
- return <ImageProp
- {...imageProps}
- onError={() => setImageLoadError(true)}
- height={currentSize.size}
- width={currentSize.size}
- style={[
- stylesheet.image,
- imageDynamicStyle,
- imageProps?.style
- ]}
- />;
- }
- if(imageUrl) {
- return <Image
- {...imageProps}
- onError={() => setImageLoadError(true)}
- height={currentSize.size}
- width={currentSize.size}
- source={{
- uri: imageUrl,
- ...imageSource
- }}
- style={[
- stylesheet.image,
- imageDynamicStyle,
- imageProps?.style
- ]}
- />;
- }
- return null;
- };
- const renderTitles = () => {
- if(!title) {
- return null;
- }
- return <View
- style={[
- stylesheet.titlesContainer,
- titlesContainerDynamicStyle
- ]}
- >
- <Text
- variant={titleVariant ? titleVariant : currentSize.titleSize}
- color={titleColor ? titleColor : "high"}
- customColor={titleCustomColor}
- ellipsizeMode="tail"
- numberOfLines={1}
- style={{
- width: "100%"
- }}
- >
- {title}
- </Text>
- {
- subTitle ?
- <Text
- variant={subTitleVariant ? subTitleVariant : currentSize.subTitleSize}
- color={subTitleColor ? subTitleColor : "low"}
- customColor={subTitleCustomColor}
- ellipsizeMode="tail"
- numberOfLines={1}
- style={{
- width: "100%"
- }}
- >
- {subTitle}
- </Text>
- :
- null
- }
- </View>;
- };
- const renderContentContainer = () => {
- if(!isShowIcon) {
- return null;
- }
- return <View
- style={[
- stylesheet.contentContainer,
- contentContainerDynamicStyle
- ]}
- >
- {renderContent()}
- </View>;
- };
- return <TouchableOpacity
- disabled={!isWorkWithAction || isDisabled || isLoading}
- onPress={!isWorkWithAction || isDisabled || isLoading ? undefined : () => {
- if(onPress) onPress();
- }}
- style={[
- style,
- stylesheet.container,
- containerDynamicStyle
- ]}
- >
- {renderContentContainer()}
- {renderTitles()}
- </TouchableOpacity>;
- };
- export default SiteLogo;
|