@tenancy.nz/feature-ui 1.10.5 → 1.10.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.
- package/dist/cjs/components/ContactCard.cjs +2 -0
- package/dist/cjs/components/ContactCardHeader.cjs +64 -0
- package/dist/cjs/components/ScrollTopButton.cjs +193 -0
- package/dist/cjs/index.cjs +2 -0
- package/dist/esm/components/ContactCard.js +1 -0
- package/dist/esm/components/ContactCardHeader.js +60 -0
- package/dist/esm/components/ScrollTopButton.js +189 -0
- package/dist/esm/index.js +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.cjs');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var Stack = require('@mui/material/Stack');
|
|
8
|
+
var ui = require('@tenancy.nz/ui');
|
|
9
|
+
|
|
10
|
+
var _excluded = ["avatarColor", "avatarUrl", "disabled", "email", "firstName", "lastName", "mobile", "sx"];
|
|
11
|
+
var CONTACT_TEXT = {
|
|
12
|
+
default: ui.token("palette.semantic.text.secondaryColor"),
|
|
13
|
+
disabled: ui.token("palette.semantic.text.disabledColor")
|
|
14
|
+
};
|
|
15
|
+
function ContactCardHeader(_ref) {
|
|
16
|
+
var _ref$avatarColor = _ref.avatarColor,
|
|
17
|
+
avatarColor = _ref$avatarColor === void 0 ? "grey" : _ref$avatarColor,
|
|
18
|
+
_ref$avatarUrl = _ref.avatarUrl,
|
|
19
|
+
avatarUrl = _ref$avatarUrl === void 0 ? void 0 : _ref$avatarUrl,
|
|
20
|
+
_ref$disabled = _ref.disabled,
|
|
21
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
22
|
+
_ref$email = _ref.email,
|
|
23
|
+
email = _ref$email === void 0 ? void 0 : _ref$email,
|
|
24
|
+
_ref$firstName = _ref.firstName,
|
|
25
|
+
firstName = _ref$firstName === void 0 ? void 0 : _ref$firstName,
|
|
26
|
+
_ref$lastName = _ref.lastName,
|
|
27
|
+
lastName = _ref$lastName === void 0 ? void 0 : _ref$lastName,
|
|
28
|
+
_ref$mobile = _ref.mobile,
|
|
29
|
+
mobile = _ref$mobile === void 0 ? void 0 : _ref$mobile,
|
|
30
|
+
_ref$sx = _ref.sx,
|
|
31
|
+
sx = _ref$sx === void 0 ? {} : _ref$sx,
|
|
32
|
+
rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
|
|
33
|
+
var name = [firstName, lastName].filter(Boolean).join(" ");
|
|
34
|
+
return /* @__PURE__ */React.createElement(Stack, _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({
|
|
35
|
+
direction: "row",
|
|
36
|
+
alignItems: "center",
|
|
37
|
+
gap: 4
|
|
38
|
+
}, rest), {}, {
|
|
39
|
+
sx: sx
|
|
40
|
+
}), /* @__PURE__ */React.createElement(ui.Avatar, {
|
|
41
|
+
color: avatarColor,
|
|
42
|
+
src: avatarUrl,
|
|
43
|
+
alt: name,
|
|
44
|
+
size: 64
|
|
45
|
+
}), /* @__PURE__ */React.createElement(Stack, {
|
|
46
|
+
gap: 2
|
|
47
|
+
}, name && /* @__PURE__ */React.createElement(ui.Heading, {
|
|
48
|
+
as: "h5",
|
|
49
|
+
color: "inherit"
|
|
50
|
+
}, name), (email || mobile) && /* @__PURE__ */React.createElement(Stack, {
|
|
51
|
+
sx: {
|
|
52
|
+
color: disabled ? CONTACT_TEXT.disabled : CONTACT_TEXT.default,
|
|
53
|
+
fontSize: "12px"
|
|
54
|
+
}
|
|
55
|
+
}, email && /* @__PURE__ */React.createElement(ui.Text, {
|
|
56
|
+
variant: "inherit",
|
|
57
|
+
weight: "500"
|
|
58
|
+
}, email), mobile && /* @__PURE__ */React.createElement(ui.Text, {
|
|
59
|
+
variant: "inherit",
|
|
60
|
+
weight: "500"
|
|
61
|
+
}, mobile))));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
exports.default = ContactCardHeader;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.cjs');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var Box = require('@mui/material/Box');
|
|
8
|
+
var Portal = require('@mui/material/Portal');
|
|
9
|
+
var ui = require('@tenancy.nz/ui');
|
|
10
|
+
var ChevronUpOutlinedIcon = require('@tenancy.nz/icons/ChevronUpOutlined');
|
|
11
|
+
|
|
12
|
+
var _excluded = ["anchorOrigin", "asIcon", "behavior", "container", "disablePortal", "label", "onClick", "position", "scrollContainer", "threshold", "x", "y"];
|
|
13
|
+
var icon = /* @__PURE__ */React.createElement(ChevronUpOutlinedIcon, null);
|
|
14
|
+
var defaultAnchorOrigin = {
|
|
15
|
+
horizontal: "right",
|
|
16
|
+
vertical: "bottom"
|
|
17
|
+
};
|
|
18
|
+
function resolveTarget(target) {
|
|
19
|
+
if (!target) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
if (typeof target === "function") {
|
|
23
|
+
return target();
|
|
24
|
+
}
|
|
25
|
+
if ("current" in target) {
|
|
26
|
+
return target.current;
|
|
27
|
+
}
|
|
28
|
+
return target;
|
|
29
|
+
}
|
|
30
|
+
function isDocumentScroller(element) {
|
|
31
|
+
if (!element) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return element === document.body || element === document.documentElement;
|
|
35
|
+
}
|
|
36
|
+
function getScrollEventTarget(element) {
|
|
37
|
+
if (isDocumentScroller(element)) {
|
|
38
|
+
return window;
|
|
39
|
+
}
|
|
40
|
+
return element;
|
|
41
|
+
}
|
|
42
|
+
function getScrollTop(element) {
|
|
43
|
+
if (!element || isDocumentScroller(element)) {
|
|
44
|
+
return window.scrollY;
|
|
45
|
+
}
|
|
46
|
+
return element.scrollTop;
|
|
47
|
+
}
|
|
48
|
+
function scrollToTop(scrollElement, behavior) {
|
|
49
|
+
if (!scrollElement || isDocumentScroller(scrollElement)) {
|
|
50
|
+
window.scrollTo({
|
|
51
|
+
top: 0,
|
|
52
|
+
behavior: behavior
|
|
53
|
+
});
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
scrollElement.scrollTo({
|
|
57
|
+
top: 0,
|
|
58
|
+
behavior: behavior
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function getPosition(position, portalElement) {
|
|
62
|
+
if (position) {
|
|
63
|
+
return position;
|
|
64
|
+
}
|
|
65
|
+
if (!portalElement) {
|
|
66
|
+
return "static";
|
|
67
|
+
}
|
|
68
|
+
if (portalElement === document.body) {
|
|
69
|
+
return "fixed";
|
|
70
|
+
}
|
|
71
|
+
return "absolute";
|
|
72
|
+
}
|
|
73
|
+
function getPlacementSx(position, anchorOrigin, x, y) {
|
|
74
|
+
return _rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.defineProperty({
|
|
75
|
+
position: position,
|
|
76
|
+
zIndex: "fab"
|
|
77
|
+
}, anchorOrigin.horizontal, x), anchorOrigin.vertical, y);
|
|
78
|
+
}
|
|
79
|
+
function useResolvedTarget(target, fallbackToBody) {
|
|
80
|
+
var _useState = React.useState(null),
|
|
81
|
+
_useState2 = _rollupPluginBabelHelpers.slicedToArray(_useState, 2),
|
|
82
|
+
element = _useState2[0],
|
|
83
|
+
setElement = _useState2[1];
|
|
84
|
+
React.useEffect(function () {
|
|
85
|
+
var resolved = resolveTarget(target);
|
|
86
|
+
if (resolved) {
|
|
87
|
+
setElement(resolved);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (fallbackToBody) {
|
|
91
|
+
setElement(document.body);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
setElement(null);
|
|
95
|
+
}, [target, fallbackToBody]);
|
|
96
|
+
return element;
|
|
97
|
+
}
|
|
98
|
+
function useScrolledPast(scrollElement, threshold) {
|
|
99
|
+
var _useState3 = React.useState(threshold <= 0),
|
|
100
|
+
_useState4 = _rollupPluginBabelHelpers.slicedToArray(_useState3, 2),
|
|
101
|
+
scrolled = _useState4[0],
|
|
102
|
+
setScrolled = _useState4[1];
|
|
103
|
+
React.useEffect(function () {
|
|
104
|
+
if (threshold <= 0) {
|
|
105
|
+
setScrolled(true);
|
|
106
|
+
return void 0;
|
|
107
|
+
}
|
|
108
|
+
var eventTarget = getScrollEventTarget(scrollElement);
|
|
109
|
+
var update = function update() {
|
|
110
|
+
return setScrolled(getScrollTop(scrollElement) > threshold);
|
|
111
|
+
};
|
|
112
|
+
update();
|
|
113
|
+
eventTarget.addEventListener("scroll", update, {
|
|
114
|
+
passive: true
|
|
115
|
+
});
|
|
116
|
+
return function () {
|
|
117
|
+
return eventTarget.removeEventListener("scroll", update);
|
|
118
|
+
};
|
|
119
|
+
}, [scrollElement, threshold]);
|
|
120
|
+
return scrolled;
|
|
121
|
+
}
|
|
122
|
+
function ScrollTopButton(_ref2) {
|
|
123
|
+
var _ref2$anchorOrigin = _ref2.anchorOrigin,
|
|
124
|
+
anchorOrigin = _ref2$anchorOrigin === void 0 ? defaultAnchorOrigin : _ref2$anchorOrigin,
|
|
125
|
+
_ref2$asIcon = _ref2.asIcon,
|
|
126
|
+
asIcon = _ref2$asIcon === void 0 ? false : _ref2$asIcon,
|
|
127
|
+
_ref2$behavior = _ref2.behavior,
|
|
128
|
+
behavior = _ref2$behavior === void 0 ? "smooth" : _ref2$behavior,
|
|
129
|
+
_ref2$container = _ref2.container,
|
|
130
|
+
container = _ref2$container === void 0 ? null : _ref2$container,
|
|
131
|
+
_ref2$disablePortal = _ref2.disablePortal,
|
|
132
|
+
disablePortal = _ref2$disablePortal === void 0 ? false : _ref2$disablePortal,
|
|
133
|
+
_ref2$label = _ref2.label,
|
|
134
|
+
label = _ref2$label === void 0 ? "Back to top" : _ref2$label,
|
|
135
|
+
_ref2$onClick = _ref2.onClick,
|
|
136
|
+
onClick = _ref2$onClick === void 0 ? void 0 : _ref2$onClick,
|
|
137
|
+
_ref2$position = _ref2.position,
|
|
138
|
+
position = _ref2$position === void 0 ? void 0 : _ref2$position,
|
|
139
|
+
_ref2$scrollContainer = _ref2.scrollContainer,
|
|
140
|
+
scrollContainer = _ref2$scrollContainer === void 0 ? null : _ref2$scrollContainer,
|
|
141
|
+
_ref2$threshold = _ref2.threshold,
|
|
142
|
+
threshold = _ref2$threshold === void 0 ? 120 : _ref2$threshold,
|
|
143
|
+
_ref2$x = _ref2.x,
|
|
144
|
+
x = _ref2$x === void 0 ? 32 : _ref2$x,
|
|
145
|
+
_ref2$y = _ref2.y,
|
|
146
|
+
y = _ref2$y === void 0 ? 32 : _ref2$y,
|
|
147
|
+
rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref2, _excluded);
|
|
148
|
+
var portalElement = useResolvedTarget(container, !disablePortal);
|
|
149
|
+
var scrollElement = useResolvedTarget(scrollContainer, true);
|
|
150
|
+
var scrolled = useScrolledPast(scrollElement, threshold);
|
|
151
|
+
var handleClick = function handleClick(event) {
|
|
152
|
+
scrollToTop(scrollElement, behavior);
|
|
153
|
+
onClick === null || onClick === void 0 || onClick(event);
|
|
154
|
+
};
|
|
155
|
+
if (!scrolled) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
if (!disablePortal && !portalElement) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
var resolvedPosition = getPosition(position, portalElement);
|
|
162
|
+
var withPlacement = function withPlacement(node) {
|
|
163
|
+
if (resolvedPosition === "static") {
|
|
164
|
+
return node;
|
|
165
|
+
}
|
|
166
|
+
return /* @__PURE__ */React.createElement(Box, {
|
|
167
|
+
sx: getPlacementSx(resolvedPosition, anchorOrigin, x, y)
|
|
168
|
+
}, node);
|
|
169
|
+
};
|
|
170
|
+
var withPortal = function withPortal(node) {
|
|
171
|
+
if (!portalElement) {
|
|
172
|
+
return node;
|
|
173
|
+
}
|
|
174
|
+
return /* @__PURE__ */React.createElement(Portal, {
|
|
175
|
+
container: portalElement
|
|
176
|
+
}, node);
|
|
177
|
+
};
|
|
178
|
+
if (asIcon) {
|
|
179
|
+
return withPortal(withPlacement(/* @__PURE__ */React.createElement(ui.IconButton, _rollupPluginBabelHelpers.objectSpread2({
|
|
180
|
+
variant: "outlined",
|
|
181
|
+
size: "large",
|
|
182
|
+
onClick: handleClick
|
|
183
|
+
}, rest), icon)));
|
|
184
|
+
}
|
|
185
|
+
return withPortal(withPlacement(/* @__PURE__ */React.createElement(ui.Button, _rollupPluginBabelHelpers.objectSpread2({
|
|
186
|
+
variant: "outlined",
|
|
187
|
+
startIcon: icon,
|
|
188
|
+
size: "large",
|
|
189
|
+
onClick: handleClick
|
|
190
|
+
}, rest), label)));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
exports.default = ScrollTopButton;
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var NotesCard = require('./components/NotesCard.cjs');
|
|
|
21
21
|
var PersonCard = require('./components/PersonCard.cjs');
|
|
22
22
|
var PersonDetailHeader = require('./components/PersonDetailHeader.cjs');
|
|
23
23
|
var PropertyCard = require('./components/PropertyCard.cjs');
|
|
24
|
+
var ScrollTopButton = require('./components/ScrollTopButton.cjs');
|
|
24
25
|
var StatusButton = require('./components/StatusButton.cjs');
|
|
25
26
|
var TenantAvatarGroup = require('./components/TenantAvatarGroup.cjs');
|
|
26
27
|
|
|
@@ -47,5 +48,6 @@ exports.NotesCard = NotesCard.default;
|
|
|
47
48
|
exports.PersonCard = PersonCard.default;
|
|
48
49
|
exports.PersonDetailHeader = PersonDetailHeader.default;
|
|
49
50
|
exports.PropertyCard = PropertyCard.default;
|
|
51
|
+
exports.ScrollTopButton = ScrollTopButton.default;
|
|
50
52
|
exports.StatusButton = StatusButton.default;
|
|
51
53
|
exports.TenantAvatarGroup = TenantAvatarGroup.default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2 } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import Stack from '@mui/material/Stack';
|
|
4
|
+
import { token, Avatar, Heading, Text } from '@tenancy.nz/ui';
|
|
5
|
+
|
|
6
|
+
var _excluded = ["avatarColor", "avatarUrl", "disabled", "email", "firstName", "lastName", "mobile", "sx"];
|
|
7
|
+
var CONTACT_TEXT = {
|
|
8
|
+
default: token("palette.semantic.text.secondaryColor"),
|
|
9
|
+
disabled: token("palette.semantic.text.disabledColor")
|
|
10
|
+
};
|
|
11
|
+
function ContactCardHeader(_ref) {
|
|
12
|
+
var _ref$avatarColor = _ref.avatarColor,
|
|
13
|
+
avatarColor = _ref$avatarColor === void 0 ? "grey" : _ref$avatarColor,
|
|
14
|
+
_ref$avatarUrl = _ref.avatarUrl,
|
|
15
|
+
avatarUrl = _ref$avatarUrl === void 0 ? void 0 : _ref$avatarUrl,
|
|
16
|
+
_ref$disabled = _ref.disabled,
|
|
17
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
18
|
+
_ref$email = _ref.email,
|
|
19
|
+
email = _ref$email === void 0 ? void 0 : _ref$email,
|
|
20
|
+
_ref$firstName = _ref.firstName,
|
|
21
|
+
firstName = _ref$firstName === void 0 ? void 0 : _ref$firstName,
|
|
22
|
+
_ref$lastName = _ref.lastName,
|
|
23
|
+
lastName = _ref$lastName === void 0 ? void 0 : _ref$lastName,
|
|
24
|
+
_ref$mobile = _ref.mobile,
|
|
25
|
+
mobile = _ref$mobile === void 0 ? void 0 : _ref$mobile,
|
|
26
|
+
_ref$sx = _ref.sx,
|
|
27
|
+
sx = _ref$sx === void 0 ? {} : _ref$sx,
|
|
28
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
29
|
+
var name = [firstName, lastName].filter(Boolean).join(" ");
|
|
30
|
+
return /* @__PURE__ */React.createElement(Stack, _objectSpread2(_objectSpread2({
|
|
31
|
+
direction: "row",
|
|
32
|
+
alignItems: "center",
|
|
33
|
+
gap: 4
|
|
34
|
+
}, rest), {}, {
|
|
35
|
+
sx: sx
|
|
36
|
+
}), /* @__PURE__ */React.createElement(Avatar, {
|
|
37
|
+
color: avatarColor,
|
|
38
|
+
src: avatarUrl,
|
|
39
|
+
alt: name,
|
|
40
|
+
size: 64
|
|
41
|
+
}), /* @__PURE__ */React.createElement(Stack, {
|
|
42
|
+
gap: 2
|
|
43
|
+
}, name && /* @__PURE__ */React.createElement(Heading, {
|
|
44
|
+
as: "h5",
|
|
45
|
+
color: "inherit"
|
|
46
|
+
}, name), (email || mobile) && /* @__PURE__ */React.createElement(Stack, {
|
|
47
|
+
sx: {
|
|
48
|
+
color: disabled ? CONTACT_TEXT.disabled : CONTACT_TEXT.default,
|
|
49
|
+
fontSize: "12px"
|
|
50
|
+
}
|
|
51
|
+
}, email && /* @__PURE__ */React.createElement(Text, {
|
|
52
|
+
variant: "inherit",
|
|
53
|
+
weight: "500"
|
|
54
|
+
}, email), mobile && /* @__PURE__ */React.createElement(Text, {
|
|
55
|
+
variant: "inherit",
|
|
56
|
+
weight: "500"
|
|
57
|
+
}, mobile))));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { ContactCardHeader as default };
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2, slicedToArray as _slicedToArray, defineProperty as _defineProperty } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import React, { useState, useEffect } from 'react';
|
|
3
|
+
import Box from '@mui/material/Box';
|
|
4
|
+
import Portal from '@mui/material/Portal';
|
|
5
|
+
import { IconButton, Button } from '@tenancy.nz/ui';
|
|
6
|
+
import ChevronUpOutlinedIcon from '@tenancy.nz/icons/ChevronUpOutlined';
|
|
7
|
+
|
|
8
|
+
var _excluded = ["anchorOrigin", "asIcon", "behavior", "container", "disablePortal", "label", "onClick", "position", "scrollContainer", "threshold", "x", "y"];
|
|
9
|
+
var icon = /* @__PURE__ */React.createElement(ChevronUpOutlinedIcon, null);
|
|
10
|
+
var defaultAnchorOrigin = {
|
|
11
|
+
horizontal: "right",
|
|
12
|
+
vertical: "bottom"
|
|
13
|
+
};
|
|
14
|
+
function resolveTarget(target) {
|
|
15
|
+
if (!target) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
if (typeof target === "function") {
|
|
19
|
+
return target();
|
|
20
|
+
}
|
|
21
|
+
if ("current" in target) {
|
|
22
|
+
return target.current;
|
|
23
|
+
}
|
|
24
|
+
return target;
|
|
25
|
+
}
|
|
26
|
+
function isDocumentScroller(element) {
|
|
27
|
+
if (!element) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return element === document.body || element === document.documentElement;
|
|
31
|
+
}
|
|
32
|
+
function getScrollEventTarget(element) {
|
|
33
|
+
if (isDocumentScroller(element)) {
|
|
34
|
+
return window;
|
|
35
|
+
}
|
|
36
|
+
return element;
|
|
37
|
+
}
|
|
38
|
+
function getScrollTop(element) {
|
|
39
|
+
if (!element || isDocumentScroller(element)) {
|
|
40
|
+
return window.scrollY;
|
|
41
|
+
}
|
|
42
|
+
return element.scrollTop;
|
|
43
|
+
}
|
|
44
|
+
function scrollToTop(scrollElement, behavior) {
|
|
45
|
+
if (!scrollElement || isDocumentScroller(scrollElement)) {
|
|
46
|
+
window.scrollTo({
|
|
47
|
+
top: 0,
|
|
48
|
+
behavior: behavior
|
|
49
|
+
});
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
scrollElement.scrollTo({
|
|
53
|
+
top: 0,
|
|
54
|
+
behavior: behavior
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function getPosition(position, portalElement) {
|
|
58
|
+
if (position) {
|
|
59
|
+
return position;
|
|
60
|
+
}
|
|
61
|
+
if (!portalElement) {
|
|
62
|
+
return "static";
|
|
63
|
+
}
|
|
64
|
+
if (portalElement === document.body) {
|
|
65
|
+
return "fixed";
|
|
66
|
+
}
|
|
67
|
+
return "absolute";
|
|
68
|
+
}
|
|
69
|
+
function getPlacementSx(position, anchorOrigin, x, y) {
|
|
70
|
+
return _defineProperty(_defineProperty({
|
|
71
|
+
position: position,
|
|
72
|
+
zIndex: "fab"
|
|
73
|
+
}, anchorOrigin.horizontal, x), anchorOrigin.vertical, y);
|
|
74
|
+
}
|
|
75
|
+
function useResolvedTarget(target, fallbackToBody) {
|
|
76
|
+
var _useState = useState(null),
|
|
77
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
78
|
+
element = _useState2[0],
|
|
79
|
+
setElement = _useState2[1];
|
|
80
|
+
useEffect(function () {
|
|
81
|
+
var resolved = resolveTarget(target);
|
|
82
|
+
if (resolved) {
|
|
83
|
+
setElement(resolved);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (fallbackToBody) {
|
|
87
|
+
setElement(document.body);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
setElement(null);
|
|
91
|
+
}, [target, fallbackToBody]);
|
|
92
|
+
return element;
|
|
93
|
+
}
|
|
94
|
+
function useScrolledPast(scrollElement, threshold) {
|
|
95
|
+
var _useState3 = useState(threshold <= 0),
|
|
96
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
97
|
+
scrolled = _useState4[0],
|
|
98
|
+
setScrolled = _useState4[1];
|
|
99
|
+
useEffect(function () {
|
|
100
|
+
if (threshold <= 0) {
|
|
101
|
+
setScrolled(true);
|
|
102
|
+
return void 0;
|
|
103
|
+
}
|
|
104
|
+
var eventTarget = getScrollEventTarget(scrollElement);
|
|
105
|
+
var update = function update() {
|
|
106
|
+
return setScrolled(getScrollTop(scrollElement) > threshold);
|
|
107
|
+
};
|
|
108
|
+
update();
|
|
109
|
+
eventTarget.addEventListener("scroll", update, {
|
|
110
|
+
passive: true
|
|
111
|
+
});
|
|
112
|
+
return function () {
|
|
113
|
+
return eventTarget.removeEventListener("scroll", update);
|
|
114
|
+
};
|
|
115
|
+
}, [scrollElement, threshold]);
|
|
116
|
+
return scrolled;
|
|
117
|
+
}
|
|
118
|
+
function ScrollTopButton(_ref2) {
|
|
119
|
+
var _ref2$anchorOrigin = _ref2.anchorOrigin,
|
|
120
|
+
anchorOrigin = _ref2$anchorOrigin === void 0 ? defaultAnchorOrigin : _ref2$anchorOrigin,
|
|
121
|
+
_ref2$asIcon = _ref2.asIcon,
|
|
122
|
+
asIcon = _ref2$asIcon === void 0 ? false : _ref2$asIcon,
|
|
123
|
+
_ref2$behavior = _ref2.behavior,
|
|
124
|
+
behavior = _ref2$behavior === void 0 ? "smooth" : _ref2$behavior,
|
|
125
|
+
_ref2$container = _ref2.container,
|
|
126
|
+
container = _ref2$container === void 0 ? null : _ref2$container,
|
|
127
|
+
_ref2$disablePortal = _ref2.disablePortal,
|
|
128
|
+
disablePortal = _ref2$disablePortal === void 0 ? false : _ref2$disablePortal,
|
|
129
|
+
_ref2$label = _ref2.label,
|
|
130
|
+
label = _ref2$label === void 0 ? "Back to top" : _ref2$label,
|
|
131
|
+
_ref2$onClick = _ref2.onClick,
|
|
132
|
+
onClick = _ref2$onClick === void 0 ? void 0 : _ref2$onClick,
|
|
133
|
+
_ref2$position = _ref2.position,
|
|
134
|
+
position = _ref2$position === void 0 ? void 0 : _ref2$position,
|
|
135
|
+
_ref2$scrollContainer = _ref2.scrollContainer,
|
|
136
|
+
scrollContainer = _ref2$scrollContainer === void 0 ? null : _ref2$scrollContainer,
|
|
137
|
+
_ref2$threshold = _ref2.threshold,
|
|
138
|
+
threshold = _ref2$threshold === void 0 ? 120 : _ref2$threshold,
|
|
139
|
+
_ref2$x = _ref2.x,
|
|
140
|
+
x = _ref2$x === void 0 ? 32 : _ref2$x,
|
|
141
|
+
_ref2$y = _ref2.y,
|
|
142
|
+
y = _ref2$y === void 0 ? 32 : _ref2$y,
|
|
143
|
+
rest = _objectWithoutProperties(_ref2, _excluded);
|
|
144
|
+
var portalElement = useResolvedTarget(container, !disablePortal);
|
|
145
|
+
var scrollElement = useResolvedTarget(scrollContainer, true);
|
|
146
|
+
var scrolled = useScrolledPast(scrollElement, threshold);
|
|
147
|
+
var handleClick = function handleClick(event) {
|
|
148
|
+
scrollToTop(scrollElement, behavior);
|
|
149
|
+
onClick === null || onClick === void 0 || onClick(event);
|
|
150
|
+
};
|
|
151
|
+
if (!scrolled) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
if (!disablePortal && !portalElement) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
var resolvedPosition = getPosition(position, portalElement);
|
|
158
|
+
var withPlacement = function withPlacement(node) {
|
|
159
|
+
if (resolvedPosition === "static") {
|
|
160
|
+
return node;
|
|
161
|
+
}
|
|
162
|
+
return /* @__PURE__ */React.createElement(Box, {
|
|
163
|
+
sx: getPlacementSx(resolvedPosition, anchorOrigin, x, y)
|
|
164
|
+
}, node);
|
|
165
|
+
};
|
|
166
|
+
var withPortal = function withPortal(node) {
|
|
167
|
+
if (!portalElement) {
|
|
168
|
+
return node;
|
|
169
|
+
}
|
|
170
|
+
return /* @__PURE__ */React.createElement(Portal, {
|
|
171
|
+
container: portalElement
|
|
172
|
+
}, node);
|
|
173
|
+
};
|
|
174
|
+
if (asIcon) {
|
|
175
|
+
return withPortal(withPlacement(/* @__PURE__ */React.createElement(IconButton, _objectSpread2({
|
|
176
|
+
variant: "outlined",
|
|
177
|
+
size: "large",
|
|
178
|
+
onClick: handleClick
|
|
179
|
+
}, rest), icon)));
|
|
180
|
+
}
|
|
181
|
+
return withPortal(withPlacement(/* @__PURE__ */React.createElement(Button, _objectSpread2({
|
|
182
|
+
variant: "outlined",
|
|
183
|
+
startIcon: icon,
|
|
184
|
+
size: "large",
|
|
185
|
+
onClick: handleClick
|
|
186
|
+
}, rest), label)));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export { ScrollTopButton as default };
|
package/dist/esm/index.js
CHANGED
|
@@ -19,5 +19,6 @@ export { default as NotesCard } from './components/NotesCard.js';
|
|
|
19
19
|
export { default as PersonCard } from './components/PersonCard.js';
|
|
20
20
|
export { default as PersonDetailHeader } from './components/PersonDetailHeader.js';
|
|
21
21
|
export { default as PropertyCard } from './components/PropertyCard.js';
|
|
22
|
+
export { default as ScrollTopButton } from './components/ScrollTopButton.js';
|
|
22
23
|
export { default as StatusButton } from './components/StatusButton.js';
|
|
23
24
|
export { default as TenantAvatarGroup } from './components/TenantAvatarGroup.js';
|
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.10.
|
|
4
|
+
"version": "1.10.6",
|
|
5
5
|
"author": "TPS <https://www.tenancy.co.nz>",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/cjs/index.cjs",
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
"primereact": "3.1.3",
|
|
20
20
|
"react": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
21
21
|
"react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
22
|
-
"@tenancy.nz/
|
|
23
|
-
"@tenancy.nz/
|
|
22
|
+
"@tenancy.nz/ui": "1.10.6",
|
|
23
|
+
"@tenancy.nz/icons": "1.10.6"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@emotion/react": "^11.14.0",
|
|
27
27
|
"@emotion/styled": "^11.14.1",
|
|
28
28
|
"@mui/material": "^7.3.1",
|
|
29
|
-
"@tenancy.nz/icons": "1.10.
|
|
30
|
-
"@tenancy.nz/ui": "1.10.
|
|
29
|
+
"@tenancy.nz/icons": "1.10.6",
|
|
30
|
+
"@tenancy.nz/ui": "1.10.6"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"react-uid": "^2.4.0"
|