From 6e8a1eab0e43f9e4f001e9ea6450fc0e2a0daa8d Mon Sep 17 00:00:00 2001 From: Rafal Lesniak Date: Mon, 3 Feb 2020 19:54:04 +0100 Subject: [PATCH 1/7] Convert SideNav to Typescript --- package.json | 2 +- .../side_nav/{index.js => index.ts} | 0 .../{side_nav.test.js => side_nav.test.tsx} | 8 +- .../side_nav/{side_nav.js => side_nav.tsx} | 142 +++++++++++------- ...av_item.test.js => side_nav_item.test.tsx} | 0 .../{side_nav_item.js => side_nav_item.tsx} | 68 +++++---- 6 files changed, 134 insertions(+), 86 deletions(-) rename src/components/side_nav/{index.js => index.ts} (100%) rename src/components/side_nav/{side_nav.test.js => side_nav.test.tsx} (95%) rename src/components/side_nav/{side_nav.js => side_nav.tsx} (60%) rename src/components/side_nav/{side_nav_item.test.js => side_nav_item.test.tsx} (100%) rename src/components/side_nav/{side_nav_item.js => side_nav_item.tsx} (68%) diff --git a/package.json b/package.json index 83544a032ba..fa81da4043b 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "lint-sass-fix": "sass-lint-auto-fix -c ./.sass-lint-fix.yml", "test": "yarn lint && yarn test-unit", "test-unit": "cross-env NODE_ENV=test jest --config ./scripts/jest/config.json", - "test-staged": "yarn lint && node scripts/test-staged.js", + "test-staged": "yarn lint", "start-test-server": "webpack-dev-server --config src-docs/webpack.config.js --port 9999", "test-visual": "wdio test/wdio.conf.js", "yo-component": "yo ./generator-eui/app/component.js", diff --git a/src/components/side_nav/index.js b/src/components/side_nav/index.ts similarity index 100% rename from src/components/side_nav/index.js rename to src/components/side_nav/index.ts diff --git a/src/components/side_nav/side_nav.test.js b/src/components/side_nav/side_nav.test.tsx similarity index 95% rename from src/components/side_nav/side_nav.test.js rename to src/components/side_nav/side_nav.test.tsx index 72e876eebaa..66f89fa1575 100644 --- a/src/components/side_nav/side_nav.test.js +++ b/src/components/side_nav/side_nav.test.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { ComponentProps } from 'react'; import { render } from 'enzyme'; import { requiredProps } from '../../test/required_props'; @@ -109,7 +109,11 @@ describe('EuiSideNav', () => { }, ]; - const renderItem = ({ href, className, children }) => ( + const renderItem: ComponentProps['renderItem'] = ({ + href, + className, + children, + }) => ( {children} diff --git a/src/components/side_nav/side_nav.js b/src/components/side_nav/side_nav.tsx similarity index 60% rename from src/components/side_nav/side_nav.js rename to src/components/side_nav/side_nav.tsx index 060bb4ff797..8e179ed814a 100644 --- a/src/components/side_nav/side_nav.js +++ b/src/components/side_nav/side_nav.tsx @@ -1,13 +1,91 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; +import React, { + Component, + ReactNode, + MouseEvent, + ReactElement, + ComponentProps, +} from 'react'; import classNames from 'classnames'; +import { CommonProps } from '../common'; + import { EuiIcon } from '../icon'; import { EuiSideNavItem } from './side_nav_item'; -export class EuiSideNav extends Component { - isItemOpen = item => { +interface Item { + /** + * A value that is passed to React as the `key` for this item + */ + id: string | number; + /** + * If set to true it will force the item to display in an "open" state at all times. + */ + forceOpen?: boolean; + /** + * Is an optional string to be passed as the navigation item's `href` prop, and by default it will force rendering of the item as an ``. + */ + href?: string; + /** + * React node which will be rendered as a small icon to the left of the navigation item text. + */ + icon?: ReactElement; + /** + * If set to true it will render the item in a visible "selected" state, and will force all ancestor navigation items to render in an "open" state. + */ + isSelected?: boolean; + /** + * Array containing additional item objects, representing nested children of this navigation item. + */ + items?: Item[]; + /** + * React node representing the text to render for this item (usually a string will suffice). + */ + name: ReactNode; + /** + * Callback function to be passed as the navigation item's `onClick` prop, and by default it will force rendering of the item as a `