@spaced-out/ui-design-system 0.1.72 → 0.1.74
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 +16 -0
- package/lib/components/Tabs/TabList/TabList.js +6 -1
- package/lib/components/Tabs/TabList/TabList.js.flow +4 -1
- package/lib/components/TruncatedTextWithTooltip/TruncatedTextWithTooltip.js +76 -0
- package/lib/components/TruncatedTextWithTooltip/TruncatedTextWithTooltip.js.flow +110 -0
- package/lib/components/TruncatedTextWithTooltip/TruncatedTextWithTooltip.module.css +18 -0
- package/lib/components/TruncatedTextWithTooltip/index.js +16 -0
- package/lib/components/TruncatedTextWithTooltip/index.js.flow +3 -0
- package/lib/components/index.js +11 -0
- package/lib/components/index.js.flow +1 -0
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
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.74](https://github.com/spaced-out/ui-design-system/compare/v0.1.73...v0.1.74) (2024-01-04)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* removed width of tablist container story ([caadaf6](https://github.com/spaced-out/ui-design-system/commit/caadaf69dfbc3c16598192719473d5b06cf8ae65))
|
|
11
|
+
* support window resize for tablist ([#156](https://github.com/spaced-out/ui-design-system/issues/156)) ([8c2990a](https://github.com/spaced-out/ui-design-system/commit/8c2990a3e862ebac43a75cc026754584260c6aaa))
|
|
12
|
+
|
|
13
|
+
### [0.1.73](https://github.com/spaced-out/ui-design-system/compare/v0.1.72...v0.1.73) (2024-01-02)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* ➕ storybook upgraded ([b6164b0](https://github.com/spaced-out/ui-design-system/commit/b6164b06193a6daff1eb0cdf24de0f991b87f584))
|
|
19
|
+
* 🎉 🆕 auto truncation with tooltip component ([15dfd7f](https://github.com/spaced-out/ui-design-system/commit/15dfd7fd1f63abba99cd4882ec075294e42dc1c8))
|
|
20
|
+
|
|
5
21
|
### [0.1.72](https://github.com/spaced-out/ui-design-system/compare/v0.1.71...v0.1.72) (2023-12-15)
|
|
6
22
|
|
|
7
23
|
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.TabList = void 0;
|
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _useWindowSize = require("../../../hooks/useWindowSize/useWindowSize");
|
|
8
9
|
var _size = require("../../../styles/variables/_size");
|
|
9
10
|
var _space = require("../../../styles/variables/_space");
|
|
10
11
|
var _classify = require("../../../utils/classify");
|
|
@@ -25,6 +26,9 @@ const TabList = /*#__PURE__*/React.forwardRef((_ref, forwardRef) => {
|
|
|
25
26
|
} = _ref;
|
|
26
27
|
const ref = React.useRef(null);
|
|
27
28
|
React.useImperativeHandle(forwardRef, () => ref.current);
|
|
29
|
+
const {
|
|
30
|
+
width
|
|
31
|
+
} = (0, _useWindowSize.useWindowSize)();
|
|
28
32
|
const [containerWidth, setContainerWidth] = React.useState(0);
|
|
29
33
|
const childrenWithProps = () => {
|
|
30
34
|
const childrenArray = React.Children.toArray(children);
|
|
@@ -113,7 +117,8 @@ const TabList = /*#__PURE__*/React.forwardRef((_ref, forwardRef) => {
|
|
|
113
117
|
const availableContainerWidth = ref.current.offsetWidth - (parseInt(_size.size36) + parseInt(_space.spaceMedium));
|
|
114
118
|
setContainerWidth(availableContainerWidth);
|
|
115
119
|
}
|
|
116
|
-
|
|
120
|
+
// it depends on width of the screen as ref.current.offsetWidth will not provide the events when changed.
|
|
121
|
+
}, [ref.current, width]);
|
|
117
122
|
return /*#__PURE__*/React.createElement("div", {
|
|
118
123
|
ref: ref,
|
|
119
124
|
"data-testid": "Tabs",
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
|
|
5
|
+
import {useWindowSize} from '../../../hooks/useWindowSize/useWindowSize';
|
|
5
6
|
import {size36, size100} from '../../../styles/variables/_size';
|
|
6
7
|
import {spaceMedium} from '../../../styles/variables/_space';
|
|
7
8
|
import {classify} from '../../../utils/classify';
|
|
@@ -37,6 +38,7 @@ export const TabList: React$AbstractComponent<TabListProps, HTMLDivElement> =
|
|
|
37
38
|
): React.Node => {
|
|
38
39
|
const ref = React.useRef(null);
|
|
39
40
|
React.useImperativeHandle(forwardRef, () => ref.current);
|
|
41
|
+
const {width} = useWindowSize();
|
|
40
42
|
|
|
41
43
|
const [containerWidth, setContainerWidth] = React.useState(0);
|
|
42
44
|
|
|
@@ -132,7 +134,8 @@ export const TabList: React$AbstractComponent<TabListProps, HTMLDivElement> =
|
|
|
132
134
|
(parseInt(size36) + parseInt(spaceMedium));
|
|
133
135
|
setContainerWidth(availableContainerWidth);
|
|
134
136
|
}
|
|
135
|
-
|
|
137
|
+
// it depends on width of the screen as ref.current.offsetWidth will not provide the events when changed.
|
|
138
|
+
}, [ref.current, width]);
|
|
136
139
|
|
|
137
140
|
return (
|
|
138
141
|
<div
|
|
@@ -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
|
+
});
|
package/lib/components/index.js
CHANGED
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spaced-out/ui-design-system",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.74",
|
|
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.
|
|
63
|
-
"@storybook/addon-essentials": "^7.
|
|
64
|
-
"@storybook/addon-mdx-gfm": "^7.
|
|
65
|
-
"@storybook/addon-storysource": "^7.
|
|
66
|
-
"@storybook/addons": "^7.
|
|
67
|
-
"@storybook/react": "^7.
|
|
68
|
-
"@storybook/react-webpack5": "^7.
|
|
69
|
-
"@storybook/test-runner": "^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.
|
|
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.
|
|
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"
|