Skip to content

Commit

Permalink
Convert EuiListGroup to TypesCript
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover committed Aug 9, 2019
1 parent 1ad7de4 commit 08fb02c
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 280 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Allow `onClick` and `href` props on `ListGroupItem` ([#1933](https://github.com/elastic/eui/pull/1933))
- Allow `onClick` and `href` props on `EuiListGroupItem` and convert to TypeScript ([#1933](https://github.com/elastic/eui/pull/1933))

## [`13.3.0`](https://github.com/elastic/eui/tree/v13.3.0)

Expand Down
73 changes: 0 additions & 73 deletions src/components/list_group/index.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { EuiListGroup } from './list_group';

export { EuiListGroupItem } from './list_group_item';
114 changes: 0 additions & 114 deletions src/components/list_group/list_group.js

This file was deleted.

112 changes: 112 additions & 0 deletions src/components/list_group/list_group.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import React, { FunctionComponent, HTMLAttributes, CSSProperties } from 'react';
import classNames from 'classnames';

import { EuiListGroupItem, EuiListGroupItemProps } from './list_group_item';
import { CommonProps } from '../common';

type EuiListGroupProps = CommonProps &
HTMLAttributes<HTMLUListElement> & {
/**
* Add a border to the list container
*/
bordered?: boolean;

/**
* Remove container padding, stretching list items to the edges
*/
flush?: boolean;

/**
* Items to display in this group
*/
listItems?: EuiListGroupItemProps[];

/**
* Sets the max-width of the page,
* set to `true` to use the default size,
* set to `false` to not restrict the width,
* set to a number for a custom width in px,
* set to a string for a custom width in custom measurement.
*/
maxWidth?: boolean | number | string;

/**
* Display tooltips on all list items
*/
showToolTips?: boolean;

/**
* Allow link text to wrap
*/
wrapText?: boolean;
};

export const EuiListGroup: FunctionComponent<EuiListGroupProps> = ({
children,
className,
listItems,
style,
flush = false,
bordered = false,
wrapText = false,
maxWidth = true,
showToolTips = false,
...rest
}) => {
let newStyle: CSSProperties | undefined;
let widthClassName;
if (maxWidth !== true) {
let value: CSSProperties['maxWidth'];
if (typeof maxWidth === 'number') {
value = `${maxWidth}px`;
} else {
value = typeof maxWidth === 'string' ? maxWidth : undefined;
}

newStyle = { ...style, maxWidth: value };
} else if (maxWidth === true) {
widthClassName = 'euiListGroup-maxWidthDefault';
}

const classes = classNames(
'euiListGroup',
{
'euiListGroup-flush': flush,
'euiListGroup-bordered': bordered,
},
widthClassName,
className
);

let childrenOrListItems = null;
if (listItems) {
childrenOrListItems = listItems.map((item, index) => {
return [
<EuiListGroupItem
key={`title-${index}`}
showToolTip={showToolTips}
wrapText={wrapText}
{...item}
/>,
];
});
} else {
if (showToolTips) {
childrenOrListItems = React.Children.map(children, child => {
if (React.isValidElement(child)) {
return React.cloneElement<Partial<EuiListGroupItemProps>>(child, {
showToolTip: true,
});
}
});
} else {
childrenOrListItems = children;
}
}

return (
<ul className={classes} style={newStyle || style} {...rest}>
{childrenOrListItems}
</ul>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('EuiListGroupItem', () => {

describe('throws an warning', () => {
const oldConsoleError = console.warn;
let consoleStub;
let consoleStub: jest.Mock;

beforeEach(() => {
// We don't use jest.spyOn() here, because EUI's tests apply a global
Expand Down
Loading

0 comments on commit 08fb02c

Please sign in to comment.