@ndlib/component-library 0.0.85 → 0.0.86

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.
@@ -4,3 +4,4 @@ declare const meta: Meta<typeof Paragraph>;
4
4
  export default meta;
5
5
  type Story = StoryObj<typeof Paragraph>;
6
6
  export declare const Default: Story;
7
+ export declare const LineClamp: Story;
@@ -23,3 +23,9 @@ export const Default = {
23
23
  children: 'Heading',
24
24
  },
25
25
  };
26
+ export const LineClamp = {
27
+ render: (args) => (_jsx(Column, { children: sizes.map((size) => (_jsxs(Group, Object.assign({ type: GROUP_TYPE.REGION }, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.LG, underline: true, sx: { color: COLOR.PRIMARY } }, { children: size.label })), [p1, p2].map((content) => (_jsx(Paragraph, Object.assign({}, args, { size: size.size, clampLines: 2 }, { children: content }))))] })))) })),
28
+ args: {
29
+ children: 'Heading',
30
+ },
31
+ };
@@ -4,6 +4,7 @@ import { StyledElementProps } from '../../../../theme';
4
4
  type ParagraphProps = StyledElementProps<HTMLSpanElement, {
5
5
  size?: PARAGRAPH_SIZE;
6
6
  typography?: TYPOGRAPHY_TYPE;
7
+ clampLines?: number;
7
8
  }>;
8
9
  export declare enum PARAGRAPH_SIZE {
9
10
  SM = "sm",
@@ -11,6 +11,8 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  };
12
12
  import { jsx as _jsx } from "theme-ui/jsx-runtime";
13
13
  import { getTypographyStyles, TYPOGRAPHY_TYPE, } from '../../../../theme/typography';
14
+ import { useTheme } from '../../../../theme';
15
+ import { multiplyRemSize } from '../../../../utils/misc';
14
16
  export var PARAGRAPH_SIZE;
15
17
  (function (PARAGRAPH_SIZE) {
16
18
  PARAGRAPH_SIZE["SM"] = "sm";
@@ -23,7 +25,15 @@ const SIZE_TYPOGRAPHY_MAP = {
23
25
  [PARAGRAPH_SIZE.LG]: TYPOGRAPHY_TYPE.PARAGRAPH_LARGE,
24
26
  };
25
27
  export const Paragraph = (_a) => {
26
- var { size, typography: typographyParam, sx } = _a, rest = __rest(_a, ["size", "typography", "sx"]);
28
+ var { size, typography: typographyParam, sx, clampLines } = _a, rest = __rest(_a, ["size", "typography", "sx", "clampLines"]);
29
+ const theme = useTheme();
27
30
  const typography = typographyParam || SIZE_TYPOGRAPHY_MAP[size || PARAGRAPH_SIZE.MD];
28
- return (_jsx("div", Object.assign({ sx: Object.assign(Object.assign(Object.assign({}, getTypographyStyles(typography)), { my: 1 }), sx) }, rest)));
31
+ const typographyStyles = getTypographyStyles(typography);
32
+ const marginHeightMultiple = theme.lineHeights[typographyStyles.lineHeight] * 0.375;
33
+ const fontSize = theme.fontSizes[typographyStyles.fontSize];
34
+ const topMargin = multiplyRemSize({
35
+ size: fontSize,
36
+ multiple: marginHeightMultiple,
37
+ });
38
+ return (_jsx("div", Object.assign({ sx: Object.assign(Object.assign(Object.assign({}, getTypographyStyles(typography)), { display: clampLines ? '-webkit-box' : undefined, '-webkit-line-clamp': clampLines ? String(clampLines) : undefined, '-webkit-box-orient': 'vertical', overflow: clampLines ? 'hidden' : undefined, my: topMargin }), sx) }, rest)));
29
39
  };
@@ -15,6 +15,7 @@ import { useTheme } from '../../../../theme';
15
15
  import { COLOR, colors } from '../../../../theme/colors';
16
16
  import { getTypographyStyles, } from '../../../../theme/typography';
17
17
  import { useMediaQuery } from '../../../providers/media';
18
+ import { multiplyRemSize } from '../../../../utils/misc';
18
19
  const ReadMoreLink = (props) => {
19
20
  const bg = colors[props.bg || COLOR.BACKGROUND];
20
21
  const color = colors[props.color || COLOR.ND_BLUE_LIGHT];
@@ -36,9 +37,11 @@ export const useLinesHeight = (args) => {
36
37
  const styles = getTypographyStyles(args.typography);
37
38
  const fontSize = styles.fontSize;
38
39
  const fontSizeRem = theme.fontSizes[fontSize];
39
- const fontSizeNumber = Number(fontSizeRem.slice(0, fontSizeRem.length - 3));
40
- const linesHeight = fontSizeNumber * theme.lineHeights[styles.lineHeight] * args.lines;
41
- return `${linesHeight}rem`;
40
+ const linesHeight = theme.lineHeights[styles.lineHeight] * args.lines;
41
+ return multiplyRemSize({
42
+ size: fontSizeRem,
43
+ multiple: linesHeight,
44
+ });
42
45
  };
43
46
  export const ReadMore = (_a) => {
44
47
  var { typography, sx, role, lines, fixedHeight, children } = _a, rest = __rest(_a, ["typography", "sx", "role", "lines", "fixedHeight", "children"]);
@@ -12,3 +12,7 @@ export declare enum KEY_CODES {
12
12
  }
13
13
  export declare const equals: (a: any, b: any) => boolean;
14
14
  export declare function importedDefaultComponentShim<T>(component: T): T;
15
+ export declare const multiplyRemSize: (params: {
16
+ size: string;
17
+ multiple: number;
18
+ }) => string;
@@ -17,3 +17,8 @@ export function importedDefaultComponentShim(component) {
17
17
  return component;
18
18
  }
19
19
  }
20
+ export const multiplyRemSize = (params) => {
21
+ const { size, multiple } = params;
22
+ const [value] = size.split('rem');
23
+ return `${Number(value) * multiple}rem`;
24
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import { multiplyRemSize } from './misc';
2
+ describe('multiplyRemSize', () => {
3
+ it('should multiply a rem size by a multiple', () => {
4
+ expect(multiplyRemSize({
5
+ size: '1rem',
6
+ multiple: 2,
7
+ })).toEqual('2rem');
8
+ expect(multiplyRemSize({
9
+ size: '1.5rem',
10
+ multiple: 2,
11
+ })).toEqual('3rem');
12
+ });
13
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ndlib/component-library",
3
- "version": "0.0.85",
3
+ "version": "0.0.86",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [