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

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.d.mts CHANGED
@@ -88,7 +88,14 @@ interface TypePeekInPanelProps {
88
88
  * provides its own chrome (e.g. an embedded agent UI). Defaults to false.
89
89
  */
90
90
  headerless?: boolean;
91
- /** Whether the panel starts open or collapsed. Default: true */
91
+ /** Controlled open state for the panel. Pair with `onOpenChange`. */
92
+ open?: boolean;
93
+ /**
94
+ * Fires when the panel opens or closes — the action-bar toggle, the panel's
95
+ * built-in close button, or a dismiss of the mobile bottom sheet.
96
+ */
97
+ onOpenChange?: (open: boolean) => void;
98
+ /** Whether the panel starts open or collapsed. Ignored when `open` is set. Default: true */
92
99
  defaultOpen?: boolean;
93
100
  /**
94
101
  * Snap points the panel can rest at when rendered as a nested mobile
package/dist/index.d.ts CHANGED
@@ -88,7 +88,14 @@ interface TypePeekInPanelProps {
88
88
  * provides its own chrome (e.g. an embedded agent UI). Defaults to false.
89
89
  */
90
90
  headerless?: boolean;
91
- /** Whether the panel starts open or collapsed. Default: true */
91
+ /** Controlled open state for the panel. Pair with `onOpenChange`. */
92
+ open?: boolean;
93
+ /**
94
+ * Fires when the panel opens or closes — the action-bar toggle, the panel's
95
+ * built-in close button, or a dismiss of the mobile bottom sheet.
96
+ */
97
+ onOpenChange?: (open: boolean) => void;
98
+ /** Whether the panel starts open or collapsed. Ignored when `open` is set. Default: true */
92
99
  defaultOpen?: boolean;
93
100
  /**
94
101
  * Snap points the panel can rest at when rendered as a nested mobile
package/dist/index.js CHANGED
@@ -42,7 +42,7 @@ module.exports = __toCommonJS(index_exports);
42
42
  var import_seeds_react_system_props = require("@sproutsocial/seeds-react-system-props");
43
43
 
44
44
  // src/PeekInStyled.tsx
45
- var React21 = __toESM(require("react"));
45
+ var React24 = __toESM(require("react"));
46
46
  var import_seeds_react_box4 = __toESM(require("@sproutsocial/seeds-react-box"));
47
47
  var import_seeds_react_button2 = __toESM(require("@sproutsocial/seeds-react-button"));
48
48
  var import_seeds_react_drawer2 = __toESM(require("@sproutsocial/seeds-react-drawer"));
@@ -1613,12 +1613,33 @@ var PeekInTrigger = ({
1613
1613
  };
1614
1614
  PeekInTrigger.displayName = "PeekInTrigger";
1615
1615
 
1616
+ // src/usePeekInPanelState.ts
1617
+ var React21 = __toESM(require("react"));
1618
+ function usePeekInPanelState(panel) {
1619
+ const panelProps = panel?.props;
1620
+ const isControlled = panelProps?.open !== void 0;
1621
+ const onOpenChange = panelProps?.onOpenChange;
1622
+ const [internalOpen, setInternalOpen] = React21.useState(
1623
+ panelProps?.defaultOpen ?? true
1624
+ );
1625
+ const panelOpen = isControlled ? panelProps.open : internalOpen;
1626
+ const setPanelOpen = React21.useCallback(
1627
+ (next) => {
1628
+ const value = typeof next === "function" ? next(panelOpen) : next;
1629
+ if (!isControlled) setInternalOpen(value);
1630
+ onOpenChange?.(value);
1631
+ },
1632
+ [isControlled, onOpenChange, panelOpen]
1633
+ );
1634
+ return { panelOpen, setPanelOpen };
1635
+ }
1636
+
1616
1637
  // src/PeekInStyled.tsx
1617
1638
  var import_jsx_runtime12 = require("react/jsx-runtime");
1618
1639
  function getChildByType(children, type) {
1619
- const childArray = React21.Children.toArray(children);
1640
+ const childArray = React24.Children.toArray(children);
1620
1641
  return childArray.find(
1621
- (child) => React21.isValidElement(child) && child.type === type
1642
+ (child) => React24.isValidElement(child) && child.type === type
1622
1643
  ) || null;
1623
1644
  }
1624
1645
  var PeekInStyled = ({
@@ -1641,19 +1662,18 @@ var PeekInStyled = ({
1641
1662
  const content = getChildByType(children, PeekInContent);
1642
1663
  const panel = getChildByType(children, PeekInPanel);
1643
1664
  const trigger = getChildByType(children, PeekInTrigger);
1644
- const panelDefaultOpen = panel?.props?.defaultOpen ?? true;
1645
- const [panelOpen, setPanelOpen] = React21.useState(panelDefaultOpen);
1646
- const panelId = React21.useId();
1647
- const handleClose = React21.useCallback(() => {
1665
+ const { panelOpen, setPanelOpen } = usePeekInPanelState(panel);
1666
+ const panelId = React24.useId();
1667
+ const handleClose = React24.useCallback(() => {
1648
1668
  onOpenChange?.(false);
1649
1669
  }, [onOpenChange]);
1650
- const contextValue = React21.useMemo(
1670
+ const contextValue = React24.useMemo(
1651
1671
  () => ({ onClose: handleClose, panelOpen, setPanelOpen, panelId }),
1652
- [handleClose, panelOpen, panelId]
1672
+ [handleClose, panelOpen, setPanelOpen, panelId]
1653
1673
  );
1654
1674
  const ariaLabel = typeof header?.props?.title === "string" ? header.props.title : "Dialog";
1655
1675
  const triggerElement = trigger ? trigger.props.children : void 0;
1656
- const modalActions = React21.useMemo(() => {
1676
+ const modalActions = React24.useMemo(() => {
1657
1677
  const result = [];
1658
1678
  if (panelToggle && panel) {
1659
1679
  result.push({
@@ -1669,7 +1689,7 @@ var PeekInStyled = ({
1669
1689
  }
1670
1690
  return result.length > 0 ? result : void 0;
1671
1691
  }, [panelToggle, panel, actions, panelOpen, panelId]);
1672
- const drawerActions = React21.useMemo(() => {
1692
+ const drawerActions = React24.useMemo(() => {
1673
1693
  const result = [];
1674
1694
  if (panelToggle && panel) {
1675
1695
  result.push({
@@ -1687,17 +1707,17 @@ var PeekInStyled = ({
1687
1707
  }, [panelToggle, panel, actions, panelOpen, panelId]);
1688
1708
  const isMobile = (0, import_seeds_react_hooks2.useIsMobile)();
1689
1709
  const isControlled = open !== void 0;
1690
- const [internalOpen, setInternalOpen] = React21.useState(defaultOpen ?? false);
1710
+ const [internalOpen, setInternalOpen] = React24.useState(defaultOpen ?? false);
1691
1711
  const effectiveMobileOpen = isControlled ? open ?? false : internalOpen;
1692
- const handleMobileOpen = React21.useCallback(() => {
1712
+ const handleMobileOpen = React24.useCallback(() => {
1693
1713
  if (!isControlled) setInternalOpen(true);
1694
1714
  onOpenChange?.(true);
1695
1715
  }, [isControlled, onOpenChange]);
1696
- const handleMobileClose = React21.useCallback(() => {
1716
+ const handleMobileClose = React24.useCallback(() => {
1697
1717
  if (!isControlled) setInternalOpen(false);
1698
1718
  onOpenChange?.(false);
1699
1719
  }, [isControlled, onOpenChange]);
1700
- const mobileTrigger = trigger ? React21.cloneElement(trigger.props.children, {
1720
+ const mobileTrigger = trigger ? React24.cloneElement(trigger.props.children, {
1701
1721
  onClick: handleMobileOpen
1702
1722
  }) : void 0;
1703
1723
  if (isMobile) {
@@ -1837,7 +1857,7 @@ var PeekInStyled = ({
1837
1857
  PeekInStyled.displayName = "PeekIn";
1838
1858
 
1839
1859
  // src/PeekInTailwind.tsx
1840
- var React24 = __toESM(require("react"));
1860
+ var React25 = __toESM(require("react"));
1841
1861
  var import_seeds_react_button3 = __toESM(require("@sproutsocial/seeds-react-button"));
1842
1862
  var import_seeds_react_drawer3 = __toESM(require("@sproutsocial/seeds-react-drawer"));
1843
1863
  var import_seeds_react_icon3 = __toESM(require("@sproutsocial/seeds-react-icon"));
@@ -1846,9 +1866,9 @@ var import_seeds_react_hooks3 = require("@sproutsocial/seeds-react-hooks");
1846
1866
  var import_v22 = require("@sproutsocial/seeds-react-modal/v2");
1847
1867
  var import_jsx_runtime13 = require("react/jsx-runtime");
1848
1868
  function getChildByType2(children, type) {
1849
- const childArray = React24.Children.toArray(children);
1869
+ const childArray = React25.Children.toArray(children);
1850
1870
  return childArray.find(
1851
- (child) => React24.isValidElement(child) && child.type === type
1871
+ (child) => React25.isValidElement(child) && child.type === type
1852
1872
  ) || null;
1853
1873
  }
1854
1874
  var PeekInTailwind = ({
@@ -1871,19 +1891,18 @@ var PeekInTailwind = ({
1871
1891
  const content = getChildByType2(children, PeekInContent);
1872
1892
  const panel = getChildByType2(children, PeekInPanel);
1873
1893
  const trigger = getChildByType2(children, PeekInTrigger);
1874
- const panelDefaultOpen = panel?.props?.defaultOpen ?? true;
1875
- const [panelOpen, setPanelOpen] = React24.useState(panelDefaultOpen);
1876
- const panelId = React24.useId();
1877
- const handleClose = React24.useCallback(() => {
1894
+ const { panelOpen, setPanelOpen } = usePeekInPanelState(panel);
1895
+ const panelId = React25.useId();
1896
+ const handleClose = React25.useCallback(() => {
1878
1897
  onOpenChange?.(false);
1879
1898
  }, [onOpenChange]);
1880
- const contextValue = React24.useMemo(
1899
+ const contextValue = React25.useMemo(
1881
1900
  () => ({ onClose: handleClose, panelOpen, setPanelOpen, panelId }),
1882
- [handleClose, panelOpen, panelId]
1901
+ [handleClose, panelOpen, setPanelOpen, panelId]
1883
1902
  );
1884
1903
  const ariaLabel = typeof header?.props?.title === "string" ? header.props.title : "Dialog";
1885
1904
  const triggerElement = trigger ? trigger.props.children : void 0;
1886
- const modalActions = React24.useMemo(() => {
1905
+ const modalActions = React25.useMemo(() => {
1887
1906
  const result = [];
1888
1907
  if (panelToggle && panel) {
1889
1908
  result.push({
@@ -1899,7 +1918,7 @@ var PeekInTailwind = ({
1899
1918
  }
1900
1919
  return result.length > 0 ? result : void 0;
1901
1920
  }, [panelToggle, panel, actions, panelOpen, panelId]);
1902
- const drawerActions = React24.useMemo(() => {
1921
+ const drawerActions = React25.useMemo(() => {
1903
1922
  const result = [];
1904
1923
  if (panelToggle && panel) {
1905
1924
  result.push({
@@ -1917,17 +1936,17 @@ var PeekInTailwind = ({
1917
1936
  }, [panelToggle, panel, actions, panelOpen, panelId]);
1918
1937
  const isMobile = (0, import_seeds_react_hooks3.useIsMobile)();
1919
1938
  const isControlled = open !== void 0;
1920
- const [internalOpen, setInternalOpen] = React24.useState(defaultOpen ?? false);
1939
+ const [internalOpen, setInternalOpen] = React25.useState(defaultOpen ?? false);
1921
1940
  const effectiveMobileOpen = isControlled ? open ?? false : internalOpen;
1922
- const handleMobileOpen = React24.useCallback(() => {
1941
+ const handleMobileOpen = React25.useCallback(() => {
1923
1942
  if (!isControlled) setInternalOpen(true);
1924
1943
  onOpenChange?.(true);
1925
1944
  }, [isControlled, onOpenChange]);
1926
- const handleMobileClose = React24.useCallback(() => {
1945
+ const handleMobileClose = React25.useCallback(() => {
1927
1946
  if (!isControlled) setInternalOpen(false);
1928
1947
  onOpenChange?.(false);
1929
1948
  }, [isControlled, onOpenChange]);
1930
- const mobileTrigger = trigger ? React24.cloneElement(trigger.props.children, {
1949
+ const mobileTrigger = trigger ? React25.cloneElement(trigger.props.children, {
1931
1950
  onClick: handleMobileOpen
1932
1951
  }) : void 0;
1933
1952
  if (isMobile) {