@xyo-network/react-shared 2.26.37 → 2.26.40
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/docs.json +1 -1
- package/package.json +1 -1
- package/src/SizeProp.ts +1 -0
- package/src/components/Ampersand.tsx +9 -0
- package/src/components/BasicHero/BasicHero.stories.tsx +58 -0
- package/src/components/BasicHero/BasicHero.tsx +162 -0
- package/src/components/BasicHero/default-desktop.svg +1 -0
- package/src/components/BasicHero/index.ts +1 -0
- package/src/components/ErrorBoundry.tsx +42 -0
- package/src/components/JsonRouteWrapper/JsonApiButton.tsx +19 -0
- package/src/components/JsonRouteWrapper/JsonFromUrl.stories.tsx +48 -0
- package/src/components/JsonRouteWrapper/JsonFromUrl.tsx +52 -0
- package/src/components/JsonRouteWrapper/JsonRouteWrapper.stories.tsx +68 -0
- package/src/components/JsonRouteWrapper/JsonRouteWrapper.tsx +78 -0
- package/src/components/JsonRouteWrapper/index.ts +3 -0
- package/src/components/ListItemButtonEx.tsx +29 -0
- package/src/components/Pipe.tsx +9 -0
- package/src/components/ScrollTableOnSm.tsx +14 -0
- package/src/components/SectionSpacingRow/SectionSpacingRow.stories.tsx +36 -0
- package/src/components/SectionSpacingRow/SectionSpacingRow.tsx +19 -0
- package/src/components/SectionSpacingRow/index.ts +1 -0
- package/src/components/StyleGuide/AppBars.example.tsx +26 -0
- package/src/components/StyleGuide/Buttons.example.tsx +41 -0
- package/src/components/StyleGuide/Papers.example.tsx +19 -0
- package/src/components/StyleGuide/StyleGuide.example.tsx +19 -0
- package/src/components/StyleGuide/StyleGuide.stories.tsx +25 -0
- package/src/components/StyleGuide/Texts.example.tsx +16 -0
- package/src/components/StyleGuide/VariantContext.example.tsx +3 -0
- package/src/components/TableCell/AddressTableCell.tsx +13 -0
- package/src/components/TableCell/EllipsisTableCell.tsx +100 -0
- package/src/components/TableCell/HashTableCell.tsx +13 -0
- package/src/components/TableCell/findParent.ts +10 -0
- package/src/components/TableCell/getRemainingRowWidth.ts +14 -0
- package/src/components/TableCell/getSmallestParentWidth.ts +13 -0
- package/src/components/TableCell/index.ts +3 -0
- package/src/components/TypographyEx.tsx +12 -0
- package/src/components/index.ts +10 -0
- package/src/contexts/Pixel/Context.ts +4 -0
- package/src/contexts/Pixel/Provider.tsx +24 -0
- package/src/contexts/Pixel/State.ts +7 -0
- package/src/contexts/Pixel/index.ts +4 -0
- package/src/contexts/Pixel/use.ts +7 -0
- package/src/contexts/contextEx/State.ts +3 -0
- package/src/contexts/contextEx/create.ts +5 -0
- package/src/contexts/contextEx/index.ts +3 -0
- package/src/contexts/contextEx/use.ts +11 -0
- package/src/contexts/index.ts +2 -0
- package/src/hooks/GradientStyles/GradientStyle.stories.tsx +68 -0
- package/src/hooks/GradientStyles/GradientStyles.tsx +60 -0
- package/src/hooks/GradientStyles/index.ts +1 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/useIsMobile.ts +8 -0
- package/src/hooks/useMediaQuery.ts +7 -0
- package/src/index.ts +5 -0
- package/src/lib/assertDefinedEx.ts +4 -0
- package/src/lib/getActualPaddingX.ts +61 -0
- package/src/lib/index.ts +3 -0
- package/src/lib/networkComponents.tsx +29 -0
- package/src/types/images.d.ts +5 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { TableCell, TableCellProps } from '@mui/material'
|
|
2
|
+
import { LinkEx } from '@xylabs/react-link'
|
|
3
|
+
import { useEffect, useRef, useState } from 'react'
|
|
4
|
+
import { To } from 'react-router-dom'
|
|
5
|
+
|
|
6
|
+
import { getActualPaddingX } from '../../lib'
|
|
7
|
+
import { findParent } from './findParent'
|
|
8
|
+
import { getRemainingRowWidth } from './getRemainingRowWidth'
|
|
9
|
+
import { getSmallestParentWidth } from './getSmallestParentWidth'
|
|
10
|
+
|
|
11
|
+
export interface EllipsisTableCellProps extends TableCellProps {
|
|
12
|
+
value?: string
|
|
13
|
+
to?: To | undefined
|
|
14
|
+
href?: string | undefined
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const EllipsisTableCell: React.FC<EllipsisTableCellProps> = ({ children, value, to, href, ...props }) => {
|
|
18
|
+
const [calcCellWidth, setCalcCellWidth] = useState<number>(0)
|
|
19
|
+
const hashDivRef = useRef<HTMLDivElement>(null)
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
const currentElement = hashDivRef.current?.parentElement
|
|
23
|
+
const cell = findParent('td', currentElement)
|
|
24
|
+
const row = findParent('tr', currentElement)
|
|
25
|
+
|
|
26
|
+
const checkWidth = (cell: HTMLElement) => {
|
|
27
|
+
const smallestParentWidth = getSmallestParentWidth(cell)
|
|
28
|
+
if (smallestParentWidth && row) {
|
|
29
|
+
const remainingWidth = getRemainingRowWidth(row)
|
|
30
|
+
const actualPaddingX = getActualPaddingX(cell)
|
|
31
|
+
const remainderWidth = smallestParentWidth - remainingWidth - actualPaddingX
|
|
32
|
+
cell.style.width = `${remainderWidth}`
|
|
33
|
+
setCalcCellWidth(remainderWidth)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const onResize = () => {
|
|
38
|
+
if (cell) {
|
|
39
|
+
checkWidth(cell)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (cell) {
|
|
44
|
+
checkWidth(cell)
|
|
45
|
+
window.addEventListener('resize', onResize)
|
|
46
|
+
row?.addEventListener('resize', onResize)
|
|
47
|
+
}
|
|
48
|
+
return () => {
|
|
49
|
+
window.removeEventListener('resize', onResize)
|
|
50
|
+
row?.removeEventListener('resize', onResize)
|
|
51
|
+
}
|
|
52
|
+
}, [hashDivRef])
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<TableCell {...props}>
|
|
56
|
+
<div ref={hashDivRef}>
|
|
57
|
+
{children ? (
|
|
58
|
+
<span
|
|
59
|
+
style={{
|
|
60
|
+
display: 'block',
|
|
61
|
+
maxWidth: calcCellWidth,
|
|
62
|
+
overflow: 'hidden',
|
|
63
|
+
textOverflow: 'ellipsis',
|
|
64
|
+
whiteSpace: 'nowrap',
|
|
65
|
+
}}
|
|
66
|
+
>
|
|
67
|
+
{children}
|
|
68
|
+
</span>
|
|
69
|
+
) : href || to ? (
|
|
70
|
+
<LinkEx
|
|
71
|
+
style={{
|
|
72
|
+
display: 'block',
|
|
73
|
+
maxWidth: calcCellWidth,
|
|
74
|
+
overflow: 'hidden',
|
|
75
|
+
textOverflow: 'ellipsis',
|
|
76
|
+
whiteSpace: 'nowrap',
|
|
77
|
+
}}
|
|
78
|
+
to={to}
|
|
79
|
+
href={href}
|
|
80
|
+
target={href ? '_blank' : undefined}
|
|
81
|
+
>
|
|
82
|
+
{value}
|
|
83
|
+
</LinkEx>
|
|
84
|
+
) : (
|
|
85
|
+
<span
|
|
86
|
+
style={{
|
|
87
|
+
display: 'block',
|
|
88
|
+
maxWidth: calcCellWidth,
|
|
89
|
+
overflow: 'hidden',
|
|
90
|
+
textOverflow: 'ellipsis',
|
|
91
|
+
whiteSpace: 'nowrap',
|
|
92
|
+
}}
|
|
93
|
+
>
|
|
94
|
+
{value}
|
|
95
|
+
</span>
|
|
96
|
+
)}
|
|
97
|
+
</div>
|
|
98
|
+
</TableCell>
|
|
99
|
+
)
|
|
100
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EllipsisTableCell, EllipsisTableCellProps } from './EllipsisTableCell'
|
|
2
|
+
|
|
3
|
+
export interface HashTableCellProps extends EllipsisTableCellProps {
|
|
4
|
+
archive?: string
|
|
5
|
+
dataType?: 'block' | 'payload'
|
|
6
|
+
exploreDomain?: string
|
|
7
|
+
network?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const HashTableCell: React.FC<HashTableCellProps> = ({ value, archive, dataType, network, exploreDomain, ...props }) => {
|
|
11
|
+
const explorePath = `/archive/${archive}/${dataType}/hash/${value}?network=${network ?? 'main'}`
|
|
12
|
+
return <EllipsisTableCell value={value} href={exploreDomain ? `${exploreDomain}${explorePath}}` : undefined} to={exploreDomain ? undefined : explorePath} {...props} />
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const findParent = (tagName: string, element: HTMLElement | null = null) => {
|
|
2
|
+
let currentElement = element
|
|
3
|
+
while (currentElement) {
|
|
4
|
+
if (currentElement.tagName.toLowerCase() === tagName.toLowerCase()) {
|
|
5
|
+
return currentElement
|
|
6
|
+
} else {
|
|
7
|
+
currentElement = currentElement.parentElement
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** @description This is the width of all the cells (except the one passed) in the row combined and the spacing of the main cell */
|
|
2
|
+
export const getRemainingRowWidth = (row: HTMLElement, forCell = 0) => {
|
|
3
|
+
let width = 0
|
|
4
|
+
for (let i = 0; i < (row?.childElementCount ?? 0); i++) {
|
|
5
|
+
const item = row?.children.item(i)
|
|
6
|
+
if (item) {
|
|
7
|
+
if (i !== forCell) {
|
|
8
|
+
width += item?.clientWidth ?? 0
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return width
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const getSmallestParentWidth = (element: HTMLElement, maxDepth = 4) => {
|
|
2
|
+
let currentElement: HTMLElement | null = element?.parentElement
|
|
3
|
+
let width = currentElement?.clientWidth ?? screen.width
|
|
4
|
+
let maxDepthCounter = maxDepth
|
|
5
|
+
while (currentElement && maxDepthCounter > 0) {
|
|
6
|
+
if (width > currentElement.clientWidth) {
|
|
7
|
+
width = currentElement.clientWidth
|
|
8
|
+
}
|
|
9
|
+
currentElement = currentElement.parentElement
|
|
10
|
+
maxDepthCounter--
|
|
11
|
+
}
|
|
12
|
+
return width
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Typography, TypographyProps } from '@mui/material'
|
|
2
|
+
|
|
3
|
+
import { useGradientStyles } from '../hooks'
|
|
4
|
+
|
|
5
|
+
export interface TypographyExProps extends TypographyProps {
|
|
6
|
+
gradient?: 'text'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const TypographyEx: React.FC<TypographyExProps> = ({ gradient, ...props }) => {
|
|
10
|
+
const { classes } = useGradientStyles()
|
|
11
|
+
return <Typography className={gradient === 'text' ? classes().heading : undefined} {...props} />
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './Ampersand'
|
|
2
|
+
export * from './BasicHero'
|
|
3
|
+
export * from './ErrorBoundry'
|
|
4
|
+
export * from './JsonRouteWrapper'
|
|
5
|
+
export * from './ListItemButtonEx'
|
|
6
|
+
export * from './Pipe'
|
|
7
|
+
export * from './ScrollTableOnSm'
|
|
8
|
+
export * from './SectionSpacingRow'
|
|
9
|
+
export * from './TableCell'
|
|
10
|
+
export * from './TypographyEx'
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { XyPixel } from '@xylabs/pixel'
|
|
2
|
+
import { WithChildren } from '@xylabs/react-shared'
|
|
3
|
+
|
|
4
|
+
import { PixelContext } from './Context'
|
|
5
|
+
|
|
6
|
+
export interface PixelProviderProps {
|
|
7
|
+
id: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const PixelProvider: React.FC<WithChildren<PixelProviderProps>> = (props) => {
|
|
11
|
+
const { children, id } = props
|
|
12
|
+
XyPixel.init(id)
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<PixelContext.Provider
|
|
16
|
+
value={{
|
|
17
|
+
pixel: XyPixel.instance,
|
|
18
|
+
provided: true,
|
|
19
|
+
}}
|
|
20
|
+
>
|
|
21
|
+
{children}
|
|
22
|
+
</PixelContext.Provider>
|
|
23
|
+
)
|
|
24
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Context, useContext } from 'react'
|
|
2
|
+
|
|
3
|
+
import { ContextExState } from './State'
|
|
4
|
+
|
|
5
|
+
export const useContextEx = <T extends ContextExState>(context: Context<T>, contextName: string, required = true) => {
|
|
6
|
+
const { provided, ...props } = useContext(context)
|
|
7
|
+
if (!provided && required) {
|
|
8
|
+
throw Error(`use${contextName} can not be used outside of a ${contextName}Context when required=true`)
|
|
9
|
+
}
|
|
10
|
+
return props
|
|
11
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Divider, Typography } from '@mui/material'
|
|
2
|
+
import { ComponentMeta, ComponentStory } from '@storybook/react'
|
|
3
|
+
import { FlexBoxProps, FlexCol } from '@xylabs/react-flexbox'
|
|
4
|
+
import { BrowserRouter } from 'react-router-dom'
|
|
5
|
+
|
|
6
|
+
import { useGradientStyles } from './GradientStyles'
|
|
7
|
+
|
|
8
|
+
const GradientTextExample: React.FC<FlexBoxProps> = (props) => {
|
|
9
|
+
const { classes } = useGradientStyles()
|
|
10
|
+
const classNames = classes()
|
|
11
|
+
return (
|
|
12
|
+
<FlexCol alignItems="stretch" {...props}>
|
|
13
|
+
<Typography variant="h4" gutterBottom>
|
|
14
|
+
XYO Network Gradient Text Options
|
|
15
|
+
</Typography>
|
|
16
|
+
<Typography variant="subtitle2" gutterBottom paddingTop={3}>
|
|
17
|
+
Highlight
|
|
18
|
+
</Typography>
|
|
19
|
+
<Divider sx={{ marginY: '8px' }} />
|
|
20
|
+
<Typography variant="h5" gutterBottom>
|
|
21
|
+
Lorem ipsum dolor sit amet consectetur, <span className={classNames.heading}>adipisicing elit.</span>
|
|
22
|
+
</Typography>
|
|
23
|
+
<Typography variant="subtitle2" gutterBottom paddingTop={3}>
|
|
24
|
+
Body Text
|
|
25
|
+
</Typography>
|
|
26
|
+
<Divider sx={{ marginY: '8px' }} />
|
|
27
|
+
<Typography variant="h5" gutterBottom className={classNames.heading}>
|
|
28
|
+
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Sint perspiciatis aliquam consequuntur nisi alias impedit ducimus ipsa voluptas, suscipit ea vel dicta quasi hic,
|
|
29
|
+
deserunt tempore, natus optio veritatis dolor?
|
|
30
|
+
</Typography>
|
|
31
|
+
<Typography variant="subtitle2" gutterBottom paddingTop={3}>
|
|
32
|
+
Caption
|
|
33
|
+
</Typography>
|
|
34
|
+
<Divider sx={{ marginY: '8px' }} />
|
|
35
|
+
<Typography variant="caption" gutterBottom className={classNames.heading}>
|
|
36
|
+
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Sint perspiciatis aliquam consequuntur nisi alias impedit ducimus ipsa voluptas, suscipit ea vel dicta quasi hic,
|
|
37
|
+
deserunt tempore, natus optio veritatis dolor?
|
|
38
|
+
</Typography>
|
|
39
|
+
<Typography variant="subtitle2" gutterBottom paddingTop={3}>
|
|
40
|
+
Card Border
|
|
41
|
+
</Typography>
|
|
42
|
+
<Divider sx={{ marginY: '8px' }} />
|
|
43
|
+
</FlexCol>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const StorybookEntry = {
|
|
48
|
+
argTypes: {},
|
|
49
|
+
component: GradientTextExample,
|
|
50
|
+
parameters: {
|
|
51
|
+
docs: {
|
|
52
|
+
page: null,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
title: 'shared/GradientText',
|
|
56
|
+
} as ComponentMeta<typeof GradientTextExample>
|
|
57
|
+
|
|
58
|
+
const Template: ComponentStory<typeof GradientTextExample> = (args) => (
|
|
59
|
+
<BrowserRouter>
|
|
60
|
+
<GradientTextExample {...args}></GradientTextExample>
|
|
61
|
+
</BrowserRouter>
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
export const Default = Template.bind({})
|
|
65
|
+
Default.args = {}
|
|
66
|
+
|
|
67
|
+
// eslint-disable-next-line import/no-default-export
|
|
68
|
+
export default StorybookEntry
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useTheme } from '@mui/material'
|
|
2
|
+
import { makeStyles } from '@mui/styles'
|
|
3
|
+
import { CSSProperties } from 'react'
|
|
4
|
+
|
|
5
|
+
export interface GradientStyles {
|
|
6
|
+
background: CSSProperties
|
|
7
|
+
border: CSSProperties
|
|
8
|
+
heading: CSSProperties
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const colorfulGradientLightMode = () => {
|
|
12
|
+
return {
|
|
13
|
+
background: {
|
|
14
|
+
backgroundImage: '-webkit-linear-gradient(232deg, #e17751, #d84e7a, #5898dd, #8c8ee5)',
|
|
15
|
+
},
|
|
16
|
+
border: {
|
|
17
|
+
borderImage: '-webkit-linear-gradient(232deg, #e17751, #d84e7a, #5898dd, #8c8ee5)',
|
|
18
|
+
borderImageSlice: 1,
|
|
19
|
+
borderImageSource: '-webkit-linear-gradient(232deg, #e17751, #d84e7a, #5898dd, #8c8ee5)',
|
|
20
|
+
borderRadius: 0,
|
|
21
|
+
borderStyle: 'solid',
|
|
22
|
+
borderWidth: '2px',
|
|
23
|
+
},
|
|
24
|
+
heading: {
|
|
25
|
+
WebkitBackgroundClip: 'text',
|
|
26
|
+
WebkitTextFillColor: 'transparent',
|
|
27
|
+
background: '-webkit-linear-gradient(232deg, #e17751, #d84e7a, #5898dd, #8c8ee5)',
|
|
28
|
+
display: 'inline-block',
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const colorfulGradientDarkMode = () => {
|
|
34
|
+
return {
|
|
35
|
+
background: {
|
|
36
|
+
backgroundImage: '-webkit-linear-gradient(232deg, #F17938, #FF5BDC, #5898dd, #B2FFFD)',
|
|
37
|
+
},
|
|
38
|
+
border: {
|
|
39
|
+
borderImage: '-webkit-linear-gradient(232deg, #F17938, #FF5BDC, #5898dd, #B2FFFD)',
|
|
40
|
+
borderImageSlice: 1,
|
|
41
|
+
borderImageSource: '-webkit-linear-gradient(232deg, #F17938, #FF5BDC, #5898dd, #B2FFFD)',
|
|
42
|
+
borderRadius: 0,
|
|
43
|
+
borderStyle: 'solid',
|
|
44
|
+
borderWidth: '2px',
|
|
45
|
+
},
|
|
46
|
+
heading: {
|
|
47
|
+
WebkitBackgroundClip: 'text',
|
|
48
|
+
WebkitTextFillColor: 'transparent',
|
|
49
|
+
background: '-webkit-linear-gradient(232deg, #F17938, #FF5BDC, #5898dd, #B2FFFD)',
|
|
50
|
+
display: 'inline-block',
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const useGradientStyles = () => {
|
|
56
|
+
const theme = useTheme()
|
|
57
|
+
const styles = theme.palette.mode === 'dark' ? colorfulGradientDarkMode() : colorfulGradientLightMode()
|
|
58
|
+
const classes = makeStyles(styles)
|
|
59
|
+
return { classes, styles }
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './GradientStyles'
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export const parseMeausureString = (measure?: string, absolute?: number) => {
|
|
2
|
+
if (measure !== undefined && measure !== null && measure.length > 0) {
|
|
3
|
+
if (measure.endsWith('px')) {
|
|
4
|
+
return parseFloat(measure.substring(0, measure.length - 2))
|
|
5
|
+
} else if (measure.endsWith('%')) {
|
|
6
|
+
if (absolute !== undefined) {
|
|
7
|
+
return (parseFloat(measure.substring(0, measure.length - 1)) / 100) * absolute
|
|
8
|
+
}
|
|
9
|
+
throw Error('Error Parsing Measure [missing absolute]')
|
|
10
|
+
} else if (measure.endsWith('vw')) {
|
|
11
|
+
return (parseFloat(measure.substring(0, measure.length - 2)) / 100) * window.innerWidth
|
|
12
|
+
} else if (measure.endsWith('vh')) {
|
|
13
|
+
return (parseFloat(measure.substring(0, measure.length - 2)) / 100) * window.innerHeight
|
|
14
|
+
}
|
|
15
|
+
throw Error(`Error Parsing Measure [${measure}]`)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const parsePadding = (padding: string) => {
|
|
20
|
+
const parts = padding.split(' ')
|
|
21
|
+
switch (parts.length) {
|
|
22
|
+
case 4: {
|
|
23
|
+
return {
|
|
24
|
+
bottom: parts[2],
|
|
25
|
+
left: parts[3],
|
|
26
|
+
right: parts[1],
|
|
27
|
+
top: parts[0],
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
case 3: {
|
|
31
|
+
return {
|
|
32
|
+
bottom: parts[2],
|
|
33
|
+
right: parts[1],
|
|
34
|
+
top: parts[0],
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
case 2: {
|
|
38
|
+
return {
|
|
39
|
+
bottom: parts[0],
|
|
40
|
+
left: parts[1],
|
|
41
|
+
right: parts[1],
|
|
42
|
+
top: parts[0],
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
case 1: {
|
|
46
|
+
return {
|
|
47
|
+
bottom: parts[0],
|
|
48
|
+
left: parts[0],
|
|
49
|
+
right: parts[0],
|
|
50
|
+
top: parts[0],
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const getActualPaddingX = (element: HTMLElement) => {
|
|
57
|
+
const padding = parsePadding(window.getComputedStyle(element, null).getPropertyValue('padding'))
|
|
58
|
+
const paddingLeft = parseMeausureString(window.getComputedStyle(element, null).getPropertyValue('padding-left') ?? padding?.left, element.clientWidth) ?? 0
|
|
59
|
+
const paddingRight = parseMeausureString(window.getComputedStyle(element, null).getPropertyValue('padding-right') ?? padding?.right, element.clientWidth) ?? 0
|
|
60
|
+
return paddingLeft + paddingRight
|
|
61
|
+
}
|
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import BubbleChartRoundedIcon from '@mui/icons-material/BubbleChartRounded'
|
|
2
|
+
import CloudRoundedIcon from '@mui/icons-material/CloudRounded'
|
|
3
|
+
import GridViewRoundedIcon from '@mui/icons-material/GridViewRounded'
|
|
4
|
+
import VisibilityRoundedIcon from '@mui/icons-material/VisibilityRounded'
|
|
5
|
+
import { SvgIconProps } from '@mui/material'
|
|
6
|
+
import { ReactElement } from 'react'
|
|
7
|
+
|
|
8
|
+
export type NetworkComponentSlug = 'sentinel' | 'bridge' | 'archivist' | 'diviner'
|
|
9
|
+
|
|
10
|
+
export interface NetworkComponentDetails {
|
|
11
|
+
name: string
|
|
12
|
+
slug: NetworkComponentSlug
|
|
13
|
+
icon: (props?: SvgIconProps) => ReactElement
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const networkComponents: NetworkComponentDetails[] = [
|
|
17
|
+
{ icon: (props) => <BubbleChartRoundedIcon {...props} />, name: 'Sentinel', slug: 'sentinel' },
|
|
18
|
+
{ icon: (props) => <CloudRoundedIcon {...props} />, name: 'Bridge', slug: 'bridge' },
|
|
19
|
+
{ icon: (props) => <GridViewRoundedIcon {...props} />, name: 'Archivist', slug: 'archivist' },
|
|
20
|
+
{ icon: (props) => <VisibilityRoundedIcon {...props} />, name: 'Diviner', slug: 'diviner' },
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
export const findNetworkComponentIndex = (slug: string) => {
|
|
24
|
+
return networkComponents.findIndex((info) => info.slug === slug)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const findNetworkComponent = (slug: string) => {
|
|
28
|
+
return networkComponents.find((info) => info.slug === slug)
|
|
29
|
+
}
|