@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.
- package/main.tsx +97 -0
- package/package.json +51 -22
- package/src/ServerStyleTags.tsx +12 -0
- package/src/Tag/cssPropList.ts +191 -0
- package/src/Tag/index.tsx +11 -0
- package/{Tag/types.d.ts → src/Tag/types.ts} +13 -9
- package/src/Tag/useTagProps.ts +28 -0
- package/src/Transition/index.tsx +148 -0
- package/src/Transition/variants.ts +178 -0
- package/src/breakpoint/index.tsx +52 -0
- package/src/breakpoint/useBreakpoint.ts +31 -0
- package/src/breakpoint/useBreakpointProps.ts +57 -0
- package/src/css/aliases.ts +35 -0
- package/src/css/getProps.ts +38 -0
- package/src/css/getValue.ts +117 -0
- package/src/css/index.ts +78 -0
- package/{css/types.d.ts → src/css/types.ts} +22 -16
- package/src/index.ts +34 -0
- package/src/isWindow.ts +3 -0
- package/src/theme/ThemeCssVars.ts +107 -0
- package/src/theme/ThemeDefaultOptions.ts +146 -0
- package/src/theme/ThemeProvider.tsx +140 -0
- package/src/theme/core.ts +21 -0
- package/src/theme/createColor.ts +53 -0
- package/src/theme/createTheme.ts +33 -0
- package/src/theme/createThemeSwitcher.ts +18 -0
- package/src/theme/index.tsx +17 -0
- package/{theme/types.d.ts → src/theme/types.ts} +103 -46
- package/src/useAnimation.ts +40 -0
- package/src/useColorTemplate.ts +11 -0
- package/src/useInterface.ts +13 -0
- package/tsconfig.json +28 -0
- package/ServerStyleTags.cjs +0 -2
- package/ServerStyleTags.cjs.map +0 -7
- package/ServerStyleTags.d.ts +0 -3
- package/ServerStyleTags.mjs +0 -2
- package/ServerStyleTags.mjs.map +0 -7
- package/Tag/cssPropList.cjs +0 -2
- package/Tag/cssPropList.cjs.map +0 -7
- package/Tag/cssPropList.d.ts +0 -2
- package/Tag/cssPropList.mjs +0 -2
- package/Tag/cssPropList.mjs.map +0 -7
- package/Tag/index.cjs +0 -2
- package/Tag/index.cjs.map +0 -7
- package/Tag/index.d.ts +0 -4
- package/Tag/index.mjs +0 -2
- package/Tag/index.mjs.map +0 -7
- package/Tag/types.cjs +0 -2
- package/Tag/types.cjs.map +0 -7
- package/Tag/types.mjs +0 -1
- package/Tag/types.mjs.map +0 -7
- package/Tag/useTagProps.cjs +0 -2
- package/Tag/useTagProps.cjs.map +0 -7
- package/Tag/useTagProps.d.ts +0 -3
- package/Tag/useTagProps.mjs +0 -2
- package/Tag/useTagProps.mjs.map +0 -7
- package/Transition/index.cjs +0 -2
- package/Transition/index.cjs.map +0 -7
- package/Transition/index.d.ts +0 -31
- package/Transition/index.mjs +0 -2
- package/Transition/index.mjs.map +0 -7
- package/Transition/variants.cjs +0 -2
- package/Transition/variants.cjs.map +0 -7
- package/Transition/variants.d.ts +0 -131
- package/Transition/variants.mjs +0 -2
- package/Transition/variants.mjs.map +0 -7
- package/breakpoint/index.cjs +0 -2
- package/breakpoint/index.cjs.map +0 -7
- package/breakpoint/index.d.ts +0 -6
- package/breakpoint/index.mjs +0 -2
- package/breakpoint/index.mjs.map +0 -7
- package/breakpoint/useBreakpoint.cjs +0 -2
- package/breakpoint/useBreakpoint.cjs.map +0 -7
- package/breakpoint/useBreakpoint.d.ts +0 -10
- package/breakpoint/useBreakpoint.mjs +0 -2
- package/breakpoint/useBreakpoint.mjs.map +0 -7
- package/breakpoint/useBreakpointProps.cjs +0 -2
- package/breakpoint/useBreakpointProps.cjs.map +0 -7
- package/breakpoint/useBreakpointProps.d.ts +0 -6
- package/breakpoint/useBreakpointProps.mjs +0 -2
- package/breakpoint/useBreakpointProps.mjs.map +0 -7
- package/css/aliases.cjs +0 -2
- package/css/aliases.cjs.map +0 -7
- package/css/aliases.d.ts +0 -4
- package/css/aliases.mjs +0 -2
- package/css/aliases.mjs.map +0 -7
- package/css/getProps.cjs +0 -2
- package/css/getProps.cjs.map +0 -7
- package/css/getProps.d.ts +0 -3
- package/css/getProps.mjs +0 -2
- package/css/getProps.mjs.map +0 -7
- package/css/getValue.cjs +0 -2
- package/css/getValue.cjs.map +0 -7
- package/css/getValue.d.ts +0 -3
- package/css/getValue.mjs +0 -2
- package/css/getValue.mjs.map +0 -7
- package/css/index.cjs +0 -2
- package/css/index.cjs.map +0 -7
- package/css/index.d.ts +0 -15
- package/css/index.mjs +0 -2
- package/css/index.mjs.map +0 -7
- package/css/types.cjs +0 -2
- package/css/types.cjs.map +0 -7
- package/css/types.mjs +0 -1
- package/css/types.mjs.map +0 -7
- package/index.cjs +0 -2
- package/index.cjs.map +0 -7
- package/index.d.ts +0 -21
- package/index.mjs +0 -2
- package/index.mjs.map +0 -7
- package/isWindow.cjs +0 -2
- package/isWindow.cjs.map +0 -7
- package/isWindow.d.ts +0 -2
- package/isWindow.mjs +0 -2
- package/isWindow.mjs.map +0 -7
- package/theme/ThemeCssVars.cjs +0 -2
- package/theme/ThemeCssVars.cjs.map +0 -7
- package/theme/ThemeCssVars.d.ts +0 -3
- package/theme/ThemeCssVars.mjs +0 -2
- package/theme/ThemeCssVars.mjs.map +0 -7
- package/theme/ThemeDefaultOptions.cjs +0 -2
- package/theme/ThemeDefaultOptions.cjs.map +0 -7
- package/theme/ThemeDefaultOptions.d.ts +0 -68
- package/theme/ThemeDefaultOptions.mjs +0 -2
- package/theme/ThemeDefaultOptions.mjs.map +0 -7
- package/theme/ThemeProvider.cjs +0 -2
- package/theme/ThemeProvider.cjs.map +0 -7
- package/theme/ThemeProvider.d.ts +0 -11
- package/theme/ThemeProvider.mjs +0 -2
- package/theme/ThemeProvider.mjs.map +0 -7
- package/theme/core.cjs +0 -2
- package/theme/core.cjs.map +0 -7
- package/theme/core.d.ts +0 -7
- package/theme/core.mjs +0 -2
- package/theme/core.mjs.map +0 -7
- package/theme/createColor.cjs +0 -2
- package/theme/createColor.cjs.map +0 -7
- package/theme/createColor.d.ts +0 -41
- package/theme/createColor.mjs +0 -2
- package/theme/createColor.mjs.map +0 -7
- package/theme/createTheme.cjs +0 -2
- package/theme/createTheme.cjs.map +0 -7
- package/theme/createTheme.d.ts +0 -2
- package/theme/createTheme.mjs +0 -2
- package/theme/createTheme.mjs.map +0 -7
- package/theme/createThemeSwitcher.cjs +0 -2
- package/theme/createThemeSwitcher.cjs.map +0 -7
- package/theme/createThemeSwitcher.d.ts +0 -6
- package/theme/createThemeSwitcher.mjs +0 -2
- package/theme/createThemeSwitcher.mjs.map +0 -7
- package/theme/index.cjs +0 -2
- package/theme/index.cjs.map +0 -7
- package/theme/index.d.ts +0 -5
- package/theme/index.mjs +0 -2
- package/theme/index.mjs.map +0 -7
- package/theme/types.cjs +0 -2
- package/theme/types.cjs.map +0 -7
- package/theme/types.mjs +0 -1
- package/theme/types.mjs.map +0 -7
- package/useAnimation.cjs +0 -2
- package/useAnimation.cjs.map +0 -7
- package/useAnimation.d.ts +0 -18
- package/useAnimation.mjs +0 -2
- package/useAnimation.mjs.map +0 -7
- package/useColorTemplate.cjs +0 -2
- package/useColorTemplate.cjs.map +0 -7
- package/useColorTemplate.d.ts +0 -4
- package/useColorTemplate.mjs +0 -2
- package/useColorTemplate.mjs.map +0 -7
- package/useInterface.cjs +0 -2
- package/useInterface.cjs.map +0 -7
- package/useInterface.d.ts +0 -2
- package/useInterface.mjs +0 -2
- package/useInterface.mjs.map +0 -7
package/main.tsx
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { createRoot } from 'react-dom/client';
|
|
3
|
+
import { createThemeSwitcher, ThemeProvider, useTheme } from './src/theme'
|
|
4
|
+
import { Tag, Transition } from './src';
|
|
5
|
+
|
|
6
|
+
const useThemeSwitcher = createThemeSwitcher("light")
|
|
7
|
+
|
|
8
|
+
const ThemeBox = () => {
|
|
9
|
+
const themeSwitcher = useThemeSwitcher()
|
|
10
|
+
return (
|
|
11
|
+
<button
|
|
12
|
+
onClick={() => {
|
|
13
|
+
themeSwitcher.change(themeSwitcher.name === 'light' ? "dark" : "light")
|
|
14
|
+
}}
|
|
15
|
+
>
|
|
16
|
+
change
|
|
17
|
+
</button>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const Trans = () => {
|
|
22
|
+
const theme = useTheme()
|
|
23
|
+
const [v, setV] = React.useState<any>('zoom')
|
|
24
|
+
const [open, setOpen] = React.useState(true)
|
|
25
|
+
return (
|
|
26
|
+
<Tag>
|
|
27
|
+
<button onClick={() => setOpen(!open)}>Click</button>
|
|
28
|
+
<button onClick={() => setV(v === 'zoom' ? { from: {}, to: { transform: "scale(.5)" } } : "zoom")}>change</button>
|
|
29
|
+
<Transition open={open} variant="fade" >
|
|
30
|
+
<Tag
|
|
31
|
+
component="div"
|
|
32
|
+
width={300}
|
|
33
|
+
bgcolor="green"
|
|
34
|
+
radius={2}
|
|
35
|
+
p={2}
|
|
36
|
+
>
|
|
37
|
+
<Transition open={open} variant={v} >
|
|
38
|
+
<Tag
|
|
39
|
+
component="div"
|
|
40
|
+
width={100}
|
|
41
|
+
bgcolor="red"
|
|
42
|
+
radius={2}
|
|
43
|
+
px={2}
|
|
44
|
+
>
|
|
45
|
+
Lorem ipsum dolor sit amet consectetur adipisicing elit.
|
|
46
|
+
</Tag>
|
|
47
|
+
</Transition>
|
|
48
|
+
</Tag>
|
|
49
|
+
</Transition>
|
|
50
|
+
</Tag>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
const App = () => {
|
|
56
|
+
return (
|
|
57
|
+
<ThemeProvider theme="light">
|
|
58
|
+
<Tag
|
|
59
|
+
flexBox
|
|
60
|
+
flexRow
|
|
61
|
+
flexWrap="wrap"
|
|
62
|
+
gap={1}
|
|
63
|
+
p={2}
|
|
64
|
+
>
|
|
65
|
+
<Trans />
|
|
66
|
+
{
|
|
67
|
+
Array.from({ length: 1 }).map((_, i) => (
|
|
68
|
+
<Tag
|
|
69
|
+
key={i}
|
|
70
|
+
hover={{
|
|
71
|
+
background: 'green'
|
|
72
|
+
}}
|
|
73
|
+
id="asdasd"
|
|
74
|
+
width={100}
|
|
75
|
+
height={100}
|
|
76
|
+
background='red'
|
|
77
|
+
radius={2}
|
|
78
|
+
baseClass='hello'
|
|
79
|
+
className='world'
|
|
80
|
+
classNames={['world2']}
|
|
81
|
+
onClick={() => {
|
|
82
|
+
alert('asd')
|
|
83
|
+
}}
|
|
84
|
+
>Tagas</Tag>
|
|
85
|
+
))
|
|
86
|
+
}
|
|
87
|
+
</Tag>
|
|
88
|
+
</ThemeProvider>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
const rootEle = document.getElementById('root')
|
|
92
|
+
|
|
93
|
+
if (rootEle) {
|
|
94
|
+
|
|
95
|
+
const root = createRoot(rootEle);
|
|
96
|
+
root.render(<App />);
|
|
97
|
+
}
|
package/package.json
CHANGED
|
@@ -1,24 +1,53 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
2
|
+
"name": "@xanui/core",
|
|
3
|
+
"version": "1.1.2",
|
|
4
|
+
"description": "",
|
|
5
|
+
"private": false,
|
|
6
|
+
"main": "./cjs/index.js",
|
|
7
|
+
"module": "./index.js",
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"scripts": {
|
|
12
|
+
"start": "makepack start",
|
|
13
|
+
"build": "makepack build",
|
|
14
|
+
"release": "makepack release"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"oncss": "^1.1.14",
|
|
18
|
+
"pretty-class": "^1.0.4",
|
|
19
|
+
"react": "^19.0.0",
|
|
20
|
+
"react-dom": "^19.0.0",
|
|
21
|
+
"react-state-bucket": "^1.1.8"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/react": "^19.0.2",
|
|
25
|
+
"@types/react-dom": "^19.0.2",
|
|
26
|
+
"makepack": "^1.6.8",
|
|
27
|
+
"typescript": "^4.9.5"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [],
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./index.d.ts",
|
|
34
|
+
"default": "./cjs/index.js"
|
|
35
|
+
},
|
|
36
|
+
"import": {
|
|
37
|
+
"types": "./index.d.ts",
|
|
38
|
+
"default": "./index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"./*": {
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./*.d.ts",
|
|
44
|
+
"default": "./cjs/*.js"
|
|
45
|
+
},
|
|
46
|
+
"import": {
|
|
47
|
+
"types": "./*.d.ts",
|
|
48
|
+
"default": "./*.js"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"./cjs": null
|
|
52
|
+
}
|
|
24
53
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { CSSFactory } from 'oncss'
|
|
3
|
+
|
|
4
|
+
const ServerStyleTags = () => {
|
|
5
|
+
return Array.from(CSSFactory.values()).map((c, idx) => <style
|
|
6
|
+
key={c.classname + idx}
|
|
7
|
+
data-oncss={c.classname}
|
|
8
|
+
dangerouslySetInnerHTML={{ __html: c.css }}
|
|
9
|
+
/>)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default ServerStyleTags
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
|
|
2
|
+
const CSS_PROP_LIST: any = {
|
|
3
|
+
typography: 1,
|
|
4
|
+
bgcolor: 1,
|
|
5
|
+
bgimage: 1,
|
|
6
|
+
bg: 1,
|
|
7
|
+
p: 1,
|
|
8
|
+
pt: 1,
|
|
9
|
+
pr: 1,
|
|
10
|
+
pb: 1,
|
|
11
|
+
pl: 1,
|
|
12
|
+
px: 1,
|
|
13
|
+
py: 1,
|
|
14
|
+
m: 1,
|
|
15
|
+
mt: 1,
|
|
16
|
+
mr: 1,
|
|
17
|
+
mb: 1,
|
|
18
|
+
ml: 1,
|
|
19
|
+
mx: 1,
|
|
20
|
+
my: 1,
|
|
21
|
+
radius: 1,
|
|
22
|
+
shadow: 1,
|
|
23
|
+
flexBox: 1,
|
|
24
|
+
flexRow: 1,
|
|
25
|
+
flexColumn: 1,
|
|
26
|
+
flexWraped: 1,
|
|
27
|
+
disabled: 1,
|
|
28
|
+
spacing: 1,
|
|
29
|
+
|
|
30
|
+
gradient: 1,
|
|
31
|
+
|
|
32
|
+
// CSS Props
|
|
33
|
+
alignContent: 1,
|
|
34
|
+
alignItems: 1,
|
|
35
|
+
alignSelf: 1,
|
|
36
|
+
animation: 1,
|
|
37
|
+
animationComposition: 1,
|
|
38
|
+
animationDelay: 1,
|
|
39
|
+
animationDirection: 1,
|
|
40
|
+
animationDuration: 1,
|
|
41
|
+
animationFillMode: 1,
|
|
42
|
+
animationIterationCount: 1,
|
|
43
|
+
animationName: 1,
|
|
44
|
+
animationTimingFunction: 1,
|
|
45
|
+
backdropFilter: 1,
|
|
46
|
+
background: 1,
|
|
47
|
+
backgroundAttachment: 1,
|
|
48
|
+
backgroundColor: 1,
|
|
49
|
+
backgroundImage: 1,
|
|
50
|
+
backgroundOrigin: 1,
|
|
51
|
+
backgroundPosition: 1,
|
|
52
|
+
backgroundRepeat: 1,
|
|
53
|
+
backgroundSize: 1,
|
|
54
|
+
border: 1,
|
|
55
|
+
borderBottom: 1,
|
|
56
|
+
borderBottomColor: 1,
|
|
57
|
+
borderBottomStyle: 1,
|
|
58
|
+
borderBottomWidth: 1,
|
|
59
|
+
borderColor: 1,
|
|
60
|
+
borderImage: 1,
|
|
61
|
+
borderLeft: 1,
|
|
62
|
+
borderLeftColor: 1,
|
|
63
|
+
borderLeftStyle: 1,
|
|
64
|
+
borderLeftWidth: 1,
|
|
65
|
+
borderRadius: 1,
|
|
66
|
+
borderRight: 1,
|
|
67
|
+
borderRightColor: 1,
|
|
68
|
+
borderRightStyle: 1,
|
|
69
|
+
borderRightWidth: 1,
|
|
70
|
+
borderStyle: 1,
|
|
71
|
+
borderTop: 1,
|
|
72
|
+
borderTopColor: 1,
|
|
73
|
+
borderTopLeftRadius: 1,
|
|
74
|
+
borderTopRightRadius: 1,
|
|
75
|
+
borderTopStyle: 1,
|
|
76
|
+
borderTopWidth: 1,
|
|
77
|
+
borderWidth: 1,
|
|
78
|
+
bottom: 1,
|
|
79
|
+
boxShadow: 1,
|
|
80
|
+
boxSizing: 1,
|
|
81
|
+
cursor: 1,
|
|
82
|
+
color: 1,
|
|
83
|
+
display: 1,
|
|
84
|
+
direction: 1,
|
|
85
|
+
filter: 1,
|
|
86
|
+
flex: 1,
|
|
87
|
+
flexBasis: 1,
|
|
88
|
+
flexDirection: 1,
|
|
89
|
+
flexFlow: 1,
|
|
90
|
+
flexGrow: 1,
|
|
91
|
+
flexShrink: 1,
|
|
92
|
+
flexWrap: 1,
|
|
93
|
+
float: 1,
|
|
94
|
+
fontFamily: 1,
|
|
95
|
+
fontSize: 1,
|
|
96
|
+
fontStyle: 1,
|
|
97
|
+
fontWeight: 1,
|
|
98
|
+
font: 1,
|
|
99
|
+
gap: 1,
|
|
100
|
+
grid: 1,
|
|
101
|
+
gridArea: 1,
|
|
102
|
+
gridAutoColumns: 1,
|
|
103
|
+
gridAutoFlow: 1,
|
|
104
|
+
gridAutoRows: 1,
|
|
105
|
+
gridColumn: 1,
|
|
106
|
+
gridColumnEnd: 1,
|
|
107
|
+
gridColumnGap: 1,
|
|
108
|
+
gridColumnStart: 1,
|
|
109
|
+
gridGap: 1,
|
|
110
|
+
gridRow: 1,
|
|
111
|
+
gridRowEnd: 1,
|
|
112
|
+
gridRowGap: 1,
|
|
113
|
+
gridRowStart: 1,
|
|
114
|
+
gridTemplate: 1,
|
|
115
|
+
gridTemplateAreas: 1,
|
|
116
|
+
gridTemplateColumns: 1,
|
|
117
|
+
gridTemplateRows: 1,
|
|
118
|
+
height: 1,
|
|
119
|
+
justifyContent: 1,
|
|
120
|
+
justifyItems: 1,
|
|
121
|
+
justifySelf: 1,
|
|
122
|
+
left: 1,
|
|
123
|
+
letterSpacing: 1,
|
|
124
|
+
lineBreak: 1,
|
|
125
|
+
lineHeight: 1,
|
|
126
|
+
listStyle: 1,
|
|
127
|
+
margin: 1,
|
|
128
|
+
marginBlock: 1,
|
|
129
|
+
marginBlockEnd: 1,
|
|
130
|
+
marginBlockStart: 1,
|
|
131
|
+
marginBottom: 1,
|
|
132
|
+
marginInline: 1,
|
|
133
|
+
marginInlineEnd: 1,
|
|
134
|
+
marginInlineStart: 1,
|
|
135
|
+
marginLeft: 1,
|
|
136
|
+
marginRight: 1,
|
|
137
|
+
marginTop: 1,
|
|
138
|
+
maxHeight: 1,
|
|
139
|
+
maxWidth: 1,
|
|
140
|
+
minHeight: 1,
|
|
141
|
+
minWidth: 1,
|
|
142
|
+
objectFit: 1,
|
|
143
|
+
objectPosition: 1,
|
|
144
|
+
opacity: 1,
|
|
145
|
+
order: 1,
|
|
146
|
+
outline: 1,
|
|
147
|
+
overflow: 1,
|
|
148
|
+
overflowX: 1,
|
|
149
|
+
overflowY: 1,
|
|
150
|
+
padding: 1,
|
|
151
|
+
paddingBlock: 1,
|
|
152
|
+
paddingBlockEnd: 1,
|
|
153
|
+
paddingBlockStart: 1,
|
|
154
|
+
paddingBottom: 1,
|
|
155
|
+
paddingInline: 1,
|
|
156
|
+
paddingInlineEnd: 1,
|
|
157
|
+
paddingInlineStart: 1,
|
|
158
|
+
paddingLeft: 1,
|
|
159
|
+
paddingRight: 1,
|
|
160
|
+
paddingTop: 1,
|
|
161
|
+
perspective: 1,
|
|
162
|
+
perspectiveOrigin: 1,
|
|
163
|
+
pointerEvents: 1,
|
|
164
|
+
position: 1,
|
|
165
|
+
resize: 1,
|
|
166
|
+
right: 1,
|
|
167
|
+
textAlign: 1,
|
|
168
|
+
textDecoration: 1,
|
|
169
|
+
textShadow: 1,
|
|
170
|
+
textTransform: 1,
|
|
171
|
+
top: 1,
|
|
172
|
+
transform: 1,
|
|
173
|
+
transformOrigin: 1,
|
|
174
|
+
transformStyle: 1,
|
|
175
|
+
transition: 1,
|
|
176
|
+
transitionDelay: 1,
|
|
177
|
+
transitionDuration: 1,
|
|
178
|
+
transitionProperty: 1,
|
|
179
|
+
transitionTimingFunction: 1,
|
|
180
|
+
userSelect: 1,
|
|
181
|
+
verticalAlign: 1,
|
|
182
|
+
visibility: 1,
|
|
183
|
+
whiteSpace: 1,
|
|
184
|
+
width: 1,
|
|
185
|
+
wordBreak: 1,
|
|
186
|
+
wordSpacing: 1,
|
|
187
|
+
wordWrap: 1,
|
|
188
|
+
zIndex: 1,
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export default CSS_PROP_LIST
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { TagComponentType, TagPropsRoot } from './types';
|
|
3
|
+
import useTagProps from './useTagProps';
|
|
4
|
+
|
|
5
|
+
const Tag = React.forwardRef(<T extends TagComponentType = 'div'>({ component, children, ...rest }: TagPropsRoot<T>, ref: React.Ref<any>) => {
|
|
6
|
+
const props: any = useTagProps(rest)
|
|
7
|
+
props.ref = ref
|
|
8
|
+
return React.createElement(component || "div", props, children)
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
export default Tag
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import * as CSS from 'csstype'
|
|
2
|
-
import { Aliases, BreakpointKeys, CSSProps, CSSValueType } from "../css/types"
|
|
1
|
+
import * as CSS from 'csstype'
|
|
2
|
+
import { Aliases, BreakpointKeys, CSSProps, CSSValueType } from "../css/types"
|
|
3
3
|
import { ColorsRefTypes, TypographyRefTypes } from '../theme/types';
|
|
4
|
-
import { classNamesTypes } from 'pretty-class'
|
|
5
|
-
|
|
4
|
+
import { classNamesTypes } from 'pretty-class'
|
|
5
|
+
|
|
6
|
+
export type TagComponentType = keyof React.JSX.IntrinsicElements | React.ComponentType<any>
|
|
6
7
|
export type TagProps<T extends TagComponentType = 'div'> = Omit<React.HTMLProps<T>, 'width' | 'height'> & {
|
|
7
8
|
component?: T;
|
|
8
9
|
children?: React.ReactNode;
|
|
9
10
|
ref?: any;
|
|
10
|
-
} & CSSPropAsAttr
|
|
11
|
+
} & CSSPropAsAttr
|
|
12
|
+
|
|
11
13
|
export type TagPropsRoot<T extends TagComponentType = 'div'> = TagProps<T> & {
|
|
12
|
-
sxr?: CSSProps
|
|
13
|
-
}
|
|
14
|
+
sxr?: CSSProps
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
14
18
|
interface TagCSSProperties {
|
|
15
19
|
alignContent: CSSValueType<"alignContent">;
|
|
16
20
|
alignItems: CSSValueType<"alignItems">;
|
|
@@ -169,11 +173,11 @@ interface TagCSSProperties {
|
|
|
169
173
|
wordWrap: CSSValueType<"wordWrap">;
|
|
170
174
|
zIndex: CSSValueType<"zIndex">;
|
|
171
175
|
}
|
|
176
|
+
|
|
172
177
|
export type CSSPropAsAttr = Partial<TagCSSProperties> & Aliases & {
|
|
173
178
|
baseClass?: string;
|
|
174
179
|
sx?: CSSProps;
|
|
175
180
|
hover?: CSSProps;
|
|
176
181
|
disabled?: boolean;
|
|
177
182
|
classNames?: classNamesTypes;
|
|
178
|
-
}
|
|
179
|
-
export {};
|
|
183
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TagComponentType, TagProps, TagPropsRoot } from './types';
|
|
2
|
+
import cssPropList from './cssPropList';
|
|
3
|
+
import { css } from '../css';
|
|
4
|
+
import { classNames } from 'pretty-class';
|
|
5
|
+
|
|
6
|
+
const useTagProps = <T extends TagComponentType = "div">({ sxr, sx, baseClass, classNames: clses, hover, ...props }: TagPropsRoot<T>): TagProps<T> => {
|
|
7
|
+
let _css: any = { ...sxr, ...sx, ...props }
|
|
8
|
+
if (hover) _css['&:hover'] = hover
|
|
9
|
+
const style = css(_css, {
|
|
10
|
+
skipProps: (prop, _val, dept): any => dept === 1 && !cssPropList[prop]
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
let skipProps = style.skiped[style.classname as any] || []
|
|
14
|
+
const _props: any = {};
|
|
15
|
+
for (let prop of skipProps) {
|
|
16
|
+
_props[prop] = (props as any)[prop]
|
|
17
|
+
}
|
|
18
|
+
_props.className = classNames([
|
|
19
|
+
baseClass ? "xui-" + baseClass : "",
|
|
20
|
+
style.classname,
|
|
21
|
+
props.className,
|
|
22
|
+
...(clses as any || []),
|
|
23
|
+
])
|
|
24
|
+
return _props
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
export default useTagProps
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import React, { ReactElement, cloneElement, Children, useState, useEffect, useId } from 'react';
|
|
3
|
+
import Tag from '../Tag';
|
|
4
|
+
import { animationEases } from '../useAnimation';
|
|
5
|
+
import { css } from '../css';
|
|
6
|
+
import { formatCSSProp } from 'oncss';
|
|
7
|
+
import { CSSProps } from '../css/types';
|
|
8
|
+
import * as variants from './variants'
|
|
9
|
+
export type TransitionVariantTypes = keyof typeof variants
|
|
10
|
+
|
|
11
|
+
export type TransitionElementProps = {
|
|
12
|
+
height: number;
|
|
13
|
+
width: number;
|
|
14
|
+
rect: DOMRect | null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type TransitionState = "open" | "opened" | "close" | "closed"
|
|
18
|
+
|
|
19
|
+
export type TransitionProps = {
|
|
20
|
+
children: ReactElement;
|
|
21
|
+
open: boolean;
|
|
22
|
+
variant: {
|
|
23
|
+
from: CSSProps;
|
|
24
|
+
to: CSSProps;
|
|
25
|
+
} | TransitionVariantTypes;
|
|
26
|
+
ease?: string;
|
|
27
|
+
easing?: keyof typeof animationEases;
|
|
28
|
+
duration?: number;
|
|
29
|
+
delay?: number;
|
|
30
|
+
disableInitialTransition?: boolean;
|
|
31
|
+
onOpen?: () => void;
|
|
32
|
+
onOpened?: () => void;
|
|
33
|
+
onClose?: () => void;
|
|
34
|
+
onClosed?: () => void;
|
|
35
|
+
onState?: (state: TransitionState) => void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const Transition = ({ children, open, ...props }: TransitionProps) => {
|
|
39
|
+
let { disableInitialTransition, variant, duration, delay, ease, easing, onOpen, onOpened, onClose, onClosed, onState } = props as TransitionProps
|
|
40
|
+
let _ease = ease || (animationEases as any)[easing as any] || animationEases.easeBounceOut
|
|
41
|
+
disableInitialTransition ??= false
|
|
42
|
+
duration ??= 400
|
|
43
|
+
variant ??= "fade"
|
|
44
|
+
|
|
45
|
+
const id = useId().replace(/:/g, "")
|
|
46
|
+
const [rendered, setRendered] = useState(false)
|
|
47
|
+
const [initial, setInitial] = useState(false)
|
|
48
|
+
const [transitionState, setTransitionState] = useState<TransitionState>(open ? (disableInitialTransition ? "opened" : "open") : "closed")
|
|
49
|
+
const [element, setElement] = useState<TransitionElementProps>({
|
|
50
|
+
height: 0,
|
|
51
|
+
width: 0,
|
|
52
|
+
rect: null
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
if (typeof variant === 'string') {
|
|
56
|
+
variant = (variants as any)[variant](element)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let from = (variant as any).from
|
|
60
|
+
let to = (variant as any).to
|
|
61
|
+
|
|
62
|
+
const [_css, setCss] = useState(open ? to : from)
|
|
63
|
+
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
const ele: HTMLElement = document.querySelector(`.trans-${id}`) as any
|
|
66
|
+
if (ele) {
|
|
67
|
+
setRendered(true)
|
|
68
|
+
setElement({
|
|
69
|
+
height: ele.clientHeight,
|
|
70
|
+
width: ele.clientWidth,
|
|
71
|
+
rect: ele.getBoundingClientRect()
|
|
72
|
+
})
|
|
73
|
+
if (!disableInitialTransition && open) {
|
|
74
|
+
setCss(from)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}, [])
|
|
78
|
+
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
const ele: HTMLElement = document.querySelector(`.trans-${id}`) as any
|
|
81
|
+
if (rendered && ele) {
|
|
82
|
+
let stimer: any = null
|
|
83
|
+
let etimer: any = null
|
|
84
|
+
ele.ontransitionstart = () => {
|
|
85
|
+
clearTimeout(stimer)
|
|
86
|
+
stimer = setTimeout(() => {
|
|
87
|
+
const isOpen = Array.from(ele.classList).includes("trans-open");
|
|
88
|
+
(onOpen && isOpen) && onOpen();
|
|
89
|
+
(onClose && !isOpen) && onClose()
|
|
90
|
+
onState && onState(isOpen ? "open" : "close")
|
|
91
|
+
setTransitionState(isOpen ? "open" : "close")
|
|
92
|
+
}, 1)
|
|
93
|
+
}
|
|
94
|
+
ele.ontransitionend = () => {
|
|
95
|
+
clearTimeout(etimer)
|
|
96
|
+
etimer = setTimeout(() => {
|
|
97
|
+
const isOpen = Array.from(ele.classList).includes("trans-open");
|
|
98
|
+
(onOpened && isOpen) && onOpened();
|
|
99
|
+
(onClosed && !isOpen) && onClosed();
|
|
100
|
+
onState && onState(isOpen ? "opened" : "closed")
|
|
101
|
+
setTransitionState(isOpen ? "opened" : "closed")
|
|
102
|
+
}, 1)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}, [rendered])
|
|
106
|
+
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
if (rendered) {
|
|
109
|
+
if (!initial) {
|
|
110
|
+
setInitial(true)
|
|
111
|
+
setTimeout(() => {
|
|
112
|
+
setCss(open ? to : from)
|
|
113
|
+
}, 50);
|
|
114
|
+
} else {
|
|
115
|
+
setCss(open ? to : from)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}, [rendered, open, JSON.stringify(from), JSON.stringify(to)])
|
|
119
|
+
|
|
120
|
+
let _: any = {}
|
|
121
|
+
if (rendered) {
|
|
122
|
+
let trans = ` ${duration}ms ${_ease} ${delay || 0}ms`
|
|
123
|
+
_ = {
|
|
124
|
+
..._css,
|
|
125
|
+
transition: Object.keys(_css || {}).map(k => formatCSSProp(k)).join(trans + ", ") + trans,
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const cls = css(_)
|
|
130
|
+
if (!children || Array.isArray(children)) throw new Error("Invalid children in Transition")
|
|
131
|
+
const first: any = Children.toArray(children).shift();
|
|
132
|
+
let classname = `${cls.classname} trans-${id} trans-${(open ? "open" : "close")} trans-state-${transitionState}`
|
|
133
|
+
const child = cloneElement(first, { classNames: [classname] })
|
|
134
|
+
if (rendered) return child
|
|
135
|
+
if (!rendered && disableInitialTransition && open) return child
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<Tag
|
|
139
|
+
height={0}
|
|
140
|
+
overflow="hidden"
|
|
141
|
+
>
|
|
142
|
+
{child}
|
|
143
|
+
</Tag>
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
export default Transition
|