@sproutsocial/seeds-react-peek-in 0.0.10 → 0.2.8

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.js CHANGED
@@ -31,9 +31,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  PeekIn: () => PeekIn,
34
+ PeekInContent: () => PeekInContent,
34
35
  PeekInHeader: () => PeekInHeader,
35
- PeekInMain: () => PeekInMain,
36
- PeekInRail: () => PeekInRail,
36
+ PeekInPanel: () => PeekInPanel,
37
37
  PeekInTrigger: () => PeekInTrigger
38
38
  });
39
39
  module.exports = __toCommonJS(index_exports);
@@ -41,6 +41,11 @@ module.exports = __toCommonJS(index_exports);
41
41
  // src/PeekIn.tsx
42
42
  var React21 = __toESM(require("react"));
43
43
  var import_seeds_react_box4 = __toESM(require("@sproutsocial/seeds-react-box"));
44
+ var import_seeds_react_button2 = __toESM(require("@sproutsocial/seeds-react-button"));
45
+ var import_seeds_react_drawer2 = __toESM(require("@sproutsocial/seeds-react-drawer"));
46
+ var import_seeds_react_icon2 = __toESM(require("@sproutsocial/seeds-react-icon"));
47
+ var import_seeds_react_text2 = __toESM(require("@sproutsocial/seeds-react-text"));
48
+ var import_seeds_react_hooks2 = require("@sproutsocial/seeds-react-hooks");
44
49
  var import_v2 = require("@sproutsocial/seeds-react-modal/v2");
45
50
 
46
51
  // src/PeekInContext.ts
@@ -103,31 +108,34 @@ var PeekInHeader = ({
103
108
  };
104
109
  PeekInHeader.displayName = "PeekInHeader";
105
110
 
106
- // src/components/PeekInMain.tsx
111
+ // src/components/PeekInContent.tsx
107
112
  var React3 = require("react");
108
113
  var import_seeds_react_box2 = __toESM(require("@sproutsocial/seeds-react-box"));
109
114
  var import_jsx_runtime2 = require("react/jsx-runtime");
110
- var PeekInMain = ({ children }) => {
115
+ var PeekInContent = ({
116
+ children
117
+ }) => {
111
118
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
112
119
  import_seeds_react_box2.default,
113
120
  {
114
121
  flex: "1 1 auto",
115
122
  overflow: "auto",
116
123
  color: "text.body",
117
- "data-slot": "peek-in-main",
118
- "data-qa-peek-in-main": true,
124
+ "data-slot": "peek-in-content",
125
+ "data-qa-peek-in-content": true,
126
+ "data-drawer-content": "",
119
127
  children
120
128
  }
121
129
  );
122
130
  };
123
- PeekInMain.displayName = "PeekInMain";
131
+ PeekInContent.displayName = "PeekInContent";
124
132
 
125
- // src/components/PeekInRail.tsx
126
- var React4 = require("react");
127
- var import_styled_components = __toESM(require("styled-components"));
133
+ // src/components/PeekInPanel.tsx
134
+ var React4 = __toESM(require("react"));
128
135
  var import_seeds_react_box3 = __toESM(require("@sproutsocial/seeds-react-box"));
129
- var import_seeds_react_text2 = __toESM(require("@sproutsocial/seeds-react-text"));
130
- var import_react = require("motion/react");
136
+ var import_seeds_react_drawer = __toESM(require("@sproutsocial/seeds-react-drawer"));
137
+ var import_seeds_react_hooks = require("@sproutsocial/seeds-react-hooks");
138
+ var import_seeds_react_panel = require("@sproutsocial/seeds-react-panel");
131
139
 
132
140
  // src/constants.ts
133
141
  var PEEK_IN_WIDTH = "calc(100vw - 64px)";
@@ -136,66 +144,86 @@ var ACTION_BUTTON_SIZE = 44;
136
144
  var ACTION_STRIP_OFFSET = 12;
137
145
  var ACTION_STRIP_TOTAL_WIDTH = ACTION_BUTTON_SIZE + ACTION_STRIP_OFFSET;
138
146
  var RAIL_DEFAULT_WIDTH = 360;
139
- var RAIL_ANIMATION_DURATION = 0.64;
147
+ var RAIL_GAP = 4;
140
148
 
141
- // src/components/PeekInRail.tsx
149
+ // src/components/PeekInPanel.tsx
142
150
  var import_jsx_runtime3 = require("react/jsx-runtime");
143
- var RailWrapper = (0, import_styled_components.default)(import_react.motion.div)`
144
- overflow: hidden;
145
- flex-shrink: 0;
146
- padding-left: 4px;
147
- `;
148
- var RailPanel = import_styled_components.default.div`
149
- display: flex;
150
- flex-direction: column;
151
- background: ${(props) => props.theme.colors.container.background.base};
152
- border-radius: ${(props) => props.theme.radii[800]};
153
- height: 100%;
154
- overflow: hidden;
155
- `;
156
- var PeekInRail = ({
151
+ var PeekInPanel = ({
157
152
  title,
158
- children
153
+ children,
154
+ snapPoints,
155
+ defaultSnapPoint,
156
+ snapPoint,
157
+ onSnapPointChange,
158
+ snapToSequentialPoints,
159
+ disableCloseOnClickOutside,
160
+ actionsInHeader
159
161
  }) => {
160
- const { railOpen, railId } = usePeekInContext();
161
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react.AnimatePresence, { initial: false, children: railOpen && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
162
- RailWrapper,
162
+ const { panelOpen, setPanelOpen, panelId } = usePeekInContext();
163
+ const isMobile = (0, import_seeds_react_hooks.useIsMobile)();
164
+ const parentDrawer = React4.useContext(import_seeds_react_drawer.DrawerContext);
165
+ React4.useEffect(() => {
166
+ if (isMobile) parentDrawer.setIsLocked(panelOpen);
167
+ }, [isMobile, panelOpen, parentDrawer]);
168
+ if (isMobile) {
169
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
170
+ import_seeds_react_drawer.default,
171
+ {
172
+ open: panelOpen,
173
+ onClose: () => setPanelOpen(false),
174
+ direction: "bottom",
175
+ closeButtonLabel: "Close",
176
+ snapPoints,
177
+ defaultSnapPoint,
178
+ snapPoint,
179
+ onSnapPointChange,
180
+ snapToSequentialPoints,
181
+ disableCloseOnClickOutside,
182
+ actionsInHeader,
183
+ "aria-label": title ?? "Panel",
184
+ children: [
185
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_seeds_react_drawer.default.Header, { title }),
186
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_seeds_react_drawer.default.Content, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
187
+ import_seeds_react_box3.default,
188
+ {
189
+ id: panelId,
190
+ role: "region",
191
+ "aria-label": title,
192
+ "data-slot": "peek-in-panel",
193
+ "data-qa-peek-in-panel": true,
194
+ children
195
+ }
196
+ ) })
197
+ ]
198
+ }
199
+ );
200
+ }
201
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_seeds_react_panel.PanelProvider, { open: panelOpen, onOpenChange: setPanelOpen, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
202
+ import_seeds_react_panel.Panel,
163
203
  {
164
- initial: { width: 0 },
165
- animate: { width: RAIL_DEFAULT_WIDTH + 4 },
166
- exit: { width: 0 },
167
- transition: { duration: RAIL_ANIMATION_DURATION, ease: "easeInOut" },
168
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
169
- RailPanel,
204
+ closeButtonLabel: "Close",
205
+ direction: "right",
206
+ width: RAIL_DEFAULT_WIDTH,
207
+ gap: RAIL_GAP,
208
+ mobileBreakpoint: 0,
209
+ title,
210
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
211
+ import_seeds_react_box3.default,
170
212
  {
171
- id: railId,
213
+ id: panelId,
172
214
  role: "region",
173
- "aria-label": typeof title === "string" ? title : void 0,
215
+ "aria-label": title,
174
216
  "data-slot": "peek-in-rail",
175
217
  "data-qa-peek-in-rail": true,
176
- children: [
177
- title && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
178
- import_seeds_react_box3.default,
179
- {
180
- display: "flex",
181
- alignItems: "center",
182
- justifyContent: "space-between",
183
- py: 300,
184
- px: 400,
185
- borderBottom: "1px solid",
186
- borderColor: "container.border.base",
187
- flexShrink: 0,
188
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_seeds_react_text2.default.SubHeadline, { as: "h3", children: title })
189
- }
190
- ),
191
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_seeds_react_box3.default, { flex: "1 1 auto", overflow: "auto", children })
192
- ]
218
+ flex: "1 1 auto",
219
+ overflow: "auto",
220
+ children
193
221
  }
194
222
  )
195
223
  }
196
224
  ) });
197
225
  };
198
- PeekInRail.displayName = "PeekInRail";
226
+ PeekInPanel.displayName = "PeekInPanel";
199
227
 
200
228
  // src/components/PeekInTrigger.tsx
201
229
  var React20 = require("react");
@@ -414,7 +442,6 @@ function useUncontrolledState({
414
442
  function isFunction(value) {
415
443
  return typeof value === "function";
416
444
  }
417
- var SYNC_STATE = Symbol("RADIX:SYNC_STATE");
418
445
 
419
446
  // ../../node_modules/@radix-ui/react-dismissable-layer/dist/index.mjs
420
447
  var React14 = __toESM(require("react"), 1);
@@ -467,7 +494,7 @@ function createSlotClone(ownerName) {
467
494
  SlotClone.displayName = `${ownerName}.SlotClone`;
468
495
  return SlotClone;
469
496
  }
470
- var SLOTTABLE_IDENTIFIER = Symbol("radix.slottable");
497
+ var SLOTTABLE_IDENTIFIER = /* @__PURE__ */ Symbol("radix.slottable");
471
498
  function isSlottable(child) {
472
499
  return React10.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
473
500
  }
@@ -536,7 +563,7 @@ var Primitive = NODES.reduce((primitive, node) => {
536
563
  const { asChild, ...primitiveProps } = props;
537
564
  const Comp = asChild ? Slot2 : node;
538
565
  if (typeof window !== "undefined") {
539
- window[Symbol.for("radix-ui")] = true;
566
+ window[/* @__PURE__ */ Symbol.for("radix-ui")] = true;
540
567
  }
541
568
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Comp, { ...primitiveProps, ref: forwardedRef });
542
569
  });
@@ -1594,41 +1621,179 @@ var PeekInRoot = ({
1594
1621
  onOpenChange,
1595
1622
  closeButtonAriaLabel = "Close",
1596
1623
  actions,
1597
- railToggle,
1624
+ panelToggle,
1625
+ snapPoints,
1626
+ defaultSnapPoint,
1627
+ snapPoint,
1628
+ onSnapPointChange,
1629
+ snapToSequentialPoints,
1630
+ disableCloseOnClickOutside,
1631
+ actionsInHeader,
1598
1632
  children
1599
1633
  }) => {
1600
1634
  const header = getChildByType(children, PeekInHeader);
1601
- const main = getChildByType(children, PeekInMain);
1602
- const rail = getChildByType(children, PeekInRail);
1635
+ const content = getChildByType(children, PeekInContent);
1636
+ const panel = getChildByType(children, PeekInPanel);
1603
1637
  const trigger = getChildByType(children, PeekInTrigger);
1604
- const railDefaultOpen = rail?.props?.defaultOpen ?? true;
1605
- const [railOpen, setRailOpen] = React21.useState(railDefaultOpen);
1606
- const railId = React21.useId();
1638
+ const panelDefaultOpen = panel?.props?.defaultOpen ?? true;
1639
+ const [panelOpen, setPanelOpen] = React21.useState(panelDefaultOpen);
1640
+ const panelId = React21.useId();
1607
1641
  const handleClose = React21.useCallback(() => {
1608
1642
  onOpenChange?.(false);
1609
1643
  }, [onOpenChange]);
1610
1644
  const contextValue = React21.useMemo(
1611
- () => ({ onClose: handleClose, railOpen, setRailOpen, railId }),
1612
- [handleClose, railOpen, railId]
1645
+ () => ({ onClose: handleClose, panelOpen, setPanelOpen, panelId }),
1646
+ [handleClose, panelOpen, panelId]
1613
1647
  );
1614
1648
  const ariaLabel = typeof header?.props?.title === "string" ? header.props.title : "Dialog";
1615
1649
  const triggerElement = trigger ? trigger.props.children : void 0;
1616
1650
  const modalActions = React21.useMemo(() => {
1617
1651
  const result = [];
1618
- if (railToggle && rail) {
1652
+ if (panelToggle && panel) {
1619
1653
  result.push({
1620
- "aria-label": railToggle["aria-label"] ?? "Toggle panel",
1621
- iconName: railToggle.iconName,
1622
- onClick: () => setRailOpen((prev) => !prev),
1623
- "aria-expanded": railOpen,
1624
- "aria-controls": railId
1654
+ "aria-label": panelToggle["aria-label"] ?? "Toggle panel",
1655
+ iconName: panelToggle.iconName,
1656
+ onClick: () => setPanelOpen((prev) => !prev),
1657
+ "aria-expanded": panelOpen,
1658
+ "aria-controls": panelId
1625
1659
  });
1626
1660
  }
1627
1661
  if (actions) {
1628
1662
  result.push(...actions);
1629
1663
  }
1630
1664
  return result.length > 0 ? result : void 0;
1631
- }, [railToggle, rail, actions, railOpen, railId]);
1665
+ }, [panelToggle, panel, actions, panelOpen, panelId]);
1666
+ const drawerActions = React21.useMemo(() => {
1667
+ const result = [];
1668
+ if (panelToggle && panel) {
1669
+ result.push({
1670
+ "aria-label": panelToggle["aria-label"] ?? "Toggle panel",
1671
+ iconName: panelToggle.iconName,
1672
+ onClick: () => setPanelOpen((prev) => !prev),
1673
+ "aria-expanded": panelOpen,
1674
+ "aria-controls": panelId
1675
+ });
1676
+ }
1677
+ if (actions) {
1678
+ result.push(...actions);
1679
+ }
1680
+ return result.length > 0 ? result : void 0;
1681
+ }, [panelToggle, panel, actions, panelOpen, panelId]);
1682
+ const isMobile = (0, import_seeds_react_hooks2.useIsMobile)();
1683
+ const isControlled = open !== void 0;
1684
+ const [internalOpen, setInternalOpen] = React21.useState(defaultOpen ?? false);
1685
+ const effectiveMobileOpen = isControlled ? open ?? false : internalOpen;
1686
+ const handleMobileOpen = React21.useCallback(() => {
1687
+ if (!isControlled) setInternalOpen(true);
1688
+ onOpenChange?.(true);
1689
+ }, [isControlled, onOpenChange]);
1690
+ const handleMobileClose = React21.useCallback(() => {
1691
+ if (!isControlled) setInternalOpen(false);
1692
+ onOpenChange?.(false);
1693
+ }, [isControlled, onOpenChange]);
1694
+ const mobileTrigger = trigger ? React21.cloneElement(trigger.props.children, {
1695
+ onClick: handleMobileOpen
1696
+ }) : void 0;
1697
+ if (isMobile) {
1698
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(PeekInContext.Provider, { value: contextValue, children: [
1699
+ mobileTrigger,
1700
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
1701
+ import_seeds_react_drawer2.default,
1702
+ {
1703
+ open: effectiveMobileOpen,
1704
+ onClose: handleMobileClose,
1705
+ direction: "bottom",
1706
+ closeButtonLabel: closeButtonAriaLabel,
1707
+ snapPoints,
1708
+ defaultSnapPoint,
1709
+ snapPoint,
1710
+ onSnapPointChange,
1711
+ snapToSequentialPoints,
1712
+ disableCloseOnClickOutside,
1713
+ actions: drawerActions,
1714
+ actionsInHeader,
1715
+ "aria-label": ariaLabel,
1716
+ children: [
1717
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1718
+ import_seeds_react_drawer2.default.Header,
1719
+ {
1720
+ render: (ctx) => /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
1721
+ import_seeds_react_box4.default,
1722
+ {
1723
+ display: "flex",
1724
+ alignItems: "center",
1725
+ justifyContent: "space-between",
1726
+ pt: 400,
1727
+ px: 450,
1728
+ flex: "0 0 auto",
1729
+ children: [
1730
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_seeds_react_box4.default, { display: "flex", alignItems: "center", gap: 300, children: [
1731
+ header?.props?.onBack && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1732
+ import_seeds_react_button2.default,
1733
+ {
1734
+ appearance: "unstyled",
1735
+ onClick: header.props.onBack,
1736
+ "aria-label": "Back",
1737
+ "data-qa-peek-in-back": true,
1738
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_seeds_react_icon2.default, { name: "arrow-left-outline", size: "small" })
1739
+ }
1740
+ ),
1741
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1742
+ import_seeds_react_text2.default,
1743
+ {
1744
+ as: "h2",
1745
+ fontSize: 400,
1746
+ fontWeight: "semibold",
1747
+ color: "text.headline",
1748
+ "data-qa-peek-in-title": true,
1749
+ children: header?.props?.title
1750
+ }
1751
+ )
1752
+ ] }),
1753
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_seeds_react_box4.default, { display: "flex", alignItems: "center", gap: 200, children: [
1754
+ header?.props?.children,
1755
+ actionsInHeader && panelToggle && panel && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1756
+ import_seeds_react_button2.default,
1757
+ {
1758
+ appearance: "pill",
1759
+ "aria-label": panelToggle["aria-label"] ?? "Toggle panel",
1760
+ onClick: () => setPanelOpen((p) => !p),
1761
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_seeds_react_icon2.default, { "aria-hidden": true, name: panelToggle.iconName })
1762
+ }
1763
+ ),
1764
+ actionsInHeader && actions?.map((action, i) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1765
+ import_seeds_react_button2.default,
1766
+ {
1767
+ appearance: "pill",
1768
+ "aria-label": action["aria-label"],
1769
+ onClick: action.onClick,
1770
+ disabled: action.disabled,
1771
+ children: action.iconName && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_seeds_react_icon2.default, { "aria-hidden": true, name: action.iconName })
1772
+ },
1773
+ i
1774
+ )),
1775
+ (actionsInHeader || !drawerActions) && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1776
+ import_seeds_react_button2.default,
1777
+ {
1778
+ appearance: "pill",
1779
+ "aria-label": ctx.closeButtonLabel,
1780
+ onClick: ctx.onClose,
1781
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_seeds_react_icon2.default, { "aria-hidden": true, name: "x-outline" })
1782
+ }
1783
+ )
1784
+ ] })
1785
+ ]
1786
+ }
1787
+ )
1788
+ }
1789
+ ),
1790
+ content,
1791
+ panel
1792
+ ]
1793
+ }
1794
+ )
1795
+ ] });
1796
+ }
1632
1797
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(PeekInContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1633
1798
  import_v2.Modal,
1634
1799
  {
@@ -1654,11 +1819,11 @@ var PeekInRoot = ({
1654
1819
  borderRadius: 800,
1655
1820
  children: [
1656
1821
  header,
1657
- main
1822
+ content
1658
1823
  ]
1659
1824
  }
1660
1825
  ),
1661
- rail
1826
+ panel
1662
1827
  ] })
1663
1828
  }
1664
1829
  ) });
@@ -1668,9 +1833,9 @@ var PeekIn = PeekInRoot;
1668
1833
  // Annotate the CommonJS export names for ESM import in node:
1669
1834
  0 && (module.exports = {
1670
1835
  PeekIn,
1836
+ PeekInContent,
1671
1837
  PeekInHeader,
1672
- PeekInMain,
1673
- PeekInRail,
1838
+ PeekInPanel,
1674
1839
  PeekInTrigger
1675
1840
  });
1676
1841
  //# sourceMappingURL=index.js.map