Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EuiFormControlLayoutCustomIcon to TS #1956

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Converted `EuiFormControlLayoutCustomIcon` to TS ([#1956](https://github.com/elastic/eui/pull/1956))
- Converted `EuiStepNumber` to TS ([#1893](https://github.com/elastic/eui/pull/1893))
- Converted `EuiFormControlLayoutClearButton` to TS ([#1922](https://github.com/elastic/eui/pull/1922))
- Added `data-test-subj` property to `EuiDraggable` and `EuiDroppable` ([#1943](https://github.com/elastic/eui/pull/1943))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiFormControlLayoutCustomIcon is rendered as button 1`] = `
<button
class="euiFormControlLayoutCustomIcon customClass euiFormControlLayoutCustomIcon--clickable"
data-test-subj="customIcon"
type="button"
>
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiIcon-isLoading euiFormControlLayoutCustomIcon__icon"
focusable="false"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
/>
</button>
`;

exports[`EuiFormControlLayoutCustomIcon is rendered as span 1`] = `
<span
class="euiFormControlLayoutCustomIcon customClass"
data-test-subj="customIcon"
>
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiIcon-isLoading euiFormControlLayoutCustomIcon__icon"
focusable="false"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
/>
</span>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import { render } from 'enzyme';
import { EuiFormControlLayoutCustomIcon } from './form_control_layout_custom_icon';

describe('EuiFormControlLayoutCustomIcon', () => {
test('is rendered as button', () => {
const props = {
onClick: () => null,
className: 'customClass',
'data-test-subj': 'customIcon',
type: 'alert',
iconRef: 'icon',
};
const component = render(<EuiFormControlLayoutCustomIcon {...props} />);

expect(component).toMatchSnapshot();
});

test('is rendered as span', () => {
const props = {
className: 'customClass',
'data-test-subj': 'customIcon',
type: 'alert',
iconRef: 'icon',
};
const component = render(<EuiFormControlLayoutCustomIcon {...props} />);

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

import { EuiIcon } from '../../icon';
import { EuiIcon, IconType } from '../../icon';
import { CommonProps, ExclusiveUnion } from '../../common';

export const EuiFormControlLayoutCustomIcon = ({
className,
onClick,
type,
iconRef,
...rest
}) => {
export interface EuiFormControlLayoutCustomIconProps {
type: IconType;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changed to required as EuiIcon type is required

iconRef?: string | ((el: HTMLButtonElement | HTMLSpanElement | null) => void);
}

export const EuiFormControlLayoutCustomIcon: FunctionComponent<
CommonProps &
ExclusiveUnion<
ButtonHTMLAttributes<HTMLButtonElement>,
HTMLAttributes<HTMLSpanElement>
> &
EuiFormControlLayoutCustomIconProps
> = ({ className, onClick, type, iconRef, ...rest }) => {
const classes = classNames('euiFormControlLayoutCustomIcon', className, {
'euiFormControlLayoutCustomIcon--clickable': onClick,
});
Expand Down Expand Up @@ -42,10 +52,3 @@ export const EuiFormControlLayoutCustomIcon = ({
</span>
);
};

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

declare module '@elastic/eui' {
/**
* @see './form_control_layout_clear_button.js'
*/
export const EuiFormControlLayoutClearButton: typeof FormControlLayoutClearButton;

/**
* @see './form_control_layout_custom_icon.js'
*/
export const EuiFormControlLayoutCustomIcon: typeof FormControlLayoutCustomIcon;
}