@indico-data/design-system 1.0.49 → 1.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/index.d.ts +1 -0
- package/lib/components/text-truncate/TextTruncate.d.ts +7 -0
- package/lib/components/text-truncate/TextTruncate.styles.d.ts +2 -0
- package/lib/components/text-truncate/TextTruncate.test.d.ts +1 -0
- package/lib/components/text-truncate/index.d.ts +1 -0
- package/lib/index.d.ts +8 -1
- package/lib/index.esm.js +9 -3
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +9 -2
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/WizardWithSidebar/WizardWithSidebar.styles.ts +2 -2
- package/src/components/index.ts +1 -0
- package/src/components/text-truncate/TextTruncate.stories.mdx +59 -0
- package/src/components/text-truncate/TextTruncate.styles.ts +3 -0
- package/src/components/text-truncate/TextTruncate.test.tsx +18 -0
- package/src/components/text-truncate/TextTruncate.tsx +21 -0
- package/src/components/text-truncate/index.ts +1 -0
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -26,13 +26,13 @@ export const StyledWizardWithSidebar = styled.div<{
|
|
|
26
26
|
.wizard-sidebar {
|
|
27
27
|
width: 245px;
|
|
28
28
|
padding: 30px;
|
|
29
|
-
border-right: 1px solid
|
|
29
|
+
border-right: 1px solid ${COLORS.silverChalice};
|
|
30
30
|
|
|
31
31
|
.sidebar-step {
|
|
32
32
|
margin-bottom: ${SPACING.sm};
|
|
33
33
|
display: flex;
|
|
34
34
|
align-items: center;
|
|
35
|
-
color:
|
|
35
|
+
color: ${COLORS.silverChalice};
|
|
36
36
|
&.current-step,
|
|
37
37
|
&.prior-step {
|
|
38
38
|
color: ${COLORS.black};
|
package/src/components/index.ts
CHANGED
|
@@ -30,3 +30,4 @@ export { LoadingAwareContainer } from './LoadingAwareContainer';
|
|
|
30
30
|
export { Wizard, WizardCard, WizardSection, StyledWizard } from './Wizard';
|
|
31
31
|
export { WizardWithSidebar } from './WizardWithSidebar';
|
|
32
32
|
export { Drawer } from './Navigation/Drawer';
|
|
33
|
+
export { TextTruncate } from './text-truncate';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Meta, Story, Canvas, ArgsTable } from '@storybook/addon-docs/blocks';
|
|
2
|
+
import { TextTruncate } from './TextTruncate';
|
|
3
|
+
|
|
4
|
+
<Meta
|
|
5
|
+
title="Text Utilities/TextTruncate"
|
|
6
|
+
component={TextTruncate}
|
|
7
|
+
argTypes={{
|
|
8
|
+
string: {
|
|
9
|
+
description: 'The string to truncate.',
|
|
10
|
+
control: {
|
|
11
|
+
type: 'text',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
maxChars: {
|
|
15
|
+
control: {
|
|
16
|
+
type: 'number',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
}}
|
|
20
|
+
/>
|
|
21
|
+
|
|
22
|
+
# Text Truncate
|
|
23
|
+
|
|
24
|
+
This component truncates the provided text if the character limit exceeds the Max Character Length
|
|
25
|
+
set on the component property. It will add `...` to the end of the truncated text. It will also
|
|
26
|
+
add a `title` attribute to the component with the full text if the text is truncated.
|
|
27
|
+
|
|
28
|
+
<Canvas>
|
|
29
|
+
<Story
|
|
30
|
+
name="default"
|
|
31
|
+
args={{
|
|
32
|
+
string: 'This string is being truncated for length.',
|
|
33
|
+
maxChars: 30,
|
|
34
|
+
}}
|
|
35
|
+
>
|
|
36
|
+
{Template.bind({})}
|
|
37
|
+
</Story>
|
|
38
|
+
</Canvas>
|
|
39
|
+
|
|
40
|
+
<ArgsTable of={TextTruncate} />
|
|
41
|
+
|
|
42
|
+
## Non Truncated Text
|
|
43
|
+
|
|
44
|
+
This is an example of a string that is shorter than the max character length and will not be
|
|
45
|
+
truncated.
|
|
46
|
+
|
|
47
|
+
<Canvas>
|
|
48
|
+
<Story
|
|
49
|
+
name="non truncated text"
|
|
50
|
+
args={{
|
|
51
|
+
string: 'This string meets the length required to not be truncated.',
|
|
52
|
+
maxChars: 100,
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
{Template.bind({})}
|
|
56
|
+
</Story>
|
|
57
|
+
</Canvas>
|
|
58
|
+
|
|
59
|
+
export const Template = (args) => <TextTruncate {...args} />;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import { TextTruncate } from './TextTruncate';
|
|
4
|
+
|
|
5
|
+
describe('TextTruncate', () => {
|
|
6
|
+
const longText = 'this is a really long string that should be truncated';
|
|
7
|
+
|
|
8
|
+
it('truncates text when it exceeds the maximum length and adds a title attr', () => {
|
|
9
|
+
const { getByTitle } = render(<TextTruncate string={longText} maxChars={20} />);
|
|
10
|
+
expect(getByTitle(longText).textContent).toEqual('this is a really lon...');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('does not truncate the text when it is below the max length', () => {
|
|
14
|
+
const { getByText } = render(<TextTruncate string={longText} maxChars={200} />);
|
|
15
|
+
expect(getByText(longText).textContent).toEqual(longText);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyledTextTruncate } from './TextTruncate.styles';
|
|
3
|
+
|
|
4
|
+
interface TextTruncateProps {
|
|
5
|
+
string: string;
|
|
6
|
+
maxChars: number;
|
|
7
|
+
children: any;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function TextTruncate({ string, maxChars, children }: TextTruncateProps) {
|
|
11
|
+
return string.length > maxChars ? (
|
|
12
|
+
<StyledTextTruncate title={string}>
|
|
13
|
+
{`${string.substring(0, maxChars)}...`}
|
|
14
|
+
{children}
|
|
15
|
+
</StyledTextTruncate>
|
|
16
|
+
) : (
|
|
17
|
+
<StyledTextTruncate>
|
|
18
|
+
{string} {children}
|
|
19
|
+
</StyledTextTruncate>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TextTruncate } from './TextTruncate';
|