@valerius_petrini/corekit-ui 0.1.59 → 0.1.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,113 @@
1
+ <script lang="ts">
2
+ import { getSizeStyle, getSizeStyleClass } from "../styles/size.js";
3
+ import type { FileInputProps } from "../types/Input.js";
4
+ import { twMerge } from "tailwind-merge";
5
+ import Text from "./Text.svelte";
6
+ import bytes from "bytes";
7
+
8
+ import Upload from "@lucide/svelte/icons/upload";
9
+ import File from "@lucide/svelte/icons/file";
10
+ import Button from "./Button.svelte";
11
+
12
+ let {
13
+ children = undefined,
14
+ class: className = "",
15
+ label = undefined,
16
+ labelClass = "",
17
+ divClass = "",
18
+ outerDivClass = "",
19
+ files = $bindable(undefined),
20
+ required = false,
21
+ disabled = false,
22
+ size = "md",
23
+ radius = "md",
24
+ id = crypto.randomUUID(),
25
+ ...restProps
26
+ }: FileInputProps = $props();
27
+
28
+ let inputElement: HTMLInputElement;
29
+
30
+ const defaultClass = "text-main-text w-full flex items-center gap-1 rounded-full outline-none px-1.5 w-full bg-inherit border-0 py-0";
31
+ const defaultLabelClass = "block text-sub-text font-medium mb-1 pointer-events-none truncate w-fit";
32
+ const defaultDivClass = "relative flex-center gap-0 bg-form-background border-[1px] border-form-border p-0";
33
+
34
+ const divFullClass = $derived(size === "full" ? "w-full" : "");
35
+ const disabledClass = $derived(disabled ? "opacity-50 pointer-events-none" : "");
36
+
37
+ const iconContainerClass = "h-5 aspect-square px-1 py-0!";
38
+ const iconClass = "h-full aspect-square text-sub-text";
39
+
40
+ const selectedDivClass = $derived(files ? "border-blue-500 cursor-default" : "hover:bg-form-hover cursor-pointer");
41
+
42
+ const combinedOuterDivClass = $derived(twMerge(
43
+ "flex flex-col bg-transparent border-0 p-0",
44
+ divFullClass,
45
+ outerDivClass,
46
+ disabledClass
47
+ ));
48
+ const combinedLabelClass = $derived(twMerge(
49
+ defaultLabelClass,
50
+ getSizeStyleClass(size, "formLabel"),
51
+ labelClass
52
+ ));
53
+ const combinedDivClass = $derived(twMerge(
54
+ defaultDivClass,
55
+ selectedDivClass,
56
+ getSizeStyleClass(radius, "radius"),
57
+ divFullClass,
58
+ divClass,
59
+ ));
60
+ let combinedClass = $derived(twMerge(
61
+ getSizeStyleClass(size, "form"),
62
+ defaultClass,
63
+ className,
64
+ ));
65
+
66
+ const Icon = $derived(files ? File : Upload);
67
+
68
+ function handleClick() {
69
+ if (!files) inputElement.click();
70
+ }
71
+
72
+ function handleClear(e: MouseEvent) {
73
+ e.stopPropagation();
74
+ files = undefined;
75
+ }
76
+ </script>
77
+
78
+ <div class={combinedOuterDivClass}>
79
+ <Text tag="label" for={id} class={combinedLabelClass} style={getSizeStyle(size, "formLabel")}>
80
+ {label}
81
+ {#if required}
82
+ <span class="text-[#E05555]">*</span>
83
+ {/if}
84
+ </Text>
85
+ <Button color="none" class={combinedDivClass} onclick={handleClick} {disabled}>
86
+ <div class={iconContainerClass}>
87
+ <Icon class={iconClass}></Icon>
88
+ </div>
89
+ <input
90
+ {id}
91
+ bind:files={files}
92
+ bind:this={inputElement}
93
+ class="hidden"
94
+ {required}
95
+ {disabled}
96
+ aria-disabled={disabled}
97
+ {...restProps}
98
+ type="file"
99
+ />
100
+ <Text class={combinedClass}>
101
+ {files ? files[0]?.name : "Upload File"}
102
+ <Text tag="span" class="text-sub-text text-xs pt-0.75">
103
+ {files ? bytes(files[0]?.size || 0) : ""}
104
+ </Text>
105
+ </Text>
106
+
107
+ {#if files}
108
+ <Button color="blue" variant="outline" size="xs" class="ml-auto mr-2" onclick={handleClear} {disabled}>
109
+ Clear
110
+ </Button>
111
+ {/if}
112
+ </Button>
113
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { FileInputProps } from "../types/Input.js";
2
+ declare const FileInput: import("svelte").Component<FileInputProps, {}, "files">;
3
+ type FileInput = ReturnType<typeof FileInput>;
4
+ export default FileInput;
@@ -105,7 +105,7 @@
105
105
  }[restProps.type as string] as Component ?? null));
106
106
 
107
107
  let defaultClass = "text-main-text w-full rounded-full outline-none px-1.5 w-full bg-inherit border-0 focus:ring-0 focus-visible:ring-0";
108
- let defaultLabelClass = "block text-sub-text rounded-md font-medium mb-1 duration-100 pointer-events-none truncate w-fit";
108
+ let defaultLabelClass = "block text-sub-text font-medium mb-1 duration-100 pointer-events-none truncate w-fit";
109
109
  let defaultDivClass = "relative *:transition-all flex-center bg-form-background border-[1px] border-form-border focus-within:ring-1 focus-within:ring-blue-500";
110
110
  let iconContainerClass = "h-5 aspect-square px-1 py-0!";
111
111
  let floatingLabelClass = "absolute w-full";
@@ -119,7 +119,7 @@
119
119
 
120
120
  let floatingLabelClassFull = $derived(twMerge(originalLabelClassInput, originalLabelClass, floatingLabelClass));
121
121
  let divFullClass = $derived(size === "full" ? "w-full" : "");
122
- let disabledClass = $derived(disabled ? "opacity-50 pointer-events-none" : "cursor-pointer");
122
+ let disabledClass = $derived(disabled ? "opacity-50 pointer-events-none" : "");
123
123
 
124
124
  function handleFocus(e: FocusEvent) {
125
125
  isFocused = true;
@@ -137,7 +137,7 @@
137
137
 
138
138
  let defaultInputClassCheck = $derived(variant !== "floating" ? "py-0" : "");
139
139
  let floatingLabelClassCheck = $derived(variant === "floating" ? floatingLabelClassFull : "");
140
- let defaultLabelClassCheck = $derived(variant !== "floating" ? "px-1.5" : "");
140
+ let defaultLabelClassCheck = $derived(variant !== "floating" ? "px-0" : "");
141
141
  let selectedLabelClass = $derived(twMerge((isFocused || hasContent) && variant === "floating" ? `${originalSelectedLabelClass} ${selectedLabelSizeClass}` : ""));
142
142
  let combinedLabelClass = $derived(twMerge(defaultLabelClass, floatingLabelClassCheck, labelSizeClass, selectedLabelClass, labelClassIcon, defaultLabelClassCheck, labelClass));
143
143
  let combinedClass = $derived(twMerge(defaultClass, sizeClasses, defaultInputClassCheck, labelSizeClass, inputClassIcon, className, isValid ? "" : invalidClass));
@@ -9,15 +9,17 @@
9
9
  });
10
10
  </script>
11
11
 
12
- {#each Object.keys(positionParts) as pos (pos)}
13
- <div class="fixed z-9999 flex flex-col gap-2 pointer-events-none {positionParts[pos as PositionStyle]}">
14
- {#each getItems(pos as PositionStyle) as item (item.id)}
15
- <div class="pointer-events-auto" animate:flip={{ duration: 300 }}>
16
- <Toast
17
- {...item}
18
- onclose={() => toast.dismiss(item.id)}
19
- />
20
- </div>
21
- {/each}
22
- </div>
23
- {/each}
12
+ <div>
13
+ {#each Object.keys(positionParts) as pos (pos)}
14
+ <div class="fixed z-9999 flex flex-col gap-2 pointer-events-none {positionParts[pos as PositionStyle]}">
15
+ {#each getItems(pos as PositionStyle) as item (item.id)}
16
+ <div class="pointer-events-auto" animate:flip={{ duration: 300 }}>
17
+ <Toast
18
+ {...item}
19
+ onclose={() => toast.dismiss(item.id)}
20
+ />
21
+ </div>
22
+ {/each}
23
+ </div>
24
+ {/each}
25
+ </div>
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export { default as Navbar } from "./components/Navbar.svelte";
6
6
  export { default as NavbarSeparator } from "./components/NavbarSeparator.svelte";
7
7
  export { default as NavbarElement } from "./components/NavbarElement.svelte";
8
8
  export { default as Input } from "./components/Input.svelte";
9
+ export { default as FileInput } from "./components/FileInput.svelte";
9
10
  export { default as Select } from "./components/Select.svelte";
10
11
  export { default as Text } from "./components/Text.svelte";
11
12
  export { default as Card } from "./components/Card.svelte";
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ export { default as Navbar } from "./components/Navbar.svelte";
6
6
  export { default as NavbarSeparator } from "./components/NavbarSeparator.svelte";
7
7
  export { default as NavbarElement } from "./components/NavbarElement.svelte";
8
8
  export { default as Input } from "./components/Input.svelte";
9
+ export { default as FileInput } from "./components/FileInput.svelte";
9
10
  export { default as Select } from "./components/Select.svelte";
10
11
  export { default as Text } from "./components/Text.svelte";
11
12
  export { default as Card } from "./components/Card.svelte";
@@ -47,7 +47,7 @@ html.dark {
47
47
  --vpcui-dark-50: #121212;
48
48
  --vpcui-dark-100: #1E1E1E;
49
49
  --vpcui-dark-150: #2A2A2A;
50
- --vpcui-dark-200: #2A2A2A;
50
+ --vpcui-dark-200: #3A3A3A;
51
51
  --vpcui-dark-250: #4A4A4A;
52
52
  --vpcui-dark-300: #A0A0A0;
53
53
 
@@ -61,7 +61,7 @@ html.dark {
61
61
  --vpcui-contrast-text: var(--vpcui-dark-950);
62
62
  --vpcui-form-background: var(--vpcui-dark-150);
63
63
  --vpcui-form-border: var(--vpcui-dark-250);
64
- --vpcui-form-hover: var(--vpcui-dark-150);
64
+ --vpcui-form-hover: var(--vpcui-dark-200);
65
65
  }
66
66
 
67
67
  html {
@@ -23,3 +23,15 @@ export interface InputProps extends BaseComponentProps {
23
23
  radius?: SizeStyle;
24
24
  id?: `${string}-${string}-${string}-${string}-${string}`;
25
25
  }
26
+ export interface FileInputProps extends BaseComponentProps {
27
+ label?: string;
28
+ labelClass?: string;
29
+ divClass?: string;
30
+ outerDivClass?: string;
31
+ files?: FileList;
32
+ required?: boolean;
33
+ disabled?: boolean;
34
+ size?: SizeStyle;
35
+ radius?: SizeStyle;
36
+ id?: `${string}-${string}-${string}-${string}-${string}`;
37
+ }
@@ -1,2 +1,3 @@
1
1
  ;
2
+ ;
2
3
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valerius_petrini/corekit-ui",
3
- "version": "0.1.59",
3
+ "version": "0.1.60",
4
4
  "description": "Component Library used across all my projects",
5
5
  "author": "Valerius Petrini Jr.",
6
6
  "license": "MIT",
@@ -42,6 +42,7 @@
42
42
  "@tailwindcss/forms": "^0.5.11",
43
43
  "@tailwindcss/typography": "^0.5.19",
44
44
  "@tailwindcss/vite": "^4.1.18",
45
+ "@types/bytes": "^3.1.5",
45
46
  "publint": "^0.3.17",
46
47
  "svelte": "^5.51.0",
47
48
  "svelte-check": "^4.4.2",
@@ -55,6 +56,7 @@
55
56
  ],
56
57
  "dependencies": {
57
58
  "@lucide/svelte": "^1.3.0",
59
+ "bytes": "^3.1.2",
58
60
  "tailwind-merge": "^3.5.0"
59
61
  }
60
62
  }