Skip to content

Commit

Permalink
fix(GlobalStatus): enhance TypeScript definition types
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed May 31, 2023
1 parent c3c736b commit dc58836
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ export const GlobalStatusScrolling = () => (
export const GlobalStatusUpdate = () => (
<ComponentBox hideCode>
{() => {
const Context = React.createContext()
const Context = React.createContext(null)

const UpdateDemo = () => {
const [errorA, setErrorA] = React.useState()
const [errorB, setErrorB] = React.useState()
const [errorA, setErrorA] = React.useState(false)
const [errorB, setErrorB] = React.useState(false)

const [isVisible, setVisibility] = React.useState(false)

Expand Down Expand Up @@ -230,7 +230,7 @@ export const GlobalStatusUpdate = () => (
} = React.useContext(Context)

// Only to demonstrate the usage of an interceptor situation
const inst = React.useRef()
const inst = React.useRef(null)
React.useEffect(() => {
if (!inst.current) {
inst.current = GlobalStatus.create({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,58 @@ export interface GlobalStatusProps extends React.HTMLProps<HTMLElement> {
*/
on_hide?: (...args: any[]) => any;
}

export type GlobalStatusStatusId = string;

export type GlobalStatusAddProps = {
id: string;
status_id: GlobalStatusStatusId;
title?: string;
text: string;
item: string;
on_close: ({ status_id }: { status_id: GlobalStatusStatusId }) => void;
};

export type GlobalStatusUpdateProps = {
id: string;
text: string;
};

export type GlobalStatusRemoveProps = {
id: string;
status_id: GlobalStatusStatusId;
};

export type GlobalStatusInterceptorProps = {
id: string;
title: string;
text: string;
status_id: GlobalStatusStatusId;
show: boolean;
};

export type GlobalStatusInterceptorUpdateEvents = {
on_show?: () => void;
on_hide?: () => void;
on_close?: () => void;
show?: boolean;
};

export type GlobalStatusInterceptor = {
update: (props: GlobalStatusInterceptorUpdateEvents) => void;
remove: () => void;
};

export default class GlobalStatus extends React.Component<
GlobalStatusProps,
any
> {
static defaultProps: object;
static create: (
props: GlobalStatusInterceptorProps
) => GlobalStatusInterceptor;
static Add: (props: GlobalStatusAddProps) => JSX.Element;
static Update: (props: GlobalStatusUpdateProps) => JSX.Element;
static Remove: (props: GlobalStatusRemoveProps) => JSX.Element;
render(): JSX.Element;
}

0 comments on commit dc58836

Please sign in to comment.