@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.
- package/dist/components/index.d.mts +84 -0
- package/dist/components/index.mjs +288 -0
- package/dist/index-Dafk8ZGv.d.mts +265 -0
- package/dist/index.d.mts +45 -0
- package/dist/index.mjs +11 -0
- package/dist/portal-DoPaAohb.mjs +61 -0
- package/dist/primitives/index.d.mts +2 -0
- package/dist/primitives/index.mjs +4 -0
- package/dist/primitives-BYUlEz2_.mjs +442 -0
- package/dist/themes-BrLbh9h6.mjs +86 -0
- package/package.json +20 -8
- package/src/components/button/button.tsx +24 -0
- package/src/components/button/variants/default.tsx +52 -0
- package/src/components/button/variants/index.ts +5 -0
- package/src/components/card/card.tsx +26 -0
- package/src/components/card/variants/default.tsx +38 -0
- package/src/components/card/variants/index.ts +5 -0
- package/src/components/field/field.tsx +27 -0
- package/src/components/field/variants/default.tsx +29 -0
- package/src/components/field/variants/index.ts +5 -0
- package/src/components/index.ts +5 -0
- package/src/components/input/input.tsx +14 -0
- package/src/components/input/variants/default.tsx +34 -0
- package/src/components/input/variants/index.ts +5 -0
- package/src/components/select/select.tsx +35 -0
- package/src/components/select/variants/default.tsx +81 -0
- package/src/components/select/variants/index.ts +5 -0
- package/src/index.tsx +13 -0
- package/src/primitives/button/button-context.tsx +5 -5
- package/src/primitives/button/button-label.tsx +7 -5
- package/src/primitives/button/button-root.tsx +12 -8
- package/src/primitives/button/button-spinner.tsx +14 -0
- package/src/primitives/button/index.ts +5 -3
- package/src/primitives/button/types.ts +6 -5
- package/src/primitives/card/{card-content.tsx → card-body.tsx} +5 -5
- package/src/primitives/card/card-footer.tsx +1 -1
- package/src/primitives/card/card-header.tsx +1 -1
- package/src/primitives/card/card-root.tsx +1 -1
- package/src/primitives/card/card-title.tsx +1 -1
- package/src/primitives/card/index.ts +4 -4
- package/src/primitives/card/types.ts +2 -2
- package/src/primitives/field/context.ts +5 -19
- package/src/primitives/field/field-description.tsx +17 -0
- package/src/primitives/field/field-error.tsx +17 -0
- package/src/primitives/field/field-label.tsx +7 -3
- package/src/primitives/field/field-root.tsx +13 -59
- package/src/primitives/field/index.ts +9 -6
- package/src/primitives/field/types.ts +8 -7
- package/src/primitives/index.ts +5 -0
- package/src/primitives/input/index.ts +1 -1
- package/src/primitives/input/input.tsx +48 -13
- package/src/primitives/input/types.ts +2 -4
- package/src/primitives/select/context.ts +3 -3
- package/src/primitives/select/index.ts +2 -2
- package/src/primitives/select/select-content.tsx +2 -2
- package/src/primitives/select/select-option.tsx +27 -4
- package/src/primitives/select/select-overlay.tsx +1 -1
- package/src/primitives/select/select-root.tsx +13 -11
- package/src/primitives/select/select-trigger.tsx +3 -2
- package/src/primitives/select/select-value.tsx +4 -1
- package/src/primitives/select/types.ts +3 -1
- package/src/themes/default/colors.ts +45 -0
- package/src/themes/default/index.ts +11 -0
- package/src/themes/index.ts +2 -0
- package/src/themes/provider.tsx +56 -0
- package/src/themes/themes.ts +6 -0
- package/src/themes/types.ts +30 -0
- package/src/utils/hsla-utils.ts +10 -0
- package/src/utils/use-themed-styles.ts +13 -0
- package/tsconfig.json +8 -0
- package/tsdown.config.ts +8 -0
- package/src/index.ts +0 -7
- package/src/primitives/field/field-control.tsx +0 -29
- 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,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
package/tsdown.config.ts
ADDED
package/src/index.ts
DELETED
|
@@ -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
|
-
}
|