Skip to content

Commit a7077ec

Browse files
author
Eric Olkowski
committed
Converted existing examples to TS
1 parent f19ee77 commit a7077ec

6 files changed

Lines changed: 42 additions & 33 deletions

File tree

packages/react-core/src/components/Truncate/examples/Truncate.md

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,58 +15,32 @@ The default behavior of the `Truncate` component is to truncate based on whether
1515

1616
By default content will be truncated at its end when it cannot fit entirely inside its parent container.
1717

18-
```js
19-
import { Truncate } from '@patternfly/react-core';
18+
```ts file="./TruncateDefault.tsx"
2019

21-
<div className="truncate-example-resize">
22-
<Truncate content={'Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.'} />
23-
</div>;
2420
```
2521

2622
### Middle
2723

2824
When passing a `position` property with a value of "middle", the position of the truncation will change based on the parent container's width and the amount of `trailingNumChars` passed in. The `trailingNumChars` will always be displayed, while the rest of the content will be truncated based on the parent container width.
2925

30-
```js
31-
import { Truncate } from '@patternfly/react-core';
26+
```ts file="./TruncateMiddle.tsx"
3227

33-
<div className="truncate-example-resize">
34-
<Truncate
35-
content={'redhat_logo_black_and_white_reversed_simple_with_fedora_container.zip'}
36-
trailingNumChars={10}
37-
position={'middle'}
38-
/>
39-
</div>;
4028
```
4129

4230
### Start
4331

4432
You can truncate content at its start by passing the `position` property with a value of "start". This can be useful if you have several strings to truncate that have similar text at the start, but unique text at the end that you want to have visible.
4533

46-
```js
47-
import { Truncate } from '@patternfly/react-core';
34+
```ts file="./TruncateStart.tsx"
4835

49-
<div className="truncate-example-resize">
50-
<Truncate
51-
content={'Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.'}
52-
position={'start'}
53-
/>
54-
</div>;
5536
```
5637

5738
### With custom tooltip position
5839

5940
You can customize the position of the `<Tooltip>` that is rendered by passing in the `tooltipPosition` property. The following example overrides the default "top" position with a "bottom" position.
6041

61-
```js
62-
import { Truncate } from '@patternfly/react-core';
42+
```ts file="./TruncateCustomTooltipPosition.tsx"
6343

64-
<div className="truncate-example-resize">
65-
<Truncate
66-
content={'Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.'}
67-
tooltipPosition={'bottom'}
68-
/>
69-
</div>;
7044
```
7145

7246
### Based on max characters
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Truncate } from '@patternfly/react-core';
2+
3+
export const TruncateCustomTooltipPosition: React.FunctionComponent = () => (
4+
<div className="truncate-example-resize">
5+
<Truncate
6+
content={'redhat_logo_black_and_white_reversed_simple_with_fedora_container.zip'}
7+
tooltipPosition={'bottom'}
8+
/>
9+
</div>
10+
);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Truncate } from '@patternfly/react-core';
2+
3+
export const TruncateDefault: React.FunctionComponent = () => (
4+
<div className="truncate-example-resize">
5+
<Truncate content={'redhat_logo_black_and_white_reversed_simple_with_fedora_container.zip'} />
6+
</div>
7+
);

packages/react-core/src/components/Truncate/examples/TruncateMaxChars.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ export const TruncateMaxChars: React.FunctionComponent = () => (
55
<div>Truncated at end position:</div>
66
<Truncate
77
maxCharsDisplayed={15}
8-
content={'Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.'}
8+
content={'redhat_logo_black_and_white_reversed_simple_with_fedora_container.zip'}
99
/>
1010
<br />
1111
<br />
1212
<div>Truncated at middle position:</div>
1313
<Truncate
1414
maxCharsDisplayed={15}
1515
position={TruncatePosition.middle}
16-
content={'Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.'}
16+
content={'redhat_logo_black_and_white_reversed_simple_with_fedora_container.zip'}
1717
/>
1818
<br />
1919
<br />
2020
<div>Truncated at start position:</div>
2121
<Truncate
2222
maxCharsDisplayed={15}
2323
position={TruncatePosition.start}
24-
content={'Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.'}
24+
content={'redhat_logo_black_and_white_reversed_simple_with_fedora_container.zip'}
2525
/>
2626
</>
2727
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Truncate } from '@patternfly/react-core';
2+
3+
export const TruncateMiddle: React.FunctionComponent = () => (
4+
<div className="truncate-example-resize">
5+
<Truncate
6+
content={'redhat_logo_black_and_white_reversed_simple_with_fedora_container.zip'}
7+
trailingNumChars={10}
8+
position={'middle'}
9+
/>
10+
</div>
11+
);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Truncate } from '@patternfly/react-core';
2+
3+
export const TruncateStart: React.FunctionComponent = () => (
4+
<div className="truncate-example-resize">
5+
<Truncate content={'redhat_logo_black_and_white_reversed_simple_with_fedora_container.zip'} position={'start'} />
6+
</div>
7+
);

0 commit comments

Comments
 (0)