Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(improvements) Navigation switcher #824

Merged
merged 6 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions src/ui/NavSwitcher/NavSwitcher.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
import React from 'react'
import React, { memo } from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'
import _map from 'lodash/map'
import { isEqual } from '@bitfinex/lib-js-util-base'

import { tracker } from 'utils/trackers'
import { propTypes, defaultProps } from './NavSwitcher.props'

const NavSwitcher = (props) => {
const { items, onChange, value: activeItem } = props
const NavSwitcher = ({
items,
onChange,
value: activeItem,
}) => {
const handleClick = (itemValue) => {
tracker.trackEvent(itemValue, 'Tab')
onChange(itemValue)
}

return (
<div className='nav-switcher'>
{items.map((item) => {
{_map(items, (item) => {
const { label, value: itemValue } = item
const itemClasses = classNames('nav-switcher-item', {
'nav-switcher-item--active': itemValue === activeItem,
'nav-switcher-item--active': isEqual(itemValue, activeItem),
})

return (
<span className={itemClasses} onClick={() => handleClick(itemValue)} key={itemValue}>
<span
key={itemValue}
className={itemClasses}
onClick={() => handleClick(itemValue)}
>
{label}
</span>
)
Expand All @@ -29,7 +38,13 @@ const NavSwitcher = (props) => {
)
}

NavSwitcher.propTypes = propTypes
NavSwitcher.defaultProps = defaultProps
NavSwitcher.propTypes = {
items: PropTypes.arrayOf(PropTypes.shape({
label: PropTypes.string,
value: PropTypes.string,
})).isRequired,
onChange: PropTypes.func.isRequired,
value: PropTypes.string.isRequired,
}

export default NavSwitcher
export default memo(NavSwitcher)
9 changes: 0 additions & 9 deletions src/ui/NavSwitcher/NavSwitcher.props.js

This file was deleted.

4 changes: 1 addition & 3 deletions src/ui/NavSwitcher/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import NavSwitcher from './NavSwitcher'

export default NavSwitcher
export { default } from './NavSwitcher'