| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- import {
- type TextStyle,
- type ViewStyle,
- StyleSheet
- } from "react-native";
- import type {
- SnackBarDynamicStyleType,
- SnackBarTypeConstantType,
- SnackBarTypes,
- SnackBarType
- } from "./type";
- import type {
- Mutable
- } from "../../types";
- import {
- windowWidth
- } from "../../utils";
- export const SNACK_BAR_TYPE_STYLES: Record<
- SnackBarType,
- {
- containerColor: keyof NCoreUIKit.ContainerContentColors;
- subTitleColor: keyof NCoreUIKit.TextContentColors;
- actionColor: keyof NCoreUIKit.TextContentColors;
- titleColor: keyof NCoreUIKit.TextContentColors;
- iconColor: keyof NCoreUIKit.IconContentColors;
- }
- > = {
- primary: {
- actionColor: "onPrimary",
- iconColor: "emphasized",
- containerColor: "mid",
- subTitleColor: "low",
- titleColor: "mid"
- },
- danger: {
- subTitleColor: "dangerLow",
- containerColor: "danger",
- actionColor: "danger",
- titleColor: "danger",
- iconColor: "danger"
- },
- success: {
- subTitleColor: "successLow",
- containerColor: "success",
- actionColor: "success",
- titleColor: "success",
- iconColor: "success"
- },
- warning: {
- subTitleColor: "warningLow",
- containerColor: "warning",
- actionColor: "warning",
- titleColor: "warning",
- iconColor: "warning"
- },
- info: {
- subTitleColor: "infoLow",
- containerColor: "info",
- actionColor: "info",
- titleColor: "info",
- iconColor: "info"
- },
- neutral: {
- containerColor: "mid",
- subTitleColor: "low",
- actionColor: "mid",
- titleColor: "mid",
- iconColor: "mid"
- }
- };
- export const getSnackBarType = ({
- type
- }: SnackBarTypeConstantType): SnackBarTypes => {
- const currentType = SNACK_BAR_TYPE_STYLES[type];
- return currentType;
- };
- const stylesheet = StyleSheet.create({
- container: {
- position: "absolute",
- alignSelf: "center",
- zIndex: 99998
- },
- containerObject: {
- flexDirection: "row",
- alignItems: "center"
- },
- contentContainer: {
- justifyContent: "center",
- alignItems: "flex-start",
- flexDirection: "column",
- flexShrink: 1,
- flex: 1
- },
- iconContainer: {
- justifyContent: "center",
- alignItems: "center"
- },
- title: {
- textAlign: "left"
- },
- subTitle: {
- textAlign: "left"
- }
- });
- export const useStyles = ({
- isInlineSafeArea,
- isFullWidth,
- safeAreaTop,
- currentType,
- radiuses,
- colors,
- spaces
- }: SnackBarDynamicStyleType) => {
- const styles = {
- container: {
- backgroundColor: colors.content.container[currentType.containerColor],
- width: windowWidth - (spaces.spacingMd * 2),
- top: safeAreaTop + spaces.spacingSm,
- borderRadius: radiuses.lg
- } as Mutable<ViewStyle>,
- containerObject: {
- paddingHorizontal: spaces.spacingLg,
- paddingVertical: spaces.spacingMd
- } as Mutable<ViewStyle>,
- contentContainer: {
- } as Mutable<ViewStyle>,
- title: {
- } as Mutable<TextStyle>,
- subTitle: {
- marginTop: spaces.spacingXs
- } as Mutable<TextStyle>,
- iconContainer: {
- paddingRight: spaces.spacingSm,
- marginRight: spaces.spacingSm
- } as Mutable<ViewStyle>,
- action: {
- paddingBottom: spaces.spacingSm,
- paddingRight: spaces.spacingSm,
- paddingLeft: spaces.spacingMd,
- paddingTop: spaces.spacingSm,
- marginLeft: spaces.spacingMd
- } as Mutable<ViewStyle>
- };
- if(isFullWidth) {
- styles.container.width = windowWidth;
- styles.container.borderRadius = 0;
- }
- if(isInlineSafeArea) {
- styles.container.paddingTop = safeAreaTop;
- styles.container.top = 0;
- }
- return styles;
- };
- export default stylesheet;
|