Skip to content

Commit

Permalink
fix: better typings
Browse files Browse the repository at this point in the history
  • Loading branch information
dackmin committed Jun 3, 2024
1 parent 8bfffc4 commit 390a06b
Show file tree
Hide file tree
Showing 61 changed files with 1,810 additions and 1,124 deletions.
66 changes: 31 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,64 @@
"packages/*"
],
"scripts": {
"lerna": "./node_modules/.bin/lerna",
"prepack": "npm run lint && npm run build && npm run test",
"unlink-all": "./node_modules/.bin/lerna exec --parallel -- npm run unlink",
"link-all": "./node_modules/.bin/lerna exec --parallel -- npm run link",
"test": "BABEL_ENV=tests ./node_modules/.bin/jest",
"lint": "./node_modules/.bin/eslint .",
"clean": "./node_modules/.bin/lerna exec --parallel -- yarn clean",
"build": "./node_modules/.bin/lerna exec -- yarn build",
"prepack": "yarn lint && yarn build && yarn test",
"test": "BABEL_ENV=tests jest",
"lint": "eslint .",
"clean": "lerna exec --parallel -- yarn clean",
"build": "lerna exec -- yarn build",
"serve": "storybook dev",
"storybook-build": "storybook build",
"generate-types": "./node_modules/.bin/lerna exec -- npm run generate-types"
"storybook-build": "storybook build"
},
"devDependencies": {
"@babel/eslint-plugin": "7.23.5",
"@babel/eslint-plugin": "7.24.6",
"@poool/eslint-config": "3.0.1",
"@poool/eslint-config-react": "3.0.1",
"@poool/eslint-plugin": "3.0.0",
"@rollup/plugin-alias": "5.1.0",
"@rollup/plugin-babel": "6.0.4",
"@rollup/plugin-commonjs": "25.0.7",
"@rollup/plugin-commonjs": "25.0.8",
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-swc": "0.3.0",
"@rollup/plugin-terser": "0.4.4",
"@rollup/plugin-typescript": "11.1.6",
"@storybook/addon-actions": "7.6.17",
"@storybook/addon-storysource": "7.6.17",
"@storybook/addon-actions": "7.6.19",
"@storybook/addon-storysource": "7.6.19",
"@storybook/addon-styling": "1.3.7",
"@storybook/react": "7.6.17",
"@storybook/react-webpack5": "7.6.17",
"@swc/core": "1.4.2",
"@storybook/react": "7.6.19",
"@storybook/react-webpack5": "7.6.19",
"@swc/core": "1.5.24",
"@swc/jest": "0.2.36",
"@testing-library/jest-dom": "6.4.2",
"@testing-library/react": "14.2.1",
"@testing-library/jest-dom": "6.4.5",
"@testing-library/react": "14.3.1",
"@testing-library/user-event": "14.5.2",
"@types/d3": "7.4.3",
"@types/jest": "29.5.12",
"@types/node": "20.14.0",
"@typescript-eslint/parser": "7.1.0",
"autoprefixer": "10.4.17",
"@typescript-eslint/parser": "7.11.0",
"autoprefixer": "10.4.19",
"babel-jest": "29.7.0",
"d3": "7.8.5",
"d3": "7.9.0",
"eslint": "8.57.0",
"eslint-config-standard": "17.1.0",
"eslint-plugin-babel": "5.3.1",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-n": "16.6.2",
"eslint-plugin-promise": "6.1.1",
"eslint-plugin-react": "7.33.2",
"eslint-plugin-n": "17.7.0",
"eslint-plugin-promise": "6.2.0",
"eslint-plugin-react": "7.34.2",
"fs-extra": "11.2.0",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"lerna": "8.1.2",
"postcss": "8.4.35",
"react": "18.2.0",
"react-dom": "18.2.0",
"rollup": "4.12.0",
"rollup-plugin-dts": "6.1.0",
"sass": "1.71.1",
"storybook": "7.6.17",
"lerna": "8.1.3",
"postcss": "8.4.38",
"react": "18.3.1",
"react-dom": "18.3.1",
"rollup": "4.18.0",
"rollup-plugin-dts": "6.1.1",
"sass": "1.77.4",
"storybook": "7.6.19",
"storybook-addon-swc": "1.2.0",
"tailwindcss": "3.4.1",
"typescript": "5.3.3"
"tailwindcss": "3.4.3",
"typescript": "5.4.5"
},
"resolutions": {
"inline-style-prefixer": "6.0.4"
Expand Down
5 changes: 5 additions & 0 deletions packages/core/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ export {
getFloatPrecision,
formatThousand,
} from './numbers';

export type {
ForwardedProps,
MockState,
} from './types';
6 changes: 6 additions & 0 deletions packages/core/lib/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { ForwardRefExoticComponent } from 'react';

export declare interface ForwardedProps<T, P>
extends ForwardRefExoticComponent<T & React.RefAttributes<P>> {}

export declare type MockState<T> = (state: T, action: any) => T;
11 changes: 5 additions & 6 deletions packages/react/lib/Abstract/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentPropsWithoutRef, ReactNode } from 'react';
import type { ComponentPropsWithoutRef, ReactNode } from 'react';
import { classNames } from '@junipero/core';

import { useFieldControl } from '../hooks';
Expand All @@ -8,11 +8,10 @@ export declare interface AbstractProps extends ComponentPropsWithoutRef<any> {
children?: ReactNode | JSX.Element;
}

const Abstract = (
{
className,
...rest
}: AbstractProps): JSX.Element => {
const Abstract = ({
className,
...rest
}: AbstractProps): JSX.Element => {
const { valid = true, dirty = false, focused = false } = useFieldControl();

return (
Expand Down
12 changes: 6 additions & 6 deletions packages/react/lib/Alert/index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import {
type MutableRefObject,
type ReactNode,
type ComponentPropsWithRef,
type ElementType,
forwardRef,
useState,
useImperativeHandle,
useRef,
MutableRefObject,
ReactNode,
ComponentPropsWithRef,
ElementType,
} from 'react';
import { classNames } from '@junipero/core';
import { type ForwardedProps, classNames } from '@junipero/core';
import { useTimeout } from '@junipero/hooks';
import PropTypes from 'prop-types';

import { Remove } from '../icons';
import Card from '../Card';
import { ForwardedProps } from '../utils';

export declare type AlertRef = {
isJunipero: boolean;
Expand Down Expand Up @@ -132,4 +131,5 @@ Alert.propTypes = {
onDismiss: PropTypes.func,
onClick: PropTypes.func,
};

export default Alert;
23 changes: 11 additions & 12 deletions packages/react/lib/Alerts/index.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
import {
ComponentPropsWithRef,
MutableRefObject,
ReactNode,
type ComponentPropsWithRef,
type MutableRefObject,
type ReactNode,
forwardRef,
useImperativeHandle,
useRef,
} from 'react';
import { classNames, omit } from '@junipero/core';
import { type ForwardedProps, classNames, omit } from '@junipero/core';
import PropTypes from 'prop-types';

import { useAlerts } from '../hooks';
import Alert, { AlertObject } from '../Alert';
import { ForwardedProps } from '../utils';

export declare type AlertsRef = {
alerts: Array<AlertObject>;
isJunipero: boolean;
innerRef: MutableRefObject<any>;
};

declare type AlertsTypes =
'danger' |
'default' |
'primary'|
'success' |
'warning';
export declare type AlertsTypes =
| 'danger'
| 'default'
| 'primary'
| 'success'
| 'warning';

export declare interface AlertsProps extends ComponentPropsWithRef<any> {
animationTimeout?: number;
className?: string;
icons?: {
[type in AlertsTypes]?: ReactNode | JSX.Element
[type in AlertsTypes]?: ReactNode | JSX.Element;
};
animateAlert?(
alert: ReactNode | JSX.Element,
Expand Down
18 changes: 7 additions & 11 deletions packages/react/lib/AlertsControl/index.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import {
ComponentProps,
ComponentPropsWithRef,
ComponentPropsWithoutRef,
ComponentRef,
ForwardedRef,
MutableRefObject,
PropsWithRef,
type ComponentPropsWithRef,
type MutableRefObject,
forwardRef,
useCallback,
useImperativeHandle,
useState,
} from 'react';
import { type ForwardedProps } from '@junipero/core';
import PropTypes from 'prop-types';

import { AlertsContext, AlertsContextType } from '../contexts';
import { AlertObject } from '../Alert';
import { ForwardedProps } from '../utils';
import { type AlertsContextType, AlertsContext } from '../contexts';
import { type AlertObject } from '../Alert';

export declare type AlertsControlRef ={
export declare type AlertsControlRef = {
alerts: Array<AlertObject>;
isJunipero: boolean;
add(alert: AlertObject): void;
Expand Down Expand Up @@ -72,4 +67,5 @@ AlertsControl.propTypes = {
alerts: PropTypes.array,
generateId: PropTypes.func,
};

export default AlertsControl;
13 changes: 6 additions & 7 deletions packages/react/lib/Badge/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import {
ComponentPropsWithRef,
ElementType,
MutableRefObject,
ReactNode,
type ComponentPropsWithRef,
type ElementType,
type MutableRefObject,
type ReactNode,
forwardRef,
useImperativeHandle,
useRef,
} from 'react';
import { classNames } from '@junipero/core';
import { type ForwardedProps, classNames } from '@junipero/core';
import PropTypes from 'prop-types';

import { ForwardedProps } from '../utils';

export declare type BadgeRef = {
isJunipero: boolean;
innerRef: MutableRefObject<any>;
Expand Down Expand Up @@ -49,4 +47,5 @@ Badge.displayName = 'Badge';
Badge.propTypes = {
tag: PropTypes.any, //TODO fixme
};

export default Badge;
34 changes: 21 additions & 13 deletions packages/react/lib/BreadCrumb/index.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,44 @@
import {
type MutableRefObject,
type ComponentPropsWithRef,
Children,
forwardRef,
Fragment,
forwardRef,
useImperativeHandle,
useReducer,
useRef,
useMemo,
ReactNode,
MutableRefObject,
ComponentPropsWithRef,
} from 'react';
import { exists, classNames, mockState } from '@junipero/core';
import {
type ForwardedProps,
type MockState,
exists,
classNames,
mockState,
} from '@junipero/core';
import PropTypes from 'prop-types';

import BreadCrumbItem from '../BreadCrumbItem';
import { ForwardedProps, MockState } from '../utils';

export declare type BreadCrumbRef = {
items: Array<JSX.Element> | Array<string>;
items: Array<JSX.Element | string>;
isJunipero: boolean;
innerRef: MutableRefObject<any>;
};

export declare interface BreadCrumbProps extends ComponentPropsWithRef<any> {
children?: JSX.Element | Array<JSX.Element>;
className?: string;
items?: Array<JSX.Element> | Array<string>;
items?: Array<JSX.Element | string>;
maxItems?: number;
filterItem?(children: JSX.Element): boolean;
ref?: MutableRefObject<BreadCrumbRef | undefined>;
}

export declare interface BreadCrumbState {
opened: boolean;
}

const BreadCrumb = forwardRef(({
className,
children,
Expand All @@ -39,11 +48,9 @@ const BreadCrumb = forwardRef(({
...rest
}: BreadCrumbProps, ref) => {
const innerRef = useRef();
const [state, dispatch] = useReducer<MockState<{opened: boolean}>>(
mockState, {
opened: false,
}
);
const [state, dispatch] = useReducer<MockState<BreadCrumbState>>(mockState, {
opened: false,
});

useImperativeHandle(ref, () => ({
items,
Expand Down Expand Up @@ -108,4 +115,5 @@ BreadCrumb.propTypes = {
maxItems: PropTypes.number,
filterItem: PropTypes.func,
};

export default BreadCrumb;
13 changes: 6 additions & 7 deletions packages/react/lib/BreadCrumbItem/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import {
ComponentPropsWithRef,
ElementType,
MutableRefObject,
ReactNode,
type ComponentPropsWithRef,
type ElementType,
type MutableRefObject,
type ReactNode,
forwardRef,
useImperativeHandle,
useRef,
} from 'react';
import { classNames } from '@junipero/core';
import { type ForwardedProps, classNames } from '@junipero/core';
import PropTypes from 'prop-types';

import { ForwardedProps } from '../utils';

export declare type BreadCrumbItemRef = {
isJunipero: boolean;
innerRef: MutableRefObject<any>;
Expand Down Expand Up @@ -58,4 +56,5 @@ BreadCrumbItem.propTypes = {
tag: PropTypes.any, // TODO fixme
animate: PropTypes.func,
};

export default BreadCrumbItem;
Loading

0 comments on commit 390a06b

Please sign in to comment.