diff --git a/src/components/ArticleItemPrefixLabel/ReadLabel.js b/src/components/ArticleItemPrefixLabel/ReadLabel.tsx similarity index 68% rename from src/components/ArticleItemPrefixLabel/ReadLabel.js rename to src/components/ArticleItemPrefixLabel/ReadLabel.tsx index 0f4b79b16..0df766185 100755 --- a/src/components/ArticleItemPrefixLabel/ReadLabel.js +++ b/src/components/ArticleItemPrefixLabel/ReadLabel.tsx @@ -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 = ({ entry, accountInfo, topOffset = '20px' }) => { const { viewerHasViewed } = entry const { isLogin, diff --git a/src/components/ArticleItemPrefixLabel/index.js b/src/components/ArticleItemPrefixLabel/index.js deleted file mode 100755 index 16d83a7da..000000000 --- a/src/components/ArticleItemPrefixLabel/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/* - * - * ArticleItemPrefixLabel - * - */ - -import React from 'react' -import T from 'prop-types' - -import { buildLog } from '@/utils' -import { PinIcon } from './styles' -import ReadLabel from './ReadLabel' - -/* eslint-disable-next-line */ -const log = buildLog('c:ArticleItemPrefixLabel:index') - -const ArticleItemPrefixLabel = ({ entry, accountInfo, topOffset }) => { - if (entry.pin) return - - return ( - - ) -} - -ArticleItemPrefixLabel.propTypes = { - accountInfo: T.shape({ - isLogin: T.bool, - customization: T.shape({ - markViewed: T.bool, - }), - }).isRequired, - entry: T.shape({ - viewerHasViewed: T.bool, - pin: T.bool, - }).isRequired, - topOffset: T.string, -} - -ArticleItemPrefixLabel.defaultProps = { - topOffset: '22px', -} - -export default React.memo(ArticleItemPrefixLabel) diff --git a/src/components/ArticleItemPrefixLabel/index.tsx b/src/components/ArticleItemPrefixLabel/index.tsx new file mode 100755 index 000000000..0fb5a9dbe --- /dev/null +++ b/src/components/ArticleItemPrefixLabel/index.tsx @@ -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 = ({ + entry, + accountInfo, + topOffset = '22px', +}) => { + if (entry.isPinned) return + + return ( + + ) +} + +export default React.memo(ArticleItemPrefixLabel) diff --git a/src/components/Switcher/Tabs/CardView.js b/src/components/Switcher/Tabs/CardView.tsx similarity index 69% rename from src/components/Switcher/Tabs/CardView.js rename to src/components/Switcher/Tabs/CardView.tsx index 817221e3e..713e69e9b 100644 --- a/src/components/Switcher/Tabs/CardView.js +++ b/src/components/Switcher/Tabs/CardView.tsx @@ -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' @@ -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 = ({ + size = SIZE.MEDIUM, + onChange = log, + items = temItems, + activeKey = '', +}) => { const [tabWidthList, setTabWidthList] = useState([]) const navRef = useRef(null) @@ -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) diff --git a/src/components/Switcher/Tabs/DesktopView.js b/src/components/Switcher/Tabs/DesktopView.tsx similarity index 76% rename from src/components/Switcher/Tabs/DesktopView.js rename to src/components/Switcher/Tabs/DesktopView.tsx index aa592aaa3..49bba8f05 100644 --- a/src/components/Switcher/Tabs/DesktopView.js +++ b/src/components/Switcher/Tabs/DesktopView.tsx @@ -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' @@ -23,6 +23,7 @@ const log = buildLog('c:Tabs:index') const temItems = [ { title: '帖子', + raw: 'posts', // icon: `${ICON_CMD}/navi/fire.svg`, localIcon: 'settings', }, @@ -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 = ({ + size = SIZE.MEDIUM, + onChange = log, + items = temItems, + activeKey = '', + slipHeight = '2px', +}) => { const { isMobile } = useDevice() const defaultActiveTabIndex = getDefaultActiveTabIndex(items, activeKey) @@ -118,7 +134,7 @@ const Tabs = ({ size, onChange, items, activeKey, slipHeight }) => { slipHeight={slipHeight} > @@ -126,31 +142,4 @@ const Tabs = ({ size, onChange, items, activeKey, slipHeight }) => { ) } -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) diff --git a/src/components/Switcher/Tabs/DrawerView.js b/src/components/Switcher/Tabs/DrawerView.tsx similarity index 58% rename from src/components/Switcher/Tabs/DrawerView.js rename to src/components/Switcher/Tabs/DrawerView.tsx index 1769a677a..ba24a4d47 100644 --- a/src/components/Switcher/Tabs/DrawerView.js +++ b/src/components/Switcher/Tabs/DrawerView.tsx @@ -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' @@ -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 = ({ + size = SIZE.MEDIUM, + onChange = log, + items = temItems, + activeKey = '', +}) => { const handleItemClick = useCallback( (item) => { onChange(isString(item) ? item : item.raw || item.title) @@ -37,7 +50,6 @@ const Tabs = ({ size, onChange, items, activeKey }) => { handleItemClick(item)} > {item.title} @@ -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) diff --git a/src/components/Switcher/Tabs/LocalIcon.js b/src/components/Switcher/Tabs/LocalIcon.js index 417cba87b..d58df3b3c 100644 --- a/src/components/Switcher/Tabs/LocalIcon.js +++ b/src/components/Switcher/Tabs/LocalIcon.js @@ -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': diff --git a/src/components/Switcher/Tabs/MobileView/ExpandView.js b/src/components/Switcher/Tabs/MobileView/ExpandView.tsx similarity index 72% rename from src/components/Switcher/Tabs/MobileView/ExpandView.js rename to src/components/Switcher/Tabs/MobileView/ExpandView.tsx index 49a56ee64..0688cb792 100644 --- a/src/components/Switcher/Tabs/MobileView/ExpandView.js +++ b/src/components/Switcher/Tabs/MobileView/ExpandView.tsx @@ -4,9 +4,9 @@ * */ -import React, { useEffect, useRef, useState, useCallback } from 'react' -import T from 'prop-types' +import React, { FC, useEffect, useRef, useState, useCallback } from 'react' +import type { TSIZE_SM, TTabItem } from '@/spec' import { ICON } from '@/config' import { SIZE } from '@/constant' import { useDevice } from '@/hooks' @@ -23,7 +23,21 @@ import { /* eslint-disable-next-line */ const log = buildLog('c:Tabs:index') -const MobileView = ({ size, onChange, items, activeKey, toggleExpand }) => { +type TProps = { + items: TTabItem[] + activeKey: string + size: TSIZE_SM + toggleExpand: () => void + onChange: () => void +} + +const MobileView: FC = ({ + size = SIZE.MEDIUM, + onChange = log, + items, + activeKey = '', + toggleExpand, +}) => { const { isMobile } = useDevice() const [tabWidthList, setTabWidthList] = useState([]) @@ -69,7 +83,7 @@ const MobileView = ({ size, onChange, items, activeKey, toggleExpand }) => {