@valerius_petrini/corekit-ui 0.1.32 → 0.1.34

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.
@@ -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,61 @@
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
+ </script>
48
+
49
+ <div class={combinedDivClass}>
50
+ <label for={id} class={combinedLabelClass}>
51
+ {@render children?.()}
52
+ </label>
53
+ <input
54
+ {id}
55
+ bind:value={value}
56
+ onfocus={handleFocus}
57
+ onblur={handleBlur}
58
+ class={combinedClass}
59
+ {...restProps}
60
+ />
61
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { FloatingInputProps } from "../types/FloatingInput.js";
2
+ declare const FloatingInput: import("svelte").Component<FloatingInputProps, {}, "value">;
3
+ type FloatingInput = ReturnType<typeof FloatingInput>;
4
+ export default FloatingInput;
@@ -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-50 flex items-center";
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,10 @@
1
+ export declare const colorStyles: {
2
+ red: string;
3
+ yellow: string;
4
+ lightgreen: string;
5
+ blue: string;
6
+ pink: string;
7
+ purple: string;
8
+ gray: string;
9
+ };
10
+ export type ColorStyle = keyof typeof colorStyles;
@@ -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
+ };
@@ -1,8 +1,12 @@
1
+ import type { ColorStyle } from "../styles/color.ts";
2
+
1
3
  export interface ButtonProps {
2
4
  children?: any;
3
5
  class?: string;
4
6
  pill?: boolean;
5
7
  icon?: boolean;
6
8
  href?: string;
9
+ color?: ColorStyle;
10
+ size?: number | string;
7
11
  [key: string]: any;
8
12
  }
@@ -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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valerius_petrini/corekit-ui",
3
- "version": "0.1.32",
3
+ "version": "0.1.34",
4
4
  "description": "Component Library used across all my projects",
5
5
  "author": "Valerius Petrini Jr.",
6
6
  "license": "MIT",