@butternutbox/pawprint-native 1.2.0 → 1.3.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.
@@ -7,12 +7,12 @@
7
7
  CJS Build start
8
8
  ESM Build start
9
9
  DTS Build start
10
- CJS dist/index.cjs 563.58 KB
10
+ CJS dist/index.cjs 564.54 KB
11
11
  CJS dist/index.cjs.map 1.10 MB
12
- CJS ⚡️ Build success in 6123ms
13
- ESM dist/index.js 532.63 KB
12
+ CJS ⚡️ Build success in 6535ms
13
+ ESM dist/index.js 533.47 KB
14
14
  ESM dist/index.js.map 1.10 MB
15
- ESM ⚡️ Build success in 6123ms
16
- DTS ⚡️ Build success in 15381ms
17
- DTS dist/index.d.cts 108.40 KB
18
- DTS dist/index.d.ts 108.40 KB
15
+ ESM ⚡️ Build success in 6536ms
16
+ DTS ⚡️ Build success in 17552ms
17
+ DTS dist/index.d.cts 111.87 KB
18
+ DTS dist/index.d.ts 111.87 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @butternutbox/pawprint-native
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 9449ba4: Refactor Menu component to include anchor to the trigger, improve stylings and API
8
+
3
9
  ## 1.2.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -10658,46 +10658,37 @@ var Tooltip = React66__default.default.forwardRef(
10658
10658
  );
10659
10659
  Tooltip.displayName = "Tooltip";
10660
10660
  var parseTokenValue53 = (value) => parseFloat(value);
10661
- var Row = styled51__default.default(reactNative.Pressable)(({ theme: theme2, divider }) => {
10661
+ var Row = styled51__default.default(reactNative.Pressable)(({ theme: theme2 }) => {
10662
10662
  const { spacing } = theme2.tokens.semantics.dimensions;
10663
- const { colour } = theme2.tokens.semantics;
10664
10663
  return {
10665
10664
  width: "100%",
10666
- alignItems: "center",
10665
+ alignItems: "flex-start",
10667
10666
  justifyContent: "center",
10668
10667
  paddingVertical: parseTokenValue53(spacing.md),
10669
- paddingHorizontal: parseTokenValue53(spacing.md),
10670
- borderBottomWidth: divider ? 1 : 0,
10671
- borderBottomColor: colour.border.divider
10668
+ paddingHorizontal: parseTokenValue53(spacing.md)
10672
10669
  };
10673
10670
  });
10674
10671
  var MenuItem = React66__default.default.forwardRef((_a, ref) => {
10675
10672
  var _b = _a, { variant = "action", onPress, children, divider = true } = _b, rest = __objRest(_b, ["variant", "onPress", "children", "divider"]);
10676
10673
  const theme2 = react.useTheme();
10677
10674
  const { colour, typography } = theme2.tokens.semantics;
10678
- const labelColour = variant === "destructive" ? colour.text.error : colour.text.action.default;
10675
+ const labelColour = variant === "destructive" ? colour.text.error : colour.text.link.default;
10679
10676
  const label = typeof children === "string" || typeof children === "number" ? String(children) : void 0;
10680
- return /* @__PURE__ */ jsxRuntime.jsx(
10681
- Row,
10682
- __spreadProps(__spreadValues({
10683
- ref,
10684
- divider,
10685
- onPress,
10686
- accessible: true,
10687
- accessibilityRole: "menuitem",
10688
- accessibilityLabel: label
10689
- }, rest), {
10690
- children: label !== void 0 ? /* @__PURE__ */ jsxRuntime.jsx(
10691
- Typography,
10692
- {
10693
- token: typography.body.medium.md,
10694
- align: "center",
10695
- color: labelColour,
10696
- children: label
10697
- }
10698
- ) : children
10699
- })
10700
- );
10677
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
10678
+ /* @__PURE__ */ jsxRuntime.jsx(
10679
+ Row,
10680
+ __spreadProps(__spreadValues({
10681
+ ref,
10682
+ onPress,
10683
+ accessible: true,
10684
+ accessibilityRole: "menuitem",
10685
+ accessibilityLabel: label
10686
+ }, rest), {
10687
+ children: label !== void 0 ? /* @__PURE__ */ jsxRuntime.jsx(Typography, { token: typography.body.medium.md, color: labelColour, children: label }) : children
10688
+ })
10689
+ ),
10690
+ divider && /* @__PURE__ */ jsxRuntime.jsx(Divider, {})
10691
+ ] });
10701
10692
  });
10702
10693
  MenuItem.displayName = "Menu.Item";
10703
10694
  var parseTokenValue54 = (value) => parseFloat(value);
@@ -10708,18 +10699,14 @@ var DismissLayer = styled51__default.default(reactNative.Pressable)({
10708
10699
  right: 0,
10709
10700
  bottom: 0
10710
10701
  });
10711
- var Anchor = styled51__default.default(reactNative.View)(({ theme: theme2, align }) => {
10712
- const inset = parseTokenValue54(theme2.tokens.semantics.dimensions.spacing.md);
10713
- return __spreadValues({
10714
- position: "absolute"
10715
- }, align === "right" ? { right: inset } : { left: inset });
10702
+ var Anchor = styled51__default.default(reactNative.View)({
10703
+ position: "absolute"
10716
10704
  });
10717
10705
  var Card = styled51__default.default(reactNative.Pressable)(({ theme: theme2, width }) => {
10718
10706
  const { borderRadius } = theme2.tokens.semantics.dimensions;
10719
10707
  const { shadow, background } = theme2.tokens.semantics.colour;
10720
10708
  return {
10721
10709
  width,
10722
- maxWidth: "90%",
10723
10710
  borderRadius: parseTokenValue54(borderRadius.md),
10724
10711
  overflow: "hidden",
10725
10712
  backgroundColor: background.surface.default,
@@ -10737,12 +10724,25 @@ var Card = styled51__default.default(reactNative.Pressable)(({ theme: theme2, wi
10737
10724
  var MenuRoot = ({
10738
10725
  open,
10739
10726
  onClose,
10727
+ anchor,
10740
10728
  anchorOffset = 0,
10741
10729
  align = "right",
10742
- width = 360,
10730
+ width = 280,
10743
10731
  closeAccessibilityLabel = "Close menu",
10744
10732
  children
10745
10733
  }) => {
10734
+ const theme2 = react.useTheme();
10735
+ const { width: windowWidth } = reactNative.useWindowDimensions();
10736
+ const { spacing } = theme2.tokens.semantics.dimensions;
10737
+ const [lastAnchor, setLastAnchor] = React66.useState(anchor);
10738
+ if (anchor && anchor !== lastAnchor) setLastAnchor(anchor);
10739
+ const shownAnchor = anchor != null ? anchor : lastAnchor;
10740
+ const position = shownAnchor ? __spreadValues({
10741
+ top: shownAnchor.y + shownAnchor.height + parseTokenValue54(spacing.xs)
10742
+ }, align === "right" ? { right: windowWidth - (shownAnchor.x + shownAnchor.width) } : { left: shownAnchor.x }) : {
10743
+ top: anchorOffset,
10744
+ [align]: parseTokenValue54(spacing.md)
10745
+ };
10746
10746
  return /* @__PURE__ */ jsxRuntime.jsxs(
10747
10747
  reactNative.Modal,
10748
10748
  {
@@ -10760,10 +10760,10 @@ var MenuRoot = ({
10760
10760
  accessibilityLabel: closeAccessibilityLabel
10761
10761
  }
10762
10762
  ),
10763
- /* @__PURE__ */ jsxRuntime.jsx(Anchor, { align, style: { top: anchorOffset }, children: /* @__PURE__ */ jsxRuntime.jsx(
10763
+ /* @__PURE__ */ jsxRuntime.jsx(Anchor, { style: position, children: /* @__PURE__ */ jsxRuntime.jsx(
10764
10764
  Card,
10765
10765
  {
10766
- width,
10766
+ width: Math.min(width, windowWidth * 0.9),
10767
10767
  onPress: () => {
10768
10768
  },
10769
10769
  accessible: false,
@@ -10779,6 +10779,25 @@ MenuRoot.displayName = "Menu";
10779
10779
  var Menu2 = Object.assign(MenuRoot, {
10780
10780
  Item: MenuItem
10781
10781
  });
10782
+ var useMenuTrigger = () => {
10783
+ const triggerRef = React66.useRef(null);
10784
+ const [anchor, setAnchor] = React66.useState();
10785
+ const open = React66.useCallback(() => {
10786
+ var _a;
10787
+ (_a = triggerRef.current) == null ? void 0 : _a.measureInWindow(
10788
+ (x, y, width, height) => setAnchor({ x, y, width, height })
10789
+ );
10790
+ }, []);
10791
+ const close = React66.useCallback(() => setAnchor(void 0), []);
10792
+ const isOpen = anchor !== void 0;
10793
+ return {
10794
+ triggerRef,
10795
+ isOpen,
10796
+ open,
10797
+ close,
10798
+ menuProps: { open: isOpen, onClose: close, anchor }
10799
+ };
10800
+ };
10782
10801
  var parseTokenValue55 = (value) => parseFloat(value);
10783
10802
  var StyledInsightRoot = styled51__default.default(reactNative.View)(
10784
10803
  ({
@@ -12926,6 +12945,7 @@ exports.slideOutAnimation = slideOutAnimation;
12926
12945
  exports.theme = theme;
12927
12946
  exports.useCopyField = useCopyField;
12928
12947
  exports.useDrawerKeyboardAvoidance = useDrawerKeyboardAvoidance;
12948
+ exports.useMenuTrigger = useMenuTrigger;
12929
12949
  exports.usePasswordField = usePasswordField;
12930
12950
  exports.usePawprint = usePawprint;
12931
12951
  exports.useSearchField = useSearchField;