Skip to content

Commit

Permalink
feature: add draggable attribute to OptionsPanel component (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
glaubersilva authored Jan 24, 2024
1 parent e7d30da commit 60ce95b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/OptionsPanel/OptionsItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import cn from 'classnames';
import {__} from '@wordpress/i18n';
import {Button, Icon, Tooltip} from '@wordpress/components';

import {draggable, minusCircle} from './icons';
import {draggableIcon, minusCircle} from './icons';
import {OptionsItemProps} from './types';
import CurrencyControl from '../CurrencyControl';
import {isCurrencyMode} from './utils';
Expand All @@ -22,11 +22,12 @@ export default function OptionsItem({
handleRemoveOption,
readOnly,
disabled,
draggable,
}: OptionsItemProps) {
return (
<div className={'givewp-options-list--item'} ref={provided.innerRef} {...provided.draggableProps}>
<span className={'givewp-options-list--item--draggable'} {...provided.dragHandleProps}>
<Icon icon={draggable} />
{draggable && <Icon icon={draggableIcon} />}
</span>
<Tooltip
text={defaultTooltip ? defaultTooltip : __('Default', 'give')}
Expand Down
2 changes: 2 additions & 0 deletions src/OptionsPanel/OptionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function OptionsList({
onRemoveOption,
readOnly,
disableSoloCheckedOption,
draggable,
}: OptionsListProps) {
const handleRemoveOption = (index: number) => (): void => {
if (onRemoveOption) {
Expand Down Expand Up @@ -103,6 +104,7 @@ export default function OptionsList({
option.checked &&
options.filter((option) => option.checked).length === 1
}
draggable={draggable}
/>
)}
</Draggable>
Expand Down
2 changes: 1 addition & 1 deletion src/OptionsPanel/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function minusCircle() {
);
}

export function draggable() {
export function draggableIcon() {
return (
<SVG xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
<Path
Expand Down
2 changes: 2 additions & 0 deletions src/OptionsPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default function Options({
readOnly = false,
label = __('Options', 'give'),
disableSoloCheckedOption = false,
draggable = true,
}: OptionsPanelProps) {
const [showValues, setShowValues] = useState<boolean>(false);

Expand Down Expand Up @@ -58,6 +59,7 @@ export default function Options({
onRemoveOption={onRemoveOption}
readOnly={readOnly}
disableSoloCheckedOption={disableSoloCheckedOption}
draggable={draggable}
/>
</BaseControl>
</PanelRow>
Expand Down
3 changes: 3 additions & 0 deletions src/OptionsPanel/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface OptionsPanelProps {
label?: string;
readOnly?: boolean;
disableSoloCheckedOption?: boolean;
draggable?: boolean;
}

export interface OptionsListProps {
Expand All @@ -25,6 +26,7 @@ export interface OptionsListProps {
onRemoveOption?: (option: OptionProps, index: number) => void;
readOnly?: boolean;
disableSoloCheckedOption?: boolean;
draggable?: boolean;
}

export interface OptionsItemProps {
Expand All @@ -41,6 +43,7 @@ export interface OptionsItemProps {
handleRemoveOption: () => void;
readOnly?: boolean;
disabled?: boolean;
draggable?: boolean;
}

export interface OptionsHeaderProps {
Expand Down

0 comments on commit 60ce95b

Please sign in to comment.