@valerius_petrini/corekit-ui 0.1.32 → 0.1.33
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.
- package/dist/components/Button.svelte +11 -2
- package/dist/components/FloatingInput.svelte +63 -0
- package/dist/components/FloatingInput.svelte.d.ts +4 -0
- package/dist/components/Navbar.svelte +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/styles/color.d.ts +10 -0
- package/dist/styles/color.js +9 -0
- package/dist/types/Button.d.ts +4 -0
- package/dist/types/FloatingInput.d.ts +12 -0
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { colorStyles } from "../styles/color.js";
|
|
2
3
|
import type { ButtonProps } from "../types/Button.js";
|
|
3
4
|
import { twMerge } from "tailwind-merge";
|
|
4
5
|
|
|
@@ -8,14 +9,22 @@
|
|
|
8
9
|
pill = false,
|
|
9
10
|
icon = false,
|
|
10
11
|
href = undefined,
|
|
12
|
+
color = undefined,
|
|
13
|
+
size = undefined,
|
|
11
14
|
...restProps
|
|
12
15
|
}: ButtonProps = $props();
|
|
13
16
|
|
|
17
|
+
function getSizeStyles(size?: number | string) {
|
|
18
|
+
if (typeof size === "number")
|
|
19
|
+
return `w-${size} h-${size}`;
|
|
20
|
+
return "";
|
|
21
|
+
}
|
|
22
|
+
|
|
14
23
|
let pillClass = "rounded-full";
|
|
15
24
|
let iconClass = "rounded-full p-2 flex-center";
|
|
16
25
|
let defaultClass = $derived(twMerge(
|
|
17
|
-
"text-white cursor-pointer px-2 py-1 transition-colors duration-300",
|
|
18
|
-
(pill ? pillClass : ""), (icon ? iconClass : "")));
|
|
26
|
+
"text-white cursor-pointer px-2 py-1 transition-colors duration-300 rounded-md",
|
|
27
|
+
(pill ? pillClass : ""), (icon ? iconClass : ""), color ? colorStyles[color] : "", getSizeStyles(size)));
|
|
19
28
|
|
|
20
29
|
let combinedClass = $derived(twMerge(defaultClass, className));
|
|
21
30
|
</script>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { FloatingInputProps } from "../types/FloatingInput.js";
|
|
3
|
+
import { twMerge } from "tailwind-merge";
|
|
4
|
+
|
|
5
|
+
let {
|
|
6
|
+
children = undefined,
|
|
7
|
+
class: className = "",
|
|
8
|
+
labelClass = "",
|
|
9
|
+
divClass = "",
|
|
10
|
+
value = $bindable(),
|
|
11
|
+
onfocus = undefined,
|
|
12
|
+
onblur = undefined,
|
|
13
|
+
validInputRegex = undefined,
|
|
14
|
+
id = crypto.randomUUID(),
|
|
15
|
+
...restProps
|
|
16
|
+
}: FloatingInputProps = $props();
|
|
17
|
+
|
|
18
|
+
let isFocused = $state(false);
|
|
19
|
+
let touched = $state(false);
|
|
20
|
+
|
|
21
|
+
let hasContent = $derived(value !== undefined && value !== null && value.toString().length > 0);
|
|
22
|
+
let isValid = $derived(!touched || !validInputRegex || validInputRegex.test(value || ""));
|
|
23
|
+
|
|
24
|
+
let defaultClass = "z-20 w-full border rounded px-3 py-2 outline-none focus:ring-2 focus:ring-blue-500 transition-all";
|
|
25
|
+
let defaultLabelClass = "block text-sm font-medium text-gray-700 mb-1 absolute transition-all duration-100 pointer-events-none";
|
|
26
|
+
let defaultDivClass = "relative";
|
|
27
|
+
|
|
28
|
+
let originalLabelClass = "left-3 top-1/2 transform -translate-y-1/2 z-0";
|
|
29
|
+
let selectedLabelClass = "left-2 z-30 bg-white px-1 top-0 transform -translate-y-1/2 text-xs";
|
|
30
|
+
|
|
31
|
+
let invalidClass = "border-red-500 focus:ring-red-500";
|
|
32
|
+
|
|
33
|
+
let combinedLabelClass = $derived(twMerge(defaultLabelClass, isFocused || hasContent ? selectedLabelClass : originalLabelClass, labelClass));
|
|
34
|
+
let combinedClass = $derived(twMerge(defaultClass, className, isValid ? "" : invalidClass));
|
|
35
|
+
let combinedDivClass = $derived(twMerge(defaultDivClass, divClass));
|
|
36
|
+
|
|
37
|
+
function handleFocus(e: FocusEvent) {
|
|
38
|
+
isFocused = true;
|
|
39
|
+
onfocus?.(e);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function handleBlur(e: FocusEvent) {
|
|
43
|
+
isFocused = false;
|
|
44
|
+
touched = true;
|
|
45
|
+
onblur?.(e);
|
|
46
|
+
|
|
47
|
+
isValid = !(validInputRegex && !validInputRegex.test(value || ""))
|
|
48
|
+
}
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<div class={combinedDivClass}>
|
|
52
|
+
<label for={id} class={combinedLabelClass}>
|
|
53
|
+
{@render children?.()}
|
|
54
|
+
</label>
|
|
55
|
+
<input
|
|
56
|
+
{id}
|
|
57
|
+
bind:value={value}
|
|
58
|
+
onfocus={handleFocus}
|
|
59
|
+
onblur={handleBlur}
|
|
60
|
+
class={combinedClass}
|
|
61
|
+
{...restProps}
|
|
62
|
+
/>
|
|
63
|
+
</div>
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
...restProps
|
|
11
11
|
}: NavbarProps = $props();
|
|
12
12
|
|
|
13
|
-
let defaultClass = "transition-colors duration-300 fixed top-0 left-0 w-full h-14 z-
|
|
13
|
+
let defaultClass = "transition-colors duration-300 fixed top-0 left-0 w-full h-14 z-[100] flex items-center";
|
|
14
14
|
|
|
15
15
|
let scrollY = $state(0);
|
|
16
16
|
|
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ export { default as SEO } from "./components/SEO.svelte";
|
|
|
5
5
|
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
|
+
export { default as FloatingInput } from "./components/FloatingInput.svelte";
|
|
8
9
|
export { fbmBackground } from "./actions/fbm.ts";
|
|
9
10
|
export type { TypewriterAction, DisplaySegment } from "./types/Typewriter.d.ts";
|
package/dist/index.js
CHANGED
|
@@ -5,4 +5,5 @@ export { default as SEO } from "./components/SEO.svelte";
|
|
|
5
5
|
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
|
+
export { default as FloatingInput } from "./components/FloatingInput.svelte";
|
|
8
9
|
export { fbmBackground } from "./actions/fbm.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const colorStyles = {
|
|
2
|
+
red: "bg-red-500 hover:bg-red-600 focus:ring-red-300",
|
|
3
|
+
yellow: "bg-yellow-500 hover:bg-yellow-600 focus:ring-yellow-300",
|
|
4
|
+
lightgreen: "bg-green-500 hover:bg-green-600 focus:ring-green-300",
|
|
5
|
+
blue: "bg-blue-500 hover:bg-blue-600 focus:ring-blue-300",
|
|
6
|
+
pink: "bg-pink-500 hover:bg-pink-600 focus:ring-pink-300",
|
|
7
|
+
purple: "bg-purple-500 hover:bg-purple-600 focus:ring-purple-300",
|
|
8
|
+
gray: "bg-gray-500 hover:bg-gray-600 focus:ring-gray-300",
|
|
9
|
+
};
|
package/dist/types/Button.d.ts
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface FloatingInputProps {
|
|
2
|
+
children?: any;
|
|
3
|
+
class?: string;
|
|
4
|
+
labelClass?: string;
|
|
5
|
+
divClass?: string;
|
|
6
|
+
value?: string;
|
|
7
|
+
onfocus?: (e?: FocusEvent) => void;
|
|
8
|
+
onblur?: (e?: FocusEvent) => void;
|
|
9
|
+
validInputRegex?: RegExp;
|
|
10
|
+
id?: `${string}-${string}-${string}-${string}-${string}`;
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
};
|