mirror of
https://github.com/woodchen-ink/clash-and-dashboard.git
synced 2025-07-18 14:01:56 +08:00
Chore: improve group select
This commit is contained in:
parent
60b38e7236
commit
a9f1cbd62b
@ -6,28 +6,57 @@ import './style.scss'
|
||||
interface TagsProps extends BaseComponentProps {
|
||||
data: Set<string>
|
||||
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 () {
|
||||
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]
|
||||
.sort()
|
||||
.map(t => {
|
||||
const tagClass = classnames({ 'tags-selected': selected === t })
|
||||
return (
|
||||
<li className={tagClass} key={t} onClick={() => onClick(t)}>
|
||||
{ t }
|
||||
</li>
|
||||
)
|
||||
})
|
||||
.sort()
|
||||
.map(t => {
|
||||
const tagClass = classnames({ 'tags-selected': select === t })
|
||||
return (
|
||||
<li className={tagClass} key={t} onClick={() => onClick(t)}>
|
||||
{ t }
|
||||
</li>
|
||||
)
|
||||
})
|
||||
|
||||
return (
|
||||
<ul className={classnames('tags', className)}>
|
||||
{ tags }
|
||||
</ul>
|
||||
<div className={classnames('tags-container', className)} style={{ height: rowHeight }}>
|
||||
<ul ref={this.state.ulRef} className={classnames('tags', { extend })}>
|
||||
{ tags }
|
||||
</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;
|
||||
$delete-height: 22px;
|
||||
|
||||
.tags-container {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
overflow-y: hidden;
|
||||
}
|
||||
|
||||
.tags {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
align-items: center;
|
||||
list-style: none;
|
||||
flex-wrap: wrap;
|
||||
padding: 3px 4px;
|
||||
box-sizing: content-box;
|
||||
|
||||
li {
|
||||
position: relative;
|
||||
@ -31,3 +38,11 @@ $delete-height: 22px;
|
||||
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)
|
||||
return (
|
||||
<div className="proxy-group">
|
||||
<span className="proxy-group-name">{ config.name }</span>
|
||||
<span className="proxy-group-type">{ config.type }</span>
|
||||
<Tags className="proxy-group-tags" data={proxies} onClick={this.handleChangeProxySelected} selected={config.now} />
|
||||
<div className="proxy-group-part">
|
||||
<span className="proxy-group-name">{ config.name }</span>
|
||||
<span className="proxy-group-type">{ config.type }</span>
|
||||
</div>
|
||||
<div className="proxy-group-tags-container">
|
||||
<Tags
|
||||
className="proxy-group-tags"
|
||||
data={proxies}
|
||||
onClick={this.handleChangeProxySelected}
|
||||
select={config.now}
|
||||
rowHeight={30} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
@ -2,12 +2,17 @@
|
||||
|
||||
.proxy-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
align-items: flex-start;
|
||||
font-size: 14px;
|
||||
padding: 12px 0;
|
||||
color: $color-black-light;
|
||||
}
|
||||
|
||||
.proxy-group-part {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 60px;
|
||||
}
|
||||
|
||||
.proxy-group-name {
|
||||
display: flex;
|
||||
padding: 0 20px;
|
||||
@ -15,6 +20,7 @@
|
||||
}
|
||||
|
||||
.proxy-group-type {
|
||||
display: block;
|
||||
height: 24px;
|
||||
line-height: 24px;
|
||||
width: 80px;
|
||||
@ -36,6 +42,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
.proxy-group-tags-container {
|
||||
padding: 15px 0;
|
||||
}
|
||||
|
||||
.proxy-group-tags {
|
||||
flex: 1;
|
||||
margin-left: 30px;
|
||||
|
Loading…
x
Reference in New Issue
Block a user