Skip to content

Commit

Permalink
Fix Input Upload
Browse files Browse the repository at this point in the history
  • Loading branch information
fortezhuo committed Nov 14, 2023
1 parent ad4f6f8 commit 7369553
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tawasukha/ui",
"version": "0.0.62",
"version": "0.0.63",
"type": "module",
"types": "dist/index.d.ts",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/inputSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Chip, XChip } from "./chip"
import { AnimatePresence } from "framer-motion"
import { debouncePromise } from "../helpers/debouncePromise"
import { ChevronDownIcon } from "@heroicons/react/24/solid"
import { useIsFirstRender } from "src/helpers/useIsFirstRender"
import { useIsFirstRender } from "../helpers/useIsFirstRender"

const _input = cva(
[
Expand Down
12 changes: 11 additions & 1 deletion src/components/inputUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Item } from "./upload/Item"
import { Uploader, type UploaderProps } from "./upload/Uploader"
import { useCallback, useEffect, useState } from "react"
import { AnimatePresence } from "framer-motion"
import { useIsFirstRender } from "../helpers/useIsFirstRender"

const _input = cva(["flex flex-wrap gap-2 w-full bg-base rounded-lg border p-2 border-dashed"], {
variants: {
Expand Down Expand Up @@ -41,6 +42,7 @@ export function InputUpload({
maxSize = 20 * 1024 * 1024,
disabled,
}: InputUploadProps) {
const isFirstRender = useIsFirstRender()
const [files, setFiles] = useState<string[]>(value ? (Array.isArray(value) ? value : []) : [])

const onRemove = useCallback(
Expand All @@ -56,6 +58,13 @@ export function InputUpload({
[files, setFiles],
)

useEffect(() => {
const _values = value ? (Array.isArray(value) ? value : []) : []
if (files.length == 0 && _values.length !== 0) {
setFiles(_values)
}
}, [files, value, setFiles])

useEffect(() => {
if (onChange) onChange(files)
}, [files])
Expand All @@ -65,7 +74,8 @@ export function InputUpload({
<Uploader {...{ url, accept, maxSize, setFiles, responseKey, disabled }} />
<AnimatePresence>
{files.map((file) => {
const name = (file || "").split("/").pop() || "Untitled"
const url = new URL(file)
const name = url.searchParams.get("name") || (file || "").split("/").pop() || "Untitled"
return (
<Item
disabled={disabled}
Expand Down
4 changes: 1 addition & 3 deletions src/components/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ export function SidebarMenu({
className={cx(
"flex flex-row py-3 px-4 border-base-2 border-b transition-colors",
"duration-300 transform cursor-pointer items-center",
isOpen && !!children
? "text-base bg-primary-3 hover:opacity-90"
: "text-primary-3 bg-primary-1 hover:text-primary-5",
"text-primary-4 bg-primary-2 bg-opacity-40 hover:bg-primary-1",
className,
)}
onClick={onClick}
Expand Down
7 changes: 2 additions & 5 deletions src/components/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,9 @@ export const Table = forwardRef<HTMLDivElement, TableProps>(function Table(
return (
<div
ref={ref}
className={cx(
"shadow shadow-offset inline-block min-w-full overflow-x-auto rounded-lg",
className,
)}
className={cx("shadow shadow-offset inline-block min-w-full overflow-x-auto", className)}
>
<div className={"table table-fixed w-full border-collapse"} {...props} />
<div className={"table w-full border-collapse"} {...props} />
</div>
)
})
2 changes: 1 addition & 1 deletion themeGenerator.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function themeGenerator() {
}
const mode = {
base: "slate",
primary: "sky",
primary: "blue",
secondary: "cyan",
success: "emerald",
warning: "amber",
Expand Down

0 comments on commit 7369553

Please sign in to comment.