@xanui/core 1.1.2 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/ServerStyleTags.js +3 -0
  2. package/ServerStyleTags.js.map +1 -0
  3. package/ServerStyleTags.mjs +3 -0
  4. package/ServerStyleTags.mjs.map +1 -0
  5. package/Tag/cssPropList.js +186 -0
  6. package/Tag/cssPropList.js.map +1 -0
  7. package/{src/Tag/cssPropList.ts → Tag/cssPropList.mjs} +2 -7
  8. package/Tag/cssPropList.mjs.map +1 -0
  9. package/Tag/index.js +6 -0
  10. package/Tag/index.js.map +1 -0
  11. package/Tag/index.mjs +6 -0
  12. package/Tag/index.mjs.map +1 -0
  13. package/Tag/useTagProps.js +21 -0
  14. package/Tag/useTagProps.js.map +1 -0
  15. package/Tag/useTagProps.mjs +21 -0
  16. package/Tag/useTagProps.mjs.map +1 -0
  17. package/Transition/index.js +93 -0
  18. package/Transition/index.js.map +1 -0
  19. package/Transition/index.mjs +93 -0
  20. package/Transition/index.mjs.map +1 -0
  21. package/Transition/variants.js +158 -0
  22. package/Transition/variants.js.map +1 -0
  23. package/{src/Transition/variants.ts → Transition/variants.mjs} +44 -64
  24. package/Transition/variants.mjs.map +1 -0
  25. package/breakpoint/BreakpointProvider.js +43 -0
  26. package/breakpoint/BreakpointProvider.js.map +1 -0
  27. package/breakpoint/BreakpointProvider.mjs +43 -0
  28. package/breakpoint/BreakpointProvider.mjs.map +1 -0
  29. package/breakpoint/useBreakpoint.js +23 -0
  30. package/breakpoint/useBreakpoint.js.map +1 -0
  31. package/breakpoint/useBreakpoint.mjs +23 -0
  32. package/breakpoint/useBreakpoint.mjs.map +1 -0
  33. package/breakpoint/useBreakpointProps.js +42 -0
  34. package/breakpoint/useBreakpointProps.js.map +1 -0
  35. package/breakpoint/useBreakpointProps.mjs +42 -0
  36. package/breakpoint/useBreakpointProps.mjs.map +1 -0
  37. package/css/aliases.js +29 -0
  38. package/css/aliases.js.map +1 -0
  39. package/css/aliases.mjs +29 -0
  40. package/css/aliases.mjs.map +1 -0
  41. package/{src/css/getProps.ts → css/getProps.js} +15 -21
  42. package/css/getProps.js.map +1 -0
  43. package/css/getProps.mjs +32 -0
  44. package/css/getProps.mjs.map +1 -0
  45. package/{src/css/getValue.ts → css/getValue.js} +40 -65
  46. package/css/getValue.js.map +1 -0
  47. package/css/getValue.mjs +92 -0
  48. package/css/getValue.mjs.map +1 -0
  49. package/css/index.js +55 -0
  50. package/css/index.js.map +1 -0
  51. package/css/index.mjs +55 -0
  52. package/css/index.mjs.map +1 -0
  53. package/index.d.ts +629 -0
  54. package/index.js +1 -0
  55. package/index.js.map +1 -0
  56. package/index.mjs +1 -0
  57. package/index.mjs.map +1 -0
  58. package/isWindow.js +1 -0
  59. package/isWindow.js.map +1 -0
  60. package/isWindow.mjs +1 -0
  61. package/isWindow.mjs.map +1 -0
  62. package/package.json +50 -51
  63. package/theme/ThemeCssVars.js +5 -0
  64. package/theme/ThemeCssVars.js.map +1 -0
  65. package/theme/ThemeCssVars.mjs +5 -0
  66. package/theme/ThemeCssVars.mjs.map +1 -0
  67. package/theme/ThemeDefaultOptions.js +131 -0
  68. package/theme/ThemeDefaultOptions.js.map +1 -0
  69. package/{src/theme/ThemeDefaultOptions.ts → theme/ThemeDefaultOptions.mjs} +17 -32
  70. package/theme/ThemeDefaultOptions.mjs.map +1 -0
  71. package/theme/ThemeProvider.js +88 -0
  72. package/theme/ThemeProvider.js.map +1 -0
  73. package/theme/ThemeProvider.mjs +88 -0
  74. package/theme/ThemeProvider.mjs.map +1 -0
  75. package/theme/core.js +18 -0
  76. package/theme/core.js.map +1 -0
  77. package/theme/core.mjs +18 -0
  78. package/theme/core.mjs.map +1 -0
  79. package/theme/createColor.js +46 -0
  80. package/theme/createColor.js.map +1 -0
  81. package/theme/createColor.mjs +46 -0
  82. package/theme/createColor.mjs.map +1 -0
  83. package/theme/createTheme.js +21 -0
  84. package/theme/createTheme.js.map +1 -0
  85. package/theme/createTheme.mjs +21 -0
  86. package/theme/createTheme.mjs.map +1 -0
  87. package/theme/createThemeSwitcher.js +12 -0
  88. package/theme/createThemeSwitcher.js.map +1 -0
  89. package/theme/createThemeSwitcher.mjs +12 -0
  90. package/theme/createThemeSwitcher.mjs.map +1 -0
  91. package/theme/index.js +2 -0
  92. package/theme/index.js.map +1 -0
  93. package/theme/index.mjs +2 -0
  94. package/theme/index.mjs.map +1 -0
  95. package/useAnimation.js +25 -0
  96. package/useAnimation.js.map +1 -0
  97. package/{src/useAnimation.ts → useAnimation.mjs} +10 -25
  98. package/useAnimation.mjs.map +1 -0
  99. package/useColorTemplate.js +6 -0
  100. package/useColorTemplate.js.map +1 -0
  101. package/useColorTemplate.mjs +6 -0
  102. package/useColorTemplate.mjs.map +1 -0
  103. package/useInterface.js +8 -0
  104. package/useInterface.js.map +1 -0
  105. package/useInterface.mjs +8 -0
  106. package/useInterface.mjs.map +1 -0
  107. package/main.tsx +0 -97
  108. package/src/ServerStyleTags.tsx +0 -12
  109. package/src/Tag/index.tsx +0 -11
  110. package/src/Tag/types.ts +0 -183
  111. package/src/Tag/useTagProps.ts +0 -28
  112. package/src/Transition/index.tsx +0 -148
  113. package/src/breakpoint/index.tsx +0 -52
  114. package/src/breakpoint/useBreakpoint.ts +0 -31
  115. package/src/breakpoint/useBreakpointProps.ts +0 -57
  116. package/src/css/aliases.ts +0 -35
  117. package/src/css/index.ts +0 -78
  118. package/src/css/types.ts +0 -60
  119. package/src/index.ts +0 -34
  120. package/src/isWindow.ts +0 -3
  121. package/src/theme/ThemeCssVars.ts +0 -107
  122. package/src/theme/ThemeProvider.tsx +0 -140
  123. package/src/theme/core.ts +0 -21
  124. package/src/theme/createColor.ts +0 -53
  125. package/src/theme/createTheme.ts +0 -33
  126. package/src/theme/createThemeSwitcher.ts +0 -18
  127. package/src/theme/index.tsx +0 -17
  128. package/src/theme/types.ts +0 -181
  129. package/src/useColorTemplate.ts +0 -11
  130. package/src/useInterface.ts +0 -13
  131. package/tsconfig.json +0 -28
package/main.tsx DELETED
@@ -1,97 +0,0 @@
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
- }
@@ -1,12 +0,0 @@
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
package/src/Tag/index.tsx DELETED
@@ -1,11 +0,0 @@
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
package/src/Tag/types.ts DELETED
@@ -1,183 +0,0 @@
1
- import * as CSS from 'csstype'
2
- import { Aliases, BreakpointKeys, CSSProps, CSSValueType } from "../css/types"
3
- import { ColorsRefTypes, TypographyRefTypes } from '../theme/types';
4
- import { classNamesTypes } from 'pretty-class'
5
-
6
- export type TagComponentType = keyof React.JSX.IntrinsicElements | React.ComponentType<any>
7
- export type TagProps<T extends TagComponentType = 'div'> = Omit<React.HTMLProps<T>, 'width' | 'height'> & {
8
- component?: T;
9
- children?: React.ReactNode;
10
- ref?: any;
11
- } & CSSPropAsAttr
12
-
13
- export type TagPropsRoot<T extends TagComponentType = 'div'> = TagProps<T> & {
14
- sxr?: CSSProps
15
- }
16
-
17
-
18
- interface TagCSSProperties {
19
- alignContent: CSSValueType<"alignContent">;
20
- alignItems: CSSValueType<"alignItems">;
21
- alignSelf: CSSValueType<"alignSelf">;
22
- animation: CSSValueType<"animation">;
23
- animationComposition: CSSValueType<"animationComposition">;
24
- animationDelay: CSSValueType<"animationDelay">;
25
- animationDirection: CSSValueType<"animationDirection">;
26
- animationDuration: CSSValueType<"animationDuration">;
27
- animationFillMode: CSSValueType<"animationFillMode">;
28
- animationIterationCount: CSSValueType<"animationIterationCount">;
29
- animationName: CSSValueType<"animationName">;
30
- animationTimingFunction: CSSValueType<"animationTimingFunction">;
31
- backdropFilter: CSSValueType<"backdropFilter">;
32
- background: CSSValueType<"background"> | ColorsRefTypes;
33
- backgroundAttachment: CSSValueType<"backgroundAttachment">;
34
- backgroundColor: CSSValueType<"backgroundColor"> | ColorsRefTypes;
35
- backgroundImage: CSSValueType<"backgroundImage">;
36
- backgroundOrigin: CSSValueType<"backgroundOrigin">;
37
- backgroundPosition: CSSValueType<"backgroundPosition">;
38
- backgroundRepeat: CSSValueType<"backgroundRepeat">;
39
- backgroundSize: CSSValueType<"backgroundSize">;
40
- border: CSSValueType<"border">;
41
- borderBottom: CSSValueType<"borderBottom">;
42
- borderBottomColor: CSSValueType<"borderBottomColor"> | ColorsRefTypes;
43
- borderBottomStyle: CSSValueType<"borderBottomStyle">;
44
- borderBottomWidth: CSSValueType<"borderBottomWidth">;
45
- borderColor: CSS.Properties['borderColor'] | ColorsRefTypes;
46
- borderImage: CSSValueType<"borderImage">;
47
- borderLeft: CSSValueType<"borderLeft">;
48
- borderLeftColor: CSSValueType<"borderLeftColor"> | ColorsRefTypes;
49
- borderLeftStyle: CSSValueType<"borderLeftStyle">;
50
- borderLeftWidth: CSSValueType<"borderLeftWidth">;
51
- borderRadius: CSSValueType<"borderRadius">;
52
- borderRight: CSSValueType<"borderRight">;
53
- borderRightColor: CSSValueType<"borderRightColor"> | ColorsRefTypes;
54
- borderRightStyle: CSSValueType<"borderRightStyle">;
55
- borderRightWidth: CSSValueType<"borderRightWidth">;
56
- borderStyle: CSSValueType<"borderStyle">;
57
- borderTop: CSSValueType<"borderTop">;
58
- borderTopColor: CSSValueType<"borderTopColor"> | ColorsRefTypes;
59
- borderTopLeftRadius: CSSValueType<"borderTopLeftRadius">;
60
- borderTopRightRadius: CSSValueType<"borderTopRightRadius">;
61
- borderTopStyle: CSSValueType<"borderTopStyle">;
62
- borderTopWidth: CSSValueType<"borderTopWidth">;
63
- borderWidth: CSSValueType<"borderWidth">;
64
- bottom: CSSValueType<"bottom">;
65
- boxShadow: CSSValueType<"boxShadow"> | number;
66
- boxSizing: CSSValueType<"boxSizing">;
67
- cursor: CSSValueType<"cursor">;
68
- color: CSS.Properties['color'] | ColorsRefTypes;
69
- display: CSSValueType<"display">;
70
- direction: "row" | "column" | CSSValueType<"direction">;
71
- filter: CSSValueType<"filter">;
72
- flex: CSSValueType<"flex">;
73
- flexBasis: CSSValueType<"flexBasis">;
74
- flexDirection: CSSValueType<"flexDirection">;
75
- flexFlow: CSSValueType<"flexFlow">;
76
- flexGrow: CSSValueType<"flexGrow">;
77
- flexShrink: CSSValueType<"flexShrink">;
78
- flexWrap: CSSValueType<"flexWrap">;
79
- float: CSSValueType<"float">;
80
- fontFamily: CSSValueType<"fontFamily"> | "default";
81
- fontSize: CSSValueType<"fontSize"> | TypographyRefTypes;
82
- fontStyle: CSSValueType<"fontStyle">;
83
- fontWeight: CSSValueType<"fontWeight"> | TypographyRefTypes;
84
- font: CSSValueType<"font"> | TypographyRefTypes;
85
- gap: CSSValueType<"gap">;
86
- grid: CSSValueType<"grid">;
87
- gridArea: CSSValueType<"gridArea">;
88
- gridAutoColumns: CSSValueType<"gridAutoColumns">;
89
- gridAutoFlow: CSSValueType<"gridAutoFlow">;
90
- gridAutoRows: CSSValueType<"gridAutoRows">;
91
- gridColumn: CSSValueType<"gridColumn">;
92
- gridColumnEnd: CSSValueType<"gridColumnEnd">;
93
- gridColumnGap: CSSValueType<"gridColumnGap">;
94
- gridColumnStart: CSSValueType<"gridColumnStart">;
95
- gridGap: CSSValueType<"gridGap">;
96
- gridRow: CSSValueType<"gridRow">;
97
- gridRowEnd: CSSValueType<"gridRowEnd">;
98
- gridRowGap: CSSValueType<"gridRowGap">;
99
- gridRowStart: CSSValueType<"gridRowStart">;
100
- gridTemplate: CSSValueType<"gridTemplate">;
101
- gridTemplateAreas: CSSValueType<"gridTemplateAreas">;
102
- gridTemplateColumns: CSSValueType<"gridTemplateColumns">;
103
- gridTemplateRows: CSSValueType<"gridTemplateRows">;
104
- height: CSSValueType<"height">;
105
- justifyContent: CSSValueType<"justifyContent">;
106
- justifyItems: CSSValueType<"justifyItems">;
107
- justifySelf: CSSValueType<"justifySelf">;
108
- left: CSSValueType<"left">;
109
- letterSpacing: CSSValueType<"letterSpacing">;
110
- lineBreak: CSSValueType<"lineBreak">;
111
- lineHeight: CSSValueType<"lineHeight"> | TypographyRefTypes;
112
- listStyle: CSSValueType<"listStyle">;
113
- margin: CSSValueType<"margin">;
114
- marginBlock: CSSValueType<"marginBlock">;
115
- marginBlockEnd: CSSValueType<"marginBlockEnd">;
116
- marginBlockStart: CSSValueType<"marginBlockStart">;
117
- marginBottom: CSSValueType<"marginBottom">;
118
- marginInline: CSSValueType<"marginInline">;
119
- marginInlineEnd: CSSValueType<"marginInlineEnd">;
120
- marginInlineStart: CSSValueType<"marginInlineStart">;
121
- marginLeft: CSSValueType<"marginLeft">;
122
- marginRight: CSSValueType<"marginRight">;
123
- marginTop: CSSValueType<"marginTop">;
124
- maxHeight: CSSValueType<"maxHeight">;
125
- maxWidth: CSSValueType<"maxWidth"> | BreakpointKeys;
126
- minHeight: CSSValueType<"minHeight">;
127
- minWidth: CSSValueType<"minWidth"> | BreakpointKeys;
128
- objectFit: CSSValueType<"objectFit">;
129
- objectPosition: CSSValueType<"objectPosition">;
130
- opacity: CSSValueType<"opacity">;
131
- order: CSSValueType<"order">;
132
- outline: CSSValueType<"outline">;
133
- overflow: CSSValueType<"overflow">;
134
- overflowX: CSSValueType<"overflowX">;
135
- overflowY: CSSValueType<"overflowY">;
136
- padding: CSSValueType<"padding">;
137
- paddingBlock: CSSValueType<"paddingBlock">;
138
- paddingBlockEnd: CSSValueType<"paddingBlockEnd">;
139
- paddingBlockStart: CSSValueType<"paddingBlockStart">;
140
- paddingBottom: CSSValueType<"paddingBottom">;
141
- paddingInline: CSSValueType<"paddingInline">;
142
- paddingInlineEnd: CSSValueType<"paddingInlineEnd">;
143
- paddingInlineStart: CSSValueType<"paddingInlineStart">;
144
- paddingLeft: CSSValueType<"paddingLeft">;
145
- paddingRight: CSSValueType<"paddingRight">;
146
- paddingTop: CSSValueType<"paddingTop">;
147
- perspective: CSSValueType<"perspective">;
148
- perspectiveOrigin: CSSValueType<"perspectiveOrigin">;
149
- pointerEvents: CSSValueType<"pointerEvents">;
150
- position: CSSValueType<"position">;
151
- right: CSSValueType<"right">;
152
- textAlign: CSSValueType<"textAlign">;
153
- textDecoration: CSSValueType<"textDecoration">;
154
- textShadow: CSSValueType<"textShadow">;
155
- textTransform: CSSValueType<"textTransform">;
156
- top: CSSValueType<"top">;
157
- transform: CSSValueType<"transform">;
158
- transformOrigin: CSSValueType<"transformOrigin">;
159
- transformStyle: CSSValueType<"transformStyle">;
160
- transition: CSSValueType<"transition">;
161
- transitionDelay: CSSValueType<"transitionDelay">;
162
- transitionDuration: CSSValueType<"transitionDuration">;
163
- transitionProperty: CSSValueType<"transitionProperty">;
164
- transitionTimingFunction: CSSValueType<"transitionTimingFunction">;
165
- translate: CSSValueType<"translate">;
166
- userSelect: CSSValueType<"userSelect">;
167
- verticalAlign: CSSValueType<"verticalAlign">;
168
- visibility: CSSValueType<"visibility">;
169
- whiteSpace: CSSValueType<"whiteSpace">;
170
- width: CSSValueType<"width"> | BreakpointKeys;
171
- wordBreak: CSSValueType<"wordBreak">;
172
- wordSpacing: CSSValueType<"wordSpacing">;
173
- wordWrap: CSSValueType<"wordWrap">;
174
- zIndex: CSSValueType<"zIndex">;
175
- }
176
-
177
- export type CSSPropAsAttr = Partial<TagCSSProperties> & Aliases & {
178
- baseClass?: string;
179
- sx?: CSSProps;
180
- hover?: CSSProps;
181
- disabled?: boolean;
182
- classNames?: classNamesTypes;
183
- }
@@ -1,28 +0,0 @@
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
@@ -1,148 +0,0 @@
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
@@ -1,52 +0,0 @@
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
- }
@@ -1,31 +0,0 @@
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
@@ -1,57 +0,0 @@
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
@@ -1,35 +0,0 @@
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