Skip to content

Commit 20b6c65

Browse files
committed
feat: add TypeScript support with new types and update Toast components
1 parent 8c36125 commit 20b6c65

File tree

14 files changed

+103
-47
lines changed

14 files changed

+103
-47
lines changed

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file helps IDEs find types more easily
2+
export * from './build';

package.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88
"module": "build/index.es.js",
99
"jsnext:main": "build/index.es.js",
1010
"types": "build/index.d.ts",
11+
"typings": "build/index.d.ts",
12+
"exports": {
13+
".": {
14+
"types": "./build/index.d.ts",
15+
"import": "./build/index.es.js",
16+
"require": "./build/index.js",
17+
"default": "./build/index.js"
18+
},
19+
"./package.json": "./package.json"
20+
},
21+
"sideEffects": false,
1122
"keywords": [
1223
"react-native",
1324
"react-native-rooster",
@@ -28,7 +39,10 @@
2839
"scripts": {
2940
"build": "rimraf -rf build && rollup -c",
3041
"prepublish": "yarn build",
31-
"test": "jest --coverage"
42+
"test": "jest --coverage",
43+
"type-check": "tsc --noEmit",
44+
"lint": "eslint \"src/**/*.{ts,tsx}\"",
45+
"validate": "yarn type-check && yarn lint && yarn test"
3246
},
3347
"peerDependencies": {
3448
"react": "*",

rollup.config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ export default [
8080
{
8181
input: 'src/index.ts',
8282
output: [{ file: 'build/index.d.ts', format: 'es' }],
83-
plugins: [dts()],
83+
plugins: [
84+
dts({
85+
respectExternal: true,
86+
compilerOptions: {
87+
preserveSymlinks: false,
88+
}
89+
})
90+
],
8491
},
8592
];

src/@types/config.d.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/@types/toast.d.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/@types/toastContext.d.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/components/Toast/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ import {
77
Platform,
88
} from 'react-native';
99
import useToast from 'hooks/useToast';
10+
import type { ToastMessage, ToastConfig } from '../../types';
1011

11-
interface IToastComponent {
12-
message: IToastMessage;
13-
toastConfig: IConfig;
12+
interface ToastComponentProps {
13+
message: ToastMessage;
14+
toastConfig: ToastConfig;
1415
index: number; // stack index
1516
bottomOffset: number; // base bottom inset (safe area + keyboard)
1617
}
1718

18-
const Toast: React.FC<IToastComponent> = ({
19+
const Toast: React.FC<ToastComponentProps> = ({
1920
message,
2021
toastConfig,
2122
index,

src/components/ToastContainer/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import useKeyboard from 'hooks/useKeyboard';
44
import { useSafeAreaInsets } from 'react-native-safe-area-context';
55
// import the actual Toast component instead of self-import
66
import Toast from '../Toast';
7+
import type { ToastMessage, ToastConfig } from '../../types';
78

8-
interface IToastContainer {
9+
interface ToastContainerProps {
910
// messages may be missing or undefined at runtime
10-
messages?: IToastMessage[];
11-
toastConfig: IConfig;
11+
messages?: ToastMessage[];
12+
toastConfig: ToastConfig;
1213
}
1314

1415
// Provide a default empty array to avoid undefined
15-
const ToastContainer: React.FC<IToastContainer> = (props) => {
16+
const ToastContainer: React.FC<ToastContainerProps> = (props) => {
1617
const { messages = [], toastConfig } = props;
1718

1819
const [keyboardHeight] = useKeyboard();

src/contexts/ToastContext.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createContext } from 'react';
2+
import type { ToastContextProps } from '../types';
23

3-
const ToastContext = createContext<IToastContext>({} as IToastContext);
4+
const ToastContext = createContext<ToastContextProps>({} as ToastContextProps);
45

56
export default ToastContext;

src/hooks/useToast.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { useContext } from 'react';
22

33
import ToastContext from 'contexts/ToastContext';
4+
import type { ToastContextProps } from '../types';
45

5-
const useToast = (): IToastContext => {
6+
const useToast = (): ToastContextProps => {
67
const context = useContext(ToastContext);
78

89
if (!context) {

0 commit comments

Comments
 (0)