@korsolutions/ui 0.0.3 → 0.0.5

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.
Files changed (74) hide show
  1. package/dist/components/index.d.mts +84 -0
  2. package/dist/components/index.mjs +288 -0
  3. package/dist/index-Dafk8ZGv.d.mts +265 -0
  4. package/dist/index.d.mts +45 -0
  5. package/dist/index.mjs +11 -0
  6. package/dist/portal-DoPaAohb.mjs +61 -0
  7. package/dist/primitives/index.d.mts +2 -0
  8. package/dist/primitives/index.mjs +4 -0
  9. package/dist/primitives-BYUlEz2_.mjs +442 -0
  10. package/dist/themes-BrLbh9h6.mjs +86 -0
  11. package/package.json +20 -8
  12. package/src/components/button/button.tsx +24 -0
  13. package/src/components/button/variants/default.tsx +52 -0
  14. package/src/components/button/variants/index.ts +5 -0
  15. package/src/components/card/card.tsx +26 -0
  16. package/src/components/card/variants/default.tsx +38 -0
  17. package/src/components/card/variants/index.ts +5 -0
  18. package/src/components/field/field.tsx +27 -0
  19. package/src/components/field/variants/default.tsx +29 -0
  20. package/src/components/field/variants/index.ts +5 -0
  21. package/src/components/index.ts +5 -0
  22. package/src/components/input/input.tsx +14 -0
  23. package/src/components/input/variants/default.tsx +34 -0
  24. package/src/components/input/variants/index.ts +5 -0
  25. package/src/components/select/select.tsx +35 -0
  26. package/src/components/select/variants/default.tsx +81 -0
  27. package/src/components/select/variants/index.ts +5 -0
  28. package/src/index.tsx +13 -0
  29. package/src/primitives/button/button-context.tsx +5 -5
  30. package/src/primitives/button/button-label.tsx +7 -5
  31. package/src/primitives/button/button-root.tsx +12 -8
  32. package/src/primitives/button/button-spinner.tsx +14 -0
  33. package/src/primitives/button/index.ts +5 -3
  34. package/src/primitives/button/types.ts +6 -5
  35. package/src/primitives/card/{card-content.tsx → card-body.tsx} +5 -5
  36. package/src/primitives/card/card-footer.tsx +1 -1
  37. package/src/primitives/card/card-header.tsx +1 -1
  38. package/src/primitives/card/card-root.tsx +1 -1
  39. package/src/primitives/card/card-title.tsx +1 -1
  40. package/src/primitives/card/index.ts +4 -4
  41. package/src/primitives/card/types.ts +2 -2
  42. package/src/primitives/field/context.ts +5 -19
  43. package/src/primitives/field/field-description.tsx +17 -0
  44. package/src/primitives/field/field-error.tsx +17 -0
  45. package/src/primitives/field/field-label.tsx +7 -3
  46. package/src/primitives/field/field-root.tsx +13 -59
  47. package/src/primitives/field/index.ts +9 -6
  48. package/src/primitives/field/types.ts +8 -7
  49. package/src/primitives/index.ts +5 -0
  50. package/src/primitives/input/index.ts +1 -1
  51. package/src/primitives/input/input.tsx +48 -13
  52. package/src/primitives/input/types.ts +2 -4
  53. package/src/primitives/select/context.ts +3 -3
  54. package/src/primitives/select/index.ts +2 -2
  55. package/src/primitives/select/select-content.tsx +2 -2
  56. package/src/primitives/select/select-option.tsx +27 -4
  57. package/src/primitives/select/select-overlay.tsx +1 -1
  58. package/src/primitives/select/select-root.tsx +13 -11
  59. package/src/primitives/select/select-trigger.tsx +3 -2
  60. package/src/primitives/select/select-value.tsx +4 -1
  61. package/src/primitives/select/types.ts +3 -1
  62. package/src/themes/default/colors.ts +45 -0
  63. package/src/themes/default/index.ts +11 -0
  64. package/src/themes/index.ts +2 -0
  65. package/src/themes/provider.tsx +56 -0
  66. package/src/themes/themes.ts +6 -0
  67. package/src/themes/types.ts +30 -0
  68. package/src/utils/hsla-utils.ts +10 -0
  69. package/src/utils/use-themed-styles.ts +13 -0
  70. package/tsconfig.json +8 -0
  71. package/tsdown.config.ts +8 -0
  72. package/src/index.ts +0 -7
  73. package/src/primitives/field/field-control.tsx +0 -29
  74. package/src/primitives/provider.tsx +0 -10
@@ -0,0 +1,56 @@
1
+ import { createContext, PropsWithChildren, useContext, useEffect, useState } from "react";
2
+ import { Colors, ColorScheme, Radius, ThemeName } from "./types";
3
+ import { themes } from "./themes";
4
+ import { useColorScheme } from "react-native";
5
+
6
+ interface ThemeContext {
7
+ colors: Colors;
8
+ radius: Radius;
9
+ fontFamily: string;
10
+ colorScheme: ColorScheme;
11
+ setColorScheme: (scheme: ColorScheme) => void;
12
+ setTheme: (themeName: ThemeName) => void;
13
+ themeName: ThemeName;
14
+ }
15
+
16
+ const ThemeContext = createContext<ThemeContext | null>(null);
17
+
18
+ export const ThemeProvider = (props: PropsWithChildren) => {
19
+ const [themeName, setTheme] = useState<ThemeName>("default");
20
+
21
+ const systemColorScheme = useColorScheme();
22
+ const [colorScheme, setColorScheme] = useState<ColorScheme>(systemColorScheme ?? "light");
23
+
24
+ const themesAssets = themes[themeName];
25
+ const colors = themesAssets.colors[colorScheme];
26
+
27
+ useEffect(() => {
28
+ if (systemColorScheme) {
29
+ setColorScheme(systemColorScheme);
30
+ }
31
+ }, [systemColorScheme]);
32
+
33
+ return (
34
+ <ThemeContext.Provider
35
+ value={{
36
+ themeName,
37
+ setTheme,
38
+ colorScheme,
39
+ setColorScheme,
40
+ colors,
41
+ radius: themesAssets.radius,
42
+ fontFamily: themesAssets.fontFamily,
43
+ }}
44
+ >
45
+ {props.children}
46
+ </ThemeContext.Provider>
47
+ );
48
+ };
49
+
50
+ export const useTheme = () => {
51
+ const context = useContext(ThemeContext);
52
+ if (!context) {
53
+ throw new Error("useTheme must be used within a ThemeProvider");
54
+ }
55
+ return context;
56
+ };
@@ -0,0 +1,6 @@
1
+ import { defaultThemeAssets } from "./default";
2
+ import { ThemeAssets, ThemeName } from "./types";
3
+
4
+ export const themes: Record<ThemeName, ThemeAssets> = {
5
+ default: defaultThemeAssets,
6
+ };
@@ -0,0 +1,30 @@
1
+ export type ThemeName = "default";
2
+ export type ColorScheme = "light" | "dark";
3
+
4
+ type Color = `hsla(${number}, ${number}%, ${number}%, ${number})`;
5
+
6
+ export interface Colors {
7
+ background: Color;
8
+ foreground: Color;
9
+ primary: Color;
10
+ primaryForeground: Color;
11
+ secondary: Color;
12
+ secondaryForeground: Color;
13
+ muted: Color;
14
+ mutedForeground: Color;
15
+ border: Color;
16
+ surface: Color;
17
+ success: Color;
18
+ warning: Color;
19
+ danger: Color;
20
+ info: Color;
21
+ }
22
+
23
+ export type Radius = number;
24
+ export type FontFamily = string;
25
+
26
+ export interface ThemeAssets {
27
+ colors: Record<ColorScheme, Colors>;
28
+ radius: Radius;
29
+ fontFamily: FontFamily;
30
+ }
@@ -0,0 +1,10 @@
1
+ export const hslaSetAlpha = (hsla: string, alpha: number): string => {
2
+ const parts = hsla.replace(/^hsla?\(|\s+|\)$/g, "").split(",");
3
+ if (parts.length < 3) {
4
+ throw new Error("Invalid HSLA color format");
5
+ }
6
+ const h = parseInt(parts[0], 10);
7
+ const s = parseInt(parts[1], 10);
8
+ const l = parseInt(parts[2], 10);
9
+ return `hsla(${h}, ${s}%, ${l}%, ${alpha})`;
10
+ };
@@ -0,0 +1,13 @@
1
+ import { useTheme } from "@/themes";
2
+ import { Colors, FontFamily, Radius } from "@/themes/types";
3
+
4
+ interface CallbackProps {
5
+ colors: Colors;
6
+ radius: Radius;
7
+ fontFamily: FontFamily;
8
+ }
9
+
10
+ export const useThemedStyles = <T>(callback: (props: CallbackProps) => T): T => {
11
+ const theme = useTheme();
12
+ return callback({ colors: theme.colors, radius: theme.radius, fontFamily: theme.fontFamily });
13
+ };
package/tsconfig.json CHANGED
@@ -1,4 +1,12 @@
1
1
  {
2
2
  "extends": "expo/tsconfig.base",
3
+ "compilerOptions": {
4
+ "strict": true,
5
+ "noUnusedLocals": true,
6
+ "noUnusedParameters": true,
7
+ "paths": {
8
+ "@/*": ["./src/*"]
9
+ }
10
+ },
3
11
  "include": ["src/**/*"]
4
12
  }
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from "tsdown";
2
+
3
+ export default defineConfig({
4
+ entry: ["./src/index.tsx", "./src/primitives/index.ts", "./src/components/index.ts"],
5
+ onSuccess() {
6
+ console.info("🙏 Build succeeded!");
7
+ },
8
+ });
package/src/index.ts DELETED
@@ -1,7 +0,0 @@
1
- export * from "./primitives/provider";
2
-
3
- export * from "./primitives/field";
4
- export * from "./primitives/input";
5
- export * from "./primitives/button";
6
- export * from "./primitives/select";
7
- export * from "./primitives/card";
@@ -1,29 +0,0 @@
1
- import React from "react";
2
- import { useField } from "./context";
3
- import { FieldRootProps } from "./field-root";
4
-
5
- interface FieldControlInjectedProps<TControlStyles> {
6
- value: FieldRootProps["value"];
7
- onChange: FieldRootProps["onChange"];
8
-
9
- onFocus?: () => void;
10
- onBlur?: () => void;
11
-
12
- styles?: TControlStyles;
13
- }
14
-
15
- export type FieldControlProps<T> = {
16
- render: (props: FieldControlInjectedProps<T>) => React.ReactElement;
17
- };
18
-
19
- export function FieldControl<T>(props: FieldControlProps<T>) {
20
- const { value, onChange, setFocused, state, styles } = useField<T>();
21
-
22
- const controlStyles = styles?.control;
23
- const composedStyles = controlStyles ? { ...controlStyles.default, ...controlStyles[state] } : undefined;
24
-
25
- const Component = props.render;
26
- return (
27
- <Component value={value} onChange={onChange} onBlur={() => setFocused(false)} onFocus={() => setFocused(true)} styles={composedStyles as T} />
28
- );
29
- }
@@ -1,10 +0,0 @@
1
- import { PortalHost } from "./portal";
2
-
3
- export const UniversalUIProvider = ({ children }: { children: React.ReactNode }) => {
4
- return (
5
- <>
6
- {children}
7
- <PortalHost />
8
- </>
9
- );
10
- };