@tenancy.nz/feature-ui 1.11.5 → 1.11.6

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.
@@ -29,6 +29,7 @@ var styles = {
29
29
  }, wide, "inline-flex")
30
30
  }
31
31
  };
32
+ var COPIED_RESET_MS = 5e3;
32
33
  var makeHref = function makeHref(type, value) {
33
34
  if (!type) {
34
35
  return "";
@@ -55,12 +56,32 @@ function ContactMethod(_ref) {
55
56
  _ref$tooltip = _ref.tooltip,
56
57
  tooltip = _ref$tooltip === void 0 ? "" : _ref$tooltip,
57
58
  rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
59
+ var _useState = React.useState(false),
60
+ _useState2 = _rollupPluginBabelHelpers.slicedToArray(_useState, 2),
61
+ copied = _useState2[0],
62
+ setCopied = _useState2[1];
63
+ var resetTimer = React.useRef(void 0);
64
+ var resetCopied = function resetCopied() {
65
+ clearTimeout(resetTimer.current);
66
+ setCopied(false);
67
+ };
68
+ React.useEffect(function () {
69
+ return function () {
70
+ return clearTimeout(resetTimer.current);
71
+ };
72
+ }, []);
58
73
  if (!value) {
59
74
  return null;
60
75
  }
61
76
  var handleCopy = function handleCopy() {
62
77
  var _navigator$clipboard;
63
- (_navigator$clipboard = navigator.clipboard) === null || _navigator$clipboard === void 0 || _navigator$clipboard.writeText(value);
78
+ (_navigator$clipboard = navigator.clipboard) === null || _navigator$clipboard === void 0 || _navigator$clipboard.writeText(value).then(function () {
79
+ clearTimeout(resetTimer.current);
80
+ setCopied(true);
81
+ resetTimer.current = setTimeout(function () {
82
+ return setCopied(false);
83
+ }, COPIED_RESET_MS);
84
+ });
64
85
  };
65
86
  var href = makeHref(type, value);
66
87
  return /* @__PURE__ */React.createElement(Stack, _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({
@@ -86,8 +107,13 @@ function ContactMethod(_ref) {
86
107
  ml: "auto",
87
108
  flexShrink: 0
88
109
  }, /* @__PURE__ */React.createElement(ui.Tooltip, {
89
- title: "Copy",
90
- placement: "top"
110
+ title: copied ? "Copied!" : "Copy",
111
+ placement: "top",
112
+ slotProps: {
113
+ transition: {
114
+ onExited: resetCopied
115
+ }
116
+ }
91
117
  }, /* @__PURE__ */React.createElement(ActionButton, {
92
118
  "aria-label": "Copy ".concat(label !== null && label !== void 0 ? label : value),
93
119
  color: "primary",
@@ -1,5 +1,5 @@
1
- import { defineProperty as _defineProperty, objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2, toConsumableArray as _toConsumableArray } from '../_virtual/_rollupPluginBabelHelpers.js';
2
- import React from 'react';
1
+ import { defineProperty as _defineProperty, objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, objectSpread2 as _objectSpread2, toConsumableArray as _toConsumableArray } from '../_virtual/_rollupPluginBabelHelpers.js';
2
+ import React, { useState, useRef, useEffect } from 'react';
3
3
  import Stack from '@mui/material/Stack';
4
4
  import CopyOutlinedIcon from '@tenancy.nz/icons/CopyOutlined';
5
5
  import { Text, Tooltip, IconButton } from '@tenancy.nz/ui';
@@ -25,6 +25,7 @@ var styles = {
25
25
  }, wide, "inline-flex")
26
26
  }
27
27
  };
28
+ var COPIED_RESET_MS = 5e3;
28
29
  var makeHref = function makeHref(type, value) {
29
30
  if (!type) {
30
31
  return "";
@@ -51,12 +52,32 @@ function ContactMethod(_ref) {
51
52
  _ref$tooltip = _ref.tooltip,
52
53
  tooltip = _ref$tooltip === void 0 ? "" : _ref$tooltip,
53
54
  rest = _objectWithoutProperties(_ref, _excluded);
55
+ var _useState = useState(false),
56
+ _useState2 = _slicedToArray(_useState, 2),
57
+ copied = _useState2[0],
58
+ setCopied = _useState2[1];
59
+ var resetTimer = useRef(void 0);
60
+ var resetCopied = function resetCopied() {
61
+ clearTimeout(resetTimer.current);
62
+ setCopied(false);
63
+ };
64
+ useEffect(function () {
65
+ return function () {
66
+ return clearTimeout(resetTimer.current);
67
+ };
68
+ }, []);
54
69
  if (!value) {
55
70
  return null;
56
71
  }
57
72
  var handleCopy = function handleCopy() {
58
73
  var _navigator$clipboard;
59
- (_navigator$clipboard = navigator.clipboard) === null || _navigator$clipboard === void 0 || _navigator$clipboard.writeText(value);
74
+ (_navigator$clipboard = navigator.clipboard) === null || _navigator$clipboard === void 0 || _navigator$clipboard.writeText(value).then(function () {
75
+ clearTimeout(resetTimer.current);
76
+ setCopied(true);
77
+ resetTimer.current = setTimeout(function () {
78
+ return setCopied(false);
79
+ }, COPIED_RESET_MS);
80
+ });
60
81
  };
61
82
  var href = makeHref(type, value);
62
83
  return /* @__PURE__ */React.createElement(Stack, _objectSpread2(_objectSpread2({
@@ -82,8 +103,13 @@ function ContactMethod(_ref) {
82
103
  ml: "auto",
83
104
  flexShrink: 0
84
105
  }, /* @__PURE__ */React.createElement(Tooltip, {
85
- title: "Copy",
86
- placement: "top"
106
+ title: copied ? "Copied!" : "Copy",
107
+ placement: "top",
108
+ slotProps: {
109
+ transition: {
110
+ onExited: resetCopied
111
+ }
112
+ }
87
113
  }, /* @__PURE__ */React.createElement(ActionButton, {
88
114
  "aria-label": "Copy ".concat(label !== null && label !== void 0 ? label : value),
89
115
  color: "primary",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tenancy.nz/feature-ui",
3
3
  "description": "React UI feature components.",
4
- "version": "1.11.5",
4
+ "version": "1.11.6",
5
5
  "author": "TPS <https://www.tenancy.co.nz>",
6
6
  "type": "module",
7
7
  "main": "dist/cjs/index.cjs",
@@ -17,15 +17,15 @@
17
17
  "classnames": "^2.2.6",
18
18
  "react": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
19
19
  "react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
20
- "@tenancy.nz/icons": "1.11.5",
21
- "@tenancy.nz/ui": "1.11.5"
20
+ "@tenancy.nz/icons": "1.11.6",
21
+ "@tenancy.nz/ui": "1.11.6"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@emotion/react": "^11.14.0",
25
25
  "@emotion/styled": "^11.14.1",
26
26
  "@mui/material": "^7.3.1",
27
- "@tenancy.nz/icons": "1.11.5",
28
- "@tenancy.nz/ui": "1.11.5"
27
+ "@tenancy.nz/icons": "1.11.6",
28
+ "@tenancy.nz/ui": "1.11.6"
29
29
  },
30
30
  "dependencies": {
31
31
  "react-uid": "^2.4.0"