From 49895d066b98ba5a3a69d388e6d5e780bc49ca94 Mon Sep 17 00:00:00 2001 From: supergrecko Date: Thu, 26 Dec 2019 21:55:13 +0100 Subject: [PATCH] EuiTabs: run ESLint --- src/components/tabs/tab.tsx | 4 +- src/components/tabs/tabbed_content/index.ts | 6 +- .../tabs/tabbed_content/tabbed_content.tsx | 95 +++++++++++-------- src/components/tabs/tabs.tsx | 41 ++++---- 4 files changed, 80 insertions(+), 66 deletions(-) diff --git a/src/components/tabs/tab.tsx b/src/components/tabs/tab.tsx index 05087aa34f12..b660321c93ac 100644 --- a/src/components/tabs/tab.tsx +++ b/src/components/tabs/tab.tsx @@ -54,7 +54,7 @@ export const EuiTab: FunctionComponent = ({ href={href} target={target} rel={secureRel} - {...rest as AnchorHTMLAttributes}> + {...(rest as AnchorHTMLAttributes)}> {children} ); @@ -67,7 +67,7 @@ export const EuiTab: FunctionComponent = ({ type="button" className={classes} disabled={disabled} - {...rest as ButtonHTMLAttributes}> + {...(rest as ButtonHTMLAttributes)}> {children} ); diff --git a/src/components/tabs/tabbed_content/index.ts b/src/components/tabs/tabbed_content/index.ts index b9f4c7a52e9b..25802ed30c42 100644 --- a/src/components/tabs/tabbed_content/index.ts +++ b/src/components/tabs/tabbed_content/index.ts @@ -1 +1,5 @@ -export { EuiTabbedContent, EuiTabbedContentTabDescriptor, EuiTabbedContentProps } from './tabbed_content'; +export { + EuiTabbedContent, + EuiTabbedContentTabDescriptor, + EuiTabbedContentProps, +} from './tabbed_content'; diff --git a/src/components/tabs/tabbed_content/tabbed_content.tsx b/src/components/tabs/tabbed_content/tabbed_content.tsx index 87932de29845..a37ca8fabd9b 100644 --- a/src/components/tabs/tabbed_content/tabbed_content.tsx +++ b/src/components/tabs/tabbed_content/tabbed_content.tsx @@ -1,10 +1,10 @@ -import React, { Component, createRef, HTMLAttributes, ReactNode } from 'react' +import React, { Component, createRef, HTMLAttributes, ReactNode } from 'react'; import { htmlIdGenerator } from '../../../services'; -import { EuiTabs, EuiTabsDisplaySizes, EuiTabsSizes } from '../tabs' +import { EuiTabs, EuiTabsDisplaySizes, EuiTabsSizes } from '../tabs'; import { EuiTab } from '../tab'; -import { CommonProps } from '../../common' +import { CommonProps } from '../../common'; const makeId = htmlIdGenerator(); @@ -24,49 +24,51 @@ interface EuiTabbedContentState { inFocus: boolean; } -export type EuiTabbedContentProps = CommonProps - & HTMLAttributes - & { - /** - * 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 - * overlay content like popovers or flyouts. - */ - autoFocus?: 'initial' | 'selected'; - /** - * Choose `default` or alternative `condensed` display styles - */ - display?: EuiTabsDisplaySizes; - /** - * Evenly stretches each tab to fill the horizontal space - */ - expand?: boolean; - /** - * Use this prop to set the initially selected tab while letting the tabbed content component - * control selection state internally - */ - initialSelectedTab?: EuiTabbedContentTabDescriptor; - onTabClick?: (selectedTab: EuiTabbedContentTabDescriptor) => void; - /** - * Use this prop if you want to control selection state within the owner component - */ - selectedTab?: EuiTabbedContentTabDescriptor; - size?: EuiTabsSizes; - /** - * Each tab needs id and content properties, so we can associate it with its panel for accessibility. - * The name property is also required to display to the user. - */ - tabs: Array -} +export type EuiTabbedContentProps = CommonProps & + HTMLAttributes & { + /** + * 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 + * overlay content like popovers or flyouts. + */ + autoFocus?: 'initial' | 'selected'; + /** + * Choose `default` or alternative `condensed` display styles + */ + display?: EuiTabsDisplaySizes; + /** + * Evenly stretches each tab to fill the horizontal space + */ + expand?: boolean; + /** + * Use this prop to set the initially selected tab while letting the tabbed content component + * control selection state internally + */ + initialSelectedTab?: EuiTabbedContentTabDescriptor; + onTabClick?: (selectedTab: EuiTabbedContentTabDescriptor) => void; + /** + * Use this prop if you want to control selection state within the owner component + */ + selectedTab?: EuiTabbedContentTabDescriptor; + size?: EuiTabsSizes; + /** + * Each tab needs id and content properties, so we can associate it with its panel for accessibility. + * The name property is also required to display to the user. + */ + tabs: EuiTabbedContentTabDescriptor[]; + }; -export class EuiTabbedContent extends Component { +export class EuiTabbedContent extends Component< + EuiTabbedContentProps, + EuiTabbedContentState +> { static defaultProps = { autoFocus: 'initial', }; private readonly rootId = makeId(); - private readonly divRef = createRef() + private readonly divRef = createRef(); constructor(props: EuiTabbedContentProps) { super(props); @@ -91,14 +93,20 @@ export class EuiTabbedContent extends Component tab.id === this.state.selectedTabId); + tabs.find( + (tab: EuiTabbedContentTabDescriptor) => + tab.id === this.state.selectedTabId + ); const { content: selectedTabContent, id: selectedTabId } = selectedTab!; diff --git a/src/components/tabs/tabs.tsx b/src/components/tabs/tabs.tsx index ef05ed8bc2f4..3c27d57fad52 100644 --- a/src/components/tabs/tabs.tsx +++ b/src/components/tabs/tabs.tsx @@ -1,13 +1,13 @@ -import React, { HTMLAttributes, PropsWithChildren } from 'react' +import React, { HTMLAttributes, PropsWithChildren } from 'react'; import classNames from 'classnames'; -import { CommonProps, keysOf } from '../common' +import { CommonProps, keysOf } from '../common'; const displayToClassNameMap = { condensed: 'euiTabs--condensed', default: null, }; -export const DISPLAYS = keysOf(displayToClassNameMap) +export const DISPLAYS = keysOf(displayToClassNameMap); export type EuiTabsDisplaySizes = keyof typeof displayToClassNameMap; @@ -16,24 +16,23 @@ const sizeToClassNameMap = { m: null, }; -export const SIZES = keysOf(sizeToClassNameMap) - -export type EuiTabsSizes = keyof typeof sizeToClassNameMap - -export type EuiTabsProps = CommonProps - & HTMLAttributes - & { - /** - * Choose `default` or alternative `condensed` display styles - */ - display?: EuiTabsDisplaySizes; - /** - * Evenly stretches each tab to fill the - * horizontal space - */ - expand?: boolean; - size?: EuiTabsSizes -} +export const SIZES = keysOf(sizeToClassNameMap); + +export type EuiTabsSizes = keyof typeof sizeToClassNameMap; + +export type EuiTabsProps = CommonProps & + HTMLAttributes & { + /** + * Choose `default` or alternative `condensed` display styles + */ + display?: EuiTabsDisplaySizes; + /** + * Evenly stretches each tab to fill the + * horizontal space + */ + expand?: boolean; + size?: EuiTabsSizes; + }; export const EuiTabs = ({ children,