@codeleap/web 2.4.7 → 3.1.1
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/package.json +20 -19
- package/src/components/ActionIcon/index.tsx +59 -0
- package/src/components/ActionIcon/styles.ts +9 -0
- package/src/components/ActivityIndicator/index.tsx +78 -0
- package/src/components/ActivityIndicator/styles.ts +11 -0
- package/src/components/Button/index.tsx +125 -0
- package/src/components/Button/styles.ts +22 -0
- package/src/components/Checkbox/index.tsx +138 -0
- package/src/components/Checkbox/styles.ts +20 -0
- package/src/components/Collapse/index.tsx +87 -0
- package/src/components/Collapse/styles.ts +8 -0
- package/src/components/Drawer/index.tsx +148 -0
- package/src/components/Drawer/styles.ts +8 -0
- package/src/components/FileInput.tsx +51 -0
- package/src/components/Icon/index.tsx +53 -0
- package/src/components/Icon/styles.ts +9 -0
- package/src/components/InputBase/index.tsx +104 -0
- package/src/components/InputBase/styles.ts +167 -0
- package/src/components/InputBase/types.ts +28 -0
- package/src/components/InputBase/utils.ts +41 -0
- package/src/components/Link/index.tsx +69 -0
- package/src/components/Link/styles.ts +11 -0
- package/src/components/List/index.tsx +103 -0
- package/src/components/List/styles.ts +8 -0
- package/src/components/LoadingOverlay/index.tsx +34 -0
- package/src/components/LoadingOverlay/styles.ts +12 -0
- package/src/components/Modal/index.tsx +189 -0
- package/src/components/Modal/styles.ts +26 -0
- package/src/components/NumberIncrement/index.tsx +292 -0
- package/src/components/NumberIncrement/styles.ts +15 -0
- package/src/components/Overlay/index.tsx +42 -0
- package/src/components/Overlay/styles.ts +8 -0
- package/src/components/RadioInput/index.tsx +155 -0
- package/src/components/RadioInput/styles.ts +14 -0
- package/src/components/Scroll/index.tsx +29 -0
- package/src/components/Scroll/styles.ts +8 -0
- package/src/components/Select/index.tsx +438 -0
- package/src/components/Select/styles.ts +179 -0
- package/src/components/Select/types.ts +100 -0
- package/src/components/Slider/index.tsx +303 -0
- package/src/components/Slider/styles.ts +11 -0
- package/src/components/Switch/index.tsx +128 -0
- package/src/components/Switch/styles.ts +20 -0
- package/src/components/Text/index.tsx +62 -0
- package/src/components/Text/styles.ts +9 -0
- package/src/components/TextInput/index.tsx +253 -0
- package/src/components/TextInput/mask.tsx +165 -0
- package/src/components/TextInput/styles.ts +15 -0
- package/src/components/Tooltip/index.tsx +155 -0
- package/src/components/Tooltip/styles.ts +9 -0
- package/src/components/Touchable/index.tsx +72 -0
- package/src/components/Touchable/styles.ts +11 -0
- package/src/components/View/index.tsx +94 -0
- package/src/components/View/styles.ts +8 -0
- package/src/components/components.ts +29 -0
- package/src/components/defaultStyles.ts +51 -0
- package/src/index.ts +6 -0
- package/src/lib/OSAlert.tsx +190 -0
- package/src/lib/Toast.ts +23 -0
- package/src/lib/hooks.ts +340 -0
- package/src/lib/index.ts +2 -0
- package/src/lib/logger.ts +13 -0
- package/src/lib/utils/cookies.ts +13 -0
- package/src/lib/utils/index.ts +4 -0
- package/src/lib/utils/pollyfils/scroll.ts +65 -0
- package/src/lib/utils/stopPropagation.ts +15 -0
- package/src/types/index.ts +1 -0
- package/src/types/utility.ts +3 -0
- package/dist/components/ActivityIndicator/index.d.ts +0 -12
- package/dist/components/ActivityIndicator/index.js +0 -57
- package/dist/components/ActivityIndicator/index.js.map +0 -1
- package/dist/components/ActivityIndicator/styles.d.ts +0 -53
- package/dist/components/ActivityIndicator/styles.js +0 -22
- package/dist/components/ActivityIndicator/styles.js.map +0 -1
- package/dist/components/Button.d.ts +0 -18
- package/dist/components/Button.js +0 -67
- package/dist/components/Button.js.map +0 -1
- package/dist/components/CenterWrapper.d.ts +0 -7
- package/dist/components/CenterWrapper.js +0 -28
- package/dist/components/CenterWrapper.js.map +0 -1
- package/dist/components/Checkbox/index.d.ts +0 -12
- package/dist/components/Checkbox/index.js +0 -58
- package/dist/components/Checkbox/index.js.map +0 -1
- package/dist/components/Checkbox/styles.d.ts +0 -53
- package/dist/components/Checkbox/styles.js +0 -64
- package/dist/components/Checkbox/styles.js.map +0 -1
- package/dist/components/Collapse.d.ts +0 -20
- package/dist/components/Collapse.js +0 -68
- package/dist/components/Collapse.js.map +0 -1
- package/dist/components/ContentView.d.ts +0 -10
- package/dist/components/ContentView.js +0 -52
- package/dist/components/ContentView.js.map +0 -1
- package/dist/components/Drawer.d.ts +0 -23
- package/dist/components/Drawer.js +0 -73
- package/dist/components/Drawer.js.map +0 -1
- package/dist/components/FileInput.d.ts +0 -8
- package/dist/components/FileInput.js +0 -69
- package/dist/components/FileInput.js.map +0 -1
- package/dist/components/HorizontalScroll.d.ts +0 -3
- package/dist/components/HorizontalScroll.js +0 -42
- package/dist/components/HorizontalScroll.js.map +0 -1
- package/dist/components/Icon.d.ts +0 -8
- package/dist/components/Icon.js +0 -55
- package/dist/components/Icon.js.map +0 -1
- package/dist/components/Link.d.ts +0 -7
- package/dist/components/Link.js +0 -63
- package/dist/components/Link.js.map +0 -1
- package/dist/components/List.d.ts +0 -18
- package/dist/components/List.js +0 -52
- package/dist/components/List.js.map +0 -1
- package/dist/components/Modal/index.d.ts +0 -21
- package/dist/components/Modal/index.js +0 -116
- package/dist/components/Modal/index.js.map +0 -1
- package/dist/components/Modal/styles.d.ts +0 -56
- package/dist/components/Modal/styles.js +0 -36
- package/dist/components/Modal/styles.js.map +0 -1
- package/dist/components/Overlay.d.ts +0 -10
- package/dist/components/Overlay.js +0 -41
- package/dist/components/Overlay.js.map +0 -1
- package/dist/components/RadioInput/index.d.ts +0 -21
- package/dist/components/RadioInput/index.js +0 -55
- package/dist/components/RadioInput/index.js.map +0 -1
- package/dist/components/RadioInput/styles.d.ts +0 -54
- package/dist/components/RadioInput/styles.js +0 -44
- package/dist/components/RadioInput/styles.js.map +0 -1
- package/dist/components/RouterPage/Menu.d.ts +0 -10
- package/dist/components/RouterPage/Menu.js +0 -36
- package/dist/components/RouterPage/Menu.js.map +0 -1
- package/dist/components/RouterPage/MenuItem.d.ts +0 -12
- package/dist/components/RouterPage/MenuItem.js +0 -42
- package/dist/components/RouterPage/MenuItem.js.map +0 -1
- package/dist/components/RouterPage/Router.d.ts +0 -8
- package/dist/components/RouterPage/Router.js +0 -27
- package/dist/components/RouterPage/Router.js.map +0 -1
- package/dist/components/RouterPage/index.d.ts +0 -29
- package/dist/components/RouterPage/index.js +0 -85
- package/dist/components/RouterPage/index.js.map +0 -1
- package/dist/components/RouterPage/styles.d.ts +0 -54
- package/dist/components/RouterPage/styles.js +0 -87
- package/dist/components/RouterPage/styles.js.map +0 -1
- package/dist/components/Scroll.d.ts +0 -5
- package/dist/components/Scroll.js +0 -24
- package/dist/components/Scroll.js.map +0 -1
- package/dist/components/Select/Custom.d.ts +0 -8
- package/dist/components/Select/Custom.js +0 -104
- package/dist/components/Select/Custom.js.map +0 -1
- package/dist/components/Select/Multi.d.ts +0 -3
- package/dist/components/Select/Multi.js +0 -105
- package/dist/components/Select/Multi.js.map +0 -1
- package/dist/components/Select/Native.d.ts +0 -17
- package/dist/components/Select/Native.js +0 -44
- package/dist/components/Select/Native.js.map +0 -1
- package/dist/components/Select/index.d.ts +0 -12
- package/dist/components/Select/index.js +0 -40
- package/dist/components/Select/index.js.map +0 -1
- package/dist/components/Select/styles.d.ts +0 -5
- package/dist/components/Select/styles.js +0 -57
- package/dist/components/Select/styles.js.map +0 -1
- package/dist/components/Select/types.d.ts +0 -49
- package/dist/components/Select/types.js +0 -3
- package/dist/components/Select/types.js.map +0 -1
- package/dist/components/Slider.d.ts +0 -5
- package/dist/components/Slider.js +0 -39
- package/dist/components/Slider.js.map +0 -1
- package/dist/components/Text.d.ts +0 -9
- package/dist/components/Text.js +0 -43
- package/dist/components/Text.js.map +0 -1
- package/dist/components/TextInput.d.ts +0 -150
- package/dist/components/TextInput.js +0 -125
- package/dist/components/TextInput.js.map +0 -1
- package/dist/components/Tooltip.d.ts +0 -12
- package/dist/components/Tooltip.js +0 -122
- package/dist/components/Tooltip.js.map +0 -1
- package/dist/components/Touchable.d.ts +0 -15
- package/dist/components/Touchable.js +0 -52
- package/dist/components/Touchable.js.map +0 -1
- package/dist/components/View.d.ts +0 -10
- package/dist/components/View.js +0 -62
- package/dist/components/View.js.map +0 -1
- package/dist/components/index.d.ts +0 -24
- package/dist/components/index.js +0 -37
- package/dist/components/index.js.map +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -25
- package/dist/index.js.map +0 -1
- package/dist/lib/OSAlert.d.ts +0 -21
- package/dist/lib/OSAlert.js +0 -140
- package/dist/lib/OSAlert.js.map +0 -1
- package/dist/lib/Toast.d.ts +0 -13
- package/dist/lib/Toast.js +0 -32
- package/dist/lib/Toast.js.map +0 -1
- package/dist/lib/hooks.d.ts +0 -28
- package/dist/lib/hooks.js +0 -183
- package/dist/lib/hooks.js.map +0 -1
- package/dist/lib/logger.d.ts +0 -2
- package/dist/lib/logger.js +0 -16
- package/dist/lib/logger.js.map +0 -1
- package/dist/lib/utils/cookies.d.ts +0 -6
- package/dist/lib/utils/cookies.js +0 -15
- package/dist/lib/utils/cookies.js.map +0 -1
- package/dist/lib/utils/index.d.ts +0 -4
- package/dist/lib/utils/index.js +0 -23
- package/dist/lib/utils/index.js.map +0 -1
- package/dist/lib/utils/pollyfils/scroll.d.ts +0 -1
- package/dist/lib/utils/pollyfils/scroll.js +0 -66
- package/dist/lib/utils/pollyfils/scroll.js.map +0 -1
- package/dist/lib/utils/stopPropagation.d.ts +0 -1
- package/dist/lib/utils/stopPropagation.js +0 -20
- package/dist/lib/utils/stopPropagation.js.map +0 -1
- package/dist/types/utility.d.ts +0 -2
- package/dist/types/utility.js +0 -3
- package/dist/types/utility.js.map +0 -1
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { CSSObject, jsx } from '@emotion/react'
|
|
3
|
+
import {
|
|
4
|
+
ComponentVariants,
|
|
5
|
+
useBooleanToggle,
|
|
6
|
+
useDefaultComponentStyle,
|
|
7
|
+
useDebounce,
|
|
8
|
+
} from '@codeleap/common'
|
|
9
|
+
import { ReactNode } from 'react'
|
|
10
|
+
import { View } from '../View'
|
|
11
|
+
|
|
12
|
+
import { StylesOf } from '../../types/utility'
|
|
13
|
+
import { Touchable } from '../Touchable'
|
|
14
|
+
import { useClickOutside } from '../../lib/hooks'
|
|
15
|
+
import { TooltipComposition, TooltipPresets } from './styles'
|
|
16
|
+
|
|
17
|
+
type TooltipPosition = 'left' | 'top' | 'bottom' | 'right'
|
|
18
|
+
|
|
19
|
+
const arrowPositionStyles = {
|
|
20
|
+
left: {
|
|
21
|
+
right: `100%`,
|
|
22
|
+
top: '50%',
|
|
23
|
+
transform: 'translate(50%,-50%)',
|
|
24
|
+
borderRight: 'none',
|
|
25
|
+
borderTop: 'none',
|
|
26
|
+
},
|
|
27
|
+
right: {
|
|
28
|
+
left: `100%`,
|
|
29
|
+
top: '50%',
|
|
30
|
+
transform: 'translate(-50%,-50%)',
|
|
31
|
+
borderLeft: 'none',
|
|
32
|
+
borderBottom: 'none',
|
|
33
|
+
},
|
|
34
|
+
bottom: {
|
|
35
|
+
left: '50%',
|
|
36
|
+
top: `100%`,
|
|
37
|
+
transform: 'translate(-50%,-50%)',
|
|
38
|
+
borderTop: 'none',
|
|
39
|
+
borderLeft: 'none',
|
|
40
|
+
},
|
|
41
|
+
top: {
|
|
42
|
+
left: '50%',
|
|
43
|
+
bottom: `100%`,
|
|
44
|
+
transform: 'translate(-50%,50%)',
|
|
45
|
+
borderBottom: 'none',
|
|
46
|
+
borderRight: 'none',
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const tooltipPositionStyles = {
|
|
51
|
+
left: (arrow = 0, visible = false) => ({
|
|
52
|
+
right: `calc(100% + ${arrow}px)`,
|
|
53
|
+
top: '50%',
|
|
54
|
+
transform: `translate(0%,-50%) scale(${visible ? '1' : '0'})`,
|
|
55
|
+
}),
|
|
56
|
+
right: (arrow = 0, visible = false) => ({
|
|
57
|
+
left: `calc(100% + ${arrow}px)`,
|
|
58
|
+
top: '50%',
|
|
59
|
+
transform: `translate(0%,-50%) scale(${visible ? '1' : '0'})`,
|
|
60
|
+
}),
|
|
61
|
+
bottom: (arrow = 0, visible = false) => ({
|
|
62
|
+
left: '50%',
|
|
63
|
+
top: `calc(100% + ${arrow}px)`,
|
|
64
|
+
transform: `translate(-50%,0%) scale(${visible ? '1' : '0'})`,
|
|
65
|
+
}),
|
|
66
|
+
top: (arrow = 0, visible = false) => ({
|
|
67
|
+
left: '50%',
|
|
68
|
+
bottom: `calc(100% + ${arrow}px)`,
|
|
69
|
+
transform: `translate(-50%,0%) scale(${visible ? '1' : '0'})`,
|
|
70
|
+
}),
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type TooltipProps = React.PropsWithChildren<{
|
|
74
|
+
position: TooltipPosition
|
|
75
|
+
styles?: StylesOf<TooltipComposition>
|
|
76
|
+
showOn?: 'click' | 'hover'
|
|
77
|
+
content?: string | ReactNode
|
|
78
|
+
} & ComponentVariants<typeof TooltipPresets>
|
|
79
|
+
>
|
|
80
|
+
const invert = (pos) => {
|
|
81
|
+
switch (pos) {
|
|
82
|
+
case 'left':
|
|
83
|
+
return 'right'
|
|
84
|
+
case 'right':
|
|
85
|
+
return 'left'
|
|
86
|
+
case 'top':
|
|
87
|
+
return 'bottom'
|
|
88
|
+
case 'bottom':
|
|
89
|
+
return 'top'
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export const Tooltip: React.FC<TooltipProps> = (props) => {
|
|
94
|
+
const {
|
|
95
|
+
children,
|
|
96
|
+
position = 'top',
|
|
97
|
+
styles,
|
|
98
|
+
variants,
|
|
99
|
+
responsiveVariants,
|
|
100
|
+
showOn,
|
|
101
|
+
content,
|
|
102
|
+
} = props
|
|
103
|
+
|
|
104
|
+
const [isVisible, setVisible] = useBooleanToggle(false)
|
|
105
|
+
|
|
106
|
+
const [debouncedVisible] = useDebounce(isVisible, 100)
|
|
107
|
+
const arrowPos = arrowPositionStyles[invert(position)]
|
|
108
|
+
|
|
109
|
+
const variantStyles = useDefaultComponentStyle('Tooltip', {
|
|
110
|
+
responsiveVariants,
|
|
111
|
+
variants,
|
|
112
|
+
styles,
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
const style = {
|
|
116
|
+
transition: 'transform 0.2s ease',
|
|
117
|
+
'&:after': {
|
|
118
|
+
...variantStyles.arrow,
|
|
119
|
+
...arrowPos,
|
|
120
|
+
transform: arrowPos.transform + ' rotate(45deg)',
|
|
121
|
+
},
|
|
122
|
+
...tooltipPositionStyles[position](10, debouncedVisible),
|
|
123
|
+
...variantStyles.bubble,
|
|
124
|
+
} as CSSObject
|
|
125
|
+
|
|
126
|
+
const wrapperRef = useClickOutside(
|
|
127
|
+
() => {
|
|
128
|
+
if (isVisible) {
|
|
129
|
+
setVisible(false)
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
if (showOn === 'click') {
|
|
135
|
+
return (
|
|
136
|
+
<Touchable
|
|
137
|
+
onPress={() => setVisible()}
|
|
138
|
+
ref={wrapperRef}
|
|
139
|
+
css={variantStyles.wrapper}
|
|
140
|
+
>
|
|
141
|
+
<View css={style}>{content}</View>
|
|
142
|
+
{children}
|
|
143
|
+
</Touchable>
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return (
|
|
148
|
+
<View onHover={setVisible} ref={wrapperRef} css={variantStyles.wrapper}>
|
|
149
|
+
<View css={style}>{content}</View>
|
|
150
|
+
{children}
|
|
151
|
+
</View>
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export * from './styles'
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createDefaultVariantFactory, includePresets } from "@codeleap/common"
|
|
2
|
+
|
|
3
|
+
export type TooltipComposition = "wrapper" | "arrow" | "bubble"
|
|
4
|
+
|
|
5
|
+
const createTooltipStyle = createDefaultVariantFactory<TooltipComposition>()
|
|
6
|
+
|
|
7
|
+
export const TooltipPresets = includePresets((styles) => createTooltipStyle(() => ({
|
|
8
|
+
wrapper: styles,
|
|
9
|
+
})) )
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { AnyFunction, useCodeleapContext } from '@codeleap/common'
|
|
3
|
+
import { jsx, CSSObject } from '@emotion/react'
|
|
4
|
+
|
|
5
|
+
import React, { ComponentPropsWithRef, ElementType, forwardRef, ReactElement } from 'react'
|
|
6
|
+
import { stopPropagation } from '../../lib'
|
|
7
|
+
import { View } from '../View'
|
|
8
|
+
import { TouchableComposition } from './styles'
|
|
9
|
+
import { StylesOf } from '../../types'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export * from './styles'
|
|
13
|
+
|
|
14
|
+
export type TouchableProps<T extends ElementType = 'button'> = ComponentPropsWithRef<T> & {
|
|
15
|
+
css?: CSSObject
|
|
16
|
+
component?: T
|
|
17
|
+
disabled?: boolean
|
|
18
|
+
propagate?: boolean
|
|
19
|
+
onPress?: AnyFunction
|
|
20
|
+
debugComponent?: string
|
|
21
|
+
debugName?: string
|
|
22
|
+
styles?: StylesOf<TouchableComposition>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const TouchableCP = <T extends ElementType = typeof View>(
|
|
26
|
+
touchableProps: TouchableProps<T>,
|
|
27
|
+
ref,
|
|
28
|
+
) => {
|
|
29
|
+
const {
|
|
30
|
+
children,
|
|
31
|
+
propagate = true,
|
|
32
|
+
component: Component = View,
|
|
33
|
+
disabled,
|
|
34
|
+
onPress,
|
|
35
|
+
onClick,
|
|
36
|
+
debugComponent,
|
|
37
|
+
debugName,
|
|
38
|
+
...props
|
|
39
|
+
} = touchableProps
|
|
40
|
+
|
|
41
|
+
const { logger } = useCodeleapContext()
|
|
42
|
+
|
|
43
|
+
const handleClick = (event: React.MouseEvent<T>) => {
|
|
44
|
+
if (disabled) return
|
|
45
|
+
|
|
46
|
+
if (!propagate) stopPropagation(event)
|
|
47
|
+
|
|
48
|
+
if (!onPress) {
|
|
49
|
+
logger.warn('No onPress passed to touchable', touchableProps)
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
logger.log(
|
|
54
|
+
`<${debugComponent || 'Touchable'}/> pressed`,
|
|
55
|
+
{ debugName, debugComponent },
|
|
56
|
+
'User interaction',
|
|
57
|
+
)
|
|
58
|
+
onClick?.()
|
|
59
|
+
onPress && onPress()
|
|
60
|
+
// logger.log('Touchable pressed', JSON.stringify(touchableProps, null, 2) ,'Component')
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<View component={Component || 'div'} {...props} onClick={handleClick} ref={ref}>
|
|
65
|
+
{children}
|
|
66
|
+
</View>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const Touchable = forwardRef(TouchableCP) as <T extends ElementType = typeof View>(
|
|
71
|
+
touchableProps: TouchableProps<T>
|
|
72
|
+
) => ReactElement
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
2
|
+
import { StylesOf } from '../../types'
|
|
3
|
+
|
|
4
|
+
export type TouchableComposition = 'wrapper'
|
|
5
|
+
|
|
6
|
+
const createTouchableStyle = createDefaultVariantFactory<
|
|
7
|
+
TouchableComposition
|
|
8
|
+
>()
|
|
9
|
+
|
|
10
|
+
export const TouchablePresets = includePresets((styles) => createTouchableStyle(() => ({ wrapper: styles })))
|
|
11
|
+
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { jsx } from '@emotion/react'
|
|
3
|
+
import {
|
|
4
|
+
ComponentVariants,
|
|
5
|
+
useDefaultComponentStyle,
|
|
6
|
+
useCodeleapContext,
|
|
7
|
+
BaseViewProps,
|
|
8
|
+
useMemo
|
|
9
|
+
} from '@codeleap/common'
|
|
10
|
+
import {
|
|
11
|
+
ComponentPropsWithRef,
|
|
12
|
+
ElementType,
|
|
13
|
+
forwardRef,
|
|
14
|
+
ReactElement,
|
|
15
|
+
ReactNode,
|
|
16
|
+
Ref,
|
|
17
|
+
} from 'react'
|
|
18
|
+
import { ViewPresets } from './styles'
|
|
19
|
+
import { useMediaQuery } from '../../lib/hooks'
|
|
20
|
+
|
|
21
|
+
export * from './styles'
|
|
22
|
+
|
|
23
|
+
export type ViewProps<T extends ElementType> = ComponentPropsWithRef<T> &
|
|
24
|
+
ComponentVariants<typeof ViewPresets> & {
|
|
25
|
+
component?: T
|
|
26
|
+
children?: ReactNode
|
|
27
|
+
css?: any
|
|
28
|
+
scroll?: boolean
|
|
29
|
+
debug?: boolean
|
|
30
|
+
} & BaseViewProps
|
|
31
|
+
|
|
32
|
+
export const ViewCP = <T extends ElementType = 'div'>(
|
|
33
|
+
viewProps: ViewProps<T>,
|
|
34
|
+
ref: Ref<any>,
|
|
35
|
+
) => {
|
|
36
|
+
const {
|
|
37
|
+
responsiveVariants = {},
|
|
38
|
+
variants = [],
|
|
39
|
+
component: Component = 'div',
|
|
40
|
+
children,
|
|
41
|
+
is,
|
|
42
|
+
not,
|
|
43
|
+
up,
|
|
44
|
+
onHover,
|
|
45
|
+
styles,
|
|
46
|
+
down,
|
|
47
|
+
css: cssProp,
|
|
48
|
+
scroll = false,
|
|
49
|
+
debug = false,
|
|
50
|
+
...props
|
|
51
|
+
} = viewProps
|
|
52
|
+
const variantStyles = useDefaultComponentStyle('View', {
|
|
53
|
+
responsiveVariants,
|
|
54
|
+
variants,
|
|
55
|
+
styles,
|
|
56
|
+
})
|
|
57
|
+
const { Theme, logger } = useCodeleapContext()
|
|
58
|
+
|
|
59
|
+
function handleHover(isMouseOverElement: boolean) {
|
|
60
|
+
onHover && onHover(isMouseOverElement)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const platformMediaQuery = useMemo(() => {
|
|
64
|
+
return Theme.media.renderToPlatformQuery({
|
|
65
|
+
is,
|
|
66
|
+
not,
|
|
67
|
+
up,
|
|
68
|
+
down,
|
|
69
|
+
})
|
|
70
|
+
}, [is, not, up, down])
|
|
71
|
+
|
|
72
|
+
const matches = useMediaQuery(platformMediaQuery)
|
|
73
|
+
|
|
74
|
+
if(debug){
|
|
75
|
+
logger.log('View', {variantStyles, platformMediaQuery, matches})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<Component
|
|
80
|
+
// className={cx(css([variantStyles.wrapper, scroll && {overflowY: 'scroll'}, platformMediaQuery]), cssProp)}
|
|
81
|
+
css={[variantStyles.wrapper, scroll && { overflowY: 'scroll' }, matches && { display: 'none' }]}
|
|
82
|
+
ref={ref}
|
|
83
|
+
onMouseEnter={() => handleHover(true)}
|
|
84
|
+
onMouseLeave={() => handleHover(false)}
|
|
85
|
+
{...props}
|
|
86
|
+
>
|
|
87
|
+
{children}
|
|
88
|
+
</Component>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const View = forwardRef(ViewCP) as <T extends ElementType = 'div'>(
|
|
93
|
+
props: ViewProps<T>
|
|
94
|
+
) => ReactElement
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
2
|
+
|
|
3
|
+
export type ViewComposition = 'wrapper'
|
|
4
|
+
|
|
5
|
+
const createViewStyle = createDefaultVariantFactory<ViewComposition>()
|
|
6
|
+
|
|
7
|
+
export const ViewPresets = includePresets((styles) => createViewStyle(() => ({ wrapper: styles })))
|
|
8
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export * from './View'
|
|
2
|
+
export * from './Icon'
|
|
3
|
+
export * from './Touchable'
|
|
4
|
+
export * from './Text'
|
|
5
|
+
export * from './Slider'
|
|
6
|
+
export * from './Scroll'
|
|
7
|
+
export * from './List'
|
|
8
|
+
export * from './ActivityIndicator'
|
|
9
|
+
export * from './Button'
|
|
10
|
+
export * from './Modal'
|
|
11
|
+
export * from './ActionIcon'
|
|
12
|
+
export * from './Checkbox'
|
|
13
|
+
export * from './Collapse'
|
|
14
|
+
export * from './Drawer'
|
|
15
|
+
export * from './Overlay'
|
|
16
|
+
export * from './TextInput'
|
|
17
|
+
export * from './RadioInput'
|
|
18
|
+
export * from './Select'
|
|
19
|
+
export * from './FileInput'
|
|
20
|
+
export * from './Slider'
|
|
21
|
+
export * from './Tooltip'
|
|
22
|
+
export * from './List'
|
|
23
|
+
export * from './Link'
|
|
24
|
+
export * from './LoadingOverlay'
|
|
25
|
+
export * from './InputBase'
|
|
26
|
+
export * from './Switch'
|
|
27
|
+
export * from './NumberIncrement'
|
|
28
|
+
|
|
29
|
+
export * from './defaultStyles'
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ViewPresets } from './View/styles'
|
|
2
|
+
import { IconPresets } from './Icon/styles'
|
|
3
|
+
import { TouchablePresets } from './Touchable/styles'
|
|
4
|
+
import { TextPresets } from './Text/styles'
|
|
5
|
+
import { ScrollPresets } from './Scroll/styles'
|
|
6
|
+
import { ActivityIndicatorPresets } from './ActivityIndicator/styles'
|
|
7
|
+
import { ButtonPresets } from './Button/styles'
|
|
8
|
+
import { ActionIconPresets } from './ActionIcon/styles'
|
|
9
|
+
import { ModalPresets } from './Modal/styles'
|
|
10
|
+
import { CheckboxPresets } from './Checkbox/styles'
|
|
11
|
+
import { CollapsePresets } from './Collapse/styles'
|
|
12
|
+
import { DrawerPresets } from './Drawer/styles'
|
|
13
|
+
import { OverlayPresets } from './Overlay/styles'
|
|
14
|
+
import { TextInputPresets } from './TextInput/styles'
|
|
15
|
+
import { RadioInputPresets } from './RadioInput/styles'
|
|
16
|
+
import { SelectPresets } from './Select/styles'
|
|
17
|
+
import { TooltipPresets } from './Tooltip/styles'
|
|
18
|
+
import { ListPresets } from './List/styles'
|
|
19
|
+
import { LinkPresets } from './Link/styles'
|
|
20
|
+
import { SliderPresets } from './Slider/styles'
|
|
21
|
+
import { LoadingOverlayPresets } from './LoadingOverlay/styles'
|
|
22
|
+
import { InputBasePresets } from './InputBase'
|
|
23
|
+
import { SwitchPresets } from './Switch/styles'
|
|
24
|
+
import { NumberIncrementPresets } from './NumberIncrement/styles'
|
|
25
|
+
|
|
26
|
+
export const defaultStyles = {
|
|
27
|
+
View: ViewPresets,
|
|
28
|
+
Icon: IconPresets,
|
|
29
|
+
Touchable: TouchablePresets,
|
|
30
|
+
Text: TextPresets,
|
|
31
|
+
ActivityIndicator: ActivityIndicatorPresets,
|
|
32
|
+
ActionIcon: ActionIconPresets,
|
|
33
|
+
Scroll: ScrollPresets,
|
|
34
|
+
Link: LinkPresets,
|
|
35
|
+
Button: ButtonPresets,
|
|
36
|
+
Modal: ModalPresets,
|
|
37
|
+
Checkbox: CheckboxPresets,
|
|
38
|
+
Collapse: CollapsePresets,
|
|
39
|
+
Drawer: DrawerPresets,
|
|
40
|
+
Overlay: OverlayPresets,
|
|
41
|
+
TextInput: TextInputPresets,
|
|
42
|
+
RadioInput: RadioInputPresets,
|
|
43
|
+
Select: SelectPresets,
|
|
44
|
+
Tooltip: TooltipPresets,
|
|
45
|
+
List: ListPresets,
|
|
46
|
+
Slider: SliderPresets,
|
|
47
|
+
LoadingOverlay: LoadingOverlayPresets,
|
|
48
|
+
InputBase: InputBasePresets,
|
|
49
|
+
Switch: SwitchPresets,
|
|
50
|
+
NumberIncrement: NumberIncrementPresets
|
|
51
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { AnyFunction, onMount, onUpdate, StyleContextProps, StyleProvider, useBooleanToggle, usePrevious } from '@codeleap/common'
|
|
2
|
+
import { Modal, Text, Button } from '../components/components'
|
|
3
|
+
import ReactDOM from 'react-dom'
|
|
4
|
+
|
|
5
|
+
type AlertButton = {
|
|
6
|
+
text: string
|
|
7
|
+
onPress: AnyFunction
|
|
8
|
+
variants?: any[]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type OSAlertArgs = {
|
|
12
|
+
title: string
|
|
13
|
+
body?: string
|
|
14
|
+
options?: AlertButton[]
|
|
15
|
+
}
|
|
16
|
+
type AlertEvent = AlertButton['onPress']
|
|
17
|
+
// type OSAlertType = 'info' | 'error' | 'warn' | 'ask'
|
|
18
|
+
type NamedEvents<E extends string> = Partial<Record<E, AlertEvent>>
|
|
19
|
+
type AlertContext = StyleContextProps<any, any>
|
|
20
|
+
function RenderModal(props: {args:OSAlertArgs; contextProps:AlertContext ; removeSelf:AnyFunction}) {
|
|
21
|
+
const [visible, toggle] = useBooleanToggle(false)
|
|
22
|
+
|
|
23
|
+
const previousVisible = usePrevious(visible)
|
|
24
|
+
|
|
25
|
+
const { title, body, options = [] } = props.args
|
|
26
|
+
|
|
27
|
+
onMount(() => {
|
|
28
|
+
toggle()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
onUpdate(() => {
|
|
32
|
+
if (!visible && previousVisible) {
|
|
33
|
+
setTimeout(props.removeSelf, 1000)
|
|
34
|
+
}
|
|
35
|
+
}, [visible])
|
|
36
|
+
|
|
37
|
+
return <StyleProvider {...props.contextProps}>
|
|
38
|
+
<Modal
|
|
39
|
+
visible={visible}
|
|
40
|
+
toggle={toggle}
|
|
41
|
+
title={title}
|
|
42
|
+
showClose={false}
|
|
43
|
+
closable={false}
|
|
44
|
+
|
|
45
|
+
footer={<>
|
|
46
|
+
{
|
|
47
|
+
options.map((o, idx) => <Button key={idx} {...o} onPress={() => {
|
|
48
|
+
o.onPress?.()
|
|
49
|
+
toggle()
|
|
50
|
+
|
|
51
|
+
}}/>)
|
|
52
|
+
}
|
|
53
|
+
</>}
|
|
54
|
+
>
|
|
55
|
+
<Text text={body || ''} />
|
|
56
|
+
|
|
57
|
+
</Modal>
|
|
58
|
+
</StyleProvider>
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const MODAL_ID = '__CODELEAP_MODAL__'
|
|
62
|
+
|
|
63
|
+
function OSAlert(props:OSAlertArgs & {context: AlertContext}) {
|
|
64
|
+
if (!document) return
|
|
65
|
+
let modalDiv = document.getElementById(MODAL_ID)
|
|
66
|
+
const remove = () => {
|
|
67
|
+
ReactDOM.unmountComponentAtNode(modalDiv)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!modalDiv) {
|
|
71
|
+
modalDiv = document.createElement('div')
|
|
72
|
+
|
|
73
|
+
modalDiv.setAttribute('id', MODAL_ID)
|
|
74
|
+
|
|
75
|
+
document.body.appendChild(modalDiv)
|
|
76
|
+
} else {
|
|
77
|
+
remove()
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
ReactDOM.render(
|
|
81
|
+
<RenderModal
|
|
82
|
+
contextProps={props.context}
|
|
83
|
+
removeSelf={remove}
|
|
84
|
+
args={props}
|
|
85
|
+
/>, modalDiv,
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function CreateOSAlert(context: AlertContext) {
|
|
90
|
+
function ask({ title, body, options }: OSAlertArgs) {
|
|
91
|
+
if (!title) {
|
|
92
|
+
title = 'Quick quetion'
|
|
93
|
+
}
|
|
94
|
+
OSAlert({
|
|
95
|
+
context,
|
|
96
|
+
title,
|
|
97
|
+
body,
|
|
98
|
+
options,
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function OSError(args: OSAlertArgs & NamedEvents<'onDismiss'>) {
|
|
103
|
+
let {
|
|
104
|
+
title,
|
|
105
|
+
body,
|
|
106
|
+
} = args
|
|
107
|
+
|
|
108
|
+
if (!title) {
|
|
109
|
+
title = 'Whoops!'
|
|
110
|
+
}
|
|
111
|
+
if (!body) {
|
|
112
|
+
body = 'Something went wrong'
|
|
113
|
+
}
|
|
114
|
+
OSAlert({
|
|
115
|
+
title,
|
|
116
|
+
context,
|
|
117
|
+
body,
|
|
118
|
+
options: [
|
|
119
|
+
{
|
|
120
|
+
text: 'OK',
|
|
121
|
+
onPress: () => {
|
|
122
|
+
|
|
123
|
+
args?.onDismiss?.()
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function warn(args: OSAlertArgs & NamedEvents<'onReject' | 'onAccept'>) {
|
|
131
|
+
const {
|
|
132
|
+
title = 'Hang on',
|
|
133
|
+
body = 'Are you sure?',
|
|
134
|
+
onAccept,
|
|
135
|
+
onReject = () => null,
|
|
136
|
+
} = args
|
|
137
|
+
|
|
138
|
+
OSAlert({
|
|
139
|
+
context,
|
|
140
|
+
title,
|
|
141
|
+
body,
|
|
142
|
+
options: [
|
|
143
|
+
{
|
|
144
|
+
text: 'Cancel',
|
|
145
|
+
onPress: () => {
|
|
146
|
+
|
|
147
|
+
onReject()
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
text: 'OK',
|
|
152
|
+
onPress: () => {
|
|
153
|
+
|
|
154
|
+
onAccept?.()
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function info(args: OSAlertArgs & NamedEvents<'onDismiss'>) {
|
|
162
|
+
|
|
163
|
+
const {
|
|
164
|
+
title = 'FYI',
|
|
165
|
+
body,
|
|
166
|
+
onDismiss = () => null,
|
|
167
|
+
} = args
|
|
168
|
+
|
|
169
|
+
OSAlert({
|
|
170
|
+
context,
|
|
171
|
+
title,
|
|
172
|
+
body,
|
|
173
|
+
options: [
|
|
174
|
+
{
|
|
175
|
+
text: 'OK',
|
|
176
|
+
onPress: () => {
|
|
177
|
+
|
|
178
|
+
onDismiss?.()
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
ask,
|
|
186
|
+
warn,
|
|
187
|
+
info,
|
|
188
|
+
error: OSError,
|
|
189
|
+
}
|
|
190
|
+
}
|
package/src/lib/Toast.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { toast } from 'react-toastify'
|
|
2
|
+
|
|
3
|
+
type ToastArgs = {
|
|
4
|
+
title:string
|
|
5
|
+
} &Parameters<typeof toast.info>[1]
|
|
6
|
+
|
|
7
|
+
function info({ title, ...others }:ToastArgs) {
|
|
8
|
+
toast.info(title, others)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function success({ title, ...others }:ToastArgs) {
|
|
12
|
+
toast.success(title, others)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function error({ title, ...others }:ToastArgs) {
|
|
16
|
+
toast.error(title, others)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default {
|
|
20
|
+
info,
|
|
21
|
+
success,
|
|
22
|
+
error,
|
|
23
|
+
}
|