Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commita800835

Browse files
authored
add Dropdown style button (#766)
* feat(buttons): add new MoreButton to Buttons famliy* fix(Tooltip): cycle import in ConfirmFooter* style(MoreButton): align intro icon* chore(Button): rename MoreButton -> DropdownButton
1 parent185b73d commita800835

File tree

11 files changed

+373
-8
lines changed

11 files changed

+373
-8
lines changed

‎src/components/Buttons/Button.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ Button.defaultProps = {
5151
className:'',
5252
}
5353

54-
exportdefaultButton
54+
exportdefaultReact.memo(Button)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
importReactfrom'react'
2+
importTfrom'prop-types'
3+
4+
import{
5+
Wrapper,
6+
IconWrapper,
7+
Block,
8+
Icon,
9+
Intro,
10+
Title,
11+
Desc,
12+
}from'../styles/dropdown_button/option_panel'
13+
14+
constOptionPanel=({ options, onClick})=>{
15+
return(
16+
<Wrapper>
17+
{options.map((item,index)=>(
18+
<Blockkey={item.key}onClick={()=>onClick(item.key)}>
19+
{/* common_check icon is special, smaller than normal icons,
20+
and check icon is always the first icon */}
21+
<IconWrapper>
22+
<Iconsrc={item.icon}index={index}bigger={index===0}/>
23+
</IconWrapper>
24+
<Intro>
25+
<Title>{item.title}</Title>
26+
<Desc>{item.desc}</Desc>
27+
</Intro>
28+
</Block>
29+
))}
30+
</Wrapper>
31+
)
32+
}
33+
34+
OptionPanel.propTypes={
35+
onClick:T.func,
36+
options:T.arrayOf(
37+
T.shape({
38+
title:T.stirng,
39+
desc:T.string,
40+
icon:T.string,
41+
}),
42+
),
43+
}
44+
45+
OptionPanel.defaultProps={
46+
options:[],
47+
onClick:console.log,
48+
}
49+
50+
exportdefaultReact.memo(OptionPanel)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
importReactfrom'react'
2+
importTfrom'prop-types'
3+
4+
import{ICON_CMD}from'@/config'
5+
6+
importTooltipfrom'@/components/Tooltip'
7+
importOptionPanelfrom'./OptionPanel'
8+
9+
import{
10+
Wrapper,
11+
ButtonWrapper,
12+
DropdownButtonWrapper,
13+
MoreIcon,
14+
}from'../styles/dropdown_button'
15+
16+
// <UpIcon src={`${ICON_CMD}/works/vote_up.svg`} />
17+
constDropdownButton=({ children, options, onClick})=>{
18+
return(
19+
<Wrapper>
20+
<ButtonWrapperonClick={onClick}>{children}</ButtonWrapper>
21+
<Tooltip
22+
placement="bottom"
23+
trigger="click"
24+
hideOnClick={false}
25+
content={<OptionPaneloptions={options}onClick={onClick}/>}
26+
noDefaultPadding
27+
>
28+
<DropdownButtonWrapper>
29+
<MoreIconsrc={`${ICON_CMD}/works/vote_up.svg`}onClick={onClick}/>
30+
</DropdownButtonWrapper>
31+
</Tooltip>
32+
</Wrapper>
33+
)
34+
}
35+
36+
DropdownButton.propTypes={
37+
children:T.oneOfType([T.string,T.node]),
38+
onClick:T.func,
39+
options:T.arrayOf(
40+
T.shape({
41+
title:T.stirng,
42+
desc:T.string,
43+
icon:T.string,
44+
}),
45+
),
46+
// ghost: T.bool,
47+
// type: T.oneOf(['primary', 'red', 'ghost']),
48+
// size: T.oneOf(['default', 'small']),
49+
// onClick: T.func,
50+
// className: T.string,
51+
}
52+
53+
DropdownButton.defaultProps={
54+
children:'Button',
55+
onClick:console.log,
56+
options:[],
57+
// ghost: false,
58+
// type: 'primary',
59+
// size: 'default',
60+
// // eslint-disable-next-line no-console
61+
// onClick: console.log,
62+
// className: '',
63+
}
64+
65+
exportdefaultReact.memo(DropdownButton)

‎src/components/Buttons/index.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export { default as Button } from './Button'
22
export{defaultasArrowButton}from'./ArrowButton'
33
export{defaultasPublishButton}from'./PublishButton'
44
export{defaultasOrButton}from'./OrButton'
5+
export{defaultasDropdownButton}from'./DropdownButton'
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
importstyledfrom'styled-components'
2+
3+
importImgfrom'@/Img'
4+
import{WrapperasNormalButton}from'../button'
5+
import{theme,cs}from'@/utils'
6+
7+
exportconstWrapper=styled.div`
8+
${cs.flex('align-center')};
9+
10+
/* &:hover {
11+
cursor: pointer;
12+
color:${theme('thread.articleTitle')};
13+
opacity: 1;
14+
}
15+
transition: all 0.25s; */
16+
`
17+
exportconstButtonWrapper=styled(NormalButton)`
18+
height: 30px;
19+
border-top-right-radius: 0;
20+
border-bottom-right-radius: 0;
21+
padding-right: 6px;
22+
`
23+
exportconstDropdownButtonWrapper=styled(NormalButton)`
24+
height: 30px;
25+
border-top-left-radius: 0;
26+
border-bottom-left-radius: 0;
27+
padding-left: 6px;
28+
`
29+
exportconstDivider=styled.div`
30+
width: 1px;
31+
height: 14px;
32+
background:${theme('button.fg')};
33+
margin-left: 10px;
34+
margin-right: 8px;
35+
opacity: 0.5;
36+
`
37+
exportconstMoreIcon=styled(Img)`
38+
fill:${theme('button.fg')};
39+
width: 12px;
40+
height: 12px;
41+
display: block;
42+
transform: rotate(180deg);
43+
`
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
importstyledfrom'styled-components'
2+
3+
importImgfrom'@/Img'
4+
import{cs,theme}from'@/utils'
5+
6+
exportconstWrapper=styled.div`
7+
${cs.flexColumn()};
8+
width: 100%;
9+
max-height: 200px;
10+
overflow: hidden;
11+
`
12+
exportconstBlock=styled.div`
13+
${cs.flex('align-start')};
14+
padding: 8px 15px;
15+
padding-left: 10px;
16+
padding-bottom: 8px;
17+
border-bottom: 1px solid;
18+
border-bottom-color: #0d3e4e;
19+
20+
:last-child {
21+
padding-bottom: 10px;
22+
border-bottom: none;
23+
}
24+
25+
&:hover {
26+
background: #0d3e4e;
27+
cursor: pointer;
28+
}
29+
transition: all 0.25s;
30+
`
31+
exportconstIconWrapper=styled.div`
32+
${cs.flex('justify-center')};
33+
width: 24px;
34+
`
35+
exportconstIcon=styled(Img)`
36+
fill:${theme('button.primary')};
37+
width:${({ bigger})=>(bigger ?'24px' :'18px')};
38+
height:${({ bigger})=>(bigger ?'24px' :'18px')};
39+
display: block;
40+
opacity:${({ index})=>(index===0 ?1 :0)};
41+
${Block}:hover & {
42+
opacity:${({ index})=>(index===0 ?1 :0.8)};
43+
}
44+
transition: opacity 0.25s;
45+
`
46+
exportconstIntro=styled.div`
47+
${cs.flexColumn()};
48+
margin-left: 7px;
49+
`
50+
exportconstTitle=styled.div`
51+
color:${theme('thread.articleTitle')};
52+
font-size: 14px;
53+
`
54+
exportconstDesc=styled.div`
55+
color:${theme('thread.articleDigest')};
56+
font-size: 11px;
57+
margin-top: 2px;
58+
`
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
importReactfrom'react'
2+
importTfrom'prop-types'
3+
4+
import{RedWrapper}from'./styles/confirm_btn'
5+
6+
constButton=({ children, ghost, onClick, size, className})=>{
7+
return(
8+
<RedWrapper
9+
ghost={ghost}
10+
onClick={onClick}
11+
size={size}
12+
className={className}
13+
>
14+
{children}
15+
</RedWrapper>
16+
)
17+
}
18+
19+
Button.propTypes={
20+
children:T.oneOfType([T.string,T.node]),
21+
ghost:T.bool,
22+
size:T.oneOf(['default','small']),
23+
onClick:T.func,
24+
className:T.string,
25+
}
26+
27+
Button.defaultProps={
28+
children:'Button',
29+
ghost:false,
30+
size:'default',
31+
// eslint-disable-next-line no-console
32+
onClick:console.log,
33+
className:'',
34+
}
35+
36+
exportdefaultReact.memo(Button)

‎src/components/Tooltip/ConfirmFooter.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
importReactfrom'react'
22

33
import{Space}from'@/components/Common'
4-
import{Button}from'@/components/Buttons'
4+
importConfirmBtnfrom'./ConfirmBtn'
5+
// import { Button } from '@/components/Buttons'
56
import{Wrapper,ButtonsWrapper,CancelButton}from'./styles/confirm_footer'
67

78
constConfirmFooter=({ onConfirm})=>{
89
return(
910
<Wrapper>
1011
<ButtonsWrapper>
11-
<Buttontype="red"size="small"onClick={onConfirm}>
12+
<ConfirmBtnsize="small"onClick={onConfirm}>
1213
确认
13-
</Button>
14+
</ConfirmBtn>
1415
<Spaceright="10px"/>
1516
<CancelButton>取消</CancelButton>
1617
</ButtonsWrapper>

‎src/components/Tooltip/index.js‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { buildLog } from '@/utils'
1111
import{useOutsideClick}from'@/hooks'
1212

1313
importConfirmFooterfrom'./ConfirmFooter'
14-
// import Content from './Content'
1514

1615
import{
1716
StyledTippy,
@@ -110,7 +109,6 @@ const Tooltip = ({
110109
onHide&&onHide()
111110
}}
112111
onShow={(instance)=>{
113-
console.log('on show: ',instance)
114112
setInstance(instance)
115113
setActive(true)
116114
onShow&&onShow()
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
importstyledfrom'styled-components'
2+
import{lighten}from'polished'
3+
4+
import{cs,theme}from'@/utils'
5+
6+
exportconstWrapper=styled.button`
7+
${cs.flex('align-center')};
8+
-webkit-appearance: button;
9+
outline: none;
10+
11+
line-height: 1.5;
12+
font-weight: 400;
13+
text-align: center;
14+
touch-action: manipulation;
15+
cursor: pointer;
16+
background-image: none;
17+
border: 1px solid transparent;
18+
white-space: nowrap;
19+
padding:${({ size})=>(size==='default' ?'4px 15px' :'0 7px')};
20+
font-size: 14px;
21+
border-radius: 4px;
22+
height:${({ size})=>(size==='default' ?'32px' :'24px')};
23+
user-select: none;
24+
transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
25+
position: relative;
26+
color: rgba(0, 0, 0, 0.65);
27+
border-color: #d9d9d9;
28+
29+
color:${({ ghost})=>
30+
!ghost ?theme('button.fg') :theme('button.primary')};
31+
32+
background-color:${({ ghost})=>
33+
!ghost ?theme('button.primary') :'transparent'};
34+
border-color:${theme('button.primary')};
35+
36+
&:hover {
37+
/* color:${theme('button.fg')}; */
38+
color:${({ ghost})=>
39+
!ghost ?theme('button.fg') :theme('button.primary')};
40+
41+
border-color:${theme('button.hoverBg')};
42+
background-color:${({ ghost})=>
43+
!ghost ?theme('button.hoverBg') :'transparent'};
44+
}
45+
46+
&:focus {
47+
color:${({ ghost})=>
48+
!ghost ?theme('button.fg') :theme('button.primary')};
49+
border-color:${theme('button.hoverBg')};
50+
background-color:${({ ghost})=>
51+
!ghost ?theme('button.hoverBg') :'transparent'};
52+
}
53+
54+
&:active {
55+
color:${({ ghost})=>
56+
!ghost ?theme('button.fg') :theme('button.primary')};
57+
background-color:${({ ghost})=>
58+
!ghost ?theme('button.hoverBg') :'transparent'};
59+
}
60+
`
61+
exportconstRedWrapper=styled(Wrapper)`
62+
color:${({ ghost})=>(ghost ?theme('baseColor.error') :'white')};
63+
background-color:${({ ghost})=>
64+
!ghost ?theme('baseColor.error') :'transparent'};
65+
border-color:${theme('baseColor.error')};
66+
67+
&:hover {
68+
border: 2px solid;
69+
background-color:${({ ghost})=>
70+
!ghost ?lighten(0.1,'tomato') :'transparent'};
71+
border-color:${lighten(0.1,'tomato')};
72+
font-weight:${({ ghost})=>(ghost ?'bold' :'normal')};
73+
}
74+
&:focus {
75+
border: 2px solid;
76+
background-color:${({ ghost})=>
77+
!ghost ?lighten(0.1,'tomato') :'transparent'};
78+
border-color:${lighten(0.1,'tomato')};
79+
font-weight:${({ ghost})=>(ghost ?'bold' :'normal')};
80+
}
81+
&:active {
82+
border: 2px solid;
83+
background-color:${({ ghost})=>
84+
!ghost ?lighten(0.1,'tomato') :'transparent'};
85+
border-color:${lighten(0.1,'tomato')};
86+
font-weight:${({ ghost})=>(ghost ?'bold' :'normal')};
87+
}
88+
transition: all 0.25s;
89+
`

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp