Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `18.2.0`.
- Convert `EuiFilterButton` to TS ([#2761](https://github.com/elastic/eui/pull/2761))
- Convert `EuiFilterSelectItem` to TS ([#2761](https://github.com/elastic/eui/pull/2761))

## [`18.2.0`](https://github.com/elastic/eui/tree/v18.2.0)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,59 @@
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import React, { Fragment, FunctionComponent, ReactChild } from 'react';
import classNames from 'classnames';

import { EuiI18n } from '../i18n';
import { EuiNotificationBadge } from '../badge/notification_badge';
import { COLORS, ICON_SIDES, EuiButtonEmpty } from '../button/button_empty';

import { IconPropType } from '../icon';
import { EuiButtonEmpty, EuiButtonEmptyProps } from '../button/button_empty';

import { useInnerText } from '../inner_text';

export const EuiFilterButton = ({
export type EuiFilterButtonProps = EuiButtonEmptyProps & {
/**
* Bolds the button if true
*/
hasActiveFilters?: boolean;
/**
* Pass the total number of filters available and it will
* add a subdued notification badge showing the number
*/
numFilters?: number;
/**
* Pass the number of selected filters and it will
* add a bright notification badge showing the number
*/
numActiveFilters?: number;
/**
* Applies a visual state to the button useful when using with a popover.
*/
isSelected?: boolean;
/**
* Should the button grow to fill its container, best used for dropdown buttons
*/
grow?: boolean;
/**
* Remove border after button, good for opposite filters
*/
withNext?: boolean;
/**
* _DEPRECATED: use `withNext`_
* Remove border after button, good for opposite filters
*/
noDivider?: boolean;
};

export const EuiFilterButton: FunctionComponent<EuiFilterButtonProps> = ({
children,
className,
iconType,
iconSide,
color,
iconSide = 'right',
color = 'text',
hasActiveFilters,
numFilters,
numActiveFilters,
isDisabled,
isSelected,
type,
grow,
type = 'button',
grow = true,
noDivider,
withNext,
textProps,
Expand Down Expand Up @@ -73,15 +104,18 @@ export const EuiFilterButton = ({
default={({ count, hasActiveFilters }) =>
`${count} ${hasActiveFilters ? 'active' : 'available'} filters`
}>
{filterBadge => (
<EuiNotificationBadge
className="euiFilterButton__notification"
size="m"
aria-label={filterBadge}
color={isDisabled || !hasActiveFilters ? 'subdued' : 'accent'}>
{numActiveFilters || numFilters}
</EuiNotificationBadge>
)}
{(filterBadge: ReactChild) => {
Comment thread
thompsongl marked this conversation as resolved.
Outdated
const ariaLabel = filterBadge as string;
return (
<EuiNotificationBadge
className="euiFilterButton__notification"
size="m"
aria-label={ariaLabel}
color={isDisabled || !hasActiveFilters ? 'subdued' : 'accent'}>
{numActiveFilters || numFilters}
</EuiNotificationBadge>
);
}}
</EuiI18n>
)}
</Fragment>
Expand All @@ -101,58 +135,3 @@ export const EuiFilterButton = ({
</EuiButtonEmpty>
);
};

EuiFilterButton.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
onClick: PropTypes.func,
/**
* Use any one of our icons
*/
iconType: IconPropType,
iconSide: PropTypes.oneOf(ICON_SIDES),
color: PropTypes.oneOf(COLORS),
/**
* Bolds the button if true
*/
hasActiveFilters: PropTypes.bool,
/**
* Pass the total number of filters available and it will
* add a subdued notification badge showing the number
*/
numFilters: PropTypes.number,
/**
* Pass the number of selected filters and it will
* add a bright notification badge showing the number
*/
numActiveFilters: PropTypes.number,
/**
* Applies a visual state to the button useful when using with a popover.
*/
isSelected: PropTypes.bool,
isDisabled: PropTypes.bool,
/**
* Defines html button input type
*/
type: PropTypes.string,
/**
* Should the button grow to fill its container, best used for dropdown buttons
*/
grow: PropTypes.bool,
/**
* Remove border after button, good for opposite filters
*/
withNext: PropTypes.bool,
/**
* _DEPRECATED: use `withNext`_
* Remove border after button, good for opposite filters
*/
noDivider: PropTypes.bool,
};

EuiFilterButton.defaultProps = {
type: 'button',
iconSide: 'right',
color: 'text',
grow: true,
};
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import React, { ButtonHTMLAttributes, Component } from 'react';
import classNames from 'classnames';

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

import { EuiFlexGroup, EuiFlexItem } from '../flex';

import { EuiIcon } from '../icon';

const CHECKED_ON = 'on';
const CHECKED_OFF = 'off';
export type FilterChecked = 'on' | 'off';
export interface EuiFilterSelectItemProps
extends CommonProps,
ButtonHTMLAttributes<HTMLButtonElement> {
checked?: FilterChecked;
showIcons?: boolean;
isFocused?: boolean;
}

const resolveIconAndColor = checked => {
const resolveIconAndColor = (checked?: FilterChecked) => {
if (!checked) {
return { icon: 'empty' };
}
return checked === CHECKED_ON
return checked === 'on'
? { icon: 'check', color: 'text' }
: { icon: 'cross', color: 'text' };
};

export class EuiFilterSelectItem extends Component {
constructor(props) {
super(props);
this.state = { hasFocus: false };
}
export class EuiFilterSelectItem extends Component<EuiFilterSelectItemProps> {
static defaultProps = {
showIcons: true,
};

buttonRef: HTMLButtonElement | null = null;
mounted: boolean = false;
Comment thread
thompsongl marked this conversation as resolved.
Outdated

state = {
hasFocus: false,
};

focus = () => {
if (this.buttonRef) {
Expand Down Expand Up @@ -98,18 +111,3 @@ export class EuiFilterSelectItem extends Component {
);
}
}

EuiFilterSelectItem.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
/**
* Applies an icon and visual styling to activated items
*/
checked: PropTypes.oneOf([CHECKED_ON, CHECKED_OFF]),
onClick: PropTypes.func,
showIcons: PropTypes.bool,
};

EuiFilterSelectItem.defaultProps = {
showIcons: true,
};
70 changes: 0 additions & 70 deletions src/components/filter_group/index.d.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/components/filter_group/index.js

This file was deleted.

9 changes: 9 additions & 0 deletions src/components/filter_group/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export { EuiFilterGroup, EuiFilterGroupProps } from './filter_group';

export { EuiFilterButton, EuiFilterButtonProps } from './filter_button';

export {
EuiFilterSelectItem,
EuiFilterSelectItemProps,
FilterChecked,
} from './filter_select_item';
1 change: 0 additions & 1 deletion src/components/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// <reference path="./code/index.d.ts" />
/// <reference path="./combo_box/index.d.ts" />
/// <reference path="./date_picker/index.d.ts" />
/// <reference path="./filter_group/index.d.ts" />
/// <reference path="./form/index.d.ts" />
/// <reference path="./modal/index.d.ts" />
/// <reference path="./tabs/index.d.ts" />
Expand Down
Loading