Skip to content

Commit

Permalink
EuiFormControlLayoutClearButton converted to TS
Browse files Browse the repository at this point in the history
  • Loading branch information
Theo committed May 7, 2019
1 parent d332537 commit 295ce3d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiFormControlLayoutClearButton is rendered 1`] = `
<button
aria-label="Clear input"
class="euiFormControlLayoutClearButton customClass"
data-test-subj="clearButton"
type="button"
>
<svg
class="euiIcon euiIcon--medium euiFormControlLayoutClearButton__icon"
focusable="false"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M7.293 8L3.146 3.854a.5.5 0 1 1 .708-.708L8 7.293l4.146-4.147a.5.5 0 0 1 .708.708L8.707 8l4.147 4.146a.5.5 0 0 1-.708.708L8 8.707l-4.146 4.147a.5.5 0 0 1-.708-.708L7.293 8z"
/>
</svg>
</button>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import { render } from 'enzyme';
import { EuiFormControlLayoutClearButton } from './form_control_layout_clear_button';

describe('EuiFormControlLayoutClearButton', () => {
test('is rendered', () => {
const clear = {
onClick: () => null,
className: 'customClass',
'data-test-subj': 'clearButton',
};
const component = render(<EuiFormControlLayoutClearButton {...clear} />);

expect(component).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import React, { FunctionComponent, HTMLAttributes } from 'react';

import classNames from 'classnames';
import { CommonProps } from '../../common';
import { EuiIcon } from '../../icon';
import { EuiI18n } from '../../i18n';

export const EuiFormControlLayoutClearButton = ({
className,
onClick,
...rest
}) => {
export const EuiFormControlLayoutClearButton: FunctionComponent<
CommonProps & HTMLAttributes<HTMLButtonElement>
> = ({ className, onClick, ...rest }) => {
const classes = classNames('euiFormControlLayoutClearButton', className);

return (
<EuiI18n token="euiFormControlLayoutClearButton.label" default="Clear input">
{label => (
<EuiI18n
token="euiFormControlLayoutClearButton.label"
default="Clear input">
{(label: string) => (
<button
type="button"
className={classes}
onClick={onClick}
aria-label={label}
{...rest}
>
{...rest}>
<EuiIcon
className="euiFormControlLayoutClearButton__icon"
type="cross"
Expand All @@ -31,8 +30,3 @@ export const EuiFormControlLayoutClearButton = ({
</EuiI18n>
);
};

EuiFormControlLayoutClearButton.propTypes = {
className: PropTypes.string,
onClick: PropTypes.func,
};
8 changes: 8 additions & 0 deletions src/components/form/form_control_layout/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { EuiFormControlLayoutClearButton as FormControlLayoutClearButton } from './form_control_layout_clear_button';

declare module '@elastic/eui' {
/**
* @see './form_control_layout_clear_button.js'
*/
export const EuiFormControlLayoutClearButton: typeof FormControlLayoutClearButton;
}
2 changes: 2 additions & 0 deletions src/components/form/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import { CommonProps } from '../common';
/// <reference path="./field_search/index.d.ts" />
/// <reference path="./field_text/index.d.ts" />
/// <reference path="./form_help_text/index.d.ts" />
/// <reference path="./form_control_layout/index.d.ts" />
/// <reference path="./form_row/index.d.ts" />
/// <reference path="./radio/index.d.ts" />
/// <reference path="./range/index.d.ts" />
/// <reference path="./select/index.d.ts" />
/// <reference path="./switch/index.d.ts" />
/// <reference path="./text_area/index.d.ts" />


import { FunctionComponent, FormHTMLAttributes, ReactNode } from 'react';

declare module '@elastic/eui' {
Expand Down

0 comments on commit 295ce3d

Please sign in to comment.