mirror of
https://github.com/woodchen-ink/clash-and-dashboard.git
synced 2025-07-18 22:11:56 +08:00
Chore: improve group select
This commit is contained in:
parent
60b38e7236
commit
a9f1cbd62b
@ -6,17 +6,40 @@ import './style.scss'
|
|||||||
interface TagsProps extends BaseComponentProps {
|
interface TagsProps extends BaseComponentProps {
|
||||||
data: Set<string>
|
data: Set<string>
|
||||||
onClick: (name: string) => void
|
onClick: (name: string) => void
|
||||||
selected: string
|
select: string
|
||||||
|
rowHeight: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Tags extends React.Component<TagsProps, {}> {
|
interface TagsState {
|
||||||
|
extend: boolean
|
||||||
|
showExtend: boolean
|
||||||
|
ulRef: React.RefObject<HTMLUListElement>
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Tags extends React.Component<TagsProps, TagsState> {
|
||||||
|
state: TagsState = {
|
||||||
|
extend: false,
|
||||||
|
showExtend: true,
|
||||||
|
ulRef: React.createRef<HTMLUListElement>()
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleExtend = () => {
|
||||||
|
this.setState({ extend: !this.state.extend })
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount () {
|
||||||
|
this.setState({ showExtend: this.state.ulRef.current.offsetHeight > 30 })
|
||||||
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { className, data, onClick, selected } = this.props
|
const { className, data, onClick, select } = this.props
|
||||||
|
const { extend } = this.state
|
||||||
|
const rowHeight = this.state.extend ? 'auto' : this.props.rowHeight
|
||||||
|
|
||||||
const tags = [...data]
|
const tags = [...data]
|
||||||
.sort()
|
.sort()
|
||||||
.map(t => {
|
.map(t => {
|
||||||
const tagClass = classnames({ 'tags-selected': selected === t })
|
const tagClass = classnames({ 'tags-selected': select === t })
|
||||||
return (
|
return (
|
||||||
<li className={tagClass} key={t} onClick={() => onClick(t)}>
|
<li className={tagClass} key={t} onClick={() => onClick(t)}>
|
||||||
{ t }
|
{ t }
|
||||||
@ -25,9 +48,15 @@ export class Tags extends React.Component<TagsProps, {}> {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ul className={classnames('tags', className)}>
|
<div className={classnames('tags-container', className)} style={{ height: rowHeight }}>
|
||||||
|
<ul ref={this.state.ulRef} className={classnames('tags', { extend })}>
|
||||||
{ tags }
|
{ tags }
|
||||||
</ul>
|
</ul>
|
||||||
|
{
|
||||||
|
this.state.showExtend &&
|
||||||
|
<span className="tags-entend" onClick={this.toggleExtend}>{ this.state.extend ? '收起' : '展开' }</span>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,19 @@ $height: 22px;
|
|||||||
$add-height: 25px;
|
$add-height: 25px;
|
||||||
$delete-height: 22px;
|
$delete-height: 22px;
|
||||||
|
|
||||||
|
.tags-container {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
overflow-y: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
.tags {
|
.tags {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex: 1;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
list-style: none;
|
list-style: none;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
padding: 3px 4px;
|
box-sizing: content-box;
|
||||||
|
|
||||||
li {
|
li {
|
||||||
position: relative;
|
position: relative;
|
||||||
@ -31,3 +38,11 @@ $delete-height: 22px;
|
|||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tags-entend {
|
||||||
|
height: 30px;
|
||||||
|
line-height: 30px;
|
||||||
|
padding: 0 10px;
|
||||||
|
user-select: none;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
@ -24,9 +24,18 @@ export class Group extends React.Component<GroupProps, {}> {
|
|||||||
const proxies = new Set(config.all)
|
const proxies = new Set(config.all)
|
||||||
return (
|
return (
|
||||||
<div className="proxy-group">
|
<div className="proxy-group">
|
||||||
|
<div className="proxy-group-part">
|
||||||
<span className="proxy-group-name">{ config.name }</span>
|
<span className="proxy-group-name">{ config.name }</span>
|
||||||
<span className="proxy-group-type">{ config.type }</span>
|
<span className="proxy-group-type">{ config.type }</span>
|
||||||
<Tags className="proxy-group-tags" data={proxies} onClick={this.handleChangeProxySelected} selected={config.now} />
|
</div>
|
||||||
|
<div className="proxy-group-tags-container">
|
||||||
|
<Tags
|
||||||
|
className="proxy-group-tags"
|
||||||
|
data={proxies}
|
||||||
|
onClick={this.handleChangeProxySelected}
|
||||||
|
select={config.now}
|
||||||
|
rowHeight={30} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,17 @@
|
|||||||
|
|
||||||
.proxy-group {
|
.proxy-group {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: flex-start;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
padding: 12px 0;
|
|
||||||
color: $color-black-light;
|
color: $color-black-light;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.proxy-group-part {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
height: 60px;
|
||||||
|
}
|
||||||
|
|
||||||
.proxy-group-name {
|
.proxy-group-name {
|
||||||
display: flex;
|
display: flex;
|
||||||
padding: 0 20px;
|
padding: 0 20px;
|
||||||
@ -15,6 +20,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.proxy-group-type {
|
.proxy-group-type {
|
||||||
|
display: block;
|
||||||
height: 24px;
|
height: 24px;
|
||||||
line-height: 24px;
|
line-height: 24px;
|
||||||
width: 80px;
|
width: 80px;
|
||||||
@ -36,6 +42,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.proxy-group-tags-container {
|
||||||
|
padding: 15px 0;
|
||||||
|
}
|
||||||
|
|
||||||
.proxy-group-tags {
|
.proxy-group-tags {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
margin-left: 30px;
|
margin-left: 30px;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user