Skip to content

Commit

Permalink
Convert EuiFacetButton to TS (#2226)
Browse files Browse the repository at this point in the history
* convert euifacetbutton to ts

* concat className

* CL
  • Loading branch information
thompsongl authored Aug 14, 2019
1 parent 76e58de commit 3da2a77
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 60 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Converted `EuiFacetButton` to TypeScript ([#2226](https://github.com/elastic/eui/pull/2226))

**Bug fixes**

- Fixed `EuiSwitch` semantics to align with aria roles ([#2193](https://github.com/elastic/eui/pull/2193))
- Removed Firefox's focus ring to match other browsers ([#2193](https://github.com/elastic/eui/pull/2193))

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,18 +1,49 @@
import React from 'react';
import PropTypes from 'prop-types';
import React, {
FunctionComponent,
HTMLAttributes,
MouseEventHandler,
ReactNode,
} from 'react';
import classNames from 'classnames';

import { CommonProps, RefCallback } from '../common';

import { EuiNotificationBadge } from '../badge';

import { EuiLoadingSpinner } from '../loading';

export const EuiFacetButton = ({
export interface EuiFacetButtonProps {
buttonRef?: RefCallback<HTMLButtonElement>;
children: ReactNode;
/**
* Any node, but preferrably a `EuiIcon` or `EuiAvatar`
*/
icon?: ReactNode;
isDisabled?: boolean;
/**
* Adds/swaps for loading spinner & disables
*/
isLoading?: boolean;
/**
* Changes visual of button to indicate it's currently selected
*/
isSelected?: boolean;
onClick?: MouseEventHandler<HTMLButtonElement>;
/**
* Adds a notification indicator for displaying the quantity provided
*/
quantity?: number;
}

export const EuiFacetButton: FunctionComponent<
CommonProps & HTMLAttributes<HTMLButtonElement> & EuiFacetButtonProps
> = ({
children,
className,
icon,
isDisabled,
isLoading,
isSelected,
isDisabled = false,
isLoading = false,
isSelected = false,
quantity,
buttonRef,
...rest
Expand Down Expand Up @@ -50,9 +81,9 @@ export const EuiFacetButton = ({
// Add an icon to the button if one exists.
let buttonIcon;

if (icon) {
if (React.isValidElement<{ className?: string }>(icon)) {
buttonIcon = React.cloneElement(icon, {
className: 'euiFacetButton__icon',
className: classNames(icon.props.className, 'euiFacetButton__icon'),
});
}

Expand All @@ -78,37 +109,3 @@ export const EuiFacetButton = ({
</button>
);
};

EuiFacetButton.propTypes = {
children: PropTypes.node.isRequired,
className: PropTypes.string,
isDisabled: PropTypes.bool,
onClick: PropTypes.func,
buttonRef: PropTypes.func,

/**
* Any node, but preferrably a `EuiIcon` or `EuiAvatar`
*/
icon: PropTypes.node,

/**
* Adds/swaps for loading spinner & disables
*/
isLoading: PropTypes.bool,

/**
* Changes visual of button to indicate it's currently selected
*/
isSelected: PropTypes.bool,

/**
* Adds a notification indicator for displaying the quantity provided
*/
quantity: PropTypes.number,
};

EuiFacetButton.defaultProps = {
isDisabled: false,
isLoading: false,
isSelected: false,
};
24 changes: 6 additions & 18 deletions src/components/facet/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
import {
ButtonHTMLAttributes,
HTMLAttributes,
ReactNode,
MouseEventHandler,
FunctionComponent,
} from 'react';
import { CommonProps, RefCallback } from '../common';
import { ButtonHTMLAttributes, HTMLAttributes, FunctionComponent } from 'react';
import { CommonProps } from '../common';
/// <reference path="../flex/index.d.ts" />

import { EuiFacetButtonProps as ButtonProps } from './facet_button';

declare module '@elastic/eui' {
/**
* Facet button type defs
*
* @see './facet_button.js'
*/

export interface EuiFacetButtonProps {
children: ReactNode;
icon?: ReactNode;
isDisabled?: boolean;
onClick?: MouseEventHandler<HTMLButtonElement>;
isLoading?: boolean;
isSelected?: boolean;
quantity: number;
buttonRef: RefCallback<HTMLButtonElement>;
}
export type EuiFacetButtonProps = ButtonProps;

export const EuiFacetButton: FunctionComponent<
CommonProps & ButtonHTMLAttributes<HTMLButtonElement> & EuiFacetButtonProps
>;
Expand Down

0 comments on commit 3da2a77

Please sign in to comment.