-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
223 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
src/components/list_group/index.js → src/components/list_group/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.