@xanui/core 1.1.0 → 1.1.2

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 (174) hide show
  1. package/main.tsx +97 -0
  2. package/package.json +51 -22
  3. package/src/ServerStyleTags.tsx +12 -0
  4. package/src/Tag/cssPropList.ts +191 -0
  5. package/src/Tag/index.tsx +11 -0
  6. package/{Tag/types.d.ts → src/Tag/types.ts} +13 -9
  7. package/src/Tag/useTagProps.ts +28 -0
  8. package/src/Transition/index.tsx +148 -0
  9. package/src/Transition/variants.ts +178 -0
  10. package/src/breakpoint/index.tsx +52 -0
  11. package/src/breakpoint/useBreakpoint.ts +31 -0
  12. package/src/breakpoint/useBreakpointProps.ts +57 -0
  13. package/src/css/aliases.ts +35 -0
  14. package/src/css/getProps.ts +38 -0
  15. package/src/css/getValue.ts +117 -0
  16. package/src/css/index.ts +78 -0
  17. package/{css/types.d.ts → src/css/types.ts} +22 -16
  18. package/src/index.ts +34 -0
  19. package/src/isWindow.ts +3 -0
  20. package/src/theme/ThemeCssVars.ts +107 -0
  21. package/src/theme/ThemeDefaultOptions.ts +146 -0
  22. package/src/theme/ThemeProvider.tsx +140 -0
  23. package/src/theme/core.ts +21 -0
  24. package/src/theme/createColor.ts +53 -0
  25. package/src/theme/createTheme.ts +33 -0
  26. package/src/theme/createThemeSwitcher.ts +18 -0
  27. package/src/theme/index.tsx +17 -0
  28. package/{theme/types.d.ts → src/theme/types.ts} +103 -46
  29. package/src/useAnimation.ts +40 -0
  30. package/src/useColorTemplate.ts +11 -0
  31. package/src/useInterface.ts +13 -0
  32. package/tsconfig.json +28 -0
  33. package/ServerStyleTags.cjs +0 -2
  34. package/ServerStyleTags.cjs.map +0 -7
  35. package/ServerStyleTags.d.ts +0 -3
  36. package/ServerStyleTags.mjs +0 -2
  37. package/ServerStyleTags.mjs.map +0 -7
  38. package/Tag/cssPropList.cjs +0 -2
  39. package/Tag/cssPropList.cjs.map +0 -7
  40. package/Tag/cssPropList.d.ts +0 -2
  41. package/Tag/cssPropList.mjs +0 -2
  42. package/Tag/cssPropList.mjs.map +0 -7
  43. package/Tag/index.cjs +0 -2
  44. package/Tag/index.cjs.map +0 -7
  45. package/Tag/index.d.ts +0 -4
  46. package/Tag/index.mjs +0 -2
  47. package/Tag/index.mjs.map +0 -7
  48. package/Tag/types.cjs +0 -2
  49. package/Tag/types.cjs.map +0 -7
  50. package/Tag/types.mjs +0 -1
  51. package/Tag/types.mjs.map +0 -7
  52. package/Tag/useTagProps.cjs +0 -2
  53. package/Tag/useTagProps.cjs.map +0 -7
  54. package/Tag/useTagProps.d.ts +0 -3
  55. package/Tag/useTagProps.mjs +0 -2
  56. package/Tag/useTagProps.mjs.map +0 -7
  57. package/Transition/index.cjs +0 -2
  58. package/Transition/index.cjs.map +0 -7
  59. package/Transition/index.d.ts +0 -31
  60. package/Transition/index.mjs +0 -2
  61. package/Transition/index.mjs.map +0 -7
  62. package/Transition/variants.cjs +0 -2
  63. package/Transition/variants.cjs.map +0 -7
  64. package/Transition/variants.d.ts +0 -131
  65. package/Transition/variants.mjs +0 -2
  66. package/Transition/variants.mjs.map +0 -7
  67. package/breakpoint/index.cjs +0 -2
  68. package/breakpoint/index.cjs.map +0 -7
  69. package/breakpoint/index.d.ts +0 -6
  70. package/breakpoint/index.mjs +0 -2
  71. package/breakpoint/index.mjs.map +0 -7
  72. package/breakpoint/useBreakpoint.cjs +0 -2
  73. package/breakpoint/useBreakpoint.cjs.map +0 -7
  74. package/breakpoint/useBreakpoint.d.ts +0 -10
  75. package/breakpoint/useBreakpoint.mjs +0 -2
  76. package/breakpoint/useBreakpoint.mjs.map +0 -7
  77. package/breakpoint/useBreakpointProps.cjs +0 -2
  78. package/breakpoint/useBreakpointProps.cjs.map +0 -7
  79. package/breakpoint/useBreakpointProps.d.ts +0 -6
  80. package/breakpoint/useBreakpointProps.mjs +0 -2
  81. package/breakpoint/useBreakpointProps.mjs.map +0 -7
  82. package/css/aliases.cjs +0 -2
  83. package/css/aliases.cjs.map +0 -7
  84. package/css/aliases.d.ts +0 -4
  85. package/css/aliases.mjs +0 -2
  86. package/css/aliases.mjs.map +0 -7
  87. package/css/getProps.cjs +0 -2
  88. package/css/getProps.cjs.map +0 -7
  89. package/css/getProps.d.ts +0 -3
  90. package/css/getProps.mjs +0 -2
  91. package/css/getProps.mjs.map +0 -7
  92. package/css/getValue.cjs +0 -2
  93. package/css/getValue.cjs.map +0 -7
  94. package/css/getValue.d.ts +0 -3
  95. package/css/getValue.mjs +0 -2
  96. package/css/getValue.mjs.map +0 -7
  97. package/css/index.cjs +0 -2
  98. package/css/index.cjs.map +0 -7
  99. package/css/index.d.ts +0 -15
  100. package/css/index.mjs +0 -2
  101. package/css/index.mjs.map +0 -7
  102. package/css/types.cjs +0 -2
  103. package/css/types.cjs.map +0 -7
  104. package/css/types.mjs +0 -1
  105. package/css/types.mjs.map +0 -7
  106. package/index.cjs +0 -2
  107. package/index.cjs.map +0 -7
  108. package/index.d.ts +0 -21
  109. package/index.mjs +0 -2
  110. package/index.mjs.map +0 -7
  111. package/isWindow.cjs +0 -2
  112. package/isWindow.cjs.map +0 -7
  113. package/isWindow.d.ts +0 -2
  114. package/isWindow.mjs +0 -2
  115. package/isWindow.mjs.map +0 -7
  116. package/theme/ThemeCssVars.cjs +0 -2
  117. package/theme/ThemeCssVars.cjs.map +0 -7
  118. package/theme/ThemeCssVars.d.ts +0 -3
  119. package/theme/ThemeCssVars.mjs +0 -2
  120. package/theme/ThemeCssVars.mjs.map +0 -7
  121. package/theme/ThemeDefaultOptions.cjs +0 -2
  122. package/theme/ThemeDefaultOptions.cjs.map +0 -7
  123. package/theme/ThemeDefaultOptions.d.ts +0 -68
  124. package/theme/ThemeDefaultOptions.mjs +0 -2
  125. package/theme/ThemeDefaultOptions.mjs.map +0 -7
  126. package/theme/ThemeProvider.cjs +0 -2
  127. package/theme/ThemeProvider.cjs.map +0 -7
  128. package/theme/ThemeProvider.d.ts +0 -11
  129. package/theme/ThemeProvider.mjs +0 -2
  130. package/theme/ThemeProvider.mjs.map +0 -7
  131. package/theme/core.cjs +0 -2
  132. package/theme/core.cjs.map +0 -7
  133. package/theme/core.d.ts +0 -7
  134. package/theme/core.mjs +0 -2
  135. package/theme/core.mjs.map +0 -7
  136. package/theme/createColor.cjs +0 -2
  137. package/theme/createColor.cjs.map +0 -7
  138. package/theme/createColor.d.ts +0 -41
  139. package/theme/createColor.mjs +0 -2
  140. package/theme/createColor.mjs.map +0 -7
  141. package/theme/createTheme.cjs +0 -2
  142. package/theme/createTheme.cjs.map +0 -7
  143. package/theme/createTheme.d.ts +0 -2
  144. package/theme/createTheme.mjs +0 -2
  145. package/theme/createTheme.mjs.map +0 -7
  146. package/theme/createThemeSwitcher.cjs +0 -2
  147. package/theme/createThemeSwitcher.cjs.map +0 -7
  148. package/theme/createThemeSwitcher.d.ts +0 -6
  149. package/theme/createThemeSwitcher.mjs +0 -2
  150. package/theme/createThemeSwitcher.mjs.map +0 -7
  151. package/theme/index.cjs +0 -2
  152. package/theme/index.cjs.map +0 -7
  153. package/theme/index.d.ts +0 -5
  154. package/theme/index.mjs +0 -2
  155. package/theme/index.mjs.map +0 -7
  156. package/theme/types.cjs +0 -2
  157. package/theme/types.cjs.map +0 -7
  158. package/theme/types.mjs +0 -1
  159. package/theme/types.mjs.map +0 -7
  160. package/useAnimation.cjs +0 -2
  161. package/useAnimation.cjs.map +0 -7
  162. package/useAnimation.d.ts +0 -18
  163. package/useAnimation.mjs +0 -2
  164. package/useAnimation.mjs.map +0 -7
  165. package/useColorTemplate.cjs +0 -2
  166. package/useColorTemplate.cjs.map +0 -7
  167. package/useColorTemplate.d.ts +0 -4
  168. package/useColorTemplate.mjs +0 -2
  169. package/useColorTemplate.mjs.map +0 -7
  170. package/useInterface.cjs +0 -2
  171. package/useInterface.cjs.map +0 -7
  172. package/useInterface.d.ts +0 -2
  173. package/useInterface.mjs +0 -2
  174. package/useInterface.mjs.map +0 -7
@@ -0,0 +1,178 @@
1
+ import { TransitionElementProps } from "."
2
+
3
+ export const slideDown = (_arg: TransitionElementProps) => {
4
+ return {
5
+ from: {
6
+ transform: `translateY(-${_arg.height}px)!important`,
7
+ },
8
+ to: {
9
+ transform: `translateY(0)!important`,
10
+ }
11
+ }
12
+ }
13
+
14
+ export const slideUp = (_arg: TransitionElementProps) => {
15
+ return {
16
+ from: {
17
+ transform: `translateY(${_arg.height}px)!important`,
18
+ },
19
+ to: {
20
+ transform: `translateY(0)!important`,
21
+ }
22
+ }
23
+ }
24
+
25
+ export const slideRight = (_arg: TransitionElementProps) => {
26
+ return {
27
+ from: {
28
+ transform: `translateX(-${_arg.width}px)!important`,
29
+ },
30
+ to: {
31
+ transform: `translateX(0)!important`,
32
+ }
33
+ }
34
+ }
35
+
36
+ export const slideLeft = (_arg: TransitionElementProps) => {
37
+ return {
38
+ from: {
39
+ transform: `translateX(${_arg.width}px)!important`,
40
+ },
41
+ to: {
42
+ transform: `translateX(0)!important`,
43
+ }
44
+ }
45
+ }
46
+
47
+ export const fade = (_arg: TransitionElementProps) => {
48
+ return {
49
+ from: {
50
+ opacity: 0
51
+ },
52
+ to: {
53
+ opacity: 1
54
+ }
55
+ }
56
+ }
57
+
58
+ export const fadeDown = (_arg: TransitionElementProps) => {
59
+ return {
60
+ from: {
61
+ transform: `translateY(-30px)!important`,
62
+ opacity: 0
63
+ },
64
+ to: {
65
+ transform: `translateY(0)!important`,
66
+ opacity: 1
67
+ }
68
+ }
69
+ }
70
+
71
+ export const fadeUp = (_arg: TransitionElementProps) => {
72
+ return {
73
+ from: {
74
+ transform: `translateY(30px)!important`,
75
+ opacity: 0
76
+ },
77
+ to: {
78
+ transform: `translateY(0)!important`,
79
+ opacity: 1
80
+ }
81
+ }
82
+ }
83
+
84
+ export const fadeRight = (_arg: TransitionElementProps) => {
85
+ return {
86
+ from: {
87
+ transform: `translateX(-30px)!important`,
88
+ opacity: 0
89
+ },
90
+ to: {
91
+ transform: `translateX(0)!important`,
92
+ opacity: 1
93
+ }
94
+ }
95
+ }
96
+
97
+ export const fadeLeft = (_arg: TransitionElementProps) => {
98
+ return {
99
+ from: {
100
+ transform: `translateX(30px)!important`,
101
+ opacity: 0
102
+ },
103
+ to: {
104
+ transform: `translateX(0)!important`,
105
+ opacity: 1
106
+ }
107
+ }
108
+ }
109
+
110
+ export const grow = (_arg: TransitionElementProps) => {
111
+ return {
112
+ from: {
113
+ transform: "scale(.8, .6)!important",
114
+ opacity: 0
115
+ },
116
+ to: {
117
+ transform: "scale(1)!important",
118
+ opacity: 1
119
+ }
120
+ }
121
+ }
122
+
123
+ export const zoom = (_arg: TransitionElementProps) => {
124
+ return {
125
+ from: {
126
+ transform: "scale(.8)!important",
127
+ opacity: 0
128
+ },
129
+ to: {
130
+ transform: "scale(1)!important",
131
+ opacity: 1
132
+ }
133
+ }
134
+ }
135
+
136
+ export const zoomOver = (_arg: TransitionElementProps) => {
137
+ return {
138
+ from: {
139
+ transform: "scale(1.2)!important",
140
+ opacity: 0
141
+ },
142
+ to: {
143
+ transform: "scale(1)!important",
144
+ opacity: 1
145
+ }
146
+ }
147
+ }
148
+
149
+ export const collapsVerticle = (_arg: TransitionElementProps) => {
150
+ return {
151
+ from: {
152
+ height: 0 + "px!important",
153
+ overflow: "hidden"
154
+ },
155
+ to: {
156
+ height: _arg?.height ? _arg?.height + "px!important" : "auto",
157
+ overflow: "hidden"
158
+ }
159
+ }
160
+ }
161
+
162
+
163
+ export const collapsHorizental = (_arg: TransitionElementProps) => {
164
+ return {
165
+ from: {
166
+ width: 0 + "px!important",
167
+ overflow: "hidden"
168
+ },
169
+ to: {
170
+ width: _arg?.width ? _arg?.width + "px!important" : "auto",
171
+ overflow: "hidden"
172
+ }
173
+ }
174
+ }
175
+
176
+
177
+
178
+
@@ -0,0 +1,52 @@
1
+ import React, { ReactNode, useState } from "react";
2
+ import isWindow from "../isWindow";
3
+ import { breakpoints } from "../css";
4
+ import { BreakpointKeys } from "../css/types";
5
+
6
+ export const BreakpointCtx = React.createContext<BreakpointKeys>("xl")
7
+
8
+ const getKey = (): BreakpointKeys => {
9
+ const isWin = isWindow()
10
+ if (isWin) {
11
+ const width = window.innerWidth
12
+ if (width < breakpoints.sm) {
13
+ return 'xs'
14
+ } else if (width > breakpoints.xs && width < breakpoints.md) {
15
+ return 'sm'
16
+ } else if (width > breakpoints.sm && width < breakpoints.lg) {
17
+ return 'md'
18
+ } else if (width > breakpoints.md && width < breakpoints.xl) {
19
+ return 'lg'
20
+ } else {
21
+ return 'xl'
22
+ }
23
+ } else {
24
+ return 'xl'
25
+ }
26
+ }
27
+
28
+ export const BreakpointProvider = ({ children }: { children?: ReactNode }) => {
29
+ const [current, setCurrent] = useState<BreakpointKeys>(getKey)
30
+
31
+ const handler = () => {
32
+ let c = getKey()
33
+ if (current !== c) {
34
+ setCurrent(c)
35
+ }
36
+ }
37
+
38
+ React.useEffect(() => {
39
+ window.removeEventListener("resize", handler)
40
+ window.addEventListener("resize", handler)
41
+ handler()
42
+ return () => {
43
+ window.removeEventListener("resize", handler)
44
+ }
45
+ }, [current])
46
+
47
+ return (
48
+ <BreakpointCtx.Provider value={current}>
49
+ {children}
50
+ </BreakpointCtx.Provider>
51
+ )
52
+ }
@@ -0,0 +1,31 @@
1
+ import { useContext } from "react"
2
+ import { BreakpointCtx } from "."
3
+ import isWindow from "../isWindow"
4
+ import { breakpoints } from "../css"
5
+ import { BreakpointKeys } from "../css/types"
6
+
7
+ const useBreakpoint = () => {
8
+ const val = useContext(BreakpointCtx)
9
+ const isWin = isWindow()
10
+ const o = {
11
+ value: val,
12
+ is: (key: BreakpointKeys) => val === key,
13
+ isDown: (key: BreakpointKeys) => {
14
+ if (isWin) {
15
+ return window.innerWidth > breakpoints[key]
16
+ }
17
+ return false
18
+ },
19
+ isUp: (key: BreakpointKeys) => {
20
+ if (isWin) {
21
+ return window.innerWidth < breakpoints[key]
22
+ }
23
+ return false
24
+ },
25
+ isOrDown: (key: BreakpointKeys) => o.is(key) || o.isDown(key),
26
+ isOrUp: (key: BreakpointKeys) => o.is(key) || o.isUp(key)
27
+ }
28
+ return o
29
+ }
30
+
31
+ export default useBreakpoint
@@ -0,0 +1,57 @@
1
+ import React, { isValidElement } from "react"
2
+ import useBreakpoint from "./useBreakpoint"
3
+ import { BreakpointKeys } from "../css/types"
4
+
5
+ export type useBreakpointPropsType<P> = P | {
6
+ [key in BreakpointKeys]?: P
7
+ }
8
+
9
+ const useBreakpoinProps = <P extends object>(props: useBreakpointPropsType<P>): useBreakpointPropsType<P> => {
10
+ const bpoint = useBreakpoint()
11
+ const stringifiedElement = JSON.stringify(props, (key, value) => {
12
+ if (key === '_owner' || key === '_store') {
13
+ return undefined; // Skip circular references
14
+ }
15
+ return value;
16
+ }, 2);
17
+
18
+ let format: any = React.useMemo(() => {
19
+
20
+ const _format: any = {
21
+ xs: {},
22
+ sm: {},
23
+ md: {},
24
+ lg: {},
25
+ xl: {}
26
+ }
27
+ for (let prop in props) {
28
+ let val = (props as any)[prop]
29
+ if (!isValidElement(val) && typeof val === 'object') {
30
+ for (let breakpoin in val) {
31
+ _format[breakpoin][prop] = (props as any)[prop][breakpoin]
32
+ }
33
+ } else {
34
+ _format.xs[prop] = (props as any)[prop]
35
+ }
36
+ }
37
+
38
+ return _format
39
+ }, [stringifiedElement, bpoint.value])
40
+
41
+ return React.useMemo(() => {
42
+ let _props = format.xs || {};
43
+ for (let key of ['sm', 'md', 'lg', 'xl']) {
44
+ if (bpoint.isOrDown(key as any)) {
45
+ _props = { ..._props, ...format[key] };
46
+ }
47
+ if (bpoint.is(key as any)) {
48
+ break;
49
+ }
50
+ }
51
+ return _props;
52
+ }, [format, bpoint.value]);
53
+ }
54
+
55
+
56
+
57
+ export default useBreakpoinProps
@@ -0,0 +1,35 @@
1
+ import { OptionAliases } from 'oncss'
2
+ import { Aliases } from './types'
3
+
4
+ const isStr = (v: any, or: any) => typeof v === 'string' ? v : or
5
+
6
+ const aliases: OptionAliases<Aliases> = {
7
+ bgcolor: (v) => ({ backgroundColor: v }),
8
+ bgimage: (v) => ({ backgroundImage: `url(${v})`, backgroundSize: "cover", backgroundRepeat: "no-repeat" }),
9
+ bg: (v) => ({ background: v }),
10
+ p: (v) => ({ padding: isStr(v, 8 * v) }),
11
+ pt: (v) => ({ paddingTop: isStr(v, 8 * v) }),
12
+ pr: (v) => ({ paddingRight: isStr(v, 8 * v) }),
13
+ pb: (v) => ({ paddingBottom: isStr(v, 8 * v) }),
14
+ pl: (v) => ({ paddingLeft: isStr(v, 8 * v) }),
15
+ px: (v) => ({ paddingLeft: isStr(v, 8 * v), paddingRight: isStr(v, 8 * v) }),
16
+ py: (v) => ({ paddingTop: isStr(v, 8 * v), paddingBottom: isStr(v, 8 * v) }),
17
+ m: (v) => ({ margin: isStr(v, 8 * v) }),
18
+ mt: (v) => ({ marginTop: isStr(v, 8 * v) }),
19
+ mr: (v) => ({ marginRight: isStr(v, 8 * v) }),
20
+ mb: (v) => ({ marginBottom: isStr(v, 8 * v) }),
21
+ ml: (v) => ({ marginLeft: isStr(v, 8 * v) }),
22
+ mx: (v) => ({ marginLeft: isStr(v, 8 * v), marginRight: isStr(v, 8 * v) }),
23
+ my: (v) => ({ marginTop: isStr(v, 8 * v), marginBottom: isStr(v, 8 * v) }),
24
+ radius: (v) => ({ borderRadius: isStr(v, 8 * v) }),
25
+ borderRadius: (v) => ({ borderRadius: isStr(v, 8 * v) }),
26
+ shadow: (v) => ({ boxShadow: v }),
27
+ flexBox: (v) => (v ? { display: "flex" } : {}),
28
+ flexRow: (v) => (v ? { flexDirection: "row" } : {}),
29
+ flexColumn: (v) => (v ? { flexDirection: "column" } : {}),
30
+ flexWraped: (v) => (v ? { flexWrap: "wrap" } : {}),
31
+ direction: (v) => (v === 'row' || v === 'column' ? { flexDirection: v } : { direction: v }),
32
+ gap: (v) => ({ gap: isStr(v, 8 * v) }),
33
+ };
34
+
35
+ export default aliases
@@ -0,0 +1,38 @@
1
+ import { CSSProps } from "./types";
2
+
3
+ const getProps = (prop: string, value: string, _css: CSSProps) => {
4
+ let important;
5
+ if (typeof value === 'string') {
6
+ const split = value.split("!")
7
+ important = split[1] ? "!important" : ""
8
+ value = split[0]
9
+ }
10
+
11
+ if (prop === 'disabled') {
12
+ if ((value as any) === true) {
13
+ return {
14
+ pointerEvents: "none!important",
15
+ cursor: "default!important",
16
+ userSelect: "none!important",
17
+ opacity: ".8!important"
18
+ } as any
19
+ }
20
+ return {}
21
+ }
22
+
23
+ if (value && typeof value === "number" && ["border", "borderRight", "borderLeft", "borderTop", "borderBottom"].includes(prop as any)) {
24
+ const keys: any = Object.keys(_css)
25
+ let p: any = {
26
+ [`${prop}Width`]: value + 'px' + (important || ""),
27
+ }
28
+ if (!keys.includes(`${prop}Color`)) {
29
+ p[`${prop}Color`] = "divider"
30
+ }
31
+ if (!keys.includes(`${prop}Style`)) {
32
+ p[`${prop}Style`] = "solid"
33
+ }
34
+ return p
35
+ }
36
+ }
37
+
38
+ export default getProps
@@ -0,0 +1,117 @@
1
+ import { CSSProps } from "./types"
2
+
3
+ const getColor = (color: string) => {
4
+ return {
5
+ [`${color}`]: `var(--color-${color}-primary)`,
6
+ [`${color}.primary`]: `var(--color-${color}-primary)`,
7
+ [`${color}.secondary`]: `var(--color-${color}-secondary)`,
8
+ [`${color}.text`]: `var(--color-${color}-text)`,
9
+ [`${color}.alpha`]: `var(--color-${color}-alpha)`
10
+ }
11
+ }
12
+
13
+ const withImportant = (important: any, value: any) => important ? value + important : value
14
+ const colors: any = {
15
+ "text": `var(--color-text-primary)`,
16
+ "text.primary": `var(--color-text-primary)`,
17
+ "text.secondary": `var(--color-text-secondary)`,
18
+
19
+ "background": `var(--color-background-primary)`,
20
+ "background.primary": `var(--color-background-primary)`,
21
+ "background.secondary": `var(--color-background-secondary)`,
22
+ "background.alpha": `var(--color-background-alpha)`,
23
+ "divider": `var(--color-divider)`,
24
+
25
+ ...getColor("brand"),
26
+ ...getColor("accent"),
27
+ ...getColor("info"),
28
+ ...getColor("success"),
29
+ ...getColor("warning"),
30
+ ...getColor("danger"),
31
+ }
32
+
33
+ const breakpoints: any = {
34
+ "xs": "var(--bp-xs)",
35
+ "sm": "var(--bp-sm)",
36
+ "md": "var(--bp-md)",
37
+ "lg": "var(--bp-lg)",
38
+ "xl": "var(--bp-xl)"
39
+ }
40
+
41
+ let fontsizes: any = {
42
+ "h1": "var(--fontsize-h1)",
43
+ "h2": "var(--fontsize-h2)",
44
+ "h3": "var(--fontsize-h3)",
45
+ "h4": "var(--fontsize-h4)",
46
+ "h5": "var(--fontsize-h5)",
47
+ "h6": "var(--fontsize-h6)",
48
+ "text": "var(--fontsize-text)",
49
+ "button": "var(--fontsize-button)",
50
+ "small": "var(--fontsize-small)"
51
+ }
52
+
53
+ let lineHeights: any = {
54
+ "h1": "var(--lineheight-h1)",
55
+ "h2": "var(--lineheight-h2)",
56
+ "h3": "var(--lineheight-h3)",
57
+ "h4": "var(--lineheight-h4)",
58
+ "h5": "var(--lineheight-h5)",
59
+ "h6": "var(--lineheight-h6)",
60
+ "text": "var(--lineheight-text)",
61
+ "button": "var(--lineheight-button)",
62
+ "small": "var(--lineheight-small)"
63
+ }
64
+
65
+ let fontWeights: any = {
66
+ "h1": "var(--fontweight-h1)",
67
+ "h2": "var(--fontweight-h2)",
68
+ "h3": "var(--fontweight-h3)",
69
+ "h4": "var(--fontweight-h4)",
70
+ "h5": "var(--fontweight-h5)",
71
+ "h6": "var(--fontweight-h6)",
72
+ "text": "var(--fontweight-text)",
73
+ "button": "var(--fontweight-button)",
74
+ "small": "var(--fontweight-small)"
75
+ }
76
+
77
+ let font: any = {
78
+ "h1": "var(--font-h1)",
79
+ "h2": "var(--font-h2)",
80
+ "h3": "var(--font-h3)",
81
+ "h4": "var(--font-h4)",
82
+ "h5": "var(--font-h5)",
83
+ "h6": "var(--font-h6)",
84
+ "text": "var(--font-text)",
85
+ "button": "var(--font-button)",
86
+ "small": "var(--font-small)"
87
+ }
88
+
89
+ const getValue = (prop: any, value: string | number, _css: CSSProps): any => {
90
+ let important;
91
+
92
+ if (typeof value === 'string') {
93
+ const split = value.split("!")
94
+ important = split[1] ? "!important" : ""
95
+ value = split[0]
96
+ }
97
+
98
+ if (['width', 'maxWidth', 'minWidth', 'max-width', 'min-width'].includes(prop)) {
99
+ return withImportant(important, breakpoints[value] || value)
100
+ } else if (['fontFamily', 'font-family'].includes(prop) && value === 'default') {
101
+ return withImportant(important, "var(--font-family)")
102
+ } if (prop === 'font' && typeof value === "string" && ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'text', 'button', 'small'].includes(value)) {
103
+ return withImportant(important, font[value] || value)
104
+ } if (['fontWeight', 'font-weight'].includes(prop) && typeof value === 'string' && ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'text', 'button', 'small'].includes(value)) {
105
+ return withImportant(important, fontWeights[value] || value)
106
+ } else if (['lineHeight', 'line-height'].includes(prop) && typeof value === 'string' && ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'text', 'button', 'small'].includes(value)) {
107
+ return withImportant(important, lineHeights[value] || value)
108
+ } else if (['fontSize', 'font-size'].includes(prop) && typeof value === 'string') {
109
+ return withImportant(important, fontsizes[value] || value)
110
+ } else if (typeof value === "number" && ["shadow", "boxShadow"].includes(prop)) {
111
+ return withImportant(important, `var(--shadow-${value})`)
112
+ }
113
+
114
+ return withImportant(important, colors[value] || value)
115
+ }
116
+
117
+ export default getValue
@@ -0,0 +1,78 @@
1
+ import getValue from "./getValue"
2
+ import getProps from "./getProps"
3
+ import aliases from "./aliases"
4
+ import { Aliases, BreakpointKeys, CSSOptionProps, CSSProps } from './types'
5
+ import { css as _css } from "oncss"
6
+
7
+ export {
8
+ getValue,
9
+ getProps
10
+ }
11
+
12
+ export const breakpoints = {
13
+ xs: 0,
14
+ sm: 600,
15
+ md: 900,
16
+ lg: 1200,
17
+ xl: 1536
18
+ }
19
+
20
+ export const css = (props: CSSProps, options?: CSSOptionProps) => {
21
+ const cssOptions: CSSOptionProps = {
22
+ ...options,
23
+ breakpoints,
24
+ aliases,
25
+ getValue: (p: any, v: any, _c: any, dept) => {
26
+ if (options?.getValue) {
27
+ let _val = options?.getValue(p, v, _c, dept)
28
+ if (_val) return _val
29
+ }
30
+ return getValue(p, v, _c)
31
+ },
32
+ getProps: (p: any, v: any, _c: any, dept) => {
33
+ if (options?.getProps) {
34
+ let _p = options?.getProps(p, v, _c, dept)
35
+ if (_p) return _p
36
+ }
37
+ return getProps(p, v, _c)
38
+ },
39
+ }
40
+ return _css<Aliases, BreakpointKeys>(props, cssOptions)
41
+ }
42
+
43
+ export const adjustColor = (hex: string, factor: number) => {
44
+
45
+ hex = hex.replace(/^#/, '')
46
+
47
+ let r = parseInt(hex.slice(0, 2), 16)
48
+ let g = parseInt(hex.slice(2, 4), 16)
49
+ let b = parseInt(hex.slice(4, 6), 16)
50
+
51
+ r = Math.floor(r * factor)
52
+ g = Math.floor(g * factor)
53
+ b = Math.floor(b * factor)
54
+
55
+ r = Math.min(255, Math.max(0, r))
56
+ g = Math.min(255, Math.max(0, g))
57
+ b = Math.min(255, Math.max(0, b))
58
+
59
+ return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`;
60
+ }
61
+
62
+ export const adjustTextContrast = (color: string) => {
63
+ color = color.replace(/^#/, '')
64
+ const r = parseInt(color.slice(0, 2), 16);
65
+ const g = parseInt(color.slice(2, 4), 16);
66
+ const b = parseInt(color.slice(4, 6), 16);
67
+
68
+ const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
69
+ return luminance > 0.5 ? '#111111' : '#FFFFFF';
70
+ }
71
+
72
+ export const alpha = (color: string, opacity = 1) => {
73
+ if (typeof opacity !== 'number') return color
74
+ let _opacity = opacity * 100
75
+ if (!color.startsWith("#")) throw new Error(`color must be hex`)
76
+ return (color + (`0${Math.round((255 / 100) * _opacity).toString(16)}`.slice(-2))).toUpperCase();
77
+ };
78
+
@@ -1,11 +1,10 @@
1
- import * as CSS from 'csstype';
2
- import { ColorsRefTypes, TypographyRefTypes, ThemeOptions } from '../theme/types';
3
- import * as oncss from 'oncss';
4
- export type FN = (theme: ThemeOptions) => string | number;
5
- export type CSSBreakpointType = {
6
- [key in BreakpointKeys]: string | number;
7
- };
8
- export type CSSValueType<T extends keyof CSS.Properties> = CSS.Properties[T] | Partial<CSSBreakpointType> | number;
1
+ import * as CSS from 'csstype'
2
+ import { ColorsRefTypes, TypographyRefTypes, ThemeOptions, } from '../theme/types';
3
+ import * as oncss from 'oncss'
4
+ export type FN = (theme: ThemeOptions) => string | number
5
+ export type CSSBreakpointType = { [key in BreakpointKeys]: string | number }
6
+ export type CSSValueType<T extends keyof CSS.Properties> = CSS.Properties[T] | Partial<CSSBreakpointType> | number
7
+
9
8
  export type Aliases = {
10
9
  bgcolor?: CSSValueType<'background'> | ColorsRefTypes;
11
10
  bgimage?: CSSValueType<'backgroundImage'>;
@@ -26,6 +25,7 @@ export type Aliases = {
26
25
  my?: CSSValueType<'margin'>;
27
26
  size?: CSSValueType<'width'>;
28
27
  spacing?: Partial<CSSBreakpointType> | number;
28
+
29
29
  radius?: CSSValueType<'borderRadius'> | number;
30
30
  borderRadius?: CSSValueType<'borderRadius'> | number;
31
31
  shadow?: CSSValueType<'boxShadow'> | number;
@@ -35,20 +35,26 @@ export type Aliases = {
35
35
  flexWraped?: boolean;
36
36
  direction?: "row" | "column" | CSSValueType<'direction'>;
37
37
  gap?: CSSValueType<'gap'>;
38
+
38
39
  color?: CSSValueType<'color'> | ColorsRefTypes;
39
40
  width?: CSSValueType<'width'> | BreakpointKeys;
40
- height?: CSSValueType<'height'>;
41
+ height?: CSSValueType<'height'>
41
42
  borderColor?: CSSValueType<'backgroundColor'> | ColorsRefTypes;
43
+
42
44
  fontFamily?: CSSValueType<"fontFamily"> | "default";
43
45
  fontSize?: CSSValueType<"fontSize"> | TypographyRefTypes;
44
46
  minWidth?: CSSValueType<"minWidth"> | BreakpointKeys;
45
47
  maxWidth?: CSSValueType<"maxWidth"> | BreakpointKeys;
46
- minHeight?: CSSValueType<"minHeight">;
47
- maxHeight?: CSSValueType<"maxHeight">;
48
- };
49
- export type BreakpointKeys = "xs" | "sm" | "md" | "lg" | "xl";
50
- export type CSSProps = oncss.CSSProps<Aliases, BreakpointKeys>;
51
- export type CSSOptionProps = oncss.CSSOptionProps<Aliases, BreakpointKeys>;
48
+ minHeight?: CSSValueType<"minHeight">
49
+ maxHeight?: CSSValueType<"maxHeight">
50
+ }
51
+
52
+
53
+ export type BreakpointKeys = "xs" | "sm" | "md" | "lg" | "xl"
54
+
55
+ export type CSSProps = oncss.CSSProps<Aliases, BreakpointKeys>
56
+ export type CSSOptionProps = oncss.CSSOptionProps<Aliases, BreakpointKeys>
57
+
52
58
  export type GlobalCSS = {
53
59
  [key: string]: oncss.CSSPropsWithoutGlobal<Aliases, BreakpointKeys>;
54
- };
60
+ }
package/src/index.ts ADDED
@@ -0,0 +1,34 @@
1
+ import Tag from './Tag'
2
+ import useTagProps from './Tag/useTagProps'
3
+ import useAnimation from './useAnimation'
4
+ import useColorTemplate from './useColorTemplate'
5
+ import useBreakpoint from './breakpoint/useBreakpoint'
6
+ import useBreakpointProps from './breakpoint/useBreakpointProps'
7
+ import ServerStyleTags from './ServerStyleTags'
8
+ import isWindow from './isWindow'
9
+ import useInterface from './useInterface'
10
+ import Transition from './Transition'
11
+
12
+ export * from './css'
13
+ export * from "./theme"
14
+ export * from './css/types'
15
+ export * from './Tag/types'
16
+ export * from './theme/types'
17
+ export * from './useColorTemplate'
18
+ export * from './useAnimation'
19
+ export type * from './Transition'
20
+ export type * from './Tag/types'
21
+ export type { useBreakpointPropsType } from './breakpoint/useBreakpointProps'
22
+
23
+ export {
24
+ Tag,
25
+ useTagProps,
26
+ useAnimation,
27
+ Transition,
28
+ useColorTemplate,
29
+ ServerStyleTags,
30
+ useBreakpoint,
31
+ useBreakpointProps,
32
+ isWindow,
33
+ useInterface
34
+ }
@@ -0,0 +1,3 @@
1
+
2
+ const isWindow = (): Window | void => typeof window !== 'undefined' ? window : undefined
3
+ export default isWindow