@sanity/ui 2.0.0-alpha.3 → 2.0.0-alpha.4
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/index.esm.js +31 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +31 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/dialog/constants.ts +4 -0
- package/src/components/dialog/dialog.tsx +74 -11
package/dist/index.js
CHANGED
|
@@ -734,7 +734,7 @@ var ResizeObserverController = function () {
|
|
|
734
734
|
};
|
|
735
735
|
return ResizeObserverController;
|
|
736
736
|
}();
|
|
737
|
-
var ResizeObserver = function () {
|
|
737
|
+
var ResizeObserver$1 = function () {
|
|
738
738
|
function ResizeObserver(callback) {
|
|
739
739
|
if (arguments.length === 0) {
|
|
740
740
|
throw new TypeError("Failed to construct 'ResizeObserver': 1 argument required, but only 0 present.");
|
|
@@ -770,7 +770,7 @@ var ResizeObserver = function () {
|
|
|
770
770
|
};
|
|
771
771
|
return ResizeObserver;
|
|
772
772
|
}();
|
|
773
|
-
const _ResizeObserver = typeof document !== "undefined" && typeof window !== "undefined" && window.ResizeObserver ? window.ResizeObserver : ResizeObserver;
|
|
773
|
+
const _ResizeObserver = typeof document !== "undefined" && typeof window !== "undefined" && window.ResizeObserver ? window.ResizeObserver : ResizeObserver$1;
|
|
774
774
|
const _elementSizeObserver = _createElementSizeObserver();
|
|
775
775
|
function _createElementRectValueListener() {
|
|
776
776
|
return {
|
|
@@ -7966,6 +7966,7 @@ const Breadcrumbs = react.forwardRef(function Breadcrumbs2(props, ref) {
|
|
|
7966
7966
|
}, itemIndex))
|
|
7967
7967
|
});
|
|
7968
7968
|
});
|
|
7969
|
+
const BORDER_OFFSET_X = 12;
|
|
7969
7970
|
function dialogStyle(_ref24) {
|
|
7970
7971
|
let {
|
|
7971
7972
|
theme
|
|
@@ -8020,9 +8021,9 @@ const Root$7 = styled__default.default(Layer)(responsivePaddingStyle, dialogStyl
|
|
|
8020
8021
|
const DialogContainer = styled__default.default(Container)(_a$b || (_a$b = __template$b(["\n &:not([hidden]) {\n display: flex;\n }\n width: 100%;\n height: 100%;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n"])));
|
|
8021
8022
|
const DialogCardRoot = styled__default.default(Card)(_b$6 || (_b$6 = __template$b(["\n &:not([hidden]) {\n display: flex;\n }\n width: 100%;\n min-height: 0;\n max-height: 100%;\n overflow: hidden;\n overflow: clip;\n"])));
|
|
8022
8023
|
const DialogLayout = styled__default.default(Flex)(_c$2 || (_c$2 = __template$b(["\n flex: 1;\n min-height: 0;\n width: 100%;\n"])));
|
|
8023
|
-
const DialogHeader = styled__default.default(Card)(_d$1 || (_d$1 = __template$b(["\n position: relative;\n z-index: 2;\n\n &:after {\n content: '';\n display: block;\n position: absolute;\n left:
|
|
8024
|
+
const DialogHeader = styled__default.default(Card)(_d$1 || (_d$1 = __template$b(["\n position: relative;\n z-index: 2;\n\n &:after {\n content: '';\n display: block;\n position: absolute;\n left: ", "px;\n right: ", "px;\n bottom: -1px;\n border-bottom: 1px solid var(--card-border-color);\n width: auto;\n opacity: ", ";\n transition: opacity 200ms ease-in;\n }\n"])), BORDER_OFFSET_X, BORDER_OFFSET_X, props => props.$isContentScrollable && props.$hasScrolledFromTop ? 1 : 0);
|
|
8024
8025
|
const DialogContent = styled__default.default(Box)(_e || (_e = __template$b(["\n position: relative;\n z-index: 1;\n overflow: auto;\n outline: none;\n"])));
|
|
8025
|
-
const DialogFooter = styled__default.default(Box)(_f || (_f = __template$b(["\n position: relative;\n z-index: 3;\n border-top: 1px solid var(--card-
|
|
8026
|
+
const DialogFooter = styled__default.default(Box)(_f || (_f = __template$b(["\n position: relative;\n z-index: 3;\n\n &:before {\n content: '';\n display: block;\n position: absolute;\n left: ", "px;\n right: ", "px;\n top: -1px;\n border-top: 1px solid var(--card-border-color);\n width: auto;\n opacity: ", ";\n transition: opacity 200ms ease-in;\n }\n"])), BORDER_OFFSET_X, BORDER_OFFSET_X, props => props.$isContentScrollable && !props.$hasScrolledToBottom ? 1 : 0);
|
|
8026
8027
|
const DialogCard = react.forwardRef(function DialogCard2(props, ref) {
|
|
8027
8028
|
var _a2;
|
|
8028
8029
|
const {
|
|
@@ -8057,6 +8058,9 @@ const DialogCard = react.forwardRef(function DialogCard2(props, ref) {
|
|
|
8057
8058
|
const labelId = "".concat(id, "_label");
|
|
8058
8059
|
const showCloseButton = Boolean(onClose) && hideCloseButton === false;
|
|
8059
8060
|
const showHeader = Boolean(header) || showCloseButton;
|
|
8061
|
+
const [isContentScrollable, setIsContentScrollable] = react.useState(false);
|
|
8062
|
+
const [hasScrolledFromTop, setHasScrolledFromTop] = react.useState(false);
|
|
8063
|
+
const [hasScrolledToBottom, setHasScrolledToBottom] = react.useState(false);
|
|
8060
8064
|
react.useEffect(() => {
|
|
8061
8065
|
if (!autoFocus) return;
|
|
8062
8066
|
if (forwardedRef.current) {
|
|
@@ -8091,6 +8095,22 @@ const DialogCard = react.forwardRef(function DialogCard2(props, ref) {
|
|
|
8091
8095
|
localContentRef.current = el;
|
|
8092
8096
|
if (typeof contentRef === "function") contentRef(el);else if (contentRef) contentRef.current = el;
|
|
8093
8097
|
}, [contentRef]);
|
|
8098
|
+
const handleContentUpdate = react.useCallback(() => {
|
|
8099
|
+
if (localContentRef.current) {
|
|
8100
|
+
setIsContentScrollable(localContentRef.current.clientHeight < localContentRef.current.scrollHeight);
|
|
8101
|
+
setHasScrolledFromTop(localContentRef.current.scrollTop > 0);
|
|
8102
|
+
setHasScrolledToBottom(localContentRef.current.scrollTop >= localContentRef.current.scrollHeight - localContentRef.current.clientHeight);
|
|
8103
|
+
}
|
|
8104
|
+
}, []);
|
|
8105
|
+
react.useEffect(() => {
|
|
8106
|
+
const resizeObserver = new ResizeObserver(handleContentUpdate);
|
|
8107
|
+
if (localContentRef.current) {
|
|
8108
|
+
resizeObserver.observe(localContentRef.current);
|
|
8109
|
+
}
|
|
8110
|
+
return () => {
|
|
8111
|
+
resizeObserver.disconnect();
|
|
8112
|
+
};
|
|
8113
|
+
}, [contentRef, handleContentUpdate]);
|
|
8094
8114
|
return /* @__PURE__ */jsxRuntime.jsx(DialogContainer, {
|
|
8095
8115
|
"data-ui": "DialogCard",
|
|
8096
8116
|
width,
|
|
@@ -8102,13 +8122,16 @@ const DialogCard = react.forwardRef(function DialogCard2(props, ref) {
|
|
|
8102
8122
|
children: /* @__PURE__ */jsxRuntime.jsxs(DialogLayout, {
|
|
8103
8123
|
direction: "column",
|
|
8104
8124
|
children: [showHeader && /* @__PURE__ */jsxRuntime.jsx(DialogHeader, {
|
|
8125
|
+
$isContentScrollable: isContentScrollable,
|
|
8126
|
+
$hasScrolledFromTop: hasScrolledFromTop,
|
|
8105
8127
|
children: /* @__PURE__ */jsxRuntime.jsxs(Flex, {
|
|
8106
8128
|
children: [/* @__PURE__ */jsxRuntime.jsx(Box, {
|
|
8107
8129
|
flex: 1,
|
|
8108
8130
|
padding: 4,
|
|
8109
8131
|
children: header && /* @__PURE__ */jsxRuntime.jsx(Text, {
|
|
8110
8132
|
id: labelId,
|
|
8111
|
-
|
|
8133
|
+
size: 1,
|
|
8134
|
+
weight: "medium",
|
|
8112
8135
|
children: header
|
|
8113
8136
|
})
|
|
8114
8137
|
}), showCloseButton && /* @__PURE__ */jsxRuntime.jsx(Box, {
|
|
@@ -8127,8 +8150,11 @@ const DialogCard = react.forwardRef(function DialogCard2(props, ref) {
|
|
|
8127
8150
|
flex: 1,
|
|
8128
8151
|
ref: setContentRef,
|
|
8129
8152
|
tabIndex: -1,
|
|
8153
|
+
onScroll: handleContentUpdate,
|
|
8130
8154
|
children
|
|
8131
8155
|
}), footer && /* @__PURE__ */jsxRuntime.jsx(DialogFooter, {
|
|
8156
|
+
$isContentScrollable: isContentScrollable,
|
|
8157
|
+
$hasScrolledToBottom: hasScrolledToBottom,
|
|
8132
8158
|
children: footer
|
|
8133
8159
|
})]
|
|
8134
8160
|
})
|