@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,148 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AnyFunction,
|
|
3
|
+
ComponentVariants,
|
|
4
|
+
IconPlaceholder,
|
|
5
|
+
onUpdate,
|
|
6
|
+
useDefaultComponentStyle,
|
|
7
|
+
} from '@codeleap/common'
|
|
8
|
+
import { CSSObject } from '@emotion/react'
|
|
9
|
+
import React, { ReactNode } from 'react'
|
|
10
|
+
import { Overlay } from '../Overlay'
|
|
11
|
+
import { View } from '../View'
|
|
12
|
+
import { Text } from '../Text'
|
|
13
|
+
import { Button } from '../Button'
|
|
14
|
+
import { StylesOf } from '../../types/utility'
|
|
15
|
+
import { DrawerComposition, DrawerPresets } from './styles'
|
|
16
|
+
|
|
17
|
+
const axisMap = {
|
|
18
|
+
top: [-1, 'Y'],
|
|
19
|
+
bottom: [1, 'Y'],
|
|
20
|
+
left: [-1, 'X'],
|
|
21
|
+
right: [1, 'X'],
|
|
22
|
+
} as const
|
|
23
|
+
|
|
24
|
+
export type DrawerProps = React.PropsWithChildren<{
|
|
25
|
+
open: boolean
|
|
26
|
+
toggle: AnyFunction
|
|
27
|
+
darkenBackground?: boolean
|
|
28
|
+
size: string | number
|
|
29
|
+
showCloseButton?: boolean
|
|
30
|
+
title?: ReactNode
|
|
31
|
+
footer?: ReactNode
|
|
32
|
+
position?: keyof typeof axisMap
|
|
33
|
+
styles?: StylesOf<DrawerComposition>
|
|
34
|
+
animationDuration?: string
|
|
35
|
+
} & ComponentVariants<typeof DrawerPresets>
|
|
36
|
+
>
|
|
37
|
+
const resolveHiddenDrawerPosition = (
|
|
38
|
+
position: DrawerProps['position'],
|
|
39
|
+
): [string, string, CSSObject] => {
|
|
40
|
+
const [translateOrient, translateAxis] = axisMap[position]
|
|
41
|
+
|
|
42
|
+
const translateValues = {
|
|
43
|
+
X: 0,
|
|
44
|
+
Y: 0,
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
translateValues[translateAxis] = 100 * translateOrient
|
|
48
|
+
|
|
49
|
+
const css = `translate(${translateValues.X}%, ${translateValues.Y}%)`
|
|
50
|
+
const positioningKeys =
|
|
51
|
+
translateAxis === 'X' ? ['top', 'bottom'] : ['left', 'right']
|
|
52
|
+
|
|
53
|
+
const positioning = Object.fromEntries(positioningKeys.map((k) => [k, 0]))
|
|
54
|
+
return [css, translateAxis, positioning]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const Drawer: React.FC<DrawerProps> = ({ ...rawProps }) => {
|
|
58
|
+
const {
|
|
59
|
+
open,
|
|
60
|
+
toggle,
|
|
61
|
+
children,
|
|
62
|
+
size,
|
|
63
|
+
title,
|
|
64
|
+
footer,
|
|
65
|
+
darkenBackground = true,
|
|
66
|
+
showCloseButton,
|
|
67
|
+
position = 'bottom',
|
|
68
|
+
variants = [],
|
|
69
|
+
responsiveVariants = {},
|
|
70
|
+
styles,
|
|
71
|
+
animationDuration = '0.3s',
|
|
72
|
+
} = rawProps
|
|
73
|
+
|
|
74
|
+
onUpdate(() => {
|
|
75
|
+
if (open) {
|
|
76
|
+
document.body.style.overflow = 'hidden'
|
|
77
|
+
} else {
|
|
78
|
+
document.body.style.overflow = 'auto'
|
|
79
|
+
}
|
|
80
|
+
}, [open])
|
|
81
|
+
|
|
82
|
+
const [hiddenStyle, axis, positioning] =
|
|
83
|
+
resolveHiddenDrawerPosition(position)
|
|
84
|
+
|
|
85
|
+
const sizeProperty = axis === 'X' ? 'width' : 'height'
|
|
86
|
+
const fullProperty = sizeProperty === 'height' ? 'width' : 'height'
|
|
87
|
+
|
|
88
|
+
const variantStyles = useDefaultComponentStyle('Drawer', {
|
|
89
|
+
styles,
|
|
90
|
+
variants,
|
|
91
|
+
responsiveVariants,
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<View
|
|
96
|
+
css={{
|
|
97
|
+
...variantStyles.wrapper,
|
|
98
|
+
transition: 'visibility 0.01s ease',
|
|
99
|
+
transitionDelay: open ? '0' : animationDuration,
|
|
100
|
+
visibility: open ? 'visible' : 'hidden',
|
|
101
|
+
}}
|
|
102
|
+
>
|
|
103
|
+
{darkenBackground && (
|
|
104
|
+
<Overlay
|
|
105
|
+
visible={open}
|
|
106
|
+
css={variantStyles.overlay}
|
|
107
|
+
onPress={() => toggle()}
|
|
108
|
+
/>
|
|
109
|
+
)}
|
|
110
|
+
<View
|
|
111
|
+
variants={['fixed']}
|
|
112
|
+
css={{
|
|
113
|
+
transform: open ? `translate(0%, 0%)` : hiddenStyle,
|
|
114
|
+
transition: `transform ${animationDuration} ease`,
|
|
115
|
+
[sizeProperty]: size,
|
|
116
|
+
[fullProperty]: '100%',
|
|
117
|
+
...positioning,
|
|
118
|
+
[position]: 0,
|
|
119
|
+
...variantStyles.box,
|
|
120
|
+
}}
|
|
121
|
+
>
|
|
122
|
+
<View
|
|
123
|
+
component='header'
|
|
124
|
+
variants={['justifySpaceBetween']}
|
|
125
|
+
css={variantStyles.header}
|
|
126
|
+
>
|
|
127
|
+
{typeof title === 'string' ? <Text text={title} /> : title}
|
|
128
|
+
{showCloseButton && (
|
|
129
|
+
<Button
|
|
130
|
+
onPress={toggle}
|
|
131
|
+
icon={'close' as IconPlaceholder}
|
|
132
|
+
variants={['icon']}
|
|
133
|
+
css={variantStyles.headerCloseButton}
|
|
134
|
+
/>
|
|
135
|
+
)}
|
|
136
|
+
</View>
|
|
137
|
+
<View css={variantStyles.body}>{children}</View>
|
|
138
|
+
{footer && (
|
|
139
|
+
<View component='footer' css={variantStyles.footer}>
|
|
140
|
+
{footer}
|
|
141
|
+
</View>
|
|
142
|
+
)}
|
|
143
|
+
</View>
|
|
144
|
+
</View>
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export * from './styles'
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createDefaultVariantFactory, includePresets } from "@codeleap/common";
|
|
2
|
+
import { ModalComposition } from "../Modal";
|
|
3
|
+
|
|
4
|
+
export type DrawerComposition = ModalComposition
|
|
5
|
+
|
|
6
|
+
const createDrawerStyle = createDefaultVariantFactory<DrawerComposition>()
|
|
7
|
+
|
|
8
|
+
export const DrawerPresets = includePresets((styles) => createDrawerStyle(() => ({ wrapper: styles })))
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
ComponentPropsWithoutRef,
|
|
3
|
+
useImperativeHandle,
|
|
4
|
+
useRef,
|
|
5
|
+
} from 'react'
|
|
6
|
+
import { WebInputFile } from '@codeleap/common'
|
|
7
|
+
|
|
8
|
+
export type FileInputRef = {
|
|
9
|
+
openFilePicker: () => void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type FileInputProps = Omit<ComponentPropsWithoutRef<'input'>, 'type'> & {
|
|
13
|
+
onFileSelect(files: WebInputFile[]): void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const FileInput = React.forwardRef<FileInputRef, FileInputProps>(
|
|
17
|
+
(inputProps, ref) => {
|
|
18
|
+
const inputRef = useRef<HTMLInputElement>(null)
|
|
19
|
+
|
|
20
|
+
const { onFileSelect, ...props } = inputProps
|
|
21
|
+
|
|
22
|
+
useImperativeHandle(ref, () => ({
|
|
23
|
+
openFilePicker: () => {
|
|
24
|
+
inputRef.current.click()
|
|
25
|
+
},
|
|
26
|
+
}))
|
|
27
|
+
|
|
28
|
+
function handleChange(e: React.ChangeEvent<HTMLInputElement>) {
|
|
29
|
+
if (!e.target.files.length) return
|
|
30
|
+
inputProps.onChange && inputProps.onChange(e)
|
|
31
|
+
const fileArray = Array.from(e.target?.files || []) as File[]
|
|
32
|
+
|
|
33
|
+
const files: WebInputFile[] = fileArray.map((obj) => ({
|
|
34
|
+
file: obj,
|
|
35
|
+
preview: URL.createObjectURL(obj),
|
|
36
|
+
}))
|
|
37
|
+
|
|
38
|
+
onFileSelect && onFileSelect(files)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<input
|
|
43
|
+
type={'file'}
|
|
44
|
+
css={{ visibility: 'hidden', width: 0, height: 0, opacity: 0, display: 'none' }}
|
|
45
|
+
{...props}
|
|
46
|
+
ref={inputRef}
|
|
47
|
+
onChange={handleChange}
|
|
48
|
+
/>
|
|
49
|
+
)
|
|
50
|
+
},
|
|
51
|
+
)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
/** @jsx jsx */
|
|
3
|
+
import { CSSObject, jsx } from '@emotion/react'
|
|
4
|
+
import {
|
|
5
|
+
ComponentVariants,
|
|
6
|
+
IconPlaceholder,
|
|
7
|
+
IconStyles,
|
|
8
|
+
useDefaultComponentStyle,
|
|
9
|
+
useCodeleapContext,
|
|
10
|
+
} from '@codeleap/common'
|
|
11
|
+
import { View, ViewProps } from '../View'
|
|
12
|
+
import { CSSInterpolation } from '@emotion/css'
|
|
13
|
+
|
|
14
|
+
export * from './styles'
|
|
15
|
+
|
|
16
|
+
export type IconProps = {
|
|
17
|
+
name: IconPlaceholder
|
|
18
|
+
style?: any
|
|
19
|
+
renderEmptySpace?: boolean
|
|
20
|
+
css?: Array<React.CSSProperties>
|
|
21
|
+
forceStyle?: CSSObject | CSSInterpolation | React.CSSProperties
|
|
22
|
+
} & ComponentVariants<typeof IconStyles>
|
|
23
|
+
|
|
24
|
+
export const Icon: React.FC<IconProps> = ({ name, style, variants, renderEmptySpace, ...otherProps }) => {
|
|
25
|
+
const { Theme, logger } = useCodeleapContext()
|
|
26
|
+
const Component = Theme?.icons?.[name]
|
|
27
|
+
|
|
28
|
+
const variantStyles = useDefaultComponentStyle('Icon', {
|
|
29
|
+
variants,
|
|
30
|
+
styles: {
|
|
31
|
+
icon: style,
|
|
32
|
+
},
|
|
33
|
+
rootElement: 'icon',
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
if (!name) {
|
|
37
|
+
const iconStyle = variantStyles.icon
|
|
38
|
+
return renderEmptySpace ? <View css={{
|
|
39
|
+
height: iconStyle.size ?? iconStyle.height,
|
|
40
|
+
width: iconStyle.size ?? iconStyle.width,
|
|
41
|
+
}}/> : null
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!Component) {
|
|
45
|
+
logger.warn(
|
|
46
|
+
`Icon: No icon found in theme for name "${name}".`,
|
|
47
|
+
{ props: { style, name, variants, variantStyles }},
|
|
48
|
+
'Component',
|
|
49
|
+
)
|
|
50
|
+
return null
|
|
51
|
+
}
|
|
52
|
+
return <Component css={variantStyles.icon} {...otherProps}/>
|
|
53
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createDefaultVariantFactory, includePresets } from "@codeleap/common"
|
|
2
|
+
|
|
3
|
+
export type IconComposition = 'icon'
|
|
4
|
+
|
|
5
|
+
const createIconStyle = createDefaultVariantFactory<IconComposition>()
|
|
6
|
+
|
|
7
|
+
export const IconPresets = includePresets((styles) =>
|
|
8
|
+
createIconStyle(() => ({ icon: styles }))
|
|
9
|
+
)
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { TypeGuards, getRenderedComponent } from '@codeleap/common'
|
|
3
|
+
import { ActionIcon, ActionIconProps } from '../ActionIcon'
|
|
4
|
+
import { View } from '../View'
|
|
5
|
+
import { useInputBaseStyles } from './styles'
|
|
6
|
+
import { InputBaseProps } from './types'
|
|
7
|
+
import { Text } from '../Text'
|
|
8
|
+
|
|
9
|
+
export * from './styles'
|
|
10
|
+
export * from './utils'
|
|
11
|
+
export * from './types'
|
|
12
|
+
|
|
13
|
+
export const InputBaseDefaultOrder:InputBaseProps['order'] = [
|
|
14
|
+
'label',
|
|
15
|
+
'description',
|
|
16
|
+
'innerWrapper',
|
|
17
|
+
'error',
|
|
18
|
+
]
|
|
19
|
+
const KeyPassthrough = (props: React.PropsWithChildren<any>) => {
|
|
20
|
+
return <>{props.children}</>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const InputBase = React.forwardRef<unknown, InputBaseProps>((props, ref) => {
|
|
24
|
+
const {
|
|
25
|
+
children,
|
|
26
|
+
error = null,
|
|
27
|
+
label,
|
|
28
|
+
description = null,
|
|
29
|
+
leftIcon = null,
|
|
30
|
+
rightIcon = null,
|
|
31
|
+
styles,
|
|
32
|
+
wrapper,
|
|
33
|
+
debugName,
|
|
34
|
+
innerWrapper,
|
|
35
|
+
focused,
|
|
36
|
+
innerWrapperProps = {},
|
|
37
|
+
wrapperProps = {},
|
|
38
|
+
disabled = false,
|
|
39
|
+
order = InputBaseDefaultOrder,
|
|
40
|
+
style,
|
|
41
|
+
labelAsRow = false,
|
|
42
|
+
innerWrapperRef,
|
|
43
|
+
...otherProps
|
|
44
|
+
} = props
|
|
45
|
+
|
|
46
|
+
const WrapperComponent = wrapper || View
|
|
47
|
+
const InnerWrapperComponent = innerWrapper || View
|
|
48
|
+
|
|
49
|
+
const _styles = useInputBaseStyles(props)
|
|
50
|
+
|
|
51
|
+
const _leftIcon = getRenderedComponent<Partial<ActionIconProps>>(leftIcon, ActionIcon, {
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
styles: _styles.leftIconStyles,
|
|
54
|
+
disabled,
|
|
55
|
+
debugName: `${debugName} left icon`,
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const _rightIcon = getRenderedComponent<Partial<ActionIconProps>>(rightIcon, ActionIcon, {
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
styles: _styles.rightIconStyles,
|
|
61
|
+
disabled,
|
|
62
|
+
debugName: `${debugName} right icon`,
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const _label = TypeGuards.isString(label) ? <Text text={label} css={_styles.labelStyle}/> : label
|
|
66
|
+
|
|
67
|
+
const _error = TypeGuards.isString(error) ? <Text text={error} css={_styles.errorStyle}/> : error
|
|
68
|
+
|
|
69
|
+
const _description = TypeGuards.isString(description) ? <Text text={description} css={_styles.descriptionStyle}/> : description
|
|
70
|
+
|
|
71
|
+
const parts = {
|
|
72
|
+
label: labelAsRow ? <View css={_styles.labelRowStyle}>
|
|
73
|
+
{_label}
|
|
74
|
+
{_description}
|
|
75
|
+
</View> : _label,
|
|
76
|
+
description: labelAsRow ? null : _description,
|
|
77
|
+
innerWrapper: <InnerWrapperComponent ref={innerWrapperRef} css={[
|
|
78
|
+
_styles.innerWrapperStyle,
|
|
79
|
+
]} {...innerWrapperProps}>
|
|
80
|
+
{_leftIcon}
|
|
81
|
+
{children}
|
|
82
|
+
{_rightIcon}
|
|
83
|
+
</InnerWrapperComponent>,
|
|
84
|
+
error: _error || <Text children={<>
|
|
85
|
+
|
|
86
|
+
</>} css={_styles.errorStyle}/>,
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<WrapperComponent
|
|
91
|
+
css={[_styles.wrapperStyle, style]}
|
|
92
|
+
{...otherProps}
|
|
93
|
+
{...wrapperProps}
|
|
94
|
+
>
|
|
95
|
+
{
|
|
96
|
+
order.map((key) => (
|
|
97
|
+
<KeyPassthrough key={key}>
|
|
98
|
+
{parts[key]}
|
|
99
|
+
</KeyPassthrough>
|
|
100
|
+
))
|
|
101
|
+
}
|
|
102
|
+
</WrapperComponent>
|
|
103
|
+
)
|
|
104
|
+
})
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { TypeGuards, createDefaultVariantFactory, getRenderedComponent, includePresets, useDefaultComponentStyle, useMemo, useNestedStylesByKey } from '@codeleap/common'
|
|
2
|
+
import { ActionIconComposition, ActionIconParts } from '../ActionIcon'
|
|
3
|
+
import { InputBaseProps } from './types'
|
|
4
|
+
|
|
5
|
+
type InputIcons = 'icon' | 'leftIcon' | 'rightIcon'
|
|
6
|
+
|
|
7
|
+
type IconParts = ActionIconParts
|
|
8
|
+
|
|
9
|
+
export type InputIconComposition = `${InputIcons}${Capitalize<IconParts>}`
|
|
10
|
+
|
|
11
|
+
export type InputBaseStates = 'error' | 'focus' | 'disabled'
|
|
12
|
+
|
|
13
|
+
export type InputBaseParts =
|
|
14
|
+
'wrapper' |
|
|
15
|
+
'innerWrapper' |
|
|
16
|
+
'label' |
|
|
17
|
+
'errorMessage' |
|
|
18
|
+
'description' |
|
|
19
|
+
'labelRow'|
|
|
20
|
+
InputIconComposition
|
|
21
|
+
|
|
22
|
+
export type IconLessInputBaseParts = Exclude<InputBaseParts, InputIconComposition>
|
|
23
|
+
|
|
24
|
+
export type InputBaseComposition = `${InputBaseParts}:${InputBaseStates}` | InputBaseParts
|
|
25
|
+
|
|
26
|
+
const createTextInputBaseComposition = createDefaultVariantFactory<InputBaseComposition>()
|
|
27
|
+
|
|
28
|
+
export const InputBasePresets = includePresets((styles) => createTextInputBaseComposition(() => ({ wrapper: styles })))
|
|
29
|
+
|
|
30
|
+
const getIconStyles = (obj, state) => {
|
|
31
|
+
return {
|
|
32
|
+
icon: {
|
|
33
|
+
...obj.icon,
|
|
34
|
+
...(state.focused && obj['icon:focus']),
|
|
35
|
+
...(state.hasError && obj['icon:error']),
|
|
36
|
+
...(state.disabled && obj['icon:disabled']),
|
|
37
|
+
},
|
|
38
|
+
wrapper: {
|
|
39
|
+
...obj.touchableWrapper,
|
|
40
|
+
...(state.focused && obj['touchableWrapper:focus']),
|
|
41
|
+
...(state.hasError && obj['touchableWrapper:error']),
|
|
42
|
+
...(state.disabled && obj['touchableWrapper:disabled']),
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function concatStyles(unstyles: Record<number, {}> = {}) {
|
|
48
|
+
let styles = {}
|
|
49
|
+
|
|
50
|
+
Object.values(unstyles || {}).forEach(style => {
|
|
51
|
+
if (style) {
|
|
52
|
+
styles = {
|
|
53
|
+
...styles,
|
|
54
|
+
...style,
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
return styles
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const useInputBaseStyles = (props: InputBaseProps) => {
|
|
63
|
+
const {
|
|
64
|
+
focused,
|
|
65
|
+
disabled,
|
|
66
|
+
error,
|
|
67
|
+
styles,
|
|
68
|
+
} = props
|
|
69
|
+
|
|
70
|
+
const hasError = !TypeGuards.isNil(error)
|
|
71
|
+
|
|
72
|
+
const variantStyles = useDefaultComponentStyle<'u:InputBase', typeof InputBasePresets>('u:InputBase', {
|
|
73
|
+
rootElement: 'wrapper',
|
|
74
|
+
styles,
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
const _leftIconStyles = useNestedStylesByKey<ActionIconComposition>('leftIcon', variantStyles)
|
|
78
|
+
const _rightIconStyles = useNestedStylesByKey<ActionIconComposition>('rightIcon', variantStyles)
|
|
79
|
+
const _generalIconStyles = useNestedStylesByKey<ActionIconComposition>('icon', variantStyles)
|
|
80
|
+
|
|
81
|
+
const generalIconStyles = getIconStyles(_generalIconStyles, { hasError, disabled, focused })
|
|
82
|
+
const leftIconStylesCompose = getIconStyles(_leftIconStyles, {
|
|
83
|
+
hasError,
|
|
84
|
+
disabled: disabled || props?.leftIcon?.disabled,
|
|
85
|
+
focused
|
|
86
|
+
})
|
|
87
|
+
const rightIconStylesCompose = getIconStyles(_rightIconStyles, {
|
|
88
|
+
hasError,
|
|
89
|
+
disabled: disabled || props?.rightIcon?.disabled,
|
|
90
|
+
focused
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
const leftIconStyles = {
|
|
94
|
+
icon: {
|
|
95
|
+
...generalIconStyles.icon,
|
|
96
|
+
...leftIconStylesCompose.icon,
|
|
97
|
+
},
|
|
98
|
+
wrapper: {
|
|
99
|
+
...generalIconStyles.wrapper,
|
|
100
|
+
...leftIconStylesCompose.wrapper,
|
|
101
|
+
},
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const rightIconStyles = {
|
|
105
|
+
icon: {
|
|
106
|
+
...generalIconStyles.icon,
|
|
107
|
+
...rightIconStylesCompose.icon,
|
|
108
|
+
},
|
|
109
|
+
wrapper: {
|
|
110
|
+
...generalIconStyles.wrapper,
|
|
111
|
+
...rightIconStylesCompose.wrapper,
|
|
112
|
+
},
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const labelStyle = [
|
|
116
|
+
variantStyles.label,
|
|
117
|
+
focused && variantStyles['label:focus'],
|
|
118
|
+
hasError && variantStyles['label:error'],
|
|
119
|
+
disabled && variantStyles['label:disabled'],
|
|
120
|
+
]
|
|
121
|
+
|
|
122
|
+
const errorStyle = [
|
|
123
|
+
variantStyles.errorMessage,
|
|
124
|
+
focused && variantStyles['errorMessage:focus'],
|
|
125
|
+
hasError && variantStyles['errorMessage:error'],
|
|
126
|
+
disabled && variantStyles['errorMessage:disabled'],
|
|
127
|
+
]
|
|
128
|
+
|
|
129
|
+
const descriptionStyle = [
|
|
130
|
+
variantStyles.description,
|
|
131
|
+
focused && variantStyles['description:focus'],
|
|
132
|
+
hasError && variantStyles['description:error'],
|
|
133
|
+
disabled && variantStyles['description:disabled'],
|
|
134
|
+
]
|
|
135
|
+
|
|
136
|
+
const wrapperStyle = [
|
|
137
|
+
variantStyles.wrapper,
|
|
138
|
+
focused && variantStyles['wrapper:focus'],
|
|
139
|
+
error && variantStyles['wrapper:error'],
|
|
140
|
+
disabled && variantStyles['wrapper:disabled'],
|
|
141
|
+
]
|
|
142
|
+
|
|
143
|
+
const innerWrapperStyle = [
|
|
144
|
+
concatStyles(variantStyles.innerWrapper),
|
|
145
|
+
focused && variantStyles['innerWrapper:focus'],
|
|
146
|
+
hasError && variantStyles['innerWrapper:error'],
|
|
147
|
+
disabled && variantStyles['innerWrapper:disabled'],
|
|
148
|
+
]
|
|
149
|
+
|
|
150
|
+
const labelRowStyle = [
|
|
151
|
+
variantStyles.labelRow,
|
|
152
|
+
focused && variantStyles['labelRow:focus'],
|
|
153
|
+
hasError && variantStyles['labelRow:error'],
|
|
154
|
+
disabled && variantStyles['labelRow:disabled'],
|
|
155
|
+
]
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
wrapperStyle,
|
|
159
|
+
innerWrapperStyle,
|
|
160
|
+
leftIconStyles,
|
|
161
|
+
rightIconStyles,
|
|
162
|
+
labelStyle,
|
|
163
|
+
errorStyle,
|
|
164
|
+
descriptionStyle,
|
|
165
|
+
labelRowStyle,
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PropsOf } from '@codeleap/common'
|
|
2
|
+
import { StylesOf } from '../../types'
|
|
3
|
+
import { InputBaseComposition } from './styles'
|
|
4
|
+
import { ActionIcon } from '../ActionIcon'
|
|
5
|
+
|
|
6
|
+
type ActionIconProps = PropsOf<typeof ActionIcon>
|
|
7
|
+
|
|
8
|
+
type OrderedParts = 'label' | 'description' | 'innerWrapper' | 'error'
|
|
9
|
+
|
|
10
|
+
export type InputBaseProps = React.PropsWithChildren<{
|
|
11
|
+
label?: React.ReactNode
|
|
12
|
+
error?: React.ReactNode
|
|
13
|
+
leftIcon?: ActionIconProps
|
|
14
|
+
rightIcon?: ActionIconProps
|
|
15
|
+
wrapper?: React.FC<any>
|
|
16
|
+
wrapperProps?: any
|
|
17
|
+
innerWrapper?: React.FC<any>
|
|
18
|
+
innerWrapperProps?: any
|
|
19
|
+
styles?: StylesOf<InputBaseComposition>
|
|
20
|
+
description?: React.ReactNode
|
|
21
|
+
debugName: string
|
|
22
|
+
focused?: boolean
|
|
23
|
+
disabled?: boolean
|
|
24
|
+
order?: OrderedParts[]
|
|
25
|
+
style?: any
|
|
26
|
+
labelAsRow?: boolean
|
|
27
|
+
innerWrapperRef?: React.MutableRefObject<HTMLDivElement | null>
|
|
28
|
+
}>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { InputBaseProps } from './types'
|
|
2
|
+
|
|
3
|
+
type OmitDiff<T1, T2> = {
|
|
4
|
+
[K in Exclude<keyof T1, keyof T2>]: T1[K]
|
|
5
|
+
} & {
|
|
6
|
+
[K in keyof T2]: T2[K]
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type InputBaseKey = keyof InputBaseProps
|
|
10
|
+
|
|
11
|
+
export function selectInputBaseProps<T extends InputBaseProps>(props: T): {
|
|
12
|
+
inputBaseProps: InputBaseProps
|
|
13
|
+
others: OmitDiff<T, T>
|
|
14
|
+
} {
|
|
15
|
+
const varList:InputBaseKey[] = [
|
|
16
|
+
'label',
|
|
17
|
+
|
|
18
|
+
'error',
|
|
19
|
+
'innerWrapper',
|
|
20
|
+
'leftIcon',
|
|
21
|
+
'rightIcon',
|
|
22
|
+
// 'styles',
|
|
23
|
+
'description',
|
|
24
|
+
'wrapper',
|
|
25
|
+
'children',
|
|
26
|
+
'innerWrapperProps',
|
|
27
|
+
'wrapperProps',
|
|
28
|
+
'disabled',
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
const copy = { ...props }
|
|
32
|
+
|
|
33
|
+
const result = varList.reduce((acc, key) => {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
acc[key] = copy[key]
|
|
36
|
+
|
|
37
|
+
return acc
|
|
38
|
+
}, {} as InputBaseProps)
|
|
39
|
+
|
|
40
|
+
return { inputBaseProps: result, others: copy as OmitDiff<T, T> }
|
|
41
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { jsx } from '@emotion/react'
|
|
3
|
+
import { ComponentVariants, useCodeleapContext, useDefaultComponentStyle } from '@codeleap/common'
|
|
4
|
+
import { ElementType } from 'react'
|
|
5
|
+
import { scrollToElem } from '../../lib/utils/pollyfils/scroll'
|
|
6
|
+
import { stopPropagation } from '../../lib/utils/stopPropagation'
|
|
7
|
+
import { Text, TextProps } from '../Text'
|
|
8
|
+
import { LinkComposition, LinkPresets } from './styles'
|
|
9
|
+
import { StylesOf } from '../..'
|
|
10
|
+
|
|
11
|
+
export type LinkProps<T extends ElementType> = TextProps<T> & {
|
|
12
|
+
openNewTab?: boolean
|
|
13
|
+
onScroll?: (to: string) => any
|
|
14
|
+
styles?: StylesOf<LinkComposition>
|
|
15
|
+
} & ComponentVariants<typeof LinkPresets>
|
|
16
|
+
|
|
17
|
+
export const Link = <T extends ElementType = 'a'>(linkProps: LinkProps<T>) => {
|
|
18
|
+
const { to, openNewTab, component = 'a', onScroll = null, responsiveVariants, variants, styles, ...props } = linkProps
|
|
19
|
+
|
|
20
|
+
const isExternal = ['http', 'tel', 'mailto'].some((start) => to.startsWith(start),
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
const Component = isExternal ? 'a' : component
|
|
24
|
+
const { logger } = useCodeleapContext()
|
|
25
|
+
|
|
26
|
+
function handleClick(event: React.MouseEvent) {
|
|
27
|
+
logger.log('Link pressed', { to, text: linkProps.text }, 'Component')
|
|
28
|
+
if (to) {
|
|
29
|
+
if (to.startsWith('#')) {
|
|
30
|
+
event.preventDefault()
|
|
31
|
+
stopPropagation(event)
|
|
32
|
+
if (onScroll) {
|
|
33
|
+
onScroll(to)
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
scrollToElem(to)
|
|
37
|
+
}
|
|
38
|
+
if (openNewTab) {
|
|
39
|
+
event.preventDefault()
|
|
40
|
+
window?.open?.(to, '_blank')
|
|
41
|
+
return false
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const linkPropOverride = {
|
|
47
|
+
[isExternal ? 'href' : 'to']: to,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const variantStyles = useDefaultComponentStyle<'u:Link', typeof LinkPresets>('u:Link', {
|
|
51
|
+
responsiveVariants,
|
|
52
|
+
variants,
|
|
53
|
+
rootElement: 'text',
|
|
54
|
+
styles,
|
|
55
|
+
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<Text
|
|
60
|
+
component={Component}
|
|
61
|
+
{...props}
|
|
62
|
+
{...linkPropOverride}
|
|
63
|
+
style={variantStyles.text}
|
|
64
|
+
onClick={handleClick}
|
|
65
|
+
/>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export * from './styles'
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createDefaultVariantFactory, includePresets } from "@codeleap/common"
|
|
2
|
+
import { TextComposition } from "../Text"
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export type LinkComposition = TextComposition
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const createLinkStyle = createDefaultVariantFactory<LinkComposition>()
|
|
10
|
+
|
|
11
|
+
export const LinkPresets = includePresets((styles) => createLinkStyle(() => ({ text: styles })))
|