@sproutsocial/seeds-react-peek-in 0.4.4 → 0.5.1

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
@@ -2,7 +2,7 @@
2
2
  import { hasStyledProps } from "@sproutsocial/seeds-react-system-props";
3
3
 
4
4
  // src/PeekInStyled.tsx
5
- import * as React21 from "react";
5
+ import * as React24 from "react";
6
6
  import Box4 from "@sproutsocial/seeds-react-box";
7
7
  import Button2 from "@sproutsocial/seeds-react-button";
8
8
  import Drawer2 from "@sproutsocial/seeds-react-drawer";
@@ -1573,12 +1573,33 @@ var PeekInTrigger = ({
1573
1573
  };
1574
1574
  PeekInTrigger.displayName = "PeekInTrigger";
1575
1575
 
1576
+ // src/usePeekInPanelState.ts
1577
+ import * as React21 from "react";
1578
+ function usePeekInPanelState(panel) {
1579
+ const panelProps = panel?.props;
1580
+ const isControlled = panelProps?.open !== void 0;
1581
+ const onOpenChange = panelProps?.onOpenChange;
1582
+ const [internalOpen, setInternalOpen] = React21.useState(
1583
+ panelProps?.defaultOpen ?? true
1584
+ );
1585
+ const panelOpen = isControlled ? panelProps.open : internalOpen;
1586
+ const setPanelOpen = React21.useCallback(
1587
+ (next) => {
1588
+ const value = typeof next === "function" ? next(panelOpen) : next;
1589
+ if (!isControlled) setInternalOpen(value);
1590
+ onOpenChange?.(value);
1591
+ },
1592
+ [isControlled, onOpenChange, panelOpen]
1593
+ );
1594
+ return { panelOpen, setPanelOpen };
1595
+ }
1596
+
1576
1597
  // src/PeekInStyled.tsx
1577
1598
  import { jsx as jsx12, jsxs as jsxs4 } from "react/jsx-runtime";
1578
1599
  function getChildByType(children, type) {
1579
- const childArray = React21.Children.toArray(children);
1600
+ const childArray = React24.Children.toArray(children);
1580
1601
  return childArray.find(
1581
- (child) => React21.isValidElement(child) && child.type === type
1602
+ (child) => React24.isValidElement(child) && child.type === type
1582
1603
  ) || null;
1583
1604
  }
1584
1605
  var PeekInStyled = ({
@@ -1601,19 +1622,18 @@ var PeekInStyled = ({
1601
1622
  const content = getChildByType(children, PeekInContent);
1602
1623
  const panel = getChildByType(children, PeekInPanel);
1603
1624
  const trigger = getChildByType(children, PeekInTrigger);
1604
- const panelDefaultOpen = panel?.props?.defaultOpen ?? true;
1605
- const [panelOpen, setPanelOpen] = React21.useState(panelDefaultOpen);
1606
- const panelId = React21.useId();
1607
- const handleClose = React21.useCallback(() => {
1625
+ const { panelOpen, setPanelOpen } = usePeekInPanelState(panel);
1626
+ const panelId = React24.useId();
1627
+ const handleClose = React24.useCallback(() => {
1608
1628
  onOpenChange?.(false);
1609
1629
  }, [onOpenChange]);
1610
- const contextValue = React21.useMemo(
1630
+ const contextValue = React24.useMemo(
1611
1631
  () => ({ onClose: handleClose, panelOpen, setPanelOpen, panelId }),
1612
- [handleClose, panelOpen, panelId]
1632
+ [handleClose, panelOpen, setPanelOpen, panelId]
1613
1633
  );
1614
1634
  const ariaLabel = typeof header?.props?.title === "string" ? header.props.title : "Dialog";
1615
1635
  const triggerElement = trigger ? trigger.props.children : void 0;
1616
- const modalActions = React21.useMemo(() => {
1636
+ const modalActions = React24.useMemo(() => {
1617
1637
  const result = [];
1618
1638
  if (panelToggle && panel) {
1619
1639
  result.push({
@@ -1629,7 +1649,7 @@ var PeekInStyled = ({
1629
1649
  }
1630
1650
  return result.length > 0 ? result : void 0;
1631
1651
  }, [panelToggle, panel, actions, panelOpen, panelId]);
1632
- const drawerActions = React21.useMemo(() => {
1652
+ const drawerActions = React24.useMemo(() => {
1633
1653
  const result = [];
1634
1654
  if (panelToggle && panel) {
1635
1655
  result.push({
@@ -1647,17 +1667,17 @@ var PeekInStyled = ({
1647
1667
  }, [panelToggle, panel, actions, panelOpen, panelId]);
1648
1668
  const isMobile = useIsMobile2();
1649
1669
  const isControlled = open !== void 0;
1650
- const [internalOpen, setInternalOpen] = React21.useState(defaultOpen ?? false);
1670
+ const [internalOpen, setInternalOpen] = React24.useState(defaultOpen ?? false);
1651
1671
  const effectiveMobileOpen = isControlled ? open ?? false : internalOpen;
1652
- const handleMobileOpen = React21.useCallback(() => {
1672
+ const handleMobileOpen = React24.useCallback(() => {
1653
1673
  if (!isControlled) setInternalOpen(true);
1654
1674
  onOpenChange?.(true);
1655
1675
  }, [isControlled, onOpenChange]);
1656
- const handleMobileClose = React21.useCallback(() => {
1676
+ const handleMobileClose = React24.useCallback(() => {
1657
1677
  if (!isControlled) setInternalOpen(false);
1658
1678
  onOpenChange?.(false);
1659
1679
  }, [isControlled, onOpenChange]);
1660
- const mobileTrigger = trigger ? React21.cloneElement(trigger.props.children, {
1680
+ const mobileTrigger = trigger ? React24.cloneElement(trigger.props.children, {
1661
1681
  onClick: handleMobileOpen
1662
1682
  }) : void 0;
1663
1683
  if (isMobile) {
@@ -1797,7 +1817,7 @@ var PeekInStyled = ({
1797
1817
  PeekInStyled.displayName = "PeekIn";
1798
1818
 
1799
1819
  // src/PeekInTailwind.tsx
1800
- import * as React24 from "react";
1820
+ import * as React25 from "react";
1801
1821
  import Button3 from "@sproutsocial/seeds-react-button";
1802
1822
  import Drawer3 from "@sproutsocial/seeds-react-drawer";
1803
1823
  import Icon3 from "@sproutsocial/seeds-react-icon";
@@ -1806,9 +1826,9 @@ import { useIsMobile as useIsMobile3 } from "@sproutsocial/seeds-react-hooks";
1806
1826
  import { Modal as Modal2, ModalBody as ModalBody2 } from "@sproutsocial/seeds-react-modal/v2";
1807
1827
  import { jsx as jsx13, jsxs as jsxs5 } from "react/jsx-runtime";
1808
1828
  function getChildByType2(children, type) {
1809
- const childArray = React24.Children.toArray(children);
1829
+ const childArray = React25.Children.toArray(children);
1810
1830
  return childArray.find(
1811
- (child) => React24.isValidElement(child) && child.type === type
1831
+ (child) => React25.isValidElement(child) && child.type === type
1812
1832
  ) || null;
1813
1833
  }
1814
1834
  var PeekInTailwind = ({
@@ -1831,19 +1851,18 @@ var PeekInTailwind = ({
1831
1851
  const content = getChildByType2(children, PeekInContent);
1832
1852
  const panel = getChildByType2(children, PeekInPanel);
1833
1853
  const trigger = getChildByType2(children, PeekInTrigger);
1834
- const panelDefaultOpen = panel?.props?.defaultOpen ?? true;
1835
- const [panelOpen, setPanelOpen] = React24.useState(panelDefaultOpen);
1836
- const panelId = React24.useId();
1837
- const handleClose = React24.useCallback(() => {
1854
+ const { panelOpen, setPanelOpen } = usePeekInPanelState(panel);
1855
+ const panelId = React25.useId();
1856
+ const handleClose = React25.useCallback(() => {
1838
1857
  onOpenChange?.(false);
1839
1858
  }, [onOpenChange]);
1840
- const contextValue = React24.useMemo(
1859
+ const contextValue = React25.useMemo(
1841
1860
  () => ({ onClose: handleClose, panelOpen, setPanelOpen, panelId }),
1842
- [handleClose, panelOpen, panelId]
1861
+ [handleClose, panelOpen, setPanelOpen, panelId]
1843
1862
  );
1844
1863
  const ariaLabel = typeof header?.props?.title === "string" ? header.props.title : "Dialog";
1845
1864
  const triggerElement = trigger ? trigger.props.children : void 0;
1846
- const modalActions = React24.useMemo(() => {
1865
+ const modalActions = React25.useMemo(() => {
1847
1866
  const result = [];
1848
1867
  if (panelToggle && panel) {
1849
1868
  result.push({
@@ -1859,7 +1878,7 @@ var PeekInTailwind = ({
1859
1878
  }
1860
1879
  return result.length > 0 ? result : void 0;
1861
1880
  }, [panelToggle, panel, actions, panelOpen, panelId]);
1862
- const drawerActions = React24.useMemo(() => {
1881
+ const drawerActions = React25.useMemo(() => {
1863
1882
  const result = [];
1864
1883
  if (panelToggle && panel) {
1865
1884
  result.push({
@@ -1877,17 +1896,17 @@ var PeekInTailwind = ({
1877
1896
  }, [panelToggle, panel, actions, panelOpen, panelId]);
1878
1897
  const isMobile = useIsMobile3();
1879
1898
  const isControlled = open !== void 0;
1880
- const [internalOpen, setInternalOpen] = React24.useState(defaultOpen ?? false);
1899
+ const [internalOpen, setInternalOpen] = React25.useState(defaultOpen ?? false);
1881
1900
  const effectiveMobileOpen = isControlled ? open ?? false : internalOpen;
1882
- const handleMobileOpen = React24.useCallback(() => {
1901
+ const handleMobileOpen = React25.useCallback(() => {
1883
1902
  if (!isControlled) setInternalOpen(true);
1884
1903
  onOpenChange?.(true);
1885
1904
  }, [isControlled, onOpenChange]);
1886
- const handleMobileClose = React24.useCallback(() => {
1905
+ const handleMobileClose = React25.useCallback(() => {
1887
1906
  if (!isControlled) setInternalOpen(false);
1888
1907
  onOpenChange?.(false);
1889
1908
  }, [isControlled, onOpenChange]);
1890
- const mobileTrigger = trigger ? React24.cloneElement(trigger.props.children, {
1909
+ const mobileTrigger = trigger ? React25.cloneElement(trigger.props.children, {
1891
1910
  onClick: handleMobileOpen
1892
1911
  }) : void 0;
1893
1912
  if (isMobile) {