@codeleap/web 3.15.0 → 3.15.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/web",
3
- "version": "3.15.0",
3
+ "version": "3.15.1",
4
4
  "main": "src/index.ts",
5
5
  "repository": {
6
6
  "url": "https://github.com/codeleap-uk/internal-libs-monorepo.git",
@@ -20,6 +20,7 @@
20
20
  "lint": "eslint -c .eslintrc.js --fix \"./src/**/*.{ts,tsx,js,jsx}\""
21
21
  },
22
22
  "dependencies": {
23
+ "@radix-ui/react-progress": "^1.0.3",
23
24
  "@radix-ui/react-slider": "1.1.1",
24
25
  "@radix-ui/react-tooltip": "^1.0.6",
25
26
  "framer-motion": "^10.10.0",
@@ -27,6 +28,7 @@
27
28
  "masonic": "^3.7.0",
28
29
  "rc-slider": "^9.7.5",
29
30
  "react-autosize-textarea": "^7.1.0",
31
+ "react-circular-progressbar": "^2.1.0",
30
32
  "react-dropzone": "^14.2.3",
31
33
  "react-image-crop": "^10.1.8",
32
34
  "react-input-mask": "^2.0.4",
@@ -0,0 +1,122 @@
1
+ import { ProgressBarPresets } from './styles'
2
+ import { TypeGuards, useDefaultComponentStyle } from '@codeleap/common'
3
+ import { Root, Indicator } from '@radix-ui/react-progress'
4
+ import { Icon, Text, View } from '../../components'
5
+ import { ProgressBarProps } from './types'
6
+ import { formatProgress as _formatProgress } from '../utils'
7
+
8
+ export * from './types'
9
+ export * from './styles'
10
+
11
+ const defaultProps: Partial<ProgressBarProps> = {
12
+ progress: 0,
13
+ variants: [],
14
+ responsiveVariants: {},
15
+ styles: {},
16
+ textProps: {},
17
+ progressIndicatorProps: {},
18
+ progressRootProps: {},
19
+ showProgress: false,
20
+ formatProgress: _formatProgress,
21
+ }
22
+
23
+ export const ProgressBar = (props: ProgressBarProps) => {
24
+ const allProps = {
25
+ ...ProgressBar.defaultProps,
26
+ ...props,
27
+ }
28
+
29
+ const {
30
+ progress,
31
+ variants,
32
+ responsiveVariants,
33
+ styles,
34
+ debugName,
35
+ formatProgress,
36
+ progressIndicatorProps,
37
+ progressRootProps,
38
+ showProgress,
39
+
40
+ leftIcon,
41
+ leftIconProps,
42
+ rightIcon,
43
+ rightIconProps,
44
+ text,
45
+ textProps,
46
+ leftText,
47
+ leftTextProps,
48
+ rightText,
49
+ rightTextProps,
50
+ ...rest
51
+ } = allProps
52
+
53
+ const variantStyles = useDefaultComponentStyle<
54
+ 'u:ProgressBar',
55
+ typeof ProgressBarPresets
56
+ >('u:ProgressBar', {
57
+ variants,
58
+ responsiveVariants,
59
+ styles,
60
+ })
61
+
62
+ return (
63
+ <View css={variantStyles.wrapper} debugName={debugName} {...rest}>
64
+ {!TypeGuards.isNil(leftIcon) ? (
65
+ <Icon
66
+ name={leftIcon}
67
+ style={{ ...variantStyles.icon, ...variantStyles.leftIcon }}
68
+ debugName={`leftIcon-${debugName}`}
69
+ {...leftIconProps}
70
+ />
71
+ ) : null}
72
+ {TypeGuards.isString(leftText) ? (
73
+ <Text
74
+ text={leftText}
75
+ css={[variantStyles.text, variantStyles.leftText]}
76
+ {...leftTextProps}
77
+ />
78
+ ) : (
79
+ leftText
80
+ )}
81
+ <Root
82
+ css={variantStyles.progress}
83
+ value={progress}
84
+ {...progressRootProps}
85
+ >
86
+ <Indicator
87
+ css={[
88
+ variantStyles.indicator,
89
+ { transform: `translateX(-${100 - progress}%)` },
90
+ ]}
91
+ {...progressIndicatorProps}
92
+ />
93
+ </Root>
94
+ {TypeGuards.isString(text) || showProgress ? (
95
+ <Text
96
+ style={variantStyles.text}
97
+ text={showProgress ? formatProgress(progress) : text}
98
+ {...textProps}
99
+ />
100
+ ) : text}
101
+ {!TypeGuards.isNil(rightIcon) ? (
102
+ <Icon
103
+ name={rightIcon}
104
+ style={{ ...variantStyles.icon, ...variantStyles.rightIcon }}
105
+ debugName={`rightIcon-${debugName}`}
106
+ {...rightIconProps}
107
+ />
108
+ ) : null}
109
+ {TypeGuards.isString(rightText) ? (
110
+ <Text
111
+ text={rightText}
112
+ css={[variantStyles.text, variantStyles.rightText]}
113
+ {...rightTextProps}
114
+ />
115
+ ) : (
116
+ rightText
117
+ )}
118
+ </View>
119
+ )
120
+ }
121
+
122
+ ProgressBar.defaultProps = defaultProps
@@ -0,0 +1,7 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+
3
+ export type ProgressBarComposition = 'wrapper' | 'progress' | 'indicator' | 'text' | 'icon' | 'leftIcon' | 'leftText' | 'rightIcon' | 'rightText'
4
+
5
+ const createProgressBarStyle = createDefaultVariantFactory<ProgressBarComposition>()
6
+
7
+ export const ProgressBarPresets = includePresets((styles) => createProgressBarStyle(() => ({ wrapper: styles })))
@@ -0,0 +1,30 @@
1
+ import { ComponentVariants, IconPlaceholder, PropsOf, StylesOf } from '@codeleap/common'
2
+ import { ProgressBarComposition, ProgressBarPresets } from './styles'
3
+ import {
4
+ ProgressProps,
5
+ ProgressIndicatorProps,
6
+ } from '@radix-ui/react-progress'
7
+ import { IconProps, View, TextProps as _TextProps } from '../../components'
8
+ import { ProgressPropsRoot } from '..'
9
+ import { ElementType } from 'react'
10
+
11
+ type TextProps = _TextProps<ElementType>
12
+
13
+ export type ProgressBarProps = ComponentVariants<typeof ProgressBarPresets> &
14
+ Omit<PropsOf<typeof View>, 'variants' | 'responsiveVariants' | 'styles'> &
15
+ ProgressPropsRoot & {
16
+ styles?: StylesOf<ProgressBarComposition>
17
+ progressIndicatorProps?: ProgressIndicatorProps
18
+ progressRootProps?: ProgressProps
19
+
20
+ leftIcon?: IconPlaceholder
21
+ leftIconProps?: Partial<IconProps>
22
+ rightIcon?: IconPlaceholder
23
+ rightIconProps?: Partial<IconProps>
24
+ text?: string
25
+ textProps?: Partial<TextProps>
26
+ leftText?: TextProps['text'] | JSX.Element
27
+ leftTextProps?: Partial<TextProps>
28
+ rightText?: TextProps['text'] | JSX.Element
29
+ rightTextProps?: Partial<TextProps>
30
+ }
@@ -0,0 +1,104 @@
1
+ import {
2
+ CircularProgressbarWithChildren,
3
+ buildStyles,
4
+ } from 'react-circular-progressbar'
5
+ import { View, Text, Icon } from '../../components'
6
+ import { TypeGuards, useDefaultComponentStyle } from '@codeleap/common'
7
+ import { ProgressCirclePresets } from './styles'
8
+ import { ProgressCircleProps } from './types'
9
+ import { formatProgress as _formatProgress } from '../utils'
10
+ import { useMemo } from '@codeleap/common'
11
+
12
+ export * from './styles'
13
+ export * from './types'
14
+
15
+ const defaultProps: Partial<ProgressCircleProps> = {
16
+ progress: 0,
17
+ variants: [],
18
+ responsiveVariants: {},
19
+ styles: {},
20
+ showProgress: false,
21
+ formatProgress: _formatProgress,
22
+ size: null,
23
+ }
24
+
25
+ export const ProgressCircle = (props: ProgressCircleProps) => {
26
+ const allProps = {
27
+ ...ProgressCircle.defaultProps,
28
+ ...props,
29
+ }
30
+
31
+ const {
32
+ text,
33
+ progress,
34
+ icon,
35
+ iconProps,
36
+ variants,
37
+ styles,
38
+ debugName,
39
+ showProgress,
40
+ responsiveVariants,
41
+ circleProps,
42
+ children,
43
+ formatProgress,
44
+ circleStyles,
45
+ textProps,
46
+ size: propSize,
47
+ ...rest
48
+ } = allProps
49
+
50
+ const variantStyles = useDefaultComponentStyle<
51
+ 'u:ProgressCircle',
52
+ typeof ProgressCirclePresets
53
+ >('u:ProgressCircle', {
54
+ variants,
55
+ responsiveVariants,
56
+ styles,
57
+ rootElement: 'wrapper',
58
+ })
59
+
60
+ const wrapperSize = useMemo(() => {
61
+ if (TypeGuards.isNumber(propSize)) return propSize
62
+ const { size, width, height } = variantStyles.circle
63
+ const value = size ?? width ?? height
64
+ return value ?? 0
65
+ }, [variantStyles.circle])
66
+
67
+ return (
68
+ <View debugName={debugName} css={variantStyles.wrapper} {...rest}>
69
+ <CircularProgressbarWithChildren
70
+ value={progress}
71
+ css={[
72
+ variantStyles.circle,
73
+ { width: wrapperSize, height: wrapperSize },
74
+ ]}
75
+ styles={buildStyles({
76
+ pathColor: variantStyles.line?.borderColor,
77
+ trailColor: variantStyles.line?.backgroundColor,
78
+ strokeLinecap: 'butt',
79
+ ...circleStyles,
80
+ })}
81
+ {...circleProps}
82
+ >
83
+ {children}
84
+ {!TypeGuards.isNil(icon) ? (
85
+ <Icon
86
+ name={icon}
87
+ style={variantStyles.icon}
88
+ debugName={`innerIcon-${debugName}`}
89
+ {...iconProps}
90
+ />
91
+ ) : null}
92
+ {TypeGuards.isString(text) || showProgress ? (
93
+ <Text
94
+ style={variantStyles.text}
95
+ text={showProgress ? formatProgress(progress) : text}
96
+ {...textProps}
97
+ />
98
+ ) : text}
99
+ </CircularProgressbarWithChildren>
100
+ </View>
101
+ )
102
+ }
103
+
104
+ ProgressCircle.defaultProps = defaultProps
@@ -0,0 +1,8 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+ import 'react-circular-progressbar/dist/styles.css'
3
+
4
+ export type ProgressCircleComposition = 'wrapper' | 'line' | 'circle' | 'text' | 'icon' | 'text'
5
+
6
+ const createProgressCircleStyle = createDefaultVariantFactory<ProgressCircleComposition>()
7
+
8
+ export const ProgressCirclePresets = includePresets((styles) => createProgressCircleStyle(() => ({ wrapper: styles })))
@@ -0,0 +1,32 @@
1
+ import { ComponentVariants, IconPlaceholder, PropsOf, StylesOf } from '@codeleap/common'
2
+ import {
3
+ IconProps,
4
+ ProgressCircleComposition,
5
+ ProgressCirclePresets,
6
+ View,
7
+ TextProps as _TextProps,
8
+ } from '../../components'
9
+ import { ProgressPropsRoot } from '..'
10
+ import { CircularProgressbarWithChildren, buildStyles } from 'react-circular-progressbar'
11
+ import { ElementType } from 'react'
12
+
13
+ type TextProps = _TextProps<ElementType>
14
+
15
+ export type ProgressCircleProps = Omit<
16
+ PropsOf<typeof View>,
17
+ 'styles' | 'variants' | 'children'
18
+ > &
19
+ ComponentVariants<typeof ProgressCirclePresets> &
20
+ ProgressPropsRoot & {
21
+ styles?: StylesOf<ProgressCircleComposition>
22
+ circleProps?: PropsOf<typeof CircularProgressbarWithChildren>
23
+ circleStyles?: Parameters<typeof buildStyles>[0]
24
+ children?: React.ReactNode
25
+ size?: number
26
+
27
+ text?: TextProps['text'] | JSX.Element
28
+ textProps?: Partial<TextProps>
29
+
30
+ icon?: IconPlaceholder
31
+ iconProps?: Partial<IconProps>
32
+ }
@@ -0,0 +1,10 @@
1
+ export * from './Bar'
2
+ export * from './Circle'
3
+
4
+ export type ProgressPropsRoot = {
5
+ progress: number
6
+ style?: React.CSSProperties
7
+ showProgress?: boolean
8
+ debugName?: string
9
+ formatProgress?: (progress: number) => string
10
+ }
@@ -0,0 +1,3 @@
1
+ export function formatProgress(value) {
2
+ return `${value.toFixed(value % 1 != 0 && !isNaN(value % 1) ? 2 : 0)}%`
3
+ }
@@ -31,6 +31,8 @@ export * from './EmptyPlaceholder'
31
31
  export * from './Grid'
32
32
  export * from './Badge'
33
33
  export * from './CropPicker'
34
- export * from './defaultStyles'
35
34
  export * from './Dropzone'
35
+ export * from './Progress'
36
36
  export * from './Tag'
37
+
38
+ export * from './defaultStyles'