@gm-pc/frame 1.25.1-beta.1 → 1.26.0-beta.1
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/package.json +3 -3
- package/src/component/breadcrumb.tsx +119 -119
- package/src/component/framework.tsx +102 -102
- package/src/component/full_tabs.tsx +104 -104
- package/src/component/info.tsx +45 -45
- package/src/component/left.tsx +15 -15
- package/src/component/right_top.tsx +31 -31
- package/src/index.less +181 -181
- package/src/index.ts +13 -13
- package/src/mobile.less +38 -38
- package/src/print.less +28 -28
- package/src/stories.tsx +162 -162
- package/src/svg/more.svg +10 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gm-pc/frame",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.26.0-beta.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "liyatang <liyatang@qq.com>",
|
|
6
6
|
"homepage": "https://github.com/gmfe/gm-pc#readme",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@gm-common/tool": "^2.10.0",
|
|
26
|
-
"@gm-pc/react": "^1.
|
|
26
|
+
"@gm-pc/react": "^1.26.0-beta.1",
|
|
27
27
|
"classnames": "^2.2.5",
|
|
28
28
|
"lodash": "^4.17.19"
|
|
29
29
|
},
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"react": "^16.14.0",
|
|
32
32
|
"react-dom": "^16.14.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "82ab129147eec88f029e08f984a261849de3d9a7"
|
|
35
35
|
}
|
|
@@ -1,119 +1,119 @@
|
|
|
1
|
-
import React, { FC } from 'react'
|
|
2
|
-
import _ from 'lodash'
|
|
3
|
-
import { is } from '@gm-common/tool'
|
|
4
|
-
import { NavData } from '@gm-pc/react'
|
|
5
|
-
|
|
6
|
-
type NavConfig = NavData
|
|
7
|
-
|
|
8
|
-
interface BreadCrumbsItem {
|
|
9
|
-
name: string
|
|
10
|
-
link?: string
|
|
11
|
-
sub?: BreadCrumbsItem[]
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type BreadCrumb = string[] | BreadCrumbsItem[]
|
|
15
|
-
|
|
16
|
-
interface BreadcrumbProps {
|
|
17
|
-
breadcrumbs: BreadCrumb
|
|
18
|
-
pathname: string
|
|
19
|
-
navConfig: NavConfig[]
|
|
20
|
-
onSelect(selected: BreadCrumbsItem): void
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const nav2BreadCrumb = (
|
|
24
|
-
breadcrumbs: BreadCrumb,
|
|
25
|
-
pathname: string,
|
|
26
|
-
navConfig: NavConfig[]
|
|
27
|
-
): BreadCrumbsItem[] => {
|
|
28
|
-
const result: BreadCrumbsItem[] = []
|
|
29
|
-
|
|
30
|
-
_.find(navConfig, (one) => {
|
|
31
|
-
_.find(one.sub, (two) => {
|
|
32
|
-
return _.find(two.sub, (three) => {
|
|
33
|
-
if (pathname.includes(three.link)) {
|
|
34
|
-
result.push(one)
|
|
35
|
-
result.push(two as any)
|
|
36
|
-
result.push(three as any)
|
|
37
|
-
|
|
38
|
-
return true
|
|
39
|
-
}
|
|
40
|
-
return false
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
_.forEach(breadcrumbs, (v) => {
|
|
46
|
-
if (_.isString(v)) {
|
|
47
|
-
result.push({ name: v })
|
|
48
|
-
} else {
|
|
49
|
-
// @ts-ignore
|
|
50
|
-
result.push({ name: v.name, link: v.link || pathname })
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
return result
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const Breadcrumb: FC<BreadcrumbProps> = ({
|
|
58
|
-
breadcrumbs,
|
|
59
|
-
pathname,
|
|
60
|
-
navConfig,
|
|
61
|
-
onSelect,
|
|
62
|
-
}) => {
|
|
63
|
-
const data = nav2BreadCrumb(breadcrumbs, pathname, navConfig)
|
|
64
|
-
|
|
65
|
-
if (!data || data.length === 0) {
|
|
66
|
-
return <div className='gm-framework-breadcrumb-default' />
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const last = data[data.length - 1]
|
|
70
|
-
|
|
71
|
-
const arr = (
|
|
72
|
-
<>
|
|
73
|
-
{_.map(data.slice(0, -1), (v, i) => (
|
|
74
|
-
<a
|
|
75
|
-
key={i + '_' + v.link}
|
|
76
|
-
href={v.link}
|
|
77
|
-
onClick={(e) => {
|
|
78
|
-
e.preventDefault()
|
|
79
|
-
if (i === 0) {
|
|
80
|
-
// @ts-ignore
|
|
81
|
-
onSelect(data[0].sub[0].sub[0])
|
|
82
|
-
} else if (i === 1) {
|
|
83
|
-
// @ts-ignore
|
|
84
|
-
onSelect(data[1].sub[0])
|
|
85
|
-
} else if (i === 2) {
|
|
86
|
-
onSelect(data[2])
|
|
87
|
-
} else {
|
|
88
|
-
onSelect(v)
|
|
89
|
-
}
|
|
90
|
-
}}
|
|
91
|
-
>
|
|
92
|
-
{v.name}
|
|
93
|
-
</a>
|
|
94
|
-
))}
|
|
95
|
-
</>
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
return (
|
|
99
|
-
<div className='gm-framework-breadcrumb-default'>
|
|
100
|
-
{!is.phone() && arr}
|
|
101
|
-
{last.link ? (
|
|
102
|
-
<a
|
|
103
|
-
href={last.link}
|
|
104
|
-
onClick={(event) => {
|
|
105
|
-
event.preventDefault()
|
|
106
|
-
onSelect(last)
|
|
107
|
-
}}
|
|
108
|
-
>
|
|
109
|
-
{last.name}
|
|
110
|
-
</a>
|
|
111
|
-
) : (
|
|
112
|
-
<span>{last.name}</span>
|
|
113
|
-
)}
|
|
114
|
-
</div>
|
|
115
|
-
)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export default Breadcrumb
|
|
119
|
-
export type { BreadcrumbProps, BreadCrumbsItem }
|
|
1
|
+
import React, { FC } from 'react'
|
|
2
|
+
import _ from 'lodash'
|
|
3
|
+
import { is } from '@gm-common/tool'
|
|
4
|
+
import { NavData } from '@gm-pc/react'
|
|
5
|
+
|
|
6
|
+
type NavConfig = NavData
|
|
7
|
+
|
|
8
|
+
interface BreadCrumbsItem {
|
|
9
|
+
name: string
|
|
10
|
+
link?: string
|
|
11
|
+
sub?: BreadCrumbsItem[]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type BreadCrumb = string[] | BreadCrumbsItem[]
|
|
15
|
+
|
|
16
|
+
interface BreadcrumbProps {
|
|
17
|
+
breadcrumbs: BreadCrumb
|
|
18
|
+
pathname: string
|
|
19
|
+
navConfig: NavConfig[]
|
|
20
|
+
onSelect(selected: BreadCrumbsItem): void
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const nav2BreadCrumb = (
|
|
24
|
+
breadcrumbs: BreadCrumb,
|
|
25
|
+
pathname: string,
|
|
26
|
+
navConfig: NavConfig[]
|
|
27
|
+
): BreadCrumbsItem[] => {
|
|
28
|
+
const result: BreadCrumbsItem[] = []
|
|
29
|
+
|
|
30
|
+
_.find(navConfig, (one) => {
|
|
31
|
+
_.find(one.sub, (two) => {
|
|
32
|
+
return _.find(two.sub, (three) => {
|
|
33
|
+
if (pathname.includes(three.link)) {
|
|
34
|
+
result.push(one)
|
|
35
|
+
result.push(two as any)
|
|
36
|
+
result.push(three as any)
|
|
37
|
+
|
|
38
|
+
return true
|
|
39
|
+
}
|
|
40
|
+
return false
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
_.forEach(breadcrumbs, (v) => {
|
|
46
|
+
if (_.isString(v)) {
|
|
47
|
+
result.push({ name: v })
|
|
48
|
+
} else {
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
result.push({ name: v.name, link: v.link || pathname })
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
return result
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const Breadcrumb: FC<BreadcrumbProps> = ({
|
|
58
|
+
breadcrumbs,
|
|
59
|
+
pathname,
|
|
60
|
+
navConfig,
|
|
61
|
+
onSelect,
|
|
62
|
+
}) => {
|
|
63
|
+
const data = nav2BreadCrumb(breadcrumbs, pathname, navConfig)
|
|
64
|
+
|
|
65
|
+
if (!data || data.length === 0) {
|
|
66
|
+
return <div className='gm-framework-breadcrumb-default' />
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const last = data[data.length - 1]
|
|
70
|
+
|
|
71
|
+
const arr = (
|
|
72
|
+
<>
|
|
73
|
+
{_.map(data.slice(0, -1), (v, i) => (
|
|
74
|
+
<a
|
|
75
|
+
key={i + '_' + v.link}
|
|
76
|
+
href={v.link}
|
|
77
|
+
onClick={(e) => {
|
|
78
|
+
e.preventDefault()
|
|
79
|
+
if (i === 0) {
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
onSelect(data[0].sub[0].sub[0])
|
|
82
|
+
} else if (i === 1) {
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
onSelect(data[1].sub[0])
|
|
85
|
+
} else if (i === 2) {
|
|
86
|
+
onSelect(data[2])
|
|
87
|
+
} else {
|
|
88
|
+
onSelect(v)
|
|
89
|
+
}
|
|
90
|
+
}}
|
|
91
|
+
>
|
|
92
|
+
{v.name}
|
|
93
|
+
</a>
|
|
94
|
+
))}
|
|
95
|
+
</>
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<div className='gm-framework-breadcrumb-default'>
|
|
100
|
+
{!is.phone() && arr}
|
|
101
|
+
{last.link ? (
|
|
102
|
+
<a
|
|
103
|
+
href={last.link}
|
|
104
|
+
onClick={(event) => {
|
|
105
|
+
event.preventDefault()
|
|
106
|
+
onSelect(last)
|
|
107
|
+
}}
|
|
108
|
+
>
|
|
109
|
+
{last.name}
|
|
110
|
+
</a>
|
|
111
|
+
) : (
|
|
112
|
+
<span>{last.name}</span>
|
|
113
|
+
)}
|
|
114
|
+
</div>
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export default Breadcrumb
|
|
119
|
+
export type { BreadcrumbProps, BreadCrumbsItem }
|
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import React, { useEffect, FC, ReactNode } from 'react'
|
|
2
|
-
import { Flex, EVENT_TYPE } from '@gm-pc/react'
|
|
3
|
-
import classNames from 'classnames'
|
|
4
|
-
import _ from 'lodash'
|
|
5
|
-
|
|
6
|
-
interface FrameworkProps {
|
|
7
|
-
menu: ReactNode
|
|
8
|
-
rightTop: ReactNode
|
|
9
|
-
scrollTop?: void
|
|
10
|
-
showMobileMenu?: boolean
|
|
11
|
-
isFullScreen?: boolean
|
|
12
|
-
children: ReactNode
|
|
13
|
-
className?: string
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface FrameworkStatic {
|
|
17
|
-
scrollTop(): void
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function useWindowEventListener(
|
|
21
|
-
type: string,
|
|
22
|
-
listener: EventListenerOrEventListenerObject
|
|
23
|
-
) {
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
window.addEventListener(type, listener)
|
|
26
|
-
|
|
27
|
-
return () => {
|
|
28
|
-
window.removeEventListener(type, listener)
|
|
29
|
-
}
|
|
30
|
-
}, [type, listener])
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const Framework: FC<FrameworkProps> & FrameworkStatic = ({
|
|
34
|
-
showMobileMenu,
|
|
35
|
-
isFullScreen,
|
|
36
|
-
menu,
|
|
37
|
-
rightTop,
|
|
38
|
-
children,
|
|
39
|
-
className,
|
|
40
|
-
}) => {
|
|
41
|
-
const addOverflowClass = () => {
|
|
42
|
-
let flag: any = window.document.body.dataset.overflowFlag || 0
|
|
43
|
-
flag++
|
|
44
|
-
window.document.body.dataset.overflowFlag = flag
|
|
45
|
-
|
|
46
|
-
if (flag === 1) {
|
|
47
|
-
window.document.body.classList.add('gm-overflow-hidden')
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const removeOverflowClass = () => {
|
|
52
|
-
let flag: any = window.document.body.dataset.overflowFlag || 0
|
|
53
|
-
flag--
|
|
54
|
-
window.document.body.dataset.overflowFlag = flag
|
|
55
|
-
if (flag === 0) {
|
|
56
|
-
window.document.body.classList.remove('gm-overflow-hidden')
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const doScroll = _.throttle(() => {
|
|
61
|
-
window.dispatchEvent(new window.CustomEvent(EVENT_TYPE.BROWSER_SCROLL))
|
|
62
|
-
}, 200)
|
|
63
|
-
|
|
64
|
-
useWindowEventListener(EVENT_TYPE.MODAL_SHOW, addOverflowClass)
|
|
65
|
-
useWindowEventListener(EVENT_TYPE.MODAL_HIDE, removeOverflowClass)
|
|
66
|
-
useWindowEventListener('scroll', doScroll)
|
|
67
|
-
|
|
68
|
-
return (
|
|
69
|
-
<div
|
|
70
|
-
className={classNames(
|
|
71
|
-
'gm-framework',
|
|
72
|
-
{
|
|
73
|
-
'gm-framework-mobile-menu': showMobileMenu,
|
|
74
|
-
},
|
|
75
|
-
className
|
|
76
|
-
)}
|
|
77
|
-
>
|
|
78
|
-
<div className='gm-framework-inner'>
|
|
79
|
-
{isFullScreen ? (
|
|
80
|
-
children
|
|
81
|
-
) : (
|
|
82
|
-
<div className='gm-framework-full-height'>
|
|
83
|
-
<Flex className='gm-framework-container'>
|
|
84
|
-
{menu && <div className='gm-framework-left'>{menu}</div>}
|
|
85
|
-
<Flex flex column className='gm-framework-right'>
|
|
86
|
-
{rightTop && <div className='gm-framework-right-top'>{rightTop}</div>}
|
|
87
|
-
<div className='gm-framework-content'>{children}</div>
|
|
88
|
-
</Flex>
|
|
89
|
-
</Flex>
|
|
90
|
-
</div>
|
|
91
|
-
)}
|
|
92
|
-
</div>
|
|
93
|
-
</div>
|
|
94
|
-
)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
Framework.scrollTop = () => {
|
|
98
|
-
window.scroll(0, 0)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export default Framework
|
|
102
|
-
export type { FrameworkProps, FrameworkStatic }
|
|
1
|
+
import React, { useEffect, FC, ReactNode } from 'react'
|
|
2
|
+
import { Flex, EVENT_TYPE } from '@gm-pc/react'
|
|
3
|
+
import classNames from 'classnames'
|
|
4
|
+
import _ from 'lodash'
|
|
5
|
+
|
|
6
|
+
interface FrameworkProps {
|
|
7
|
+
menu: ReactNode
|
|
8
|
+
rightTop: ReactNode
|
|
9
|
+
scrollTop?: void
|
|
10
|
+
showMobileMenu?: boolean
|
|
11
|
+
isFullScreen?: boolean
|
|
12
|
+
children: ReactNode
|
|
13
|
+
className?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface FrameworkStatic {
|
|
17
|
+
scrollTop(): void
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function useWindowEventListener(
|
|
21
|
+
type: string,
|
|
22
|
+
listener: EventListenerOrEventListenerObject
|
|
23
|
+
) {
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
window.addEventListener(type, listener)
|
|
26
|
+
|
|
27
|
+
return () => {
|
|
28
|
+
window.removeEventListener(type, listener)
|
|
29
|
+
}
|
|
30
|
+
}, [type, listener])
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const Framework: FC<FrameworkProps> & FrameworkStatic = ({
|
|
34
|
+
showMobileMenu,
|
|
35
|
+
isFullScreen,
|
|
36
|
+
menu,
|
|
37
|
+
rightTop,
|
|
38
|
+
children,
|
|
39
|
+
className,
|
|
40
|
+
}) => {
|
|
41
|
+
const addOverflowClass = () => {
|
|
42
|
+
let flag: any = window.document.body.dataset.overflowFlag || 0
|
|
43
|
+
flag++
|
|
44
|
+
window.document.body.dataset.overflowFlag = flag
|
|
45
|
+
|
|
46
|
+
if (flag === 1) {
|
|
47
|
+
window.document.body.classList.add('gm-overflow-hidden')
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const removeOverflowClass = () => {
|
|
52
|
+
let flag: any = window.document.body.dataset.overflowFlag || 0
|
|
53
|
+
flag--
|
|
54
|
+
window.document.body.dataset.overflowFlag = flag
|
|
55
|
+
if (flag === 0) {
|
|
56
|
+
window.document.body.classList.remove('gm-overflow-hidden')
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const doScroll = _.throttle(() => {
|
|
61
|
+
window.dispatchEvent(new window.CustomEvent(EVENT_TYPE.BROWSER_SCROLL))
|
|
62
|
+
}, 200)
|
|
63
|
+
|
|
64
|
+
useWindowEventListener(EVENT_TYPE.MODAL_SHOW, addOverflowClass)
|
|
65
|
+
useWindowEventListener(EVENT_TYPE.MODAL_HIDE, removeOverflowClass)
|
|
66
|
+
useWindowEventListener('scroll', doScroll)
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div
|
|
70
|
+
className={classNames(
|
|
71
|
+
'gm-framework',
|
|
72
|
+
{
|
|
73
|
+
'gm-framework-mobile-menu': showMobileMenu,
|
|
74
|
+
},
|
|
75
|
+
className
|
|
76
|
+
)}
|
|
77
|
+
>
|
|
78
|
+
<div className='gm-framework-inner'>
|
|
79
|
+
{isFullScreen ? (
|
|
80
|
+
children
|
|
81
|
+
) : (
|
|
82
|
+
<div className='gm-framework-full-height'>
|
|
83
|
+
<Flex className='gm-framework-container'>
|
|
84
|
+
{menu && <div className='gm-framework-left'>{menu}</div>}
|
|
85
|
+
<Flex flex column className='gm-framework-right'>
|
|
86
|
+
{rightTop && <div className='gm-framework-right-top'>{rightTop}</div>}
|
|
87
|
+
<div className='gm-framework-content'>{children}</div>
|
|
88
|
+
</Flex>
|
|
89
|
+
</Flex>
|
|
90
|
+
</div>
|
|
91
|
+
)}
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
Framework.scrollTop = () => {
|
|
98
|
+
window.scroll(0, 0)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export default Framework
|
|
102
|
+
export type { FrameworkProps, FrameworkStatic }
|
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
import React, { FC, useState, CSSProperties, ReactNode } from 'react'
|
|
2
|
-
import classNames from 'classnames'
|
|
3
|
-
import { Flex, FlexProps } from '@gm-pc/react'
|
|
4
|
-
import _ from 'lodash'
|
|
5
|
-
|
|
6
|
-
interface FullTabsItem {
|
|
7
|
-
text: string
|
|
8
|
-
value: string
|
|
9
|
-
children: ReactNode
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface FullTabsProps extends Omit<FlexProps, 'onChange'> {
|
|
13
|
-
tabs: FullTabsItem[]
|
|
14
|
-
defaultActive?: string
|
|
15
|
-
active?: string
|
|
16
|
-
onChange?(value: string): void
|
|
17
|
-
keep?: boolean
|
|
18
|
-
className?: string
|
|
19
|
-
column?: boolean
|
|
20
|
-
/** 使用 row,需要手动将 column 设置为false, Tip: 因为 column 默认为 true,column 会于 row 冲突 */
|
|
21
|
-
row?: boolean
|
|
22
|
-
style?: CSSProperties
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* 请使用Tabs,配置full
|
|
26
|
-
* @deprecated
|
|
27
|
-
*/
|
|
28
|
-
const FullTabs: FC<FullTabsProps> = ({
|
|
29
|
-
tabs,
|
|
30
|
-
active,
|
|
31
|
-
defaultActive,
|
|
32
|
-
keep,
|
|
33
|
-
onChange,
|
|
34
|
-
className,
|
|
35
|
-
column = true,
|
|
36
|
-
...rest
|
|
37
|
-
}) => {
|
|
38
|
-
if (active !== undefined && defaultActive !== undefined) {
|
|
39
|
-
console.warn('prop `active` and prop `defaultActive` can not exist at the same time!')
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (active !== undefined && !onChange) {
|
|
43
|
-
console.warn('prop `active` `onChange` must exist at the same time!')
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const [selected, setSelected] = useState(defaultActive || active)
|
|
47
|
-
|
|
48
|
-
const handleClick = (value: string) => {
|
|
49
|
-
setSelected(value)
|
|
50
|
-
onChange && onChange(value)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const tabsChildrenKeep = () => (
|
|
54
|
-
<>
|
|
55
|
-
{_.map(tabs, (tab: FullTabsItem) => (
|
|
56
|
-
<div
|
|
57
|
-
key={tab.value}
|
|
58
|
-
className={classNames('gm-framework-full-tabs-content-item', {
|
|
59
|
-
'gm-hidden': selected !== tab.value,
|
|
60
|
-
})}
|
|
61
|
-
>
|
|
62
|
-
{tab.children}
|
|
63
|
-
</div>
|
|
64
|
-
))}
|
|
65
|
-
</>
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
const tabsChildren = () => {
|
|
69
|
-
const item = _.find(tabs, (tab) => tab.value === selected)
|
|
70
|
-
return (
|
|
71
|
-
<div className='gm-framework-full-tabs-content-item'>{item && item.children}</div>
|
|
72
|
-
)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return (
|
|
76
|
-
<Flex
|
|
77
|
-
{...rest}
|
|
78
|
-
column={column}
|
|
79
|
-
className={classNames('gm-framework-full-tabs', className)}
|
|
80
|
-
>
|
|
81
|
-
<div className='gm-framework-full-tabs-head-fix'>
|
|
82
|
-
<Flex alignEnd className='gm-framework-full-tabs-head'>
|
|
83
|
-
{_.map(tabs, (tab) => (
|
|
84
|
-
<div
|
|
85
|
-
key={tab.value}
|
|
86
|
-
className={classNames('gm-framework-full-tabs-head-item', {
|
|
87
|
-
active: selected === tab.value,
|
|
88
|
-
})}
|
|
89
|
-
onClick={() => handleClick(tab.value)}
|
|
90
|
-
>
|
|
91
|
-
{tab.text}
|
|
92
|
-
</div>
|
|
93
|
-
))}
|
|
94
|
-
</Flex>
|
|
95
|
-
</div>
|
|
96
|
-
<Flex flex column className='gm-framework-full-tabs-content'>
|
|
97
|
-
{keep ? tabsChildrenKeep() : tabsChildren()}
|
|
98
|
-
</Flex>
|
|
99
|
-
</Flex>
|
|
100
|
-
)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export default FullTabs
|
|
104
|
-
export type { FullTabsProps, FullTabsItem }
|
|
1
|
+
import React, { FC, useState, CSSProperties, ReactNode } from 'react'
|
|
2
|
+
import classNames from 'classnames'
|
|
3
|
+
import { Flex, FlexProps } from '@gm-pc/react'
|
|
4
|
+
import _ from 'lodash'
|
|
5
|
+
|
|
6
|
+
interface FullTabsItem {
|
|
7
|
+
text: string
|
|
8
|
+
value: string
|
|
9
|
+
children: ReactNode
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface FullTabsProps extends Omit<FlexProps, 'onChange'> {
|
|
13
|
+
tabs: FullTabsItem[]
|
|
14
|
+
defaultActive?: string
|
|
15
|
+
active?: string
|
|
16
|
+
onChange?(value: string): void
|
|
17
|
+
keep?: boolean
|
|
18
|
+
className?: string
|
|
19
|
+
column?: boolean
|
|
20
|
+
/** 使用 row,需要手动将 column 设置为false, Tip: 因为 column 默认为 true,column 会于 row 冲突 */
|
|
21
|
+
row?: boolean
|
|
22
|
+
style?: CSSProperties
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 请使用Tabs,配置full
|
|
26
|
+
* @deprecated
|
|
27
|
+
*/
|
|
28
|
+
const FullTabs: FC<FullTabsProps> = ({
|
|
29
|
+
tabs,
|
|
30
|
+
active,
|
|
31
|
+
defaultActive,
|
|
32
|
+
keep,
|
|
33
|
+
onChange,
|
|
34
|
+
className,
|
|
35
|
+
column = true,
|
|
36
|
+
...rest
|
|
37
|
+
}) => {
|
|
38
|
+
if (active !== undefined && defaultActive !== undefined) {
|
|
39
|
+
console.warn('prop `active` and prop `defaultActive` can not exist at the same time!')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (active !== undefined && !onChange) {
|
|
43
|
+
console.warn('prop `active` `onChange` must exist at the same time!')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const [selected, setSelected] = useState(defaultActive || active)
|
|
47
|
+
|
|
48
|
+
const handleClick = (value: string) => {
|
|
49
|
+
setSelected(value)
|
|
50
|
+
onChange && onChange(value)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const tabsChildrenKeep = () => (
|
|
54
|
+
<>
|
|
55
|
+
{_.map(tabs, (tab: FullTabsItem) => (
|
|
56
|
+
<div
|
|
57
|
+
key={tab.value}
|
|
58
|
+
className={classNames('gm-framework-full-tabs-content-item', {
|
|
59
|
+
'gm-hidden': selected !== tab.value,
|
|
60
|
+
})}
|
|
61
|
+
>
|
|
62
|
+
{tab.children}
|
|
63
|
+
</div>
|
|
64
|
+
))}
|
|
65
|
+
</>
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
const tabsChildren = () => {
|
|
69
|
+
const item = _.find(tabs, (tab) => tab.value === selected)
|
|
70
|
+
return (
|
|
71
|
+
<div className='gm-framework-full-tabs-content-item'>{item && item.children}</div>
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<Flex
|
|
77
|
+
{...rest}
|
|
78
|
+
column={column}
|
|
79
|
+
className={classNames('gm-framework-full-tabs', className)}
|
|
80
|
+
>
|
|
81
|
+
<div className='gm-framework-full-tabs-head-fix'>
|
|
82
|
+
<Flex alignEnd className='gm-framework-full-tabs-head'>
|
|
83
|
+
{_.map(tabs, (tab) => (
|
|
84
|
+
<div
|
|
85
|
+
key={tab.value}
|
|
86
|
+
className={classNames('gm-framework-full-tabs-head-item', {
|
|
87
|
+
active: selected === tab.value,
|
|
88
|
+
})}
|
|
89
|
+
onClick={() => handleClick(tab.value)}
|
|
90
|
+
>
|
|
91
|
+
{tab.text}
|
|
92
|
+
</div>
|
|
93
|
+
))}
|
|
94
|
+
</Flex>
|
|
95
|
+
</div>
|
|
96
|
+
<Flex flex column className='gm-framework-full-tabs-content'>
|
|
97
|
+
{keep ? tabsChildrenKeep() : tabsChildren()}
|
|
98
|
+
</Flex>
|
|
99
|
+
</Flex>
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export default FullTabs
|
|
104
|
+
export type { FullTabsProps, FullTabsItem }
|