@sproutsocial/seeds-react-peek-in 0.0.11 → 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/esm/index.js CHANGED
@@ -1,6 +1,11 @@
1
1
  // src/PeekIn.tsx
2
2
  import * as React21 from "react";
3
3
  import Box4 from "@sproutsocial/seeds-react-box";
4
+ import Button2 from "@sproutsocial/seeds-react-button";
5
+ import Drawer2 from "@sproutsocial/seeds-react-drawer";
6
+ import Icon2 from "@sproutsocial/seeds-react-icon";
7
+ import Text2 from "@sproutsocial/seeds-react-text";
8
+ import { useIsMobile as useIsMobile2 } from "@sproutsocial/seeds-react-hooks";
4
9
  import { Modal, ModalBody } from "@sproutsocial/seeds-react-modal/v2";
5
10
 
6
11
  // src/PeekInContext.ts
@@ -63,31 +68,34 @@ var PeekInHeader = ({
63
68
  };
64
69
  PeekInHeader.displayName = "PeekInHeader";
65
70
 
66
- // src/components/PeekInMain.tsx
71
+ // src/components/PeekInContent.tsx
67
72
  import "react";
68
73
  import Box2 from "@sproutsocial/seeds-react-box";
69
74
  import { jsx as jsx2 } from "react/jsx-runtime";
70
- var PeekInMain = ({ children }) => {
75
+ var PeekInContent = ({
76
+ children
77
+ }) => {
71
78
  return /* @__PURE__ */ jsx2(
72
79
  Box2,
73
80
  {
74
81
  flex: "1 1 auto",
75
82
  overflow: "auto",
76
83
  color: "text.body",
77
- "data-slot": "peek-in-main",
78
- "data-qa-peek-in-main": true,
84
+ "data-slot": "peek-in-content",
85
+ "data-qa-peek-in-content": true,
86
+ "data-drawer-content": "",
79
87
  children
80
88
  }
81
89
  );
82
90
  };
83
- PeekInMain.displayName = "PeekInMain";
91
+ PeekInContent.displayName = "PeekInContent";
84
92
 
85
- // src/components/PeekInRail.tsx
86
- import "react";
87
- import styled from "styled-components";
93
+ // src/components/PeekInPanel.tsx
94
+ import * as React4 from "react";
88
95
  import Box3 from "@sproutsocial/seeds-react-box";
89
- import Text2 from "@sproutsocial/seeds-react-text";
90
- import { AnimatePresence, motion } from "motion/react";
96
+ import Drawer, { DrawerContext } from "@sproutsocial/seeds-react-drawer";
97
+ import { useIsMobile } from "@sproutsocial/seeds-react-hooks";
98
+ import { Panel, PanelProvider } from "@sproutsocial/seeds-react-panel";
91
99
 
92
100
  // src/constants.ts
93
101
  var PEEK_IN_WIDTH = "calc(100vw - 64px)";
@@ -96,66 +104,86 @@ var ACTION_BUTTON_SIZE = 44;
96
104
  var ACTION_STRIP_OFFSET = 12;
97
105
  var ACTION_STRIP_TOTAL_WIDTH = ACTION_BUTTON_SIZE + ACTION_STRIP_OFFSET;
98
106
  var RAIL_DEFAULT_WIDTH = 360;
99
- var RAIL_ANIMATION_DURATION = 0.64;
107
+ var RAIL_GAP = 4;
100
108
 
101
- // src/components/PeekInRail.tsx
109
+ // src/components/PeekInPanel.tsx
102
110
  import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
103
- var RailWrapper = styled(motion.div)`
104
- overflow: hidden;
105
- flex-shrink: 0;
106
- padding-left: 4px;
107
- `;
108
- var RailPanel = styled.div`
109
- display: flex;
110
- flex-direction: column;
111
- background: ${(props) => props.theme.colors.container.background.base};
112
- border-radius: ${(props) => props.theme.radii[800]};
113
- height: 100%;
114
- overflow: hidden;
115
- `;
116
- var PeekInRail = ({
111
+ var PeekInPanel = ({
117
112
  title,
118
- children
113
+ children,
114
+ snapPoints,
115
+ defaultSnapPoint,
116
+ snapPoint,
117
+ onSnapPointChange,
118
+ snapToSequentialPoints,
119
+ disableCloseOnClickOutside,
120
+ actionsInHeader
119
121
  }) => {
120
- const { railOpen, railId } = usePeekInContext();
121
- return /* @__PURE__ */ jsx3(AnimatePresence, { initial: false, children: railOpen && /* @__PURE__ */ jsx3(
122
- RailWrapper,
122
+ const { panelOpen, setPanelOpen, panelId } = usePeekInContext();
123
+ const isMobile = useIsMobile();
124
+ const parentDrawer = React4.useContext(DrawerContext);
125
+ React4.useEffect(() => {
126
+ if (isMobile) parentDrawer.setIsLocked(panelOpen);
127
+ }, [isMobile, panelOpen, parentDrawer]);
128
+ if (isMobile) {
129
+ return /* @__PURE__ */ jsxs2(
130
+ Drawer,
131
+ {
132
+ open: panelOpen,
133
+ onClose: () => setPanelOpen(false),
134
+ direction: "bottom",
135
+ closeButtonLabel: "Close",
136
+ snapPoints,
137
+ defaultSnapPoint,
138
+ snapPoint,
139
+ onSnapPointChange,
140
+ snapToSequentialPoints,
141
+ disableCloseOnClickOutside,
142
+ actionsInHeader,
143
+ "aria-label": title ?? "Panel",
144
+ children: [
145
+ /* @__PURE__ */ jsx3(Drawer.Header, { title }),
146
+ /* @__PURE__ */ jsx3(Drawer.Content, { children: /* @__PURE__ */ jsx3(
147
+ Box3,
148
+ {
149
+ id: panelId,
150
+ role: "region",
151
+ "aria-label": title,
152
+ "data-slot": "peek-in-panel",
153
+ "data-qa-peek-in-panel": true,
154
+ children
155
+ }
156
+ ) })
157
+ ]
158
+ }
159
+ );
160
+ }
161
+ return /* @__PURE__ */ jsx3(PanelProvider, { open: panelOpen, onOpenChange: setPanelOpen, children: /* @__PURE__ */ jsx3(
162
+ Panel,
123
163
  {
124
- initial: { width: 0 },
125
- animate: { width: RAIL_DEFAULT_WIDTH + 4 },
126
- exit: { width: 0 },
127
- transition: { duration: RAIL_ANIMATION_DURATION, ease: "easeInOut" },
128
- children: /* @__PURE__ */ jsxs2(
129
- RailPanel,
164
+ closeButtonLabel: "Close",
165
+ direction: "right",
166
+ width: RAIL_DEFAULT_WIDTH,
167
+ gap: RAIL_GAP,
168
+ mobileBreakpoint: 0,
169
+ title,
170
+ children: /* @__PURE__ */ jsx3(
171
+ Box3,
130
172
  {
131
- id: railId,
173
+ id: panelId,
132
174
  role: "region",
133
- "aria-label": typeof title === "string" ? title : void 0,
175
+ "aria-label": title,
134
176
  "data-slot": "peek-in-rail",
135
177
  "data-qa-peek-in-rail": true,
136
- children: [
137
- title && /* @__PURE__ */ jsx3(
138
- Box3,
139
- {
140
- display: "flex",
141
- alignItems: "center",
142
- justifyContent: "space-between",
143
- py: 300,
144
- px: 400,
145
- borderBottom: "1px solid",
146
- borderColor: "container.border.base",
147
- flexShrink: 0,
148
- children: /* @__PURE__ */ jsx3(Text2.SubHeadline, { as: "h3", children: title })
149
- }
150
- ),
151
- /* @__PURE__ */ jsx3(Box3, { flex: "1 1 auto", overflow: "auto", children })
152
- ]
178
+ flex: "1 1 auto",
179
+ overflow: "auto",
180
+ children
153
181
  }
154
182
  )
155
183
  }
156
184
  ) });
157
185
  };
158
- PeekInRail.displayName = "PeekInRail";
186
+ PeekInPanel.displayName = "PeekInPanel";
159
187
 
160
188
  // src/components/PeekInTrigger.tsx
161
189
  import "react";
@@ -374,7 +402,6 @@ function useUncontrolledState({
374
402
  function isFunction(value) {
375
403
  return typeof value === "function";
376
404
  }
377
- var SYNC_STATE = Symbol("RADIX:SYNC_STATE");
378
405
 
379
406
  // ../../node_modules/@radix-ui/react-dismissable-layer/dist/index.mjs
380
407
  import * as React14 from "react";
@@ -427,7 +454,7 @@ function createSlotClone(ownerName) {
427
454
  SlotClone.displayName = `${ownerName}.SlotClone`;
428
455
  return SlotClone;
429
456
  }
430
- var SLOTTABLE_IDENTIFIER = Symbol("radix.slottable");
457
+ var SLOTTABLE_IDENTIFIER = /* @__PURE__ */ Symbol("radix.slottable");
431
458
  function isSlottable(child) {
432
459
  return React10.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
433
460
  }
@@ -496,7 +523,7 @@ var Primitive = NODES.reduce((primitive, node) => {
496
523
  const { asChild, ...primitiveProps } = props;
497
524
  const Comp = asChild ? Slot2 : node;
498
525
  if (typeof window !== "undefined") {
499
- window[Symbol.for("radix-ui")] = true;
526
+ window[/* @__PURE__ */ Symbol.for("radix-ui")] = true;
500
527
  }
501
528
  return /* @__PURE__ */ jsx6(Comp, { ...primitiveProps, ref: forwardedRef });
502
529
  });
@@ -1554,41 +1581,179 @@ var PeekInRoot = ({
1554
1581
  onOpenChange,
1555
1582
  closeButtonAriaLabel = "Close",
1556
1583
  actions,
1557
- railToggle,
1584
+ panelToggle,
1585
+ snapPoints,
1586
+ defaultSnapPoint,
1587
+ snapPoint,
1588
+ onSnapPointChange,
1589
+ snapToSequentialPoints,
1590
+ disableCloseOnClickOutside,
1591
+ actionsInHeader,
1558
1592
  children
1559
1593
  }) => {
1560
1594
  const header = getChildByType(children, PeekInHeader);
1561
- const main = getChildByType(children, PeekInMain);
1562
- const rail = getChildByType(children, PeekInRail);
1595
+ const content = getChildByType(children, PeekInContent);
1596
+ const panel = getChildByType(children, PeekInPanel);
1563
1597
  const trigger = getChildByType(children, PeekInTrigger);
1564
- const railDefaultOpen = rail?.props?.defaultOpen ?? true;
1565
- const [railOpen, setRailOpen] = React21.useState(railDefaultOpen);
1566
- const railId = React21.useId();
1598
+ const panelDefaultOpen = panel?.props?.defaultOpen ?? true;
1599
+ const [panelOpen, setPanelOpen] = React21.useState(panelDefaultOpen);
1600
+ const panelId = React21.useId();
1567
1601
  const handleClose = React21.useCallback(() => {
1568
1602
  onOpenChange?.(false);
1569
1603
  }, [onOpenChange]);
1570
1604
  const contextValue = React21.useMemo(
1571
- () => ({ onClose: handleClose, railOpen, setRailOpen, railId }),
1572
- [handleClose, railOpen, railId]
1605
+ () => ({ onClose: handleClose, panelOpen, setPanelOpen, panelId }),
1606
+ [handleClose, panelOpen, panelId]
1573
1607
  );
1574
1608
  const ariaLabel = typeof header?.props?.title === "string" ? header.props.title : "Dialog";
1575
1609
  const triggerElement = trigger ? trigger.props.children : void 0;
1576
1610
  const modalActions = React21.useMemo(() => {
1577
1611
  const result = [];
1578
- if (railToggle && rail) {
1612
+ if (panelToggle && panel) {
1613
+ result.push({
1614
+ "aria-label": panelToggle["aria-label"] ?? "Toggle panel",
1615
+ iconName: panelToggle.iconName,
1616
+ onClick: () => setPanelOpen((prev) => !prev),
1617
+ "aria-expanded": panelOpen,
1618
+ "aria-controls": panelId
1619
+ });
1620
+ }
1621
+ if (actions) {
1622
+ result.push(...actions);
1623
+ }
1624
+ return result.length > 0 ? result : void 0;
1625
+ }, [panelToggle, panel, actions, panelOpen, panelId]);
1626
+ const drawerActions = React21.useMemo(() => {
1627
+ const result = [];
1628
+ if (panelToggle && panel) {
1579
1629
  result.push({
1580
- "aria-label": railToggle["aria-label"] ?? "Toggle panel",
1581
- iconName: railToggle.iconName,
1582
- onClick: () => setRailOpen((prev) => !prev),
1583
- "aria-expanded": railOpen,
1584
- "aria-controls": railId
1630
+ "aria-label": panelToggle["aria-label"] ?? "Toggle panel",
1631
+ iconName: panelToggle.iconName,
1632
+ onClick: () => setPanelOpen((prev) => !prev),
1633
+ "aria-expanded": panelOpen,
1634
+ "aria-controls": panelId
1585
1635
  });
1586
1636
  }
1587
1637
  if (actions) {
1588
1638
  result.push(...actions);
1589
1639
  }
1590
1640
  return result.length > 0 ? result : void 0;
1591
- }, [railToggle, rail, actions, railOpen, railId]);
1641
+ }, [panelToggle, panel, actions, panelOpen, panelId]);
1642
+ const isMobile = useIsMobile2();
1643
+ const isControlled = open !== void 0;
1644
+ const [internalOpen, setInternalOpen] = React21.useState(defaultOpen ?? false);
1645
+ const effectiveMobileOpen = isControlled ? open ?? false : internalOpen;
1646
+ const handleMobileOpen = React21.useCallback(() => {
1647
+ if (!isControlled) setInternalOpen(true);
1648
+ onOpenChange?.(true);
1649
+ }, [isControlled, onOpenChange]);
1650
+ const handleMobileClose = React21.useCallback(() => {
1651
+ if (!isControlled) setInternalOpen(false);
1652
+ onOpenChange?.(false);
1653
+ }, [isControlled, onOpenChange]);
1654
+ const mobileTrigger = trigger ? React21.cloneElement(trigger.props.children, {
1655
+ onClick: handleMobileOpen
1656
+ }) : void 0;
1657
+ if (isMobile) {
1658
+ return /* @__PURE__ */ jsxs4(PeekInContext.Provider, { value: contextValue, children: [
1659
+ mobileTrigger,
1660
+ /* @__PURE__ */ jsxs4(
1661
+ Drawer2,
1662
+ {
1663
+ open: effectiveMobileOpen,
1664
+ onClose: handleMobileClose,
1665
+ direction: "bottom",
1666
+ closeButtonLabel: closeButtonAriaLabel,
1667
+ snapPoints,
1668
+ defaultSnapPoint,
1669
+ snapPoint,
1670
+ onSnapPointChange,
1671
+ snapToSequentialPoints,
1672
+ disableCloseOnClickOutside,
1673
+ actions: drawerActions,
1674
+ actionsInHeader,
1675
+ "aria-label": ariaLabel,
1676
+ children: [
1677
+ /* @__PURE__ */ jsx12(
1678
+ Drawer2.Header,
1679
+ {
1680
+ render: (ctx) => /* @__PURE__ */ jsxs4(
1681
+ Box4,
1682
+ {
1683
+ display: "flex",
1684
+ alignItems: "center",
1685
+ justifyContent: "space-between",
1686
+ pt: 400,
1687
+ px: 450,
1688
+ flex: "0 0 auto",
1689
+ children: [
1690
+ /* @__PURE__ */ jsxs4(Box4, { display: "flex", alignItems: "center", gap: 300, children: [
1691
+ header?.props?.onBack && /* @__PURE__ */ jsx12(
1692
+ Button2,
1693
+ {
1694
+ appearance: "unstyled",
1695
+ onClick: header.props.onBack,
1696
+ "aria-label": "Back",
1697
+ "data-qa-peek-in-back": true,
1698
+ children: /* @__PURE__ */ jsx12(Icon2, { name: "arrow-left-outline", size: "small" })
1699
+ }
1700
+ ),
1701
+ /* @__PURE__ */ jsx12(
1702
+ Text2,
1703
+ {
1704
+ as: "h2",
1705
+ fontSize: 400,
1706
+ fontWeight: "semibold",
1707
+ color: "text.headline",
1708
+ "data-qa-peek-in-title": true,
1709
+ children: header?.props?.title
1710
+ }
1711
+ )
1712
+ ] }),
1713
+ /* @__PURE__ */ jsxs4(Box4, { display: "flex", alignItems: "center", gap: 200, children: [
1714
+ header?.props?.children,
1715
+ actionsInHeader && panelToggle && panel && /* @__PURE__ */ jsx12(
1716
+ Button2,
1717
+ {
1718
+ appearance: "pill",
1719
+ "aria-label": panelToggle["aria-label"] ?? "Toggle panel",
1720
+ onClick: () => setPanelOpen((p) => !p),
1721
+ children: /* @__PURE__ */ jsx12(Icon2, { "aria-hidden": true, name: panelToggle.iconName })
1722
+ }
1723
+ ),
1724
+ actionsInHeader && actions?.map((action, i) => /* @__PURE__ */ jsx12(
1725
+ Button2,
1726
+ {
1727
+ appearance: "pill",
1728
+ "aria-label": action["aria-label"],
1729
+ onClick: action.onClick,
1730
+ disabled: action.disabled,
1731
+ children: action.iconName && /* @__PURE__ */ jsx12(Icon2, { "aria-hidden": true, name: action.iconName })
1732
+ },
1733
+ i
1734
+ )),
1735
+ (actionsInHeader || !drawerActions) && /* @__PURE__ */ jsx12(
1736
+ Button2,
1737
+ {
1738
+ appearance: "pill",
1739
+ "aria-label": ctx.closeButtonLabel,
1740
+ onClick: ctx.onClose,
1741
+ children: /* @__PURE__ */ jsx12(Icon2, { "aria-hidden": true, name: "x-outline" })
1742
+ }
1743
+ )
1744
+ ] })
1745
+ ]
1746
+ }
1747
+ )
1748
+ }
1749
+ ),
1750
+ content,
1751
+ panel
1752
+ ]
1753
+ }
1754
+ )
1755
+ ] });
1756
+ }
1592
1757
  return /* @__PURE__ */ jsx12(PeekInContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx12(
1593
1758
  Modal,
1594
1759
  {
@@ -1614,11 +1779,11 @@ var PeekInRoot = ({
1614
1779
  borderRadius: 800,
1615
1780
  children: [
1616
1781
  header,
1617
- main
1782
+ content
1618
1783
  ]
1619
1784
  }
1620
1785
  ),
1621
- rail
1786
+ panel
1622
1787
  ] })
1623
1788
  }
1624
1789
  ) });
@@ -1627,9 +1792,9 @@ PeekInRoot.displayName = "PeekIn";
1627
1792
  var PeekIn = PeekInRoot;
1628
1793
  export {
1629
1794
  PeekIn,
1795
+ PeekInContent,
1630
1796
  PeekInHeader,
1631
- PeekInMain,
1632
- PeekInRail,
1797
+ PeekInPanel,
1633
1798
  PeekInTrigger
1634
1799
  };
1635
1800
  //# sourceMappingURL=index.js.map