diff --git a/package.json b/package.json index 3c3ea62027a..3f586f11f19 100644 --- a/package.json +++ b/package.json @@ -146,6 +146,7 @@ "@testing-library/react-16-17": "npm:@testing-library/react@^12.1.5", "@testing-library/react-hooks": "^7.0.2", "@testing-library/user-event": "^13.5.0", + "@types/cheerio": "^0.22.31", "@types/classnames": "^2.2.10", "@types/enzyme": "^3.10.5", "@types/jest": "^24.0.6", diff --git a/src-docs/src/components/guide_tabbed_page/guide_tabbed_page.tsx b/src-docs/src/components/guide_tabbed_page/guide_tabbed_page.tsx index fbdcbf40e2a..78c9fce25ed 100644 --- a/src-docs/src/components/guide_tabbed_page/guide_tabbed_page.tsx +++ b/src-docs/src/components/guide_tabbed_page/guide_tabbed_page.tsx @@ -1,4 +1,9 @@ -import React, { FunctionComponent, ReactNode, useContext } from 'react'; +import React, { + FunctionComponent, + PropsWithChildren, + ReactNode, + useContext, +} from 'react'; import { Switch, Route, @@ -17,19 +22,20 @@ import { import { LanguageSelector, ThemeContext } from '../with_theme'; import { GuideSection } from '../guide_section/guide_section'; -export type GuideTabbedPageProps = CommonProps & { - description?: ReactNode; - guidelines?: ReactNode; - intro?: ReactNode; - isBeta?: boolean; - isNew?: boolean; - notice?: ReactNode; - pages?: any; - rightSideItems?: ReactNode[]; - showThemeLanguageToggle?: boolean; - tabs?: any; - title: string; -}; +export type GuideTabbedPageProps = PropsWithChildren & + CommonProps & { + description?: ReactNode; + guidelines?: ReactNode; + intro?: ReactNode; + isBeta?: boolean; + isNew?: boolean; + notice?: ReactNode; + pages?: any; + rightSideItems?: ReactNode[]; + showThemeLanguageToggle?: boolean; + tabs?: any; + title: string; + }; export const GuideTabbedPage: FunctionComponent = ({ description, diff --git a/src-docs/src/views/elastic_charts/metric/metric_chart_grid.tsx b/src-docs/src/views/elastic_charts/metric/metric_chart_grid.tsx index e8fb53581fd..4508de3f285 100644 --- a/src-docs/src/views/elastic_charts/metric/metric_chart_grid.tsx +++ b/src-docs/src/views/elastic_charts/metric/metric_chart_grid.tsx @@ -149,6 +149,7 @@ export default () => { const chartBaseTheme = isDarkTheme ? DARK_THEME : LIGHT_THEME; return ( + {/* @ts-ignore @elastic/charts typings are not yet compatible with React 18 */} diff --git a/src-docs/src/views/elastic_charts/metric/metric_chart_grid_column.tsx b/src-docs/src/views/elastic_charts/metric/metric_chart_grid_column.tsx index d5c6bff2679..5e1810534fa 100644 --- a/src-docs/src/views/elastic_charts/metric/metric_chart_grid_column.tsx +++ b/src-docs/src/views/elastic_charts/metric/metric_chart_grid_column.tsx @@ -22,6 +22,7 @@ export default () => { const chartBaseTheme = isDarkTheme ? DARK_THEME : LIGHT_THEME; return ( + {/* @ts-ignore @elastic/charts typings are not yet compatible with React 18 */} { const chartBaseTheme = isDarkTheme ? DARK_THEME : LIGHT_THEME; return ( + {/* @ts-ignore @elastic/charts typings are not yet compatible with React 18 */} { No Data + {/* @ts-ignore @elastic/charts typings are not yet compatible with React 18 */} { Filtered Out + {/* @ts-ignore @elastic/charts typings are not yet compatible with React 18 */} { })); return ( + {/* @ts-ignore @elastic/charts typings are not yet compatible with React 18 */} { paddingSize="none" style={{ overflow: 'hidden', width: '200px' }} > + {/* @ts-ignore @elastic/charts typings are not yet compatible with React 18 */} { paddingSize="none" style={{ overflow: 'hidden', width: '200px' }} > + {/* @ts-ignore @elastic/charts typings are not yet compatible with React 18 */} { paddingSize="none" style={{ overflow: 'hidden', height: '100%', width: '100%' }} > + {/* @ts-ignore @elastic/charts typings are not yet compatible with React 18 */} { + {/* @ts-ignore @elastic/charts typings are not yet compatible with React 18 */} { return ( + {/* @ts-ignore @elastic/charts typings are not yet compatible with React 18 */} { @@ -23,19 +23,19 @@ export default () => { { value: 'errorPages', text: 'Page not found', - component: errorPages, + component: , source: errorPagesSource, }, { value: 'noPrivileges', text: 'No permission', - component: noPrivileges, + component: , source: noPrivilegesSource, }, { value: 'licenseUpgrade', text: 'License upgrade', - component: licenseUpgrade, + component: , source: licenseUpgradeSource, }, ]; diff --git a/src-docs/src/views/page_components/page.tsx b/src-docs/src/views/page_components/page.tsx index e26cb30003b..64e2b8a13e4 100644 --- a/src-docs/src/views/page_components/page.tsx +++ b/src-docs/src/views/page_components/page.tsx @@ -12,7 +12,7 @@ export default ({ content = <>, sideBar, ...rest -}: EuiPageProps & { +}: Omit & { content: ReactElement; sideBar?: ReactElement; }) => ( diff --git a/src-docs/src/views/resizable_container/resizable_container_reset_values.tsx b/src-docs/src/views/resizable_container/resizable_container_reset_values.tsx index 7d5ce5ece77..824a19e82bc 100644 --- a/src-docs/src/views/resizable_container/resizable_container_reset_values.tsx +++ b/src-docs/src/views/resizable_container/resizable_container_reset_values.tsx @@ -30,7 +30,7 @@ const defaultSizes = storedSizes || { export default () => { const [savedSizes, setSavedSizes] = useState(storedSizes); const [sizes, setSizes] = useState(defaultSizes); - const onPanelWidthChange = useCallback((newSizes) => { + const onPanelWidthChange = useCallback((newSizes: Record) => { setSizes((prevSizes: Record) => ({ ...prevSizes, ...newSizes, diff --git a/src-docs/src/views/tables/custom/custom.tsx b/src-docs/src/views/tables/custom/custom.tsx index 8f47e74a2a5..aad9499ad03 100644 --- a/src-docs/src/views/tables/custom/custom.tsx +++ b/src-docs/src/views/tables/custom/custom.tsx @@ -296,7 +296,7 @@ export default class extends Component<{}, State> { size="m" style={{ verticalAlign: 'text-top' }} />{' '} - {title} + {title as ReactNode} ), }, @@ -674,6 +674,7 @@ export default class extends Component<{}, State> { mobileOptions={{ header: column.label, ...column.mobileOptions, + render: column.mobileOptions?.render?.(item), }} > {child} diff --git a/src-docs/src/views/theme/typography/_typography_js.tsx b/src-docs/src/views/theme/typography/_typography_js.tsx index 0ae87c008e0..60c773239b2 100644 --- a/src-docs/src/views/theme/typography/_typography_js.tsx +++ b/src-docs/src/views/theme/typography/_typography_js.tsx @@ -217,6 +217,14 @@ export const FontScaleJS = () => { ); }; +interface FontScaleDetails { + id: typeof EuiThemeFontScales[number]; + value: string; + size: string; + lineHeight: string; + index: number; +} + export const FontScaleValuesJS = () => { const euiThemeContext = useEuiTheme(); const scaleKeys = EuiThemeFontScales; @@ -261,7 +269,7 @@ export const FontScaleValuesJS = () => { - tableLayout="auto" items={scaleKeys.map((scale, index) => { return { diff --git a/src-docs/src/views/theme/typography/_typography_sass.tsx b/src-docs/src/views/theme/typography/_typography_sass.tsx index 16b1a9b2c4f..abb08a2263d 100644 --- a/src-docs/src/views/theme/typography/_typography_sass.tsx +++ b/src-docs/src/views/theme/typography/_typography_sass.tsx @@ -165,12 +165,18 @@ export const FontWeightSass: FunctionComponent = ({ ); }; +interface FontWeightDetails { + id: typeof euiFontWeights[number]; + token: string; + value: number; +} + export const FontWeightValuesSass = () => { const values = useJsonVars(); return ( <> - items={euiFontWeights.map(function (weight) { return { id: weight, @@ -221,7 +227,7 @@ const euiFontSizes = [ 'euiFontSizeL', 'euiFontSizeXL', 'euiFontSizeXXL', -]; +] as const; export const FontScaleSass = () => { return ( @@ -243,12 +249,20 @@ export const FontScaleSass = () => { ); }; +interface FontSizesDetails { + id: typeof euiFontSizes[number]; + token: string; + mixin: string; + value: string; + index: number; +} + export const FontScaleValuesSass = () => { const values = useJsonVars(); return ( <> - items={euiFontSizes.map(function (size, index) { return { id: size, diff --git a/src/components/basic_table/in_memory_table.tsx b/src/components/basic_table/in_memory_table.tsx index 9c959c265f7..f03dacd5fef 100644 --- a/src/components/basic_table/in_memory_table.tsx +++ b/src/components/basic_table/in_memory_table.tsx @@ -423,7 +423,10 @@ export class EuiInMemoryTable extends Component< // EuiBasicTable returns the column's `field` instead of `name` on sort // and the column's `name` instead of `field` on pagination if (sortName) { - const sortColumn = findColumnByFieldOrName(this.props.columns, sortName); + const sortColumn = findColumnByFieldOrName( + this.props.columns, + sortName as ReactNode + ); if (sortColumn) { // Ensure sortName uses `name` sortName = sortColumn.name as keyof T; @@ -460,7 +463,7 @@ export class EuiInMemoryTable extends Component< this.setState({ pageIndex, pageSize, - sortName, + sortName: sortName as ReactNode, sortDirection, }); }; diff --git a/src/components/collapsible_nav_beta/collapsible_nav_beta.stories.tsx b/src/components/collapsible_nav_beta/collapsible_nav_beta.stories.tsx index a68c1ad8c9f..f8b4b366dc7 100644 --- a/src/components/collapsible_nav_beta/collapsible_nav_beta.stories.tsx +++ b/src/components/collapsible_nav_beta/collapsible_nav_beta.stories.tsx @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import React, { FunctionComponent } from 'react'; +import React, { FunctionComponent, PropsWithChildren } from 'react'; import type { Meta, StoryObj } from '@storybook/react'; import { EuiFlyoutBody, EuiFlyoutFooter } from '../flyout'; @@ -22,7 +22,9 @@ export default meta; type Story = StoryObj<{}>; // TODO: Make this a stateful component in upcoming EuiCollapsibleNavBeta work -const OpenCollapsibleNav: FunctionComponent<{}> = ({ children }) => { +const OpenCollapsibleNav: FunctionComponent = ({ + children, +}) => { return ( {}}> {children} diff --git a/src/components/date_picker/date_picker.tsx b/src/components/date_picker/date_picker.tsx index 38c7ab79633..4c41d516553 100644 --- a/src/components/date_picker/date_picker.tsx +++ b/src/components/date_picker/date_picker.tsx @@ -13,6 +13,7 @@ import React, { Ref, useState, useCallback, + RefCallback, } from 'react'; import classNames from 'classnames'; @@ -226,9 +227,12 @@ export const EuiDatePicker: FunctionComponent = ({ } // Set an internal ref on ReactDatePicker's `input` so we can set its :invalid state via useEuiValidatableControl - const [inputValidityRef, _setInputValidityRef] = useState(null); - const setInputValidityRef = useCallback((ref) => { - _setInputValidityRef(ref?.input); + const [inputValidityRef, _setInputValidityRef] = + useState(null); + const setInputValidityRef = useCallback< + RefCallback + >((ref) => { + _setInputValidityRef(ref?.input || null); }, []); useEuiValidatableControl({ isInvalid, controlEl: inputValidityRef }); const inputRefs = useCombinedRefs([inputRef, setInputValidityRef]); diff --git a/src/components/form/form.tsx b/src/components/form/form.tsx index a3d653f72d1..c37c47b87a5 100644 --- a/src/components/form/form.tsx +++ b/src/components/form/form.tsx @@ -66,7 +66,7 @@ export const EuiForm = forwardRef( [fullWidth] ); - const handleFocus = useCallback((node) => { + const handleFocus = useCallback((node: HTMLDivElement) => { node?.focus(); }, []); diff --git a/src/components/markdown_editor/markdown_editor.tsx b/src/components/markdown_editor/markdown_editor.tsx index 45551bfcfc1..658b3bc0dfd 100644 --- a/src/components/markdown_editor/markdown_editor.tsx +++ b/src/components/markdown_editor/markdown_editor.tsx @@ -259,7 +259,7 @@ export const EuiMarkdownEditor = forwardRef< const isPreviewing = viewMode === MODE_VIEWING; const isEditing = viewMode === MODE_EDITING; - const replaceNode = useCallback( + const replaceNode = useCallback( (position, next) => { const leading = value.substr(0, position.start.offset); const trailing = value.substr(position.end.offset); diff --git a/src/components/observer/resize_observer/resize_observer.tsx b/src/components/observer/resize_observer/resize_observer.tsx index 7b018789b5b..aa0b040ee14 100644 --- a/src/components/observer/resize_observer/resize_observer.tsx +++ b/src/components/observer/resize_observer/resize_observer.tsx @@ -76,7 +76,7 @@ export const useResizeObserver = ( // new state (and trigger a re-render) when the new dimensions actually differ const _currentDimensions = useRef(size); const setSize = useCallback( - (dimensions) => { + (dimensions: { width: number; height: number }) => { const doesWidthMatter = dimension !== 'height'; const doesHeightMatter = dimension !== 'width'; if ( diff --git a/src/components/popover/wrapping_popover.tsx b/src/components/popover/wrapping_popover.tsx index 8ea55d39ead..d193c0fa845 100644 --- a/src/components/popover/wrapping_popover.tsx +++ b/src/components/popover/wrapping_popover.tsx @@ -10,7 +10,8 @@ import React, { Component } from 'react'; import { EuiPopover, Props as EuiPopoverProps } from './popover'; import { EuiPortal } from '../portal'; -export interface EuiWrappingPopoverProps extends EuiPopoverProps { +export interface EuiWrappingPopoverProps + extends Omit { button: HTMLElement; } diff --git a/src/components/portal/portal.tsx b/src/components/portal/portal.tsx index 88fe1f0de86..7ddd1f69b29 100644 --- a/src/components/portal/portal.tsx +++ b/src/components/portal/portal.tsx @@ -11,7 +11,7 @@ * into portals. */ -import React, { Component, ReactNode } from 'react'; +import React, { Component, ContextType, ReactNode } from 'react'; import { createPortal } from 'react-dom'; import { EuiNestedThemeContext } from '../../services'; @@ -43,6 +43,7 @@ export interface EuiPortalProps { export class EuiPortal extends Component { static contextType = EuiNestedThemeContext; + declare context: ContextType; portalNode: HTMLDivElement | null = null; diff --git a/src/components/resizable_container/resizable_panel.test.tsx b/src/components/resizable_container/resizable_panel.test.tsx index c01b3a1467b..4742f56f8d0 100644 --- a/src/components/resizable_container/resizable_panel.test.tsx +++ b/src/components/resizable_container/resizable_panel.test.tsx @@ -6,7 +6,10 @@ * Side Public License, v 1. */ -import React, { FunctionComponent } from 'react'; +import React, { + FunctionComponent, + PropsWithChildren, +} from 'react'; import { render } from '@testing-library/react'; import { requiredProps } from '../../test/required_props'; import { shouldRenderCustomStyles } from '../../test/internal'; @@ -16,7 +19,7 @@ import { EuiResizablePanel } from './resizable_panel'; describe('EuiResizablePanel', () => { const mockRegistry = { panels: {}, resizers: {} }; - const wrapper: FunctionComponent = ({ children }) => ( + const wrapper: FunctionComponent = ({ children }) => ( {children} diff --git a/src/components/side_nav/side_nav_types.ts b/src/components/side_nav/side_nav_types.ts index 9e986ff8caa..15f2601af21 100644 --- a/src/components/side_nav/side_nav_types.ts +++ b/src/components/side_nav/side_nav_types.ts @@ -18,7 +18,7 @@ export interface EuiSideNavItemType extends Omit<_EuiSideNavItemButtonProps, 'children'>, Omit< _EuiSideNavItemProps, - 'isParent' | 'depth' | 'isOpen' | 'childrenOnly' + 'isParent' | 'depth' | 'isOpen' | 'childrenOnly' | 'items' > { /** * A value that is passed to React as the `key` for this item diff --git a/src/components/tabs/tabbed_content/tabbed_content.tsx b/src/components/tabs/tabbed_content/tabbed_content.tsx index 0a1146f9b72..99ed28a5bcc 100644 --- a/src/components/tabs/tabbed_content/tabbed_content.tsx +++ b/src/components/tabs/tabbed_content/tabbed_content.tsx @@ -37,7 +37,7 @@ interface EuiTabbedContentState { } export type EuiTabbedContentProps = CommonProps & - HTMLAttributes & { + Omit, 'autoFocus'> & { /** * When tabbing into the tabs, set the focus on `initial` for the first tab, * or `selected` for the currently selected tab. Best use case is for inside of diff --git a/src/components/timeline/timeline_item_icon.tsx b/src/components/timeline/timeline_item_icon.tsx index 8b6beac4a44..cd323c970c7 100644 --- a/src/components/timeline/timeline_item_icon.tsx +++ b/src/components/timeline/timeline_item_icon.tsx @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import React, { FunctionComponent, ReactNode } from 'react'; +import React, { FunctionComponent, isValidElement, ReactNode } from 'react'; import { IconType } from '../icon'; import { EuiAvatar } from '../avatar'; import { useEuiTheme } from '../../services'; @@ -37,12 +37,11 @@ export const EuiTimelineItemIcon: FunctionComponent< const ariaLabel = iconAriaLabel ? iconAriaLabel : ''; - const iconRender = - typeof icon === 'string' ? ( - - ) : ( - icon - ); + const iconRender = isValidElement(icon) ? ( + icon + ) : ( + + ); return (
diff --git a/src/components/tree_view/tree_view.tsx b/src/components/tree_view/tree_view.tsx index d1a63d53ea2..35eff6b403d 100644 --- a/src/components/tree_view/tree_view.tsx +++ b/src/components/tree_view/tree_view.tsx @@ -6,7 +6,12 @@ * Side Public License, v 1. */ -import React, { Component, HTMLAttributes, createContext } from 'react'; +import React, { + Component, + HTMLAttributes, + createContext, + ContextType, +} from 'react'; import classNames from 'classnames'; import { CommonProps } from '../common'; import { EuiI18n } from '../i18n'; @@ -110,8 +115,12 @@ export type EuiTreeViewProps = Omit< export class EuiTreeView extends Component { treeIdGenerator = htmlIdGenerator('euiTreeView'); + static contextType = EuiTreeViewContext; + declare context: ContextType; + isNested: boolean = !!this.context; + state: EuiTreeViewState = { openItems: this.props.expandByDefault ? this.props.items diff --git a/yarn.lock b/yarn.lock index 0d661bf87c3..8866de02a75 100755 --- a/yarn.lock +++ b/yarn.lock @@ -4446,7 +4446,7 @@ resolved "https://registry.yarnpkg.com/@types/cheerio/-/cheerio-0.22.8.tgz#5702f74f78b73e13f1eb1bd435c2c9de61a250d4" integrity sha512-LzF540VOFabhS2TR2yYFz2Mu/fTfkA+5AwYddtJbOJGwnYrr2e7fHadT7/Z3jNGJJdCRlO3ySxmW26NgRdwhNA== -"@types/cheerio@^0.22.22": +"@types/cheerio@^0.22.22", "@types/cheerio@^0.22.31": version "0.22.31" resolved "https://registry.yarnpkg.com/@types/cheerio/-/cheerio-0.22.31.tgz#b8538100653d6bb1b08a1e46dec75b4f2a5d5eb6" integrity sha512-Kt7Cdjjdi2XWSfrZ53v4Of0wG3ZcmaegFXjMmz9tfNrZSkzzo36G0AL1YqSdcIA78Etjt6E609pt5h1xnQkPUw==