Skip to content

Commit b9ab67d

Browse files
Merge pull request #214 from skyflowapi/himanshu/SK-2110-identify-and-fix-gaps-in-typescript-public-interfaces-react-sdk
SK-2110: fix typescript types in interfaces for react sdk
2 parents 418858f + 992046f commit b9ab67d

15 files changed

Lines changed: 124 additions & 47 deletions

File tree

samples/SkyflowElements/src/components/CardBrandChoice/index.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ const CardBrandChoice = () => {
3232
invalid: {
3333
color: '#f44336',
3434
},
35-
dropdownIcon: {
36-
// Pass styles for the dropdown icon.
37-
},
38-
dropdown: {
39-
// Pass styles for the card choice dropdown.
40-
},
4135
},
4236
labelStyles: {
4337
base: {

samples/SkyflowElements/src/components/ComposableElements/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const ComposableElements = () => {
1515
base: {
1616
fontFamily: 'Inter',
1717
fontStyle: 'normal',
18-
fontWeight: 400,
18+
fontWeight: '400',
1919
fontSize: '14px',
2020
lineHeight: '21px',
2121
color: '#1d1d1d',
@@ -32,7 +32,7 @@ const ComposableElements = () => {
3232
base: {
3333
fontFamily: 'Inter',
3434
fontStyle: 'normal',
35-
fontWeight: 400,
35+
fontWeight: '400',
3636
fontSize: '14px',
3737
lineHeight: '21px',
3838
},

samples/SkyflowElements/src/components/DynamicComposableElements/index.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,22 @@ const DynamicComposableElements = () => {
2222
base: {
2323
fontFamily: 'Inter',
2424
fontStyle: 'normal',
25-
fontWeight: 400,
25+
fontWeight: '400',
2626
fontSize: '14px',
2727
lineHeight: '21px',
2828
color: '#1d1d1d',
2929
padding: '0px 16px'
3030
},
3131
complete: {
3232
color: '#4caf50',
33-
}
34-
35-
},
36-
empty: {
37-
},
38-
focus: {
39-
},
40-
invalid: {
41-
color: '#f44336',
33+
},
34+
empty: {
35+
},
36+
focus: {
37+
},
38+
invalid: {
39+
color: '#f44336',
40+
},
4241
},
4342
});
4443

src/common/index.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Copyright (c) 2022 Skyflow, Inc.
3+
*/
4+
import type {
5+
ContainerOptions,
6+
ErrorTextStyles,
7+
LabelStyles,
8+
InputStyles,
9+
} from 'skyflow-js/types/utils/common';
10+
11+
export type {
12+
ContainerOptions,
13+
ErrorTextStyles,
14+
LabelStyles,
15+
InputStyles,
16+
};
17+
18+
export interface StylesConfig {
19+
inputStyles?: InputStyles;
20+
labelStyles?: LabelStyles;
21+
errorTextStyles?: ErrorTextStyles;
22+
}
23+
24+
export interface CollectElementState {
25+
elementType: string;
26+
isEmpty: boolean;
27+
isFocused: boolean;
28+
isValid: boolean;
29+
isComplete: boolean;
30+
value?: string;
31+
}
32+
33+
export interface ElementClassesConfig {
34+
inputStyles?: InputStyles;
35+
labelStyles?: LabelStyles;
36+
errorTextStyles?: ErrorTextStyles;
37+
}
38+
39+
export interface EventCallback {
40+
priority: boolean;
41+
callback: EventCallbackFunction;
42+
}
43+
44+
export type EventCallbackFunction = (...args: any[]) => void;
45+
46+
export interface ComposableSubmitResponse {
47+
records?: Array<{
48+
table: string;
49+
fields: Record<string, any>;
50+
}>;
51+
errors?: Array<{
52+
code: number;
53+
description: string;
54+
}>;
55+
}
56+

src/elements/ComposableContainer/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import EventEmitter from '../../utils/event-emitter'
77
import ComposableContainer from 'skyflow-js/types/core/external/collect/compose-collect-container';
88
import Skyflow from 'skyflow-js'
99
import { v4 as uuid } from 'uuid';
10+
import { ComposableSubmitResponse } from '../../common';
1011
export interface IComposableContainer {
1112
children?: React.ReactNode
1213
container: ComposableContainer
1314
id?: string
14-
onSubmit?: () => void
15+
onSubmit?: (response?: ComposableSubmitResponse) => void
1516
}
1617

1718
const ComposableContainerComponent: FC<IComposableContainer> = ({ children, ...props }) => {
@@ -24,7 +25,7 @@ const ComposableContainerComponent: FC<IComposableContainer> = ({ children, ...p
2425
setCurrentCount((prev) => prev + 1);
2526
});
2627

27-
const iterateOverChildren = (children) => {
28+
const iterateOverChildren = (children: React.ReactNode) => {
2829
return React.Children.map(children, (child) => {
2930
if (!React.isValidElement(child)) return child;
3031
return React.cloneElement(child, { eventEmitter: eventEmitter } as Partial<unknown>)

src/elements/FileRenderElement/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
import React, { FC } from 'react'
55
import { FileRenderElements, SkyflowRenderElementProps, SkyflowRenderElementRef } from '..'
66
import { v4 as uuid } from 'uuid';
7+
import RevealElementType from 'skyflow-js/types/core/external/reveal/reveal-element';
78
import useUpdateFileRenderElement from '../../hooks/UpdateFileRenderElement';
89
import useErrorOverride from '../../hooks/OverrideError';
910

11+
// eslint-disable-next-line react/display-name
1012
const FileRenderElement = React.forwardRef<SkyflowRenderElementRef, SkyflowRenderElementProps>(({ ...props }, ref) => {
1113
const uniqueDivId = React.useRef(uuid());
12-
const [element, setElement] = React.useState<any>(null);
14+
const [element, setElement] = React.useState<RevealElementType | null>(null);
1315

1416
useErrorOverride(element, ref, props);
1517

src/elements/RevealElement/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
/*
22
Copyright (c) 2022 Skyflow, Inc.
33
*/
4-
import React, { FC } from 'react'
5-
import { SkyflowCollectElementRef, SkyflowRevealElementProps, SkyflowRevealElementRef } from '..'
4+
import React from 'react'
5+
import { SkyflowRevealElementProps, SkyflowRevealElementRef } from '..'
66
import { v4 as uuid } from 'uuid';
77
import Skyflow from 'skyflow-js';
8+
import RevealElementType from 'skyflow-js/types/core/external/reveal/reveal-element';
89
import useUpdateRevealElement from '../../hooks/UpdateRevealElement';
910
import useErrorOverride from '../../hooks/OverrideError';
1011

12+
// eslint-disable-next-line react/display-name
1113
const RevealElement = React.forwardRef<SkyflowRevealElementRef, SkyflowRevealElementProps>( ({ ...props }, ref) => {
1214
const uniqueDivId = React.useRef(uuid());
13-
const [element,setElement] = React.useState<any>(null);
15+
const [element,setElement] = React.useState<RevealElementType | null>(null);
1416

1517
useErrorOverride(element, ref, props);
1618

src/elements/index.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import CollectContainer from 'skyflow-js/types/core/external/collect/collect-con
88
import ComposableContainer from 'skyflow-js/types/core/external/collect/compose-collect-container'
99
import RevealContainer from 'skyflow-js/types/core/external/reveal/reveal-container'
1010
import { IValidationRule, RedactionType } from 'skyflow-js/types/utils/common'
11+
import { ElementClassesConfig, CollectElementState } from '../common'
12+
import EventEmitter from '../utils/event-emitter'
1113

1214
export const FileRenderElements = {};
1315
export const CollectElements = {};
@@ -22,13 +24,13 @@ export interface SkyflowCollectElementProps {
2224
placeholder?: string
2325
errorText?: string
2426
validations?: IValidationRule[] | undefined
25-
classes?: Record<string, unknown>
27+
classes?: ElementClassesConfig
2628
options?: ICollectElementOptions
27-
onChange?: (state: unknown) => void
28-
onFocus?: (state: unknown) => void
29-
onBlur?: (state: unknown) => void
30-
onReady?: (state: unknown) => void
31-
eventEmitter?:any
29+
onChange?: (state: CollectElementState) => void
30+
onFocus?: (state: CollectElementState) => void
31+
onBlur?: (state: CollectElementState) => void
32+
onReady?: (state: CollectElementState) => void
33+
eventEmitter?: EventEmitter
3234
skyflowID?:string
3335
ref?: {current: SkyflowCollectElementRef | null};
3436
// TODO ref
@@ -44,7 +46,7 @@ export interface SkyflowRevealElementProps {
4446
id?: string
4547
label?: string
4648
altText?: string
47-
classes?: Record<string, unknown>
49+
classes?: ElementClassesConfig
4850
options?: IRevealOptions
4951
redaction?: RedactionType
5052
ref?: {current: SkyflowRevealElementRef | null}
@@ -58,7 +60,7 @@ export interface SkyflowRenderElementProps {
5860
container: RevealContainer
5961
id: string
6062
altText?: string
61-
classes?: Record<string, unknown>
63+
classes?: ElementClassesConfig
6264
skyflowID:string
6365
table: string
6466
column: string

src/hooks/CollectContainer/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import React from 'react'
55
import Skyflow from 'skyflow-js'
66
import CollectContainer from 'skyflow-js/types/core/external/collect/collect-container'
7-
7+
import { ContainerOptions } from '../../common'
88
import { useSkyflowClient } from '../../core/hook'
99

10-
const useCollectContainer = (options?): CollectContainer => {
10+
const useCollectContainer = (options?: ContainerOptions): CollectContainer => {
1111
const { skyflow } = useSkyflowClient()
1212

1313
return React.useMemo(

src/hooks/ComposableContainer/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import React from 'react'
55
import Skyflow from 'skyflow-js'
66
import ComposableContainer from 'skyflow-js/types/core/external/collect/compose-collect-container'
7-
7+
import { ContainerOptions } from '../../common'
88
import { useSkyflowClient } from '../../core/hook'
99

10-
const useComposableContainer = (options) => {
10+
const useComposableContainer = (options: ContainerOptions) => {
1111
const { skyflow } = useSkyflowClient()
1212
return React.useMemo(
1313
() => skyflow?.container(Skyflow.ContainerType.COMPOSABLE, options) as ComposableContainer,

0 commit comments

Comments
 (0)