Skip to content

Commit

Permalink
fix: issue with typings for react
Browse files Browse the repository at this point in the history
  • Loading branch information
nmerget committed Mar 28, 2024
1 parent c8cf524 commit e37f7d6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
8 changes: 8 additions & 0 deletions packages/components/scripts/post-build/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const overwriteEvents = (tmp) => {
'export type ChangeEvent<T> = Event;',
'export type ChangeEvent<T> = React.ChangeEvent<T>;'
);
modelFileContent = modelFileContent.replace(
'export type InputEvent<T> = Event;',
'export type InputEvent<T> = React.FormEvent<T>;'
);
modelFileContent = modelFileContent.replace(
'export type InteractionEvent<T> = FocusEvent;',
'export type InteractionEvent<T> = React.FocusEvent<T>;'
Expand Down Expand Up @@ -46,6 +50,10 @@ module.exports = (tmp) => {
from: /= useState/g,
to: '= useState<any>'
},
{
from: `handleFrameworkEvent(this`,
to: `// handleFrameworkEvent(this`
},
{
from: ` } from "react"`,
to: `, forwardRef, HTMLProps } from "react"`
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/components/input/input.lite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
DEFAULT_MESSAGE_ID_SUFFIX
} from '../../shared/constants';
import {
InputEvent,
ChangeEvent,
InteractionEvent,
KeyValueType
Expand All @@ -36,7 +37,7 @@ export default function DBInput(props: DBInputProps) {
label: DEFAULT_LABEL,
placeholder: ' '
},
handleInput: (event: ChangeEvent<HTMLInputElement>) => {
handleInput: (event: InputEvent<HTMLInputElement>) => {
if (props.onInput) {
props.onInput(event);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/components/textarea/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface DBTextareaDefaultProps {
export type DBTextareaProps = DBTextareaDefaultProps &
ChangeEventProps<HTMLTextAreaElement> &
DefaultVariantProps &
InputEventProps<HTMLInputElement> &
InputEventProps<HTMLTextAreaElement> &
FocusEventProps<HTMLTextAreaElement> &
FormProps &
GlobalProps &
Expand All @@ -52,7 +52,7 @@ export interface DBTextareaDefaultState {}

export type DBTextareaState = DBTextareaDefaultState &
ChangeEventState<HTMLTextAreaElement> &
InputEventState<HTMLInputElement> &
InputEventState<HTMLTextAreaElement> &
FocusEventState<HTMLTextAreaElement> &
FormState &
GlobalState;
6 changes: 3 additions & 3 deletions packages/components/src/components/textarea/textarea.lite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
DEFAULT_LABEL,
DEFAULT_MESSAGE_ID_SUFFIX
} from '../../shared/constants';
import { ChangeEvent, InteractionEvent } from '../../shared/model';
import { ChangeEvent, InputEvent, InteractionEvent } from '../../shared/model';
import { handleFrameworkEvent } from '../../utils/form-components';

useMetadata({
Expand All @@ -31,7 +31,7 @@ export default function DBTextarea(props: DBTextareaProps) {
placeholder: ' ',
rows: '4'
},
handleInput: (event: ChangeEvent<HTMLInputElement>) => {
handleInput: (event: InputEvent<HTMLTextAreaElement>) => {
if (props.onInput) {
props.onInput(event);
}
Expand All @@ -40,7 +40,7 @@ export default function DBTextarea(props: DBTextareaProps) {
props.input(event);
}
},
handleChange: (event: ChangeEvent<HTMLInputElement>) => {
handleChange: (event: ChangeEvent<HTMLTextAreaElement>) => {
if (props.onChange) {
props.onChange(event);
}
Expand Down
9 changes: 5 additions & 4 deletions packages/components/src/shared/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,16 +408,17 @@ export type ItemClickState = {
handleItemClick: (id: string) => void;
};

export type ChangeEvent<T> = Event;
export type InputEvent<T> = Event;
export type InputEventProps<T> = {
input?: (event: ChangeEvent<T>) => void;
onInput?: (event: ChangeEvent<T>) => void;
input?: (event: InputEvent<T>) => void;
onInput?: (event: InputEvent<T>) => void;
};

export type InputEventState<T> = {
handleInput: (event: ChangeEvent<T>) => void;
handleInput: (event: InputEvent<T>) => void;
};

export type ChangeEvent<T> = Event;
export type ChangeEventProps<T> = {
change?: (event: ChangeEvent<T>) => void;
onChange?: (event: ChangeEvent<T>) => void;
Expand Down

0 comments on commit e37f7d6

Please sign in to comment.