@valerius_petrini/corekit-ui 0.1.46 → 0.1.48

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,5 +1,6 @@
1
1
  <script lang="ts">
2
- import { colorStyles } from "../styles/color.js";
2
+ import { generateColorStyle } from "../styles/color.js";
3
+ import { sizeStyleParts, type SizeStyle } from "../styles/size.js";
3
4
  import type { ButtonProps } from "../types/Button.js";
4
5
  import { twMerge } from "tailwind-merge";
5
6
 
@@ -9,26 +10,55 @@
9
10
  pill = false,
10
11
  icon = false,
11
12
  href = undefined,
12
- color = undefined,
13
- size = undefined,
13
+ color = "none",
14
+ variant = "full",
15
+ disabled = false,
16
+ external = false,
17
+ size = "md",
18
+ radius = "md",
14
19
  ...restProps
15
20
  }: ButtonProps = $props();
16
21
 
17
- function getSizeStyles(size?: number | string) {
18
- if (typeof size === "number")
19
- return `w-${size} h-${size}`;
20
- return "";
21
- }
22
+ const sizeClasses = $derived.by(() => {
23
+ if (typeof size === "string") {
24
+ const parts = sizeStyleParts[size as SizeStyle];
25
+ return icon ? parts.buttonIcon : parts.button;
26
+ }
27
+ return icon ? "p-0 flex-none" : "h-fit";
28
+ });
22
29
 
23
- let pillClass = "rounded-full";
24
- let iconClass = "rounded-full p-2 flex-center";
25
- let defaultClass = $derived(twMerge(
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)));
30
+ const customStyle = $derived(
31
+ typeof size === "number"
32
+ ? `width: ${size}px; height: ${size}px; flex: none;`
33
+ : ""
34
+ );
28
35
 
29
- let combinedClass = $derived(twMerge(defaultClass, className));
36
+ const defaultClass = "inline-flex items-center justify-center gap-2 transition-colors duration-300 text-white whitespace-nowrap";
37
+ const radiusClass = $derived(pill || icon ? "rounded-full" : sizeStyleParts[radius as SizeStyle].radius);
38
+ const disabledClass = $derived(disabled ? "opacity-50 pointer-events-none" : "cursor-pointer");
39
+
40
+ const mergedClass = $derived(twMerge(
41
+ defaultClass,
42
+ generateColorStyle(color, variant),
43
+ disabledClass,
44
+ sizeClasses,
45
+ radiusClass,
46
+ className
47
+ ));
48
+
49
+ const mergedStyle = $derived([customStyle, restProps.style].filter(Boolean).join("; "));
30
50
  </script>
31
51
 
32
- <svelte:element this={href ? "a" : "button"} class={combinedClass} {href} {...restProps}>
52
+ <svelte:element
53
+ this={href ? "a" : "button"}
54
+ class={mergedClass}
55
+ {disabled}
56
+ aria-disabled={disabled}
57
+ type={href ? undefined : (restProps.type || "button")}
58
+ style={mergedStyle}
59
+ target={external ? "_blank" : undefined}
60
+ rel={external ? "noopener noreferrer" : undefined}
61
+ {...(href ? { href } : {})}
62
+ {...restProps}>
33
63
  {@render children?.()}
34
64
  </svelte:element>
@@ -10,7 +10,7 @@
10
10
  ...restProps
11
11
  }: CardProps = $props();
12
12
 
13
- let defaultClass = "text-main-text shadow-xl rounded-lg transition-colors bg-sub-background hover:bg-sub-background-hover p-4";
13
+ let defaultClass = "text-main-text shadow-xl radius-lg transition-colors bg-sub-background hover:bg-sub-background-hover p-4";
14
14
  let combinedClass = $derived(twMerge(defaultClass, className));
15
15
  </script>
16
16
 
@@ -0,0 +1,35 @@
1
+ <script lang="ts">
2
+ import { twMerge } from "tailwind-merge";
3
+ import Text from "./Text.svelte";
4
+ import type { CheckboxProps } from "../types/Checkbox.js";
5
+
6
+ let {
7
+ children = undefined,
8
+ class: className = "",
9
+ labelClass = "",
10
+ divClass = "",
11
+ checked = $bindable(),
12
+ id = crypto.randomUUID(),
13
+ ...restProps
14
+ }: CheckboxProps = $props();
15
+
16
+ let defaultClass = "z-20 bg-form-input-background text-main-text rounded-lg outline-none focus:ring-2 focus:ring-blue-500 transition-all";
17
+ let defaultLabelClass = "block text-sub-text font-medium";
18
+ let defaultDivClass = "relative flex items-center gap-2";
19
+
20
+ let combinedLabelClass = $derived(twMerge(defaultLabelClass, labelClass));
21
+ let combinedClass = $derived(twMerge(defaultClass, className));
22
+ let combinedDivClass = $derived(twMerge(defaultDivClass, divClass));
23
+ </script>
24
+
25
+ <div class={combinedDivClass}>
26
+ <input
27
+ type="checkbox"
28
+ id={id}
29
+ bind:checked={checked}
30
+ class={combinedClass}
31
+ {...restProps}/>
32
+ <Text tag="label" for={id} class={combinedLabelClass}>
33
+ {@render children?.()}
34
+ </Text>
35
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { CheckboxProps } from "../types/Checkbox.js";
2
+ declare const Checkbox: import("svelte").Component<CheckboxProps, {}, "checked">;
3
+ type Checkbox = ReturnType<typeof Checkbox>;
4
+ export default Checkbox;
@@ -6,7 +6,7 @@
6
6
  let {
7
7
  children = undefined,
8
8
  class: className = "",
9
- divName = "",
9
+ divClass = "",
10
10
  optionClass = "",
11
11
  value = $bindable(),
12
12
  options = [],
@@ -22,7 +22,7 @@
22
22
 
23
23
  let combinedLabelClass = $derived(twMerge(defaultLabelClass, selectedLabelClass, className));
24
24
  let combinedSelectClass = $derived(twMerge(defaultSelectClass, className));
25
- let combinedDivClass = $derived(twMerge(defaultDivClass, divName));
25
+ let combinedDivClass = $derived(twMerge(defaultDivClass, divClass));
26
26
  </script>
27
27
 
28
28
  <div class={combinedDivClass}>
@@ -12,7 +12,7 @@
12
12
  ...restProps
13
13
  }: NavbarElementProps = $props();
14
14
 
15
- let defaultClass = "navbar-element w-fit h-full flex items-center px-5 py-0 text-main-text hover:bg-navbar-element-hover-background rounded-none";
15
+ let defaultClass = "navbar-element w-fit h-full px-5 py-0 text-main-text hover:bg-navbar-element-hover-background";
16
16
 
17
17
  let scrollY = $state(0);
18
18
 
@@ -34,6 +34,6 @@
34
34
  });
35
35
  </script>
36
36
 
37
- <Button {href} class={combinedClass} {...restProps}>
37
+ <Button radius={0} {href} class={combinedClass} {...restProps}>
38
38
  {@render children?.()}
39
39
  </Button>
@@ -18,8 +18,8 @@
18
18
  "em": "text-base italic",
19
19
  "small": "text-sm",
20
20
  "blockquote": "border-l-4 border-gray-500 pl-2 opacity-70",
21
- "pre": "font-mono bg-sub-background px-3 py-2 rounded overflow-x-auto whitespace-pre",
22
- "code": "font-mono bg-sub-background px-3 py-2 rounded inline-block",
21
+ "pre": "font-mono bg-sub-background px-3 py-2 radius overflow-x-auto whitespace-pre",
22
+ "code": "font-mono bg-sub-background px-3 py-2 radius inline-block",
23
23
  "a": "text-blue-400 hover:text-blue-500 hover:underline",
24
24
  "li": "text-base list-disc list-inside",
25
25
  "h1": "text-6xl font-extrabold",
@@ -31,7 +31,7 @@
31
31
  };
32
32
 
33
33
  let defaultClass = "text-main-text";
34
- let combinedClass = $derived(twMerge(defaultClass, className, tagStyles[tag] || ""));
34
+ let combinedClass = $derived(twMerge(defaultClass, tagStyles[tag] || "", className));
35
35
  </script>
36
36
 
37
37
  <svelte:element this={tag} class={combinedClass} {...restProps}>
@@ -1,11 +1,4 @@
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
- sub: string;
10
- };
11
- export type ColorStyle = keyof typeof colorStyles;
1
+ export type ColorStyle = "red" | "yellow" | "lightgreen" | "blue" | "pink" | "purple" | "gray" | "sub" | "none";
2
+ export type ColorStyleType = "full" | "light" | "outline" | "ghost";
3
+ export declare const colorStyleParts: Record<ColorStyle, Record<ColorStyleType, string>>;
4
+ export declare function generateColorStyle(color: ColorStyle, variant: ColorStyleType): string;
@@ -1,10 +1,62 @@
1
- export const colorStyles = {
2
- red: "bg-red-500 hover:bg-red-600",
3
- yellow: "bg-yellow-500 hover:bg-yellow-600",
4
- lightgreen: "bg-green-500 hover:bg-green-600",
5
- blue: "bg-blue-500 hover:bg-blue-600",
6
- pink: "bg-pink-500 hover:bg-pink-600",
7
- purple: "bg-purple-500 hover:bg-purple-600",
8
- gray: "bg-gray-500 hover:bg-gray-600",
9
- sub: "bg-sub-background hover:bg-sub-background-hover"
1
+ export const colorStyleParts = {
2
+ red: {
3
+ full: "bg-red-500 hover:bg-red-600",
4
+ light: "bg-red-500/35 hover:bg-red-600/35 text-white/60",
5
+ outline: "border border-red-500 hover:border-red-600 text-red-500 hover:text-red-600 hover:bg-red-500/10",
6
+ ghost: "hover:bg-red-500"
7
+ },
8
+ yellow: {
9
+ full: "bg-yellow-500 hover:bg-yellow-600",
10
+ light: "bg-yellow-500/35 hover:bg-yellow-600/35 text-white/60",
11
+ outline: "border border-yellow-500 hover:border-yellow-600 text-yellow-500 hover:text-yellow-600 hover:bg-yellow-500/10",
12
+ ghost: "hover:bg-yellow-500"
13
+ },
14
+ lightgreen: {
15
+ full: "bg-green-500 hover:bg-green-600",
16
+ light: "bg-green-500/35 hover:bg-green-600/35 text-white/60",
17
+ outline: "border border-green-500 hover:border-green-600 text-green-500 hover:text-green-600 hover:bg-green-500/10",
18
+ ghost: "hover:bg-green-500"
19
+ },
20
+ blue: {
21
+ full: "bg-blue-500 hover:bg-blue-600",
22
+ light: "bg-blue-500/35 hover:bg-blue-600/35 text-white/60",
23
+ outline: "border border-blue-500 hover:border-blue-600 text-blue-500 hover:text-blue-600 hover:bg-blue-500/10",
24
+ ghost: "hover:bg-blue-500"
25
+ },
26
+ pink: {
27
+ full: "bg-pink-500 hover:bg-pink-600",
28
+ light: "bg-pink-500/35 hover:bg-pink-600/35 text-white/60",
29
+ outline: "border border-pink-500 hover:border-pink-600 text-pink-500 hover:text-pink-600 hover:bg-pink-500/10",
30
+ ghost: "hover:bg-pink-500"
31
+ },
32
+ purple: {
33
+ full: "bg-purple-500 hover:bg-purple-600",
34
+ light: "bg-purple-500/35 hover:bg-purple-600/35 text-white/60",
35
+ outline: "border border-purple-500 hover:border-purple-600 text-purple-500 hover:text-purple-600 hover:bg-purple-500/10",
36
+ ghost: "hover:bg-purple-500"
37
+ },
38
+ gray: {
39
+ full: "bg-gray-500 hover:bg-gray-600",
40
+ light: "bg-gray-500/35 hover:bg-gray-600/35 text-white/60",
41
+ outline: "border border-gray-500 hover:border-gray-600 text-gray-500 hover:text-gray-600 hover:bg-gray-500/10",
42
+ ghost: "hover:bg-gray-500"
43
+ },
44
+ sub: {
45
+ full: "bg-sub-background hover:bg-sub-background-hover",
46
+ light: "bg-sub-background hover:bg-sub-background-hover text-white/60",
47
+ outline: "border border-sub-background hover:border-sub-background-hover text-sub-background hover:text-sub-background-hover hover:bg-sub-background/10",
48
+ ghost: "hover:bg-sub-background"
49
+ },
50
+ none: {
51
+ full: "",
52
+ light: "",
53
+ outline: "",
54
+ ghost: ""
55
+ }
10
56
  };
57
+ export function generateColorStyle(color, variant) {
58
+ const styles = colorStyleParts[color];
59
+ if (!styles)
60
+ return "";
61
+ return styles[variant] || "";
62
+ }
@@ -0,0 +1,3 @@
1
+ export type SizeStyle = "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | "full" | "none" | number;
2
+ export type SizeStyleType = "button" | "buttonIcon" | "radius";
3
+ export declare const sizeStyleParts: Record<SizeStyle, Record<SizeStyleType, string>>;
@@ -0,0 +1,57 @@
1
+ export const sizeStyleParts = {
2
+ xs: {
3
+ button: "text-xs h-4 px-1 py-0.5",
4
+ buttonIcon: "text-xs h-4 w-4 p-0.5",
5
+ radius: "rounded-xs"
6
+ },
7
+ sm: {
8
+ button: "text-sm h-6 px-2 py-1",
9
+ buttonIcon: "text-sm h-6 w-6 p-1",
10
+ radius: "rounded-sm"
11
+ },
12
+ md: {
13
+ button: "text-base h-8 px-3 py-1.5",
14
+ buttonIcon: "text-base h-8 w-8 p-1.5",
15
+ radius: "rounded-md"
16
+ },
17
+ lg: {
18
+ button: "text-lg h-10 px-4 py-2",
19
+ buttonIcon: "text-lg h-10 w-10 p-2",
20
+ radius: "rounded-lg"
21
+ },
22
+ xl: {
23
+ button: "text-xl h-12 px-5 py-2.5",
24
+ buttonIcon: "text-xl h-12 w-12 p-2.5",
25
+ radius: "rounded-xl"
26
+ },
27
+ "2xl": {
28
+ button: "text-2xl h-14 px-6 py-3",
29
+ buttonIcon: "text-2xl h-14 w-14 p-3",
30
+ radius: "rounded-2xl"
31
+ },
32
+ "3xl": {
33
+ button: "text-3xl h-16 px-7 py-3.5",
34
+ buttonIcon: "text-3xl h-16 w-16 p-3.5",
35
+ radius: "rounded-3xl"
36
+ },
37
+ "4xl": {
38
+ button: "text-4xl h-18 px-8 py-4",
39
+ buttonIcon: "text-4xl h-18 w-18 p-4",
40
+ radius: "rounded-4xl"
41
+ },
42
+ full: {
43
+ button: "w-full text-base h-8 px-3 py-1",
44
+ buttonIcon: "w-full aspect-square text-base p-1",
45
+ radius: "rounded-full"
46
+ },
47
+ none: {
48
+ button: "",
49
+ buttonIcon: "",
50
+ radius: "rounded-none"
51
+ },
52
+ 0: {
53
+ button: "",
54
+ buttonIcon: "",
55
+ radius: "rounded-none"
56
+ }
57
+ };
@@ -1,4 +1,5 @@
1
- import type { ColorStyle } from "../styles/color.ts";
1
+ import type { ColorStyle, ColorStyleType } from "../styles/color.ts";
2
+ import type { SizeStyle } from "../styles/size.ts";
2
3
 
3
4
  export interface ButtonProps {
4
5
  children?: any;
@@ -7,6 +8,10 @@ export interface ButtonProps {
7
8
  icon?: boolean;
8
9
  href?: string;
9
10
  color?: ColorStyle;
10
- size?: number | string;
11
+ variant?: ColorStyleType;
12
+ disabled?: boolean;
13
+ external?: boolean;
14
+ size?: SizeStyle;
15
+ radius?: SizeStyle;
11
16
  [key: string]: any;
12
17
  }
@@ -0,0 +1,9 @@
1
+ export interface CheckboxProps {
2
+ children?: any;
3
+ class?: string;
4
+ labelClass?: string;
5
+ divClass?: string;
6
+ checked?: boolean;
7
+ id?: string;
8
+ [key: string]: any;
9
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valerius_petrini/corekit-ui",
3
- "version": "0.1.46",
3
+ "version": "0.1.48",
4
4
  "description": "Component Library used across all my projects",
5
5
  "author": "Valerius Petrini Jr.",
6
6
  "license": "MIT",