@ndlib/component-library 0.0.19 → 0.0.21
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/dist/components/elements/text/ReadMore/ReadMore.stories.d.ts +7 -0
- package/dist/components/elements/text/ReadMore/ReadMore.stories.js +19 -0
- package/dist/components/elements/text/ReadMore/index.d.ts +10 -0
- package/dist/components/elements/text/ReadMore/index.js +74 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/theme/typography.d.ts +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { ReadMore } from '.';
|
|
3
|
+
declare const meta: Meta<typeof ReadMore>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof ReadMore>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const NotTruncated: Story;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ReadMore } from '.';
|
|
3
|
+
import { Column } from '../../layout/Column';
|
|
4
|
+
import { TYPOGRAPHY_TYPE } from '../../../../theme/typography';
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'Elements/ReadMore',
|
|
7
|
+
component: ReadMore,
|
|
8
|
+
//👇 Enables auto-generated documentation for the component story
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
};
|
|
11
|
+
export default meta;
|
|
12
|
+
const p1 = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris ultrices venenatis purus at porta. Etiam congue sapien leo, sed malesuada justo commodo in. Nunc consequat, massa non cursus posuere, magna eros lacinia lectus, eget lobortis mi erat ut justo. Maecenas nisi mi, mollis sed ornare vitae, pharetra sed augue. Curabitur mollis orci risus, sed imperdiet nisi aliquet et. Ut non elit nec magna rhoncus maximus sit amet ut dui. Mauris sit amet eleifend lectus. Aliquam consectetur posuere libero eu ultricies. Etiam rutrum non orci nec vulputate. Sed vel accumsan diam. Cras aliquet eros eros, sit amet pharetra eros tincidunt ut. Vestibulum est erat, eleifend dapibus eros vel, elementum vehicula risus. Etiam blandit condimentum sodales. Donec non libero in orci aliquam egestas fringilla eget purus. Suspendisse pellentesque at ligula ut accumsan.';
|
|
13
|
+
const p2 = 'Lorem ipsum dolor sit';
|
|
14
|
+
export const Default = {
|
|
15
|
+
render: () => (_jsx(Column, { children: _jsx(ReadMore, { text: p1, sx: { width: '250px' }, lines: 2, typography: TYPOGRAPHY_TYPE.PARAGRAPH_MEDIUM }) })),
|
|
16
|
+
};
|
|
17
|
+
export const NotTruncated = {
|
|
18
|
+
render: () => (_jsx(Column, { children: _jsx(ReadMore, { text: p2, sx: { width: '250px' }, lines: 2, typography: TYPOGRAPHY_TYPE.PARAGRAPH_MEDIUM }) })),
|
|
19
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** @jsxImportSource theme-ui */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { StyledElementProps } from '../../../../theme';
|
|
4
|
+
import { TYPOGRAPHY_TYPE } from '../../../../theme/typography';
|
|
5
|
+
export declare const ReadMore: React.FC<StyledElementProps<HTMLDivElement, {
|
|
6
|
+
text: string;
|
|
7
|
+
typography: TYPOGRAPHY_TYPE;
|
|
8
|
+
lines: number;
|
|
9
|
+
fixedHeight?: boolean;
|
|
10
|
+
}>>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "theme-ui/jsx-runtime";
|
|
13
|
+
/** @jsxImportSource theme-ui */
|
|
14
|
+
import React, { useState } from 'react';
|
|
15
|
+
import { useTheme } from '../../../../theme';
|
|
16
|
+
import { COLOR } from '../../../../theme/colors';
|
|
17
|
+
import { getTypographyStyles, } from '../../../../theme/typography';
|
|
18
|
+
const ReadMoreLink = () => {
|
|
19
|
+
return (_jsx("div", Object.assign({ css: {
|
|
20
|
+
whiteSpace: 'nowrap',
|
|
21
|
+
position: 'absolute',
|
|
22
|
+
right: 0,
|
|
23
|
+
bottom: 0,
|
|
24
|
+
paddingLeft: '3rem',
|
|
25
|
+
background: 'linear-gradient(to right, rgba(255, 255, 255, 0), rgb(255, 255, 255) 30%, rgb(255, 255, 255))',
|
|
26
|
+
} }, { children: _jsx("div", Object.assign({ "aria-hidden": "true", sx: {
|
|
27
|
+
transform: 'scale(0.9)',
|
|
28
|
+
color: COLOR.ND_BLUE_LIGHT,
|
|
29
|
+
cursor: 'pointer',
|
|
30
|
+
} }, { children: "Read More..." })) })));
|
|
31
|
+
};
|
|
32
|
+
const useLinesHeight = (args) => {
|
|
33
|
+
const theme = useTheme();
|
|
34
|
+
const styles = getTypographyStyles(args.typography);
|
|
35
|
+
const fontSize = styles.fontSize;
|
|
36
|
+
const fontSizeRem = theme.fontSizes[fontSize];
|
|
37
|
+
// slice of the 'rem' from end of fontSize string and convert to number
|
|
38
|
+
const fontSizeNumber = Number(fontSizeRem.slice(0, fontSizeRem.length - 3));
|
|
39
|
+
// Multiply the fontSize by the lineHeight ratio and the number of lines
|
|
40
|
+
const linesHeight = fontSizeNumber * theme.lineHeights[styles.lineHeight] * args.lines;
|
|
41
|
+
return `${linesHeight}rem`;
|
|
42
|
+
};
|
|
43
|
+
// A react component that accepts text content and truncates it 3 lines. If the content
|
|
44
|
+
// exceeds the alloted space, an ellipsis will be placed at the end of the last line.
|
|
45
|
+
// This component does not use the css property `text-overflow: ellipsis`
|
|
46
|
+
// because it does not work with multiple lines of text.
|
|
47
|
+
export const ReadMore = (_a) => {
|
|
48
|
+
var { text, typography, sx, role, lines, fixedHeight } = _a, rest = __rest(_a, ["text", "typography", "sx", "role", "lines", "fixedHeight"]);
|
|
49
|
+
const ref = React.useRef(null);
|
|
50
|
+
const [showEllipsis, setShowEllipsis] = useState(true);
|
|
51
|
+
const wrapperHeight = useLinesHeight({ typography, lines });
|
|
52
|
+
React.useEffect(() => {
|
|
53
|
+
if (ref.current) {
|
|
54
|
+
// Check if the content exceeds the alloted space
|
|
55
|
+
if (fixedHeight) {
|
|
56
|
+
ref.current.style.height = wrapperHeight;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
ref.current.style.maxHeight = wrapperHeight;
|
|
60
|
+
}
|
|
61
|
+
const isOverflowing = ref.current.scrollHeight > ref.current.clientHeight;
|
|
62
|
+
if (isOverflowing) {
|
|
63
|
+
setShowEllipsis(true);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
setShowEllipsis(false);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}, [text, wrapperHeight, fixedHeight]);
|
|
70
|
+
return (_jsxs("div", Object.assign({ role: role || 'paragraph', ref: ref, style: {
|
|
71
|
+
overflow: 'hidden',
|
|
72
|
+
position: 'relative',
|
|
73
|
+
}, sx: Object.assign(Object.assign({}, getTypographyStyles(typography)), sx) }, rest, { children: [text, showEllipsis && _jsx(ReadMoreLink, {})] })));
|
|
74
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { theme, ThemeProvider } from './theme';
|
|
1
|
+
export { theme, ThemeProvider, useTheme } from './theme';
|
|
2
2
|
export { COLOR } from './theme/colors';
|
|
3
3
|
export { TYPOGRAPHY_TYPE, FONT, FONT_SIZE, FONT_WEIGHT, LINE_HEIGHT, } from './theme/typography';
|
|
4
4
|
export { Alert, Alerts } from './components/elements/Alerts';
|
|
@@ -22,6 +22,9 @@ export { Checkbox } from './components/elements/Fields/Checkbox';
|
|
|
22
22
|
export { CheckboxGroup } from './components/elements/Fields/CheckboxGroup';
|
|
23
23
|
export { Radio } from './components/elements/Fields/Radio';
|
|
24
24
|
export { RadioGroup } from './components/elements/Fields/RadioGroup';
|
|
25
|
+
export { List, ListItem, LIST_SIZE } from './components/elements/List';
|
|
26
|
+
export { ReadMore } from './components/elements/text/ReadMore';
|
|
27
|
+
export { Icon } from './components/elements/Icon';
|
|
25
28
|
export { Card, CARD_SIZE, CARD_LAYOUT } from './components/composites/Card';
|
|
26
29
|
export { UiProvider } from './components/providers/ui';
|
|
27
30
|
export { MenuProvider, useMenu } from './components/providers/menu';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { theme, ThemeProvider } from './theme';
|
|
1
|
+
export { theme, ThemeProvider, useTheme } from './theme';
|
|
2
2
|
export { COLOR } from './theme/colors';
|
|
3
3
|
export { TYPOGRAPHY_TYPE, FONT, FONT_SIZE, FONT_WEIGHT, LINE_HEIGHT, } from './theme/typography';
|
|
4
4
|
export { Alert, Alerts } from './components/elements/Alerts';
|
|
@@ -22,6 +22,9 @@ export { Checkbox } from './components/elements/Fields/Checkbox';
|
|
|
22
22
|
export { CheckboxGroup } from './components/elements/Fields/CheckboxGroup';
|
|
23
23
|
export { Radio } from './components/elements/Fields/Radio';
|
|
24
24
|
export { RadioGroup } from './components/elements/Fields/RadioGroup';
|
|
25
|
+
export { List, ListItem, LIST_SIZE } from './components/elements/List';
|
|
26
|
+
export { ReadMore } from './components/elements/text/ReadMore';
|
|
27
|
+
export { Icon } from './components/elements/Icon';
|
|
25
28
|
export { Card, CARD_SIZE, CARD_LAYOUT } from './components/composites/Card';
|
|
26
29
|
export { UiProvider } from './components/providers/ui';
|
|
27
30
|
export { MenuProvider, useMenu } from './components/providers/menu';
|
|
@@ -82,12 +82,12 @@ export declare const typographyStyleMap: {
|
|
|
82
82
|
fontFamily: FONT;
|
|
83
83
|
fontSize: FONT_SIZE;
|
|
84
84
|
fontWeight?: FONT_WEIGHT;
|
|
85
|
-
lineHeight
|
|
85
|
+
lineHeight: LINE_HEIGHT;
|
|
86
86
|
};
|
|
87
87
|
};
|
|
88
88
|
export declare const getTypographyStyles: (typography?: TYPOGRAPHY_TYPE) => {
|
|
89
89
|
fontFamily: FONT;
|
|
90
90
|
fontSize: FONT_SIZE;
|
|
91
91
|
fontWeight?: FONT_WEIGHT | undefined;
|
|
92
|
-
lineHeight
|
|
92
|
+
lineHeight: LINE_HEIGHT;
|
|
93
93
|
};
|