From 3fd6abb879b6aa4d3fa42b40210f39c2160d00c7 Mon Sep 17 00:00:00 2001 From: YetAnotherZephyruso <176294927+YetAnotherZephyruso@users.noreply.github.com> Date: Thu, 1 Aug 2024 00:36:23 +0800 Subject: [PATCH] feat: custom table columns order for mobile (#885) --- package.json | 2 +- src/components/ConnectionsSettingsModal.tsx | 68 ++++++++++++++++----- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index f788054..abfaadd 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "type": "module", "scripts": { "build": "vite build", - "dev": "vite", + "dev": "vite --host", "format": "prettier -w .", "lint": "eslint --fix .", "prepare": "husky", diff --git a/src/components/ConnectionsSettingsModal.tsx b/src/components/ConnectionsSettingsModal.tsx index cff9e5d..dcbf53f 100644 --- a/src/components/ConnectionsSettingsModal.tsx +++ b/src/components/ConnectionsSettingsModal.tsx @@ -1,6 +1,12 @@ import { createForm } from '@felte/solid' import { validator } from '@felte/validator-zod' -import { IconMenuOrder, IconNetwork, IconX } from '@tabler/icons-solidjs' +import { + IconArrowDown, + IconArrowUp, + IconMenuOrder, + IconNetwork, + IconX, +} from '@tabler/icons-solidjs' import type { DragEventHandler, Draggable, @@ -147,6 +153,29 @@ export const ConnectionsSettingsModal = (props: { } } + const moveElementInOrder = ( + key: CONNECTIONS_TABLE_ACCESSOR_KEY, + direction: 'forward' | 'backward', + ) => { + const arr = [...props.order] + const length = arr.length + const index = arr.indexOf(key) + + if (index < 0 || index >= length) { + return + } + + const newIndex = direction === 'forward' ? index + 1 : index - 1 + + if (newIndex < 0 || newIndex >= length) { + return + } + + ;[arr[index], arr[newIndex]] = [arr[newIndex], arr[index]] + + props.onOrderChange(arr) + } + const FormRow: Component<{ key: CONNECTIONS_TABLE_ACCESSOR_KEY }> = ({ key }) => { @@ -165,25 +194,36 @@ export const ConnectionsSettingsModal = (props: {
- - { - props.onVisibleChange({ - ...props.visible, - [key]: e.target.checked, - }) - }} - /> +
+
)