@codeleap/web 1.0.0
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/.eslintignore +2 -0
- package/.eslintrc.js +3 -0
- package/.turbo/turbo-build.log +1 -0
- package/dist/components/ActivityIndicator/index.d.ts +12 -0
- package/dist/components/ActivityIndicator/index.js +60 -0
- package/dist/components/ActivityIndicator/index.js.map +1 -0
- package/dist/components/ActivityIndicator/styles.d.ts +42 -0
- package/dist/components/ActivityIndicator/styles.js +22 -0
- package/dist/components/ActivityIndicator/styles.js.map +1 -0
- package/dist/components/Button.d.ts +15 -0
- package/dist/components/Button.js +48 -0
- package/dist/components/Button.js.map +1 -0
- package/dist/components/CenterWrapper.d.ts +7 -0
- package/dist/components/CenterWrapper.js +28 -0
- package/dist/components/CenterWrapper.js.map +1 -0
- package/dist/components/Checkbox.d.ts +11 -0
- package/dist/components/Checkbox.js +46 -0
- package/dist/components/Checkbox.js.map +1 -0
- package/dist/components/ContentView.d.ts +10 -0
- package/dist/components/ContentView.js +52 -0
- package/dist/components/ContentView.js.map +1 -0
- package/dist/components/Drawer.d.ts +23 -0
- package/dist/components/Drawer.js +66 -0
- package/dist/components/Drawer.js.map +1 -0
- package/dist/components/FileInput.d.ts +8 -0
- package/dist/components/FileInput.js +69 -0
- package/dist/components/FileInput.js.map +1 -0
- package/dist/components/FlatList.d.ts +18 -0
- package/dist/components/FlatList.js +52 -0
- package/dist/components/FlatList.js.map +1 -0
- package/dist/components/HorizontalScroll.d.ts +3 -0
- package/dist/components/HorizontalScroll.js +42 -0
- package/dist/components/HorizontalScroll.js.map +1 -0
- package/dist/components/Icon.d.ts +12 -0
- package/dist/components/Icon.js +21 -0
- package/dist/components/Icon.js.map +1 -0
- package/dist/components/Link.d.ts +6 -0
- package/dist/components/Link.js +66 -0
- package/dist/components/Link.js.map +1 -0
- package/dist/components/Modal/index.d.ts +19 -0
- package/dist/components/Modal/index.js +111 -0
- package/dist/components/Modal/index.js.map +1 -0
- package/dist/components/Modal/styles.d.ts +44 -0
- package/dist/components/Modal/styles.js +33 -0
- package/dist/components/Modal/styles.js.map +1 -0
- package/dist/components/Overlay.d.ts +10 -0
- package/dist/components/Overlay.js +41 -0
- package/dist/components/Overlay.js.map +1 -0
- package/dist/components/PageRouter/Menu.d.ts +10 -0
- package/dist/components/PageRouter/Menu.js +36 -0
- package/dist/components/PageRouter/Menu.js.map +1 -0
- package/dist/components/PageRouter/MenuItem.d.ts +11 -0
- package/dist/components/PageRouter/MenuItem.js +42 -0
- package/dist/components/PageRouter/MenuItem.js.map +1 -0
- package/dist/components/PageRouter/Router.d.ts +8 -0
- package/dist/components/PageRouter/Router.js +27 -0
- package/dist/components/PageRouter/Router.js.map +1 -0
- package/dist/components/PageRouter/index.d.ts +15 -0
- package/dist/components/PageRouter/index.js +76 -0
- package/dist/components/PageRouter/index.js.map +1 -0
- package/dist/components/RadioInput/index.d.ts +62 -0
- package/dist/components/RadioInput/index.js +53 -0
- package/dist/components/RadioInput/index.js.map +1 -0
- package/dist/components/RadioInput/styles.d.ts +43 -0
- package/dist/components/RadioInput/styles.js +44 -0
- package/dist/components/RadioInput/styles.js.map +1 -0
- package/dist/components/Select.d.ts +17 -0
- package/dist/components/Select.js +44 -0
- package/dist/components/Select.js.map +1 -0
- package/dist/components/Slider.d.ts +5 -0
- package/dist/components/Slider.js +36 -0
- package/dist/components/Slider.js.map +1 -0
- package/dist/components/Text.d.ts +9 -0
- package/dist/components/Text.js +39 -0
- package/dist/components/Text.js.map +1 -0
- package/dist/components/TextInput.d.ts +122 -0
- package/dist/components/TextInput.js +125 -0
- package/dist/components/TextInput.js.map +1 -0
- package/dist/components/Tooltip-old.d.ts +11 -0
- package/dist/components/Tooltip-old.js +151 -0
- package/dist/components/Tooltip-old.js.map +1 -0
- package/dist/components/Tooltip.d.ts +12 -0
- package/dist/components/Tooltip.js +124 -0
- package/dist/components/Tooltip.js.map +1 -0
- package/dist/components/Touchable.d.ts +12 -0
- package/dist/components/Touchable.js +48 -0
- package/dist/components/Touchable.js.map +1 -0
- package/dist/components/View.d.ts +9 -0
- package/dist/components/View.js +47 -0
- package/dist/components/View.js.map +1 -0
- package/dist/components/index.d.ts +22 -0
- package/dist/components/index.js +35 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/router/Menu.d.ts +10 -0
- package/dist/components/router/Menu.js +39 -0
- package/dist/components/router/Menu.js.map +1 -0
- package/dist/components/router/MenuItem.d.ts +11 -0
- package/dist/components/router/MenuItem.js +42 -0
- package/dist/components/router/MenuItem.js.map +1 -0
- package/dist/components/router/Router.d.ts +8 -0
- package/dist/components/router/Router.js +28 -0
- package/dist/components/router/Router.js.map +1 -0
- package/dist/components/router/index.d.ts +14 -0
- package/dist/components/router/index.js +69 -0
- package/dist/components/router/index.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/hooks.d.ts +8 -0
- package/dist/lib/hooks.js +49 -0
- package/dist/lib/hooks.js.map +1 -0
- package/dist/lib/logger.d.ts +2 -0
- package/dist/lib/logger.js +16 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/utils/cookies.d.ts +6 -0
- package/dist/lib/utils/cookies.js +15 -0
- package/dist/lib/utils/cookies.js.map +1 -0
- package/dist/lib/utils/index.d.ts +4 -0
- package/dist/lib/utils/index.js +23 -0
- package/dist/lib/utils/index.js.map +1 -0
- package/dist/lib/utils/pollyfils/scroll.d.ts +1 -0
- package/dist/lib/utils/pollyfils/scroll.js +58 -0
- package/dist/lib/utils/pollyfils/scroll.js.map +1 -0
- package/dist/lib/utils/stopPropagation.d.ts +1 -0
- package/dist/lib/utils/stopPropagation.js +21 -0
- package/dist/lib/utils/stopPropagation.js.map +1 -0
- package/dist/types/utility.d.ts +2 -0
- package/dist/types/utility.js +3 -0
- package/dist/types/utility.js.map +1 -0
- package/package.json +38 -0
- package/src/components/ActivityIndicator/index.tsx +55 -0
- package/src/components/ActivityIndicator/styles.ts +18 -0
- package/src/components/Button.tsx +67 -0
- package/src/components/CenterWrapper.tsx +24 -0
- package/src/components/Checkbox.tsx +46 -0
- package/src/components/ContentView.tsx +48 -0
- package/src/components/Drawer.tsx +114 -0
- package/src/components/FileInput.tsx +48 -0
- package/src/components/FlatList.tsx +77 -0
- package/src/components/HorizontalScroll.tsx +24 -0
- package/src/components/Icon.tsx +26 -0
- package/src/components/Link.tsx +51 -0
- package/src/components/Modal/index.tsx +150 -0
- package/src/components/Modal/styles.ts +49 -0
- package/src/components/Overlay.tsx +25 -0
- package/src/components/PageRouter/Menu.tsx +49 -0
- package/src/components/PageRouter/MenuItem.tsx +55 -0
- package/src/components/PageRouter/Router.tsx +23 -0
- package/src/components/PageRouter/index.tsx +81 -0
- package/src/components/RadioInput/index.tsx +72 -0
- package/src/components/RadioInput/styles.ts +57 -0
- package/src/components/Select.tsx +60 -0
- package/src/components/Slider.tsx +14 -0
- package/src/components/Text.tsx +27 -0
- package/src/components/TextInput.tsx +219 -0
- package/src/components/Tooltip.tsx +138 -0
- package/src/components/Touchable.tsx +47 -0
- package/src/components/View.tsx +54 -0
- package/src/components/index.ts +23 -0
- package/src/index.ts +4 -0
- package/src/lib/hooks.ts +42 -0
- package/src/lib/logger.ts +15 -0
- package/src/lib/utils/cookies.ts +19 -0
- package/src/lib/utils/index.ts +4 -0
- package/src/lib/utils/pollyfils/scroll.ts +59 -0
- package/src/lib/utils/stopPropagation.ts +17 -0
- package/src/types/utility.ts +4 -0
- package/tsconfig.json +42 -0
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
|
@@ -0,0 +1,23 @@
|
|
|
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
ADDED
package/src/lib/hooks.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
}
|