Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add display, descriptionWidth, textWrap and isInvalid props to EuiExpression #3467

Merged
merged 33 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c4d93cd
added truncate example, pending prop
andreadelrio May 12, 2020
faaa6ad
added prop
andreadelrio May 12, 2020
23dad35
added test and updated example
andreadelrio May 13, 2020
f03e8fe
add cl
andreadelrio May 13, 2020
0f13450
remove unneeded line
andreadelrio May 13, 2020
1bf1d04
added description to tooltip
andreadelrio May 13, 2020
60fa604
fix conflict
andreadelrio May 13, 2020
efe0e00
renamed prop, turned into enum
andreadelrio May 13, 2020
eb52280
example is function component
andreadelrio May 13, 2020
72b2918
Merge remote-tracking branch 'upstream/master' into expression-truncate
andreadelrio May 13, 2020
dfc860a
update snippet
andreadelrio May 13, 2020
89d3992
make the example more like alerting
andreadelrio May 18, 2020
d256cc7
new styles
andreadelrio May 27, 2020
cb0d1aa
fix conflict
andreadelrio May 27, 2020
cb9ebd1
basic combobox working
andreadelrio May 28, 2020
c4e396b
more progress on example
andreadelrio May 28, 2020
1caac1a
added align right
andreadelrio May 28, 2020
a392e3e
removed truncate
andreadelrio May 28, 2020
6e7585b
will rename column prop
andreadelrio May 28, 2020
1c1b811
renamed column prop
andreadelrio May 28, 2020
36bb3ec
cleanup
andreadelrio May 29, 2020
b1e01dc
updated tests and added handling of color
andreadelrio May 29, 2020
fc1ddf7
remove unneeded line
andreadelrio May 29, 2020
4128407
Review updates
May 29, 2020
b606ecc
Merge pull request #10 from cchaos/andreadelrio/expression-truncate
andreadelrio May 29, 2020
5cc964a
added invalid example
andreadelrio Jun 1, 2020
4e583f8
update test
andreadelrio Jun 1, 2020
f6d39f2
re-added textWrap prop =D
andreadelrio Jun 1, 2020
d15a4b4
update cl
andreadelrio Jun 1, 2020
52dec78
PR feedback
andreadelrio Jun 1, 2020
3e21df3
tiny styling fix
andreadelrio Jun 2, 2020
e0209b0
update CL
andreadelrio Jun 2, 2020
85b20b6
nits
andreadelrio Jun 2, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Added `partition` key to `EuiChartThemeType` for Partition chart support ([#3387](https://github.com/elastic/eui/pull/3387))
- Updated `EuiImage`'s `caption` prop type from `string` to `ReactNode` ([#3387](https://github.com/elastic/eui/pull/3387))
- Fixed `EuiCodeEditor` console error when using the editor without import the default theme ([#3454](https://github.com/elastic/eui/pull/3454))
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved
- Added `truncate` prop to `EuiExpression` ([#3467](https://github.com/elastic/eui/pull/3467))

**Bug Fixes**

Expand Down
34 changes: 34 additions & 0 deletions src-docs/src/views/expression/expression_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ const stringingSnippet = `<div>
/>
</div>`;

import Truncate from './truncate';
const truncateSource = require('!!raw-loader!./truncate');
const truncateHtml = renderToHtml(Truncate);
const truncateSnippet = `<EuiExpression
description="description"
value={value}
truncate={true}
/>`;

export const ExpressionExample = {
title: 'Expression',
sections: [
Expand Down Expand Up @@ -114,5 +123,30 @@ export const ExpressionExample = {
snippet: stringingSnippet,
demo: <Stringing />,
},
{
title: 'Truncate text',
source: [
{
type: GuideSectionTypes.JS,
code: truncateSource,
},
{
type: GuideSectionTypes.HTML,
code: truncateHtml,
},
],
text: (
<p>
There might be cases where you need to truncate the text, to do so use
the <EuiCode>truncate</EuiCode> prop. You can opt for this option when
space is limited and <strong>EuiExpression</strong>&apos;s value can
be quite long. When truncating, you can complement{' '}
<strong>EuiExpression</strong> with an <strong>EuiToolTip</strong>{' '}
displaying its full value.
</p>
),
snippet: truncateSnippet,
demo: <Truncate />,
},
],
};
105 changes: 105 additions & 0 deletions src-docs/src/views/expression/truncate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import React, { Component, HTMLAttributes } from 'react';
import { EuiExpression } from '../../../../src/components/expression';
import { EuiToolTip } from '../../../../src/components/tool_tip';
import { EuiPanel } from '../../../../src/components/panel';
import {
EuiPopoverTitle,
EuiPopover,
} from '../../../../src/components/popover';
import { EuiSelect } from '../../../../src/components/form/select';

export type TruncateProps = HTMLAttributes<HTMLDivElement>;

interface TruncateState {
isOpen: boolean;
value: string;
}

export default class extends Component<TruncateProps, TruncateState> {
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved
state = {
isOpen: false,
value: 'products.discount_percentage',
};

togglePopover = () => {
this.setState(prevState => ({
isOpen: !prevState.isOpen,
}));
};

closeExample = () => {
this.setState({
isOpen: false,
});
};

changeExample = (event: any) => {
this.setState({
value: event.target.value,
});
this.closeExample();
};

renderPopover = () => (
<div style={{ zIndex: 200 }}>
<EuiPopoverTitle>Average of</EuiPopoverTitle>
<EuiSelect
compressed
value={this.state.value}
onChange={e => this.changeExample(e)}
options={[
{
value: 'products.base_price',
text: 'products.base_price',
},
{
value: 'products.base_unit_price',
text: 'products.base_unit_price',
},
{
value: 'products.discount_percentage',
text: 'products.discount_percentage',
},
{ value: 'day_of_week_i', text: 'day_of_week_i' },
]}
/>
</div>
);

render() {
const popOver = (
<EuiPopover
button={
<EuiExpression
// truncate={true}
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved
style={{ maxWidth: '220px' }}
description="Average of"
value={this.state.value}
isActive={this.state.isOpen}
onClick={() => this.togglePopover()}
/>
}
isOpen={this.state.isOpen}
closePopover={() => this.closeExample()}
ownFocus
panelPaddingSize="s"
anchorPosition="downLeft">
{this.renderPopover()}
</EuiPopover>
);

return (
<div>
<EuiPanel paddingSize="l" style={{ width: '272px' }}>
{this.state.isOpen ? (
popOver
) : (
<EuiToolTip content={`AVERAGE OF ${this.state.value}`}>
{popOver}
</EuiToolTip>
)}
</EuiPanel>
</div>
);
}
}
20 changes: 19 additions & 1 deletion src/components/expression/__snapshots__/expression.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,25 @@ exports[`EuiExpression props isActive true renders active 1`] = `
</span>
`;

exports[`EuiExpression props uppercase false renders inherted case 1`] = `
exports[`EuiExpression props truncate true truncates text 1`] = `
<span
class="euiExpression euiExpression-isUppercase euiExpression-isTruncate euiExpression--secondary"
>
<span
class="euiExpression__description"
>
the answer is
</span>
<span
class="euiExpression__value"
>
42
</span>
</span>
`;

exports[`EuiExpression props uppercase false renders inherited case 1`] = `
<span
class="euiExpression euiExpression--secondary"
>
Expand Down
7 changes: 6 additions & 1 deletion src/components/expression/_expression.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
text-transform: uppercase;
}

.euiExpression-isTruncate {
@include euiTextTruncate;
vertical-align: bottom;
thompsongl marked this conversation as resolved.
Show resolved Hide resolved
}

.euiExpression-isClickable {
cursor: pointer;
border-bottom: $euiBorderEditable;
Expand Down Expand Up @@ -57,4 +62,4 @@
color: $color;
}
}
}
}
16 changes: 15 additions & 1 deletion src/components/expression/expression.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('EuiExpression', () => {
expect(render(component)).toMatchSnapshot();
});

test('false renders inherted case', () => {
test('false renders inherited case', () => {
const component = (
<EuiExpression
description="the answer is"
Expand All @@ -83,6 +83,20 @@ describe('EuiExpression', () => {
});
});

describe('truncate', () => {
test('true truncates text', () => {
const component = (
<EuiExpression
description="the answer is"
value="42"
truncate={true}
/>
);

expect(render(component)).toMatchSnapshot();
});
});

describe('isActive', () => {
test('true renders active', () => {
const component = (
Expand Down
6 changes: 6 additions & 0 deletions src/components/expression/expression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export type EuiExpressionProps = CommonProps & {
* Turns the component into a button and adds an editable style border at the bottom
*/
onClick?: MouseEventHandler<HTMLButtonElement>;
/**
* Truncates text
*/
truncate?: boolean;
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved
};

type Buttonlike = EuiExpressionProps &
Expand All @@ -85,6 +89,7 @@ export const EuiExpression: React.FunctionComponent<
valueProps,
color = 'secondary',
uppercase = true,
truncate = false,
isActive = false,
onClick,
...rest
Expand All @@ -96,6 +101,7 @@ export const EuiExpression: React.FunctionComponent<
'euiExpression-isActive': isActive,
'euiExpression-isClickable': onClick,
'euiExpression-isUppercase': uppercase,
'euiExpression-isTruncate': truncate,
},
colorToClassNameMap[color]
);
Expand Down