forked from input-output-hk/daedalus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into chore/ddw-596-webpack-5-upgrade
# Conflicts: # source/renderer/app/i18n/locales/defaultMessages.json
- Loading branch information
Showing
27 changed files
with
296 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
source/renderer/app/components/sidebar/SidebarCategory.messages.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { defineMessages } from 'react-intl'; | ||
|
||
export const messages = defineMessages({ | ||
wallets: { | ||
id: 'sidebar.categoryTooltip.wallets', | ||
defaultMessage: '!!!Wallets', | ||
description: 'Text for the tooltip of wallets category', | ||
}, | ||
staking: { | ||
id: 'sidebar.categoryTooltip.staking', | ||
defaultMessage: '!!!Staking', | ||
description: 'Text for the tooltip of staking category', | ||
}, | ||
settings: { | ||
id: 'sidebar.categoryTooltip.settings', | ||
defaultMessage: '!!!Settings', | ||
description: 'Text for the tooltip of settings category', | ||
}, | ||
voting: { | ||
id: 'sidebar.categoryTooltip.voting', | ||
defaultMessage: '!!!Voting', | ||
description: 'Text for the tooltip of voting category', | ||
}, | ||
}); |
57 changes: 34 additions & 23 deletions
57
source/renderer/app/components/sidebar/SidebarCategory.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,53 @@ | ||
import React, { Component } from 'react'; | ||
// @ts-ignore ts-migrate(2305) FIXME: Module '"react"' has no exported member 'Node'. | ||
import type { Node } from 'react'; | ||
import React from 'react'; | ||
import SVGInline from 'react-svg-inline'; | ||
import { observer } from 'mobx-react'; | ||
import classNames from 'classnames'; | ||
import { camelCase } from 'lodash'; | ||
import { PopOver } from 'react-polymorph/lib/components/PopOver'; | ||
import { injectIntl } from 'react-intl'; | ||
import type { SidebarCategoryInfo } from '../../config/sidebarConfig'; | ||
import styles from './SidebarCategory.scss'; | ||
import { messages } from './SidebarCategory.messages'; | ||
import type { Intl } from '../../types/i18nTypes'; | ||
import { TOOLTIP_DELAY } from '../../config/timingConfig'; | ||
|
||
type Props = { | ||
category: SidebarCategoryInfo; | ||
intl: Intl; | ||
isActive: boolean; | ||
onClick: (...args: Array<any>) => any; | ||
content?: Node; | ||
content?: React.ReactNode; | ||
}; | ||
|
||
@observer | ||
class SidebarCategory extends Component<Props> { | ||
render() { | ||
const { category, isActive, onClick, content } = this.props; | ||
const { name, icon, route } = category; | ||
const className = camelCase(name); | ||
const componentStyles = classNames( | ||
styles.component, | ||
className, | ||
styles[className], | ||
{ | ||
[styles.active]: isActive, | ||
} | ||
); | ||
const iconClassName = classNames(styles.icon, styles[`${className}Icon`]); | ||
return ( | ||
function SidebarCategory({ | ||
category, | ||
intl, | ||
isActive, | ||
onClick, | ||
content, | ||
}: Props) { | ||
const { name, icon, route, tooltipTextId } = category; | ||
const className = camelCase(name); | ||
const componentStyles = classNames( | ||
styles.component, | ||
className, | ||
styles[className], | ||
isActive && styles.active | ||
); | ||
const iconClassName = classNames(styles.icon, styles[`${className}Icon`]); | ||
return ( | ||
<PopOver | ||
delay={TOOLTIP_DELAY} | ||
offset={[0, -20]} | ||
content={tooltipTextId && intl.formatMessage(messages[tooltipTextId])} | ||
placement="bottom" | ||
> | ||
<button className={componentStyles} onClick={() => onClick(route)}> | ||
<SVGInline svg={icon} className={iconClassName} /> | ||
{content} | ||
</button> | ||
); | ||
} | ||
</PopOver> | ||
); | ||
} | ||
|
||
export default SidebarCategory; | ||
export default injectIntl(observer(SidebarCategory)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
source/renderer/app/components/staking/stake-pools/StakePoolsTableHeader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React from 'react'; | ||
import { observer } from 'mobx-react'; | ||
import classNames from 'classnames'; | ||
import { HeaderGroup } from 'react-table'; | ||
import { StakePoolsTableHeaderCell } from './StakePoolsTableHeaderCell'; | ||
import StakePool from '../../../domains/StakePool'; | ||
import { | ||
useInViewPort, | ||
StakePoolsOrder, | ||
StakePoolSortableProps, | ||
} from './hooks'; | ||
import styles from './StakePoolsTable.scss'; | ||
|
||
type Props = { | ||
headerGroups: HeaderGroup<StakePool>[]; | ||
stakePoolsOrder: StakePoolsOrder; | ||
stakePoolsSortBy: StakePoolSortableProps; | ||
onHandleSort: (name: string) => void; | ||
onTableHeaderMouseEnter: () => void; | ||
onTableHeaderMouseLeave: () => void; | ||
}; | ||
|
||
export const Component = ({ | ||
stakePoolsSortBy, | ||
stakePoolsOrder, | ||
headerGroups, | ||
onHandleSort, | ||
onTableHeaderMouseEnter, | ||
onTableHeaderMouseLeave, | ||
}: Props) => { | ||
const { setTargetRef, isInViewport } = useInViewPort(); | ||
|
||
return ( | ||
<> | ||
<div ref={setTargetRef} /> | ||
<div | ||
className={classNames( | ||
styles.thead, | ||
!isInViewport && styles.stickyHeader | ||
)} | ||
onMouseEnter={onTableHeaderMouseEnter} | ||
onMouseLeave={onTableHeaderMouseLeave} | ||
> | ||
{headerGroups.map((headerGroup) => ( | ||
/* eslint-disable-next-line react/jsx-key */ | ||
<div {...headerGroup.getHeaderGroupProps()} className={styles.tr}> | ||
{headerGroup.headers.map((column) => ( | ||
<StakePoolsTableHeaderCell | ||
{...column.getHeaderProps({ | ||
style: { width: undefined }, | ||
})} | ||
stakePoolsSortBy={stakePoolsSortBy} | ||
stakePoolsOrder={stakePoolsOrder} | ||
onHandleSort={onHandleSort} | ||
name={column.id} | ||
key={column.id} | ||
> | ||
{column.render('Header')} | ||
</StakePoolsTableHeaderCell> | ||
))} | ||
</div> | ||
))} | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export const StakePoolsTableHeader = observer(Component); |
1 change: 1 addition & 0 deletions
1
source/renderer/app/components/staking/stake-pools/hooks/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
source/renderer/app/components/staking/stake-pools/hooks/useInViewPort.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useRef, useState, useCallback } from 'react'; | ||
|
||
export const useInViewPort = () => { | ||
const [isInViewport, setIsInViewport] = useState(true); | ||
const targetRef = useRef(null); | ||
const observerRef = useRef( | ||
new IntersectionObserver((entries) => { | ||
entries.forEach((entry) => { | ||
setIsInViewport(entry.isIntersecting); | ||
}); | ||
}) | ||
); | ||
|
||
// React will call the ref callback twice. Once when the component mounts and again when it unmounts. | ||
// https://reactjs.org/docs/hooks-faq.html#how-can-i-measure-a-dom-node | ||
const setTargetRef = useCallback((target: HTMLElement) => { | ||
if (targetRef.current) { | ||
observerRef.current.unobserve(targetRef.current); | ||
} | ||
|
||
if (target) { | ||
observerRef.current.observe(target); | ||
} | ||
|
||
targetRef.current = target; | ||
}, []); | ||
|
||
return { isInViewport, setTargetRef }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.