|
|
|
@ -1,12 +1,13 @@
|
|
|
|
'use client'
|
|
|
|
'use client'
|
|
|
|
import type { FC } from 'react'
|
|
|
|
import type { FC } from 'react'
|
|
|
|
import React from 'react'
|
|
|
|
import React, { useState } from 'react'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { PlusIcon } from '@heroicons/react/24/outline'
|
|
|
|
import { PlusIcon } from '@heroicons/react/24/outline'
|
|
|
|
import { ReactSortable } from 'react-sortablejs'
|
|
|
|
import { ReactSortable } from 'react-sortablejs'
|
|
|
|
import RemoveIcon from '../../base/icons/remove-icon'
|
|
|
|
import RemoveIcon from '../../base/icons/remove-icon'
|
|
|
|
|
|
|
|
|
|
|
|
import s from './style.module.css'
|
|
|
|
import s from './style.module.css'
|
|
|
|
|
|
|
|
import cn from '@/utils/classnames'
|
|
|
|
|
|
|
|
|
|
|
|
export type Options = string[]
|
|
|
|
export type Options = string[]
|
|
|
|
export type IConfigSelectProps = {
|
|
|
|
export type IConfigSelectProps = {
|
|
|
|
@ -19,6 +20,8 @@ const ConfigSelect: FC<IConfigSelectProps> = ({
|
|
|
|
onChange,
|
|
|
|
onChange,
|
|
|
|
}) => {
|
|
|
|
}) => {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
const [delBtnHoverIndex, setDelBtnHoverIndex] = useState(-1)
|
|
|
|
|
|
|
|
const [focusedIndex, setFocusedIndex] = useState(-1)
|
|
|
|
|
|
|
|
|
|
|
|
const optionList = options.map((content, index) => {
|
|
|
|
const optionList = options.map((content, index) => {
|
|
|
|
return ({
|
|
|
|
return ({
|
|
|
|
@ -36,48 +39,62 @@ const ConfigSelect: FC<IConfigSelectProps> = ({
|
|
|
|
list={optionList}
|
|
|
|
list={optionList}
|
|
|
|
setList={list => onChange(list.map(item => item.name))}
|
|
|
|
setList={list => onChange(list.map(item => item.name))}
|
|
|
|
handle='.handle'
|
|
|
|
handle='.handle'
|
|
|
|
ghostClass="opacity-50"
|
|
|
|
ghostClass="opacity-30"
|
|
|
|
animation={150}
|
|
|
|
animation={150}
|
|
|
|
>
|
|
|
|
>
|
|
|
|
{options.map((o, index) => (
|
|
|
|
{options.map((o, index) => {
|
|
|
|
<div className={`${s.inputWrap} relative`} key={index}>
|
|
|
|
const delBtnHover = delBtnHoverIndex === index
|
|
|
|
<div className='handle flex items-center justify-center w-4 h-4 cursor-grab'>
|
|
|
|
const inputFocused = focusedIndex === index
|
|
|
|
<svg width="6" height="10" viewBox="0 0 6 10" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
|
|
return (
|
|
|
|
<path fillRule="evenodd" clipRule="evenodd" d="M1 2C1.55228 2 2 1.55228 2 1C2 0.447715 1.55228 0 1 0C0.447715 0 0 0.447715 0 1C0 1.55228 0.447715 2 1 2ZM1 6C1.55228 6 2 5.55228 2 5C2 4.44772 1.55228 4 1 4C0.447715 4 0 4.44772 0 5C0 5.55228 0.447715 6 1 6ZM6 1C6 1.55228 5.55228 2 5 2C4.44772 2 4 1.55228 4 1C4 0.447715 4.44772 0 5 0C5.55228 0 6 0.447715 6 1ZM5 6C5.55228 6 6 5.55228 6 5C6 4.44772 5.55228 4 5 4C4.44772 4 4 4.44772 4 5C4 5.55228 4.44772 6 5 6ZM2 9C2 9.55229 1.55228 10 1 10C0.447715 10 0 9.55229 0 9C0 8.44771 0.447715 8 1 8C1.55228 8 2 8.44771 2 9ZM5 10C5.55228 10 6 9.55229 6 9C6 8.44771 5.55228 8 5 8C4.44772 8 4 8.44771 4 9C4 9.55229 4.44772 10 5 10Z" fill="#98A2B3" />
|
|
|
|
<div
|
|
|
|
</svg>
|
|
|
|
className={cn(
|
|
|
|
</div>
|
|
|
|
`${s.inputWrap} relative border border-components-panel-border-subtle bg-components-panel-on-panel-item-bg`,
|
|
|
|
<input
|
|
|
|
inputFocused && 'border-components-input-border-active bg-components-input-bg-active',
|
|
|
|
|
|
|
|
delBtnHover && 'bg-state-destructive-hover',
|
|
|
|
|
|
|
|
)}
|
|
|
|
key={index}
|
|
|
|
key={index}
|
|
|
|
type="input"
|
|
|
|
>
|
|
|
|
value={o || ''}
|
|
|
|
<div className='handle flex items-center justify-center w-3.5 h-3.5 cursor-grab text-text-quaternary'>
|
|
|
|
onChange={(e) => {
|
|
|
|
<svg width="6" height="10" viewBox="0 0 6 10" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
|
|
const value = e.target.value
|
|
|
|
<path fillRule="evenodd" clipRule="evenodd" d="M1 2C1.55228 2 2 1.55228 2 1C2 0.447715 1.55228 0 1 0C0.447715 0 0 0.447715 0 1C0 1.55228 0.447715 2 1 2ZM1 6C1.55228 6 2 5.55228 2 5C2 4.44772 1.55228 4 1 4C0.447715 4 0 4.44772 0 5C0 5.55228 0.447715 6 1 6ZM6 1C6 1.55228 5.55228 2 5 2C4.44772 2 4 1.55228 4 1C4 0.447715 4.44772 0 5 0C5.55228 0 6 0.447715 6 1ZM5 6C5.55228 6 6 5.55228 6 5C6 4.44772 5.55228 4 5 4C4.44772 4 4 4.44772 4 5C4 5.55228 4.44772 6 5 6ZM2 9C2 9.55229 1.55228 10 1 10C0.447715 10 0 9.55229 0 9C0 8.44771 0.447715 8 1 8C1.55228 8 2 8.44771 2 9ZM5 10C5.55228 10 6 9.55229 6 9C6 8.44771 5.55228 8 5 8C4.44772 8 4 8.44771 4 9C4 9.55229 4.44772 10 5 10Z" fill="currentColor" />
|
|
|
|
onChange(options.map((item, i) => {
|
|
|
|
</svg>
|
|
|
|
if (index === i)
|
|
|
|
</div>
|
|
|
|
return value
|
|
|
|
<input
|
|
|
|
|
|
|
|
key={index}
|
|
|
|
|
|
|
|
type="input"
|
|
|
|
|
|
|
|
value={o || ''}
|
|
|
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
|
|
|
const value = e.target.value
|
|
|
|
|
|
|
|
onChange(options.map((item, i) => {
|
|
|
|
|
|
|
|
if (index === i)
|
|
|
|
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
|
|
return item
|
|
|
|
return item
|
|
|
|
}))
|
|
|
|
}))
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
className={'w-full pl-1.5 pr-8 text-sm leading-9 text-gray-900 border-0 grow h-9 bg-transparent focus:outline-none cursor-pointer'}
|
|
|
|
onFocus={() => { setFocusedIndex(index) }}
|
|
|
|
/>
|
|
|
|
onBlur={() => { setFocusedIndex(-1) }}
|
|
|
|
<RemoveIcon
|
|
|
|
className={'w-full pl-1 pr-8 system-sm-medium text-text-secondary border-0 grow h-8 bg-transparent group focus:outline-none cursor-pointer caret-[#295EFF]'}
|
|
|
|
className={`${s.deleteBtn} absolute top-1/2 translate-y-[-50%] right-1.5 items-center justify-center w-6 h-6 rounded-md cursor-pointer hover:bg-[#FEE4E2]`}
|
|
|
|
/>
|
|
|
|
onClick={() => {
|
|
|
|
<RemoveIcon
|
|
|
|
onChange(options.filter((_, i) => index !== i))
|
|
|
|
className={`${s.deleteBtn} absolute top-1/2 translate-y-[-50%] right-1 items-center justify-center w-6 h-6 rounded-lg cursor-pointer`}
|
|
|
|
}}
|
|
|
|
onClick={() => {
|
|
|
|
/>
|
|
|
|
onChange(options.filter((_, i) => index !== i))
|
|
|
|
</div>
|
|
|
|
}}
|
|
|
|
))}
|
|
|
|
onMouseEnter={() => setDelBtnHoverIndex(index)}
|
|
|
|
|
|
|
|
onMouseLeave={() => setDelBtnHoverIndex(-1)}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</div>)
|
|
|
|
|
|
|
|
})}
|
|
|
|
</ReactSortable>
|
|
|
|
</ReactSortable>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
<div
|
|
|
|
<div
|
|
|
|
onClick={() => { onChange([...options, '']) }}
|
|
|
|
onClick={() => { onChange([...options, '']) }}
|
|
|
|
className='flex items-center h-9 px-3 gap-2 rounded-lg cursor-pointer text-gray-400 bg-gray-100'>
|
|
|
|
className='flex items-center h-8 px-2 gap-1 rounded-lg cursor-pointer bg-components-button-tertiary-bg'>
|
|
|
|
<PlusIcon width={16} height={16}></PlusIcon>
|
|
|
|
<PlusIcon className='text-components-button-tertiary-text' width={16} height={16} />
|
|
|
|
<div className='text-gray-500 text-[13px]'>{t('appDebug.variableConfig.addOption')}</div>
|
|
|
|
<div className='text-components-button-tertiary-text system-sm-medium'>{t('appDebug.variableConfig.addOption')}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|