diff --git a/.gitignore b/.gitignore index b258c97d..6264fedc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ -dist/ -node_modules -.env \ No newline at end of file +dist/ +node_modules +.env +.idea/ \ No newline at end of file diff --git a/preload/src/api/electron.js b/preload/src/api/electron.js index f8c91558..50bfeac6 100644 --- a/preload/src/api/electron.js +++ b/preload/src/api/electron.js @@ -1,4 +1,4 @@ -import {ipcRenderer as IPC, shell} from "electron"; +import {ipcRenderer as IPC, shell, webUtils} from "electron"; export const ipcRenderer = { send: IPC.send.bind(IPC), @@ -9,4 +9,4 @@ export const ipcRenderer = { off: IPC.off.bind(IPC) }; -export {shell}; \ No newline at end of file +export {shell, webUtils}; \ No newline at end of file diff --git a/renderer/src/styles/ui/file.css b/renderer/src/styles/ui/file.css new file mode 100644 index 00000000..53caff84 --- /dev/null +++ b/renderer/src/styles/ui/file.css @@ -0,0 +1,62 @@ +.bd-file-input-wrap { + position: relative; +} + +.bd-file-input { + color: var(--text-normal); + background-color: var(--input-background); + min-width: 250px; + width: 100%; + font-size: 16px; + border-radius: 3px; + padding: 10px; + height: 40px; + box-sizing: border-box; + overflow: hidden; + border: none; +} + +.bd-file-input::-webkit-file-upload-button { + color: white; + background: #3E82E5; + outline: 0; + border: 0; + padding: 12px 16px!important; + margin-top: -10px; + margin-left: -10px; + margin-right: 10px; + bottom: 0; + border-radius: 3px 0 0 3px; + font-size: 14px; + font-weight: 500; + cursor: pointer; + user-select: none; +} + +.bd-file-input-wrap .bd-file-input-clear { + position: absolute; + top: 50%; + right: 5px; + transform: translateY(-50%); + opacity: 0.5; +} + +.bd-file-input-wrap .bd-file-input-clear:hover { + background: none; + opacity: 1; +} + +.bd-file-input-wrap .bd-file-input-clear svg { + width: 18px !important; + height: 18px !important; +} + +.bd-file-input-wrap.bd-file-input-disabled { + cursor: not-allowed; + opacity: 0.5; +} + +.bd-file-input-wrap.bd-file-input-disabled .bd-file-input, +.bd-file-input-wrap.bd-file-input-disabled .bd-file-input-clear { + pointer-events: none; +} \ No newline at end of file diff --git a/renderer/src/ui/settings/components/file.jsx b/renderer/src/ui/settings/components/file.jsx new file mode 100644 index 00000000..beb4d1ec --- /dev/null +++ b/renderer/src/ui/settings/components/file.jsx @@ -0,0 +1,35 @@ +import {webUtils} from "electron"; +import React from "@modules/react"; +import Button from "@ui/base/button"; +import Close from "@ui/icons/close"; + +const {useRef, useCallback, useEffect} = React; + + +export default function Filepicker({multiple, accept, clearable, onChange, disabled, actions}) { + const inputRef = useRef(null); + + const change = useCallback((e) => { + if (disabled) return; + const files = []; + for (const file of e.target.files) { + files.push(webUtils.getPathForFile(file)); + } + onChange?.(multiple ? files : files[0]); + }, [onChange, disabled, multiple]); + + const clear = useCallback(() => { + inputRef.current.value = ""; + onChange?.(multiple ? [] : ""); + }, [onChange, multiple]); + + useEffect(() => { + if (!actions) return; + actions.clear = clear; + }, [clear, actions]); + + return