@spaced-out/ui-design-system 0.1.72 → 0.1.73

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/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.1.73](https://github.com/spaced-out/ui-design-system/compare/v0.1.72...v0.1.73) (2024-01-02)
6
+
7
+
8
+ ### Features
9
+
10
+ * ➕ storybook upgraded ([b6164b0](https://github.com/spaced-out/ui-design-system/commit/b6164b06193a6daff1eb0cdf24de0f991b87f584))
11
+ * 🎉 🆕 auto truncation with tooltip component ([15dfd7f](https://github.com/spaced-out/ui-design-system/commit/15dfd7fd1f63abba99cd4882ec075294e42dc1c8))
12
+
5
13
  ### [0.1.72](https://github.com/spaced-out/ui-design-system/compare/v0.1.71...v0.1.72) (2023-12-15)
6
14
 
7
15
 
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TruncatedTextWithTooltip = void 0;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ var _debounce = _interopRequireDefault(require("lodash/debounce"));
9
+ var _size = require("../../styles/variables/_size");
10
+ var _classify = _interopRequireDefault(require("../../utils/classify"));
11
+ var _Tooltip = require("../Tooltip");
12
+ var _TruncatedTextWithTooltipModule = _interopRequireDefault(require("./TruncatedTextWithTooltip.module.css"));
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
16
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
17
+ const TruncatedTextWithTooltip = _ref => {
18
+ let {
19
+ classNames,
20
+ children,
21
+ tooltip,
22
+ wrapText = false,
23
+ ...props
24
+ } = _ref;
25
+ const [showMouseTip, setShowMouseTip] = React.useState(false);
26
+ const truncatedRef = React.useRef();
27
+ const checkWidths = React.useMemo(() => (0, _debounce.default)(() => {
28
+ const span = truncatedRef.current;
29
+ if (span) {
30
+ setShowMouseTip(span.offsetWidth < span.scrollWidth);
31
+ }
32
+ }, 200), []);
33
+
34
+ // Running only on mount and unmount
35
+ React.useEffect(() => {
36
+ const span = truncatedRef.current;
37
+ if (span) {
38
+ // Note(Nishant): This is a fix for the issue where the parent width is not set
39
+ // explicitly by the calling component, for truncation to work the parent wrapper should
40
+ // have a defined width. For cases where width is not set the component would set the
41
+ // width of the parent to 100%(sizeFluid) for the auto truncation to kick in
42
+ const parent = span.parentNode;
43
+ if (parent && parent instanceof HTMLElement) {
44
+ const computedStyles = window.getComputedStyle(parent);
45
+ const computedWidth = computedStyles.getPropertyValue('width');
46
+ const clientWidth = parent.clientWidth;
47
+ if (computedWidth !== `${clientWidth}px`) {
48
+ // Set the parent width to 100% if not explicitly set
49
+ parent.style.width = _size.sizeFluid;
50
+ }
51
+ }
52
+ }
53
+ window.addEventListener('resize', checkWidths);
54
+ return () => {
55
+ window.removeEventListener('resize', checkWidths);
56
+ };
57
+ }, [checkWidths]);
58
+ React.useEffect(() => {
59
+ checkWidths();
60
+ }, [children]);
61
+ const content = showMouseTip ? /*#__PURE__*/React.createElement(_Tooltip.Tooltip, _extends({}, tooltip, {
62
+ body: tooltip?.body ?? children,
63
+ elevation: tooltip?.elevation ?? 'toast'
64
+ }), /*#__PURE__*/React.createElement("span", _extends({}, props, {
65
+ className: (0, _classify.default)(_TruncatedTextWithTooltipModule.default.truncatedText, classNames?.wrapper),
66
+ ref: truncatedRef
67
+ }), children)) : /*#__PURE__*/React.createElement("span", _extends({}, props, {
68
+ className: (0, _classify.default)({
69
+ [_TruncatedTextWithTooltipModule.default.truncatedText]: !wrapText,
70
+ [_TruncatedTextWithTooltipModule.default.wrapText]: wrapText
71
+ }, classNames?.wrapper),
72
+ ref: truncatedRef
73
+ }), children);
74
+ return content;
75
+ };
76
+ exports.TruncatedTextWithTooltip = TruncatedTextWithTooltip;
@@ -0,0 +1,110 @@
1
+ // @flow strict
2
+
3
+ import * as React from 'react';
4
+ import debounce from 'lodash/debounce';
5
+
6
+ import {sizeFluid} from '../../styles/variables/_size';
7
+ import classify from '../../utils/classify';
8
+ import type {BaseTooltipProps} from '../Tooltip';
9
+ import {Tooltip} from '../Tooltip';
10
+
11
+ import css from './TruncatedTextWithTooltip.module.css';
12
+
13
+
14
+ type ClassNames = $ReadOnly<{wrapper?: string}>;
15
+
16
+ export type TruncatedTextWithTooltipProps = {
17
+ children?: React.Node,
18
+ tooltip?: BaseTooltipProps,
19
+ classNames?: ClassNames,
20
+ wrapText?: boolean,
21
+ ...
22
+ };
23
+
24
+ export const TruncatedTextWithTooltip = ({
25
+ classNames,
26
+ children,
27
+ tooltip,
28
+ wrapText = false,
29
+ ...props
30
+ }: TruncatedTextWithTooltipProps): React.Node => {
31
+ const [showMouseTip, setShowMouseTip] = React.useState(false);
32
+ const truncatedRef = React.useRef<?HTMLSpanElement>();
33
+
34
+ const checkWidths = React.useMemo(
35
+ () =>
36
+ debounce(() => {
37
+ const span = truncatedRef.current;
38
+
39
+ if (span) {
40
+ setShowMouseTip(span.offsetWidth < span.scrollWidth);
41
+ }
42
+ }, 200),
43
+ [],
44
+ );
45
+
46
+ // Running only on mount and unmount
47
+ React.useEffect(() => {
48
+ const span = truncatedRef.current;
49
+
50
+ if (span) {
51
+ // Note(Nishant): This is a fix for the issue where the parent width is not set
52
+ // explicitly by the calling component, for truncation to work the parent wrapper should
53
+ // have a defined width. For cases where width is not set the component would set the
54
+ // width of the parent to 100%(sizeFluid) for the auto truncation to kick in
55
+ const parent = span.parentNode;
56
+ if (parent && parent instanceof HTMLElement) {
57
+ const computedStyles = window.getComputedStyle(parent);
58
+ const computedWidth = computedStyles.getPropertyValue('width');
59
+ const clientWidth = parent.clientWidth;
60
+
61
+ if (computedWidth !== `${clientWidth}px`) {
62
+ // Set the parent width to 100% if not explicitly set
63
+ parent.style.width = sizeFluid;
64
+ }
65
+ }
66
+ }
67
+
68
+ window.addEventListener('resize', checkWidths);
69
+
70
+ return () => {
71
+ window.removeEventListener('resize', checkWidths);
72
+ };
73
+ }, [checkWidths]);
74
+
75
+ React.useEffect(() => {
76
+ checkWidths();
77
+ }, [children]);
78
+
79
+ const content = showMouseTip ? (
80
+ <Tooltip
81
+ {...tooltip}
82
+ body={tooltip?.body ?? children}
83
+ elevation={tooltip?.elevation ?? 'toast'}
84
+ >
85
+ <span
86
+ {...props}
87
+ className={classify(css.truncatedText, classNames?.wrapper)}
88
+ ref={truncatedRef}
89
+ >
90
+ {children}
91
+ </span>
92
+ </Tooltip>
93
+ ) : (
94
+ <span
95
+ {...props}
96
+ className={classify(
97
+ {
98
+ [css.truncatedText]: !wrapText,
99
+ [css.wrapText]: wrapText,
100
+ },
101
+ classNames?.wrapper,
102
+ )}
103
+ ref={truncatedRef}
104
+ >
105
+ {children}
106
+ </span>
107
+ );
108
+
109
+ return content;
110
+ };
@@ -0,0 +1,18 @@
1
+ @value (sizeFluid) from '../../styles/variables/_size.css';
2
+
3
+ .wrapper {
4
+ display: flex;
5
+ width: sizeFluid;
6
+ }
7
+
8
+ .truncatedText {
9
+ width: sizeFluid;
10
+ text-overflow: ellipsis;
11
+ overflow: hidden;
12
+ white-space: nowrap;
13
+ }
14
+
15
+ .wrapText,
16
+ .truncatedText {
17
+ width: sizeFluid;
18
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _TruncatedTextWithTooltip = require("./TruncatedTextWithTooltip");
7
+ Object.keys(_TruncatedTextWithTooltip).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _TruncatedTextWithTooltip[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _TruncatedTextWithTooltip[key];
14
+ }
15
+ });
16
+ });
@@ -0,0 +1,3 @@
1
+ // @flow strict
2
+
3
+ export * from './TruncatedTextWithTooltip';
@@ -564,6 +564,17 @@ Object.keys(_Truncate).forEach(function (key) {
564
564
  }
565
565
  });
566
566
  });
567
+ var _TruncatedTextWithTooltip = require("./TruncatedTextWithTooltip");
568
+ Object.keys(_TruncatedTextWithTooltip).forEach(function (key) {
569
+ if (key === "default" || key === "__esModule") return;
570
+ if (key in exports && exports[key] === _TruncatedTextWithTooltip[key]) return;
571
+ Object.defineProperty(exports, key, {
572
+ enumerable: true,
573
+ get: function () {
574
+ return _TruncatedTextWithTooltip[key];
575
+ }
576
+ });
577
+ });
567
578
  var _Typeahead = require("./Typeahead");
568
579
  Object.keys(_Typeahead).forEach(function (key) {
569
580
  if (key === "default" || key === "__esModule") return;
@@ -51,4 +51,5 @@ export * from './Toast';
51
51
  export * from './Toggle';
52
52
  export * from './Tooltip';
53
53
  export * from './Truncate';
54
+ export * from './TruncatedTextWithTooltip';
54
55
  export * from './Typeahead';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spaced-out/ui-design-system",
3
- "version": "0.1.72",
3
+ "version": "0.1.73",
4
4
  "main": "index.js",
5
5
  "description": "Sense UI components library",
6
6
  "author": {
@@ -59,16 +59,16 @@
59
59
  "@babel/preset-react": "^7.18.6",
60
60
  "@commitlint/cli": "^17.1.2",
61
61
  "@commitlint/config-conventional": "^17.1.0",
62
- "@storybook/addon-a11y": "^7.4.6",
63
- "@storybook/addon-essentials": "^7.4.6",
64
- "@storybook/addon-mdx-gfm": "^7.4.6",
65
- "@storybook/addon-storysource": "^7.4.6",
66
- "@storybook/addons": "^7.4.6",
67
- "@storybook/react": "^7.4.6",
68
- "@storybook/react-webpack5": "^7.4.6",
69
- "@storybook/test-runner": "^0.13.0",
62
+ "@storybook/addon-a11y": "^7.6.7",
63
+ "@storybook/addon-essentials": "^7.6.7",
64
+ "@storybook/addon-mdx-gfm": "^7.6.7",
65
+ "@storybook/addon-storysource": "^7.6.7",
66
+ "@storybook/addons": "^7.6.7",
67
+ "@storybook/react": "^7.6.7",
68
+ "@storybook/react-webpack5": "^7.6.7",
69
+ "@storybook/test-runner": "^0.16.0",
70
70
  "@storybook/testing-react": "^2.0.0",
71
- "@storybook/theming": "^7.4.6",
71
+ "@storybook/theming": "^7.6.7",
72
72
  "@testing-library/react": "^11.2.7",
73
73
  "all-contributors-cli": "^6.20.0",
74
74
  "babel-eslint": "^10.1.0",
@@ -105,7 +105,7 @@
105
105
  "rimraf": "^3.0.2",
106
106
  "simple-git": "^3.12.0",
107
107
  "standard-version": "^9.5.0",
108
- "storybook": "^7.4.6",
108
+ "storybook": "^7.6.7",
109
109
  "storybook-css-modules": "^1.0.8",
110
110
  "storybook-vscode-component": "^1.0.9",
111
111
  "style-dictionary": "^3.7.1"