@codeleap/web 1.0.1 → 1.1.3
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/dist/components/ActivityIndicator/index.d.ts +0 -1
- package/dist/components/ActivityIndicator/styles.d.ts +5 -1
- package/dist/components/Checkbox/index.d.ts +12 -0
- package/dist/components/Checkbox/index.js +57 -0
- package/dist/components/Checkbox/index.js.map +1 -0
- package/dist/components/Checkbox/styles.d.ts +46 -0
- package/dist/components/Checkbox/styles.js +58 -0
- package/dist/components/Checkbox/styles.js.map +1 -0
- package/dist/components/ContentView.d.ts +0 -1
- package/dist/components/ContentView.js +1 -1
- package/dist/components/ContentView.js.map +1 -1
- package/dist/components/FileInput.d.ts +1 -5
- package/dist/components/FileInput.js.map +1 -1
- package/dist/components/Icon.d.ts +2 -3
- package/dist/components/Icon.js +18 -4
- package/dist/components/Icon.js.map +1 -1
- package/dist/components/Link.d.ts +1 -1
- package/dist/components/Modal/styles.d.ts +5 -1
- package/dist/components/Overlay.d.ts +0 -1
- package/dist/components/PageRouter/Menu.d.ts +0 -1
- package/dist/components/PageRouter/MenuItem.d.ts +1 -1
- package/dist/components/PageRouter/MenuItem.js.map +1 -1
- package/dist/components/PageRouter/Router.js +1 -1
- package/dist/components/PageRouter/Router.js.map +1 -1
- package/dist/components/PageRouter/index.js +1 -1
- package/dist/components/PageRouter/index.js.map +1 -1
- package/dist/components/RadioInput/index.d.ts +1 -42
- package/dist/components/RadioInput/styles.d.ts +5 -1
- package/dist/components/Slider.d.ts +0 -1
- package/dist/components/Text.d.ts +1 -1
- package/dist/components/TextInput.d.ts +1 -89
- package/dist/components/TextInput.js +4 -4
- package/dist/components/TextInput.js.map +1 -1
- package/dist/components/Touchable.d.ts +2 -2
- package/dist/components/View.d.ts +3 -3
- package/dist/lib/hooks.d.ts +1 -1
- package/package.json +6 -3
- package/.eslintignore +0 -2
- package/.eslintrc.js +0 -3
- package/.turbo/turbo-build.log +0 -1
- package/dist/components/Tooltip-old.d.ts +0 -11
- package/dist/components/Tooltip-old.js +0 -151
- package/dist/components/Tooltip-old.js.map +0 -1
- package/dist/components/router/Menu.d.ts +0 -10
- package/dist/components/router/Menu.js +0 -39
- package/dist/components/router/Menu.js.map +0 -1
- package/dist/components/router/MenuItem.d.ts +0 -11
- package/dist/components/router/MenuItem.js +0 -42
- package/dist/components/router/MenuItem.js.map +0 -1
- package/dist/components/router/Router.d.ts +0 -8
- package/dist/components/router/Router.js +0 -28
- package/dist/components/router/Router.js.map +0 -1
- package/dist/components/router/index.d.ts +0 -14
- package/dist/components/router/index.js +0 -69
- package/dist/components/router/index.js.map +0 -1
- package/src/components/ActivityIndicator/index.tsx +0 -55
- package/src/components/ActivityIndicator/styles.ts +0 -18
- package/src/components/Button.tsx +0 -67
- package/src/components/CenterWrapper.tsx +0 -24
- package/src/components/Checkbox.tsx +0 -46
- package/src/components/ContentView.tsx +0 -48
- package/src/components/Drawer.tsx +0 -114
- package/src/components/FileInput.tsx +0 -48
- package/src/components/FlatList.tsx +0 -77
- package/src/components/HorizontalScroll.tsx +0 -24
- package/src/components/Icon.tsx +0 -26
- package/src/components/Link.tsx +0 -51
- package/src/components/Modal/index.tsx +0 -150
- package/src/components/Modal/styles.ts +0 -49
- package/src/components/Overlay.tsx +0 -25
- package/src/components/PageRouter/Menu.tsx +0 -49
- package/src/components/PageRouter/MenuItem.tsx +0 -55
- package/src/components/PageRouter/Router.tsx +0 -23
- package/src/components/PageRouter/index.tsx +0 -81
- package/src/components/RadioInput/index.tsx +0 -72
- package/src/components/RadioInput/styles.ts +0 -57
- package/src/components/Select.tsx +0 -60
- package/src/components/Slider.tsx +0 -14
- package/src/components/Text.tsx +0 -27
- package/src/components/TextInput.tsx +0 -219
- package/src/components/Tooltip.tsx +0 -138
- package/src/components/Touchable.tsx +0 -47
- package/src/components/View.tsx +0 -54
- package/src/components/index.ts +0 -23
- package/src/index.ts +0 -4
- package/src/lib/hooks.ts +0 -59
- package/src/lib/logger.ts +0 -15
- package/src/lib/utils/cookies.ts +0 -19
- package/src/lib/utils/index.ts +0 -4
- package/src/lib/utils/pollyfils/scroll.ts +0 -59
- package/src/lib/utils/stopPropagation.ts +0 -17
- package/src/types/utility.ts +0 -4
- package/tsconfig.json +0 -42
package/src/components/Text.tsx
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/** @jsx jsx */
|
|
2
|
-
import { jsx } from '@emotion/react'
|
|
3
|
-
import { ComponentVariants, TextComposition, TextStyles, useComponentStyle } from '@codeleap/common';
|
|
4
|
-
import { ComponentPropsWithoutRef, ElementType } from 'react';
|
|
5
|
-
import { StylesOf } from '../types/utility';
|
|
6
|
-
|
|
7
|
-
export type TextProps< T extends ElementType> = {
|
|
8
|
-
component?: T
|
|
9
|
-
text?: string
|
|
10
|
-
styles?: StylesOf<TextComposition>
|
|
11
|
-
} & ComponentPropsWithoutRef<T> & ComponentVariants<typeof TextStyles>
|
|
12
|
-
|
|
13
|
-
export const Text = <T extends ElementType >(textProps:TextProps<T>) => {
|
|
14
|
-
const {variants = [], responsiveVariants = {}, text, children, component = 'p', styles, ...props} = textProps
|
|
15
|
-
const variantStyles = useComponentStyle('Text', {
|
|
16
|
-
rootElement: 'text',
|
|
17
|
-
responsiveVariants,
|
|
18
|
-
variants,
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
const Component = component
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return <Component {...props} css={{...variantStyles.text, ...props.style, ...styles?.text}} >
|
|
25
|
-
{text || children}
|
|
26
|
-
</Component>
|
|
27
|
-
}
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ComponentVariants,
|
|
3
|
-
FormTypes,
|
|
4
|
-
IconPlaceholder,
|
|
5
|
-
|
|
6
|
-
onUpdate,
|
|
7
|
-
|
|
8
|
-
TextInputComposition,
|
|
9
|
-
TextInputStyles,
|
|
10
|
-
useBooleanToggle,
|
|
11
|
-
useComponentStyle } from '@codeleap/common';
|
|
12
|
-
import React, { ComponentPropsWithoutRef, forwardRef, useImperativeHandle, useRef, useState } from 'react'
|
|
13
|
-
import TextareaAutosize from 'react-autosize-textarea'
|
|
14
|
-
import { Text } from './Text';
|
|
15
|
-
import { View } from './View';
|
|
16
|
-
import { Button } from './Button';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/** @jsx jsx */
|
|
20
|
-
import { jsx } from '@emotion/react'
|
|
21
|
-
import { StylesOf } from '../types/utility';
|
|
22
|
-
import { Icon } from '.';
|
|
23
|
-
|
|
24
|
-
type IconProp = {name: IconPlaceholder, action?:() => void}
|
|
25
|
-
type MergedRef = React.LegacyRef<HTMLInputElement> & React.Ref<HTMLTextAreaElement>
|
|
26
|
-
type ValidateFN = (value:string) => { status: 'error' | 'success', message?: string }
|
|
27
|
-
type NativeProps = ComponentPropsWithoutRef<'input'> &
|
|
28
|
-
ComponentPropsWithoutRef<'textarea'>
|
|
29
|
-
|
|
30
|
-
export type TextInputProps =
|
|
31
|
-
ComponentVariants<typeof TextInputStyles> &
|
|
32
|
-
Omit<NativeProps, 'value'> &
|
|
33
|
-
{
|
|
34
|
-
multiline?: boolean;
|
|
35
|
-
onChangeText?: (text: string) => void;
|
|
36
|
-
disabled?: boolean;
|
|
37
|
-
edited?: boolean;
|
|
38
|
-
type?: string;
|
|
39
|
-
label?:React.ReactNode
|
|
40
|
-
ref?: MergedRef
|
|
41
|
-
leftIcon?:IconProp
|
|
42
|
-
rightIcon?:IconProp
|
|
43
|
-
styles?: StylesOf<TextInputComposition>
|
|
44
|
-
validate?: FormTypes.ValidatorFunction | string
|
|
45
|
-
value?:string
|
|
46
|
-
password?:boolean
|
|
47
|
-
visibilityToggle?: boolean
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export const TextInput = forwardRef<HTMLInputElement, TextInputProps>((rawprops, inputRef) => {
|
|
51
|
-
const {
|
|
52
|
-
onChange,
|
|
53
|
-
type,
|
|
54
|
-
value,
|
|
55
|
-
onChangeText,
|
|
56
|
-
disabled,
|
|
57
|
-
edited,
|
|
58
|
-
onFocus,
|
|
59
|
-
onBlur,
|
|
60
|
-
multiline,
|
|
61
|
-
responsiveVariants,
|
|
62
|
-
variants,
|
|
63
|
-
label,
|
|
64
|
-
leftIcon,
|
|
65
|
-
rightIcon,
|
|
66
|
-
styles,
|
|
67
|
-
validate,
|
|
68
|
-
password,
|
|
69
|
-
visibilityToggle,
|
|
70
|
-
...props
|
|
71
|
-
} = rawprops
|
|
72
|
-
|
|
73
|
-
const [_ig, setFocus] = useState(false)
|
|
74
|
-
const [editedState, setEdited] = useState(edited)
|
|
75
|
-
const [error, setError] = useState<ReturnType<FormTypes.ValidatorFunction>>({
|
|
76
|
-
valid: true,
|
|
77
|
-
message: '',
|
|
78
|
-
})
|
|
79
|
-
const input = useRef<any>(null)
|
|
80
|
-
const [textIsVisible, setTextVisible] = useBooleanToggle(false)
|
|
81
|
-
const variantStyles =useComponentStyle('TextInput', {
|
|
82
|
-
variants,
|
|
83
|
-
responsiveVariants,
|
|
84
|
-
styles,
|
|
85
|
-
})
|
|
86
|
-
const InputElement = multiline ? TextareaAutosize : 'input'
|
|
87
|
-
|
|
88
|
-
const handleBlur:TextInputProps['onBlur'] = (e) => {
|
|
89
|
-
if (!editedState && value) setEdited(true)
|
|
90
|
-
setFocus(false)
|
|
91
|
-
|
|
92
|
-
if (onBlur) {
|
|
93
|
-
onBlur(e)
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const handleFocus:TextInputProps['onFocus'] = (e) => {
|
|
98
|
-
setFocus(true)
|
|
99
|
-
if (onFocus) {
|
|
100
|
-
onFocus(e)
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const handleChange = (event) => {
|
|
105
|
-
const text = event.target.value
|
|
106
|
-
if (onChange) onChange(event)
|
|
107
|
-
if (onChangeText) onChangeText(text)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
onUpdate(() => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const result = typeof validate === 'function' ?
|
|
117
|
-
validate(input?.current?.value) :
|
|
118
|
-
{message: validate, valid: false}
|
|
119
|
-
setError(result)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}, [value, validate])
|
|
123
|
-
|
|
124
|
-
useImperativeHandle(inputRef, () => input.current)
|
|
125
|
-
|
|
126
|
-
const showError = (!error.valid && error.message)
|
|
127
|
-
const inputType = type || password ? 'password' : 'text'
|
|
128
|
-
|
|
129
|
-
const inputVisibilityType = textIsVisible ? 'text' : 'password'
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const leftIconStyle = {
|
|
133
|
-
...variantStyles.icon,
|
|
134
|
-
...(showError ? variantStyles['icon:error'] : {} ),
|
|
135
|
-
...variantStyles.leftIcon,
|
|
136
|
-
...(showError ? variantStyles['leftIcon:error'] : {} ),
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const rightIconStyle = {
|
|
140
|
-
...variantStyles.icon,
|
|
141
|
-
...(showError ? variantStyles['icon:error'] : {} ),
|
|
142
|
-
...variantStyles.rightIcon,
|
|
143
|
-
...(showError ? variantStyles['rightIcon:error'] : {} ),
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return (
|
|
147
|
-
<View
|
|
148
|
-
css={[variantStyles.wrapper, showError && variantStyles['wrapper:error']]}
|
|
149
|
-
>
|
|
150
|
-
<InputLabel label={label} style={variantStyles.label}/>
|
|
151
|
-
|
|
152
|
-
<div css={[variantStyles.innerWrapper, showError && variantStyles['innerWrapper:error']]}>
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
<InputIcon {...leftIcon} style={leftIconStyle}/>
|
|
156
|
-
<InputElement
|
|
157
|
-
ref={input}
|
|
158
|
-
type={visibilityToggle ? inputVisibilityType : inputType}
|
|
159
|
-
onChange={handleChange}
|
|
160
|
-
value={value}
|
|
161
|
-
disabled={disabled}
|
|
162
|
-
onFocus={handleFocus}
|
|
163
|
-
onBlur={handleBlur}
|
|
164
|
-
rows={4}
|
|
165
|
-
{...props}
|
|
166
|
-
css={[variantStyles.textField, showError && variantStyles['textField:error']]}
|
|
167
|
-
/>
|
|
168
|
-
{
|
|
169
|
-
visibilityToggle ?
|
|
170
|
-
<InputIcon name={
|
|
171
|
-
(textIsVisible ? 'input-visiblity:visible' : 'input-visiblity:hidden') as IconPlaceholder
|
|
172
|
-
} action={() => setTextVisible()} style={rightIconStyle}/>
|
|
173
|
-
:
|
|
174
|
-
<InputIcon {...rightIcon} style={rightIconStyle}/>
|
|
175
|
-
}
|
|
176
|
-
</div>
|
|
177
|
-
|
|
178
|
-
<FormError message={error.message} css={{
|
|
179
|
-
...variantStyles.error,
|
|
180
|
-
|
|
181
|
-
}}/>
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
</View>
|
|
185
|
-
)
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
const FormError = ({message, ...props}) => {
|
|
189
|
-
|
|
190
|
-
if (['number', 'string', 'undefined'].includes(typeof message)){
|
|
191
|
-
return <Text text={`${message||' '}`} variants={['p2', 'marginTop:1']} {...props}/>
|
|
192
|
-
}
|
|
193
|
-
return message
|
|
194
|
-
}
|
|
195
|
-
export const InputIcon:React.FC<{style:any} & IconProp> = ({name, style, action}) => {
|
|
196
|
-
if (!name) return null
|
|
197
|
-
|
|
198
|
-
if (action){
|
|
199
|
-
|
|
200
|
-
return <Button icon={name} onPress={() => action()} styles={{
|
|
201
|
-
icon: style,
|
|
202
|
-
}} variants={['icon']}/>
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return <Icon name={name} style={style}/>
|
|
206
|
-
}
|
|
207
|
-
export const InputLabel = ({label, style}) => {
|
|
208
|
-
if (!label) return null
|
|
209
|
-
|
|
210
|
-
switch (typeof label){
|
|
211
|
-
case 'string':
|
|
212
|
-
return <Text css={style} text={label} component={'label'}/>
|
|
213
|
-
case 'object':
|
|
214
|
-
|
|
215
|
-
return label
|
|
216
|
-
default:
|
|
217
|
-
return null
|
|
218
|
-
}
|
|
219
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/** @jsx jsx */
|
|
2
|
-
import { CSSObject, jsx } from '@emotion/react'
|
|
3
|
-
import { ComponentVariants, TooltipComposition, TooltipStyles, useBooleanToggle, useComponentStyle, useDebounce } from '@codeleap/common'
|
|
4
|
-
import { ReactNode } from 'react'
|
|
5
|
-
import { View } from './View'
|
|
6
|
-
|
|
7
|
-
import { StylesOf } from '../types/utility'
|
|
8
|
-
import { Touchable } from './Touchable'
|
|
9
|
-
import { useClickOutside } from '../lib/hooks'
|
|
10
|
-
|
|
11
|
-
type TooltipPosition = 'left'| 'top' | 'bottom' | 'right'
|
|
12
|
-
|
|
13
|
-
const arrowPositionStyles = {
|
|
14
|
-
left: {
|
|
15
|
-
right: `100%`,
|
|
16
|
-
top: '50%',
|
|
17
|
-
transform: 'translate(50%,-50%)',
|
|
18
|
-
borderRight: 'none',
|
|
19
|
-
borderTop: 'none',
|
|
20
|
-
},
|
|
21
|
-
right: {
|
|
22
|
-
left: `100%`,
|
|
23
|
-
top: '50%',
|
|
24
|
-
transform: 'translate(-50%,-50%)',
|
|
25
|
-
borderLeft: 'none',
|
|
26
|
-
borderBottom: 'none',
|
|
27
|
-
},
|
|
28
|
-
bottom: {
|
|
29
|
-
left: '50%',
|
|
30
|
-
top: `100%`,
|
|
31
|
-
transform: 'translate(-50%,-50%)',
|
|
32
|
-
borderTop: 'none',
|
|
33
|
-
borderLeft: 'none',
|
|
34
|
-
},
|
|
35
|
-
top: {
|
|
36
|
-
left: '50%',
|
|
37
|
-
bottom: `100%`,
|
|
38
|
-
transform: 'translate(-50%,50%)',
|
|
39
|
-
borderBottom: 'none',
|
|
40
|
-
borderRight: 'none',
|
|
41
|
-
},
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const tooltipPositionStyles = {
|
|
45
|
-
left: (arrow = 0, visible = false) => ({
|
|
46
|
-
right: `calc(100% + ${arrow}px)`,
|
|
47
|
-
top: '50%',
|
|
48
|
-
transform: `translate(0%,-50%) scale(${visible ? '1' : '0' })`,
|
|
49
|
-
}),
|
|
50
|
-
right: (arrow = 0, visible = false) => ({
|
|
51
|
-
left: `calc(100% + ${arrow}px)`,
|
|
52
|
-
top: '50%',
|
|
53
|
-
transform: `translate(0%,-50%) scale(${visible ? '1' : '0' })`,
|
|
54
|
-
}),
|
|
55
|
-
bottom: (arrow = 0, visible = false) => ({
|
|
56
|
-
left: '50%',
|
|
57
|
-
top: `calc(100% + ${arrow}px)`,
|
|
58
|
-
transform: `translate(-50%,0%) scale(${visible ? '1' : '0' })`,
|
|
59
|
-
}),
|
|
60
|
-
top: (arrow = 0, visible = false) => ({
|
|
61
|
-
left: '50%',
|
|
62
|
-
bottom: `calc(100% + ${arrow}px)`,
|
|
63
|
-
transform: `translate(-50%,0%) scale(${visible ? '1' : '0' })`,
|
|
64
|
-
}),
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export type TooltipProps = {
|
|
68
|
-
position: TooltipPosition
|
|
69
|
-
styles?: StylesOf<TooltipComposition>
|
|
70
|
-
showOn?: 'click' | 'hover'
|
|
71
|
-
content?: string | ReactNode
|
|
72
|
-
} & ComponentVariants<typeof TooltipStyles>
|
|
73
|
-
|
|
74
|
-
const invert = (pos) => {
|
|
75
|
-
switch (pos){
|
|
76
|
-
case 'left':
|
|
77
|
-
return 'right'
|
|
78
|
-
case 'right':
|
|
79
|
-
return 'left'
|
|
80
|
-
case 'top':
|
|
81
|
-
return 'bottom'
|
|
82
|
-
case 'bottom':
|
|
83
|
-
return 'top'
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export const Tooltip:React.FC<TooltipProps> = (props) => {
|
|
88
|
-
const {children, position = 'top', styles, variants, responsiveVariants, showOn, content} = props
|
|
89
|
-
|
|
90
|
-
const [isVisible, setVisible] = useBooleanToggle(false)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const debouncedVisible = useDebounce(isVisible, 100)
|
|
94
|
-
const arrowPos = arrowPositionStyles[invert(position)]
|
|
95
|
-
|
|
96
|
-
const variantStyles = useComponentStyle('Tooltip', {
|
|
97
|
-
responsiveVariants,
|
|
98
|
-
variants,
|
|
99
|
-
styles,
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
const style = {
|
|
103
|
-
transition: 'transform 0.2s ease',
|
|
104
|
-
...variantStyles.bubble,
|
|
105
|
-
'&:after': {
|
|
106
|
-
...variantStyles.arrow,
|
|
107
|
-
...arrowPos,
|
|
108
|
-
transform: arrowPos.transform + ' rotate(45deg)',
|
|
109
|
-
},
|
|
110
|
-
...styles,
|
|
111
|
-
...tooltipPositionStyles[position](10, debouncedVisible),
|
|
112
|
-
} as CSSObject
|
|
113
|
-
|
|
114
|
-
const wrapperId = useClickOutside(() => {
|
|
115
|
-
if (isVisible){
|
|
116
|
-
setVisible(false)
|
|
117
|
-
}
|
|
118
|
-
}, {
|
|
119
|
-
deps: [setVisible, isVisible],
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
if (showOn === 'click'){
|
|
123
|
-
return <Touchable onPress={() => setVisible()} id={wrapperId} css={variantStyles.wrapper}>
|
|
124
|
-
<View css={style} >
|
|
125
|
-
{content}
|
|
126
|
-
</View>
|
|
127
|
-
{children}
|
|
128
|
-
</Touchable>
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return <View onHover={setVisible} id={wrapperId} css={variantStyles.wrapper}>
|
|
133
|
-
<View css={style} >
|
|
134
|
-
{content}
|
|
135
|
-
</View>
|
|
136
|
-
{children}
|
|
137
|
-
</View>
|
|
138
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/** @jsx jsx */
|
|
2
|
-
import { AnyFunction, useStyle } from '@codeleap/common';
|
|
3
|
-
import { jsx, CSSObject } from '@emotion/react'
|
|
4
|
-
|
|
5
|
-
import React, { ComponentPropsWithRef, ElementType } from 'react'
|
|
6
|
-
import { stopPropagation } from '../lib/utils/stopPropagation';
|
|
7
|
-
import { View } from './View';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export type TouchableProps<T extends ElementType> = ComponentPropsWithRef<T> & {
|
|
12
|
-
css?:CSSObject
|
|
13
|
-
component?: T
|
|
14
|
-
disabled?:boolean
|
|
15
|
-
propagate?: boolean
|
|
16
|
-
onPress?: AnyFunction
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const Touchable = <T extends ElementType = typeof View>(touchableProps:TouchableProps<T>) => {
|
|
20
|
-
const { children, propagate = true, component: Component = View, disabled, onPress, onClick, ...props } = touchableProps
|
|
21
|
-
|
|
22
|
-
const { logger } = useStyle()
|
|
23
|
-
|
|
24
|
-
const handleClick = (event: React.MouseEvent<T>) => {
|
|
25
|
-
|
|
26
|
-
if (disabled) return
|
|
27
|
-
|
|
28
|
-
if (!propagate) stopPropagation(event)
|
|
29
|
-
|
|
30
|
-
if (!onClick && !onPress) throw new Error('No onClick or onPress passed to touchable')
|
|
31
|
-
onPress && onPress()
|
|
32
|
-
|
|
33
|
-
onClick && onClick(event)
|
|
34
|
-
|
|
35
|
-
// logger.log('Touchable pressed', JSON.stringify(touchableProps, null, 2) ,'Component')
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
<Component
|
|
40
|
-
{...props}
|
|
41
|
-
|
|
42
|
-
onClick={handleClick}
|
|
43
|
-
>
|
|
44
|
-
{children}
|
|
45
|
-
</Component>
|
|
46
|
-
)
|
|
47
|
-
}
|
package/src/components/View.tsx
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/** @jsx jsx */
|
|
2
|
-
import { CSSObject, jsx } from '@emotion/react'
|
|
3
|
-
import { ComponentVariants, useComponentStyle, useStyle, ViewStyles, BaseViewProps } from '@codeleap/common'
|
|
4
|
-
import { ComponentPropsWithRef, ElementType, forwardRef, ReactElement, ReactNode, Ref } from 'react'
|
|
5
|
-
|
|
6
|
-
export type ViewProps<T extends ElementType> =
|
|
7
|
-
ComponentPropsWithRef<T> &
|
|
8
|
-
ComponentVariants<typeof ViewStyles> & {
|
|
9
|
-
component?:T
|
|
10
|
-
children?:ReactNode
|
|
11
|
-
css?: any
|
|
12
|
-
} & BaseViewProps
|
|
13
|
-
|
|
14
|
-
export const ViewCP = <T extends ElementType = 'div'>(viewProps:ViewProps<T>, ref:Ref<any>) => {
|
|
15
|
-
const {
|
|
16
|
-
responsiveVariants = {},
|
|
17
|
-
variants = [],
|
|
18
|
-
component: Component = 'div',
|
|
19
|
-
children,
|
|
20
|
-
is,
|
|
21
|
-
not,
|
|
22
|
-
up,
|
|
23
|
-
onHover,
|
|
24
|
-
down,
|
|
25
|
-
...props
|
|
26
|
-
} = viewProps;
|
|
27
|
-
const variantStyles = useComponentStyle('View', {
|
|
28
|
-
responsiveVariants,
|
|
29
|
-
variants,
|
|
30
|
-
});
|
|
31
|
-
const { Theme } = useStyle();
|
|
32
|
-
|
|
33
|
-
function handleHover(isMouseOverElement:boolean){
|
|
34
|
-
onHover && onHover(isMouseOverElement)
|
|
35
|
-
}
|
|
36
|
-
const shouldRenderToPlatform = Theme.hooks.shouldRenderToPlatform({ is, not, up, down })
|
|
37
|
-
if (!shouldRenderToPlatform) return null
|
|
38
|
-
|
|
39
|
-
const platformMediaQuery = Theme.media.renderToPlatformQuery({ is, not, up, down })
|
|
40
|
-
|
|
41
|
-
return <Component
|
|
42
|
-
css={[variantStyles.wrapper, platformMediaQuery]}
|
|
43
|
-
ref={ref}
|
|
44
|
-
onMouseEnter={() => handleHover(true)}
|
|
45
|
-
onMouseLeave={() => handleHover(false)}
|
|
46
|
-
{...props}
|
|
47
|
-
>
|
|
48
|
-
{children}
|
|
49
|
-
</Component>
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const View = forwardRef(ViewCP)as <
|
|
53
|
-
T extends ElementType = 'div',
|
|
54
|
-
>(props:ViewProps<T>) => ReactElement
|
package/src/components/index.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export * from './Button'
|
|
2
|
-
export * from './Text'
|
|
3
|
-
export * from './TextInput'
|
|
4
|
-
export * from './View'
|
|
5
|
-
export * from './Link'
|
|
6
|
-
export * from './Checkbox'
|
|
7
|
-
export * from './Modal'
|
|
8
|
-
export * from './ActivityIndicator'
|
|
9
|
-
export * from './RadioInput'
|
|
10
|
-
export * from './Icon'
|
|
11
|
-
export * from './FileInput'
|
|
12
|
-
export * from './Overlay'
|
|
13
|
-
export * from './Drawer'
|
|
14
|
-
export * from './ContentView'
|
|
15
|
-
export * from './FlatList'
|
|
16
|
-
export * from './Touchable'
|
|
17
|
-
export * from './Tooltip'
|
|
18
|
-
export * from './Slider'
|
|
19
|
-
export * from './Select'
|
|
20
|
-
|
|
21
|
-
export * from './PageRouter'
|
|
22
|
-
export * from './CenterWrapper'
|
|
23
|
-
export * from './HorizontalScroll'
|
package/src/index.ts
DELETED
package/src/lib/hooks.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { AnyFunction, onUpdate } from '@codeleap/common';
|
|
2
|
-
import { useRef, useState } from 'react';
|
|
3
|
-
import {v4} from 'uuid'
|
|
4
|
-
export function useWindowSize(){
|
|
5
|
-
const [size, setSize] = useState([window.innerWidth, window.innerWidth])
|
|
6
|
-
|
|
7
|
-
function handleResize(){
|
|
8
|
-
setSize([window.innerWidth, window.innerHeight])
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
onUpdate(() => {
|
|
12
|
-
window.addEventListener('resize', handleResize)
|
|
13
|
-
return () => {
|
|
14
|
-
window.removeEventListener('resize', handleResize)
|
|
15
|
-
}
|
|
16
|
-
}, [])
|
|
17
|
-
|
|
18
|
-
return size
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type UseClickOutsideOpts = {customId?:string, deps:any[]}
|
|
22
|
-
export function useClickOutside(callback: AnyFunction, {customId, deps = []} : UseClickOutsideOpts){
|
|
23
|
-
const id = useRef(customId || v4()).current
|
|
24
|
-
|
|
25
|
-
function onClick(e:Event){
|
|
26
|
-
const element = document.getElementById(id)
|
|
27
|
-
const isInside = element.contains(e.target as Node)
|
|
28
|
-
|
|
29
|
-
if (!isInside){
|
|
30
|
-
callback(e)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
onUpdate(() => {
|
|
35
|
-
document.addEventListener('click', onClick)
|
|
36
|
-
return () => {
|
|
37
|
-
document.removeEventListener('click', onClick)
|
|
38
|
-
}
|
|
39
|
-
}, [...deps, onClick])
|
|
40
|
-
|
|
41
|
-
return id
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function useScrollEffect(
|
|
45
|
-
effect: (passed: boolean, current: number) => any,
|
|
46
|
-
breakpoint: number,
|
|
47
|
-
) {
|
|
48
|
-
function handleScroll() {
|
|
49
|
-
const passed = window.scrollY > breakpoint
|
|
50
|
-
effect(passed, window.scrollY)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
onUpdate(() => {
|
|
54
|
-
document.addEventListener('scroll', handleScroll)
|
|
55
|
-
return () => {
|
|
56
|
-
document.removeEventListener('scroll', handleScroll)
|
|
57
|
-
}
|
|
58
|
-
}, [breakpoint])
|
|
59
|
-
}
|
package/src/lib/logger.ts
DELETED
package/src/lib/utils/cookies.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import Cookies from 'js-cookie'
|
|
2
|
-
|
|
3
|
-
const get = (key) => (
|
|
4
|
-
Cookies.get(key)
|
|
5
|
-
)
|
|
6
|
-
|
|
7
|
-
const set = (key, value) => (
|
|
8
|
-
Cookies.set(key, value, { expires: 365 })
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
const remove = (key) => (
|
|
12
|
-
Cookies.remove(key)
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
export default {
|
|
16
|
-
get,
|
|
17
|
-
set,
|
|
18
|
-
remove,
|
|
19
|
-
}
|
package/src/lib/utils/index.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
// native smooth scrolling for Chrome, Firefox & Opera
|
|
2
|
-
// @see: https://caniuse.com/#feat=css-scroll-behavior
|
|
3
|
-
const nativeSmoothScrollTo = elem => {
|
|
4
|
-
window.scroll({
|
|
5
|
-
behavior: 'smooth',
|
|
6
|
-
left: 0,
|
|
7
|
-
top: elem.getBoundingClientRect().top + window.pageYOffset,
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
// polyfilled smooth scrolling for IE, Edge & Safari
|
|
12
|
-
const smoothScrollTo = (to, duration) => {
|
|
13
|
-
const element = document.scrollingElement || document.documentElement,
|
|
14
|
-
start = element.scrollTop,
|
|
15
|
-
change = to - start,
|
|
16
|
-
startDate = +new Date();
|
|
17
|
-
|
|
18
|
-
// t = current time
|
|
19
|
-
// b = start value
|
|
20
|
-
// c = change in value
|
|
21
|
-
// d = duration
|
|
22
|
-
const easeInOutQuad = (t, b, c, d) => {
|
|
23
|
-
t /= d/2;
|
|
24
|
-
if (t < 1) return c/2*t*t + b;
|
|
25
|
-
t--;
|
|
26
|
-
return -c/2 * (t*(t-2) - 1) + b;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const animateScroll = () => {
|
|
30
|
-
const currentDate = +new Date();
|
|
31
|
-
const currentTime = currentDate - startDate;
|
|
32
|
-
element.scrollTop = parseInt(easeInOutQuad(currentTime, start, change, duration));
|
|
33
|
-
if (currentTime < duration) {
|
|
34
|
-
requestAnimationFrame(animateScroll);
|
|
35
|
-
} else {
|
|
36
|
-
element.scrollTop = to;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
animateScroll();
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
// detect support for the behavior property in ScrollOptions
|
|
43
|
-
const supportsNativeSmoothScroll = 'scrollBehavior' in document.documentElement.style;
|
|
44
|
-
|
|
45
|
-
// smooth scrolling stub
|
|
46
|
-
export const scrollToElem = elemSelector => {
|
|
47
|
-
if (!elemSelector) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const elem = document.querySelector(elemSelector);
|
|
52
|
-
if (elem) {
|
|
53
|
-
if (supportsNativeSmoothScroll) {
|
|
54
|
-
nativeSmoothScrollTo(elem);
|
|
55
|
-
} else {
|
|
56
|
-
smoothScrollTo(elem.offsetTop, 600);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { AnyFunction } from '@codeleap/common'
|
|
2
|
-
|
|
3
|
-
export function stopPropagation(event:any){
|
|
4
|
-
const tryCalls = [
|
|
5
|
-
event?.stopPropagation,
|
|
6
|
-
event?.preventDefault,
|
|
7
|
-
event.nativeEvent?.stopImmediatePropagation as AnyFunction,
|
|
8
|
-
]
|
|
9
|
-
|
|
10
|
-
for (const call of tryCalls){
|
|
11
|
-
try {
|
|
12
|
-
call()
|
|
13
|
-
} catch (e){
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
}
|
package/src/types/utility.ts
DELETED