Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make some component types compatible with react 18 #383

Merged
merged 3 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/components/Form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import styled from '../../utils/styled';
import { Prompt } from '../Prompt';
import { FormContext, FormContextType, FormValueNotifier, FormValueChange } from '../../contexts';
import { StandardProps } from '../../common';
import { ReactComponentDefaultProps } from '../../utils/react-18-compat';

export interface FormSubmitEvent {
/**
Expand Down Expand Up @@ -50,7 +51,7 @@ export interface FormValidationError {
error: React.ReactChild;
}

export interface FormProps<FormValues> extends StandardProps {
export interface FormProps<FormValues> extends StandardProps, ReactComponentDefaultProps {
feedm3 marked this conversation as resolved.
Show resolved Hide resolved
/**
* Shows the given message if the user wants to navigate
* with changes being made or renders custom component with message if provided.
Expand Down Expand Up @@ -351,6 +352,7 @@ export class Form<Values extends FormValuesData> extends React.Component<FormPro
prompt,
...rest
} = this.props;

const { changed } = this.state;
return (
<StyledForm {...rest} onSubmit={this.submit}>
Expand Down
3 changes: 2 additions & 1 deletion src/components/PaddedContainer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as React from 'react';
import styled, { css } from '../../utils/styled';
import { distance } from '../../distance';
import { ReactComponentDefaultProps } from '../../utils/react-18-compat';

export interface PaddedContainerProps {
export interface PaddedContainerProps extends ReactComponentDefaultProps {
/**
* Padding on top. Valid values: xxsmall, xsmall, small, medium, large, xlarge, xxlarge, xxxlarge.
*/
Expand Down
10 changes: 10 additions & 0 deletions src/utils/react-18-compat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as React from 'react';

/**
* This interface needs to be added to a property type that is used on `React.Component`.
*
* With React 18, React.Component and React.FC don't include children types anymore.
*/
export interface ReactComponentDefaultProps {
children?: React.ReactNode | undefined;
feedm3 marked this conversation as resolved.
Show resolved Hide resolved
}