@codeleap/web 3.18.7 → 3.18.8
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 +1 -1
- package/src/components/Slider/index.tsx +16 -12
- package/src/components/Text/index.tsx +9 -1
- package/src/components/Text/types.ts +14 -12
- package/src/components/View/index.tsx +12 -32
- package/src/components/View/types.ts +22 -0
- package/src/index.ts +1 -0
- package/src/lib/index.ts +1 -0
- package/src/lib/useAnimatedStyle.ts +28 -0
- package/src/lib/useBreakpointMatch.ts +1 -1
package/package.json
CHANGED
|
@@ -27,14 +27,14 @@ export type SliderProps = Partial<Omit<PrimitiveSliderProps, 'value' | 'onValueC
|
|
|
27
27
|
separator?: string
|
|
28
28
|
transformer?: (value: number[], defaultValue: PrimitiveSliderProps['defaultValue']) => string
|
|
29
29
|
}
|
|
30
|
-
value: number[]
|
|
31
|
-
onValueChange: (val: number[]) => void
|
|
30
|
+
value: number | number[]
|
|
31
|
+
onValueChange: (val: number | number[]) => void
|
|
32
32
|
styles?: StylesOf<SliderComposition>
|
|
33
33
|
style?: PropsOf<typeof View>['style']
|
|
34
34
|
trackMarks?: Record<number, string>
|
|
35
35
|
trackMarkComponent?: React.ComponentType<TrackMarkProps>
|
|
36
36
|
onPressThumbSetValue?: boolean
|
|
37
|
-
onPressThumb?: (value: number, thumbIndex: number) => void
|
|
37
|
+
onPressThumb?: (value: number | number[], thumbIndex: number) => void
|
|
38
38
|
} & ComponentVariants<typeof SliderPresets>
|
|
39
39
|
|
|
40
40
|
export type TrackMarkProps = {
|
|
@@ -67,7 +67,7 @@ export const Slider = (props: SliderProps) => {
|
|
|
67
67
|
const {
|
|
68
68
|
debounce = null,
|
|
69
69
|
onValueChange,
|
|
70
|
-
value,
|
|
70
|
+
value: _value,
|
|
71
71
|
label,
|
|
72
72
|
debugName,
|
|
73
73
|
styles = {},
|
|
@@ -77,7 +77,7 @@ export const Slider = (props: SliderProps) => {
|
|
|
77
77
|
variants,
|
|
78
78
|
trackMarks,
|
|
79
79
|
trackMarkComponent = DefaultSliderTrackMark,
|
|
80
|
-
defaultValue:
|
|
80
|
+
defaultValue: defaultSliderValue = [],
|
|
81
81
|
max = 100,
|
|
82
82
|
min = 0,
|
|
83
83
|
indicatorLabel = null,
|
|
@@ -89,6 +89,10 @@ export const Slider = (props: SliderProps) => {
|
|
|
89
89
|
...sliderProps
|
|
90
90
|
} = others
|
|
91
91
|
|
|
92
|
+
const isUniqueValue = !TypeGuards.isArray(_value)
|
|
93
|
+
const value = isUniqueValue ? [_value] : _value
|
|
94
|
+
const _defaultValue = TypeGuards.isArray(defaultSliderValue) ? defaultSliderValue : [defaultSliderValue]
|
|
95
|
+
|
|
92
96
|
const defaultValueRef = useRef<PrimitiveSliderProps['defaultValue']>(_defaultValue)
|
|
93
97
|
const defaultValue = defaultValueRef.current
|
|
94
98
|
|
|
@@ -102,9 +106,9 @@ export const Slider = (props: SliderProps) => {
|
|
|
102
106
|
|
|
103
107
|
const currentThumbRef = useRef(null)
|
|
104
108
|
|
|
105
|
-
const handleChange: SliderProps['onValueChange'] = (newValue) => {
|
|
106
|
-
if (
|
|
107
|
-
onValueChange(newValue)
|
|
109
|
+
const handleChange: SliderProps['onValueChange'] = (newValue: Array<number>) => {
|
|
110
|
+
if (isUniqueValue) {
|
|
111
|
+
onValueChange(newValue?.[0])
|
|
108
112
|
return
|
|
109
113
|
}
|
|
110
114
|
|
|
@@ -244,15 +248,15 @@ export const Slider = (props: SliderProps) => {
|
|
|
244
248
|
<SliderRange style={selectedTrackStyle} />
|
|
245
249
|
</SliderTrack>
|
|
246
250
|
|
|
247
|
-
{defaultValue.map((
|
|
251
|
+
{defaultValue.map((_, i) => (
|
|
248
252
|
<SliderThumb
|
|
249
253
|
key={i}
|
|
250
|
-
// @ts-ignore
|
|
251
254
|
index={i}
|
|
252
255
|
style={thumbStyle}
|
|
253
256
|
onClick={() => {
|
|
254
|
-
if (onPressThumbSetValue) onValueChange?.(
|
|
255
|
-
if (TypeGuards.isFunction(onPressThumb)) onPressThumb?.(
|
|
257
|
+
if (onPressThumbSetValue) onValueChange?.(value)
|
|
258
|
+
if (TypeGuards.isFunction(onPressThumb)) onPressThumb?.(value, i)
|
|
259
|
+
|
|
256
260
|
currentThumbRef.current = i
|
|
257
261
|
}}
|
|
258
262
|
onMouseEnter={() => currentThumbRef.current = i}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TypeGuards, useDefaultComponentStyle } from '@codeleap/common'
|
|
2
|
+
import { motion } from 'framer-motion'
|
|
2
3
|
import React, { ElementType } from 'react'
|
|
3
4
|
import { TextPresets } from './styles'
|
|
4
5
|
import { TextProps } from './types'
|
|
@@ -11,6 +12,8 @@ const defaultProps: Partial<TextProps<'p'>> = {
|
|
|
11
12
|
component: 'p',
|
|
12
13
|
debounce: null,
|
|
13
14
|
pressDisabled: false,
|
|
15
|
+
animated: false,
|
|
16
|
+
animatedProps: {},
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
export const Text = <T extends ElementType>(textProps: TextProps<T>) => {
|
|
@@ -27,16 +30,20 @@ export const Text = <T extends ElementType>(textProps: TextProps<T>) => {
|
|
|
27
30
|
css,
|
|
28
31
|
text = null,
|
|
29
32
|
children,
|
|
30
|
-
component
|
|
33
|
+
component,
|
|
31
34
|
debugName,
|
|
32
35
|
msg = null,
|
|
33
36
|
onPress,
|
|
34
37
|
debounce,
|
|
35
38
|
pressDisabled,
|
|
36
39
|
onClick,
|
|
40
|
+
animated,
|
|
41
|
+
animatedProps,
|
|
37
42
|
...props
|
|
38
43
|
} = allProps
|
|
39
44
|
|
|
45
|
+
const Component = animated ? (motion?.[component] || motion.p) : (component || 'p')
|
|
46
|
+
|
|
40
47
|
const pressedRef = React.useRef(false)
|
|
41
48
|
|
|
42
49
|
const variantStyles = useDefaultComponentStyle<'u:Text', typeof TextPresets>('u:Text', {
|
|
@@ -89,6 +96,7 @@ export const Text = <T extends ElementType>(textProps: TextProps<T>) => {
|
|
|
89
96
|
css={_styles}
|
|
90
97
|
{...props}
|
|
91
98
|
{...pressProps}
|
|
99
|
+
{...animatedProps}
|
|
92
100
|
>
|
|
93
101
|
{text || children}
|
|
94
102
|
</Component>
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { StylesOf, ComponentVariants } from '@codeleap/common'
|
|
2
|
+
import { MotionProps } from 'framer-motion'
|
|
2
3
|
import { ComponentPropsWithoutRef, ElementType } from 'react'
|
|
3
4
|
import { TextComposition, TextPresets } from './styles'
|
|
4
5
|
|
|
5
|
-
export type TextProps<T extends ElementType> =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
export type TextProps<T extends ElementType> = ComponentPropsWithoutRef<T> &
|
|
7
|
+
ComponentVariants<typeof TextPresets> & {
|
|
8
|
+
component?: T
|
|
9
|
+
text: string
|
|
10
|
+
styles?: StylesOf<TextComposition>
|
|
11
|
+
msg?: string
|
|
12
|
+
debugName?: string
|
|
13
|
+
debounce?: number
|
|
14
|
+
pressDisabled?: boolean
|
|
15
|
+
onPress?: (event: React.MouseEventHandler<T>) => void
|
|
16
|
+
animated?: boolean
|
|
17
|
+
animatedProps?: Partial<MotionProps>
|
|
18
|
+
}
|
|
@@ -1,49 +1,24 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
2
|
import { jsx, CSSObject } from '@emotion/react'
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
useDefaultComponentStyle,
|
|
6
|
-
useCodeleapContext,
|
|
7
|
-
useMemo,
|
|
8
|
-
BreakpointPlaceholder,
|
|
9
|
-
BaseViewProps,
|
|
10
|
-
|
|
11
|
-
TypeGuards,
|
|
12
|
-
} from '@codeleap/common'
|
|
13
|
-
import {
|
|
14
|
-
forwardRef,
|
|
15
|
-
Ref,
|
|
16
|
-
} from 'react'
|
|
3
|
+
import { useDefaultComponentStyle, useCodeleapContext, useMemo, TypeGuards } from '@codeleap/common'
|
|
4
|
+
import { forwardRef, Ref } from 'react'
|
|
17
5
|
import { ViewPresets } from './styles'
|
|
18
6
|
import { useMediaQuery } from '../../lib/hooks'
|
|
19
|
-
import {
|
|
7
|
+
import { NativeHTMLElement } from '../../types'
|
|
8
|
+
import { motion } from 'framer-motion'
|
|
9
|
+
import { ViewProps } from './types'
|
|
20
10
|
|
|
21
11
|
export * from './styles'
|
|
22
|
-
|
|
23
|
-
export type ViewProps<T extends NativeHTMLElement> =
|
|
24
|
-
HTMLProps<T> &
|
|
25
|
-
ComponentVariants<typeof ViewPresets> &
|
|
26
|
-
{
|
|
27
|
-
component?: T
|
|
28
|
-
scroll?: boolean
|
|
29
|
-
debugName?: string
|
|
30
|
-
debug?: boolean
|
|
31
|
-
is?: BreakpointPlaceholder
|
|
32
|
-
not?: BreakpointPlaceholder
|
|
33
|
-
up?: BreakpointPlaceholder
|
|
34
|
-
down?: BreakpointPlaceholder
|
|
35
|
-
onHover?: (isMouseOverElement: boolean) => void
|
|
36
|
-
} & BaseViewProps
|
|
12
|
+
export * from './types'
|
|
37
13
|
|
|
38
14
|
export const ViewCP = (
|
|
39
15
|
viewProps: ViewProps<'div'>,
|
|
40
16
|
ref: Ref<any>,
|
|
41
17
|
) => {
|
|
42
|
-
|
|
43
18
|
const {
|
|
44
19
|
responsiveVariants = {},
|
|
45
20
|
variants = [],
|
|
46
|
-
component
|
|
21
|
+
component = 'div',
|
|
47
22
|
children,
|
|
48
23
|
is,
|
|
49
24
|
not,
|
|
@@ -54,10 +29,14 @@ export const ViewCP = (
|
|
|
54
29
|
scroll = false,
|
|
55
30
|
debug = false,
|
|
56
31
|
style,
|
|
32
|
+
animated = false,
|
|
33
|
+
animatedProps = {},
|
|
57
34
|
css = [],
|
|
58
35
|
...props
|
|
59
36
|
} = viewProps
|
|
60
37
|
|
|
38
|
+
const Component = animated ? (motion?.[component] || motion.div) : (component || 'div')
|
|
39
|
+
|
|
61
40
|
const variantStyles = useDefaultComponentStyle<'u:View', typeof ViewPresets>('u:View', {
|
|
62
41
|
responsiveVariants,
|
|
63
42
|
variants,
|
|
@@ -107,6 +86,7 @@ export const ViewCP = (
|
|
|
107
86
|
ref={ref}
|
|
108
87
|
{...onHoverProps}
|
|
109
88
|
{...props}
|
|
89
|
+
{...animatedProps}
|
|
110
90
|
>
|
|
111
91
|
{children}
|
|
112
92
|
</Component>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BaseViewProps, BreakpointPlaceholder, ComponentVariants } from '@codeleap/common'
|
|
2
|
+
import { HTMLProps, NativeHTMLElement } from '../../types'
|
|
3
|
+
import { AnimationProps, MotionProps } from 'framer-motion'
|
|
4
|
+
import { ViewPresets } from './styles'
|
|
5
|
+
|
|
6
|
+
export type ViewProps<T extends NativeHTMLElement> =
|
|
7
|
+
HTMLProps<T> &
|
|
8
|
+
ComponentVariants<typeof ViewPresets> &
|
|
9
|
+
Omit<AnimationProps, 'variants'> &
|
|
10
|
+
{
|
|
11
|
+
component?: T
|
|
12
|
+
scroll?: boolean
|
|
13
|
+
debugName?: string
|
|
14
|
+
debug?: boolean
|
|
15
|
+
is?: BreakpointPlaceholder
|
|
16
|
+
not?: BreakpointPlaceholder
|
|
17
|
+
up?: BreakpointPlaceholder
|
|
18
|
+
down?: BreakpointPlaceholder
|
|
19
|
+
onHover?: (isMouseOverElement: boolean) => void
|
|
20
|
+
animated?: boolean
|
|
21
|
+
animatedProps?: Partial<MotionProps>
|
|
22
|
+
} & BaseViewProps
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './types/utility'
|
|
|
5
5
|
export * from './lib/useSearchParams'
|
|
6
6
|
export * from './lib/useBreakpointMatch'
|
|
7
7
|
export * from './lib/usePopState'
|
|
8
|
+
export * from './lib/useAnimatedStyle'
|
|
8
9
|
export { default as Toast } from './lib/Toast'
|
|
9
10
|
export { CreateOSAlert, useGlobalAlertComponent, AlertOutlet } from './lib/OSAlert'
|
|
10
11
|
export type { GlobalAlertComponentProps, GlobalAlertType } from './lib/OSAlert'
|
package/src/lib/index.ts
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React, { useRef } from 'react'
|
|
2
|
+
import { onUpdate, useState } from '@codeleap/common'
|
|
3
|
+
import { AnimationProps } from 'framer-motion'
|
|
4
|
+
|
|
5
|
+
type UpdaterReturn = Omit<AnimationProps['animate'], 'transition'> & {
|
|
6
|
+
transition: AnimationProps['transition']
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type UseAnimatedStyleReturn = Pick<AnimationProps, 'animate' | 'initial' | 'transition'>
|
|
10
|
+
|
|
11
|
+
export const useAnimatedStyle = (updater: () => UpdaterReturn, deps: Array<any>): UseAnimatedStyleReturn => {
|
|
12
|
+
const initialStyle = updater()
|
|
13
|
+
|
|
14
|
+
const [animatedStyle, setAnimatedStyle] = useState(initialStyle)
|
|
15
|
+
const transition = useRef(initialStyle.transition)
|
|
16
|
+
|
|
17
|
+
onUpdate(() => {
|
|
18
|
+
const animatedStyleUpdated = updater()
|
|
19
|
+
|
|
20
|
+
setAnimatedStyle(animatedStyleUpdated)
|
|
21
|
+
}, deps)
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
animate: animatedStyle,
|
|
25
|
+
transition: transition.current,
|
|
26
|
+
initial: false,
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -4,7 +4,7 @@ import { useMediaQuery } from './hooks'
|
|
|
4
4
|
|
|
5
5
|
export type BreakpointsMatch<T extends string = string> = Record<T, any>
|
|
6
6
|
|
|
7
|
-
export function useBreakpointMatch<T extends string = string>(values: BreakpointsMatch<T
|
|
7
|
+
export function useBreakpointMatch<T extends string = string>(values: Partial<BreakpointsMatch<T>>) {
|
|
8
8
|
const { Theme } = useCodeleapContext()
|
|
9
9
|
|
|
10
10
|
const themeBreakpoints: Record<string, number> = Theme?.breakpoints
|