@xyo-network/react-address-render 2.47.2
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/LICENSE +165 -0
- package/README.md +13 -0
- package/dist/cjs/components/RenderRowBox.js +21 -0
- package/dist/cjs/components/RenderRowBox.js.map +1 -0
- package/dist/cjs/components/favorite/FavoriteIconButton.js +36 -0
- package/dist/cjs/components/favorite/FavoriteIconButton.js.map +1 -0
- package/dist/cjs/components/favorite/index.js +5 -0
- package/dist/cjs/components/favorite/index.js.map +1 -0
- package/dist/cjs/components/index.js +6 -0
- package/dist/cjs/components/index.js.map +1 -0
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/docs.json +19144 -0
- package/dist/esm/components/RenderRowBox.js +16 -0
- package/dist/esm/components/RenderRowBox.js.map +1 -0
- package/dist/esm/components/favorite/FavoriteIconButton.js +31 -0
- package/dist/esm/components/favorite/FavoriteIconButton.js.map +1 -0
- package/dist/esm/components/favorite/index.js +2 -0
- package/dist/esm/components/favorite/index.js.map +1 -0
- package/dist/esm/components/index.js +3 -0
- package/dist/esm/components/index.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/types/components/RenderRowBox.d.ts +15 -0
- package/dist/types/components/RenderRowBox.d.ts.map +1 -0
- package/dist/types/components/favorite/FavoriteIconButton.d.ts +13 -0
- package/dist/types/components/favorite/FavoriteIconButton.d.ts.map +1 -0
- package/dist/types/components/favorite/index.d.ts +2 -0
- package/dist/types/components/favorite/index.d.ts.map +1 -0
- package/dist/types/components/index.d.ts +3 -0
- package/dist/types/components/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +80 -0
- package/src/components/RenderRowBox.stories.tsx +66 -0
- package/src/components/RenderRowBox.tsx +56 -0
- package/src/components/favorite/FavoriteIconButton.tsx +55 -0
- package/src/components/favorite/index.ts +1 -0
- package/src/components/index.ts +2 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ListItemIcon, ListItemText, useTheme } from '@mui/material';
|
|
3
|
+
import { FlexGrowRow } from '@xylabs/react-flexbox';
|
|
4
|
+
import { Identicon } from '@xylabs/react-identicon';
|
|
5
|
+
import { useXyoEvent } from '@xyo-network/react-event';
|
|
6
|
+
import { EllipsizeBox, useShareForwardedRef } from '@xyo-network/react-shared';
|
|
7
|
+
import { forwardRef } from 'react';
|
|
8
|
+
import { FavoriteIconButton } from './favorite';
|
|
9
|
+
export const AddressRenderRowBox = forwardRef(({ address, children, favorite: favoriteProp = false, iconOnly, iconSize = 24, icons, showFavorite = false, ...props }, ref) => {
|
|
10
|
+
const theme = useTheme();
|
|
11
|
+
const sharedRef = useShareForwardedRef(ref);
|
|
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] }));
|
|
14
|
+
});
|
|
15
|
+
AddressRenderRowBox.displayName = 'AddressRenderRowBox';
|
|
16
|
+
//# sourceMappingURL=RenderRowBox.js.map
|
|
@@ -0,0 +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,EAAE,QAAQ,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,GAAG,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE;IAC7H,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAA;IAExB,MAAM,SAAS,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAA;IAC3C,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,WAAW,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;IAEhE,OAAO,CACL,MAAC,WAAW,IACV,GAAG,EAAE,CAAC,EACN,cAAc,EAAC,YAAY,EAC3B,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,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,OAAO,GACK,GACF,CAChB,EACA,QAAQ,EACR,YAAY,IAAI,OAAO,CAAC,CAAC,CAAC,KAAC,kBAAkB,IAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,GAAI,CAAC,CAAC,CAAC,IAAI,IACrG,CACf,CAAA;AACH,CAAC,CACF,CAAA;AAED,mBAAmB,CAAC,WAAW,GAAG,qBAAqB,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import StarIcon from '@mui/icons-material/Star';
|
|
3
|
+
import StarBorderIcon from '@mui/icons-material/StarBorder';
|
|
4
|
+
import { IconButton } from '@mui/material';
|
|
5
|
+
import { useXyoEvent } from '@xyo-network/react-event';
|
|
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) => {
|
|
9
|
+
const [favorite, setFavorite] = useState(favoriteProp);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
setFavorite(favoriteProp);
|
|
12
|
+
}, [favoriteProp]);
|
|
13
|
+
const sharedRef = useShareForwardedRef(ref);
|
|
14
|
+
const [buttonRef, dispatch] = useXyoEvent(undefined, sharedRef);
|
|
15
|
+
return (_jsxs(IconButton, { ref: buttonRef,
|
|
16
|
+
// used to prevent parent items from rippling when IconButton is clicked
|
|
17
|
+
onMouseDown: (e) => e.stopPropagation(), onClick: (event) => {
|
|
18
|
+
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] }));
|
|
29
|
+
});
|
|
30
|
+
FavoriteIconButton.displayName = 'FavoriteIconButton';
|
|
31
|
+
//# sourceMappingURL=FavoriteIconButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FavoriteIconButton.js","sourceRoot":"","sources":["../../../../src/components/favorite/FavoriteIconButton.tsx"],"names":[],"mappings":";AAAA,OAAO,QAAQ,MAAM,0BAA0B,CAAA;AAC/C,OAAO,cAAc,MAAM,gCAAgC,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAmB,MAAM,eAAe,CAAA;AAE3D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAYvD,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAC1C,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE;IAC/D,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAA;IACtD,SAAS,CAAC,GAAG,EAAE;QACb,WAAW,CAAC,YAAY,CAAC,CAAA;IAC3B,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAA;IAElB,MAAM,SAAS,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAA;IAC3C,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,GAAG,WAAW,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;IAE/D,OAAO,CACL,MAAC,UAAU,IACT,GAAG,EAAE,SAAS;QACd,wEAAwE;QACxE,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,eAAe,EAAE,EACvC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YACjB,KAAK,CAAC,eAAe,EAAE,CAAA;YACvB,WAAW,CAAC,CAAC,OAAO,EAAE,EAAE;gBACtB,MAAM,gBAAgB,GAAG,CAAC,OAAO,CAAA;gBACjC,MAAM,aAAa,GAAkB;oBACnC,OAAO;oBACP,QAAQ,EAAE,gBAAgB;iBAC3B,CAAA;gBACD,QAAQ,CAAC,SAAS,EAAE,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAA;gBAC9D,OAAO,gBAAgB,CAAA;YACzB,CAAC,CAAC,CAAA;QACJ,CAAC,KACG,KAAK,aAER,QAAQ,CAAC,CAAC,CAAC,KAAC,QAAQ,IAAC,KAAK,EAAC,WAAW,GAAG,CAAC,CAAC,CAAC,KAAC,cAAc,KAAG,EAC9D,QAAQ,IACE,CACd,CAAA;AACH,CAAC,CACF,CAAA;AAED,kBAAkB,CAAC,WAAW,GAAG,oBAAoB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/favorite/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { FlexBoxProps } from '@xylabs/react-flexbox';
|
|
3
|
+
import { WithChildren } from '@xylabs/react-shared';
|
|
4
|
+
export interface AddressRenderRowBoxPropsBase {
|
|
5
|
+
address?: string | null;
|
|
6
|
+
favorite?: boolean;
|
|
7
|
+
iconOnly?: boolean;
|
|
8
|
+
iconSize?: number;
|
|
9
|
+
icons?: boolean;
|
|
10
|
+
showFavorite?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface AddressRenderRowBoxProps extends WithChildren, AddressRenderRowBoxPropsBase, FlexBoxProps {
|
|
13
|
+
}
|
|
14
|
+
export declare const AddressRenderRowBox: import("react").ForwardRefExoticComponent<AddressRenderRowBoxProps & import("react").RefAttributes<HTMLElement>>;
|
|
15
|
+
//# sourceMappingURL=RenderRowBox.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { IconButtonProps } from '@mui/material';
|
|
3
|
+
import { WithChildren } from '@xylabs/react-shared';
|
|
4
|
+
export interface FavoriteEvent {
|
|
5
|
+
address?: string;
|
|
6
|
+
favorite: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface FavoriteIconButtonProps extends WithChildren, IconButtonProps {
|
|
9
|
+
address?: string;
|
|
10
|
+
favorite?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare const FavoriteIconButton: import("react").ForwardRefExoticComponent<Omit<FavoriteIconButtonProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
|
|
13
|
+
//# sourceMappingURL=FavoriteIconButton.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/favorite/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xyo-network/react-address-render",
|
|
3
|
+
"author": {
|
|
4
|
+
"email": "support@xyo.network",
|
|
5
|
+
"name": "XYO Development Team",
|
|
6
|
+
"url": "https://xyo.network"
|
|
7
|
+
},
|
|
8
|
+
"bugs": {
|
|
9
|
+
"email": "support@xyo.network",
|
|
10
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/issues"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@xylabs/react-flexbox": "^2.16.11",
|
|
14
|
+
"@xylabs/react-identicon": "^2.16.11",
|
|
15
|
+
"@xylabs/react-shared": "^2.16.11",
|
|
16
|
+
"@xyo-network/react-event": "^2.47.2",
|
|
17
|
+
"@xyo-network/react-shared": "^2.47.2"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"@mui/icons-material": "^5",
|
|
21
|
+
"@mui/material": "^5",
|
|
22
|
+
"@mui/styles": "^5",
|
|
23
|
+
"axios": "^1",
|
|
24
|
+
"react": "^18",
|
|
25
|
+
"react-dom": "^18",
|
|
26
|
+
"react-router-dom": "^6"
|
|
27
|
+
},
|
|
28
|
+
"description": "Common React library for all XYO projects that use React",
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@storybook/react": "^6.5.16",
|
|
31
|
+
"@xylabs/ts-scripts-yarn3": "^2.16.1",
|
|
32
|
+
"@xylabs/tsconfig-react": "^2.16.1",
|
|
33
|
+
"@xyo-network/account": "^2.53.3",
|
|
34
|
+
"require-from-string": "^2.0.2",
|
|
35
|
+
"typescript": "^4.9.5"
|
|
36
|
+
},
|
|
37
|
+
"browser": "dist/esm/index.js",
|
|
38
|
+
"docs": "dist/docs.json",
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"node": {
|
|
42
|
+
"import": "./dist/esm/index.js",
|
|
43
|
+
"require": "./dist/cjs/index.js"
|
|
44
|
+
},
|
|
45
|
+
"browser": {
|
|
46
|
+
"import": "./dist/esm/index.js",
|
|
47
|
+
"require": "./dist/cjs/index.js"
|
|
48
|
+
},
|
|
49
|
+
"default": "./dist/esm/index.js"
|
|
50
|
+
},
|
|
51
|
+
"./dist/docs.json": {
|
|
52
|
+
"default": "./dist/docs.json"
|
|
53
|
+
},
|
|
54
|
+
"./package.json": "./package.json"
|
|
55
|
+
},
|
|
56
|
+
"main": "dist/cjs/index.js",
|
|
57
|
+
"module": "dist/esm/index.js",
|
|
58
|
+
"homepage": "https://xyo.network",
|
|
59
|
+
"keywords": [
|
|
60
|
+
"xyo",
|
|
61
|
+
"utility",
|
|
62
|
+
"typescript",
|
|
63
|
+
"react"
|
|
64
|
+
],
|
|
65
|
+
"license": "LGPL-3.0",
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public"
|
|
68
|
+
},
|
|
69
|
+
"repository": {
|
|
70
|
+
"type": "git",
|
|
71
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js.git"
|
|
72
|
+
},
|
|
73
|
+
"scripts": {
|
|
74
|
+
"lint-pkg": "npmPkgJsonLint .",
|
|
75
|
+
"license": "yarn license-checker --exclude \"MIT, ISC, Apache-2.0, BSD, BSD-2-Clause, CC-BY-4.0, Unlicense, CC-BY-3.0, CC0-1.0\""
|
|
76
|
+
},
|
|
77
|
+
"sideEffects": false,
|
|
78
|
+
"types": "dist/types/index.d.ts",
|
|
79
|
+
"version": "2.47.2"
|
|
80
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ComponentMeta, ComponentStory } from '@storybook/react'
|
|
2
|
+
import { Account } from '@xyo-network/account'
|
|
3
|
+
import { useXyoEvent } from '@xyo-network/react-event'
|
|
4
|
+
|
|
5
|
+
import { AddressRenderRowBox } from './RenderRowBox'
|
|
6
|
+
|
|
7
|
+
const address = new Account({ phrase: 'temp' }).addressValue.hex
|
|
8
|
+
|
|
9
|
+
const StorybookEntry = {
|
|
10
|
+
argTypes: {},
|
|
11
|
+
component: AddressRenderRowBox,
|
|
12
|
+
parameters: {
|
|
13
|
+
docs: {
|
|
14
|
+
page: null,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
title: 'address/render/AddressRenderRowBox',
|
|
18
|
+
} as ComponentMeta<typeof AddressRenderRowBox>
|
|
19
|
+
|
|
20
|
+
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
|
+
}
|
|
24
|
+
|
|
25
|
+
const Default = Template.bind({})
|
|
26
|
+
Default.args = {}
|
|
27
|
+
|
|
28
|
+
const WithAddress = Template.bind({})
|
|
29
|
+
WithAddress.args = {
|
|
30
|
+
address,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const WithIcon = Template.bind({})
|
|
34
|
+
WithIcon.args = {
|
|
35
|
+
address,
|
|
36
|
+
icons: true,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const WithIconOnly = Template.bind({})
|
|
40
|
+
WithIconOnly.args = {
|
|
41
|
+
address,
|
|
42
|
+
iconOnly: true,
|
|
43
|
+
icons: true,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const WithFavorite = Template.bind({})
|
|
47
|
+
WithFavorite.args = {
|
|
48
|
+
address,
|
|
49
|
+
favorite: true,
|
|
50
|
+
icons: true,
|
|
51
|
+
showFavorite: true,
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const WithChildren = Template.bind({})
|
|
55
|
+
WithChildren.args = {
|
|
56
|
+
address,
|
|
57
|
+
children: <span>{'[InsertedChild]'}</span>,
|
|
58
|
+
favorite: true,
|
|
59
|
+
icons: true,
|
|
60
|
+
showFavorite: true,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { Default, WithAddress, WithChildren, WithFavorite, WithIcon, WithIconOnly }
|
|
64
|
+
|
|
65
|
+
// eslint-disable-next-line import/no-default-export
|
|
66
|
+
export default StorybookEntry
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ListItemIcon, ListItemText, useTheme } from '@mui/material'
|
|
2
|
+
import { FlexBoxProps, FlexGrowRow } from '@xylabs/react-flexbox'
|
|
3
|
+
import { Identicon } from '@xylabs/react-identicon'
|
|
4
|
+
import { WithChildren } from '@xylabs/react-shared'
|
|
5
|
+
import { useXyoEvent } from '@xyo-network/react-event'
|
|
6
|
+
import { EllipsizeBox, useShareForwardedRef } from '@xyo-network/react-shared'
|
|
7
|
+
import { forwardRef } from 'react'
|
|
8
|
+
|
|
9
|
+
import { FavoriteIconButton } from './favorite'
|
|
10
|
+
|
|
11
|
+
export interface AddressRenderRowBoxPropsBase {
|
|
12
|
+
address?: string | null
|
|
13
|
+
favorite?: boolean
|
|
14
|
+
iconOnly?: boolean
|
|
15
|
+
iconSize?: number
|
|
16
|
+
icons?: boolean
|
|
17
|
+
showFavorite?: boolean
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface AddressRenderRowBoxProps extends WithChildren, AddressRenderRowBoxPropsBase, FlexBoxProps {}
|
|
21
|
+
|
|
22
|
+
export const AddressRenderRowBox = forwardRef<HTMLElement, AddressRenderRowBoxProps>(
|
|
23
|
+
({ address, children, favorite: favoriteProp = false, iconOnly, iconSize = 24, icons, showFavorite = false, ...props }, ref) => {
|
|
24
|
+
const theme = useTheme()
|
|
25
|
+
|
|
26
|
+
const sharedRef = useShareForwardedRef(ref)
|
|
27
|
+
const [elementRef, dispatch] = useXyoEvent(undefined, sharedRef)
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<FlexGrowRow
|
|
31
|
+
gap={2}
|
|
32
|
+
justifyContent="flex-start"
|
|
33
|
+
ref={elementRef}
|
|
34
|
+
onClick={() => (address ? dispatch('address', 'click', address) : undefined)}
|
|
35
|
+
{...props}
|
|
36
|
+
>
|
|
37
|
+
{icons && address ? (
|
|
38
|
+
<ListItemIcon sx={{ minWidth: 0 }}>
|
|
39
|
+
<Identicon size={iconSize} value={address} />
|
|
40
|
+
</ListItemIcon>
|
|
41
|
+
) : null}
|
|
42
|
+
{iconOnly ? null : (
|
|
43
|
+
<ListItemText>
|
|
44
|
+
<EllipsizeBox ellipsisPosition={'end'} width="100%" typographyProps={{ fontSize: theme.typography.body1.fontSize }}>
|
|
45
|
+
{address}
|
|
46
|
+
</EllipsizeBox>
|
|
47
|
+
</ListItemText>
|
|
48
|
+
)}
|
|
49
|
+
{children}
|
|
50
|
+
{showFavorite && address ? <FavoriteIconButton size={'small'} address={address} favorite={favoriteProp} /> : null}
|
|
51
|
+
</FlexGrowRow>
|
|
52
|
+
)
|
|
53
|
+
},
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
AddressRenderRowBox.displayName = 'AddressRenderRowBox'
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import StarIcon from '@mui/icons-material/Star'
|
|
2
|
+
import StarBorderIcon from '@mui/icons-material/StarBorder'
|
|
3
|
+
import { IconButton, IconButtonProps } from '@mui/material'
|
|
4
|
+
import { WithChildren } from '@xylabs/react-shared'
|
|
5
|
+
import { useXyoEvent } from '@xyo-network/react-event'
|
|
6
|
+
import { useShareForwardedRef } from '@xyo-network/react-shared'
|
|
7
|
+
import { forwardRef, useEffect, useState } from 'react'
|
|
8
|
+
|
|
9
|
+
export interface FavoriteEvent {
|
|
10
|
+
address?: string
|
|
11
|
+
favorite: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface FavoriteIconButtonProps extends WithChildren, IconButtonProps {
|
|
15
|
+
address?: string
|
|
16
|
+
favorite?: boolean
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const FavoriteIconButton = forwardRef<HTMLButtonElement, FavoriteIconButtonProps>(
|
|
20
|
+
({ address, children, favorite: favoriteProp, ...props }, ref) => {
|
|
21
|
+
const [favorite, setFavorite] = useState(favoriteProp)
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
setFavorite(favoriteProp)
|
|
24
|
+
}, [favoriteProp])
|
|
25
|
+
|
|
26
|
+
const sharedRef = useShareForwardedRef(ref)
|
|
27
|
+
const [buttonRef, dispatch] = useXyoEvent(undefined, sharedRef)
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<IconButton
|
|
31
|
+
ref={buttonRef}
|
|
32
|
+
// used to prevent parent items from rippling when IconButton is clicked
|
|
33
|
+
onMouseDown={(e) => e.stopPropagation()}
|
|
34
|
+
onClick={(event) => {
|
|
35
|
+
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
|
+
})
|
|
45
|
+
}}
|
|
46
|
+
{...props}
|
|
47
|
+
>
|
|
48
|
+
{favorite ? <StarIcon color="secondary" /> : <StarBorderIcon />}
|
|
49
|
+
{children}
|
|
50
|
+
</IconButton>
|
|
51
|
+
)
|
|
52
|
+
},
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
FavoriteIconButton.displayName = 'FavoriteIconButton'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './FavoriteIconButton'
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components'
|