From b435d22161648eda9efd4e0416f08184ec0a124a Mon Sep 17 00:00:00 2001
From: cchaos
Date: Tue, 3 Mar 2020 20:59:40 -0500
Subject: [PATCH 1/5] [EuiListGroup] Added `gutterSize`
---
.../__snapshots__/list_group.test.tsx.snap | 143 +++++++++++++++++-
src/components/list_group/_index.scss | 2 +
src/components/list_group/_list_group.scss | 15 +-
.../list_group/_list_group_item.scss | 5 -
src/components/list_group/_variables.scss | 4 +
src/components/list_group/list_group.test.tsx | 89 ++++++++++-
src/components/list_group/list_group.tsx | 19 ++-
.../__snapshots__/nav_drawer.test.js.snap | 16 +-
8 files changed, 273 insertions(+), 20 deletions(-)
create mode 100644 src/components/list_group/_variables.scss
diff --git a/src/components/list_group/__snapshots__/list_group.test.tsx.snap b/src/components/list_group/__snapshots__/list_group.test.tsx.snap
index fbd22fd489e..72252c29443 100644
--- a/src/components/list_group/__snapshots__/list_group.test.tsx.snap
+++ b/src/components/list_group/__snapshots__/list_group.test.tsx.snap
@@ -3,7 +3,148 @@
exports[`EuiListGroup is rendered 1`] = `
`;
+
+exports[`EuiListGroup is rendered with listItems 1`] = `
+
+`;
+
+exports[`EuiListGroup props bordered is rendered 1`] = `
+
+`;
+
+exports[`EuiListGroup props flush is rendered 1`] = `
+
+`;
+
+exports[`EuiListGroup props gutter size m is rendered 1`] = `
+
+`;
+
+exports[`EuiListGroup props gutter size none is rendered 1`] = `
+
+`;
+
+exports[`EuiListGroup props gutter size s is rendered 1`] = `
+
+`;
+
+exports[`EuiListGroup props maxWidth as a number is rendered 1`] = `
+
+`;
+
+exports[`EuiListGroup props maxWidth as a string is rendered 1`] = `
+
+`;
+
+exports[`EuiListGroup props maxWidth as true is rendered 1`] = `
+
+`;
+
+exports[`EuiListGroup props showToolTips is rendered 1`] = `
+
+`;
+
+exports[`EuiListGroup props wrapText is rendered 1`] = `
+
+`;
diff --git a/src/components/list_group/_index.scss b/src/components/list_group/_index.scss
index 9d6423c4f21..a841513f7c6 100644
--- a/src/components/list_group/_index.scss
+++ b/src/components/list_group/_index.scss
@@ -1,5 +1,7 @@
// List group provides a way to neatly present a set of text-based items
@import '../header/variables';
+@import 'variables';
+
@import 'list_group';
@import 'list_group_item';
diff --git a/src/components/list_group/_list_group.scss b/src/components/list_group/_list_group.scss
index 9e8fa0373e3..58b32426526 100644
--- a/src/components/list_group/_list_group.scss
+++ b/src/components/list_group/_list_group.scss
@@ -2,13 +2,9 @@
* The List Group component provides neatly styled lists containing plain text
* or links. The outer container can be bordered, with padding, or borderless
* with links flush to the sides.
- *(
- * List items can be displayed with active and disabled states.
*/
.euiListGroup {
- padding: $euiSizeS;
-
&.euiListGroup-flush {
padding: 0;
border: none;
@@ -23,3 +19,14 @@
.euiListGroup-maxWidthDefault {
max-width: $euiFormMaxWidth;
}
+
+// Gutter Sizes
+@each $gutterName, $gutterSize in $euiListGroupGutterTypes {
+ .euiListGroup--#{$gutterName} {
+ padding: $gutterSize;
+
+ .euiListGroupItem:not(:first-of-type) {
+ margin-top: $gutterSize;
+ }
+ }
+}
diff --git a/src/components/list_group/_list_group_item.scss b/src/components/list_group/_list_group_item.scss
index e0434fc62a2..2910f5969c2 100644
--- a/src/components/list_group/_list_group_item.scss
+++ b/src/components/list_group/_list_group_item.scss
@@ -1,6 +1,5 @@
.euiListGroupItem {
padding: 0;
- margin-top: $euiSizeS;
border-radius: $euiBorderRadius;
overflow: hidden;
display: flex;
@@ -8,10 +7,6 @@
transition: background-color $euiAnimSpeedFast;
position: relative;
- &:first-child {
- margin-top: 0;
- }
-
&.euiListGroupItem-isActive,
&.euiListGroupItem-isClickable:hover {
background-color: tintOrShade($euiColorLightestShade, 0%, 30%);
diff --git a/src/components/list_group/_variables.scss b/src/components/list_group/_variables.scss
new file mode 100644
index 00000000000..27dfdc8d3d0
--- /dev/null
+++ b/src/components/list_group/_variables.scss
@@ -0,0 +1,4 @@
+$euiListGroupGutterTypes: (
+ gutterS: $euiSizeS,
+ gutterM: $euiSize,
+);
diff --git a/src/components/list_group/list_group.test.tsx b/src/components/list_group/list_group.test.tsx
index 9808ec3880f..d22dbecf23b 100644
--- a/src/components/list_group/list_group.test.tsx
+++ b/src/components/list_group/list_group.test.tsx
@@ -2,7 +2,32 @@ import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../test/required_props';
-import { EuiListGroup } from './list_group';
+import { EuiListGroup, GUTTER_SIZES } from './list_group';
+import { EuiListGroupItemProps } from './list_group_item';
+
+const someListItems: EuiListGroupItemProps[] = [
+ {
+ label: 'Label with iconType',
+ iconType: 'stop',
+ },
+ {
+ label: 'Custom extra action',
+ extraAction: {
+ iconType: 'bell',
+ alwaysShow: true,
+ },
+ },
+ {
+ label: 'Button with onClick',
+ onClick: e => {
+ console.log('Visualize clicked', e);
+ },
+ },
+ {
+ label: 'Link with href',
+ href: '#',
+ },
+];
describe('EuiListGroup', () => {
test('is rendered', () => {
@@ -10,4 +35,66 @@ describe('EuiListGroup', () => {
expect(component).toMatchSnapshot();
});
+
+ test('is rendered with listItems', () => {
+ const component = render();
+
+ expect(component).toMatchSnapshot();
+ });
+
+ describe('props', () => {
+ test('bordered is rendered', () => {
+ const component = render();
+
+ expect(component).toMatchSnapshot();
+ });
+
+ test('flush is rendered', () => {
+ const component = render();
+
+ expect(component).toMatchSnapshot();
+ });
+
+ test('showToolTips is rendered', () => {
+ const component = render();
+
+ expect(component).toMatchSnapshot();
+ });
+
+ test('wrapText is rendered', () => {
+ const component = render();
+
+ expect(component).toMatchSnapshot();
+ });
+
+ describe('gutter size', () => {
+ GUTTER_SIZES.forEach(gutter => {
+ test(`${gutter} is rendered`, () => {
+ const component = render();
+
+ expect(component).toMatchSnapshot();
+ });
+ });
+ });
+
+ describe('maxWidth', () => {
+ test('as true is rendered', () => {
+ const component = render();
+
+ expect(component).toMatchSnapshot();
+ });
+
+ test('as a number is rendered', () => {
+ const component = render();
+
+ expect(component).toMatchSnapshot();
+ });
+
+ test('as a string is rendered', () => {
+ const component = render();
+
+ expect(component).toMatchSnapshot();
+ });
+ });
+ });
});
diff --git a/src/components/list_group/list_group.tsx b/src/components/list_group/list_group.tsx
index 1d6354f8867..b79a1d388de 100644
--- a/src/components/list_group/list_group.tsx
+++ b/src/components/list_group/list_group.tsx
@@ -4,6 +4,16 @@ import classNames from 'classnames';
import { EuiListGroupItem, EuiListGroupItemProps } from './list_group_item';
import { CommonProps } from '../common';
+type GutterSize = 'none' | 's' | 'm';
+const gutterSizeToClassNameMap: { [size in GutterSize]: string } = {
+ none: '',
+ s: 'euiListGroup--gutterS',
+ m: 'euiListGroup--gutterM',
+};
+export const GUTTER_SIZES = Object.keys(
+ gutterSizeToClassNameMap
+) as GutterSize[];
+
export type EuiListGroupProps = CommonProps &
HTMLAttributes & {
/**
@@ -16,6 +26,11 @@ export type EuiListGroupProps = CommonProps &
*/
flush?: boolean;
+ /**
+ * Spacing between list items
+ */
+ gutterSize?: GutterSize;
+
/**
* Items to display in this group. See #EuiListGroupItem
*/
@@ -36,7 +51,7 @@ export type EuiListGroupProps = CommonProps &
showToolTips?: boolean;
/**
- * Allow link text to wrap
+ * Allow link text to wrap vs truncated
*/
wrapText?: boolean;
ariaLabelledby?: string;
@@ -49,6 +64,7 @@ export const EuiListGroup: FunctionComponent = ({
style,
flush = false,
bordered = false,
+ gutterSize = 's',
wrapText = false,
maxWidth = true,
showToolTips = false,
@@ -76,6 +92,7 @@ export const EuiListGroup: FunctionComponent = ({
'euiListGroup-flush': flush,
'euiListGroup-bordered': bordered,
},
+ gutterSizeToClassNameMap[gutterSize],
widthClassName,
className
);
diff --git a/src/components/nav_drawer/__snapshots__/nav_drawer.test.js.snap b/src/components/nav_drawer/__snapshots__/nav_drawer.test.js.snap
index 01827dde7fa..b8b6c6384b4 100644
--- a/src/components/nav_drawer/__snapshots__/nav_drawer.test.js.snap
+++ b/src/components/nav_drawer/__snapshots__/nav_drawer.test.js.snap
@@ -15,7 +15,7 @@ exports[`EuiNavDrawer is rendered 1`] = `
id="navDrawerMenu"
>
),
demo: ,
+ snippet: `
+
+`,
},
{
title: 'List item color and size',
@@ -154,6 +200,11 @@ export const ListGroupExample = {
>
),
demo: ,
+ snippet: ``,
},
],
};
diff --git a/src-docs/src/views/list_group/list_group_link_actions.js b/src-docs/src/views/list_group/list_group_link_actions.js
index 129681e17db..e3e31b1df89 100644
--- a/src-docs/src/views/list_group/list_group_link_actions.js
+++ b/src-docs/src/views/list_group/list_group_link_actions.js
@@ -1,24 +1,14 @@
-import React, { Component, Fragment } from 'react';
+import React, { Component } from 'react';
-import {
- EuiListGroup,
- EuiListGroupItem,
- EuiSpacer,
- EuiSwitch,
- EuiCode,
- EuiFlexGroup,
- EuiFlexItem,
-} from '../../../../src/components';
+import { EuiListGroup, EuiListGroupItem } from '../../../../src/components';
export default class extends Component {
constructor(props) {
super(props);
this.state = {
- flushWidth: false,
- showBorder: false,
favorite1: undefined,
- favorite2: undefined,
+ favorite2: 'link2',
favorite3: undefined,
};
}
@@ -65,106 +55,71 @@ export default class extends Component {
};
render() {
- const {
- flushWidth,
- showBorder,
- favorite1,
- favorite2,
- favorite3,
- } = this.state;
+ const { favorite1, favorite2, favorite3 } = this.state;
return (
-
-
-
-
- Show as flush
-
- }
- checked={this.state.flushWidth}
- onChange={this.toggleFlushWidth}
- />
-
-
-
- Show as bordered
-
- }
- checked={this.state.showBorder}
- onChange={this.toggleBorder}
- />
-
-
+
+ window.alert('Button clicked')}
+ isActive
+ extraAction={{
+ color: 'subdued',
+ onClick: this.link1Clicked,
+ iconType: favorite1 === 'link1' ? 'pinFilled' : 'pin',
+ iconSize: 's',
+ 'aria-label': 'Favorite link1',
+ alwaysShow: favorite1 === 'link1',
+ }}
+ />
-
+ window.alert('Button clicked')}
+ label="EUI button link"
+ extraAction={{
+ color: 'subdued',
+ onClick: this.link2Clicked,
+ iconType: favorite2 === 'link2' ? 'pinFilled' : 'pin',
+ iconSize: 's',
+ 'aria-label': 'Favorite link2',
+ alwaysShow: favorite2 === 'link2',
+ }}
+ />
-
- window.alert('Button clicked')}
- isActive
- extraAction={{
- color: 'subdued',
- onClick: this.link1Clicked,
- iconType: favorite1 === 'link1' ? 'pinFilled' : 'pin',
- iconSize: 's',
- 'aria-label': 'Favorite link1',
- alwaysShow: favorite1 === 'link1',
- }}
- />
+ window.alert('Button clicked')}
+ iconType="broom"
+ label="EUI button link"
+ extraAction={{
+ color: 'subdued',
+ onClick: this.link3Clicked,
+ iconType: favorite3 === 'link3' ? 'pinFilled' : 'pin',
+ iconSize: 's',
+ 'aria-label': 'Favorite link3',
+ alwaysShow: favorite3 === 'link3',
+ isDisabled: true,
+ }}
+ />
- window.alert('Button clicked')}
- label="EUI button link"
- extraAction={{
- color: 'subdued',
- onClick: this.link2Clicked,
- iconType: favorite2 === 'link2' ? 'pinFilled' : 'pin',
- iconSize: 's',
- 'aria-label': 'Favorite link2',
- alwaysShow: favorite2 === 'link2',
- }}
- />
-
- window.alert('Button clicked')}
- iconType="broom"
- label="EUI button link"
- extraAction={{
- color: 'subdued',
- onClick: this.link3Clicked,
- iconType: favorite3 === 'link3' ? 'pinFilled' : 'pin',
- iconSize: 's',
- 'aria-label': 'Favorite link3',
- alwaysShow: favorite3 === 'link3',
- isDisabled: true,
- }}
- />
-
- window.alert('Action clicked'),
- iconType: 'pin',
- iconSize: 's',
- 'aria-label': 'Favorite link4',
- }}
- />
-
-
+ window.alert('Action clicked'),
+ iconType: 'pin',
+ iconSize: 's',
+ 'aria-label': 'Favorite link4',
+ }}
+ />
+
);
}
}
diff --git a/src-docs/src/views/list_group/list_group_links.js b/src-docs/src/views/list_group/list_group_links.js
index c2660d17137..c0c5e7198ac 100644
--- a/src-docs/src/views/list_group/list_group_links.js
+++ b/src-docs/src/views/list_group/list_group_links.js
@@ -1,13 +1,6 @@
-import React, { Component, Fragment } from 'react';
+import React from 'react';
-import {
- EuiListGroup,
- EuiSpacer,
- EuiSwitch,
- EuiCode,
- EuiFlexGroup,
- EuiFlexItem,
-} from '../../../../src/components';
+import { EuiListGroup } from '../../../../src/components';
const myContent = [
{
@@ -44,62 +37,6 @@ const myContent = [
},
];
-export default class extends Component {
- constructor(props) {
- super(props);
-
- this.state = {
- flushWidth: false,
- showBorder: false,
- };
- }
-
- toggleFlushWidth = () => {
- this.setState(prevState => ({ flushWidth: !prevState.flushWidth }));
- };
-
- toggleBorder = () => {
- this.setState(prevState => ({ showBorder: !prevState.showBorder }));
- };
-
- render() {
- const { flushWidth, showBorder } = this.state;
-
- return (
-
-
-
-
- Show as flush
-
- }
- checked={this.state.flushWidth}
- onChange={this.toggleFlushWidth}
- />
-
-
-
- Show as bordered
-
- }
- checked={this.state.showBorder}
- onChange={this.toggleBorder}
- />
-
-
-
-
-
-
-
- );
- }
-}
+export default () => {
+ return ;
+};
From f490759fe43b0ca3ff0f143f01b315b38bd2bb4c Mon Sep 17 00:00:00 2001
From: cchaos
Date: Tue, 3 Mar 2020 22:09:31 -0500
Subject: [PATCH 4/5] Cleanup
---
src/components/list_group/_index.scss | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/components/list_group/_index.scss b/src/components/list_group/_index.scss
index a841513f7c6..bf49f315ffe 100644
--- a/src/components/list_group/_index.scss
+++ b/src/components/list_group/_index.scss
@@ -1,6 +1,3 @@
-// List group provides a way to neatly present a set of text-based items
-
-@import '../header/variables';
@import 'variables';
@import 'list_group';
From 7995d2dc40cbe5e5d002aadcd7e9a81a1d3a1c8f Mon Sep 17 00:00:00 2001
From: cchaos
Date: Thu, 5 Mar 2020 10:46:41 -0500
Subject: [PATCH 5/5] cl
---
CHANGELOG.md | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d4a73b2e4a5..bb3b3aff7b9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)
-No public interface changes since `20.1.0`.
+- Added `gutterSize` prop to `EuiListGroup` ([#2980](https://github.com/elastic/eui/pull/2980))
+- Added `color` prop to `EuiListGroupItem` and updated size style ([#2980](https://github.com/elastic/eui/pull/2980))
## [`20.1.0`](https://github.com/elastic/eui/tree/v20.1.0)