mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-19 15:21:23 +02:00
Better pair editor delete button
This commit is contained in:
@@ -18,7 +18,7 @@ export function Checkbox({ checked, onChange, className, disabled }: Props) {
|
|||||||
onCheckedChange={onChange}
|
onCheckedChange={onChange}
|
||||||
className={classnames(
|
className={classnames(
|
||||||
className,
|
className,
|
||||||
'w-5 h-5 border border-gray-200 rounded',
|
'flex-shrink-0 w-5 h-5 border border-gray-200 rounded',
|
||||||
'focus:border-focus',
|
'focus:border-focus',
|
||||||
'disabled:opacity-disabled',
|
'disabled:opacity-disabled',
|
||||||
'outline-none',
|
'outline-none',
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ const _IconButton = forwardRef<HTMLButtonElement, Props>(function IconButton(
|
|||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
className={classnames(
|
className={classnames(
|
||||||
className,
|
className,
|
||||||
'text-gray-700 hover:text-gray-1000',
|
'flex-shrink-0 text-gray-700 hover:text-gray-1000',
|
||||||
'!px-0',
|
'!px-0',
|
||||||
size === 'md' && 'w-9',
|
size === 'md' && 'w-9',
|
||||||
size === 'sm' && 'w-8',
|
size === 'sm' && 'w-8',
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import type { GenericCompletionConfig } from './Editor/genericCompletion';
|
|||||||
import { Icon } from './Icon';
|
import { Icon } from './Icon';
|
||||||
import { IconButton } from './IconButton';
|
import { IconButton } from './IconButton';
|
||||||
import { Input } from './Input';
|
import { Input } from './Input';
|
||||||
|
import { HStack } from './Stacks';
|
||||||
|
|
||||||
export type PairEditorProps = {
|
export type PairEditorProps = {
|
||||||
pairs: Pair[];
|
pairs: Pair[];
|
||||||
@@ -235,65 +236,66 @@ const FormRow = memo(function FormRow({
|
|||||||
<div
|
<div
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={classnames(
|
className={classnames(
|
||||||
'pb-2 group grid grid-cols-[auto_auto_minmax(0,1fr)_minmax(0,1fr)_auto]',
|
'pb-2 group grid grid-cols-[auto_minmax(0,1fr)_auto]',
|
||||||
'grid-rows-1 gap-2 items-center',
|
'grid-rows-1 items-center',
|
||||||
!pairContainer.pair.enabled && 'opacity-60',
|
!pairContainer.pair.enabled && 'opacity-60',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{!isLast ? (
|
{!isLast ? (
|
||||||
<div
|
<div
|
||||||
className={classnames(
|
className={classnames(
|
||||||
'-mr-2 py-2 h-9 w-3 flex items-center',
|
'py-2 h-9 w-3 flex items-center',
|
||||||
'justify-center opacity-0 hover:opacity-100',
|
'justify-center opacity-0 hover:opacity-100',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Icon icon="drag" className="pointer-events-none" />
|
<Icon icon="drag" className="pointer-events-none" />
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<span className="w-1" />
|
<span className="w-3" />
|
||||||
)}
|
)}
|
||||||
<Checkbox
|
<HStack space={2} alignItems="center">
|
||||||
disabled={isLast || !pairContainer.pair.name}
|
<Checkbox
|
||||||
checked={isLast || !pairContainer.pair.name ? false : !!pairContainer.pair.enabled}
|
disabled={isLast}
|
||||||
className={isLast ? '!opacity-disabled' : undefined}
|
checked={isLast ? false : !!pairContainer.pair.enabled}
|
||||||
onChange={handleChangeEnabled}
|
className={classnames(isLast && '!opacity-disabled')}
|
||||||
/>
|
onChange={handleChangeEnabled}
|
||||||
<Input
|
|
||||||
hideLabel
|
|
||||||
require={!isLast && !!pairContainer.pair.enabled && !!pairContainer.pair.value}
|
|
||||||
useTemplating
|
|
||||||
containerClassName={classnames(isLast && 'border-dashed')}
|
|
||||||
defaultValue={pairContainer.pair.name}
|
|
||||||
label="Name"
|
|
||||||
name="name"
|
|
||||||
onChange={handleChangeName}
|
|
||||||
onFocus={handleFocus}
|
|
||||||
placeholder={namePlaceholder ?? 'name'}
|
|
||||||
autocomplete={nameAutocomplete}
|
|
||||||
/>
|
|
||||||
<Input
|
|
||||||
hideLabel
|
|
||||||
containerClassName={classnames(isLast && 'border-dashed')}
|
|
||||||
defaultValue={pairContainer.pair.value}
|
|
||||||
label="Value"
|
|
||||||
name="value"
|
|
||||||
onChange={handleChangeValue}
|
|
||||||
onFocus={handleFocus}
|
|
||||||
placeholder={valuePlaceholder ?? 'value'}
|
|
||||||
useTemplating
|
|
||||||
autocomplete={valueAutocomplete?.(pairContainer.pair.name)}
|
|
||||||
/>
|
|
||||||
{onDelete ? (
|
|
||||||
<IconButton
|
|
||||||
icon="trash"
|
|
||||||
title="Delete header"
|
|
||||||
onClick={handleDelete}
|
|
||||||
tabIndex={-1}
|
|
||||||
className={classnames('opacity-0 group-hover:opacity-100')}
|
|
||||||
/>
|
/>
|
||||||
) : (
|
<Input
|
||||||
<IconButton title="" icon="empty" />
|
hideLabel
|
||||||
)}
|
require={!isLast && !!pairContainer.pair.enabled && !!pairContainer.pair.value}
|
||||||
|
useTemplating
|
||||||
|
containerClassName={classnames(isLast && 'border-dashed')}
|
||||||
|
defaultValue={pairContainer.pair.name}
|
||||||
|
label="Name"
|
||||||
|
name="name"
|
||||||
|
onChange={handleChangeName}
|
||||||
|
onFocus={handleFocus}
|
||||||
|
placeholder={namePlaceholder ?? 'name'}
|
||||||
|
autocomplete={nameAutocomplete}
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
hideLabel
|
||||||
|
containerClassName={classnames(isLast && 'border-dashed')}
|
||||||
|
defaultValue={pairContainer.pair.value}
|
||||||
|
label="Value"
|
||||||
|
name="value"
|
||||||
|
onChange={handleChangeValue}
|
||||||
|
onFocus={handleFocus}
|
||||||
|
placeholder={valuePlaceholder ?? 'value'}
|
||||||
|
useTemplating
|
||||||
|
autocomplete={valueAutocomplete?.(pairContainer.pair.name)}
|
||||||
|
/>
|
||||||
|
</HStack>
|
||||||
|
<IconButton
|
||||||
|
aria-hidden={!onDelete}
|
||||||
|
disabled={!onDelete}
|
||||||
|
color="custom"
|
||||||
|
icon={onDelete ? 'trash' : 'empty'}
|
||||||
|
size="sm"
|
||||||
|
title="Delete header"
|
||||||
|
onClick={handleDelete}
|
||||||
|
className="ml-0.5 opacity-0 group-hover:opacity-100 focus-visible:opacity-100"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user