Skip to content

Commit d1012cc

Browse files
ykornilovYury Kornilov
andauthored
chore: translate Item to TS (#280)
Co-authored-by: Yury Kornilov <[email protected]>
1 parent a7d4c4f commit d1012cc

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

src/components/GridLayout/GridLayout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import type {
3131

3232
const hasPluginId = (value: PluginRef): value is {props: {id: string}} => {
3333
return (
34+
value !== null &&
3435
'props' in value &&
3536
typeof value.props === 'object' &&
3637
value.props !== null &&

src/components/Item/Item.js renamed to src/components/Item/Item.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
import React from 'react';
22

3-
import PropTypes from 'prop-types';
4-
53
import {prepareItem} from '../../hocs/prepareItem';
4+
import type {ConfigItem} from '../../shared/types';
5+
import type {PluginRef, PluginWidgetProps} from '../../typings';
66
import {cn} from '../../utils/cn';
7+
import type {RegisterManager} from '../../utils/register-manager';
78

89
import './Item.scss';
910

1011
const b = cn('dashkit-item');
1112

13+
type ItemProps = {
14+
registerManager: RegisterManager;
15+
rendererProps: Omit<PluginWidgetProps, 'onBeforeLoad'>;
16+
type: string;
17+
isPlaceholder?: boolean;
18+
forwardedPluginRef?: (pluginRef: PluginRef) => void;
19+
onItemRender?: (item: ConfigItem) => void;
20+
onItemMountChange?: (item: ConfigItem, meta: {isAsync: boolean; isMounted: boolean}) => void;
21+
item: ConfigItem;
22+
};
23+
1224
// TODO: getDerivedStateFromError и заглушка с ошибкой
13-
const Item = ({
25+
const Item: React.FC<ItemProps> = ({
1426
registerManager,
1527
rendererProps,
1628
type,
@@ -50,6 +62,8 @@ const Item = ({
5062
});
5163
};
5264
}
65+
66+
return undefined;
5367
}, []);
5468

5569
const onLoad = React.useCallback(() => {
@@ -88,15 +102,4 @@ const Item = ({
88102
);
89103
};
90104

91-
Item.propTypes = {
92-
forwardedPluginRef: PropTypes.any,
93-
rendererProps: PropTypes.object,
94-
registerManager: PropTypes.object,
95-
type: PropTypes.string,
96-
isPlaceholder: PropTypes.bool,
97-
onItemRender: PropTypes.func,
98-
onItemMountChange: PropTypes.func,
99-
item: PropTypes.object,
100-
};
101-
102105
export default prepareItem(Item);

src/typings/plugin.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,16 @@ export interface PluginWidgetProps<T = StringParams> {
4141

4242
export type PluginDefaultLayout = Partial<Omit<WidgetLayout, 'i'>>;
4343

44-
export type PluginRef = React.RefObject<any> | Record<string, unknown>;
44+
export type PluginRef = object | null;
4545

4646
export interface Plugin<P extends PluginWidgetProps<T> = any, T = StringParams> extends PluginBase {
4747
defaultLayout?: PluginDefaultLayout;
48-
renderer: (props: P, forwardedRef: React.RefObject<any>) => React.ReactNode;
49-
placeholderRenderer?: (props: P, forwardedRef: React.RefObject<any>) => React.ReactNode;
48+
renderer: (
49+
props: P,
50+
forwardedRef: ((instance: PluginRef) => void) | undefined,
51+
) => React.ReactNode;
52+
placeholderRenderer?: (
53+
props: P,
54+
forwardedRef: ((instance: PluginRef) => void) | undefined,
55+
) => React.ReactNode;
5056
}

0 commit comments

Comments
 (0)