Skip to content

Commit

Permalink
Allow href and onClick in ListGroupItem (elastic#1933)
Browse files Browse the repository at this point in the history
* Allow href and onClick in ListGroupItem

* Convert EuiListGroup to TypeScript

* PR comments
  • Loading branch information
joshdover authored and thompsongl committed Sep 10, 2019
1 parent 6e56e1b commit 51e13e5
Show file tree
Hide file tree
Showing 10 changed files with 252 additions and 307 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Converted `EuiFacetButton` to TypeScript ([#2226](https://github.com/elastic/eui/pull/2226))
- Adds an optional `onClear` prop to the the `EuiDatePicker` component ([#2235](https://github.com/elastic/eui/pull/2235))
- Added support for `onClick` and `href` props on `EuiListGroupItem` and converted to TypeScript ([#1933](https://github.com/elastic/eui/pull/1933))

**Bug fixes**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ exports[`EuiListGroupItem props extraAction is rendered 1`] = `
</li>
`;

exports[`EuiListGroupItem props href and onClick is rendered 1`] = `
<li
class="euiListGroupItem euiListGroupItem--medium euiListGroupItem-isClickable"
>
<a
class="euiListGroupItem__button"
href="#"
>
<span
class="euiListGroupItem__label"
title=""
/>
</a>
</li>
`;

exports[`EuiListGroupItem props href is rendered 1`] = `
<li
class="euiListGroupItem euiListGroupItem--medium euiListGroupItem-isClickable"
Expand Down Expand Up @@ -308,19 +324,3 @@ exports[`EuiListGroupItem throws an warning if both iconType and icon are provid
</span>
</li>
`;

exports[`EuiListGroupItem throws an warning if both onClick and href are provided but still renders 1`] = `
<li
class="euiListGroupItem euiListGroupItem--medium euiListGroupItem-isClickable"
>
<a
class="euiListGroupItem__button"
href="#"
>
<span
class="euiListGroupItem__label"
title=""
/>
</a>
</li>
`;
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>
);
};
Loading

0 comments on commit 51e13e5

Please sign in to comment.