| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- import {
- type FC
- } from "react";
- import {
- View
- } from "react-native";
- import type INotificationIndicatorProps from "./type";
- import stylesheet, {
- getNotificationIndicatorType,
- useStyles
- } from "./stylesheet";
- import {
- NCoreUIKitTheme
- } from "../../core/hooks";
- import type ITextProps from "../text/type";
- import Loading from "../loading";
- import Text from "../text";
- const NotificationIndicator: FC<INotificationIndicatorProps> = ({
- floorBackgroundColor = "default",
- titleVariant = "labelSmallSize",
- spreadBehaviour = "baseline",
- isDisabled = false,
- type = "neutral",
- customTheme,
- titleStyle,
- isLoading,
- location,
- children,
- title,
- style,
- ...props
- }) => {
- const {
- typography,
- radiuses,
- borders,
- colors,
- spaces
- } = NCoreUIKitTheme.useContext(customTheme);
- const currentType = getNotificationIndicatorType({
- type
- });
- const {
- indicatorContainer: indicatorContainerDynamicStyle,
- titleContainer: titleContainerDynamicStyle,
- container: containerDynamicStyle,
- loading: loadingDynamicStyle,
- overlay: overlayDynamicStyle,
- title: titleDynamicStyle
- } = useStyles({
- floorBackgroundColor,
- spreadBehaviour,
- currentType,
- isDisabled,
- isLoading,
- radiuses,
- borders,
- colors,
- spaces,
- type
- });
- const titleProps: ITextProps = {
- color: currentType.titleColor,
- variant: titleVariant
- };
- const fontSize = typography[titleProps.variant as keyof NCoreUIKit.Typography].fontSize;
- let baseLocation = location ? location : {
- bottom: undefined,
- left: undefined,
- right: 0,
- top: 2
- };
- if(!location && title) {
- baseLocation = {
- right: -fontSize / String(title).length,
- top: -fontSize / 2,
- bottom: undefined,
- left: undefined
- };
- }
- if (isDisabled || isLoading) {
- const stateType = type === "danger" ? "error" : type;
- titleProps.customColor = colors.system.state.content.disabled[stateType];
- }
- const renderTitle = () => {
- if (!title) {
- return null;
- }
- return <View
- style={[
- stylesheet.titleContainer,
- titleContainerDynamicStyle
- ]}
- >
- <Text
- variant="bodyMediumSize"
- style={[
- titleStyle,
- stylesheet.title,
- titleDynamicStyle
- ]}
- {...titleProps}
- >
- {title}
- </Text>
- {renderOverlay()}
- </View>;
- };
- const renderIndicatorContainer = () => {
- if (isLoading) {
- return <Loading
- style={[
- loadingDynamicStyle
- ]}
- />;
- }
- return <View
- style={[
- stylesheet.indicatorContainer,
- indicatorContainerDynamicStyle,
- baseLocation
- ]}
- >
- {renderTitle()}
- </View>;
- };
- const renderOverlay = () => {
- return <View
- style={[
- stylesheet.overlay,
- overlayDynamicStyle
- ]}
- />;
- };
- return <View
- {...props}
- style={[
- style,
- stylesheet.container,
- containerDynamicStyle
- ]}
- >
- {children}
- {renderIndicatorContainer()}
- </View>;
- };
- export default NotificationIndicator;
|