@codeleap/web 3.24.3 → 4.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/package.json +2 -1
- package/src/components/ActionIcon/index.tsx +51 -52
- package/src/components/ActionIcon/styles.ts +1 -5
- package/src/components/ActionIcon/types.ts +15 -0
- package/src/components/ActivityIndicator/index.tsx +34 -55
- package/src/components/ActivityIndicator/styles.ts +0 -6
- package/src/components/ActivityIndicator/types.ts +12 -0
- package/src/components/Badge/index.tsx +43 -80
- package/src/components/Badge/styles.ts +1 -11
- package/src/components/Badge/types.ts +28 -0
- package/src/components/Button/index.tsx +46 -89
- package/src/components/Button/styles.ts +0 -5
- package/src/components/Button/types.ts +25 -0
- package/src/components/Checkbox/index.tsx +83 -97
- package/src/components/Checkbox/styles.ts +1 -5
- package/src/components/Checkbox/types.ts +15 -0
- package/src/components/Collapse/index.tsx +41 -83
- package/src/components/Collapse/styles.ts +3 -6
- package/src/components/Collapse/types.ts +11 -0
- package/src/components/ColorPicker/index.tsx +95 -48
- package/src/components/ColorPicker/styles.ts +11 -11
- package/src/components/ColorPicker/types.ts +26 -12
- package/src/components/CropPicker/index.tsx +100 -104
- package/src/components/CropPicker/styles.ts +0 -7
- package/src/components/CropPicker/types.ts +8 -15
- package/src/components/DatePicker/{defaultComponents → components}/Header.tsx +9 -17
- package/src/components/DatePicker/{defaultComponents → components}/OuterInput.tsx +6 -7
- package/src/components/DatePicker/index.tsx +110 -124
- package/src/components/DatePicker/styles.ts +1 -12
- package/src/components/DatePicker/types.ts +16 -33
- package/src/components/Drawer/index.tsx +133 -125
- package/src/components/Drawer/styles.ts +0 -5
- package/src/components/Drawer/types.ts +23 -0
- package/src/components/Dropzone/index.tsx +87 -63
- package/src/components/Dropzone/styles.ts +0 -6
- package/src/components/Dropzone/types.ts +29 -37
- package/src/components/EmptyPlaceholder/index.tsx +63 -83
- package/src/components/EmptyPlaceholder/styles.ts +0 -5
- package/src/components/EmptyPlaceholder/types.ts +32 -0
- package/src/components/FileInput/index.tsx +72 -0
- package/src/components/FileInput/types.ts +14 -0
- package/src/components/Grid/index.tsx +40 -41
- package/src/components/Grid/styles.ts +2 -9
- package/src/components/Grid/types.ts +10 -12
- package/src/components/Icon/index.tsx +45 -47
- package/src/components/Icon/styles.ts +0 -8
- package/src/components/Icon/types.ts +15 -0
- package/src/components/InputBase/index.tsx +71 -42
- package/src/components/InputBase/styles.ts +37 -47
- package/src/components/InputBase/types.ts +19 -7
- package/src/components/InputBase/utils.ts +3 -23
- package/src/components/List/ListLayout.tsx +20 -37
- package/src/components/List/index.tsx +36 -41
- package/src/components/List/styles.ts +5 -11
- package/src/components/List/types.ts +30 -20
- package/src/components/LoadingOverlay/index.tsx +31 -33
- package/src/components/LoadingOverlay/styles.ts +3 -8
- package/src/components/LoadingOverlay/types.ts +16 -0
- package/src/components/Modal/index.tsx +98 -160
- package/src/components/Modal/styles.ts +0 -5
- package/src/components/Modal/types.ts +55 -0
- package/src/components/NumberIncrement/index.tsx +67 -98
- package/src/components/NumberIncrement/styles.ts +0 -5
- package/src/components/NumberIncrement/types.ts +29 -0
- package/src/components/Overlay/index.tsx +37 -35
- package/src/components/Overlay/styles.ts +3 -5
- package/src/components/Overlay/types.ts +13 -0
- package/src/components/Pager/index.tsx +65 -81
- package/src/components/Pager/styles.ts +3 -9
- package/src/components/Pager/types.ts +35 -0
- package/src/components/PaginationButtons/index.tsx +173 -0
- package/src/components/PaginationButtons/styles.ts +7 -0
- package/src/components/PaginationButtons/types.ts +26 -0
- package/src/components/PaginationIndicator/index.tsx +69 -0
- package/src/components/PaginationIndicator/styles.ts +3 -0
- package/src/components/PaginationIndicator/types.ts +18 -0
- package/src/components/Progress/Bar/index.tsx +45 -50
- package/src/components/Progress/Bar/styles.ts +10 -0
- package/src/components/Progress/Bar/types.ts +26 -0
- package/src/components/Progress/Circle/index.tsx +45 -48
- package/src/components/Progress/Circle/styles.ts +1 -8
- package/src/components/Progress/Circle/types.ts +10 -22
- package/src/components/RadioInput/index.tsx +78 -124
- package/src/components/RadioInput/styles.ts +0 -6
- package/src/components/RadioInput/types.ts +29 -0
- package/src/components/SearchInput/index.tsx +10 -10
- package/src/components/SectionFilters/index.tsx +47 -36
- package/src/components/SectionFilters/styles.ts +1 -5
- package/src/components/SectionFilters/types.ts +14 -13
- package/src/components/SegmentedControl/index.tsx +111 -89
- package/src/components/SegmentedControl/styles.ts +7 -21
- package/src/components/SegmentedControl/types.ts +44 -0
- package/src/components/Select/index.tsx +92 -56
- package/src/components/Select/styles.ts +19 -36
- package/src/components/Select/types.ts +15 -10
- package/src/components/Slider/index.tsx +85 -93
- package/src/components/Slider/styles.ts +13 -6
- package/src/components/Slider/types.ts +29 -0
- package/src/components/Switch/index.tsx +63 -74
- package/src/components/Switch/styles.ts +1 -6
- package/src/components/Switch/types.ts +13 -0
- package/src/components/Tag/index.tsx +39 -44
- package/src/components/Tag/styles.ts +1 -9
- package/src/components/Tag/types.ts +10 -10
- package/src/components/Text/index.tsx +37 -48
- package/src/components/Text/styles.ts +0 -8
- package/src/components/Text/types.ts +8 -8
- package/src/components/TextEditor/index.tsx +49 -28
- package/src/components/TextEditor/styles.ts +1 -8
- package/src/components/TextEditor/types.ts +11 -6
- package/src/components/TextInput/index.tsx +58 -96
- package/src/components/TextInput/mask.tsx +2 -50
- package/src/components/TextInput/styles.ts +3 -8
- package/src/components/TextInput/types.ts +85 -0
- package/src/components/Tooltip/index.tsx +61 -84
- package/src/components/Tooltip/styles.ts +3 -10
- package/src/components/Tooltip/types.ts +46 -0
- package/src/components/Touchable/index.tsx +43 -86
- package/src/components/Touchable/styles.ts +0 -6
- package/src/components/Touchable/types.ts +22 -0
- package/src/components/View/index.tsx +36 -50
- package/src/components/View/styles.ts +0 -6
- package/src/components/View/types.ts +14 -15
- package/src/components/components.ts +2 -3
- package/src/index.ts +1 -0
- package/src/lib/WebStyleRegistry.ts +51 -0
- package/src/lib/hooks/index.ts +5 -0
- package/src/lib/hooks/useBreakpointMatch.ts +8 -7
- package/src/{components/CropPicker/useCropPicker.tsx → lib/hooks/useCropPicker.ts} +66 -13
- package/src/lib/hooks/useFileInput.ts +15 -0
- package/src/lib/hooks/useInfiniteScroll.ts +77 -0
- package/src/lib/hooks/useMediaQuery.ts +4 -3
- package/src/lib/hooks/usePagination.ts +79 -63
- package/src/lib/hooks/useRefresh.ts +87 -0
- package/src/lib/hooks/useStylesFor.ts +13 -0
- package/src/lib/index.ts +1 -0
- package/src/lib/utils/cache.ts +9 -0
- package/src/lib/utils/index.ts +1 -0
- package/src/lib/utils/test.ts +2 -2
- package/src/components/CropPicker/utils.ts +0 -51
- package/src/components/FileInput.tsx +0 -91
- package/src/components/List/PaginationIndicator.tsx +0 -102
- package/src/components/List/useInfiniteScroll.ts +0 -159
- package/src/components/Progress/Bar/styles.tsx +0 -7
- package/src/components/Progress/Bar/types.tsx +0 -30
- package/src/components/Scroll/index.tsx +0 -32
- package/src/components/Scroll/styles.ts +0 -8
- package/src/components/SegmentedControl/SegmentedControlOption.tsx +0 -84
- package/src/components/defaultStyles.ts +0 -79
- /package/src/components/DatePicker/{defaultComponents → components}/index.tsx +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/web",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "https://github.com/codeleap-uk/internal-libs-monorepo.git",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"@codeleap/common": "*",
|
|
46
|
+
"@codeleap/styles": "*",
|
|
46
47
|
"@emotion/react": "11.10.6",
|
|
47
48
|
"@reach/router": "^1.3.4",
|
|
48
49
|
"axios": "1.3.5",
|
|
@@ -1,94 +1,93 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Touchable, TouchableProps } from '../Touchable'
|
|
1
|
+
import { TypeGuards } from '@codeleap/common'
|
|
2
|
+
import { Icon } from '../Icon'
|
|
3
|
+
import { Touchable } from '../Touchable'
|
|
5
4
|
import { View } from '../View'
|
|
6
|
-
import {
|
|
5
|
+
import { ActionIconParts } from './styles'
|
|
6
|
+
import { ActionIconProps } from './types'
|
|
7
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
8
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
9
|
+
import { AnyRecord, IJSX, mergeStyles, StyledComponentProps } from '@codeleap/styles'
|
|
10
|
+
import { ElementType } from 'react'
|
|
7
11
|
|
|
8
12
|
export * from './styles'
|
|
9
|
-
|
|
10
|
-
/** IconButton */
|
|
11
|
-
export type ActionIconProps = Omit<TouchableProps, 'styles' | 'variants'> & ComponentCommonProps & {
|
|
12
|
-
iconProps?: Partial<IconProps>
|
|
13
|
-
/** prop */
|
|
14
|
-
icon?: IconProps['name']
|
|
15
|
-
/** prop */
|
|
16
|
-
name?: IconProps['name']
|
|
17
|
-
|
|
18
|
-
styles?: StylesOf<ActionIconComposition>
|
|
19
|
-
} & ComponentVariants<typeof ActionIconPresets>
|
|
20
|
-
|
|
21
|
-
const defaultProps: Partial<ActionIconProps> = {
|
|
22
|
-
disabled: false,
|
|
23
|
-
tabIndex: 0,
|
|
24
|
-
}
|
|
13
|
+
export * from './types'
|
|
25
14
|
|
|
26
15
|
export const ActionIcon = (props: ActionIconProps) => {
|
|
27
|
-
const allProps = {
|
|
28
|
-
...ActionIcon.defaultProps,
|
|
29
|
-
...props,
|
|
30
|
-
}
|
|
31
|
-
|
|
32
16
|
const {
|
|
33
17
|
icon,
|
|
34
18
|
name,
|
|
35
19
|
iconProps,
|
|
36
20
|
onPress,
|
|
37
|
-
|
|
38
|
-
variants = [],
|
|
39
|
-
styles = {},
|
|
21
|
+
style,
|
|
40
22
|
children,
|
|
41
23
|
disabled,
|
|
42
24
|
debugName,
|
|
43
25
|
...touchableProps
|
|
44
|
-
} =
|
|
26
|
+
} = {
|
|
27
|
+
...ActionIcon.defaultProps,
|
|
28
|
+
...props,
|
|
29
|
+
}
|
|
45
30
|
|
|
46
|
-
const
|
|
47
|
-
responsiveVariants,
|
|
48
|
-
variants,
|
|
49
|
-
styles,
|
|
50
|
-
rootElement: 'touchableWrapper',
|
|
51
|
-
})
|
|
31
|
+
const styles = useStylesFor(ActionIcon.styleRegistryName, style)
|
|
52
32
|
|
|
53
33
|
const isPressable = TypeGuards.isFunction(onPress) && !disabled
|
|
54
34
|
|
|
55
|
-
const WrapperComponent:
|
|
35
|
+
const WrapperComponent: ElementType = isPressable ? Touchable : View
|
|
56
36
|
|
|
57
37
|
const handlePress = (e) => {
|
|
58
38
|
if (!isPressable) return
|
|
59
|
-
|
|
39
|
+
|
|
40
|
+
const pressed = e?.type === 'click' || e?.keyCode === 13 || e?.key === 'Enter'
|
|
41
|
+
|
|
42
|
+
if (pressed) {
|
|
60
43
|
onPress?.()
|
|
61
44
|
}
|
|
62
45
|
}
|
|
63
46
|
|
|
64
|
-
const getStyles = (key: ActionIconParts) => (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
47
|
+
const getStyles = (key: ActionIconParts) => mergeStyles([
|
|
48
|
+
styles[key],
|
|
49
|
+
disabled && styles[`${key}:disabled`],
|
|
50
|
+
isPressable && styles[`${key}:pressable`],
|
|
51
|
+
])
|
|
52
|
+
|
|
53
|
+
const wrapperProps = isPressable ? {
|
|
54
|
+
onPress: () => handlePress({ type: 'click' }),
|
|
55
|
+
onKeyDown: handlePress,
|
|
56
|
+
} : {}
|
|
57
|
+
|
|
58
|
+
const wrapperStyles = getStyles('touchableWrapper')
|
|
59
|
+
const iconStyles = getStyles('icon')
|
|
69
60
|
|
|
70
61
|
return (
|
|
71
62
|
<WrapperComponent
|
|
72
|
-
css={getStyles('touchableWrapper')}
|
|
73
63
|
disabled={disabled}
|
|
74
64
|
debugName={debugName}
|
|
75
|
-
{
|
|
76
|
-
...(isPressable && {
|
|
77
|
-
onPress: () => handlePress({ type: 'click' }),
|
|
78
|
-
onKeyDown: handlePress,
|
|
79
|
-
})
|
|
80
|
-
}
|
|
65
|
+
{...wrapperProps}
|
|
81
66
|
{...touchableProps}
|
|
67
|
+
style={wrapperStyles}
|
|
82
68
|
>
|
|
83
69
|
<Icon
|
|
84
70
|
debugName={debugName}
|
|
85
71
|
name={icon ?? name}
|
|
86
|
-
style={getStyles('icon')}
|
|
87
72
|
{...iconProps}
|
|
73
|
+
style={iconStyles}
|
|
88
74
|
/>
|
|
89
75
|
{children}
|
|
90
76
|
</WrapperComponent>
|
|
91
77
|
)
|
|
92
78
|
}
|
|
93
79
|
|
|
94
|
-
ActionIcon.
|
|
80
|
+
ActionIcon.styleRegistryName = 'ActionIcon'
|
|
81
|
+
ActionIcon.elements = ['touchable', 'icon']
|
|
82
|
+
ActionIcon.rootElement = 'touchableWrapper'
|
|
83
|
+
|
|
84
|
+
ActionIcon.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
85
|
+
return ActionIcon as (props: StyledComponentProps<ActionIconProps, typeof styles>) => IJSX
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
ActionIcon.defaultProps = {
|
|
89
|
+
disabled: false,
|
|
90
|
+
tabIndex: 0,
|
|
91
|
+
} as Partial<ActionIconProps>
|
|
92
|
+
|
|
93
|
+
WebStyleRegistry.registerComponent(ActionIcon)
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
2
1
|
import { IconComposition } from '../Icon'
|
|
3
2
|
import { TouchableComposition } from '../Touchable/styles'
|
|
4
3
|
|
|
5
4
|
export type ActionIconParts = IconComposition | `touchable${Capitalize<TouchableComposition>}`
|
|
5
|
+
|
|
6
6
|
export type ActionIconStates = 'disabled' | 'pressable'
|
|
7
7
|
|
|
8
8
|
export type ActionIconComposition = ActionIconParts | `${ActionIconParts}:${ActionIconStates}`
|
|
9
|
-
|
|
10
|
-
const createActionIconStyle = createDefaultVariantFactory<ActionIconComposition>()
|
|
11
|
-
|
|
12
|
-
export const ActionIconPresets = includePresets((style) => createActionIconStyle(() => ({ touchableWrapper: style })))
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ComponentCommonProps } from '../../types'
|
|
2
|
+
import { TouchableProps } from '../Touchable'
|
|
3
|
+
import { ActionIconComposition } from './styles'
|
|
4
|
+
import { IconProps } from '../Icon'
|
|
5
|
+
import { AppIcon, StyledProp } from '@codeleap/styles'
|
|
6
|
+
|
|
7
|
+
export type ActionIconProps =
|
|
8
|
+
Omit<TouchableProps, 'style'> &
|
|
9
|
+
ComponentCommonProps &
|
|
10
|
+
{
|
|
11
|
+
iconProps?: Partial<IconProps>
|
|
12
|
+
icon?: AppIcon
|
|
13
|
+
name?: AppIcon
|
|
14
|
+
style?: StyledProp<ActionIconComposition>
|
|
15
|
+
}
|
|
@@ -1,75 +1,54 @@
|
|
|
1
1
|
import { View } from '../View'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
StylesOf,
|
|
9
|
-
TypeGuards,
|
|
10
|
-
} from '@codeleap/common'
|
|
11
|
-
import { ActivityIndicatorPresets } from './styles'
|
|
12
|
-
import { CSSInterpolation } from '@emotion/css'
|
|
13
|
-
import { ComponentCommonProps, ComponentWithDefaultProps } from '../../types'
|
|
2
|
+
import React, { forwardRef } from 'react'
|
|
3
|
+
import { TypeGuards } from '@codeleap/common'
|
|
4
|
+
import { ActivityIndicatorProps } from './types'
|
|
5
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
6
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
7
|
+
import { AnyRecord, IJSX, StyledComponentProps, StyledComponentWithProps } from '@codeleap/styles'
|
|
14
8
|
|
|
15
9
|
export * from './styles'
|
|
10
|
+
export * from './types'
|
|
16
11
|
|
|
17
|
-
|
|
18
|
-
export type ActivityIndicatorProps = ComponentCommonProps & {
|
|
19
|
-
style?: React.CSSProperties
|
|
20
|
-
styles?: StylesOf<ActivityIndicatorComposition>
|
|
21
|
-
css?: CSSInterpolation | CSSInterpolation[]
|
|
22
|
-
/** prop */
|
|
23
|
-
component?: React.ComponentType<Omit<ActivityIndicatorProps & {ref?: React.Ref<any>}, 'component'>>
|
|
24
|
-
/** prop */
|
|
25
|
-
size?: number
|
|
26
|
-
} & ComponentVariants<typeof ActivityIndicatorStyles>
|
|
27
|
-
|
|
28
|
-
export const ActivityIndicator = React.forwardRef<typeof View, ActivityIndicatorProps>((activityIndicatorProps, ref) => {
|
|
29
|
-
const allProps = {
|
|
30
|
-
...ActivityIndicator.defaultProps,
|
|
31
|
-
...activityIndicatorProps,
|
|
32
|
-
}
|
|
33
|
-
|
|
12
|
+
export const ActivityIndicator = forwardRef<HTMLDivElement, ActivityIndicatorProps>((props, ref) => {
|
|
34
13
|
const {
|
|
35
|
-
style
|
|
36
|
-
styles = {},
|
|
14
|
+
style,
|
|
37
15
|
component: Component,
|
|
38
|
-
variants = [],
|
|
39
|
-
responsiveVariants = {},
|
|
40
16
|
size,
|
|
41
|
-
...
|
|
42
|
-
} =
|
|
17
|
+
...rest
|
|
18
|
+
} = {
|
|
19
|
+
...ActivityIndicator.defaultProps,
|
|
20
|
+
...props,
|
|
21
|
+
}
|
|
43
22
|
|
|
44
|
-
const
|
|
45
|
-
'u:ActivityIndicator',
|
|
46
|
-
{
|
|
47
|
-
responsiveVariants,
|
|
48
|
-
variants,
|
|
49
|
-
styles,
|
|
50
|
-
rootElement: 'wrapper',
|
|
51
|
-
},
|
|
52
|
-
)
|
|
23
|
+
const styles = useStylesFor(ActivityIndicator.styleRegistryName, style)
|
|
53
24
|
|
|
54
25
|
const _size = React.useMemo(() => {
|
|
55
26
|
return TypeGuards.isNumber(size) ? {
|
|
56
27
|
width: size,
|
|
57
28
|
height: size,
|
|
58
|
-
} :
|
|
29
|
+
} : null
|
|
59
30
|
}, [size])
|
|
60
31
|
|
|
61
32
|
return (
|
|
62
|
-
<
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
/>
|
|
68
|
-
</View>
|
|
33
|
+
<Component
|
|
34
|
+
ref={ref}
|
|
35
|
+
{...rest}
|
|
36
|
+
style={[styles.wrapper, _size]}
|
|
37
|
+
/>
|
|
69
38
|
)
|
|
70
|
-
}) as
|
|
39
|
+
}) as StyledComponentWithProps<ActivityIndicatorProps>
|
|
40
|
+
|
|
41
|
+
ActivityIndicator.styleRegistryName = 'ActivityIndicator'
|
|
42
|
+
ActivityIndicator.elements = ['wrapper']
|
|
43
|
+
ActivityIndicator.rootElement = 'wrapper'
|
|
44
|
+
|
|
45
|
+
ActivityIndicator.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
46
|
+
return ActivityIndicator as (props: StyledComponentProps<ActivityIndicatorProps, typeof styles>) => IJSX
|
|
47
|
+
}
|
|
71
48
|
|
|
72
49
|
ActivityIndicator.defaultProps = {
|
|
73
|
-
component: View
|
|
50
|
+
component: View,
|
|
74
51
|
size: null,
|
|
75
|
-
}
|
|
52
|
+
} as Partial<ActivityIndicatorProps>
|
|
53
|
+
|
|
54
|
+
WebStyleRegistry.registerComponent(ActivityIndicator)
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
2
|
-
|
|
3
1
|
export type ActivityIndicatorComposition = 'wrapper'
|
|
4
|
-
|
|
5
|
-
const createActivityIndicatorStyle = createDefaultVariantFactory<ActivityIndicatorComposition>()
|
|
6
|
-
|
|
7
|
-
export const ActivityIndicatorPresets = includePresets((styles) => createActivityIndicatorStyle(() => ({ wrapper: styles })))
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { StyledProp } from '@codeleap/styles'
|
|
3
|
+
import { ComponentCommonProps } from '../../types'
|
|
4
|
+
import { ActivityIndicatorComposition } from './styles'
|
|
5
|
+
|
|
6
|
+
export type ActivityIndicatorProps =
|
|
7
|
+
ComponentCommonProps &
|
|
8
|
+
{
|
|
9
|
+
style?: StyledProp<ActivityIndicatorComposition>
|
|
10
|
+
component?: React.ComponentType<Omit<ActivityIndicatorProps & { ref?: React.Ref<HTMLDivElement> }, 'component'>>
|
|
11
|
+
size?: number
|
|
12
|
+
}
|
|
@@ -1,42 +1,14 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { TypeGuards } from '@codeleap/common'
|
|
3
3
|
import { Text } from '../Text'
|
|
4
|
-
import { View
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { View } from '../View'
|
|
5
|
+
import { BadgeContent, BadgeProps } from './types'
|
|
6
|
+
import { useStylesFor } from '../../lib/hooks/useStylesFor'
|
|
7
|
+
import { WebStyleRegistry } from '../../lib/WebStyleRegistry'
|
|
8
|
+
import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
|
|
7
9
|
|
|
8
10
|
export * from './styles'
|
|
9
|
-
|
|
10
|
-
/** * Badge */
|
|
11
|
-
export type BadgeProps = ComponentVariants<typeof BadgePresets>
|
|
12
|
-
& ViewProps<'div'>
|
|
13
|
-
& ComponentCommonProps
|
|
14
|
-
& {
|
|
15
|
-
styles?: StylesOf<BadgeComposition>
|
|
16
|
-
/** prop */
|
|
17
|
-
maxCount?: number
|
|
18
|
-
/** prop */
|
|
19
|
-
minCount?: number
|
|
20
|
-
/** prop */
|
|
21
|
-
debugName?: string
|
|
22
|
-
innerWrapperProps?: Partial<PropsOf<typeof View>>
|
|
23
|
-
textProps?: Partial<PropsOf<typeof Text>>
|
|
24
|
-
/** prop */
|
|
25
|
-
getBadgeContent?: (props: BadgeContent) => string
|
|
26
|
-
/** prop */
|
|
27
|
-
renderBadgeContent?: (props: BadgeContent & { content: string }) => JSX.Element
|
|
28
|
-
/** prop */
|
|
29
|
-
disabled?: boolean
|
|
30
|
-
/** prop */
|
|
31
|
-
badge?: number | boolean
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
type BadgeContent = BadgeProps & { count: number }
|
|
35
|
-
|
|
36
|
-
export type BadgeComponentProps = {
|
|
37
|
-
badge?: BadgeProps['badge']
|
|
38
|
-
badgeProps?: Partial<BadgeProps>
|
|
39
|
-
}
|
|
11
|
+
export * from './types'
|
|
40
12
|
|
|
41
13
|
const defaultGetBadgeContent = ({ count, maxCount }: BadgeContent) => {
|
|
42
14
|
if (Number(count) > maxCount) {
|
|
@@ -46,66 +18,44 @@ const defaultGetBadgeContent = ({ count, maxCount }: BadgeContent) => {
|
|
|
46
18
|
}
|
|
47
19
|
}
|
|
48
20
|
|
|
49
|
-
const defaultProps: Partial<BadgeProps> = {
|
|
50
|
-
maxCount: 9,
|
|
51
|
-
minCount: 1,
|
|
52
|
-
getBadgeContent: defaultGetBadgeContent,
|
|
53
|
-
renderBadgeContent: null,
|
|
54
|
-
disabled: false,
|
|
55
|
-
badge: true,
|
|
56
|
-
}
|
|
57
|
-
|
|
58
21
|
export const Badge = (props: BadgeProps) => {
|
|
59
|
-
const allProps = {
|
|
60
|
-
...Badge.defaultProps,
|
|
61
|
-
...props,
|
|
62
|
-
}
|
|
63
|
-
|
|
64
22
|
const {
|
|
65
23
|
debugName,
|
|
66
|
-
innerWrapperProps
|
|
67
|
-
textProps
|
|
24
|
+
innerWrapperProps,
|
|
25
|
+
textProps,
|
|
68
26
|
maxCount,
|
|
69
27
|
minCount,
|
|
70
28
|
getBadgeContent,
|
|
71
29
|
renderBadgeContent,
|
|
72
|
-
styles = {},
|
|
73
|
-
variants = [],
|
|
74
|
-
responsiveVariants = {},
|
|
75
30
|
disabled,
|
|
76
|
-
style
|
|
77
|
-
css,
|
|
31
|
+
style,
|
|
78
32
|
badge,
|
|
79
33
|
...rest
|
|
80
|
-
} =
|
|
34
|
+
} = {
|
|
35
|
+
...Badge.defaultProps,
|
|
36
|
+
...props,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const styles = useStylesFor(Badge.styleRegistryName, style)
|
|
81
40
|
|
|
82
41
|
const visible = (TypeGuards.isBoolean(badge) && badge === true) || TypeGuards.isNumber(badge)
|
|
83
42
|
|
|
84
43
|
if (!visible) return null
|
|
85
44
|
|
|
86
|
-
const variantStyles = useDefaultComponentStyle<'u:Badge', typeof BadgePresets>('u:Badge', {
|
|
87
|
-
responsiveVariants,
|
|
88
|
-
variants,
|
|
89
|
-
styles,
|
|
90
|
-
rootElement: 'wrapper',
|
|
91
|
-
})
|
|
92
|
-
|
|
93
45
|
const wrapperStyles = [
|
|
94
|
-
|
|
95
|
-
(disabled &&
|
|
96
|
-
css,
|
|
97
|
-
style,
|
|
46
|
+
styles?.wrapper,
|
|
47
|
+
(disabled && styles?.['wrapper:disabled']),
|
|
98
48
|
]
|
|
99
49
|
|
|
100
50
|
const innerWrapperStyles = [
|
|
101
|
-
|
|
102
|
-
(disabled &&
|
|
51
|
+
styles?.innerWrapper,
|
|
52
|
+
(disabled && styles?.['innerWrapper:disabled']),
|
|
103
53
|
innerWrapperProps?.style,
|
|
104
54
|
]
|
|
105
55
|
|
|
106
56
|
const countStyles = [
|
|
107
|
-
|
|
108
|
-
(disabled &&
|
|
57
|
+
styles?.count,
|
|
58
|
+
(disabled && styles?.['count:disabled']),
|
|
109
59
|
textProps?.style,
|
|
110
60
|
]
|
|
111
61
|
|
|
@@ -115,18 +65,15 @@ export const Badge = (props: BadgeProps) => {
|
|
|
115
65
|
|
|
116
66
|
const showContent = TypeGuards.isNumber(count) && count >= minCount
|
|
117
67
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (TypeGuards.isNil(renderBadgeContent)) {
|
|
121
|
-
BadgeContent = () => <Text text={content} {...textProps} css={countStyles} />
|
|
122
|
-
}
|
|
68
|
+
const BadgeContent = TypeGuards.isNil(renderBadgeContent) ? () => <Text text={content} {...textProps} /> : renderBadgeContent
|
|
123
69
|
|
|
124
70
|
return (
|
|
125
|
-
<View {...rest}
|
|
126
|
-
<View {...innerWrapperProps}
|
|
71
|
+
<View {...rest} style={wrapperStyles}>
|
|
72
|
+
<View {...innerWrapperProps} style={innerWrapperStyles}>
|
|
127
73
|
{showContent
|
|
128
74
|
? <BadgeContent
|
|
129
75
|
{...props}
|
|
76
|
+
style={countStyles}
|
|
130
77
|
maxCount={maxCount}
|
|
131
78
|
minCount={minCount}
|
|
132
79
|
count={count}
|
|
@@ -140,4 +87,20 @@ export const Badge = (props: BadgeProps) => {
|
|
|
140
87
|
)
|
|
141
88
|
}
|
|
142
89
|
|
|
143
|
-
Badge.
|
|
90
|
+
Badge.styleRegistryName = 'Badge'
|
|
91
|
+
Badge.elements = ['wrapper', 'innerWrapper', 'count']
|
|
92
|
+
Badge.rootElement = 'wrapper'
|
|
93
|
+
|
|
94
|
+
Badge.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
95
|
+
return Badge as (props: StyledComponentProps<BadgeProps, typeof styles>) => IJSX
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
Badge.defaultProps = {
|
|
99
|
+
maxCount: 9,
|
|
100
|
+
minCount: 1,
|
|
101
|
+
getBadgeContent: defaultGetBadgeContent,
|
|
102
|
+
disabled: false,
|
|
103
|
+
badge: true,
|
|
104
|
+
} as Partial<BadgeProps>
|
|
105
|
+
|
|
106
|
+
WebStyleRegistry.registerComponent(Badge)
|
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
2
|
-
|
|
3
1
|
type BadgeParts = 'wrapper' | 'innerWrapper' | 'count'
|
|
4
2
|
|
|
5
3
|
type BadgeStates = 'disabled'
|
|
6
4
|
|
|
7
|
-
export type BadgeComposition =
|
|
8
|
-
`${BadgeParts}:${BadgeStates}`
|
|
9
|
-
| BadgeParts
|
|
10
|
-
|
|
11
|
-
const createBadgeStyle = createDefaultVariantFactory<BadgeComposition>()
|
|
12
|
-
|
|
13
|
-
export const BadgePresets = includePresets((styles) => createBadgeStyle(() => ({
|
|
14
|
-
wrapper: styles
|
|
15
|
-
})))
|
|
5
|
+
export type BadgeComposition = `${BadgeParts}:${BadgeStates}` | BadgeParts
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TextProps } from '../Text'
|
|
2
|
+
import { ViewProps } from '../View'
|
|
3
|
+
import { BadgeComposition } from './styles'
|
|
4
|
+
import { ComponentCommonProps } from '../../types'
|
|
5
|
+
import { StyledProp } from '@codeleap/styles'
|
|
6
|
+
|
|
7
|
+
export type BadgeProps =
|
|
8
|
+
Omit<ViewProps, 'style'> &
|
|
9
|
+
ComponentCommonProps &
|
|
10
|
+
{
|
|
11
|
+
style?: StyledProp<BadgeComposition>
|
|
12
|
+
maxCount?: number
|
|
13
|
+
minCount?: number
|
|
14
|
+
debugName?: string
|
|
15
|
+
innerWrapperProps?: Partial<ViewProps>
|
|
16
|
+
textProps?: Partial<TextProps>
|
|
17
|
+
getBadgeContent?: (props: BadgeContent) => string
|
|
18
|
+
renderBadgeContent?: (props: BadgeContent & { content: string }) => JSX.Element
|
|
19
|
+
disabled?: boolean
|
|
20
|
+
badge?: number | boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type BadgeContent = BadgeProps & { count: number }
|
|
24
|
+
|
|
25
|
+
export type BadgeComponentProps = {
|
|
26
|
+
badge?: BadgeProps['badge']
|
|
27
|
+
badgeProps?: Partial<BadgeProps>
|
|
28
|
+
}
|