Skip to content

Commit

Permalink
feat: customize grid item size (close alist-org/alist#6051)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Feb 18, 2024
1 parent 26a0408 commit 42d6bf1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/pages/home/folder/Grid.tsx
Expand Up @@ -2,14 +2,16 @@ import { Grid } from "@hope-ui/solid"
import { For } from "solid-js"
import { GridItem } from "./GridItem"
import "lightgallery/css/lightgallery-bundle.css"
import { objStore } from "~/store"
import { local, objStore } from "~/store"

const GridLayout = () => {
return (
<Grid
w="$full"
gap="$1"
templateColumns="repeat(auto-fill, minmax(100px,1fr))"
templateColumns={`repeat(auto-fill, minmax(${
parseInt(local["grid_item_size"]) + 20
}px,1fr))`}
>
<For each={objStore.objs}>
{(obj, i) => {
Expand Down
16 changes: 13 additions & 3 deletions src/pages/home/folder/GridItem.tsx
Expand Up @@ -4,7 +4,13 @@ import { useContextMenu } from "solid-contextmenu"
import { batch, createMemo, createSignal, Show } from "solid-js"
import { CenterLoading, LinkWithPush, ImageWithError } from "~/components"
import { usePath, useUtil } from "~/hooks"
import { checkboxOpen, getMainColor, selectAll, selectIndex } from "~/store"
import {
checkboxOpen,
getMainColor,
local,
selectAll,
selectIndex,
} from "~/store"
import { ObjType, StoreObj } from "~/types"
import { bus, hoverColor } from "~/utils"
import { getIconByObj } from "~/utils/icon"
Expand All @@ -16,7 +22,11 @@ export const GridItem = (props: { obj: StoreObj; index: number }) => {
}
const { setPathAs } = usePath()
const objIcon = (
<Icon color={getMainColor()} boxSize="$12" as={getIconByObj(props.obj)} />
<Icon
color={getMainColor()}
boxSize={`${parseInt(local["grid_item_size"]) - 30}px`}
as={getIconByObj(props.obj)}
/>
)
const [hover, setHover] = createSignal(false)
const showCheckbox = createMemo(
Expand Down Expand Up @@ -65,7 +75,7 @@ export const GridItem = (props: { obj: StoreObj; index: number }) => {
>
<Center
class="item-thumbnail"
h="70px"
h={`${parseInt(local["grid_item_size"])}px`}
w="$full"
// @ts-ignore
on:click={(e) => {
Expand Down
5 changes: 5 additions & 0 deletions src/store/local_settings.ts
Expand Up @@ -41,6 +41,11 @@ export const initialLocalSettings = [
type: "select",
options: ["static", "sticky", "only_navbar_sticky"],
},
{
key: "grid_item_size",
default: "90",
type: "number",
},
]
export type LocalSetting = (typeof initialLocalSettings)[number]
for (const setting of initialLocalSettings) {
Expand Down

0 comments on commit 42d6bf1

Please sign in to comment.