@codeleap/web 1.1.0 → 1.1.4
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/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/package.json +3 -2
- package/.eslintignore +0 -2
- package/.eslintrc.js +0 -3
- package/.turbo/turbo-build.log +0 -2
- 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/index.tsx +0 -47
- package/src/components/Checkbox/styles.ts +0 -57
- 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 -29
- 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 -57
- 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 -223
- 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
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/** @jsx jsx */
|
|
2
|
-
import { jsx } from '@emotion/react';
|
|
3
|
-
import { SelectStyles, ComponentVariants, useComponentStyle, StylesOf, SelectComposition } from '@codeleap/common';
|
|
4
|
-
import { ComponentPropsWithRef, ReactNode } from 'react';
|
|
5
|
-
import { View, ViewProps } from './View';
|
|
6
|
-
import { Text } from './Text';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
type NativeSelectProps = ComponentPropsWithRef<'select'>;
|
|
10
|
-
type Option = {
|
|
11
|
-
label: string;
|
|
12
|
-
value: string | number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type SelectProps = NativeSelectProps & {
|
|
16
|
-
options: Array<Option>
|
|
17
|
-
styles?: StylesOf<SelectComposition>
|
|
18
|
-
label?: string | ReactNode
|
|
19
|
-
wrapperProps?: ViewProps<'div'>
|
|
20
|
-
onValueChange?: (value: string | number) => void
|
|
21
|
-
} & ComponentVariants<typeof SelectStyles>;
|
|
22
|
-
|
|
23
|
-
export const Select = (selectProps:SelectProps) => {
|
|
24
|
-
const {
|
|
25
|
-
variants = [],
|
|
26
|
-
responsiveVariants = {},
|
|
27
|
-
options,
|
|
28
|
-
styles,
|
|
29
|
-
label,
|
|
30
|
-
onValueChange,
|
|
31
|
-
wrapperProps,
|
|
32
|
-
value,
|
|
33
|
-
...props
|
|
34
|
-
} = selectProps;
|
|
35
|
-
|
|
36
|
-
const variantStyles = useComponentStyle('Select', {
|
|
37
|
-
responsiveVariants,
|
|
38
|
-
variants,
|
|
39
|
-
styles,
|
|
40
|
-
})
|
|
41
|
-
function handleChange(e){
|
|
42
|
-
props.onChange && props.onChange(e)
|
|
43
|
-
onValueChange && onValueChange(e.target.value)
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
return (
|
|
47
|
-
<View css={variantStyles.wrapper} {...wrapperProps}>
|
|
48
|
-
{label ? (
|
|
49
|
-
typeof label === 'string' ? <Text css={variantStyles.label} text={label}/> : label
|
|
50
|
-
) : null}
|
|
51
|
-
<View component='select' css={variantStyles.select} {...props} onChange={handleChange}>
|
|
52
|
-
{options.map((option, index) => (
|
|
53
|
-
<option value={option.value} key={index} selected={value == option.value}>
|
|
54
|
-
{option.label}
|
|
55
|
-
</option>
|
|
56
|
-
))}
|
|
57
|
-
</View>
|
|
58
|
-
</View>
|
|
59
|
-
)
|
|
60
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import RCSlider, {SliderProps as RCSliderProps} from 'rc-slider'
|
|
2
|
-
|
|
3
|
-
type SliderProps = RCSliderProps & {
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export const Slider:React.FC<SliderProps> = (sliderProps) => {
|
|
8
|
-
const {
|
|
9
|
-
|
|
10
|
-
...props
|
|
11
|
-
} = sliderProps
|
|
12
|
-
|
|
13
|
-
return <RCSlider {...props} />
|
|
14
|
-
}
|
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,223 +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 [focused, 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
|
-
...(focused ? variantStyles['icon:focus'] : {} ),
|
|
136
|
-
...variantStyles.leftIcon,
|
|
137
|
-
...(showError ? variantStyles['leftIcon:error'] : {} ),
|
|
138
|
-
...(focused ? variantStyles['leftIcon:focus'] : {}),
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const rightIconStyle = {
|
|
142
|
-
...variantStyles.icon,
|
|
143
|
-
...(focused ? variantStyles['icon:focus'] : {}),
|
|
144
|
-
...(showError ? variantStyles['icon:error'] : {} ),
|
|
145
|
-
...variantStyles.rightIcon,
|
|
146
|
-
...(showError ? variantStyles['rightIcon:error'] : {} ),
|
|
147
|
-
...(focused ? variantStyles['rightIcon:focus'] : {}),
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return (
|
|
151
|
-
<View
|
|
152
|
-
css={[variantStyles.wrapper, focused && variantStyles['wrapper:focus'], showError && variantStyles['wrapper:error']]}
|
|
153
|
-
>
|
|
154
|
-
<InputLabel label={label} style={variantStyles.label}/>
|
|
155
|
-
|
|
156
|
-
<View css={[variantStyles.innerWrapper, focused && variantStyles['innerWrapper:focus'], showError && variantStyles['innerWrapper:error']]}>
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
<InputIcon {...leftIcon} style={leftIconStyle}/>
|
|
160
|
-
<InputElement
|
|
161
|
-
ref={input}
|
|
162
|
-
type={visibilityToggle ? inputVisibilityType : inputType}
|
|
163
|
-
onChange={handleChange}
|
|
164
|
-
value={value}
|
|
165
|
-
disabled={disabled}
|
|
166
|
-
onFocus={handleFocus}
|
|
167
|
-
onBlur={handleBlur}
|
|
168
|
-
rows={4}
|
|
169
|
-
{...props}
|
|
170
|
-
css={[variantStyles.textField, focused && variantStyles['textField:focus'], showError && variantStyles['textField:error']]}
|
|
171
|
-
/>
|
|
172
|
-
{
|
|
173
|
-
visibilityToggle ?
|
|
174
|
-
<InputIcon name={
|
|
175
|
-
(textIsVisible ? 'input-visiblity:visible' : 'input-visiblity:hidden') as IconPlaceholder
|
|
176
|
-
} action={() => setTextVisible()} style={rightIconStyle}/>
|
|
177
|
-
:
|
|
178
|
-
<InputIcon {...rightIcon} style={rightIconStyle}/>
|
|
179
|
-
}
|
|
180
|
-
</View>
|
|
181
|
-
|
|
182
|
-
<FormError message={error.message} css={{
|
|
183
|
-
...variantStyles.error,
|
|
184
|
-
|
|
185
|
-
}}/>
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
</View>
|
|
189
|
-
)
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
const FormError = ({message, ...props}) => {
|
|
193
|
-
|
|
194
|
-
if (['number', 'string', 'undefined'].includes(typeof message)){
|
|
195
|
-
return <Text text={`${message||' '}`} variants={['p2', 'marginTop:1']} {...props}/>
|
|
196
|
-
}
|
|
197
|
-
return message
|
|
198
|
-
}
|
|
199
|
-
export const InputIcon:React.FC<{style:any} & IconProp> = ({name, style, action}) => {
|
|
200
|
-
if (!name) return null
|
|
201
|
-
|
|
202
|
-
if (action){
|
|
203
|
-
|
|
204
|
-
return <Button icon={name} onPress={() => action()} styles={{
|
|
205
|
-
icon: style,
|
|
206
|
-
}} variants={['icon']}/>
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return <Icon name={name} style={style}/>
|
|
210
|
-
}
|
|
211
|
-
export const InputLabel = ({label, style}) => {
|
|
212
|
-
if (!label) return null
|
|
213
|
-
|
|
214
|
-
switch (typeof label){
|
|
215
|
-
case 'string':
|
|
216
|
-
return <Text css={style} text={label} component={'label'}/>
|
|
217
|
-
case 'object':
|
|
218
|
-
|
|
219
|
-
return label
|
|
220
|
-
default:
|
|
221
|
-
return null
|
|
222
|
-
}
|
|
223
|
-
}
|
|
@@ -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