@linzjs/windows 8.8.1 → 8.8.2

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.
@@ -0,0 +1,34 @@
1
+ @use "@linzjs/lui/dist/scss/Core" as lui;
2
+
3
+ .CopyToClipboard {
4
+ cursor: pointer;
5
+ }
6
+
7
+ .windows_tooltip {
8
+ position: relative;
9
+ cursor: pointer;
10
+
11
+ .windows_tooltiptext {
12
+ opacity: 0;
13
+ transition: opacity 0.3s ease, width 0.3s ease;
14
+ pointer-events: none;
15
+ background-color: white;
16
+ color: rgb(46 52 56);
17
+ text-align: left;
18
+ padding: 4px 8px;
19
+ position: absolute;
20
+ z-index: 1;
21
+ line-height: 18px;
22
+ font-size: 13px;
23
+ overflow: hidden;
24
+
25
+ left: calc(100% + 8px);
26
+ transform: translateY(42%);
27
+ box-shadow: 0 2px 3px #00000040, 0 0 3px #00000026;
28
+ }
29
+
30
+ &:hover .windows_tooltiptext {
31
+ visibility: visible;
32
+ opacity: 1;
33
+ }
34
+ }
@@ -0,0 +1,57 @@
1
+ import './CopyableText.scss';
2
+
3
+ import clsx from 'clsx';
4
+ import { CSSProperties, ReactElement, useEffect, useRef, useState } from 'react';
5
+
6
+ export interface CopyableTextProps {
7
+ dataTestId?: string;
8
+ style?: CSSProperties;
9
+ className?: string;
10
+ text: string | number;
11
+ }
12
+
13
+ export const CopyableText = (props: CopyableTextProps): ReactElement => {
14
+ const [copied, setCopied] = useState(false);
15
+
16
+ const { dataTestId, style, className, text } = props;
17
+ const timeoutRefDisplay = useRef<ReturnType<typeof setTimeout> | null>(null);
18
+
19
+ const copy = () => {
20
+ window.navigator.clipboard.writeText(String(text)).then(
21
+ () => {
22
+ setCopied(true);
23
+ timeoutRefDisplay.current = setTimeout(() => void setCopied(false), 3000);
24
+ },
25
+ (err: Error) => {
26
+ alert(`Data copy failed: ${err.message}`);
27
+ },
28
+ );
29
+ };
30
+
31
+ useEffect(
32
+ () => () => {
33
+ if (timeoutRefDisplay.current) {
34
+ clearTimeout(timeoutRefDisplay.current);
35
+ timeoutRefDisplay.current = null;
36
+ }
37
+ },
38
+ [],
39
+ );
40
+
41
+ return (
42
+ <span
43
+ data-testid={dataTestId}
44
+ style={style}
45
+ className={clsx('windows_tooltip', className)}
46
+ onClick={(event) => {
47
+ event.stopPropagation();
48
+ copy();
49
+ }}
50
+ >
51
+ <span className="windows_tooltiptext" style={{ width: copied ? '62px' : '47px' }}>
52
+ {copied ? 'Copied!' : 'Copy'}
53
+ </span>
54
+ {text}
55
+ </span>
56
+ );
57
+ };
@@ -0,0 +1 @@
1
+ export * from './CopyableText';
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "popout"
14
14
  ],
15
15
  "main": "./dist/index.ts",
16
- "version": "8.8.1",
16
+ "version": "8.8.2",
17
17
  "peerDependencies": {
18
18
  "@linzjs/lui": ">=23",
19
19
  "lodash-es": ">=4",