Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react'
import React, { FC } from 'react'

import { ReadedLabel } from './styles'

const ReadLabel = ({ entry, accountInfo, topOffset }) => {
import type { TProps } from './index'

const ReadLabel: FC<TProps> = ({ entry, accountInfo, topOffset = '20px' }) => {
const { viewerHasViewed } = entry
const {
isLogin,
Expand Down
43 changes: 0 additions & 43 deletions src/components/ArticleItemPrefixLabel/index.js

This file was deleted.

37 changes: 37 additions & 0 deletions src/components/ArticleItemPrefixLabel/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
*
* ArticleItemPrefixLabel
*
*/

import React, { FC } from 'react'

import type { TAccount } from '@/spec'
import { buildLog } from '@/utils'
import { PinIcon } from './styles'
import ReadLabel from './ReadLabel'

/* eslint-disable-next-line */
const log = buildLog('c:ArticleItemPrefixLabel:index')

export type TProps = {
accountInfo: TAccount
topOffset?: string
entry: {
viewerHasViewed?: boolean
isPinned?: boolean
}
}
const ArticleItemPrefixLabel: FC<TProps> = ({
entry,
accountInfo,
topOffset = '22px',
}) => {
if (entry.isPinned) return <PinIcon top={topOffset} />

return (
<ReadLabel entry={entry} accountInfo={accountInfo} topOffset={topOffset} />
)
}

export default React.memo(ArticleItemPrefixLabel)
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*
*/

import React, { useRef, useState, useCallback } from 'react'
import T from 'prop-types'
import React, { FC, useRef, useState, useCallback } from 'react'

import type { TSIZE_SM, TTabItem } from '@/spec'
import { buildLog, isString } from '@/utils'
import { SIZE } from '@/constant'

Expand All @@ -20,12 +20,25 @@ const log = buildLog('c:Tabs:index')
const temItems = [
{
title: '帖子',
// icon: `${ICON_CMD}/navi/fire.svg`,
raw: 'posts',
localIcon: 'settings',
},
]

const Tabs = ({ size, onChange, items, activeKey }) => {
type TProps = {
items?: TTabItem[]
onChange: () => void
activeKey?: string
size: TSIZE_SM
slipHeight: '1px' | '2px'
}

const Tabs: FC<TProps> = ({
size = SIZE.MEDIUM,
onChange = log,
items = temItems,
activeKey = '',
}) => {
const [tabWidthList, setTabWidthList] = useState([])

const navRef = useRef(null)
Expand Down Expand Up @@ -69,29 +82,4 @@ const Tabs = ({ size, onChange, items, activeKey }) => {
)
}

Tabs.propTypes = {
items: T.oneOfType([
T.arrayOf(T.string),
T.arrayOf(
T.shape({
title: T.string,
raw: T.string,
alias: T.string,
icon: T.oneOfType([T.string, T.node]),
localIcon: T.string,
}),
),
]),
onChange: T.func,
activeKey: T.string,
size: T.oneOf([SIZE.MEDIUM, SIZE.SMALL]),
}

Tabs.defaultProps = {
items: temItems,
onChange: log,
activeKey: '',
size: SIZE.MEDIUM,
}

export default React.memo(Tabs)
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*
*/

import React, { useEffect, useRef, useState, useCallback } from 'react'
import T from 'prop-types'
import React, { FC, useEffect, useRef, useState, useCallback } from 'react'
import { isEmpty, findIndex } from 'ramda'

import type { TSIZE_SM, TTabItem } from '@/spec'
import { useDevice } from '@/hooks'
import { SIZE } from '@/constant'
import { buildLog, isString } from '@/utils'
Expand All @@ -23,6 +23,7 @@ const log = buildLog('c:Tabs:index')
const temItems = [
{
title: '帖子',
raw: 'posts',
// icon: `${ICON_CMD}/navi/fire.svg`,
localIcon: 'settings',
},
Expand All @@ -36,18 +37,33 @@ const temItems = [
* @param {string} activeKey
* @returns number
*/
const getDefaultActiveTabIndex = (items, activeKey) => {
const getDefaultActiveTabIndex = (
items: TTabItem[],
activeKey: string,
): number => {
if (isEmpty(activeKey)) return 0
const index = findIndex((item) => {
return isString(item)
? activeKey === item
: activeKey === (item.raw || item.title)
return activeKey === (item.raw || item.title)
}, items)

return index >= 0 ? index : 0
}

const Tabs = ({ size, onChange, items, activeKey, slipHeight }) => {
type TProps = {
items?: TTabItem[]
onChange: () => void
activeKey?: string
size: TSIZE_SM
slipHeight: '1px' | '2px'
}

const Tabs: FC<TProps> = ({
size = SIZE.MEDIUM,
onChange = log,
items = temItems,
activeKey = '',
slipHeight = '2px',
}) => {
const { isMobile } = useDevice()

const defaultActiveTabIndex = getDefaultActiveTabIndex(items, activeKey)
Expand Down Expand Up @@ -118,39 +134,12 @@ const Tabs = ({ size, onChange, items, activeKey, slipHeight }) => {
slipHeight={slipHeight}
>
<RealBar
width={`${size === 'default' ? slipWidth : slipWidth - 6}px`}
width={`${size === SIZE.MEDIUM ? slipWidth : slipWidth - 6}px`}
/>
</SlipBar>
</Nav>
</Wrapper>
)
}

Tabs.propTypes = {
items: T.oneOfType([
T.arrayOf(T.string),
T.arrayOf(
T.shape({
title: T.string,
raw: T.string,
alias: T.string,
icon: T.oneOfType([T.string, T.node]),
localIcon: T.string,
}),
),
]),
onChange: T.func,
activeKey: T.string,
size: T.oneOf([SIZE.MEDIUM, SIZE.SMALL]),
slipHeight: T.oneOf(['1px', '2px']),
}

Tabs.defaultProps = {
items: temItems,
onChange: log,
activeKey: '',
size: SIZE.MEDIUM,
slipHeight: '2px',
}

export default React.memo(Tabs)
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*
*/

import React, { useCallback } from 'react'
import T from 'prop-types'
import React, { FC, useCallback } from 'react'

import type { TSIZE_SM, TTabItem } from '@/spec'
import { buildLog, isString } from '@/utils'
import { SIZE } from '@/constant'

Expand All @@ -23,7 +23,20 @@ const temItems = [
},
]

const Tabs = ({ size, onChange, items, activeKey }) => {
type TProps = {
items?: TTabItem[]
onChange: () => void
activeKey?: string
size: TSIZE_SM
slipHeight: '1px' | '2px'
}

const Tabs: FC<TProps> = ({
size = SIZE.MEDIUM,
onChange = log,
items = temItems,
activeKey = '',
}) => {
const handleItemClick = useCallback(
(item) => {
onChange(isString(item) ? item : item.raw || item.title)
Expand All @@ -37,7 +50,6 @@ const Tabs = ({ size, onChange, items, activeKey }) => {
<TabItem
key={isString(item) ? item : item.raw || item.title}
active={activeKey === item.raw}
size={size}
onClick={() => handleItemClick(item)}
>
{item.title}
Expand All @@ -47,29 +59,4 @@ const Tabs = ({ size, onChange, items, activeKey }) => {
)
}

Tabs.propTypes = {
items: T.oneOfType([
T.arrayOf(T.string),
T.arrayOf(
T.shape({
title: T.string,
raw: T.string,
alias: T.string,
icon: T.oneOfType([T.string, T.node]),
localIcon: T.string,
}),
),
]),
onChange: T.func,
activeKey: T.string,
size: T.oneOf([SIZE.MEDIUM, SIZE.SMALL]),
}

Tabs.defaultProps = {
items: temItems,
onChange: log,
activeKey: '',
size: SIZE.MEDIUM,
}

export default React.memo(Tabs)
6 changes: 6 additions & 0 deletions src/components/Switcher/Tabs/LocalIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ import {
TabFavoritesIcon,
} from '../styles/tabs/local_icon'

// type TProps = {
// raw: string
// active: boolean
// small?: boolean
// }

const TabIcon = ({ raw, active, small }) => {
switch (raw) {
case 'tech':
Expand Down
Loading