@xanui/core 1.3.7 → 1.3.9
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/AppRoot/AppRootProvider.cjs.map +1 -1
- package/AppRoot/AppRootProvider.js.map +1 -1
- package/AppRoot/Renderar.cjs.map +1 -1
- package/AppRoot/Renderar.js.map +1 -1
- package/AppRoot/index.cjs +6 -5
- package/AppRoot/index.cjs.map +1 -1
- package/AppRoot/index.d.ts +2 -1
- package/AppRoot/index.js +6 -5
- package/AppRoot/index.js.map +1 -1
- package/Document/index.cjs.map +1 -1
- package/Document/index.js.map +1 -1
- package/Iframe/index.cjs +1 -0
- package/Iframe/index.cjs.map +1 -1
- package/Iframe/index.js +1 -0
- package/Iframe/index.js.map +1 -1
- package/Portal/index.cjs.map +1 -1
- package/Portal/index.js.map +1 -1
- package/Tag/ServerStyleTag.cjs.map +1 -1
- package/Tag/ServerStyleTag.js.map +1 -1
- package/Tag/cssPropList.cjs.map +1 -1
- package/Tag/cssPropList.js.map +1 -1
- package/Tag/index.cjs +2 -2
- package/Tag/index.cjs.map +1 -1
- package/Tag/index.js +2 -2
- package/Tag/index.js.map +1 -1
- package/Tag/types.d.ts +3 -2
- package/Tag/useTagProps.cjs +23 -4
- package/Tag/useTagProps.cjs.map +1 -1
- package/Tag/useTagProps.d.ts +1 -0
- package/Tag/useTagProps.js +23 -4
- package/Tag/useTagProps.js.map +1 -1
- package/Transition/index.cjs +1 -1
- package/Transition/index.cjs.map +1 -1
- package/Transition/index.d.ts +7 -2
- package/Transition/index.js +1 -1
- package/Transition/index.js.map +1 -1
- package/Transition/variants.cjs.map +1 -1
- package/Transition/variants.js.map +1 -1
- package/animate/easing.cjs.map +1 -1
- package/animate/easing.js.map +1 -1
- package/animate/index.cjs.map +1 -1
- package/animate/index.js.map +1 -1
- package/breakpoint/BreakpointProvider.cjs.map +1 -1
- package/breakpoint/BreakpointProvider.js.map +1 -1
- package/breakpoint/useBreakpoint.cjs.map +1 -1
- package/breakpoint/useBreakpoint.js.map +1 -1
- package/breakpoint/useBreakpointProps.cjs.map +1 -1
- package/breakpoint/useBreakpointProps.js.map +1 -1
- package/cookie.cjs.map +1 -1
- package/cookie.js.map +1 -1
- package/css/CSSCacheProvider.cjs.map +1 -1
- package/css/CSSCacheProvider.js.map +1 -1
- package/css/aliases.cjs.map +1 -1
- package/css/aliases.js.map +1 -1
- package/css/getProps.cjs +9 -6
- package/css/getProps.cjs.map +1 -1
- package/css/getProps.js +9 -6
- package/css/getProps.js.map +1 -1
- package/css/getValue.cjs +11 -10
- package/css/getValue.cjs.map +1 -1
- package/css/getValue.js +11 -10
- package/css/getValue.js.map +1 -1
- package/css/index.cjs +0 -32
- package/css/index.cjs.map +1 -1
- package/css/index.d.ts +1 -4
- package/css/index.js +1 -30
- package/css/index.js.map +1 -1
- package/hooks/useColorTemplate.cjs +26 -29
- package/hooks/useColorTemplate.cjs.map +1 -1
- package/hooks/useColorTemplate.d.ts +8 -6
- package/hooks/useColorTemplate.js +26 -29
- package/hooks/useColorTemplate.js.map +1 -1
- package/hooks/useInterface.cjs +1 -0
- package/hooks/useInterface.cjs.map +1 -1
- package/hooks/useInterface.d.ts +1 -3
- package/hooks/useInterface.js +1 -0
- package/hooks/useInterface.js.map +1 -1
- package/hooks/useMergeRefs.cjs.map +1 -1
- package/hooks/useMergeRefs.js.map +1 -1
- package/hooks/useTransition.cjs.map +1 -1
- package/hooks/useTransition.js.map +1 -1
- package/hooks/useTransitionGroup.cjs.map +1 -1
- package/hooks/useTransitionGroup.js.map +1 -1
- package/index.cjs +0 -3
- package/index.cjs.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +1 -1
- package/package.json +1 -1
- package/readme.md +109 -109
- package/theme/ThemeCssVars.cjs +39 -3
- package/theme/ThemeCssVars.cjs.map +1 -1
- package/theme/ThemeCssVars.js +39 -3
- package/theme/ThemeCssVars.js.map +1 -1
- package/theme/ThemeDefaultOptions.cjs +20 -86
- package/theme/ThemeDefaultOptions.cjs.map +1 -1
- package/theme/ThemeDefaultOptions.js +20 -86
- package/theme/ThemeDefaultOptions.js.map +1 -1
- package/theme/ThemeProvider.cjs +4 -3
- package/theme/ThemeProvider.cjs.map +1 -1
- package/theme/ThemeProvider.d.ts +3 -3
- package/theme/ThemeProvider.js +5 -4
- package/theme/ThemeProvider.js.map +1 -1
- package/theme/core.cjs +22 -13
- package/theme/core.cjs.map +1 -1
- package/theme/core.d.ts +1 -1
- package/theme/core.js +24 -15
- package/theme/core.js.map +1 -1
- package/theme/index.cjs +3 -0
- package/theme/index.cjs.map +1 -1
- package/theme/index.js +1 -0
- package/theme/index.js.map +1 -1
- package/theme/oklch.cjs +249 -0
- package/theme/oklch.cjs.map +1 -0
- package/theme/oklch.js +246 -0
- package/theme/oklch.js.map +1 -0
- package/theme/types.d.ts +28 -70
|
@@ -1,68 +1,65 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
const useColorTemplate = (color, type) => {
|
|
3
|
-
const is_def = color === "
|
|
4
|
-
if (is_def) {
|
|
5
|
-
color = "divider";
|
|
6
|
-
}
|
|
3
|
+
const is_def = color === "surface";
|
|
7
4
|
if (type === "outline") {
|
|
8
5
|
return {
|
|
9
|
-
|
|
6
|
+
main: {
|
|
10
7
|
bgcolor: `transparent`,
|
|
11
|
-
color: is_def ? `
|
|
8
|
+
color: is_def ? `surface.contrast` : `${color}.main`,
|
|
12
9
|
border: "1px solid",
|
|
13
|
-
borderColor: is_def ? `
|
|
10
|
+
borderColor: is_def ? `surface.muted` : `${color}.main`,
|
|
14
11
|
},
|
|
15
|
-
|
|
12
|
+
hover: {
|
|
16
13
|
bgcolor: `transparent`,
|
|
17
|
-
color: is_def ? `
|
|
14
|
+
color: is_def ? `surface.contrast` : `${color}.light`,
|
|
18
15
|
border: "1px solid",
|
|
19
|
-
borderColor: is_def ? `
|
|
16
|
+
borderColor: is_def ? `surface.muted` : `${color}.light`,
|
|
20
17
|
}
|
|
21
18
|
};
|
|
22
19
|
}
|
|
23
20
|
else if (type === "fill") {
|
|
24
21
|
return {
|
|
25
|
-
|
|
26
|
-
bgcolor: color
|
|
27
|
-
color: is_def ? `
|
|
22
|
+
main: {
|
|
23
|
+
bgcolor: is_def ? `surface.light` : `${color}`,
|
|
24
|
+
color: is_def ? `surface.contrast` : `${color}.contrast`,
|
|
28
25
|
border: "1px solid",
|
|
29
|
-
borderColor: is_def ? `divider
|
|
26
|
+
borderColor: is_def ? `surface.divider` : `${color}.light`,
|
|
30
27
|
},
|
|
31
|
-
|
|
32
|
-
bgcolor: `${color}.
|
|
33
|
-
color: is_def ? `
|
|
28
|
+
hover: {
|
|
29
|
+
bgcolor: is_def ? `surface.dark` : `${color}.light`,
|
|
30
|
+
color: is_def ? `surface.contrast` : `${color}.contrast`,
|
|
34
31
|
border: "1px solid",
|
|
35
|
-
borderColor: is_def ? `divider
|
|
32
|
+
borderColor: is_def ? `surface.divider` : `${color}.light`,
|
|
36
33
|
}
|
|
37
34
|
};
|
|
38
35
|
}
|
|
39
36
|
else if (type === "text") {
|
|
40
37
|
return {
|
|
41
|
-
|
|
38
|
+
main: {
|
|
42
39
|
bgcolor: "transparent",
|
|
43
|
-
color: is_def ? `
|
|
40
|
+
color: is_def ? `surface.contrast` : `${color}.main`,
|
|
44
41
|
border: 0,
|
|
45
42
|
borderColor: `transparent`,
|
|
46
43
|
},
|
|
47
|
-
|
|
44
|
+
hover: {
|
|
48
45
|
bgcolor: "transparent",
|
|
49
|
-
color: is_def ? `
|
|
46
|
+
color: is_def ? `surface.contrast` : `${color}.light`,
|
|
50
47
|
border: 0,
|
|
51
48
|
borderColor: `transparent`,
|
|
52
49
|
}
|
|
53
50
|
};
|
|
54
51
|
}
|
|
55
|
-
else if (type === "
|
|
52
|
+
else if (type === "ghost") {
|
|
56
53
|
return {
|
|
57
|
-
|
|
58
|
-
bgcolor: `${color}.
|
|
59
|
-
color: is_def ? `
|
|
54
|
+
main: {
|
|
55
|
+
bgcolor: `${color}.ghost`,
|
|
56
|
+
color: is_def ? `surface.contrast` : color,
|
|
60
57
|
border: 0,
|
|
61
58
|
borderColor: `transparent`,
|
|
62
59
|
},
|
|
63
|
-
|
|
64
|
-
bgcolor: `${color}.
|
|
65
|
-
color: is_def ? `
|
|
60
|
+
hover: {
|
|
61
|
+
bgcolor: `${color}.ghost`,
|
|
62
|
+
color: is_def ? `surface.contrast` : `${color}.light`,
|
|
66
63
|
border: 0,
|
|
67
64
|
borderColor: `transparent`,
|
|
68
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useColorTemplate.js","sources":["../../src/hooks/useColorTemplate.ts"],"sourcesContent":["\"use client\";\
|
|
1
|
+
{"version":3,"file":"useColorTemplate.js","sources":["../../src/hooks/useColorTemplate.ts"],"sourcesContent":["\"use client\";\n\nimport { ThemeColorKeys } from \"../theme/types\";\n\nexport type UseColorTemplateType = \"fill\" | \"outline\" | \"text\" | \"ghost\"\nexport type UseColorTemplateColor = ThemeColorKeys\n\nconst useColorTemplate = (color: UseColorTemplateColor, type: UseColorTemplateType) => {\n const is_def = color === \"surface\";\n\n if (type === \"outline\") {\n return {\n main: {\n bgcolor: `transparent`,\n color: is_def ? `surface.contrast` : `${color}.main`,\n border: \"1px solid\",\n borderColor: is_def ? `surface.muted` : `${color}.main`,\n },\n hover: {\n bgcolor: `transparent`,\n color: is_def ? `surface.contrast` : `${color}.light`,\n border: \"1px solid\",\n borderColor: is_def ? `surface.muted` : `${color}.light`,\n }\n }\n } else if (type === \"fill\") {\n return {\n main: {\n bgcolor: is_def ? `surface.light` : `${color}`,\n color: is_def ? `surface.contrast` : `${color}.contrast`,\n border: \"1px solid\",\n borderColor: is_def ? `surface.divider` : `${color}.light`,\n },\n hover: {\n bgcolor: is_def ? `surface.dark` : `${color}.light`,\n color: is_def ? `surface.contrast` : `${color}.contrast`,\n border: \"1px solid\",\n borderColor: is_def ? `surface.divider` : `${color}.light`,\n }\n }\n } else if (type === \"text\") {\n return {\n main: {\n bgcolor: \"transparent\",\n color: is_def ? `surface.contrast` : `${color}.main`,\n border: 0,\n borderColor: `transparent`,\n },\n hover: {\n bgcolor: \"transparent\",\n color: is_def ? `surface.contrast` : `${color}.light`,\n border: 0,\n borderColor: `transparent`,\n }\n }\n } else if (type === \"ghost\") {\n return {\n main: {\n bgcolor: `${color}.ghost`,\n color: is_def ? `surface.contrast` : color,\n border: 0,\n borderColor: `transparent`,\n },\n hover: {\n bgcolor: `${color}.ghost`,\n color: is_def ? `surface.contrast` : `${color}.light`,\n border: 0,\n borderColor: `transparent`,\n }\n }\n }\n\n throw new Error(`useColorTemplate: Unknown type ${type}`);\n}\n\nexport default useColorTemplate"],"names":[],"mappings":";AAOA;AACI;AAEA;;AAEQ;AACI;;AAEA;;AAEH;AACD;AACI;;AAEA;;AAEH;;;AAEF;;AAEC;;;AAGI;;AAEH;AACD;;;AAGI;;AAEH;;;AAEF;;AAEC;AACI;;AAEA;AACA;AACH;AACD;AACI;;AAEA;AACA;AACH;;;AAEF;;AAEC;;;AAGI;AACA;AACH;AACD;;;AAGI;AACA;AACH;;;AAIT;AACJ;;"}
|
package/hooks/useInterface.cjs
CHANGED
|
@@ -9,6 +9,7 @@ require('../css/getValue.cjs');
|
|
|
9
9
|
require('oncss');
|
|
10
10
|
require('../Document/index.cjs');
|
|
11
11
|
require('../css/CSSCacheProvider.cjs');
|
|
12
|
+
require('../theme/ThemeDefaultOptions.cjs');
|
|
12
13
|
|
|
13
14
|
const useInterface = (name, userPorps, defaultProps) => {
|
|
14
15
|
const theme = core.useTheme();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInterface.cjs","sources":["../../src/hooks/useInterface.ts"],"sourcesContent":["import { useTheme } from \"../theme\"\
|
|
1
|
+
{"version":3,"file":"useInterface.cjs","sources":["../../src/hooks/useInterface.ts"],"sourcesContent":["import { useTheme } from \"../theme\"\n\nconst useInterface = <P extends object>(name: string, userPorps: P, defaultProps: P) => {\n const theme = useTheme()\n let _props = { ...defaultProps, ...userPorps } as P\n if (name in theme.interfaces) {\n return theme.interfaces[name](_props, theme)\n }\n return [_props, theme]\n}\n\nexport default useInterface"],"names":["useTheme"],"mappings":";;;;;;;;;;;;;AAEA,MAAM,YAAY,GAAG,CAAmB,IAAY,EAAE,SAAY,EAAE,YAAe,KAAI;AACnF,IAAA,MAAM,KAAK,GAAGA,aAAQ,EAAE;AACxB,IAAA,IAAI,MAAM,GAAG,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAK,YAAY,CAAA,EAAK,SAAS,CAAO;AACnD,IAAA,IAAI,IAAI,IAAI,KAAK,CAAC,UAAU,EAAE;QAC1B,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC;IAChD;AACA,IAAA,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC;AAC1B;;;;"}
|
package/hooks/useInterface.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
declare const useInterface: <P extends object>(name: string, userPorps: P, defaultProps: P) => P | (P | ThemeOptions)[];
|
|
1
|
+
declare const useInterface: <P extends object>(name: string, userPorps: P, defaultProps: P) => any;
|
|
4
2
|
|
|
5
3
|
export { useInterface as default };
|
package/hooks/useInterface.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInterface.js","sources":["../../src/hooks/useInterface.ts"],"sourcesContent":["import { useTheme } from \"../theme\"\
|
|
1
|
+
{"version":3,"file":"useInterface.js","sources":["../../src/hooks/useInterface.ts"],"sourcesContent":["import { useTheme } from \"../theme\"\n\nconst useInterface = <P extends object>(name: string, userPorps: P, defaultProps: P) => {\n const theme = useTheme()\n let _props = { ...defaultProps, ...userPorps } as P\n if (name in theme.interfaces) {\n return theme.interfaces[name](_props, theme)\n }\n return [_props, theme]\n}\n\nexport default useInterface"],"names":[],"mappings":";;;;;;;;;;;AAEA,MAAM,YAAY,GAAG,CAAmB,IAAY,EAAE,SAAY,EAAE,YAAe,KAAI;AACnF,IAAA,MAAM,KAAK,GAAG,QAAQ,EAAE;AACxB,IAAA,IAAI,MAAM,GAAG,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAK,YAAY,CAAA,EAAK,SAAS,CAAO;AACnD,IAAA,IAAI,IAAI,IAAI,KAAK,CAAC,UAAU,EAAE;QAC1B,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC;IAChD;AACA,IAAA,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC;AAC1B;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMergeRefs.cjs","sources":["../../src/hooks/useMergeRefs.ts"],"sourcesContent":["\"use client\";\
|
|
1
|
+
{"version":3,"file":"useMergeRefs.cjs","sources":["../../src/hooks/useMergeRefs.ts"],"sourcesContent":["\"use client\";\nimport { useCallback } from \"react\";\n\nfunction useMergeRefs<T>(\n ...refs: Array<React.Ref<T> | undefined>\n) {\n return useCallback((value: T | null) => {\n for (const ref of refs) {\n if (!ref) continue;\n if (typeof ref === \"function\") {\n ref(value);\n } else {\n (ref as React.MutableRefObject<T | null>).current = value;\n }\n }\n }, refs);\n}\n\nexport default useMergeRefs;"],"names":[],"mappings":";;;;;AAGA;AAGG;AACG;AACG;;AACA;;;;AAGI;;;;AAIb;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMergeRefs.js","sources":["../../src/hooks/useMergeRefs.ts"],"sourcesContent":["\"use client\";\
|
|
1
|
+
{"version":3,"file":"useMergeRefs.js","sources":["../../src/hooks/useMergeRefs.ts"],"sourcesContent":["\"use client\";\nimport { useCallback } from \"react\";\n\nfunction useMergeRefs<T>(\n ...refs: Array<React.Ref<T> | undefined>\n) {\n return useCallback((value: T | null) => {\n for (const ref of refs) {\n if (!ref) continue;\n if (typeof ref === \"function\") {\n ref(value);\n } else {\n (ref as React.MutableRefObject<T | null>).current = value;\n }\n }\n }, refs);\n}\n\nexport default useMergeRefs;"],"names":[],"mappings":";;;AAGA;AAGG;AACG;AACG;;AACA;;;;AAGI;;;;AAIb;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTransition.cjs","sources":["../../src/hooks/useTransition.ts"],"sourcesContent":["\"use client\"\
|
|
1
|
+
{"version":3,"file":"useTransition.cjs","sources":["../../src/hooks/useTransition.ts"],"sourcesContent":["\"use client\"\nimport { useRef, useState, useCallback, useLayoutEffect } from \"react\"\nimport animate, { AnimateOptions } from \"../animate\"\n\nexport type UseTransitionStatus =\n | \"entering\"\n | \"entered\"\n | \"exiting\"\n | \"exited\"\n\nexport type UseTransitionProps<T extends Record<string, number>> = AnimateOptions<T> & {\n initialStatus?: \"entered\" | \"exited\"\n onEnter?: () => void\n onEntered?: () => void\n onExit?: () => void\n onExited?: () => void\n}\n\nconst useTransition = <T extends Record<string, number>>(props: UseTransitionProps<T>) => {\n const {\n initialStatus = \"exited\",\n onEnter,\n onEntered,\n onExit,\n onExited,\n ...options\n } = props\n\n const resolve = (val: T | (() => T)): T =>\n typeof val === \"function\" ? (val as () => T)() : val\n\n const [open, setOpen] = useState(initialStatus === \"entered\")\n const [status, setStatus] = useState<UseTransitionStatus>(initialStatus)\n\n const stateRef = useRef<T | null>(null)\n const readyRef = useRef(false)\n\n const animating = useRef<null | (() => void)>(null)\n\n useLayoutEffect(() => {\n const from = resolve(options.from)\n const to = resolve(options.to)\n stateRef.current = initialStatus === \"entered\" ? to : from\n readyRef.current = true\n }, [])\n\n const run = useCallback(\n (nextOpen: boolean, withAnimation = true) => {\n if (!readyRef.current || !stateRef.current) return\n\n animating.current?.()\n\n const resolvedFrom = resolve(options.from)\n const resolvedTo = resolve(options.to)\n const from = stateRef.current\n const to = nextOpen ? resolvedTo : resolvedFrom\n\n if (nextOpen) {\n setStatus(\"entering\")\n onEnter?.()\n } else {\n setStatus(\"exiting\")\n onExit?.()\n }\n\n if (!withAnimation) {\n stateRef.current = to\n options.onUpdate?.(to, 1)\n\n if (nextOpen) {\n setStatus(\"entered\")\n onEntered?.()\n } else {\n setStatus(\"exited\")\n onExited?.()\n }\n\n options.onDone?.(stateRef.current)\n return\n }\n\n animating.current = animate({\n ...options,\n from,\n to,\n duration: options.duration ?? 400,\n onUpdate: (value: T, progress: number) => {\n stateRef.current = value\n options.onUpdate?.(value, progress)\n },\n onDone: (value) => {\n if (nextOpen) {\n setStatus(\"entered\")\n onEntered?.()\n } else {\n setStatus(\"exited\")\n onExited?.()\n }\n options.onDone?.(value)\n },\n })\n },\n [options, onEnter, onEntered, onExit, onExited]\n )\n\n const enter = useCallback((withAnimation = true) => {\n setOpen(true)\n run(true, withAnimation)\n }, [run])\n\n const exit = useCallback((withAnimation = true) => {\n setOpen(false)\n run(false, withAnimation)\n }, [run])\n\n const toggle = useCallback((withAnimation = true) => {\n setOpen((prev) => {\n const next = !prev\n run(next, withAnimation)\n return next\n })\n }, [run])\n\n return {\n isEntered: open,\n status,\n state: stateRef,\n enter,\n exit,\n toggle,\n isReady: readyRef.current\n }\n}\n\nexport default useTransition"],"names":[],"mappings":";;;;;;;AAkBA;;;AAaG;;AAGA;AACA;AAEA;;;;AAKG;AACA;;;;;;AAOG;;;AAIA;;;;AAKG;;;;AAGA;;;AAIA;;;;AAKG;;;;AAGA;;;;;AAON;AAGG;;AAGG;;AAEH;;;;AAIM;;;;AAGA;;AAEH;AACH;AAEN;;;AAMA;AACH;;;AAIG;AACH;;AAGG;AACG;AACA;AACA;AACH;AACH;;AAGG;;AAEA;;;;;;AAMN;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTransition.js","sources":["../../src/hooks/useTransition.ts"],"sourcesContent":["\"use client\"\
|
|
1
|
+
{"version":3,"file":"useTransition.js","sources":["../../src/hooks/useTransition.ts"],"sourcesContent":["\"use client\"\nimport { useRef, useState, useCallback, useLayoutEffect } from \"react\"\nimport animate, { AnimateOptions } from \"../animate\"\n\nexport type UseTransitionStatus =\n | \"entering\"\n | \"entered\"\n | \"exiting\"\n | \"exited\"\n\nexport type UseTransitionProps<T extends Record<string, number>> = AnimateOptions<T> & {\n initialStatus?: \"entered\" | \"exited\"\n onEnter?: () => void\n onEntered?: () => void\n onExit?: () => void\n onExited?: () => void\n}\n\nconst useTransition = <T extends Record<string, number>>(props: UseTransitionProps<T>) => {\n const {\n initialStatus = \"exited\",\n onEnter,\n onEntered,\n onExit,\n onExited,\n ...options\n } = props\n\n const resolve = (val: T | (() => T)): T =>\n typeof val === \"function\" ? (val as () => T)() : val\n\n const [open, setOpen] = useState(initialStatus === \"entered\")\n const [status, setStatus] = useState<UseTransitionStatus>(initialStatus)\n\n const stateRef = useRef<T | null>(null)\n const readyRef = useRef(false)\n\n const animating = useRef<null | (() => void)>(null)\n\n useLayoutEffect(() => {\n const from = resolve(options.from)\n const to = resolve(options.to)\n stateRef.current = initialStatus === \"entered\" ? to : from\n readyRef.current = true\n }, [])\n\n const run = useCallback(\n (nextOpen: boolean, withAnimation = true) => {\n if (!readyRef.current || !stateRef.current) return\n\n animating.current?.()\n\n const resolvedFrom = resolve(options.from)\n const resolvedTo = resolve(options.to)\n const from = stateRef.current\n const to = nextOpen ? resolvedTo : resolvedFrom\n\n if (nextOpen) {\n setStatus(\"entering\")\n onEnter?.()\n } else {\n setStatus(\"exiting\")\n onExit?.()\n }\n\n if (!withAnimation) {\n stateRef.current = to\n options.onUpdate?.(to, 1)\n\n if (nextOpen) {\n setStatus(\"entered\")\n onEntered?.()\n } else {\n setStatus(\"exited\")\n onExited?.()\n }\n\n options.onDone?.(stateRef.current)\n return\n }\n\n animating.current = animate({\n ...options,\n from,\n to,\n duration: options.duration ?? 400,\n onUpdate: (value: T, progress: number) => {\n stateRef.current = value\n options.onUpdate?.(value, progress)\n },\n onDone: (value) => {\n if (nextOpen) {\n setStatus(\"entered\")\n onEntered?.()\n } else {\n setStatus(\"exited\")\n onExited?.()\n }\n options.onDone?.(value)\n },\n })\n },\n [options, onEnter, onEntered, onExit, onExited]\n )\n\n const enter = useCallback((withAnimation = true) => {\n setOpen(true)\n run(true, withAnimation)\n }, [run])\n\n const exit = useCallback((withAnimation = true) => {\n setOpen(false)\n run(false, withAnimation)\n }, [run])\n\n const toggle = useCallback((withAnimation = true) => {\n setOpen((prev) => {\n const next = !prev\n run(next, withAnimation)\n return next\n })\n }, [run])\n\n return {\n isEntered: open,\n status,\n state: stateRef,\n enter,\n exit,\n toggle,\n isReady: readyRef.current\n }\n}\n\nexport default useTransition"],"names":[],"mappings":";;;;;AAkBA;;;AAaG;;AAGA;AACA;AAEA;;;;AAKG;AACA;;;;;;AAOG;;;AAIA;;;;AAKG;;;;AAGA;;;AAIA;;;;AAKG;;;;AAGA;;;;;AAON;AAGG;;AAGG;;AAEH;;;;AAIM;;;;AAGA;;AAEH;AACH;AAEN;;;AAMA;AACH;;;AAIG;AACH;;AAGG;AACG;AACA;AACA;AACH;AACH;;AAGG;;AAEA;;;;;;AAMN;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTransitionGroup.cjs","sources":["../../src/hooks/useTransitionGroup.ts"],"sourcesContent":["\"use client\"\
|
|
1
|
+
{"version":3,"file":"useTransitionGroup.cjs","sources":["../../src/hooks/useTransitionGroup.ts"],"sourcesContent":["\"use client\"\nimport { useRef, useState, useCallback } from \"react\"\nimport animate from \"../animate\"\nimport { UseTransitionStatus } from \"./useTransition\"\n\nexport type UseTransitionGroupItem<T extends Record<string, number>> = {\n key: string | number\n from: T\n to: T\n}\n\nexport type UseTransitionGroupProps<T extends Record<string, number>> = {\n items: UseTransitionGroupItem<T>[]\n duration?: number\n stagger?: number // delay between items in ms\n mountOnEnter?: boolean\n unmountOnExit?: boolean\n onUpdate?: (value: T, key: string | number, progress: number) => void\n onEnter?: (key: string | number) => void\n onEntered?: (key: string | number) => void\n onExit?: (key: string | number) => void\n onExited?: (key: string | number) => void\n}\n\n/**\n * useTransitionGroup - staggered animations for multiple items\n */\nfunction useTransitionGroup<T extends Record<string, number>>(\n options: UseTransitionGroupProps<T>\n) {\n // status of each item\n const [statuses, setStatuses] = useState<\n Record<string | number, UseTransitionStatus>\n >(\n () =>\n Object.fromEntries(\n options.items.map((item) => [\n item.key,\n options.mountOnEnter ? \"exited\" : \"entered\",\n ])\n )\n )\n\n // refs to cancel per-item animations\n const animatingRefs = useRef<Record<string | number, (() => void) | null>>({})\n\n // track mounted items (for mount/unmount)\n const [mounted, setMounted] = useState<Record<string | number, boolean>>(\n () =>\n Object.fromEntries(\n options.items.map((item) => [\n item.key,\n !options.mountOnEnter,\n ])\n )\n )\n\n // animate a single item\n const animateItem = useCallback(\n (item: UseTransitionGroupItem<T>, entering: boolean, delay = 0) => {\n // cancel previous\n animatingRefs.current[item.key]?.()\n\n if (entering) setStatuses((s: any) => ({ ...s, [item.key]: \"entering\" }))\n else setStatuses((s: any) => ({ ...s, [item.key]: \"exiting\" }))\n\n if (entering && options.mountOnEnter) {\n setMounted((m) => ({ ...m, [item.key]: true }))\n }\n\n // start animation after delay\n const timeout = setTimeout(() => {\n if (entering) options.onEnter?.(item.key)\n else options.onExit?.(item.key)\n\n animatingRefs.current[item.key] = animate({\n from: entering ? item.from : item.to,\n to: entering ? item.to : item.from,\n duration: options.duration ?? 400,\n onUpdate: (value, progress) =>\n options.onUpdate?.(value, item.key, progress),\n onDone: () => {\n if (entering) {\n setStatuses((s: any) => ({ ...s, [item.key]: \"entered\" }))\n options.onEntered?.(item.key)\n } else {\n setStatuses((s: any) => ({ ...s, [item.key]: \"exited\" }))\n options.onExited?.(item.key)\n if (options.unmountOnExit) {\n setMounted((m) => ({ ...m, [item.key]: false }))\n }\n }\n },\n })\n }, delay)\n\n return () => clearTimeout(timeout)\n },\n [options]\n )\n\n // run staggered animation on array of items\n const run = useCallback(\n (entering: boolean) => {\n options.items.forEach((item, index) => {\n const delay = (options.stagger ?? 100) * index\n const status = statuses[item.key]\n\n // skip if already animating in same direction\n if (entering && (status === \"entering\" || status === \"entered\")) return\n if (!entering && (status === \"exiting\" || status === \"exited\")) return\n\n animateItem(item, entering, delay)\n })\n },\n [options.items, options.stagger, animateItem, statuses]\n )\n\n const enter = useCallback(() => run(true), [run])\n const exit = useCallback(() => run(false), [run])\n const toggle = useCallback(() => {\n const anyEntered = Object.values(statuses).some(\n (s) => s === \"entering\" || s === \"entered\"\n )\n run(!anyEntered)\n }, [run, statuses])\n\n return {\n statuses,\n mounted,\n enter,\n exit,\n toggle,\n }\n}\n\nexport default useTransitionGroup"],"names":[],"mappings":";;;;;;AAwBA;;AAEG;AACH;;;AAUe;;;;AAOZ;;;AAOY;;;;AAOZ;;;;AAKM;AAAc;;AACT;AAEL;AACG;;;AAIH;;AACG;;;;;AAIG;AACA;AACA;;;;;AAKM;;;;AAGA;;AAEA;AACG;;;;AAIX;;AAGJ;AACH;;AAKH;;;AAGS;;;;;;;AAOA;AACH;AACH;AAIH;AACA;AACA;;AAIG;AACH;;;;;;;;AASH;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTransitionGroup.js","sources":["../../src/hooks/useTransitionGroup.ts"],"sourcesContent":["\"use client\"\
|
|
1
|
+
{"version":3,"file":"useTransitionGroup.js","sources":["../../src/hooks/useTransitionGroup.ts"],"sourcesContent":["\"use client\"\nimport { useRef, useState, useCallback } from \"react\"\nimport animate from \"../animate\"\nimport { UseTransitionStatus } from \"./useTransition\"\n\nexport type UseTransitionGroupItem<T extends Record<string, number>> = {\n key: string | number\n from: T\n to: T\n}\n\nexport type UseTransitionGroupProps<T extends Record<string, number>> = {\n items: UseTransitionGroupItem<T>[]\n duration?: number\n stagger?: number // delay between items in ms\n mountOnEnter?: boolean\n unmountOnExit?: boolean\n onUpdate?: (value: T, key: string | number, progress: number) => void\n onEnter?: (key: string | number) => void\n onEntered?: (key: string | number) => void\n onExit?: (key: string | number) => void\n onExited?: (key: string | number) => void\n}\n\n/**\n * useTransitionGroup - staggered animations for multiple items\n */\nfunction useTransitionGroup<T extends Record<string, number>>(\n options: UseTransitionGroupProps<T>\n) {\n // status of each item\n const [statuses, setStatuses] = useState<\n Record<string | number, UseTransitionStatus>\n >(\n () =>\n Object.fromEntries(\n options.items.map((item) => [\n item.key,\n options.mountOnEnter ? \"exited\" : \"entered\",\n ])\n )\n )\n\n // refs to cancel per-item animations\n const animatingRefs = useRef<Record<string | number, (() => void) | null>>({})\n\n // track mounted items (for mount/unmount)\n const [mounted, setMounted] = useState<Record<string | number, boolean>>(\n () =>\n Object.fromEntries(\n options.items.map((item) => [\n item.key,\n !options.mountOnEnter,\n ])\n )\n )\n\n // animate a single item\n const animateItem = useCallback(\n (item: UseTransitionGroupItem<T>, entering: boolean, delay = 0) => {\n // cancel previous\n animatingRefs.current[item.key]?.()\n\n if (entering) setStatuses((s: any) => ({ ...s, [item.key]: \"entering\" }))\n else setStatuses((s: any) => ({ ...s, [item.key]: \"exiting\" }))\n\n if (entering && options.mountOnEnter) {\n setMounted((m) => ({ ...m, [item.key]: true }))\n }\n\n // start animation after delay\n const timeout = setTimeout(() => {\n if (entering) options.onEnter?.(item.key)\n else options.onExit?.(item.key)\n\n animatingRefs.current[item.key] = animate({\n from: entering ? item.from : item.to,\n to: entering ? item.to : item.from,\n duration: options.duration ?? 400,\n onUpdate: (value, progress) =>\n options.onUpdate?.(value, item.key, progress),\n onDone: () => {\n if (entering) {\n setStatuses((s: any) => ({ ...s, [item.key]: \"entered\" }))\n options.onEntered?.(item.key)\n } else {\n setStatuses((s: any) => ({ ...s, [item.key]: \"exited\" }))\n options.onExited?.(item.key)\n if (options.unmountOnExit) {\n setMounted((m) => ({ ...m, [item.key]: false }))\n }\n }\n },\n })\n }, delay)\n\n return () => clearTimeout(timeout)\n },\n [options]\n )\n\n // run staggered animation on array of items\n const run = useCallback(\n (entering: boolean) => {\n options.items.forEach((item, index) => {\n const delay = (options.stagger ?? 100) * index\n const status = statuses[item.key]\n\n // skip if already animating in same direction\n if (entering && (status === \"entering\" || status === \"entered\")) return\n if (!entering && (status === \"exiting\" || status === \"exited\")) return\n\n animateItem(item, entering, delay)\n })\n },\n [options.items, options.stagger, animateItem, statuses]\n )\n\n const enter = useCallback(() => run(true), [run])\n const exit = useCallback(() => run(false), [run])\n const toggle = useCallback(() => {\n const anyEntered = Object.values(statuses).some(\n (s) => s === \"entering\" || s === \"entered\"\n )\n run(!anyEntered)\n }, [run, statuses])\n\n return {\n statuses,\n mounted,\n enter,\n exit,\n toggle,\n }\n}\n\nexport default useTransitionGroup"],"names":[],"mappings":";;;;AAwBA;;AAEG;AACH;;;AAUe;;;;AAOZ;;;AAOY;;;;AAOZ;;;;AAKM;AAAc;;AACT;AAEL;AACG;;;AAIH;;AACG;;;;;AAIG;AACA;AACA;;;;;AAKM;;;;AAGA;;AAEA;AACG;;;;AAIX;;AAGJ;AACH;;AAKH;;;AAGS;;;;;;;AAOA;AACH;AACH;AAIH;AACA;AACA;;AAIG;AACH;;;;;;;;AASH;;"}
|
package/index.cjs
CHANGED
|
@@ -49,9 +49,6 @@ exports.Iframe = index$1;
|
|
|
49
49
|
exports.animate = index$6.default;
|
|
50
50
|
exports.useTransition = useTransition;
|
|
51
51
|
exports.useTransitionGroup = useTransitionGroup;
|
|
52
|
-
exports.adjustColor = index$7.adjustColor;
|
|
53
|
-
exports.adjustTextContrast = index$7.adjustTextContrast;
|
|
54
|
-
exports.alpha = index$7.alpha;
|
|
55
52
|
exports.breakpoints = index$7.breakpoints;
|
|
56
53
|
exports.css = index$7.css;
|
|
57
54
|
exports.themeRootClass = index$8.themeRootClass;
|
package/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { default as useBreakpoint } from './breakpoint/useBreakpoint.js';
|
|
|
5
5
|
export { default as useBreakpointProps, useBreakpointPropsType } from './breakpoint/useBreakpointProps.js';
|
|
6
6
|
export { default as useInterface } from './hooks/useInterface.js';
|
|
7
7
|
export { default as useMergeRefs } from './hooks/useMergeRefs.js';
|
|
8
|
-
export { default as Transition, TransitionProps, TransitionVariantTypes } from './Transition/index.js';
|
|
8
|
+
export { default as Transition, TransitionProps, TransitionVariantCallback, TransitionVariantTypes } from './Transition/index.js';
|
|
9
9
|
export { default as AppRoot, AppRootProps } from './AppRoot/index.js';
|
|
10
10
|
export { default as Portal, PortalProps } from './Portal/index.js';
|
|
11
11
|
export { Renderar } from './AppRoot/Renderar.js';
|
|
@@ -16,11 +16,11 @@ export { default as Iframe, IframeProps } from './Iframe/index.js';
|
|
|
16
16
|
export { AnimateOptions, default as animate } from './animate/index.js';
|
|
17
17
|
export { UseTransitionProps, UseTransitionStatus, default as useTransition } from './hooks/useTransition.js';
|
|
18
18
|
export { UseTransitionGroupItem, UseTransitionGroupProps, default as useTransitionGroup } from './hooks/useTransitionGroup.js';
|
|
19
|
-
export {
|
|
19
|
+
export { breakpoints, css } from './css/index.js';
|
|
20
20
|
export { themeRootClass } from './theme/index.js';
|
|
21
21
|
export { Aliases, BreakpointKeys, CSSBreakpointType, CSSOptionProps, CSSProps, CSSValueType, FN, GlobalCSS } from './css/types.js';
|
|
22
22
|
export { CSSPropAsAttr, TagCSSProperties, TagComponentType, TagProps, TagPropsRoot } from './Tag/types.js';
|
|
23
|
-
export { ColorsRefTypes, ObjectType, ThemeColorOption,
|
|
23
|
+
export { BaseTypographyKeys, ColorsRefTypes, ObjectType, ThemeColorKeys, ThemeColorOption, ThemeInterface, ThemeMode, ThemeOptionInput, ThemeOptions, ThemeTypographyItem, TypographyRefTypes } from './theme/types.js';
|
|
24
24
|
export { default as getValue } from './css/getValue.js';
|
|
25
25
|
export { default as getProps } from './css/getProps.js';
|
|
26
26
|
export { default as ThemeProvider, ThemeProviderProps } from './theme/ThemeProvider.js';
|
package/index.js
CHANGED
|
@@ -16,7 +16,7 @@ export { default as Iframe } from './Iframe/index.js';
|
|
|
16
16
|
export { default as animate } from './animate/index.js';
|
|
17
17
|
export { default as useTransition } from './hooks/useTransition.js';
|
|
18
18
|
export { default as useTransitionGroup } from './hooks/useTransitionGroup.js';
|
|
19
|
-
export {
|
|
19
|
+
export { breakpoints, css } from './css/index.js';
|
|
20
20
|
export { themeRootClass } from './theme/index.js';
|
|
21
21
|
export { default as getValue } from './css/getValue.js';
|
|
22
22
|
export { default as getProps } from './css/getProps.js';
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,109 +1,109 @@
|
|
|
1
|
-
# Xanui Core
|
|
2
|
-
|
|
3
|
-
Xanui Core is a lightweight styling and theming toolkit for React. It bundles a constraint-based CSS generator, a TypeScript-friendly `<Tag>` primitive, responsive helpers, and an opinionated theme engine so that design tokens, animations, and layout logic stay consistent across your application.
|
|
4
|
-
|
|
5
|
-
## Highlights
|
|
6
|
-
|
|
7
|
-
- Build any element with `<Tag>` and the ergonomic `sx`/alias props while still passing native attributes.
|
|
8
|
-
- Author design tokens once via `createTheme`, ship them with `ThemeProvider`, and switch them at runtime with `createThemeSwitcher`.
|
|
9
|
-
- Drive responsive layouts using `BreakpointProvider`, `useBreakpoint`, and `useBreakpointProps` without bespoke media queries.
|
|
10
|
-
- Compose micro-animations through `useAnimation`, ready-made `Transition` variants, and reusable CSS utilities.
|
|
11
|
-
- Support SSR portals by rehydrating critical styles with `RenderServerStyles`.
|
|
12
|
-
|
|
13
|
-
## Installation
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm install @xanui/core
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Quick Start
|
|
20
|
-
|
|
21
|
-
```tsx
|
|
22
|
-
import { ThemeProvider, Tag, createTheme, createThemeSwitcher } from '@xanui/core'
|
|
23
|
-
|
|
24
|
-
// Register a custom theme once at startup
|
|
25
|
-
createTheme('brand', {
|
|
26
|
-
colors: {
|
|
27
|
-
brand: { primary: '#7C3AED', secondary: '#5B21B6' },
|
|
28
|
-
},
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
const useThemeSwitcher = createThemeSwitcher('brand', ThemeSwitcherOption)
|
|
32
|
-
|
|
33
|
-
export const App = () => {
|
|
34
|
-
const { name, change } = useThemeSwitcher()
|
|
35
|
-
|
|
36
|
-
return (
|
|
37
|
-
<ThemeProvider theme={name} isRootProvider>
|
|
38
|
-
<Tag
|
|
39
|
-
component="main"
|
|
40
|
-
px={24}
|
|
41
|
-
py={32}
|
|
42
|
-
bgcolor="background"
|
|
43
|
-
color="
|
|
44
|
-
gap={24}
|
|
45
|
-
>
|
|
46
|
-
<Tag component="h1" fontSize="h2">
|
|
47
|
-
Xanui Core
|
|
48
|
-
</Tag>
|
|
49
|
-
|
|
50
|
-
<button onClick={() => change(name === 'brand' ? 'dark' : 'brand')}>
|
|
51
|
-
Toggle Theme
|
|
52
|
-
</button>
|
|
53
|
-
</Tag>
|
|
54
|
-
</ThemeProvider>
|
|
55
|
-
)
|
|
56
|
-
}
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## Core Concepts
|
|
60
|
-
|
|
61
|
-
- **Design Tokens** – `createTheme` merges your overrides with defaults and exposes typed references like `
|
|
62
|
-
- **Adaptive Layout** – Wrap your app with `BreakpointProvider` (automatically included by `ThemeProvider` when `isRootProvider` is `true`) to consume breakpoint helpers throughout the tree.
|
|
63
|
-
- **Composable Styles** – `css`, `getValue`, and `getProps` transform alias props, breakpoints, and pseudo selectors into atomic class names. Use them directly for utilities such as scrollbars or keyframes.
|
|
64
|
-
- **Animation Primitives** – `useAnimation` builds scoped keyframes on the fly; `Transition` controls mount/unmount sequences with variants such as `fade`, `slideDown`, or `collapseVertical`.
|
|
65
|
-
|
|
66
|
-
## Server-Side Rendering
|
|
67
|
-
|
|
68
|
-
When rendering on the server, collect the emitted styles:
|
|
69
|
-
|
|
70
|
-
```tsx
|
|
71
|
-
import RenderServerStyles from '@xanui/core/RenderServerStyles'
|
|
72
|
-
|
|
73
|
-
export const Document = () => (
|
|
74
|
-
<html>
|
|
75
|
-
<head>
|
|
76
|
-
<RenderServerStyles />
|
|
77
|
-
</head>
|
|
78
|
-
<body>{/* app */}</body>
|
|
79
|
-
</html>
|
|
80
|
-
)
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## Documentation
|
|
84
|
-
|
|
85
|
-
Detailed API docs (props tables, option summaries, and usage examples) live inside the `docs/` directory. Each API/component has its own `README.md` for fast reference:
|
|
86
|
-
|
|
87
|
-
- `docs/tag/README.md`
|
|
88
|
-
- `docs/theme-provider/README.md`
|
|
89
|
-
- `docs/transition/README.md`
|
|
90
|
-
- `docs/use-animation/README.md`
|
|
91
|
-
- `docs/use-color-template/README.md`
|
|
92
|
-
- `docs/use-interface/README.md`
|
|
93
|
-
- `docs/use-breakpoint/README.md`
|
|
94
|
-
- `docs/use-breakpoint-props/README.md`
|
|
95
|
-
- `docs/use-scrollbar/README.md`
|
|
96
|
-
- `docs/render-server-styles/README.md`
|
|
97
|
-
- `docs/css/README.md`
|
|
98
|
-
- `docs/create-theme/README.md`
|
|
99
|
-
|
|
100
|
-
## Contributing
|
|
101
|
-
|
|
102
|
-
1. Fork and clone the repo.
|
|
103
|
-
2. Run `npm install`.
|
|
104
|
-
3. Use `npm run build` to verify type safety.
|
|
105
|
-
4. Submit a pull request that focuses on one improvement at a time.
|
|
106
|
-
|
|
107
|
-
---
|
|
108
|
-
|
|
109
|
-
Need another integration example or a new preset? Open an issue so we can keep the primitives lean and discoverable.
|
|
1
|
+
# Xanui Core
|
|
2
|
+
|
|
3
|
+
Xanui Core is a lightweight styling and theming toolkit for React. It bundles a constraint-based CSS generator, a TypeScript-friendly `<Tag>` primitive, responsive helpers, and an opinionated theme engine so that design tokens, animations, and layout logic stay consistent across your application.
|
|
4
|
+
|
|
5
|
+
## Highlights
|
|
6
|
+
|
|
7
|
+
- Build any element with `<Tag>` and the ergonomic `sx`/alias props while still passing native attributes.
|
|
8
|
+
- Author design tokens once via `createTheme`, ship them with `ThemeProvider`, and switch them at runtime with `createThemeSwitcher`.
|
|
9
|
+
- Drive responsive layouts using `BreakpointProvider`, `useBreakpoint`, and `useBreakpointProps` without bespoke media queries.
|
|
10
|
+
- Compose micro-animations through `useAnimation`, ready-made `Transition` variants, and reusable CSS utilities.
|
|
11
|
+
- Support SSR portals by rehydrating critical styles with `RenderServerStyles`.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @xanui/core
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { ThemeProvider, Tag, createTheme, createThemeSwitcher } from '@xanui/core'
|
|
23
|
+
|
|
24
|
+
// Register a custom theme once at startup
|
|
25
|
+
createTheme('brand', {
|
|
26
|
+
colors: {
|
|
27
|
+
brand: { primary: '#7C3AED', secondary: '#5B21B6' },
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const useThemeSwitcher = createThemeSwitcher('brand', ThemeSwitcherOption)
|
|
32
|
+
|
|
33
|
+
export const App = () => {
|
|
34
|
+
const { name, change } = useThemeSwitcher()
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<ThemeProvider theme={name} isRootProvider>
|
|
38
|
+
<Tag
|
|
39
|
+
component="main"
|
|
40
|
+
px={24}
|
|
41
|
+
py={32}
|
|
42
|
+
bgcolor="background"
|
|
43
|
+
color="surface.contrast"
|
|
44
|
+
gap={24}
|
|
45
|
+
>
|
|
46
|
+
<Tag component="h1" fontSize="h2">
|
|
47
|
+
Xanui Core
|
|
48
|
+
</Tag>
|
|
49
|
+
|
|
50
|
+
<button onClick={() => change(name === 'brand' ? 'dark' : 'brand')}>
|
|
51
|
+
Toggle Theme
|
|
52
|
+
</button>
|
|
53
|
+
</Tag>
|
|
54
|
+
</ThemeProvider>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Core Concepts
|
|
60
|
+
|
|
61
|
+
- **Design Tokens** – `createTheme` merges your overrides with defaults and exposes typed references like `primary.main` or typography presets.
|
|
62
|
+
- **Adaptive Layout** – Wrap your app with `BreakpointProvider` (automatically included by `ThemeProvider` when `isRootProvider` is `true`) to consume breakpoint helpers throughout the tree.
|
|
63
|
+
- **Composable Styles** – `css`, `getValue`, and `getProps` transform alias props, breakpoints, and pseudo selectors into atomic class names. Use them directly for utilities such as scrollbars or keyframes.
|
|
64
|
+
- **Animation Primitives** – `useAnimation` builds scoped keyframes on the fly; `Transition` controls mount/unmount sequences with variants such as `fade`, `slideDown`, or `collapseVertical`.
|
|
65
|
+
|
|
66
|
+
## Server-Side Rendering
|
|
67
|
+
|
|
68
|
+
When rendering on the server, collect the emitted styles:
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
import RenderServerStyles from '@xanui/core/RenderServerStyles'
|
|
72
|
+
|
|
73
|
+
export const Document = () => (
|
|
74
|
+
<html>
|
|
75
|
+
<head>
|
|
76
|
+
<RenderServerStyles />
|
|
77
|
+
</head>
|
|
78
|
+
<body>{/* app */}</body>
|
|
79
|
+
</html>
|
|
80
|
+
)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Documentation
|
|
84
|
+
|
|
85
|
+
Detailed API docs (props tables, option summaries, and usage examples) live inside the `docs/` directory. Each API/component has its own `README.md` for fast reference:
|
|
86
|
+
|
|
87
|
+
- `docs/tag/README.md`
|
|
88
|
+
- `docs/theme-provider/README.md`
|
|
89
|
+
- `docs/transition/README.md`
|
|
90
|
+
- `docs/use-animation/README.md`
|
|
91
|
+
- `docs/use-color-template/README.md`
|
|
92
|
+
- `docs/use-interface/README.md`
|
|
93
|
+
- `docs/use-breakpoint/README.md`
|
|
94
|
+
- `docs/use-breakpoint-props/README.md`
|
|
95
|
+
- `docs/use-scrollbar/README.md`
|
|
96
|
+
- `docs/render-server-styles/README.md`
|
|
97
|
+
- `docs/css/README.md`
|
|
98
|
+
- `docs/create-theme/README.md`
|
|
99
|
+
|
|
100
|
+
## Contributing
|
|
101
|
+
|
|
102
|
+
1. Fork and clone the repo.
|
|
103
|
+
2. Run `npm install`.
|
|
104
|
+
3. Use `npm run build` to verify type safety.
|
|
105
|
+
4. Submit a pull request that focuses on one improvement at a time.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
Need another integration example or a new preset? Open an issue so we can keep the primitives lean and discoverable.
|