@teamsparta/stack-bottom-sheet
Version:
stack bottom sheet
270 lines (263 loc) • 8.8 kB
JavaScript
"use client";
;
"use client";
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
var target = {};
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop];
if (source != null && __getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(source)) {
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
target[prop] = source[prop];
}
return target;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/compounds/BottomSheetContent.tsx
var BottomSheetContent_exports = {};
__export(BottomSheetContent_exports, {
BottomSheetContent: () => BottomSheetContent
});
module.exports = __toCommonJS(BottomSheetContent_exports);
var import_react3 = require("react");
var import_vaul2 = require("vaul");
// src/context.ts
var import_stack_utils = require("@teamsparta/stack-utils");
var [BottomSheetProvider, useBottomSheet] = (0, import_stack_utils.createContext)("BottomSheetRoot");
// src/style.ts
var import_react = require("@emotion/react");
var import_stack_tokens = require("@teamsparta/stack-tokens");
var import_stack_utils2 = require("@teamsparta/stack-utils");
var import_stack_z_index = require("@teamsparta/stack-z-index");
var bottomSheetBodyPaddingVar = "--stack-bottom-sheet-body-padding";
var BOTTOM_SHEET_MAX_WIDTH = 600;
var overlayCss = (0, import_react.css)({
backgroundColor: import_stack_tokens.vars.dimm.default,
position: "fixed",
inset: 0
});
var contentWrapperCss = (0, import_react.css)({
position: "fixed",
bottom: 0,
left: 0,
right: 0,
backgroundColor: import_stack_tokens.vars.background.modal,
borderRadius: "20px 20px 0 0",
boxShadow: import_stack_tokens.vars.shadow.elevation1,
zIndex: import_stack_z_index.zIndex.modal,
width: "100%",
maxWidth: BOTTOM_SHEET_MAX_WIDTH,
margin: "0 auto"
});
var contentCss = (0, import_react.css)({
display: "flex",
flexDirection: "column",
width: "100%",
maxHeight: "calc(100dvh - 40px)",
height: "auto"
});
var fogCss = (0, import_react.css)({
position: "absolute",
bottom: 0,
left: 0,
right: 0,
height: "16px",
background: `linear-gradient(to bottom, color-mix(in srgb, ${import_stack_tokens.vars.background.modal} 0%, transparent), ${import_stack_tokens.vars.background.modal})`
});
var bodyCss = (0, import_react.css)({
padding: (0, import_stack_utils2.getVar)(bottomSheetBodyPaddingVar),
flex: 1
});
var headerCss = (0, import_react.css)({
position: "relative",
padding: "28px 20px 16px 20px"
});
var headerDismissibleCss = (0, import_react.css)({
paddingTop: "40px"
});
var titleCss = (0, import_react.css)({
wordBreak: "keep-all",
whiteSpace: "pre-wrap"
});
var subTitleCss = (0, import_react.css)({
marginBottom: "4px"
});
var descriptionCss = (0, import_react.css)({
wordBreak: "keep-all",
whiteSpace: "pre-wrap",
marginTop: "4px"
});
var footerCss = (0, import_react.css)({
padding: "8px 20px 20px 20px"
});
var captionCss = (0, import_react.css)({
width: "100%",
marginTop: 16,
wordBreak: "keep-all",
whiteSpace: "pre-wrap"
});
var scrollAreaRootCss = (0, import_react.css)({
height: "100%",
width: "100%",
overflow: "hidden",
display: "flex",
flexDirection: "column"
});
var scrollAreaContentCss = (0, import_react.css)({
flex: 1,
overflow: "auto"
});
var scrollAreaScrollbarCss = (0, import_react.css)({
width: "12px",
display: "flex",
userSelect: "none",
touchAction: "none",
paddingInline: "4px",
transition: "background-color 160ms ease-out"
});
var scrollAreaThumbCss = (0, import_react.css)({
flex: 1,
backgroundColor: import_stack_tokens.vars.neutral[30],
borderRadius: "10px",
position: "relative",
transition: "background-color 160ms ease-out"
});
var closeButtonCss = (0, import_react.css)({
position: "absolute",
right: 16,
top: 20,
zIndex: 1,
display: "inline-flex",
alignItems: "center",
justifyContent: "center",
padding: 0,
width: 28,
height: 28,
flexShrink: 0,
borderRadius: "50%",
backgroundColor: import_stack_tokens.vars.fill.subtle,
border: "none",
cursor: "pointer"
});
var grabberCss = (0, import_react.css)({
"&&": {
position: "absolute",
top: 12,
left: "50%",
transform: "translateX(-50%)",
width: 40,
height: 4,
borderRadius: 100,
backgroundColor: import_stack_tokens.vars.bottomSheet.grabber.background
},
"& [data-vaul-handle-hitarea]": {
width: "100vw",
maxWidth: BOTTOM_SHEET_MAX_WIDTH
}
});
// src/compounds/BottomSheetOverlay.tsx
var import_stack_core = require("@teamsparta/stack-core");
var import_stack_z_index2 = require("@teamsparta/stack-z-index");
var import_react2 = require("react");
var import_vaul = require("vaul");
var import_jsx_runtime = require("@emotion/react/jsx-runtime");
var BottomSheetOverlay = (0, import_react2.forwardRef)((_a, ref) => {
var _b = _a, { children, style: styleFromProps } = _b, restProps = __objRest(_b, ["children", "style"]);
const { theme } = useBottomSheet("BottomSheetOverlay");
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_vaul.Drawer.Overlay,
__spreadProps(__spreadValues({
asChild: false,
ref,
style: __spreadValues({
position: "relative",
zIndex: import_stack_z_index2.zIndex.overlay
}, styleFromProps)
}, restProps), {
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_core.StackThemeProvider, { theme, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { css: overlayCss, children }) })
})
);
});
BottomSheetOverlay.displayName = "BottomSheetOverlay";
// src/compounds/BottomSheetContent.tsx
var import_jsx_runtime2 = require("@emotion/react/jsx-runtime");
var BottomSheetContent = (0, import_react3.forwardRef)(
(_a, ref) => {
var _b = _a, {
children,
onInteractOutside,
style,
overlay = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BottomSheetOverlay, {})
} = _b, restProps = __objRest(_b, [
"children",
"onInteractOutside",
"style",
"overlay"
]);
const {
closeOnInteractOutside: closeOnInteractOutsideFromContext,
theme,
dismissible
} = useBottomSheet("BottomSheetContent");
const hasOverlay = overlay !== null;
const closeOnInteractOutside = hasOverlay && dismissible ? closeOnInteractOutsideFromContext : false;
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_vaul2.Drawer.Portal, { children: [
overlay,
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
import_vaul2.Drawer.Content,
__spreadProps(__spreadValues({
"data-stack-color-theme": theme,
ref,
asChild: false,
css: contentWrapperCss,
style,
onInteractOutside: closeOnInteractOutside ? onInteractOutside : (e) => {
e.preventDefault();
onInteractOutside == null ? void 0 : onInteractOutside(e);
}
}, restProps), {
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { css: contentCss, children })
})
)
] });
}
);
BottomSheetContent.displayName = "BottomSheetContent";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
BottomSheetContent
});