@codeleap/web 3.1.1 → 3.2.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 +13 -10
- package/src/components/ActionIcon/index.tsx +24 -15
- package/src/components/ActivityIndicator/index.tsx +39 -46
- package/src/components/ActivityIndicator/styles.ts +7 -11
- package/src/components/Button/index.tsx +17 -21
- package/src/components/Checkbox/index.tsx +103 -96
- package/src/components/Collapse/index.tsx +4 -3
- package/src/components/Drawer/index.tsx +25 -17
- package/src/components/FileInput.tsx +60 -32
- package/src/components/Icon/index.tsx +6 -5
- package/src/components/InputBase/index.tsx +9 -4
- package/src/components/InputBase/types.ts +1 -0
- package/src/components/List/index.tsx +3 -0
- package/src/components/LoadingOverlay/index.tsx +36 -23
- package/src/components/Modal/index.tsx +260 -88
- package/src/components/Modal/styles.ts +3 -4
- package/src/components/NumberIncrement/index.tsx +2 -0
- package/src/components/Overlay/index.tsx +11 -10
- package/src/components/Pager/index.tsx +166 -0
- package/src/components/Pager/styles.ts +14 -0
- package/src/components/RadioInput/index.tsx +21 -19
- package/src/components/Scroll/index.tsx +6 -3
- package/src/components/SegmentedControl/SegmentedControlOption.tsx +78 -0
- package/src/components/SegmentedControl/index.tsx +161 -0
- package/src/components/SegmentedControl/styles.ts +26 -0
- package/src/components/Select/index.tsx +13 -11
- package/src/components/Select/types.ts +23 -23
- package/src/components/Slider/index.tsx +77 -72
- package/src/components/Switch/index.tsx +96 -93
- package/src/components/Text/index.tsx +18 -33
- package/src/components/TextInput/index.tsx +14 -8
- package/src/components/Tooltip/index.tsx +1 -1
- package/src/components/Touchable/index.tsx +16 -18
- package/src/components/View/index.tsx +49 -25
- package/src/components/View/styles.ts +0 -1
- package/src/components/components.ts +2 -2
- package/src/components/defaultStyles.ts +16 -3
- package/src/lib/OSAlert.tsx +1 -1
- package/src/types/utility.ts +31 -2
- package/src/components/Link/index.tsx +0 -69
- package/src/components/Link/styles.ts +0 -11
|
@@ -1,33 +1,31 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
|
+
import { CSSObject, jsx } from '@emotion/react'
|
|
2
3
|
import { AnyFunction, useCodeleapContext } from '@codeleap/common'
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import React, { ComponentPropsWithRef, ElementType, forwardRef, ReactElement } from 'react'
|
|
4
|
+
import React, { forwardRef } from 'react'
|
|
6
5
|
import { stopPropagation } from '../../lib'
|
|
7
6
|
import { View } from '../View'
|
|
8
7
|
import { TouchableComposition } from './styles'
|
|
9
|
-
import { StylesOf } from '../../types'
|
|
10
|
-
|
|
8
|
+
import { StylesOf, NativeHTMLElement, HTMLProps } from '../../types'
|
|
11
9
|
|
|
12
10
|
export * from './styles'
|
|
13
11
|
|
|
14
|
-
export type TouchableProps<T extends
|
|
15
|
-
css?: CSSObject
|
|
12
|
+
export type TouchableProps<T extends NativeHTMLElement = 'button'> = Omit<HTMLProps<T>, 'style'> & {
|
|
16
13
|
component?: T
|
|
17
14
|
disabled?: boolean
|
|
18
15
|
propagate?: boolean
|
|
16
|
+
style?: CSSObject
|
|
19
17
|
onPress?: AnyFunction
|
|
20
18
|
debugComponent?: string
|
|
21
19
|
debugName?: string
|
|
22
20
|
styles?: StylesOf<TouchableComposition>
|
|
23
21
|
}
|
|
24
22
|
|
|
25
|
-
export const TouchableCP = <T extends
|
|
23
|
+
export const TouchableCP = <T extends NativeHTMLElement = 'button'>(
|
|
26
24
|
touchableProps: TouchableProps<T>,
|
|
27
25
|
ref,
|
|
28
26
|
) => {
|
|
29
27
|
const {
|
|
30
|
-
|
|
28
|
+
|
|
31
29
|
propagate = true,
|
|
32
30
|
component: Component = View,
|
|
33
31
|
disabled,
|
|
@@ -45,28 +43,28 @@ export const TouchableCP = <T extends ElementType = typeof View>(
|
|
|
45
43
|
|
|
46
44
|
if (!propagate) stopPropagation(event)
|
|
47
45
|
|
|
48
|
-
if (!onPress) {
|
|
46
|
+
if (!onPress && !onClick) {
|
|
49
47
|
logger.warn('No onPress passed to touchable', touchableProps)
|
|
50
48
|
return
|
|
51
|
-
|
|
49
|
+
}
|
|
52
50
|
|
|
53
51
|
logger.log(
|
|
54
52
|
`<${debugComponent || 'Touchable'}/> pressed`,
|
|
55
53
|
{ debugName, debugComponent },
|
|
56
54
|
'User interaction',
|
|
57
55
|
)
|
|
58
|
-
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
onClick?.(event)
|
|
59
58
|
onPress && onPress()
|
|
60
|
-
|
|
59
|
+
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
return (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
</View>
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
<View component={Component || 'button'} {...props} debugName={debugName} onClick={handleClick} ref={ref}/>
|
|
67
65
|
)
|
|
68
66
|
}
|
|
69
67
|
|
|
70
|
-
export const Touchable = forwardRef(TouchableCP) as <T extends
|
|
68
|
+
export const Touchable = forwardRef(TouchableCP) as <T extends NativeHTMLElement = 'button'>(
|
|
71
69
|
touchableProps: TouchableProps<T>
|
|
72
|
-
) =>
|
|
70
|
+
) => JSX.Element
|
|
@@ -1,38 +1,45 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
|
-
import { jsx } from '@emotion/react'
|
|
2
|
+
import { jsx, CSSObject } from '@emotion/react'
|
|
3
3
|
import {
|
|
4
4
|
ComponentVariants,
|
|
5
5
|
useDefaultComponentStyle,
|
|
6
6
|
useCodeleapContext,
|
|
7
|
+
useMemo,
|
|
8
|
+
BreakpointPlaceholder,
|
|
7
9
|
BaseViewProps,
|
|
8
|
-
|
|
10
|
+
|
|
11
|
+
TypeGuards,
|
|
9
12
|
} from '@codeleap/common'
|
|
10
13
|
import {
|
|
11
|
-
ComponentPropsWithRef,
|
|
12
|
-
ElementType,
|
|
13
14
|
forwardRef,
|
|
14
|
-
ReactElement,
|
|
15
|
-
ReactNode,
|
|
16
15
|
Ref,
|
|
17
16
|
} from 'react'
|
|
18
17
|
import { ViewPresets } from './styles'
|
|
19
18
|
import { useMediaQuery } from '../../lib/hooks'
|
|
19
|
+
import { HTMLProps, NativeHTMLElement } from '../../types'
|
|
20
20
|
|
|
21
21
|
export * from './styles'
|
|
22
22
|
|
|
23
|
-
export type ViewProps<T extends
|
|
24
|
-
|
|
23
|
+
export type ViewProps<T extends NativeHTMLElement> =
|
|
24
|
+
HTMLProps<T> &
|
|
25
|
+
ComponentVariants<typeof ViewPresets> &
|
|
26
|
+
{
|
|
25
27
|
component?: T
|
|
26
|
-
children?: ReactNode
|
|
27
|
-
css?: any
|
|
28
28
|
scroll?: boolean
|
|
29
|
+
debugName?: string
|
|
29
30
|
debug?: boolean
|
|
31
|
+
is?: BreakpointPlaceholder
|
|
32
|
+
not?: BreakpointPlaceholder
|
|
33
|
+
up?: BreakpointPlaceholder
|
|
34
|
+
down?: BreakpointPlaceholder
|
|
35
|
+
onHover?: (isMouseOverElement: boolean) => void
|
|
30
36
|
} & BaseViewProps
|
|
31
37
|
|
|
32
|
-
export const ViewCP =
|
|
33
|
-
viewProps: ViewProps<
|
|
38
|
+
export const ViewCP = (
|
|
39
|
+
viewProps: ViewProps<'div'>,
|
|
34
40
|
ref: Ref<any>,
|
|
35
41
|
) => {
|
|
42
|
+
|
|
36
43
|
const {
|
|
37
44
|
responsiveVariants = {},
|
|
38
45
|
variants = [],
|
|
@@ -42,22 +49,26 @@ export const ViewCP = <T extends ElementType = 'div'>(
|
|
|
42
49
|
not,
|
|
43
50
|
up,
|
|
44
51
|
onHover,
|
|
45
|
-
|
|
52
|
+
debugName,
|
|
46
53
|
down,
|
|
47
|
-
css: cssProp,
|
|
48
54
|
scroll = false,
|
|
49
55
|
debug = false,
|
|
56
|
+
style,
|
|
57
|
+
css = [],
|
|
50
58
|
...props
|
|
51
59
|
} = viewProps
|
|
52
|
-
|
|
60
|
+
|
|
61
|
+
const variantStyles = useDefaultComponentStyle<'u:View', typeof ViewPresets>('u:View', {
|
|
53
62
|
responsiveVariants,
|
|
54
63
|
variants,
|
|
55
|
-
styles,
|
|
64
|
+
styles: { wrapper: style },
|
|
65
|
+
rootElement: 'wrapper',
|
|
56
66
|
})
|
|
67
|
+
|
|
57
68
|
const { Theme, logger } = useCodeleapContext()
|
|
58
69
|
|
|
59
70
|
function handleHover(isMouseOverElement: boolean) {
|
|
60
|
-
onHover
|
|
71
|
+
onHover?.(isMouseOverElement)
|
|
61
72
|
}
|
|
62
73
|
|
|
63
74
|
const platformMediaQuery = useMemo(() => {
|
|
@@ -71,17 +82,30 @@ export const ViewCP = <T extends ElementType = 'div'>(
|
|
|
71
82
|
|
|
72
83
|
const matches = useMediaQuery(platformMediaQuery)
|
|
73
84
|
|
|
74
|
-
|
|
75
|
-
|
|
85
|
+
const componentStyles = useMemo(() => {
|
|
86
|
+
return [
|
|
87
|
+
variantStyles.wrapper,
|
|
88
|
+
scroll && { overflowY: 'scroll' },
|
|
89
|
+
matches && { display: 'none' },
|
|
90
|
+
style,
|
|
91
|
+
css,
|
|
92
|
+
]
|
|
93
|
+
}, [scroll, matches, css])
|
|
94
|
+
|
|
95
|
+
const onHoverProps = TypeGuards.isFunction(onHover) && {
|
|
96
|
+
onMouseEnter: () => handleHover(true),
|
|
97
|
+
onMouseLeave: () => handleHover(false),
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (debug) {
|
|
101
|
+
logger.log(debugName, { componentStyles, platformMediaQuery, matches })
|
|
76
102
|
}
|
|
77
103
|
|
|
78
104
|
return (
|
|
79
105
|
<Component
|
|
80
|
-
|
|
81
|
-
css={[variantStyles.wrapper, scroll && { overflowY: 'scroll' }, matches && { display: 'none' }]}
|
|
106
|
+
css={componentStyles}
|
|
82
107
|
ref={ref}
|
|
83
|
-
|
|
84
|
-
onMouseLeave={() => handleHover(false)}
|
|
108
|
+
{...onHoverProps}
|
|
85
109
|
{...props}
|
|
86
110
|
>
|
|
87
111
|
{children}
|
|
@@ -89,6 +113,6 @@ export const ViewCP = <T extends ElementType = 'div'>(
|
|
|
89
113
|
)
|
|
90
114
|
}
|
|
91
115
|
|
|
92
|
-
export const View = forwardRef(ViewCP) as <T extends
|
|
116
|
+
export const View = forwardRef(ViewCP) as unknown as <T extends NativeHTMLElement = 'div'>(
|
|
93
117
|
props: ViewProps<T>
|
|
94
|
-
) =>
|
|
118
|
+
) => JSX.Element
|
|
@@ -20,10 +20,10 @@ export * from './FileInput'
|
|
|
20
20
|
export * from './Slider'
|
|
21
21
|
export * from './Tooltip'
|
|
22
22
|
export * from './List'
|
|
23
|
-
export * from './Link'
|
|
24
23
|
export * from './LoadingOverlay'
|
|
25
24
|
export * from './InputBase'
|
|
26
25
|
export * from './Switch'
|
|
27
26
|
export * from './NumberIncrement'
|
|
28
|
-
|
|
27
|
+
export * from './SegmentedControl'
|
|
28
|
+
export * from './Pager'
|
|
29
29
|
export * from './defaultStyles'
|
|
@@ -16,12 +16,13 @@ import { RadioInputPresets } from './RadioInput/styles'
|
|
|
16
16
|
import { SelectPresets } from './Select/styles'
|
|
17
17
|
import { TooltipPresets } from './Tooltip/styles'
|
|
18
18
|
import { ListPresets } from './List/styles'
|
|
19
|
-
import { LinkPresets } from './Link/styles'
|
|
20
19
|
import { SliderPresets } from './Slider/styles'
|
|
21
20
|
import { LoadingOverlayPresets } from './LoadingOverlay/styles'
|
|
22
21
|
import { InputBasePresets } from './InputBase'
|
|
23
22
|
import { SwitchPresets } from './Switch/styles'
|
|
24
23
|
import { NumberIncrementPresets } from './NumberIncrement/styles'
|
|
24
|
+
import { SegmentedControlPresets } from './SegmentedControl/styles'
|
|
25
|
+
import { PagerPresets } from './Pager/styles'
|
|
25
26
|
|
|
26
27
|
export const defaultStyles = {
|
|
27
28
|
View: ViewPresets,
|
|
@@ -31,7 +32,7 @@ export const defaultStyles = {
|
|
|
31
32
|
ActivityIndicator: ActivityIndicatorPresets,
|
|
32
33
|
ActionIcon: ActionIconPresets,
|
|
33
34
|
Scroll: ScrollPresets,
|
|
34
|
-
|
|
35
|
+
|
|
35
36
|
Button: ButtonPresets,
|
|
36
37
|
Modal: ModalPresets,
|
|
37
38
|
Checkbox: CheckboxPresets,
|
|
@@ -47,5 +48,17 @@ export const defaultStyles = {
|
|
|
47
48
|
LoadingOverlay: LoadingOverlayPresets,
|
|
48
49
|
InputBase: InputBasePresets,
|
|
49
50
|
Switch: SwitchPresets,
|
|
50
|
-
NumberIncrement: NumberIncrementPresets
|
|
51
|
+
NumberIncrement: NumberIncrementPresets,
|
|
52
|
+
SegmentedControlPresets: SegmentedControlPresets,
|
|
53
|
+
Pager: PagerPresets,
|
|
51
54
|
}
|
|
55
|
+
|
|
56
|
+
import createCache from '@emotion/cache'
|
|
57
|
+
|
|
58
|
+
export const createCodeleapWebCache = () => {
|
|
59
|
+
return createCache({
|
|
60
|
+
key: 'codeleap-web',
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const codeleapWebCache = createCodeleapWebCache()
|
package/src/lib/OSAlert.tsx
CHANGED
|
@@ -44,7 +44,7 @@ function RenderModal(props: {args:OSAlertArgs; contextProps:AlertContext ; remov
|
|
|
44
44
|
|
|
45
45
|
footer={<>
|
|
46
46
|
{
|
|
47
|
-
options.map((o, idx) => <Button key={idx} {...o} onPress={() => {
|
|
47
|
+
options.map((o, idx) => <Button debugName={`OSAlert ${title}`} key={idx} {...o} onPress={() => {
|
|
48
48
|
o.onPress?.()
|
|
49
49
|
toggle()
|
|
50
50
|
|
package/src/types/utility.ts
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import React, { InputHTMLAttributes } from 'react'
|
|
2
|
+
import { CSSInterpolation } from '@emotion/css'
|
|
3
|
+
import { PropsOf } from '@codeleap/common'
|
|
2
4
|
|
|
3
|
-
export type StylesOf<C extends string> = Partial<Record<C, CSSInterpolation
|
|
5
|
+
export type StylesOf<C extends string> = Partial<Record<C, CSSInterpolation>>
|
|
6
|
+
|
|
7
|
+
type WithChildren<T> = T & { children?: React.ReactNode }
|
|
8
|
+
|
|
9
|
+
// You're right, this is not standard or very clean. But for some reason all the types provided by ComponentPropsWithoutRef<T> become any when imported outside the package, while this keeps working.
|
|
10
|
+
// It's important that the elements used are defined explicitly, otherwise typescript will throw JavascriptHeapOutOfMemory when building the package.
|
|
11
|
+
export type ElementMap = {
|
|
12
|
+
'select': WithChildren<JSX.IntrinsicElements['select']>
|
|
13
|
+
'input': WithChildren<JSX.IntrinsicElements['input']>
|
|
14
|
+
'textarea': WithChildren<JSX.IntrinsicElements['textarea']>
|
|
15
|
+
'button': WithChildren<JSX.IntrinsicElements['button']>
|
|
16
|
+
'form': WithChildren<JSX.IntrinsicElements['form']>
|
|
17
|
+
'label': WithChildren<JSX.IntrinsicElements['label']>
|
|
18
|
+
'a': WithChildren<JSX.IntrinsicElements['a']>
|
|
19
|
+
'img': WithChildren<JSX.IntrinsicElements['img']>
|
|
20
|
+
'div': WithChildren<JSX.IntrinsicElements['div']>
|
|
21
|
+
'span': WithChildren<JSX.IntrinsicElements['span']>
|
|
22
|
+
'p': WithChildren<JSX.IntrinsicElements['p']>
|
|
23
|
+
'section': WithChildren<JSX.IntrinsicElements['section']>
|
|
24
|
+
'header': WithChildren<JSX.IntrinsicElements['header']>
|
|
25
|
+
'footer': WithChildren<JSX.IntrinsicElements['footer']>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type NativeHTMLElement = keyof ElementMap
|
|
29
|
+
|
|
30
|
+
export type HTMLProps<T extends NativeHTMLElement> = ElementMap[T]
|
|
31
|
+
|
|
32
|
+
export type ComponentWithDefaultProps<P> = ((props: P) => JSX.Element) & { defaultProps?: Partial<P> }
|
|
@@ -1,69 +0,0 @@
|
|
|
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'
|
|
@@ -1,11 +0,0 @@
|
|
|
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 })))
|