@xyo-network/react-address-render 2.47.2 → 2.47.4

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.
Files changed (45) hide show
  1. package/dist/cjs/components/RenderRowBox.js +3 -2
  2. package/dist/cjs/components/RenderRowBox.js.map +1 -1
  3. package/dist/cjs/components/favorite/FavoriteIconButton.js +20 -12
  4. package/dist/cjs/components/favorite/FavoriteIconButton.js.map +1 -1
  5. package/dist/cjs/components/favorite/Popper.js +21 -0
  6. package/dist/cjs/components/favorite/Popper.js.map +1 -0
  7. package/dist/cjs/components/favorite/PopperButtonGroup.js +20 -0
  8. package/dist/cjs/components/favorite/PopperButtonGroup.js.map +1 -0
  9. package/dist/cjs/components/favorite/lib/PopperId.js +5 -0
  10. package/dist/cjs/components/favorite/lib/PopperId.js.map +1 -0
  11. package/dist/cjs/components/favorite/lib/index.js +5 -0
  12. package/dist/cjs/components/favorite/lib/index.js.map +1 -0
  13. package/dist/docs.json +736 -594
  14. package/dist/esm/components/RenderRowBox.js +2 -2
  15. package/dist/esm/components/RenderRowBox.js.map +1 -1
  16. package/dist/esm/components/favorite/FavoriteIconButton.js +21 -13
  17. package/dist/esm/components/favorite/FavoriteIconButton.js.map +1 -1
  18. package/dist/esm/components/favorite/Popper.js +16 -0
  19. package/dist/esm/components/favorite/Popper.js.map +1 -0
  20. package/dist/esm/components/favorite/PopperButtonGroup.js +14 -0
  21. package/dist/esm/components/favorite/PopperButtonGroup.js.map +1 -0
  22. package/dist/esm/components/favorite/lib/PopperId.js +2 -0
  23. package/dist/esm/components/favorite/lib/PopperId.js.map +1 -0
  24. package/dist/esm/components/favorite/lib/index.js +2 -0
  25. package/dist/esm/components/favorite/lib/index.js.map +1 -0
  26. package/dist/types/components/RenderRowBox.d.ts +2 -0
  27. package/dist/types/components/RenderRowBox.d.ts.map +1 -1
  28. package/dist/types/components/favorite/FavoriteIconButton.d.ts +2 -0
  29. package/dist/types/components/favorite/FavoriteIconButton.d.ts.map +1 -1
  30. package/dist/types/components/favorite/Popper.d.ts +11 -0
  31. package/dist/types/components/favorite/Popper.d.ts.map +1 -0
  32. package/dist/types/components/favorite/PopperButtonGroup.d.ts +9 -0
  33. package/dist/types/components/favorite/PopperButtonGroup.d.ts.map +1 -0
  34. package/dist/types/components/favorite/lib/PopperId.d.ts +2 -0
  35. package/dist/types/components/favorite/lib/PopperId.d.ts.map +1 -0
  36. package/dist/types/components/favorite/lib/index.d.ts +2 -0
  37. package/dist/types/components/favorite/lib/index.d.ts.map +1 -0
  38. package/package.json +3 -3
  39. package/src/components/RenderRowBox.stories.tsx +23 -3
  40. package/src/components/RenderRowBox.tsx +5 -3
  41. package/src/components/favorite/FavoriteIconButton.tsx +35 -12
  42. package/src/components/favorite/Popper.tsx +59 -0
  43. package/src/components/favorite/PopperButtonGroup.tsx +36 -0
  44. package/src/components/favorite/lib/PopperId.ts +1 -0
  45. package/src/components/favorite/lib/index.ts +1 -0
@@ -6,11 +6,11 @@ import { useXyoEvent } from '@xyo-network/react-event';
6
6
  import { EllipsizeBox, useShareForwardedRef } from '@xyo-network/react-shared';
7
7
  import { forwardRef } from 'react';
8
8
  import { FavoriteIconButton } from './favorite';
9
- export const AddressRenderRowBox = forwardRef(({ address, children, favorite: favoriteProp = false, iconOnly, iconSize = 24, icons, showFavorite = false, ...props }, ref) => {
9
+ export const AddressRenderRowBox = forwardRef(({ address, alias, children, favorite: favoriteProp = false, iconOnly, iconSize = 24, icons, name, showFavorite = false, ...props }, ref) => {
10
10
  const theme = useTheme();
11
11
  const sharedRef = useShareForwardedRef(ref);
12
12
  const [elementRef, dispatch] = useXyoEvent(undefined, sharedRef);
13
- return (_jsxs(FlexGrowRow, { gap: 2, justifyContent: "flex-start", ref: elementRef, onClick: () => (address ? dispatch('address', 'click', address) : undefined), ...props, children: [icons && address ? (_jsx(ListItemIcon, { sx: { minWidth: 0 }, children: _jsx(Identicon, { size: iconSize, value: address }) })) : null, iconOnly ? null : (_jsx(ListItemText, { children: _jsx(EllipsizeBox, { ellipsisPosition: 'end', width: "100%", typographyProps: { fontSize: theme.typography.body1.fontSize }, children: address }) })), children, showFavorite && address ? _jsx(FavoriteIconButton, { size: 'small', address: address, favorite: favoriteProp }) : null] }));
13
+ return (_jsxs(FlexGrowRow, { gap: 2, justifyContent: "flex-start", ref: elementRef, onClick: () => (address ? dispatch('address', 'click', address) : undefined), ...props, children: [icons && address ? (_jsx(ListItemIcon, { sx: { minWidth: 0 }, children: _jsx(Identicon, { size: iconSize, value: address }) })) : null, iconOnly ? null : (_jsx(ListItemText, { children: _jsx(EllipsizeBox, { ellipsisPosition: 'end', width: "100%", typographyProps: { fontSize: theme.typography.body1.fontSize }, children: alias ?? name ?? address }) })), children, showFavorite && address ? _jsx(FavoriteIconButton, { alias: alias, size: 'small', address: address, favorite: favoriteProp }) : null] }));
14
14
  });
15
15
  AddressRenderRowBox.displayName = 'AddressRenderRowBox';
16
16
  //# sourceMappingURL=RenderRowBox.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RenderRowBox.js","sourceRoot":"","sources":["../../../src/components/RenderRowBox.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACpE,OAAO,EAAgB,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAa/C,MAAM,CAAC,MAAM,mBAAmB,GAAG,UAAU,CAC3C,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,GAAG,KAAK,EAAE,QAAQ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AAS,CAAC,KACxE,KAAK,aAER,KAAK,IAAI,OAAO,CAAC,CAAC,CAAC,CAClB,KAAC,YAAY,IAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,YAC/B,KAAC,SAAS,IAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,GAAI,GAChC,CAChB,CAAC,CAAC,CAAC,IAAI,EACP,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACjB,KAAC,YAAY,cACX,KAAC,YAAY,IAAC,gBAAgB,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,EAAC,eAAe,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,QAAQ,EAAE,YAC/G,KAAK,IAAI,IAAI,IAAI,OAAO,GACZ,GACF,CAChB,EACA,QAAQ,EACR,YAAY,IAAI,OAAO,CAAC,CAAC,CAAC,KAAC,kBAAkB,IAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,GAAI,CAAC,CAAC,CAAC,IAAI,IACnH,CACf,CAAA;AACH,CAAC,CACF,CAAA;AAED,mBAAmB,CAAC,WAAW,GAAG,qBAAqB,CAAA"}
@@ -4,28 +4,36 @@ import StarBorderIcon from '@mui/icons-material/StarBorder';
4
4
  import { IconButton } from '@mui/material';
5
5
  import { useXyoEvent } from '@xyo-network/react-event';
6
6
  import { useShareForwardedRef } from '@xyo-network/react-shared';
7
- import { forwardRef, useEffect, useState } from 'react';
8
- export const FavoriteIconButton = forwardRef(({ address, children, favorite: favoriteProp, ...props }, ref) => {
7
+ import { forwardRef, useEffect, useRef, useState } from 'react';
8
+ import { popperId } from './lib';
9
+ import { FavoritePopper } from './Popper';
10
+ export const FavoriteIconButton = forwardRef(({ address, alias, children, favorite: favoriteProp, ...props }, ref) => {
11
+ const [openPopper, setOpenPopper] = useState(false);
9
12
  const [favorite, setFavorite] = useState(favoriteProp);
10
13
  useEffect(() => {
11
14
  setFavorite(favoriteProp);
12
15
  }, [favoriteProp]);
13
16
  const sharedRef = useShareForwardedRef(ref);
14
17
  const [buttonRef, dispatch] = useXyoEvent(undefined, sharedRef);
15
- return (_jsxs(IconButton, { ref: buttonRef,
18
+ const onConfirmFavorite = (alias, newFavoriteState) => {
19
+ setFavorite(() => {
20
+ const favoriteEvent = {
21
+ address,
22
+ alias,
23
+ favorite: !!newFavoriteState,
24
+ };
25
+ dispatch('address', 'favorite', JSON.stringify(favoriteEvent));
26
+ return newFavoriteState;
27
+ });
28
+ setOpenPopper(false);
29
+ };
30
+ const starRef = useRef(null);
31
+ return (_jsxs(IconButton, { ref: buttonRef, "aria-describedby": popperId,
16
32
  // used to prevent parent items from rippling when IconButton is clicked
17
33
  onMouseDown: (e) => e.stopPropagation(), onClick: (event) => {
18
34
  event.stopPropagation();
19
- setFavorite((current) => {
20
- const newFavoriteState = !current;
21
- const favoriteEvent = {
22
- address,
23
- favorite: newFavoriteState,
24
- };
25
- dispatch('address', 'favorite', JSON.stringify(favoriteEvent));
26
- return newFavoriteState;
27
- });
28
- }, ...props, children: [favorite ? _jsx(StarIcon, { color: "secondary" }) : _jsx(StarBorderIcon, {}), children] }));
35
+ setOpenPopper(true);
36
+ }, ...props, children: [_jsx("span", { ref: starRef, children: favorite ? _jsx(StarIcon, { component: 'svg', color: "secondary" }) : _jsx(StarBorderIcon, {}) }), _jsx(FavoritePopper, { alias: alias, favorite: favorite, favoriteRef: starRef, open: openPopper, onConfirmFavorite: onConfirmFavorite, onClickAway: () => setOpenPopper(false) }), children] }));
29
37
  });
30
38
  FavoriteIconButton.displayName = 'FavoriteIconButton';
31
39
  //# sourceMappingURL=FavoriteIconButton.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FavoriteIconButton.js","sourceRoot":"","sources":["../../../../src/components/favorite/FavoriteIconButton.tsx"],"names":[],"mappings":";AAAA,OAAO,QAAQ,MAAM,0BAA0B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AiB,EACpC,WAAW,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,GACvC,EACD,QAAQ,IACE,CACd,CAAA;AACH,CAAC,CACF,CAAA;AAED,kBAAkB,CAAC,WAAW,GAAG,oBAAoB,CAAA"}
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Card, CardContent, ClickAwayListener, Fade, Popper, TextField } from '@mui/material';
3
+ import { forwardRef, useEffect, useState } from 'react';
4
+ import { popperId } from './lib';
5
+ import { PopperButtonGroup } from './PopperButtonGroup';
6
+ export const FavoritePopper = forwardRef(({ alias: aliasProp, favorite, favoriteRef, onClickAway = () => {
7
+ return;
8
+ }, onConfirmFavorite, ...props }, ref) => {
9
+ const [alias, setAlias] = useState();
10
+ useEffect(() => {
11
+ setAlias(aliasProp);
12
+ }, [aliasProp]);
13
+ return (_jsx(ClickAwayListener, { onClickAway: onClickAway, children: _jsx(Popper, { id: popperId, anchorEl: favoriteRef?.current, transition: true, ref: ref, ...props, children: ({ TransitionProps }) => (_jsx(Fade, { ...TransitionProps, timeout: 350, children: _jsx(Card, { children: _jsxs(CardContent, { sx: { display: 'flex', gap: 1 }, children: [_jsx(TextField, { autoFocus: true, label: "Favorite Alias", placeholder: "optional", size: "small", value: alias ?? '', onChange: (e) => setAlias(e.target.value) }), _jsx(PopperButtonGroup, { favorite: favorite, onConfirmFavorite: onConfirmFavorite, alias: alias })] }) }) })) }) }));
14
+ });
15
+ FavoritePopper.displayName = 'FavoritePopper';
16
+ //# sourceMappingURL=Popper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Popper.js","sourceRoot":"","sources":["../../../../src/components/favorite/Popper.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAe,SAAS,EAAE,MAAM,eAAe,CAAA;AAC1G,OAAO,EAAE,UAAU,EAAa,SAAS,EA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,iBAAiB,EAAE,KAAK,EAAE,KAAK,GAAI,IACjF,GACT,GACF,CACR,GACM,GACS,CACrB,CAAA;AACH,CAAC,CACF,CAAA;AAED,cAAc,CAAC,WAAW,GAAG,gBAAgB,CAAA"}
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import DeleteIcon from '@mui/icons-material/Delete';
3
+ import StarIcon from '@mui/icons-material/Star';
4
+ import { Button, ButtonGroup } from '@mui/material';
5
+ export const PopperButtonGroup = ({ alias, onConfirmFavorite, favorite, ...props }) => {
6
+ return (_jsxs(ButtonGroup, { ...props, children: [_jsx(Button, { variant: "contained", onClick: (e) => {
7
+ e.stopPropagation();
8
+ onConfirmFavorite?.(alias, true);
9
+ }, children: _jsx(StarIcon, {}) }), favorite ? (_jsx(Button, { variant: "contained", onClick: (e) => {
10
+ e.stopPropagation();
11
+ onConfirmFavorite?.(alias, false);
12
+ }, children: _jsx(DeleteIcon, {}) })) : null] }));
13
+ };
14
+ //# sourceMappingURL=PopperButtonGroup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PopperButtonGroup.js","sourceRoot":"","sources":["../../../../src/components/favorite/PopperButtonGroup.tsx"],"names":[],"mappings":";AAAA,OAAO,UAAU,MAAM,4BAA4B,CAAA;AACnD,OAAO,QAAQ,MAAM,0BAA0B,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,WAAW,EAAoB,MAAM,eAAe,CAAA;AAQrE,MAAM,CAAC,MAAM,iBAAiB,GAAkC,CAAC,EAAE,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE;IACnH,OAAO,CACL,MAAC,WAAW,OAAK,KAAK,aACpB,KAAC,MAAM,IACL,OAAO,EAAC,WAAW,EACnB,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;oBACb,CAAC,CAAC,eAAe,EAAE,CAAA;oBACnB,iBAAiB,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;gBAClC,CAAC,YAED,KAAC,QAAQ,KAAG,GACL,EACR,QAAQ,CAAC,CAAC,CAAC,CACV,KAAC,MAAM,IACL,OAAO,EAAC,WAAW,EACnB,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;oBACb,CAAC,CAAC,eAAe,EAAE,CAAA;oBACnB,iBAAiB,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;gBACnC,CAAC,YAED,KAAC,UAAU,KAAG,GACP,CACV,CAAC,CAAC,CAAC,IAAI,IACI,CACf,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export const popperId = 'favorite-popper';
2
+ //# sourceMappingURL=PopperId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PopperId.js","sourceRoot":"","sources":["../../../../../src/components/favorite/lib/PopperId.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,iBAAiB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './PopperId';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/components/favorite/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA"}
@@ -3,10 +3,12 @@ import { FlexBoxProps } from '@xylabs/react-flexbox';
3
3
  import { WithChildren } from '@xylabs/react-shared';
4
4
  export interface AddressRenderRowBoxPropsBase {
5
5
  address?: string | null;
6
+ alias?: string;
6
7
  favorite?: boolean;
7
8
  iconOnly?: boolean;
8
9
  iconSize?: number;
9
10
  icons?: boolean;
11
+ name?: string;
10
12
  showFavorite?: boolean;
11
13
  }
12
14
  export interface AddressRenderRowBoxProps extends WithChildren, AddressRenderRowBoxPropsBase, FlexBoxProps {
@@ -1 +1 @@
1
- {"version":3,"file":"RenderRowBox.d.ts","sourceRoot":"","sources":["../../../src/components/RenderRowBox.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAe,MAAM,uBAAuB,CAAA;AAEjE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAOnD,MAAM,WAAW,4BAA4B;IAC3C,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,wBAAyB,SAAQ,YAAY,EAAE,4BAA4B,EAAE,YAAY;CAAG;AAE7G,eAAO,MAAM,mBAAmB,kHAgC/B,CAAA"}
1
+ {"version":3,"file":"RenderRowBox.d.ts","sourceRoot":"","sources":["../../../src/components/RenderRowBox.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAe,MAAM,uBAAuB,CAAA;AAEjE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAOnD,MAAM,WAAW,4BAA4B;IAC3C,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,wBAAyB,SAAQ,YAAY,EAAE,4BAA4B,EAAE,YAAY;CAAG;AAE7G,eAAO,MAAM,mBAAmB,kHAgC/B,CAAA"}
@@ -3,10 +3,12 @@ import { IconButtonProps } from '@mui/material';
3
3
  import { WithChildren } from '@xylabs/react-shared';
4
4
  export interface FavoriteEvent {
5
5
  address?: string;
6
+ alias?: string;
6
7
  favorite: boolean;
7
8
  }
8
9
  export interface FavoriteIconButtonProps extends WithChildren, IconButtonProps {
9
10
  address?: string;
11
+ alias?: string;
10
12
  favorite?: boolean;
11
13
  }
12
14
  export declare const FavoriteIconButton: import("react").ForwardRefExoticComponent<Omit<FavoriteIconButtonProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
@@ -1 +1 @@
1
- {"version":3,"file":"FavoriteIconButton.d.ts","sourceRoot":"","sources":["../../../../src/components/favorite/FavoriteIconButton.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAc,eAAe,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAKnD,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,uBAAwB,SAAQ,YAAY,EAAE,eAAe;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,eAAO,MAAM,kBAAkB,oIAkC9B,CAAA"}
1
+ {"version":3,"file":"FavoriteIconButton.d.ts","sourceRoot":"","sources":["../../../../src/components/favorite/FavoriteIconButton.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAc,eAAe,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAQnD,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,uBAAwB,SAAQ,YAAY,EAAE,eAAe;IAE5E,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,eAAO,MAAM,kBAAkB,oIAmD9B,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { PopperProps } from '@mui/material';
2
+ import { RefObject } from 'react';
3
+ export interface FavoritePopperProps extends PopperProps {
4
+ alias?: string;
5
+ favorite?: boolean;
6
+ favoriteRef?: RefObject<HTMLElement>;
7
+ onClickAway?: (event: MouseEvent | TouchEvent) => void;
8
+ onConfirmFavorite?: (alias?: string, newFavoriteState?: boolean) => void;
9
+ }
10
+ export declare const FavoritePopper: import("react").ForwardRefExoticComponent<Omit<FavoritePopperProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
11
+ //# sourceMappingURL=Popper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Popper.d.ts","sourceRoot":"","sources":["../../../../src/components/favorite/Popper.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsD,WAAW,EAAa,MAAM,eAAe,CAAA;AAC1G,OAAO,EAAc,SAAS,EAAuB,MAAM,OAAO,CAAA;AAKlE,MAAM,WAAW,mBAAoB,SAAQ,WAAW;IACtD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,WAAW,CAAC,EAAE,SAAS,CAAC,WAAW,CAAC,CAAA;IACpC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,KAAK,IAAI,CAAA;IACtD,iBAAiB,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,gBAAgB,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;CACzE;AACD,eAAO,MAAM,cAAc,6HA2C1B,CAAA"}
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { ButtonGroupProps } from '@mui/material';
3
+ export interface FavoritePopperProps extends ButtonGroupProps {
4
+ alias?: string;
5
+ favorite?: boolean;
6
+ onConfirmFavorite?: (alias?: string, newFavoriteState?: boolean) => void;
7
+ }
8
+ export declare const PopperButtonGroup: React.FC<FavoritePopperProps>;
9
+ //# sourceMappingURL=PopperButtonGroup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PopperButtonGroup.d.ts","sourceRoot":"","sources":["../../../../src/components/favorite/PopperButtonGroup.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAuB,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAErE,MAAM,WAAW,mBAAoB,SAAQ,gBAAgB;IAC3D,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,iBAAiB,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,gBAAgB,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;CACzE;AAED,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAyB3D,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const popperId = "favorite-popper";
2
+ //# sourceMappingURL=PopperId.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PopperId.d.ts","sourceRoot":"","sources":["../../../../../src/components/favorite/lib/PopperId.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,oBAAoB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './PopperId';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/favorite/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA"}
package/package.json CHANGED
@@ -13,8 +13,8 @@
13
13
  "@xylabs/react-flexbox": "^2.16.11",
14
14
  "@xylabs/react-identicon": "^2.16.11",
15
15
  "@xylabs/react-shared": "^2.16.11",
16
- "@xyo-network/react-event": "^2.47.2",
17
- "@xyo-network/react-shared": "^2.47.2"
16
+ "@xyo-network/react-event": "^2.47.4",
17
+ "@xyo-network/react-shared": "^2.47.4"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "@mui/icons-material": "^5",
@@ -76,5 +76,5 @@
76
76
  },
77
77
  "sideEffects": false,
78
78
  "types": "dist/types/index.d.ts",
79
- "version": "2.47.2"
79
+ "version": "2.47.4"
80
80
  }
@@ -1,7 +1,9 @@
1
1
  import { ComponentMeta, ComponentStory } from '@storybook/react'
2
2
  import { Account } from '@xyo-network/account'
3
3
  import { useXyoEvent } from '@xyo-network/react-event'
4
+ import { useState } from 'react'
4
5
 
6
+ import { FavoriteEvent } from './favorite'
5
7
  import { AddressRenderRowBox } from './RenderRowBox'
6
8
 
7
9
  const address = new Account({ phrase: 'temp' }).addressValue.hex
@@ -18,8 +20,17 @@ const StorybookEntry = {
18
20
  } as ComponentMeta<typeof AddressRenderRowBox>
19
21
 
20
22
  const Template: ComponentStory<typeof AddressRenderRowBox> = (args) => {
21
- const [ref] = useXyoEvent<HTMLLIElement>((noun, verb, data) => console.log(`${noun}|${verb}|${data}`))
22
- return <AddressRenderRowBox {...args} ref={ref} />
23
+ const [ref] = useXyoEvent<HTMLLIElement>((noun, verb, data) => {
24
+ console.log(`${noun}|${verb}|${data}`)
25
+ const parsedEvent = JSON.parse(data ?? '') as FavoriteEvent
26
+ if (parsedEvent.favorite) {
27
+ setAlias(parsedEvent.alias)
28
+ } else {
29
+ setAlias(undefined)
30
+ }
31
+ })
32
+ const [alias, setAlias] = useState(args.alias)
33
+ return <AddressRenderRowBox {...args} alias={alias} ref={ref} />
23
34
  }
24
35
 
25
36
  const Default = Template.bind({})
@@ -51,6 +62,15 @@ WithFavorite.args = {
51
62
  showFavorite: true,
52
63
  }
53
64
 
65
+ const WithFavoriteAlias = Template.bind({})
66
+ WithFavoriteAlias.args = {
67
+ address,
68
+ alias: 'My Alias',
69
+ favorite: true,
70
+ icons: true,
71
+ showFavorite: true,
72
+ }
73
+
54
74
  const WithChildren = Template.bind({})
55
75
  WithChildren.args = {
56
76
  address,
@@ -60,7 +80,7 @@ WithChildren.args = {
60
80
  showFavorite: true,
61
81
  }
62
82
 
63
- export { Default, WithAddress, WithChildren, WithFavorite, WithIcon, WithIconOnly }
83
+ export { Default, WithAddress, WithChildren, WithFavorite, WithFavoriteAlias, WithIcon, WithIconOnly }
64
84
 
65
85
  // eslint-disable-next-line import/no-default-export
66
86
  export default StorybookEntry
@@ -10,17 +10,19 @@ import { FavoriteIconButton } from './favorite'
10
10
 
11
11
  export interface AddressRenderRowBoxPropsBase {
12
12
  address?: string | null
13
+ alias?: string
13
14
  favorite?: boolean
14
15
  iconOnly?: boolean
15
16
  iconSize?: number
16
17
  icons?: boolean
18
+ name?: string
17
19
  showFavorite?: boolean
18
20
  }
19
21
 
20
22
  export interface AddressRenderRowBoxProps extends WithChildren, AddressRenderRowBoxPropsBase, FlexBoxProps {}
21
23
 
22
24
  export const AddressRenderRowBox = forwardRef<HTMLElement, AddressRenderRowBoxProps>(
23
- ({ address, children, favorite: favoriteProp = false, iconOnly, iconSize = 24, icons, showFavorite = false, ...props }, ref) => {
25
+ ({ address, alias, children, favorite: favoriteProp = false, iconOnly, iconSize = 24, icons, name, showFavorite = false, ...props }, ref) => {
24
26
  const theme = useTheme()
25
27
 
26
28
  const sharedRef = useShareForwardedRef(ref)
@@ -42,12 +44,12 @@ export const AddressRenderRowBox = forwardRef<HTMLElement, AddressRenderRowBoxPr
42
44
  {iconOnly ? null : (
43
45
  <ListItemText>
44
46
  <EllipsizeBox ellipsisPosition={'end'} width="100%" typographyProps={{ fontSize: theme.typography.body1.fontSize }}>
45
- {address}
47
+ {alias ?? name ?? address}
46
48
  </EllipsizeBox>
47
49
  </ListItemText>
48
50
  )}
49
51
  {children}
50
- {showFavorite && address ? <FavoriteIconButton size={'small'} address={address} favorite={favoriteProp} /> : null}
52
+ {showFavorite && address ? <FavoriteIconButton alias={alias} size={'small'} address={address} favorite={favoriteProp} /> : null}
51
53
  </FlexGrowRow>
52
54
  )
53
55
  },
@@ -4,20 +4,28 @@ import { IconButton, IconButtonProps } from '@mui/material'
4
4
  import { WithChildren } from '@xylabs/react-shared'
5
5
  import { useXyoEvent } from '@xyo-network/react-event'
6
6
  import { useShareForwardedRef } from '@xyo-network/react-shared'
7
- import { forwardRef, useEffect, useState } from 'react'
7
+ import { forwardRef, useEffect, useRef, useState } from 'react'
8
+
9
+ import { popperId } from './lib'
10
+ import { FavoritePopper } from './Popper'
8
11
 
9
12
  export interface FavoriteEvent {
10
13
  address?: string
14
+ alias?: string
11
15
  favorite: boolean
12
16
  }
13
17
 
14
18
  export interface FavoriteIconButtonProps extends WithChildren, IconButtonProps {
19
+ // TODO - this could be anything really
15
20
  address?: string
21
+ alias?: string
16
22
  favorite?: boolean
17
23
  }
18
24
 
19
25
  export const FavoriteIconButton = forwardRef<HTMLButtonElement, FavoriteIconButtonProps>(
20
- ({ address, children, favorite: favoriteProp, ...props }, ref) => {
26
+ ({ address, alias, children, favorite: favoriteProp, ...props }, ref) => {
27
+ const [openPopper, setOpenPopper] = useState(false)
28
+
21
29
  const [favorite, setFavorite] = useState(favoriteProp)
22
30
  useEffect(() => {
23
31
  setFavorite(favoriteProp)
@@ -25,27 +33,42 @@ export const FavoriteIconButton = forwardRef<HTMLButtonElement, FavoriteIconButt
25
33
 
26
34
  const sharedRef = useShareForwardedRef(ref)
27
35
  const [buttonRef, dispatch] = useXyoEvent(undefined, sharedRef)
36
+ const onConfirmFavorite = (alias?: string, newFavoriteState?: boolean) => {
37
+ setFavorite(() => {
38
+ const favoriteEvent: FavoriteEvent = {
39
+ address,
40
+ alias,
41
+ favorite: !!newFavoriteState,
42
+ }
43
+ dispatch('address', 'favorite', JSON.stringify(favoriteEvent))
44
+ return newFavoriteState
45
+ })
46
+ setOpenPopper(false)
47
+ }
48
+
49
+ const starRef = useRef<HTMLSpanElement>(null)
28
50
 
29
51
  return (
30
52
  <IconButton
31
53
  ref={buttonRef}
54
+ aria-describedby={popperId}
32
55
  // used to prevent parent items from rippling when IconButton is clicked
33
56
  onMouseDown={(e) => e.stopPropagation()}
34
57
  onClick={(event) => {
35
58
  event.stopPropagation()
36
- setFavorite((current) => {
37
- const newFavoriteState = !current
38
- const favoriteEvent: FavoriteEvent = {
39
- address,
40
- favorite: newFavoriteState,
41
- }
42
- dispatch('address', 'favorite', JSON.stringify(favoriteEvent))
43
- return newFavoriteState
44
- })
59
+ setOpenPopper(true)
45
60
  }}
46
61
  {...props}
47
62
  >
48
- {favorite ? <StarIcon color="secondary" /> : <StarBorderIcon />}
63
+ <span ref={starRef}>{favorite ? <StarIcon component={'svg'} color="secondary" /> : <StarBorderIcon />}</span>
64
+ <FavoritePopper
65
+ alias={alias}
66
+ favorite={favorite}
67
+ favoriteRef={starRef}
68
+ open={openPopper}
69
+ onConfirmFavorite={onConfirmFavorite}
70
+ onClickAway={() => setOpenPopper(false)}
71
+ />
49
72
  {children}
50
73
  </IconButton>
51
74
  )
@@ -0,0 +1,59 @@
1
+ import { Card, CardContent, ClickAwayListener, Fade, Popper, PopperProps, TextField } from '@mui/material'
2
+ import { forwardRef, RefObject, useEffect, useState } from 'react'
3
+
4
+ import { popperId } from './lib'
5
+ import { PopperButtonGroup } from './PopperButtonGroup'
6
+
7
+ export interface FavoritePopperProps extends PopperProps {
8
+ alias?: string
9
+ favorite?: boolean
10
+ favoriteRef?: RefObject<HTMLElement>
11
+ onClickAway?: (event: MouseEvent | TouchEvent) => void
12
+ onConfirmFavorite?: (alias?: string, newFavoriteState?: boolean) => void
13
+ }
14
+ export const FavoritePopper = forwardRef<HTMLDivElement, FavoritePopperProps>(
15
+ (
16
+ {
17
+ alias: aliasProp,
18
+ favorite,
19
+ favoriteRef,
20
+ onClickAway = () => {
21
+ return
22
+ },
23
+ onConfirmFavorite,
24
+ ...props
25
+ },
26
+ ref,
27
+ ) => {
28
+ const [alias, setAlias] = useState<string>()
29
+ useEffect(() => {
30
+ setAlias(aliasProp)
31
+ }, [aliasProp])
32
+
33
+ return (
34
+ <ClickAwayListener onClickAway={onClickAway}>
35
+ <Popper id={popperId} anchorEl={favoriteRef?.current} transition ref={ref} {...props}>
36
+ {({ TransitionProps }) => (
37
+ <Fade {...TransitionProps} timeout={350}>
38
+ <Card>
39
+ <CardContent sx={{ display: 'flex', gap: 1 }}>
40
+ <TextField
41
+ autoFocus
42
+ label="Favorite Alias"
43
+ placeholder="optional"
44
+ size="small"
45
+ value={alias ?? ''}
46
+ onChange={(e) => setAlias(e.target.value)}
47
+ />
48
+ <PopperButtonGroup favorite={favorite} onConfirmFavorite={onConfirmFavorite} alias={alias} />
49
+ </CardContent>
50
+ </Card>
51
+ </Fade>
52
+ )}
53
+ </Popper>
54
+ </ClickAwayListener>
55
+ )
56
+ },
57
+ )
58
+
59
+ FavoritePopper.displayName = 'FavoritePopper'
@@ -0,0 +1,36 @@
1
+ import DeleteIcon from '@mui/icons-material/Delete'
2
+ import StarIcon from '@mui/icons-material/Star'
3
+ import { Button, ButtonGroup, ButtonGroupProps } from '@mui/material'
4
+
5
+ export interface FavoritePopperProps extends ButtonGroupProps {
6
+ alias?: string
7
+ favorite?: boolean
8
+ onConfirmFavorite?: (alias?: string, newFavoriteState?: boolean) => void
9
+ }
10
+
11
+ export const PopperButtonGroup: React.FC<FavoritePopperProps> = ({ alias, onConfirmFavorite, favorite, ...props }) => {
12
+ return (
13
+ <ButtonGroup {...props}>
14
+ <Button
15
+ variant="contained"
16
+ onClick={(e) => {
17
+ e.stopPropagation()
18
+ onConfirmFavorite?.(alias, true)
19
+ }}
20
+ >
21
+ <StarIcon />
22
+ </Button>
23
+ {favorite ? (
24
+ <Button
25
+ variant="contained"
26
+ onClick={(e) => {
27
+ e.stopPropagation()
28
+ onConfirmFavorite?.(alias, false)
29
+ }}
30
+ >
31
+ <DeleteIcon />
32
+ </Button>
33
+ ) : null}
34
+ </ButtonGroup>
35
+ )
36
+ }
@@ -0,0 +1 @@
1
+ export const popperId = 'favorite-popper'
@@ -0,0 +1 @@
1
+ export * from './PopperId'