Skip to content

Commit

Permalink
chore(typings): provide types
Browse files Browse the repository at this point in the history
  • Loading branch information
luancurti committed Jun 1, 2023
1 parent 0704098 commit a6c57b8
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 143 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
extends:['@platformbuilders/eslint-config-builders'],
ignorePatterns: ['exampleDev']
ignorePatterns: ['exampleDev', 'types']
};
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"name": "@platformbuilders/react-native-toast",
"version": "0.0.4",
"version": "0.0.5",
"description": "",
"author": "Platform Builders <[email protected]>",
"repository": {
"type": "git",
"url": "git+https://github.com/platformbuilders/template-hooks.git"
},
"main": "dist/index.js",
"module": "dist/index.es.js",
"types": "dist/index.d.ts",
"engines": {
"node": ">=12",
Expand All @@ -19,7 +18,7 @@
"test": "cross-env CI=1 react-scripts test --env=jsdom --passWithNoTests",
"test:watch": "react-scripts test --env=jsdom",
"build": "rm -rf dist && npm run build:cjs",
"build:cjs": "tsc ./src/index.ts --module CommonJS --jsx react-jsx --outDir dist --skipLibCheck true --esModuleInterop true",
"build:cjs": "tsc --project ./tsconfig.json",
"start": "rollup -c -w",
"prepare": "husky install",
"pretty": "prettier --config ./.prettierrc.js --write \"src/**/*.{jsx,ts,tsx,json}\"",
Expand Down
74 changes: 2 additions & 72 deletions src/Toast.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FC, useEffect, useState } from 'react';
import { ImageSourcePropType, LayoutChangeEvent } from 'react-native';
import { LayoutChangeEvent } from 'react-native';
import {
PanGestureHandler,
PanGestureHandlerGestureEvent,
Expand All @@ -14,6 +14,7 @@ import {
withTiming,
} from 'react-native-reanimated';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { PanGestureContextType, ToastConfig, ToastProps } from '../types/index';
import {
CloseButton,
CloseText,
Expand All @@ -24,83 +25,12 @@ import {
Title,
} from './styles';

export type ToastType = 'success' | 'alert' | 'warning' | 'custom';

type ToastConfig = {
fontFamily?: string;
textColor?: string;
backgroundColor?: {
success?: string;
alert?: string;
warning?: string;
custom?: string;
};
icon: {
success: {
icon?: ImageSourcePropType;
height?: number;
width?: number;
};
alert: {
icon?: ImageSourcePropType;
height?: number;
width?: number;
};
warning: {
icon?: ImageSourcePropType;
height?: number;
width?: number;
};
custom: {
icon?: ImageSourcePropType;
height?: number;
width?: number;
};
};
autoHide: {
success: boolean;
alert: boolean;
warning: boolean;
custom: boolean;
};
showCloseButton: {
success: boolean;
alert: boolean;
warning: boolean;
custom: boolean;
};
showIcon?: boolean;
};

export type ToastProps = {
title?: string | undefined;
message: string;
type: ToastType;
duration?: number;
};

type Props = {
children?: React.ReactNode;
data: ToastProps;
config: ToastConfig;
};

type PanGestureContextType = {
translateY: number;
};

/**
*
* @typedef {ToastProps} - Parâmetros do toast
*
* @example
* const { showToast } = useToast();
* showToast({
* title: 'Sucesso',
* message: 'Toast de notificação de sucesso',
* type: 'success',
*});
*/
export const Toast: FC<Props> = ({ data, config }) => {
const insets = useSafeAreaInsets();

Expand Down
64 changes: 7 additions & 57 deletions src/ToastProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,61 +1,11 @@
import React, { createContext, useContext, useState } from 'react';
import { ImageSourcePropType } from 'react-native';
import { Toast, ToastProps, ToastType } from './Toast';

export type ToastConfigProps = {
fontFamily?: string;
textColor?: string;
backgroundColor?: {
success?: string;
alert?: string;
warning?: string;
custom?: string;
};
icon?: {
success?: {
icon?: ImageSourcePropType;
height?: number;
width?: number;
};
alert?: {
icon?: ImageSourcePropType;
height?: number;
width?: number;
};
warning?: {
icon?: ImageSourcePropType;
height?: number;
width?: number;
};
custom?: {
icon?: ImageSourcePropType;
height?: number;
width?: number;
};
};
autoHide?: {
success?: boolean;
alert?: boolean;
warning?: boolean;
custom?: boolean;
};
showCloseButton?: {
success?: boolean;
alert?: boolean;
warning?: boolean;
custom?: boolean;
};
showIcon?: boolean;
};

type ContextType = {
showToast(data: ToastProps): void;
};

interface ToastProviderProps {
children: React.ReactNode;
config?: ToastConfigProps;
}
import {
ContextType,
ToastProps,
ToastProviderProps,
ToastType,
} from '../types/index';
import { Toast } from './Toast';

const ToastContext = createContext<ContextType>({
showToast: () => {},
Expand Down
20 changes: 10 additions & 10 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
{
"compilerOptions": {
"target": "es6",
"module": "esnext",
"target": "ESNext",
"module": "CommonJS",
"lib": [
"esnext",
"DOM"
"ESNext",
],
"types": [
"react",
"jest"
"jest",
],
"jsx": "react-jsx",
"jsx": "react",
"declaration": true,
"declarationMap": true,
"declarationMap": false,
"experimentalDecorators": true,
"sourceMap": true,
"sourceMap": false,
"outDir": "dist",
"importHelpers": true,
"resolveJsonModule": true,
Expand All @@ -37,11 +36,12 @@
"allowJs": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"noEmit": true
"noEmit": false
},
"compileOnSave": true,
"include": [
"src"
"src/**/*",
"types/**/*"
],
"exclude": [
"node_modules",
Expand Down
115 changes: 115 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import type { ImageSourcePropType } from 'react-native';

declare type ToastType = 'success' | 'alert' | 'warning' | 'custom';

declare type PanGestureContextType = {
translateY: number;
}

declare type ToastConfig = {
fontFamily?: string;
textColor?: string;
backgroundColor?: {
success?: string;
alert?: string;
warning?: string;
custom?: string;
};
icon: {
success: {
icon?: ImageSourcePropType;
height?: number;
width?: number;
};
alert: {
icon?: ImageSourcePropType;
height?: number;
width?: number;
};
warning: {
icon?: ImageSourcePropType;
height?: number;
width?: number;
};
custom: {
icon?: ImageSourcePropType;
height?: number;
width?: number;
};
};
autoHide: {
success: boolean;
alert: boolean;
warning: boolean;
custom: boolean;
};
showCloseButton: {
success: boolean;
alert: boolean;
warning: boolean;
custom: boolean;
};
showIcon?: boolean;
}

declare type ToastProps = {
title?: string | undefined;
message: string;
type: ToastType;
duration?: number;
}

declare type ToastConfigProps = {
fontFamily?: string;
textColor?: string;
backgroundColor?: {
success?: string;
alert?: string;
warning?: string;
custom?: string;
};
icon?: {
success?: {
icon?: ImageSourcePropType;
height?: number;
width?: number;
};
alert?: {
icon?: ImageSourcePropType;
height?: number;
width?: number;
};
warning?: {
icon?: ImageSourcePropType;
height?: number;
width?: number;
};
custom?: {
icon?: ImageSourcePropType;
height?: number;
width?: number;
};
};
autoHide?: {
success?: boolean;
alert?: boolean;
warning?: boolean;
custom?: boolean;
};
showCloseButton?: {
success?: boolean;
alert?: boolean;
warning?: boolean;
custom?: boolean;
};
showIcon?: boolean;
}

declare type ContextType = {
showToast(data: ToastProps): void;
}

declare interface ToastProviderProps {
children: React.ReactNode;
config?: ToastConfigProps;
}

0 comments on commit a6c57b8

Please sign in to comment.