@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.esm.js
CHANGED
|
@@ -721,7 +721,7 @@ var ResizeObserverController = function () {
|
|
|
721
721
|
};
|
|
722
722
|
return ResizeObserverController;
|
|
723
723
|
}();
|
|
724
|
-
var ResizeObserver = function () {
|
|
724
|
+
var ResizeObserver$1 = function () {
|
|
725
725
|
function ResizeObserver(callback) {
|
|
726
726
|
if (arguments.length === 0) {
|
|
727
727
|
throw new TypeError("Failed to construct 'ResizeObserver': 1 argument required, but only 0 present.");
|
|
@@ -757,7 +757,7 @@ var ResizeObserver = function () {
|
|
|
757
757
|
};
|
|
758
758
|
return ResizeObserver;
|
|
759
759
|
}();
|
|
760
|
-
const _ResizeObserver = typeof document !== "undefined" && typeof window !== "undefined" && window.ResizeObserver ? window.ResizeObserver : ResizeObserver;
|
|
760
|
+
const _ResizeObserver = typeof document !== "undefined" && typeof window !== "undefined" && window.ResizeObserver ? window.ResizeObserver : ResizeObserver$1;
|
|
761
761
|
const _elementSizeObserver = _createElementSizeObserver();
|
|
762
762
|
function _createElementRectValueListener() {
|
|
763
763
|
return {
|
|
@@ -7953,6 +7953,7 @@ const Breadcrumbs = forwardRef(function Breadcrumbs2(props, ref) {
|
|
|
7953
7953
|
}, itemIndex))
|
|
7954
7954
|
});
|
|
7955
7955
|
});
|
|
7956
|
+
const BORDER_OFFSET_X = 12;
|
|
7956
7957
|
function dialogStyle(_ref24) {
|
|
7957
7958
|
let {
|
|
7958
7959
|
theme
|
|
@@ -8007,9 +8008,9 @@ const Root$7 = styled(Layer)(responsivePaddingStyle, dialogStyle, responsiveDial
|
|
|
8007
8008
|
const DialogContainer = styled(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"])));
|
|
8008
8009
|
const DialogCardRoot = styled(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"])));
|
|
8009
8010
|
const DialogLayout = styled(Flex)(_c$2 || (_c$2 = __template$b(["\n flex: 1;\n min-height: 0;\n width: 100%;\n"])));
|
|
8010
|
-
const DialogHeader = styled(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:
|
|
8011
|
+
const DialogHeader = styled(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);
|
|
8011
8012
|
const DialogContent = styled(Box)(_e || (_e = __template$b(["\n position: relative;\n z-index: 1;\n overflow: auto;\n outline: none;\n"])));
|
|
8012
|
-
const DialogFooter = styled(Box)(_f || (_f = __template$b(["\n position: relative;\n z-index: 3;\n border-top: 1px solid var(--card-
|
|
8013
|
+
const DialogFooter = styled(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);
|
|
8013
8014
|
const DialogCard = forwardRef(function DialogCard2(props, ref) {
|
|
8014
8015
|
var _a2;
|
|
8015
8016
|
const {
|
|
@@ -8044,6 +8045,9 @@ const DialogCard = forwardRef(function DialogCard2(props, ref) {
|
|
|
8044
8045
|
const labelId = "".concat(id, "_label");
|
|
8045
8046
|
const showCloseButton = Boolean(onClose) && hideCloseButton === false;
|
|
8046
8047
|
const showHeader = Boolean(header) || showCloseButton;
|
|
8048
|
+
const [isContentScrollable, setIsContentScrollable] = useState(false);
|
|
8049
|
+
const [hasScrolledFromTop, setHasScrolledFromTop] = useState(false);
|
|
8050
|
+
const [hasScrolledToBottom, setHasScrolledToBottom] = useState(false);
|
|
8047
8051
|
useEffect(() => {
|
|
8048
8052
|
if (!autoFocus) return;
|
|
8049
8053
|
if (forwardedRef.current) {
|
|
@@ -8078,6 +8082,22 @@ const DialogCard = forwardRef(function DialogCard2(props, ref) {
|
|
|
8078
8082
|
localContentRef.current = el;
|
|
8079
8083
|
if (typeof contentRef === "function") contentRef(el);else if (contentRef) contentRef.current = el;
|
|
8080
8084
|
}, [contentRef]);
|
|
8085
|
+
const handleContentUpdate = useCallback(() => {
|
|
8086
|
+
if (localContentRef.current) {
|
|
8087
|
+
setIsContentScrollable(localContentRef.current.clientHeight < localContentRef.current.scrollHeight);
|
|
8088
|
+
setHasScrolledFromTop(localContentRef.current.scrollTop > 0);
|
|
8089
|
+
setHasScrolledToBottom(localContentRef.current.scrollTop >= localContentRef.current.scrollHeight - localContentRef.current.clientHeight);
|
|
8090
|
+
}
|
|
8091
|
+
}, []);
|
|
8092
|
+
useEffect(() => {
|
|
8093
|
+
const resizeObserver = new ResizeObserver(handleContentUpdate);
|
|
8094
|
+
if (localContentRef.current) {
|
|
8095
|
+
resizeObserver.observe(localContentRef.current);
|
|
8096
|
+
}
|
|
8097
|
+
return () => {
|
|
8098
|
+
resizeObserver.disconnect();
|
|
8099
|
+
};
|
|
8100
|
+
}, [contentRef, handleContentUpdate]);
|
|
8081
8101
|
return /* @__PURE__ */jsx(DialogContainer, {
|
|
8082
8102
|
"data-ui": "DialogCard",
|
|
8083
8103
|
width,
|
|
@@ -8089,13 +8109,16 @@ const DialogCard = forwardRef(function DialogCard2(props, ref) {
|
|
|
8089
8109
|
children: /* @__PURE__ */jsxs(DialogLayout, {
|
|
8090
8110
|
direction: "column",
|
|
8091
8111
|
children: [showHeader && /* @__PURE__ */jsx(DialogHeader, {
|
|
8112
|
+
$isContentScrollable: isContentScrollable,
|
|
8113
|
+
$hasScrolledFromTop: hasScrolledFromTop,
|
|
8092
8114
|
children: /* @__PURE__ */jsxs(Flex, {
|
|
8093
8115
|
children: [/* @__PURE__ */jsx(Box, {
|
|
8094
8116
|
flex: 1,
|
|
8095
8117
|
padding: 4,
|
|
8096
8118
|
children: header && /* @__PURE__ */jsx(Text, {
|
|
8097
8119
|
id: labelId,
|
|
8098
|
-
|
|
8120
|
+
size: 1,
|
|
8121
|
+
weight: "medium",
|
|
8099
8122
|
children: header
|
|
8100
8123
|
})
|
|
8101
8124
|
}), showCloseButton && /* @__PURE__ */jsx(Box, {
|
|
@@ -8114,8 +8137,11 @@ const DialogCard = forwardRef(function DialogCard2(props, ref) {
|
|
|
8114
8137
|
flex: 1,
|
|
8115
8138
|
ref: setContentRef,
|
|
8116
8139
|
tabIndex: -1,
|
|
8140
|
+
onScroll: handleContentUpdate,
|
|
8117
8141
|
children
|
|
8118
8142
|
}), footer && /* @__PURE__ */jsx(DialogFooter, {
|
|
8143
|
+
$isContentScrollable: isContentScrollable,
|
|
8144
|
+
$hasScrolledToBottom: hasScrolledToBottom,
|
|
8119
8145
|
children: footer
|
|
8120
8146
|
})]
|
|
8121
8147
|
})
|