Skip to content

Commit 850cb36

Browse files
committed
improve typing
1 parent fd60d16 commit 850cb36

File tree

6 files changed

+41
-41
lines changed

6 files changed

+41
-41
lines changed

components/dash-core-components/src/components/Tabs.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {has, isNil} from 'ramda';
44
import LoadingElement from '../utils/_LoadingElement';
55
import {PersistedProps, PersistenceTypes, TabProps, TabsProps} from '../types';
66
import './css/tabs.css';
7-
import {DashComponent} from '@dash-renderer/types/component';
7+
import {DashComponent} from '@dash-renderer/types';
88

99
interface EnhancedTabProps extends TabProps {
1010
selected: boolean;

components/dash-core-components/src/types.ts

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
import React from 'react';
2-
import {DashComponent} from '@dash-renderer/types/component';
3-
import ExternalWrapper from '@dash-renderer/wrapper/ExternalWrapper';
4-
import {useDashContext} from '@dash-renderer/wrapper/DashContext';
5-
6-
declare global {
7-
interface Window {
8-
dash_component_api: {
9-
useDashContext: typeof useDashContext;
10-
ExternalWrapper: typeof ExternalWrapper;
11-
};
12-
}
13-
}
2+
import {BaseDashProps, DashComponent} from '@dash-renderer/types';
143

154
export enum PersistenceTypes {
165
'local' = 'local',
@@ -22,14 +11,7 @@ export enum PersistedProps {
2211
'value' = 'value',
2312
}
2413

25-
export interface BaseComponentProps<T> {
26-
/**
27-
* The ID of this component, used to identify dash components
28-
* in callbacks. The ID needs to be unique across all of the
29-
* components in an app.
30-
*/
31-
id?: string;
32-
14+
export interface BaseDccProps<T> extends BaseDashProps {
3315
/**
3416
* Additional CSS class for the root DOM node
3517
*/
@@ -122,7 +104,7 @@ export type SliderTooltip = {
122104
transform?: string;
123105
};
124106

125-
export interface SliderProps extends BaseComponentProps<SliderProps> {
107+
export interface SliderProps extends BaseDccProps<SliderProps> {
126108
/**
127109
* Minimum allowed value of the slider
128110
*/
@@ -209,7 +191,7 @@ export interface SliderProps extends BaseComponentProps<SliderProps> {
209191
verticalHeight?: number;
210192
}
211193

212-
export interface RangeSliderProps extends BaseComponentProps<RangeSliderProps> {
194+
export interface RangeSliderProps extends BaseDccProps<RangeSliderProps> {
213195
/**
214196
* Minimum allowed value of the slider
215197
*/
@@ -356,7 +338,7 @@ export type OptionsArray = (OptionValue | DetailedOption)[];
356338
*/
357339
export type OptionsDict = Record<string, string>;
358340

359-
export interface DropdownProps extends BaseComponentProps<DropdownProps> {
341+
export interface DropdownProps extends BaseDccProps<DropdownProps> {
360342
/**
361343
* An array of options {label: [string|number], value: [string|number]},
362344
* an optional disabled field can be used for each option
@@ -439,7 +421,7 @@ export interface DropdownProps extends BaseComponentProps<DropdownProps> {
439421
};
440422
}
441423

442-
export interface ChecklistProps extends BaseComponentProps<ChecklistProps> {
424+
export interface ChecklistProps extends BaseDccProps<ChecklistProps> {
443425
/**
444426
* An array of options
445427
*/
@@ -484,7 +466,7 @@ export interface ChecklistProps extends BaseComponentProps<ChecklistProps> {
484466
labelClassName?: string;
485467
}
486468

487-
export interface RadioItemsProps extends BaseComponentProps<RadioItemsProps> {
469+
export interface RadioItemsProps extends BaseDccProps<RadioItemsProps> {
488470
/**
489471
* An array of options
490472
*/
@@ -529,7 +511,7 @@ export interface RadioItemsProps extends BaseComponentProps<RadioItemsProps> {
529511
labelClassName?: string;
530512
}
531513

532-
export interface TextAreaProps extends BaseComponentProps<TextAreaProps> {
514+
export interface TextAreaProps extends BaseDccProps<TextAreaProps> {
533515
/**
534516
* The value of the textarea
535517
*/
@@ -753,7 +735,7 @@ export interface TooltipProps {
753735
setProps: (props: Partial<TooltipProps>) => void;
754736
}
755737

756-
export interface LoadingProps extends BaseComponentProps<LoadingProps> {
738+
export interface LoadingProps extends BaseDccProps<LoadingProps> {
757739
/**
758740
* Array that holds components to render
759741
*/
@@ -837,7 +819,7 @@ export interface LoadingProps extends BaseComponentProps<LoadingProps> {
837819
custom_spinner?: React.ReactNode;
838820
}
839821

840-
export interface TabsProps extends BaseComponentProps<TabsProps> {
822+
export interface TabsProps extends BaseDccProps<TabsProps> {
841823
/**
842824
* The value of the currently selected Tab
843825
*/
@@ -901,7 +883,7 @@ export interface TabsProps extends BaseComponentProps<TabsProps> {
901883
// Note a quirk in how this extends the BaseComponentProps: `setProps` is shared
902884
// with `TabsProps` (plural!) due to how tabs are implemented. This is
903885
// intentional.
904-
export interface TabProps extends BaseComponentProps<TabsProps> {
886+
export interface TabProps extends BaseDccProps<TabsProps> {
905887
/**
906888
* The tab's label
907889
*/

dash/dash-renderer/src/dashApi.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,10 @@ function getLayout(componentPathOrId: DashLayoutPath | string): any {
3030
}
3131
}
3232

33-
(window as any).dash_component_api = {
33+
window.dash_component_api = {
3434
ExternalWrapper,
3535
DashContext,
3636
useDashContext,
3737
getLayout,
3838
stringifyId
3939
};
40-
41-
export interface DashComponentApi {
42-
ExternalWrapper: typeof ExternalWrapper;
43-
DashContext: typeof DashContext;
44-
useDashContext: typeof useDashContext;
45-
getLayout: typeof getLayout;
46-
stringifyId: typeof stringifyId;
47-
}

dash/dash-renderer/src/types/component.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1+
import {
2+
DashContext,
3+
DashContextProviderProps,
4+
useDashContext
5+
} from '../wrapper/DashContext';
6+
import ExternalWrapper from '../wrapper/ExternalWrapper';
7+
import {stringifyId} from '../actions/dependencies';
8+
19
export type BaseDashProps = {
210
id?: string;
311
componentPath?: DashLayoutPath;
412
[key: string]: any;
513
};
614

15+
export interface DashComponentApi {
16+
ExternalWrapper: typeof ExternalWrapper;
17+
DashContext: typeof DashContext;
18+
useDashContext: typeof useDashContext;
19+
getLayout: (componentPathOrId: DashLayoutPath | string) => DashComponent;
20+
stringifyId: typeof stringifyId;
21+
}
22+
723
export type DashComponent = {
824
type: string;
925
namespace: string;
10-
props: BaseDashProps;
26+
props: DashContextProviderProps & BaseDashProps;
1127
};
1228

1329
export type UpdatePropsPayload = {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {DashComponentApi} from './component';
2+
3+
declare global {
4+
interface Window {
5+
dash_component_api: DashComponentApi;
6+
}
7+
}
8+
9+
export * from './component';
10+
export * from './callbacks';

dash/dash-renderer/src/wrapper/DashContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type DashContextType = {
4040

4141
export const DashContext = React.createContext<DashContextType>({} as any);
4242

43-
type DashContextProviderProps = {
43+
export type DashContextProviderProps = {
4444
children: JSX.Element;
4545
componentPath: DashLayoutPath;
4646
};

0 commit comments

Comments
 (0)