Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jinfa-platform
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄庭坚
jinfa-platform
Commits
bc180b49
Commit
bc180b49
authored
Jul 05, 2021
by
XieZhiXiong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 添加 ButtonTabs Radio.Button 选项卡组件
parent
1bfe7271
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
174 additions
and
23 deletions
+174
-23
ButtonTabs.tsx
src/components/ButtonTabs/ButtonTabs.tsx
+69
-0
ButtonTabsItem.tsx
src/components/ButtonTabs/ButtonTabsItem.tsx
+31
-0
context.ts
src/components/ButtonTabs/context.ts
+16
-0
index.tsx
src/components/ButtonTabs/index.tsx
+19
-23
interface.ts
src/components/ButtonTabs/interface.ts
+39
-0
No files found.
src/components/ButtonTabs/ButtonTabs.tsx
0 → 100644
View file @
bc180b49
/*
* @Author: XieZhiXiong
* @Date: 2021-06-15 17:13:25
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-06-15 17:19:58
* @Description: Radio.Button 选项卡
*/
import
React
,
{
useEffect
,
useState
}
from
'react'
;
import
{
ButtonTabsProps
,
KeyType
}
from
'./interface'
;
import
{
ButtonTabsContextProvider
}
from
'./context'
;
import
ButtonSwitch
from
'../ButtonSwitch'
;
import
MellowCard
from
'../MellowCard'
;
const
ButtonTabs
:
React
.
FC
<
ButtonTabsProps
>
=
(
props
)
=>
{
const
{
options
=
[],
onChange
=
undefined
,
value
,
size
=
'small'
,
extra
,
defaultValue
,
children
,
}
=
props
;
const
initValue
=
'value'
in
props
?
props
.
value
:
defaultValue
;
const
[
switchValue
,
setSwitchValue
]
=
useState
<
KeyType
>
(
initValue
);
useEffect
(()
=>
{
if
(
'value'
in
props
)
{
setSwitchValue
(
value
);
}
},
[
value
]);
const
triggerChange
=
(
next
:
KeyType
)
=>
{
if
(
onChange
)
{
onChange
(
next
);
}
};
const
handleButtonSwitchChange
=
(
next
:
KeyType
)
=>
{
if
(
!
(
'value'
in
props
))
{
setSwitchValue
(
next
);
}
triggerChange
(
next
);
};
return
(
<
MellowCard
title=
{
extra
}
extra=
{
(
<
ButtonSwitch
options=
{
options
}
onChange=
{
handleButtonSwitchChange
}
value=
{
switchValue
}
size=
{
size
}
/>
)
}
>
<
ButtonTabsContextProvider
value=
{
{
current
:
switchValue
,
}
}
>
{
children
}
</
ButtonTabsContextProvider
>
</
MellowCard
>
);
};
export
default
ButtonTabs
;
src/components/ButtonTabs/ButtonTabsItem.tsx
0 → 100644
View file @
bc180b49
/*
* @Author: XieZhiXiong
* @Date: 2021-07-05 17:08:26
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-07-05 18:06:08
* @Description:
*/
import
React
from
'react'
;
import
{
ButtonTabsItemProps
}
from
'./interface'
;
import
ButtonTabsContext
from
'./context'
;
const
ButtonTabsItem
:
React
.
FC
<
ButtonTabsItemProps
>
=
(
props
)
=>
{
const
{
activeKey
,
children
,
style
,
...
rest
}
=
props
;
const
context
=
React
.
useContext
(
ButtonTabsContext
);
return
(
<
div
{
...
rest
}
key=
{
activeKey
}
style=
{
{
...
style
,
display
:
context
.
current
===
activeKey
?
'block'
:
'none'
,
}
}
>
{
children
}
</
div
>
);
};
export
default
ButtonTabsItem
;
src/components/ButtonTabs/context.ts
0 → 100644
View file @
bc180b49
/*
* @Author: XieZhiXiong
* @Date: 2021-07-05 17:30:25
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-07-05 17:30:25
* @Description:
*/
import
*
as
React
from
'react'
;
import
{
ButtonTabsContextProps
}
from
'./interface'
;
const
ButtonTabsContext
=
React
.
createContext
<
ButtonTabsContextProps
|
null
>
(
null
);
export
const
ButtonTabsContextProvider
=
ButtonTabsContext
.
Provider
;
export
default
ButtonTabsContext
;
\ No newline at end of file
src/components/ButtonTabs/index.tsx
View file @
bc180b49
/*
* @Author: XieZhiXiong
* @Date: 2021-0
6-15 17:13:25
* @Date: 2021-0
7-05 17:10:21
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-0
6-15 17:19:58
* @Description:
Radio.Button 选项卡
* @LastEditTime: 2021-0
7-05 17:10:21
* @Description:
*/
import
React
from
'react'
;
import
ButtonSwitch
,
{
ButtonSwitchProps
}
from
'../ButtonSwitch'
;
import
styles
from
'./index.less'
;
import
*
as
React
from
'react'
;
import
InternalButtonTabs
from
'./ButtonTabs'
;
import
Item
from
'./ButtonTabsItem'
;
import
{
ButtonTabsProps
,
}
from
'./interface'
;
interface
IProps
extends
ButtonSwitchProps
{
export
*
from
'./interface'
;
interface
CompoundedComponent
extends
React
.
ForwardRefExoticComponent
<
ButtonTabsProps
>
{
Item
:
typeof
Item
;
}
const
ButtonTabs
:
React
.
FC
=
()
=>
{
return
(
<
div
className=
{
styles
[
'button-tabs'
]
}
>
<
div
className=
{
styles
[
'button-tabs-head'
]
}
>
<
div
className=
{
styles
[
'button-tabs-head-extra'
]
}
>
我是拓展
</
div
>
<
div
className=
{
styles
[
'button-tabs-head-nav'
]
}
>
我是拓展
</
div
>
</
div
>
</
div
>
);
const
ButtonTabs
=
InternalButtonTabs
as
CompoundedComponent
;
ButtonTabs
.
Item
=
Item
;
export
{
Item
,
};
export
default
ButtonTabs
;
export
default
ButtonTabs
;
\ No newline at end of file
src/components/ButtonTabs/interface.ts
0 → 100644
View file @
bc180b49
/*
* @Author: XieZhiXiong
* @Date: 2021-07-05 17:06:56
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-07-05 17:06:57
* @Description:
*/
import
{
HTMLAttributes
}
from
'react'
;
import
{
ButtonSwitchProps
}
from
'../ButtonSwitch'
;
import
{
MellowCardProps
}
from
'../MellowCard'
;
export
type
KeyType
=
string
|
number
;
export
interface
ButtonTabsItemProps
extends
Omit
<
HTMLAttributes
<
HTMLDivElement
>
,
'onChange'
>
{
/**
* 标识
*/
activeKey
:
KeyType
,
children
?:
React
.
ReactNode
,
}
export
interface
ButtonTabsProps
extends
ButtonSwitchProps
,
Omit
<
MellowCardProps
,
'extra'
|
'onChange'
|
'size'
>
{
/**
* 头部左侧自定义拓展
*/
extra
?:
React
.
ReactNode
,
/**
* 默认值
*/
defaultValue
?:
KeyType
,
children
?:
React
.
ReactNode
,
}
export
interface
ButtonTabsContextProps
{
current
:
KeyType
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment