From 25c46352b4c1bebb8be507d717b32b9c0aa824f3 Mon Sep 17 00:00:00 2001 From: Greg Thompson Date: Fri, 23 Aug 2019 13:56:00 -0500 Subject: [PATCH] Revert "Convert `EuiSwitch` to TS (#2243)" This reverts commit 39dbcf69adca4b5f6181e97d56b49e5fb04c1e86. --- src/components/form/index.d.ts | 1 + ...itch.test.tsx.snap => switch.test.js.snap} | 10 +-- src/components/form/switch/index.d.ts | 21 +++++ src/components/form/switch/index.js | 1 + src/components/form/switch/index.ts | 1 - src/components/form/switch/switch.js | 86 +++++++++++++++++++ .../{switch.test.tsx => switch.test.js} | 12 +-- src/components/form/switch/switch.tsx | 86 ------------------- 8 files changed, 113 insertions(+), 105 deletions(-) rename src/components/form/switch/__snapshots__/{switch.test.tsx.snap => switch.test.js.snap} (95%) create mode 100644 src/components/form/switch/index.d.ts create mode 100644 src/components/form/switch/index.js delete mode 100644 src/components/form/switch/index.ts create mode 100644 src/components/form/switch/switch.js rename src/components/form/switch/{switch.test.tsx => switch.test.js} (65%) delete mode 100644 src/components/form/switch/switch.tsx diff --git a/src/components/form/index.d.ts b/src/components/form/index.d.ts index a31e554069b..366419d36f9 100644 --- a/src/components/form/index.d.ts +++ b/src/components/form/index.d.ts @@ -9,6 +9,7 @@ import { CommonProps } from '../common'; /// /// /// +/// /// import { FunctionComponent, FormHTMLAttributes, ReactNode } from 'react'; diff --git a/src/components/form/switch/__snapshots__/switch.test.tsx.snap b/src/components/form/switch/__snapshots__/switch.test.js.snap similarity index 95% rename from src/components/form/switch/__snapshots__/switch.test.tsx.snap rename to src/components/form/switch/__snapshots__/switch.test.js.snap index b05767ccc4d..642f2dce792 100644 --- a/src/components/form/switch/__snapshots__/switch.test.tsx.snap +++ b/src/components/form/switch/__snapshots__/switch.test.js.snap @@ -5,7 +5,6 @@ exports[`EuiSwitch assigns automatically generated ID to label 1`] = ` class="euiSwitch" > + + + + ); + } +} + +EuiSwitch.propTypes = { + name: PropTypes.string, + id: PropTypes.string, + label: PropTypes.node, + checked: PropTypes.bool, + onChange: PropTypes.func, + disabled: PropTypes.bool, + compressed: PropTypes.bool, +}; diff --git a/src/components/form/switch/switch.test.tsx b/src/components/form/switch/switch.test.js similarity index 65% rename from src/components/form/switch/switch.test.tsx rename to src/components/form/switch/switch.test.js index a564df98ca1..50927c7fa6e 100644 --- a/src/components/form/switch/switch.test.tsx +++ b/src/components/form/switch/switch.test.js @@ -4,25 +4,17 @@ import { requiredProps } from '../../../test/required_props'; import { EuiSwitch } from './switch'; -const props = { - checked: false, - label: 'Label', - onChange: () => {}, -}; - jest.mock('../form_row/make_id', () => () => 'generated-id'); describe('EuiSwitch', () => { test('is rendered', () => { - const component = render( - - ); + const component = render(); expect(component).toMatchSnapshot(); }); test('assigns automatically generated ID to label', () => { - const component = render(); + const component = render(); expect(component).toMatchSnapshot(); }); diff --git a/src/components/form/switch/switch.tsx b/src/components/form/switch/switch.tsx deleted file mode 100644 index 334b7394bb6..00000000000 --- a/src/components/form/switch/switch.tsx +++ /dev/null @@ -1,86 +0,0 @@ -import React, { - ButtonHTMLAttributes, - FunctionComponent, - ReactNode, - useState, -} from 'react'; -import classNames from 'classnames'; - -import { CommonProps, Omit } from '../../common'; -import makeId from '../../form/form_row/make_id'; -import { EuiIcon } from '../../icon'; - -export type EuiSwitchEvent = React.BaseSyntheticEvent< - React.MouseEvent, - HTMLButtonElement, - EventTarget & { - checked: boolean; - } ->; - -export type EuiSwitchProps = CommonProps & - Omit, 'onChange'> & { - label: ReactNode; - checked: boolean; - onChange: (event: EuiSwitchEvent) => void; - disabled?: boolean; - compressed?: boolean; - }; - -export const EuiSwitch: FunctionComponent = ({ - label, - id, - name, - checked, - disabled, - compressed, - onChange, - className, - ...rest -}) => { - const [switchId] = useState(id || makeId()); - - const onClick = (e: React.MouseEvent) => { - const event = (e as unknown) as EuiSwitchEvent; - event.target.checked = !checked; - onChange(event); - }; - - const classes = classNames( - 'euiSwitch', - { - 'euiSwitch--compressed': compressed, - }, - className - ); - - return ( -
- - - -
- ); -};