diff --git a/packages/patternfly-4/react-charts/src/components/ChartDonutUtilization/ChartDonutThreshold.tsx b/packages/patternfly-4/react-charts/src/components/ChartDonutUtilization/ChartDonutThreshold.tsx index 5e3f7343830..3d7bebbb9fb 100644 --- a/packages/patternfly-4/react-charts/src/components/ChartDonutUtilization/ChartDonutThreshold.tsx +++ b/packages/patternfly-4/react-charts/src/components/ChartDonutUtilization/ChartDonutThreshold.tsx @@ -392,6 +392,7 @@ export const ChartDonutThreshold: React.FunctionComponent { + // Returns computed data representing pie chart slices const getComputedData = () => { - const computedData = []; - const datum = getData(data); - let prevYVal = 0; - datum.forEach((dataPoint: {_x?: any, _y: any}) => { - computedData.push({ x: dataPoint._x, y: dataPoint._y ? Math.abs(dataPoint._y - prevYVal) : 0 }); - prevYVal = dataPoint._y; - }); - computedData.push({ y: prevYVal ? Math.abs(100 - prevYVal) : 0 }); - return computedData; - }; + // Format and sort data. Sorting ensures thresholds are displayed in the correct order and simplifies calculations. + const datum = Data.formatData(data, {x, y, ...rest}, ['x', 'y']).sort((a: any,b: any) => a._y - b._y); - const getData = (datum: any[]) => { - const accessorTypes = ['x', 'y']; - return Data.formatData(datum, { x, y, ...rest }, accessorTypes); + // Data must be offset so that the sum of all data point y-values (including the final slice) == 100. + const [prev, computedData] = datum.reduce((acc: [number, any], dataPoint: {_x: number | string, _y: number}) => { + return [ + dataPoint._y, // Set the previous value to current y value + [ + ...acc[1], + { + x: dataPoint._x, // Conditionally add x property only if it is in the original data object + y: dataPoint._y - acc[0] // Must be offset by previous value + } + ] + ]; + }, [0, []]); + + return [ + ...computedData, + { + y: prev ? (100 - prev) : 0 + } + ]; }; // Returns the horizontal shift for the dynamic utilization donut cart @@ -449,24 +459,27 @@ export const ChartDonutThreshold: React.FunctionComponent React.Children.toArray(children).map(child => { if (child.props) { - const datum = getData([{ ...child.props.data }]); - const orientation = child.props.donutOrientation || donutOrientation; + const {data: childData, ...childProps} = child.props; + const datum = Data.formatData([childData], childProps, ['x', 'y']); // Format child data independently of this component's props + const orientation = childProps.donutOrientation || donutOrientation; const dynamicTheme = - child.props.theme || - getDonutThresholdDynamicTheme(child.props.themeColor || themeColor, - child.props.themeVariant || themeVariant); + childProps.theme || + getDonutThresholdDynamicTheme(childProps.themeColor || themeColor, + childProps.themeVariant || themeVariant); return React.cloneElement(child, { - donutDx: child.props.donutDx || getDynamicDonutDx(dynamicTheme, orientation), - donutDy: child.props.donutDy || getDynamicDonutDy(dynamicTheme), - donutHeight: child.props.donutHeight || donutHeight - (theme.pie.height - dynamicTheme.pie.height), + data: childData, + donutDx: getDynamicDonutDx(dynamicTheme, orientation), + donutDy: getDynamicDonutDy(dynamicTheme), + donutHeight: donutHeight - (theme.pie.height - dynamicTheme.pie.height), donutOrientation: orientation, - donutWidth: child.props.donutWidth || donutWidth - (theme.pie.width - dynamicTheme.pie.width), - endAngle: child.props.endAngle || 360 * (datum[0]._y ? datum[0]._y / 100 : 100), - height: child.props.height || height, - showStatic: child.props.showStatic || false, + donutWidth: donutWidth - (theme.pie.width - dynamicTheme.pie.width), + endAngle: 360 * (datum[0]._y ? datum[0]._y / 100 : 100), + height, + showStatic: false, standalone: false, theme: dynamicTheme, - width: child.props.width || width + width: width, + ...childProps, }); } return child; @@ -479,6 +492,7 @@ export const ChartDonutThreshold: React.FunctionComponent 0 ? innerRadius : 0} + labels={labels} origin={getChartOrigin({ chartHeight: donutHeight, chartWidth: donutWidth, diff --git a/packages/patternfly-4/react-charts/src/components/ChartDonutUtilization/__snapshots__/ChartDonutThreshold.test.tsx.snap b/packages/patternfly-4/react-charts/src/components/ChartDonutUtilization/__snapshots__/ChartDonutThreshold.test.tsx.snap index 49ca44c31d1..170da596cec 100644 --- a/packages/patternfly-4/react-charts/src/components/ChartDonutUtilization/__snapshots__/ChartDonutThreshold.test.tsx.snap +++ b/packages/patternfly-4/react-charts/src/components/ChartDonutUtilization/__snapshots__/ChartDonutThreshold.test.tsx.snap @@ -15,6 +15,7 @@ exports[`Chart 1`] = ` } height={230} innerRadius={98} + labels={Array []} origin={ Object { "x": 115, @@ -494,6 +495,7 @@ exports[`Chart 2`] = ` } height={230} innerRadius={98} + labels={Array []} origin={ Object { "x": 115, @@ -966,25 +968,26 @@ exports[`renders component data 1`] = ` @@ -30,7 +29,6 @@ exports[`AboutModalBoxCloseButton Test onclose 1`] = ` > diff --git a/packages/patternfly-4/react-core/src/components/Accordion/Accordion.test.tsx b/packages/patternfly-4/react-core/src/components/Accordion/Accordion.test.tsx index 854b313db7f..b35c036ceb2 100644 --- a/packages/patternfly-4/react-core/src/components/Accordion/Accordion.test.tsx +++ b/packages/patternfly-4/react-core/src/components/Accordion/Accordion.test.tsx @@ -2,6 +2,8 @@ import React from 'react'; import { shallow, mount } from 'enzyme'; import { Accordion } from './Accordion'; import { AccordionToggle } from './AccordionToggle'; +import { AccordionContent } from './AccordionContent'; +import { AccordionItem } from './AccordionItem'; describe('Accordion', () => { test('Accordion default', () => { @@ -25,4 +27,17 @@ describe('Accordion', () => { expect(button.props['aria-expanded']).toBe(true); expect(button.props.className).toContain('pf-m-expanded'); }); + + test('Accordion with non-default headingLevel', () => { + const view = shallow( + + + Item One + Item One Content + + + ); + expect(view.render()).toMatchSnapshot(); + }); + }); diff --git a/packages/patternfly-4/react-core/src/components/Accordion/Accordion.tsx b/packages/patternfly-4/react-core/src/components/Accordion/Accordion.tsx index 750917c06c6..04ab0892ede 100644 --- a/packages/patternfly-4/react-core/src/components/Accordion/Accordion.tsx +++ b/packages/patternfly-4/react-core/src/components/Accordion/Accordion.tsx @@ -2,6 +2,8 @@ import * as React from 'react'; import { css } from '@patternfly/react-styles'; import styles from '@patternfly/react-styles/css/components/Accordion/accordion'; +export const AccordionContext = React.createContext('h3'); + export interface AccordionProps extends React.HTMLProps { /** Content rendered inside the Accordion */ children?: React.ReactNode; @@ -9,15 +11,18 @@ export interface AccordionProps extends React.HTMLProps { className?: string; /** Adds accessible text to the Accordion */ 'aria-label'?: string; + /** the heading level to use */ + headingLevel?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'; } export const Accordion: React.FunctionComponent = ({ children = null, className = '', 'aria-label': ariaLabel = '', + headingLevel = 'h3', ...props }: AccordionProps) => (
- {children} + {children}
); diff --git a/packages/patternfly-4/react-core/src/components/Accordion/AccordionToggle.tsx b/packages/patternfly-4/react-core/src/components/Accordion/AccordionToggle.tsx index 6ba130e5fda..aa384c96462 100644 --- a/packages/patternfly-4/react-core/src/components/Accordion/AccordionToggle.tsx +++ b/packages/patternfly-4/react-core/src/components/Accordion/AccordionToggle.tsx @@ -2,7 +2,9 @@ import * as React from 'react'; import { css } from '@patternfly/react-styles'; import styles from '@patternfly/react-styles/css/components/Accordion/accordion'; import { AngleRightIcon } from '@patternfly/react-icons'; +import { AccordionContext } from './Accordion'; import { Omit } from '../../helpers/typeUtils'; +import { ElementType } from 'react'; export interface AccordionToggleProps extends Omit, 'type'> { /** Content rendered inside the Accordion toggle */ @@ -23,16 +25,20 @@ export const AccordionToggle: React.FunctionComponent = ({ ...props }: AccordionToggleProps) => (
-

- -

+ + {(AccordionHeadingLevel: any) => ( + + + + )} +
); diff --git a/packages/patternfly-4/react-core/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap b/packages/patternfly-4/react-core/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap index 8b5b87cfc40..98bdd56bc51 100644 --- a/packages/patternfly-4/react-core/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +++ b/packages/patternfly-4/react-core/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap @@ -6,3 +6,52 @@ exports[`Accordion Accordion default 1`] = ` class="pf-c-accordion" /> `; + +exports[`Accordion Accordion with non-default headingLevel 1`] = ` +
+
+

+ +

+
+
+
+ Item One Content +
+
+
+`; diff --git a/packages/patternfly-4/react-core/src/components/Alert/__snapshots__/Alert.test.tsx.snap b/packages/patternfly-4/react-core/src/components/Alert/__snapshots__/Alert.test.tsx.snap index 152755dd083..763aec0dd54 100644 --- a/packages/patternfly-4/react-core/src/components/Alert/__snapshots__/Alert.test.tsx.snap +++ b/packages/patternfly-4/react-core/src/components/Alert/__snapshots__/Alert.test.tsx.snap @@ -23,7 +23,6 @@ exports[`Alert - danger Action Close Button 1`] = ` > @@ -90,7 +89,6 @@ exports[`Alert - danger Action Close Button 1`] = ` > @@ -144,7 +142,6 @@ exports[`Alert - danger Action Link 1`] = ` > @@ -240,7 +237,6 @@ exports[`Alert - danger Action and Title 1`] = ` > @@ -338,7 +334,6 @@ exports[`Alert - danger Custom aria label 1`] = ` > @@ -430,7 +425,6 @@ exports[`Alert - danger Description 1`] = ` > @@ -493,7 +487,6 @@ exports[`Alert - danger Title 1`] = ` > @@ -558,7 +551,6 @@ exports[`Alert - danger inline variation 1`] = ` > @@ -628,7 +620,6 @@ exports[`Alert - info Action Close Button 1`] = ` > @@ -695,7 +686,6 @@ exports[`Alert - info Action Close Button 1`] = ` > @@ -749,7 +739,6 @@ exports[`Alert - info Action Link 1`] = ` > @@ -845,7 +834,6 @@ exports[`Alert - info Action and Title 1`] = ` > @@ -943,7 +931,6 @@ exports[`Alert - info Custom aria label 1`] = ` > @@ -1035,7 +1022,6 @@ exports[`Alert - info Description 1`] = ` > @@ -1098,7 +1084,6 @@ exports[`Alert - info Title 1`] = ` > @@ -1163,7 +1148,6 @@ exports[`Alert - info inline variation 1`] = ` > @@ -1233,7 +1217,6 @@ exports[`Alert - success Action Close Button 1`] = ` > @@ -1300,7 +1283,6 @@ exports[`Alert - success Action Close Button 1`] = ` > @@ -1354,7 +1336,6 @@ exports[`Alert - success Action Link 1`] = ` > @@ -1450,7 +1431,6 @@ exports[`Alert - success Action and Title 1`] = ` > @@ -1548,7 +1528,6 @@ exports[`Alert - success Custom aria label 1`] = ` > @@ -1640,7 +1619,6 @@ exports[`Alert - success Description 1`] = ` > @@ -1703,7 +1681,6 @@ exports[`Alert - success Title 1`] = ` > @@ -1768,7 +1745,6 @@ exports[`Alert - success inline variation 1`] = ` > @@ -1838,7 +1814,6 @@ exports[`Alert - warning Action Close Button 1`] = ` > @@ -1905,7 +1880,6 @@ exports[`Alert - warning Action Close Button 1`] = ` > @@ -1959,7 +1933,6 @@ exports[`Alert - warning Action Link 1`] = ` > @@ -2055,7 +2028,6 @@ exports[`Alert - warning Action and Title 1`] = ` > @@ -2153,7 +2125,6 @@ exports[`Alert - warning Custom aria label 1`] = ` > @@ -2245,7 +2216,6 @@ exports[`Alert - warning Description 1`] = ` > @@ -2308,7 +2278,6 @@ exports[`Alert - warning Title 1`] = ` > @@ -2373,7 +2342,6 @@ exports[`Alert - warning inline variation 1`] = ` > diff --git a/packages/patternfly-4/react-core/src/components/ApplicationLauncher/__snapshots__/ApplicationLauncher.test.js.snap b/packages/patternfly-4/react-core/src/components/ApplicationLauncher/__snapshots__/ApplicationLauncher.test.js.snap index 57043bfbdb1..97e567c01d0 100644 --- a/packages/patternfly-4/react-core/src/components/ApplicationLauncher/__snapshots__/ApplicationLauncher.test.js.snap +++ b/packages/patternfly-4/react-core/src/components/ApplicationLauncher/__snapshots__/ApplicationLauncher.test.js.snap @@ -286,7 +286,6 @@ exports[`ApplicationLauncher dropup + right aligned 1`] = ` > @@ -346,7 +345,6 @@ exports[`ApplicationLauncher dropup + right aligned 1`] = ` > @@ -665,7 +663,6 @@ exports[`ApplicationLauncher dropup 1`] = ` > @@ -725,7 +722,6 @@ exports[`ApplicationLauncher dropup 1`] = ` > @@ -1044,7 +1040,6 @@ exports[`ApplicationLauncher expanded 1`] = ` > @@ -1104,7 +1099,6 @@ exports[`ApplicationLauncher expanded 1`] = ` > @@ -1681,7 +1675,6 @@ exports[`ApplicationLauncher regular 1`] = ` > @@ -1741,7 +1734,6 @@ exports[`ApplicationLauncher regular 1`] = ` > @@ -2060,7 +2052,6 @@ exports[`ApplicationLauncher right aligned 1`] = ` > @@ -2120,7 +2111,6 @@ exports[`ApplicationLauncher right aligned 1`] = ` > diff --git a/packages/patternfly-4/react-core/src/components/Breadcrumb/__snapshots__/BreadcrumbItem.test.tsx.snap b/packages/patternfly-4/react-core/src/components/Breadcrumb/__snapshots__/BreadcrumbItem.test.tsx.snap index e30f4ed22ec..847784e33c7 100644 --- a/packages/patternfly-4/react-core/src/components/Breadcrumb/__snapshots__/BreadcrumbItem.test.tsx.snap +++ b/packages/patternfly-4/react-core/src/components/Breadcrumb/__snapshots__/BreadcrumbItem.test.tsx.snap @@ -18,7 +18,6 @@ exports[`BreadcrumbItem component should render breadcrumbItem with className 1` > @@ -38,7 +37,6 @@ exports[`BreadcrumbItem component should render breadcrumbItem with custom eleme > @@ -57,7 +55,6 @@ exports[`BreadcrumbItem component should render breadcrumbItem with id 1`] = ` > @@ -75,7 +72,6 @@ exports[`BreadcrumbItem component should render breadcrumbItem with target 1`] = > @@ -93,7 +89,6 @@ exports[`BreadcrumbItem component should render default breadcrumbItem 1`] = ` > @@ -117,7 +112,6 @@ exports[`BreadcrumbItem component should render link breadcrumbItem 1`] = ` > diff --git a/packages/patternfly-4/react-core/src/components/ClipboardCopy/__snapshots__/CopyButton.test.js.snap b/packages/patternfly-4/react-core/src/components/ClipboardCopy/__snapshots__/CopyButton.test.js.snap index 1d391d85575..d1ccfaee515 100644 --- a/packages/patternfly-4/react-core/src/components/ClipboardCopy/__snapshots__/CopyButton.test.js.snap +++ b/packages/patternfly-4/react-core/src/components/ClipboardCopy/__snapshots__/CopyButton.test.js.snap @@ -27,7 +27,6 @@ exports[`copy button render 1`] = ` > diff --git a/packages/patternfly-4/react-core/src/components/ClipboardCopy/__snapshots__/ToggleButton.test.js.snap b/packages/patternfly-4/react-core/src/components/ClipboardCopy/__snapshots__/ToggleButton.test.js.snap index a2c1fbb0630..24cbc3ab3e0 100644 --- a/packages/patternfly-4/react-core/src/components/ClipboardCopy/__snapshots__/ToggleButton.test.js.snap +++ b/packages/patternfly-4/react-core/src/components/ClipboardCopy/__snapshots__/ToggleButton.test.js.snap @@ -14,7 +14,6 @@ exports[`toggle button render 1`] = ` aria-hidden="true" className="pf-c-clipboard-copy__group-toggle-icon" color="currentColor" - noVerticalAlign={false} size="sm" title={null} /> diff --git a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelector.d.ts b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelector.d.ts deleted file mode 100644 index 4edddc55989..00000000000 --- a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelector.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { FunctionComponent, ReactNode } from 'react'; -import { OneOf } from '../../helpers/typeUtils'; - -export interface ContextSelectorProps { - children?: ReactNode; - isOpen?: boolean; - onToggle?(value: boolean): void; - onSelect?(event: React.SyntheticEvent, value: ReactNode): void; - screenReaderLabel?: string; - toggleText?: string; - searchButtonAriaLabel?: string; - searchInputValue?: string; - onSearchInputChange?(value: string): void; - searchInputPlaceholder?: string; - onSearchButtonClick?(event: React.SyntheticEvent): void; -} - -declare const ContextSelector: FunctionComponent; - -export default ContextSelector; diff --git a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelector.md b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelector.md index 44b0d45e7af..92a3071b239 100644 --- a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelector.md +++ b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelector.md @@ -1,6 +1,7 @@ --- title: 'Context selector' propComponents: ['ContextSelector', 'ContextSelectorItem'] +typescript: true --- import { ContextSelector, ContextSelectorItem } from '@patternfly/react-core'; diff --git a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelector.test.js b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelector.test.tsx similarity index 89% rename from packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelector.test.js rename to packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelector.test.tsx index 0c37498c512..3333c27f63c 100644 --- a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelector.test.js +++ b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelector.test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { shallow, mount } from 'enzyme'; -import ContextSelector from './ContextSelector'; -import ContextSelectorItem from './ContextSelectorItem'; +import { ContextSelector } from './ContextSelector'; +import { ContextSelectorItem } from './ContextSelectorItem'; const items = [ My Project, diff --git a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelector.js b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelector.tsx similarity index 71% rename from packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelector.js rename to packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelector.tsx index a3bce11b1fc..3cedc5c3a41 100644 --- a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelector.js +++ b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelector.tsx @@ -1,67 +1,71 @@ -import React from 'react'; -import styles from '@patternfly/react-styles/css/components/ContextSelector/context-selector'; +import * as React from 'react'; +import styles from '@patternfly/react-styles/css/components/ContextSelector/context-selector' import { css } from '@patternfly/react-styles'; -import PropTypes from 'prop-types'; -import FocusTrap from 'focus-trap-react'; import { SearchIcon } from '@patternfly/react-icons'; -import ContextSelectorToggle from './ContextSelectorToggle'; -import ContextSelectorMenuList from './ContextSelectorMenuList'; +import { ContextSelectorToggle } from './ContextSelectorToggle'; +import { ContextSelectorMenuList } from './ContextSelectorMenuList'; import { ContextSelectorContext } from './contextSelectorConstants'; import { Button, ButtonVariant } from '../Button'; import { TextInput } from '../TextInput'; import { InputGroup } from '../InputGroup'; import { KEY_CODES } from '../../helpers/constants'; +// Can't use ES6 imports :( +// The types for it are also wrong, we should probably ditch this dependency. +// tslint:disable-next-line +const FocusTrap: any = require('focus-trap-react'); + // seed for the aria-labelledby ID let currentId = 0; const newId = currentId++; -const propTypes = { +export interface ContextSelectorProps { /** content rendered inside the Context Selector */ - children: PropTypes.node, + children?: React.ReactNode; /** Classes applied to root element of Context Selector */ - className: PropTypes.string, + className?: string; /** Flag to indicate if Context Selector is opened */ - isOpen: PropTypes.bool, + isOpen?: boolean; /** Function callback called when user clicks toggle button */ - onToggle: PropTypes.func, + onToggle?: (value: boolean) => void; /** Function callback called when user selects item */ - onSelect: PropTypes.func, + onSelect?: (event: any, value: React.ReactNode) => void; /** Labels the Context Selector for Screen Readers */ - screenReaderLabel: PropTypes.string, + screenReaderLabel?: string; /** Text that appears in the Context Selector Toggle */ - toggleText: PropTypes.string, + toggleText?: string; /** aria-label for the Context Selector Search Button */ - searchButtonAriaLabel: PropTypes.string, + searchButtonAriaLabel?: string; /** Value in the Search field */ - searchInputValue: PropTypes.string, + searchInputValue?: string; /** Function callback called when user changes the Search Input */ - onSearchInputChange: PropTypes.func, + onSearchInputChange?(value: string): void; /** Search Input placeholder */ - searchInputPlaceholder: PropTypes.string, + searchInputPlaceholder?: string; /** Function callback for when Search Button is clicked */ - onSearchButtonClick: PropTypes.func -}; + onSearchButtonClick?(event?: React.SyntheticEvent): void; +} + +export class ContextSelector extends React.Component { -const defaultProps = { - children: null, - className: '', - isOpen: false, - onToggle: () => {}, - onSelect: () => {}, - screenReaderLabel: '', - toggleText: '', - searchButtonAriaLabel: 'Search menu items', - searchInputValue: '', - onSearchInputChange: () => {}, - searchInputPlaceholder: 'Search', - onSearchButtonClick: () => {} -}; + static defaultProps = { + children: null as React.ReactNode, + className: '', + isOpen: false, + onToggle: () => undefined as any, + onSelect: () => undefined as any, + screenReaderLabel: '', + toggleText: '', + searchButtonAriaLabel: 'Search menu items', + searchInputValue: '', + onSearchInputChange: () => undefined as any, + searchInputPlaceholder: 'Search', + onSearchButtonClick: () => undefined as any + } -class ContextSelector extends React.Component { - parentRef = React.createRef(); + parentRef: React.RefObject = React.createRef(); - onEnterPressed = event => { + onEnterPressed = (event: any) => { if (event.charCode === KEY_CODES.ENTER) { this.props.onSearchButtonClick(); } @@ -140,8 +144,3 @@ class ContextSelector extends React.Component { ); } } - -ContextSelector.propTypes = propTypes; -ContextSelector.defaultProps = defaultProps; - -export default ContextSelector; diff --git a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorItem.d.ts b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorItem.d.ts deleted file mode 100644 index 8daec453c25..00000000000 --- a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorItem.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { FunctionComponent, HTMLProps, ReactType } from 'react'; - -export interface ContextSelectorItemProps { - isDisabled?: boolean; - isSelected?: boolean; - isHovered?: boolean; - onClick?: Function; -} - -declare const ContextSelectorItem: FunctionComponent; - -export default ContextSelectorItem; diff --git a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorItem.test.js b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorItem.test.tsx similarity index 83% rename from packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorItem.test.js rename to packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorItem.test.tsx index ac165f7e5fc..996ad870ae9 100644 --- a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorItem.test.js +++ b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorItem.test.tsx @@ -1,10 +1,10 @@ import React from 'react'; import { shallow, mount } from 'enzyme'; -import ContextSelectorItem from './ContextSelectorItem'; +import { ContextSelectorItem } from './ContextSelectorItem'; test('Renders ContextSelectorItem', () => { const view = shallow( - + My Project ); @@ -13,7 +13,7 @@ test('Renders ContextSelectorItem', () => { test('Renders ContextSelectorItem disabled and hovered', () => { const view = shallow( - + My Project ); @@ -23,7 +23,7 @@ test('Renders ContextSelectorItem disabled and hovered', () => { test('Verify onClick is called ', () => { const mockfn = jest.fn(); const view = mount( - + My Project ); diff --git a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorItem.js b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorItem.tsx similarity index 62% rename from packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorItem.js rename to packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorItem.tsx index fcce248005e..8564583cb99 100644 --- a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorItem.js +++ b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorItem.tsx @@ -1,40 +1,38 @@ -import React from 'react'; -import PropTypes from 'prop-types'; +import * as React from 'react'; import styles from '@patternfly/react-styles/css/components/ContextSelector/context-selector'; import { css } from '@patternfly/react-styles'; import { ContextSelectorContext } from './contextSelectorConstants'; -const propTypes = { +export interface ContextSelectorItemProps { /** Anything which can be rendered as Context Selector item */ - children: PropTypes.node, + children?: React.ReactNode; /** Classes applied to root element of the Context Selector item */ - className: PropTypes.string, + className?: string; /** Render Context Selector item as disabled */ - isDisabled: PropTypes.bool, + isDisabled?: boolean; + // isSelected? /** Forces display of the hover state of the element */ - isHovered: PropTypes.bool, + isHovered?: boolean; /** Callback for click event */ - onClick: PropTypes.func, + onClick: (event: React.MouseEvent) => void; /** internal index of the item */ - index: PropTypes.number, + index: number; /** Internal callback for ref tracking */ - sendRef: PropTypes.func, - /** Additional props are spread to the button element */ - '': PropTypes.any // eslint-disable-line react/require-default-props -}; - -const defaultProps = { - children: null, - className: '', - isHovered: false, - isDisabled: false, - onClick: () => {}, - index: undefined, - sendRef: Function.prototype -}; + sendRef: (index: number, current: any) => void; +} -class ContextSelectorItem extends React.Component { - ref = React.createRef(); +export class ContextSelectorItem extends React.Component{ + static defaultProps = { + children: null as React.ReactNode, + className: '', + isHovered: false, + isDisabled: false, + onClick: (): any => undefined, + index: undefined as number, + sendRef: Function.prototype + } + + ref: React.RefObject = React.createRef(); componentDidMount() { /* eslint-disable-next-line */ @@ -57,8 +55,8 @@ class ContextSelectorItem extends React.Component { ref={this.ref} onClick={event => { if (!isDisabled) { - onClick && onClick(event); - onSelect && onSelect(event, children); + onClick(event); + onSelect(event, children); } }} {...props} @@ -71,8 +69,3 @@ class ContextSelectorItem extends React.Component { ); } } - -ContextSelectorItem.propTypes = propTypes; -ContextSelectorItem.defaultProps = defaultProps; - -export default ContextSelectorItem; diff --git a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorMenuList.js b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorMenuList.js deleted file mode 100644 index d989a4ecf98..00000000000 --- a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorMenuList.js +++ /dev/null @@ -1,53 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import styles from '@patternfly/react-styles/css/components/ContextSelector/context-selector'; -import { css } from '@patternfly/react-styles'; - -const propTypes = { - /** Content rendered inside the Context Selector Menu */ - children: PropTypes.node, - /** Classess applied to root element of Context Selector menu */ - className: PropTypes.string, - /** Flag to indicate if Context Selector menu is opened */ - isOpen: PropTypes.bool, - /** Additional props are spread to the container component */ - '': PropTypes.any // eslint-disable-line react/require-default-props -}; - -const defaultProps = { - children: null, - className: '', - isOpen: true -}; - -class ContextSelectorMenuList extends React.Component { - refsCollection = []; - - sendRef = (index, ref) => { - this.refsCollection[index] = ref; - }; - - extendChildren() { - return React.Children.map(this.props.children, (child, index) => - React.cloneElement(child, { - sendRef: this.sendRef, - index - }) - ); - } - - render() { - const { className, isOpen, children, ...props } = this.props; - - return ( - - ); - } -} - -ContextSelectorMenuList.propTypes = propTypes; -ContextSelectorMenuList.defaultProps = defaultProps; - -export default ContextSelectorMenuList; diff --git a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorMenuList.test.js b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorMenuList.test.tsx similarity index 69% rename from packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorMenuList.test.js rename to packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorMenuList.test.tsx index 88a2993ccf8..1db53b46de0 100644 --- a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorMenuList.test.js +++ b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorMenuList.test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { shallow } from 'enzyme'; -import ContextSelectorItem from './ContextSelectorItem'; -import ContextSelectorMenuList from './ContextSelectorMenuList'; +import { ContextSelectorItem } from './ContextSelectorItem'; +import { ContextSelectorMenuList } from './ContextSelectorMenuList'; const items = [ My Project, @@ -13,7 +13,7 @@ const items = [ test('Renders ContextSelectorMenuList open', () => { const view = shallow( - + {items} ); @@ -21,6 +21,9 @@ test('Renders ContextSelectorMenuList open', () => { }); test('Renders ContextSelectorMenuList closed', () => { - const view = shallow({items}); + const view = shallow( + + {items} + ); expect(view).toMatchSnapshot(); }); diff --git a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorMenuList.tsx b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorMenuList.tsx new file mode 100644 index 00000000000..db590237578 --- /dev/null +++ b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorMenuList.tsx @@ -0,0 +1,50 @@ +import * as React from 'react'; +import styles from '@patternfly/react-styles/css/components/ContextSelector/context-selector'; +import { css } from '@patternfly/react-styles'; + +export interface ContextSelectorMenuListProps { + /** Content rendered inside the Context Selector Menu */ + children?: React.ReactNode; + /** Classess applied to root element of Context Selector menu */ + className?: string; + /** Flag to indicate if Context Selector menu is opened */ + isOpen?: boolean; +} + +export class ContextSelectorMenuList extends React.Component { + + static defaultProps = { + children: null as React.ReactNode, + className: '', + isOpen: true + } + + refsCollection = [] as any; + + sendRef = (index: number, ref: any) => { + this.refsCollection[index] = ref; + }; + + extendChildren() { + return React.Children.map(this.props.children, (child, index) => + React.cloneElement(child as React.ReactElement, { + sendRef: this.sendRef, + index + }) + ); + } + + render = () => { + const { + className, + isOpen, + children, + ...props + } = this.props; + return ( + + ); + } +} diff --git a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorToggle.test.js b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorToggle.test.tsx similarity index 95% rename from packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorToggle.test.js rename to packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorToggle.test.tsx index 71d1c50fad7..7b0fc303272 100644 --- a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorToggle.test.js +++ b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorToggle.test.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { shallow, mount } from 'enzyme'; -import ContextSelectorToggle from './ContextSelectorToggle'; +import { ContextSelectorToggle } from './ContextSelectorToggle'; test('Renders ContextSelectorToggle', () => { const view = shallow(); diff --git a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorToggle.js b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorToggle.tsx similarity index 66% rename from packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorToggle.js rename to packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorToggle.tsx index 5b0d38928ad..8c7a167c379 100644 --- a/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorToggle.js +++ b/packages/patternfly-4/react-core/src/components/ContextSelector/ContextSelectorToggle.tsx @@ -1,48 +1,47 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; +import * as React from 'react'; import { CaretDownIcon } from '@patternfly/react-icons'; import styles from '@patternfly/react-styles/css/components/ContextSelector/context-selector'; import { css } from '@patternfly/react-styles'; import { KEY_CODES } from '../../helpers/constants'; -const propTypes = { +export interface ContextSelectorToggleProps { /** HTML ID of toggle */ - id: PropTypes.string.isRequired, + id: string; /** Classes applied to root element of toggle */ - className: PropTypes.string, + className?: string; /** Text that appears in the Context Selector Toggle */ - toggleText: PropTypes.string, + toggleText?: string; /** Flag to indicate if menu is opened */ - isOpen: PropTypes.bool, + isOpen?: boolean; /** Callback called when toggle is clicked */ - onToggle: PropTypes.func, + onToggle?: (event: any, value: boolean) => void; /** Callback for toggle open on keyboard entry */ - onEnter: PropTypes.func, + onEnter: () => void; /** Element which wraps toggle */ - parentRef: PropTypes.any, + parentRef?: any; /** Forces focus state */ - isFocused: PropTypes.bool, + isFocused?: boolean; /** Forces hover state */ - isHovered: PropTypes.bool, + isHovered?: boolean; /** Forces active state */ - isActive: PropTypes.bool, - /** Additional props are spread to the container ); } -} - -ContextSelectorToggle.propTypes = propTypes; -ContextSelectorToggle.defaultProps = defaultProps; - -export default ContextSelectorToggle; +} \ No newline at end of file diff --git a/packages/patternfly-4/react-core/src/components/ContextSelector/__snapshots__/ContextSelector.test.js.snap b/packages/patternfly-4/react-core/src/components/ContextSelector/__snapshots__/ContextSelector.test.tsx.snap similarity index 99% rename from packages/patternfly-4/react-core/src/components/ContextSelector/__snapshots__/ContextSelector.test.js.snap rename to packages/patternfly-4/react-core/src/components/ContextSelector/__snapshots__/ContextSelector.test.tsx.snap index ca876950c62..50b4e78b02b 100644 --- a/packages/patternfly-4/react-core/src/components/ContextSelector/__snapshots__/ContextSelector.test.js.snap +++ b/packages/patternfly-4/react-core/src/components/ContextSelector/__snapshots__/ContextSelector.test.tsx.snap @@ -80,7 +80,6 @@ exports[`Renders ContextSelector open 1`] = `