Skip to content

Commit 772d429

Browse files
author
Tom Lienard
authored
feat(Text): add dir prop (#2219)
* feat(Text): add `dir` prop * fix: update snapshots * fix: use correct type
1 parent bf586b8 commit 772d429

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import type { ComponentStory } from '@storybook/react'
2+
import { Text } from '../index'
3+
4+
export const Dir: ComponentStory<typeof Text> = () => (
5+
<>
6+
<strong>ltr</strong>
7+
<div style={{ marginBottom: 16, marginTop: 8, width: 500 }}>
8+
<Text as="div" variant="body" oneLine dir="ltr">
9+
This text is quite long. Lorem ipsum dolor sit amet, consectetur
10+
adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore
11+
magna aliqua.
12+
</Text>
13+
</div>
14+
<strong>rtl</strong>
15+
<div style={{ marginBottom: 16, marginTop: 8, width: 500 }}>
16+
<Text as="div" variant="body" oneLine dir="rtl">
17+
This text is quite long. Lorem ipsum dolor sit amet, consectetur
18+
adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore
19+
magna aliqua.
20+
</Text>
21+
</div>
22+
<strong>auto</strong>
23+
<div style={{ marginBottom: 16, marginTop: 8, width: 500 }}>
24+
<Text as="div" variant="body" oneLine dir="auto">
25+
This text is quite long. Lorem ipsum dolor sit amet, consectetur
26+
adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore
27+
magna aliqua.
28+
</Text>
29+
</div>
30+
</>
31+
)
32+
33+
Dir.parameters = {
34+
docs: {
35+
description: {
36+
story:
37+
'`dir` prop will change the direction of the `...` when using `oneLine`',
38+
},
39+
},
40+
}

packages/ui/src/components/Text/__stories__/index.stories.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ export { Disabled } from './Disabled.stories'
2323
export { Italic } from './Italic.stories'
2424
export { Underline } from './Underline.stories'
2525
export { OneLine } from './OneLine.stories'
26+
export { Dir } from './Dir.stories'

packages/ui/src/components/Text/__tests__/__snapshots__/index.test.tsx.snap

+30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`Text renders correctly with dir 1`] = `
4+
<DocumentFragment>
5+
.cache-gbpmfn-StyledText {
6+
color: #4a4f62;
7+
font-size: 16px;
8+
font-family: Asap;
9+
font-weight: 400;
10+
letter-spacing: 0;
11+
line-height: 24px;
12+
text-transform: none;
13+
-webkit-text-decoration: none;
14+
text-decoration: none;
15+
white-space: nowrap;
16+
text-overflow: ellipsis;
17+
overflow: hidden;
18+
}
19+
20+
<div
21+
style="margin-bottom: 16px; margin-top: 8px; width: 500px;"
22+
>
23+
<div
24+
class="cache-gbpmfn-StyledText e1tg3t120"
25+
dir="rtl"
26+
>
27+
This text is quite long. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
28+
</div>
29+
</div>
30+
</DocumentFragment>
31+
`;
32+
333
exports[`Text renders correctly with tooltip 1`] = `
434
<DocumentFragment>
535
.cache-gbpmfn-StyledText {

packages/ui/src/components/Text/__tests__/index.test.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ describe('Text', () => {
2121
</div>,
2222
))
2323

24+
test(`renders correctly with dir`, () =>
25+
shouldMatchEmotionSnapshot(
26+
<div style={{ marginBottom: 16, marginTop: 8, width: 500 }}>
27+
<Text as="div" variant="body" oneLine dir="rtl">
28+
This text is quite long. Lorem ipsum dolor sit amet, consectetur
29+
adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore
30+
magna aliqua.
31+
</Text>
32+
</div>,
33+
))
34+
2435
test(`with multiple nested chidldren renders correctly`, () =>
2536
shouldMatchEmotionSnapshot(
2637
<Text as="div" variant="body">

packages/ui/src/components/Text/index.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ type TextProps = {
8787
italic?: boolean
8888
underline?: boolean
8989
id?: string
90+
dir?: 'ltr' | 'rtl' | 'auto'
9091
}
9192

9293
const StyledText = styled('div', {
@@ -123,6 +124,7 @@ export const Text = ({
123124
italic = false,
124125
underline = false,
125126
id,
127+
dir,
126128
}: TextProps) => {
127129
const [isTruncated, setIsTruncated] = useState(false)
128130
const elementRef = useRef(null)
@@ -150,6 +152,7 @@ export const Text = ({
150152
italic={italic}
151153
underline={underline}
152154
id={id}
155+
dir={dir}
153156
>
154157
{children}
155158
</StyledText>

0 commit comments

Comments
 (0)