@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.
Files changed (150) hide show
  1. package/package.json +2 -1
  2. package/src/components/ActionIcon/index.tsx +51 -52
  3. package/src/components/ActionIcon/styles.ts +1 -5
  4. package/src/components/ActionIcon/types.ts +15 -0
  5. package/src/components/ActivityIndicator/index.tsx +34 -55
  6. package/src/components/ActivityIndicator/styles.ts +0 -6
  7. package/src/components/ActivityIndicator/types.ts +12 -0
  8. package/src/components/Badge/index.tsx +43 -80
  9. package/src/components/Badge/styles.ts +1 -11
  10. package/src/components/Badge/types.ts +28 -0
  11. package/src/components/Button/index.tsx +46 -89
  12. package/src/components/Button/styles.ts +0 -5
  13. package/src/components/Button/types.ts +25 -0
  14. package/src/components/Checkbox/index.tsx +83 -97
  15. package/src/components/Checkbox/styles.ts +1 -5
  16. package/src/components/Checkbox/types.ts +15 -0
  17. package/src/components/Collapse/index.tsx +41 -83
  18. package/src/components/Collapse/styles.ts +3 -6
  19. package/src/components/Collapse/types.ts +11 -0
  20. package/src/components/ColorPicker/index.tsx +95 -48
  21. package/src/components/ColorPicker/styles.ts +11 -11
  22. package/src/components/ColorPicker/types.ts +26 -12
  23. package/src/components/CropPicker/index.tsx +100 -104
  24. package/src/components/CropPicker/styles.ts +0 -7
  25. package/src/components/CropPicker/types.ts +8 -15
  26. package/src/components/DatePicker/{defaultComponents → components}/Header.tsx +9 -17
  27. package/src/components/DatePicker/{defaultComponents → components}/OuterInput.tsx +6 -7
  28. package/src/components/DatePicker/index.tsx +110 -124
  29. package/src/components/DatePicker/styles.ts +1 -12
  30. package/src/components/DatePicker/types.ts +16 -33
  31. package/src/components/Drawer/index.tsx +133 -125
  32. package/src/components/Drawer/styles.ts +0 -5
  33. package/src/components/Drawer/types.ts +23 -0
  34. package/src/components/Dropzone/index.tsx +87 -63
  35. package/src/components/Dropzone/styles.ts +0 -6
  36. package/src/components/Dropzone/types.ts +29 -37
  37. package/src/components/EmptyPlaceholder/index.tsx +63 -83
  38. package/src/components/EmptyPlaceholder/styles.ts +0 -5
  39. package/src/components/EmptyPlaceholder/types.ts +32 -0
  40. package/src/components/FileInput/index.tsx +72 -0
  41. package/src/components/FileInput/types.ts +14 -0
  42. package/src/components/Grid/index.tsx +40 -41
  43. package/src/components/Grid/styles.ts +2 -9
  44. package/src/components/Grid/types.ts +10 -12
  45. package/src/components/Icon/index.tsx +45 -47
  46. package/src/components/Icon/styles.ts +0 -8
  47. package/src/components/Icon/types.ts +15 -0
  48. package/src/components/InputBase/index.tsx +71 -42
  49. package/src/components/InputBase/styles.ts +37 -47
  50. package/src/components/InputBase/types.ts +19 -7
  51. package/src/components/InputBase/utils.ts +3 -23
  52. package/src/components/List/ListLayout.tsx +20 -37
  53. package/src/components/List/index.tsx +36 -41
  54. package/src/components/List/styles.ts +5 -11
  55. package/src/components/List/types.ts +30 -20
  56. package/src/components/LoadingOverlay/index.tsx +31 -33
  57. package/src/components/LoadingOverlay/styles.ts +3 -8
  58. package/src/components/LoadingOverlay/types.ts +16 -0
  59. package/src/components/Modal/index.tsx +98 -160
  60. package/src/components/Modal/styles.ts +0 -5
  61. package/src/components/Modal/types.ts +55 -0
  62. package/src/components/NumberIncrement/index.tsx +67 -98
  63. package/src/components/NumberIncrement/styles.ts +0 -5
  64. package/src/components/NumberIncrement/types.ts +29 -0
  65. package/src/components/Overlay/index.tsx +37 -35
  66. package/src/components/Overlay/styles.ts +3 -5
  67. package/src/components/Overlay/types.ts +13 -0
  68. package/src/components/Pager/index.tsx +65 -81
  69. package/src/components/Pager/styles.ts +3 -9
  70. package/src/components/Pager/types.ts +35 -0
  71. package/src/components/PaginationButtons/index.tsx +173 -0
  72. package/src/components/PaginationButtons/styles.ts +7 -0
  73. package/src/components/PaginationButtons/types.ts +26 -0
  74. package/src/components/PaginationIndicator/index.tsx +69 -0
  75. package/src/components/PaginationIndicator/styles.ts +3 -0
  76. package/src/components/PaginationIndicator/types.ts +18 -0
  77. package/src/components/Progress/Bar/index.tsx +45 -50
  78. package/src/components/Progress/Bar/styles.ts +10 -0
  79. package/src/components/Progress/Bar/types.ts +26 -0
  80. package/src/components/Progress/Circle/index.tsx +45 -48
  81. package/src/components/Progress/Circle/styles.ts +1 -8
  82. package/src/components/Progress/Circle/types.ts +10 -22
  83. package/src/components/RadioInput/index.tsx +78 -124
  84. package/src/components/RadioInput/styles.ts +0 -6
  85. package/src/components/RadioInput/types.ts +29 -0
  86. package/src/components/SearchInput/index.tsx +10 -10
  87. package/src/components/SectionFilters/index.tsx +47 -36
  88. package/src/components/SectionFilters/styles.ts +1 -5
  89. package/src/components/SectionFilters/types.ts +14 -13
  90. package/src/components/SegmentedControl/index.tsx +111 -89
  91. package/src/components/SegmentedControl/styles.ts +7 -21
  92. package/src/components/SegmentedControl/types.ts +44 -0
  93. package/src/components/Select/index.tsx +92 -56
  94. package/src/components/Select/styles.ts +19 -36
  95. package/src/components/Select/types.ts +15 -10
  96. package/src/components/Slider/index.tsx +85 -93
  97. package/src/components/Slider/styles.ts +13 -6
  98. package/src/components/Slider/types.ts +29 -0
  99. package/src/components/Switch/index.tsx +63 -74
  100. package/src/components/Switch/styles.ts +1 -6
  101. package/src/components/Switch/types.ts +13 -0
  102. package/src/components/Tag/index.tsx +39 -44
  103. package/src/components/Tag/styles.ts +1 -9
  104. package/src/components/Tag/types.ts +10 -10
  105. package/src/components/Text/index.tsx +37 -48
  106. package/src/components/Text/styles.ts +0 -8
  107. package/src/components/Text/types.ts +8 -8
  108. package/src/components/TextEditor/index.tsx +49 -28
  109. package/src/components/TextEditor/styles.ts +1 -8
  110. package/src/components/TextEditor/types.ts +11 -6
  111. package/src/components/TextInput/index.tsx +58 -96
  112. package/src/components/TextInput/mask.tsx +2 -50
  113. package/src/components/TextInput/styles.ts +3 -8
  114. package/src/components/TextInput/types.ts +85 -0
  115. package/src/components/Tooltip/index.tsx +61 -84
  116. package/src/components/Tooltip/styles.ts +3 -10
  117. package/src/components/Tooltip/types.ts +46 -0
  118. package/src/components/Touchable/index.tsx +43 -86
  119. package/src/components/Touchable/styles.ts +0 -6
  120. package/src/components/Touchable/types.ts +22 -0
  121. package/src/components/View/index.tsx +36 -50
  122. package/src/components/View/styles.ts +0 -6
  123. package/src/components/View/types.ts +14 -15
  124. package/src/components/components.ts +2 -3
  125. package/src/index.ts +1 -0
  126. package/src/lib/WebStyleRegistry.ts +51 -0
  127. package/src/lib/hooks/index.ts +5 -0
  128. package/src/lib/hooks/useBreakpointMatch.ts +8 -7
  129. package/src/{components/CropPicker/useCropPicker.tsx → lib/hooks/useCropPicker.ts} +66 -13
  130. package/src/lib/hooks/useFileInput.ts +15 -0
  131. package/src/lib/hooks/useInfiniteScroll.ts +77 -0
  132. package/src/lib/hooks/useMediaQuery.ts +4 -3
  133. package/src/lib/hooks/usePagination.ts +79 -63
  134. package/src/lib/hooks/useRefresh.ts +87 -0
  135. package/src/lib/hooks/useStylesFor.ts +13 -0
  136. package/src/lib/index.ts +1 -0
  137. package/src/lib/utils/cache.ts +9 -0
  138. package/src/lib/utils/index.ts +1 -0
  139. package/src/lib/utils/test.ts +2 -2
  140. package/src/components/CropPicker/utils.ts +0 -51
  141. package/src/components/FileInput.tsx +0 -91
  142. package/src/components/List/PaginationIndicator.tsx +0 -102
  143. package/src/components/List/useInfiniteScroll.ts +0 -159
  144. package/src/components/Progress/Bar/styles.tsx +0 -7
  145. package/src/components/Progress/Bar/types.tsx +0 -30
  146. package/src/components/Scroll/index.tsx +0 -32
  147. package/src/components/Scroll/styles.ts +0 -8
  148. package/src/components/SegmentedControl/SegmentedControlOption.tsx +0 -84
  149. package/src/components/defaultStyles.ts +0 -79
  150. /package/src/components/DatePicker/{defaultComponents → components}/index.tsx +0 -0
@@ -1,10 +1,10 @@
1
1
  import { TypeGuards } from '@codeleap/common'
2
2
 
3
3
  export const getTestId = (props: Record<string, any>) => {
4
- let id = props.testId || props['data-testid'] || props.id || props.debugName
4
+ let id = props?.testId || props?.['data-testid'] || props?.id || props?.debugName
5
5
 
6
6
  if (TypeGuards.isString(id)) {
7
- id = id.replace(/\s/g, '_').toLowerCase()
7
+ id = id?.replace(/\s/g, '_').toLowerCase()
8
8
  }
9
9
 
10
10
  return id
@@ -1,51 +0,0 @@
1
- import { Crop } from 'react-image-crop'
2
- import { ImageReading } from './types'
3
-
4
- export function readImage(file: File | Blob): Promise<ImageReading> {
5
- const reader = new FileReader()
6
- return new Promise<ImageReading>((resolve) => {
7
- reader.onload = () => {
8
- const image = new Image()
9
- image.onload = () => resolve(image)
10
- image.src = reader.result as string
11
- }
12
- reader.readAsDataURL(file)
13
- })
14
- }
15
-
16
- export function cropImage(image: ImageReading, crop: Crop): Promise<[string, Blob]> {
17
- const canvas = document.createElement('canvas')
18
- const ctx = canvas.getContext('2d', { alpha: true })
19
-
20
- if (!ctx) throw new Error('No 2d context')
21
-
22
- canvas.width = image.naturalWidth * (crop.width / 100)
23
- canvas.height = image.naturalHeight * (crop.height / 100)
24
-
25
- const x = image.naturalWidth * (crop.x / 100)
26
- const y = image.naturalHeight * (crop.y / 100)
27
-
28
- ctx.drawImage(
29
- image,
30
- x,
31
- y,
32
- canvas.width,
33
- canvas.height,
34
- 0,
35
- 0,
36
- canvas.width,
37
- canvas.height,
38
- )
39
-
40
- return new Promise<[string, Blob]>((resolve, reject) => {
41
- canvas.toBlob(blob => {
42
- if (!blob) {
43
- reject(new Error('Canvas is empty'))
44
- return
45
- }
46
- readImage(blob).then(cropped => {
47
- resolve([cropped.src, blob])
48
- }).catch(reject)
49
- }, 'image/png')
50
- })
51
- }
@@ -1,91 +0,0 @@
1
- /** @jsx jsx */
2
- import { jsx, CSSObject } from '@emotion/react'
3
- import React, {
4
- useImperativeHandle,
5
- useRef,
6
- } from 'react'
7
- import { WebInputFile, useCallback } from '@codeleap/common'
8
- import { HTMLProps } from '../types'
9
-
10
- export type FileInputRef = {
11
- openFilePicker: () => Promise<WebInputFile[]>
12
- clear: () => void
13
- }
14
-
15
- export type FileInputProps = Omit<HTMLProps<'input'>, 'type' | 'ref'> & {
16
- onFileSelect?: (files: WebInputFile[]) => void
17
- autoClear?: boolean
18
- }
19
-
20
- export const _FileInput = (inputProps: FileInputProps, ref: React.Ref<FileInputRef>) => {
21
- const inputRef = useRef<HTMLInputElement>(null)
22
-
23
- const { onFileSelect, autoClear = true, ...props } = inputProps
24
-
25
- const resolveWithFile = useRef<(file: WebInputFile[]) => any>()
26
-
27
- const clearInput = useCallback(() => {
28
- if (!inputRef.current) return
29
- inputRef.current.value = null
30
- }, [])
31
-
32
- useImperativeHandle(ref, () => ({
33
- openFilePicker: () => {
34
- inputRef.current.click()
35
-
36
- return new Promise<WebInputFile[]>((resolve) => {
37
- resolveWithFile.current = resolve
38
- })
39
- },
40
- clear: clearInput,
41
- }))
42
-
43
- async function handleChange(e: React.ChangeEvent<HTMLInputElement>) {
44
- if (!e.target.files.length) return
45
- inputProps.onChange && inputProps.onChange(e)
46
- const fileArray = Array.from(e.target?.files || []) as File[]
47
-
48
- const files: WebInputFile[] = fileArray.map((obj) => ({
49
- file: obj,
50
- preview: URL.createObjectURL(obj),
51
- }))
52
-
53
- onFileSelect && onFileSelect(files)
54
-
55
- if (resolveWithFile.current) {
56
- await resolveWithFile.current(files)
57
- resolveWithFile.current = undefined
58
- }
59
-
60
- if (autoClear) {
61
- clearInput()
62
- }
63
- }
64
-
65
- return (
66
- <input
67
- type={'file'}
68
- css={{ visibility: 'hidden', width: 0, height: 0, opacity: 0, display: 'none' }}
69
- {...props}
70
- ref={inputRef}
71
- onChange={handleChange}
72
- />
73
- )
74
- }
75
-
76
- export const FileInput = React.forwardRef<FileInputRef, FileInputProps>(_FileInput) as unknown as (
77
- (props: FileInputProps & { ref?: React.MutableRefObject<FileInputRef> | React.Ref<FileInputRef> }) => JSX.Element
78
- )
79
-
80
- export const useFileInput = () => {
81
- const inputRef = useRef<FileInputRef | null>(null)
82
-
83
- const openFilePicker = () => {
84
- return inputRef.current?.openFilePicker()
85
- }
86
-
87
- return {
88
- openFilePicker,
89
- ref: inputRef,
90
- }
91
- }
@@ -1,102 +0,0 @@
1
- import React from 'react'
2
- import {
3
- assignTextStyle,
4
- ComponentVariants,
5
- createDefaultVariantFactory,
6
- getNestedStylesByKey,
7
- includePresets,
8
- StylesOf,
9
- TypeGuards,
10
- useDefaultComponentStyle,
11
- } from '@codeleap/common'
12
- import { ActivityIndicator, ActivityIndicatorComposition, ActivityIndicatorProps } from '../ActivityIndicator'
13
- import { Text, TextProps } from '../Text'
14
- import { View } from '../View'
15
- import { ComponentCommonProps } from '../../types'
16
-
17
- export type PaginationIndicatorComposition = 'text' | `loader${Capitalize<ActivityIndicatorComposition>}` | 'wrapper'
18
-
19
- const createPaginationIndicatorStyle = createDefaultVariantFactory<PaginationIndicatorComposition>()
20
-
21
- const presets = includePresets((style) => createPaginationIndicatorStyle(() => ({ loaderWrapper: style, text: style })))
22
-
23
- export const PaginationIndicatorStyles = {
24
- ...presets,
25
- default: createPaginationIndicatorStyle((theme) => {
26
- return {
27
- wrapper: {
28
- ...theme.presets.fullWidth,
29
- ...theme.presets.center,
30
- },
31
- loaderWrapper: {
32
- ...theme.presets.center,
33
- ...theme.spacing.marginVertical(3),
34
- },
35
- text: {
36
- ...assignTextStyle('h4')(theme).text,
37
- ...theme.presets.textCenter,
38
- ...theme.spacing.marginVertical(3),
39
- ...theme.presets.fullWidth,
40
- },
41
- }
42
- }),
43
- }
44
-
45
- export type PaginationIndicatorProps = {
46
- isFetching?: boolean
47
- noMoreItemsText: React.ReactChild
48
- hasMore?: boolean
49
- activityIndicator?: JSX.Element
50
- styles?: StylesOf<PaginationIndicatorComposition>
51
- style?: React.CSSProperties
52
- indicatorProps?: Partial<ActivityIndicatorProps>
53
- textProps?: Partial<TextProps<'p'>>
54
- } & ComponentVariants<typeof PaginationIndicatorStyles> & ComponentCommonProps
55
-
56
- const defaultProps: Partial<PaginationIndicatorProps> = {}
57
-
58
- export const PaginationIndicator = (props: PaginationIndicatorProps) => {
59
- const allProps = {
60
- ...PaginationIndicator.defaultProps,
61
- ...props,
62
- }
63
-
64
- const {
65
- hasMore,
66
- isFetching,
67
- noMoreItemsText,
68
- style,
69
- activityIndicator,
70
- styles = {},
71
- responsiveVariants = {},
72
- variants = [],
73
- indicatorProps = {},
74
- debugName,
75
- } = allProps
76
-
77
- const variantStyles = useDefaultComponentStyle<
78
- 'u:PaginationIndicator',
79
- typeof PaginationIndicatorStyles
80
- >('u:PaginationIndicator', {
81
- variants,
82
- responsiveVariants,
83
- styles,
84
- })
85
-
86
- const loaderStyles = getNestedStylesByKey('loader', variantStyles)
87
-
88
- if (isFetching) {
89
- return activityIndicator || <View css={[variantStyles.wrapper, style]}><ActivityIndicator debugName={debugName} {...indicatorProps} styles={loaderStyles}/></View>
90
- }
91
-
92
- if (!hasMore) {
93
- if (TypeGuards.isString(noMoreItemsText) || TypeGuards.isNumber(noMoreItemsText)) {
94
- return <Text debugName={debugName} css={[variantStyles.text, style]} text={noMoreItemsText.toString()}/>
95
- }
96
- return noMoreItemsText
97
- }
98
-
99
- return null
100
- }
101
-
102
- PaginationIndicator.defaultProps = defaultProps
@@ -1,159 +0,0 @@
1
- import React from 'react'
2
- import { AnyFunction, TypeGuards, useEffect } from '@codeleap/common'
3
- import { ListProps } from '.'
4
- import { GridProps } from '../Grid'
5
- import { useInfiniteLoader, LoadMoreItemsCallback, UseInfiniteLoaderOptions } from 'masonic'
6
-
7
- export type UseInfiniteScrollArgs<Item extends Element = any> = {
8
- threshold?: number
9
- onLoadMore?: AnyFunction
10
- loadMoreOptions?: Partial<UseInfiniteLoaderOptions<Item>>
11
- }
12
-
13
- export type UseInfiniteScrollProps<Item extends Element = any> =
14
- Partial<ListProps> &
15
- Partial<GridProps> &
16
- UseInfiniteScrollArgs<Item>
17
-
18
- export type UseInfiniteScrollReturn<Item extends Element = any> = {
19
- onLoadMore: LoadMoreItemsCallback<Item>
20
- isRefresh: boolean
21
- layoutProps: {
22
- isEmpty: boolean
23
- refreshing: boolean
24
- scrollableRef: React.MutableRefObject<undefined>
25
- }
26
- onRefreshItems: AnyFunction
27
- }
28
-
29
- type UseRefreshOptions = {
30
- threshold: number
31
- debounce: number
32
- enabled: boolean
33
- }
34
-
35
- const scrollDebounce = (func, delay) => {
36
- const timerRef = React.useRef(null)
37
-
38
- const scrollDebounce = (...args) => {
39
- clearTimeout(timerRef.current)
40
- timerRef.current = setTimeout(() => {
41
- func(...args)
42
- }, delay)
43
- }
44
-
45
- return scrollDebounce
46
- }
47
-
48
- export const useRefresh = (onRefresh = () => null, options: UseRefreshOptions) => {
49
- const {
50
- threshold,
51
- debounce,
52
- enabled,
53
- } = options
54
-
55
- const [refresh, setRefresh] = React.useState(false)
56
-
57
- const pushToTopRef = React.useRef(0)
58
-
59
- const refresher = React.useCallback(async (_onRefresh: AnyFunction) => {
60
- setRefresh(true)
61
- await _onRefresh?.()
62
-
63
- setTimeout(() => {
64
- setRefresh(false)
65
- pushToTopRef.current = 0
66
- }, 2500)
67
- }, [])
68
-
69
- const containerRef = React.useRef(null)
70
-
71
- const onScroll = scrollDebounce(() => {
72
- if (containerRef.current) {
73
- const rect = containerRef.current?.getBoundingClientRect()
74
- const scrollTop = window?.pageYOffset || document?.documentElement?.scrollTop
75
-
76
- const containerTop = rect.top + scrollTop
77
- const containerHeight = rect.height
78
-
79
- const distanceFromTop = Math.max(0, scrollTop - containerTop)
80
- const distanceFromBottom = Math.max(0, containerTop + containerHeight - scrollTop)
81
-
82
- const totalDistance = containerHeight + distanceFromTop + distanceFromBottom
83
- const percentage = (distanceFromTop / totalDistance) * 100
84
-
85
- if (percentage < threshold) {
86
- if (pushToTopRef.current === 2) {
87
- refresher(onRefresh)
88
- }
89
-
90
- pushToTopRef.current = pushToTopRef.current + 1
91
- }
92
- }
93
- }, debounce)
94
-
95
- useEffect(() => {
96
- if (enabled) {
97
- window.addEventListener('scroll', onScroll)
98
-
99
- return () => {
100
- window.removeEventListener('scroll', onScroll)
101
- }
102
- }
103
- }, [enabled])
104
-
105
- return {
106
- refresh,
107
- scrollableRef: containerRef,
108
- refresher,
109
- }
110
- }
111
-
112
- export function useInfiniteScroll<Item extends Element = any>(props: UseInfiniteScrollProps<Item>): UseInfiniteScrollReturn<Item> {
113
- const {
114
- onRefresh,
115
- data,
116
- hasNextPage,
117
- refresh: refreshEnabled,
118
- fetchNextPage,
119
- refreshThreshold,
120
- refreshDebounce,
121
- loadMoreOptions = {},
122
- onLoadMore,
123
- threshold = 16,
124
- } = props
125
-
126
- const infiniteLoader = useInfiniteLoader(
127
- async (args) => {
128
- if (hasNextPage) await fetchNextPage?.()
129
- if (TypeGuards.isFunction(onLoadMore)) await onLoadMore?.(args)
130
- },
131
- {
132
- isItemLoaded: (index, items) => !!items?.[index],
133
- threshold: threshold,
134
- ...loadMoreOptions,
135
- },
136
- )
137
-
138
- const refreshHookReturn = useRefresh(
139
- onRefresh,
140
- {
141
- threshold: refreshThreshold,
142
- debounce: refreshDebounce,
143
- enabled: refreshEnabled,
144
- }
145
- )
146
-
147
- const isEmpty = React.useMemo(() => (!data || !data?.length), [data?.length])
148
-
149
- return {
150
- onLoadMore: infiniteLoader,
151
- isRefresh: refreshHookReturn.refresh,
152
- layoutProps: {
153
- scrollableRef: refreshHookReturn.scrollableRef,
154
- refreshing: refreshHookReturn.refresh,
155
- isEmpty,
156
- },
157
- onRefreshItems: refreshHookReturn.refresher,
158
- }
159
- }
@@ -1,7 +0,0 @@
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 })))
@@ -1,30 +0,0 @@
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
- }
@@ -1,32 +0,0 @@
1
- /** @jsx jsx */
2
- import { jsx } from '@emotion/react'
3
- import {
4
- ElementType,
5
- forwardRef,
6
- ReactElement,
7
- Ref,
8
- } from 'react'
9
- import { NativeHTMLElement } from '../../types'
10
- import { View, ViewProps } from '../View'
11
-
12
- export const ScrollCP = <T extends NativeHTMLElement = 'div'>(
13
- props: ViewProps<T>,
14
- ref: Ref<any>,
15
- ) => {
16
-
17
- return (
18
- // @ts-ignore
19
- <View
20
- {...props}
21
- ref={ref}
22
- scroll
23
- />
24
-
25
- )
26
- }
27
-
28
- export * from './styles'
29
-
30
- export const Scroll = forwardRef(ScrollCP) as <T extends NativeHTMLElement = 'div'>(
31
- props: ViewProps<T>
32
- ) => JSX.Element
@@ -1,8 +0,0 @@
1
- import { createDefaultVariantFactory, includePresets } from "@codeleap/common";
2
- import { ViewComposition } from "../View";
3
-
4
- export type ScrollCompostion = ViewComposition
5
-
6
- const createScrollStyle = createDefaultVariantFactory<ScrollCompostion>()
7
-
8
- export const ScrollPresets = includePresets((styles) => createScrollStyle(() => ({ wrapper: styles })))
@@ -1,84 +0,0 @@
1
- /** @jsx jsx */
2
- import { CSSObject, jsx } from '@emotion/react'
3
-
4
- import React, { forwardRef } from 'react'
5
- import { PropsOf, IconPlaceholder } from '@codeleap/common'
6
- import { StylesOf } from '../../types'
7
- import { Text } from '../Text'
8
- import { Touchable } from '../Touchable'
9
- import { SegmentedControlComposition } from './styles'
10
- import { Icon, IconProps } from '../Icon'
11
-
12
- type OptionRef = PropsOf<typeof Touchable>['ref']
13
-
14
- export type SegmentedControlOptionProps = PropsOf<typeof Touchable> & {
15
- selected?: boolean
16
- label: string
17
- variantStyles?: StylesOf<SegmentedControlComposition>
18
- value?: any
19
- textProps?: Omit<PropsOf<typeof Text>, 'key'>
20
- iconProps?: Partial<IconProps>
21
- icon?: IconPlaceholder
22
- ref?: OptionRef
23
- }
24
-
25
- const SegmentedControlOptionCP = (props: SegmentedControlOptionProps, ref: OptionRef) => {
26
- const {
27
- selected,
28
- onPress,
29
- style,
30
- variantStyles = {},
31
- iconProps = {},
32
- label,
33
- icon,
34
- textProps,
35
- disabled,
36
- ...touchableProps
37
- } = props
38
-
39
-
40
- const iconStyles = {
41
- ...variantStyles.icon as object,
42
- ...(selected ? variantStyles['icon:selected'] as object : {}),
43
- ...(disabled ? variantStyles['icon:disabled'] as object : {}),
44
- }
45
-
46
- return (
47
- <Touchable
48
- key={touchableProps.key}
49
- ref={ref}
50
- css={[
51
- variantStyles.button,
52
- selected && variantStyles['button:selected'],
53
- disabled && variantStyles['button:disabled'],
54
- style as any,
55
- ]}
56
- onPress={onPress}
57
- disabled={disabled}
58
- {...touchableProps}
59
- >
60
- {
61
- !!icon && (
62
- <Icon
63
- debugName={touchableProps?.debugName}
64
- name={icon}
65
- style={iconStyles}
66
- {...iconProps}
67
- />
68
- )
69
- }
70
- <Text
71
- text={label}
72
- debugName={touchableProps?.debugName}
73
- css={[
74
- variantStyles.text,
75
- selected && variantStyles['text:selected'],
76
- disabled && variantStyles['text:disabled'],
77
- ]}
78
- {...textProps}
79
- />
80
- </Touchable>
81
- )
82
- }
83
-
84
- export const SegmentedControlOption = forwardRef(SegmentedControlOptionCP) as ((props: SegmentedControlOptionProps) => JSX.Element)
@@ -1,79 +0,0 @@
1
- import { ViewPresets } from './View/styles'
2
- import { IconPresets } from './Icon/styles'
3
- import { TouchablePresets } from './Touchable/styles'
4
- import { TextPresets } from './Text/styles'
5
- import { ScrollPresets } from './Scroll/styles'
6
- import { ActivityIndicatorPresets } from './ActivityIndicator/styles'
7
- import { ButtonPresets } from './Button/styles'
8
- import { ActionIconPresets } from './ActionIcon/styles'
9
- import { ModalPresets } from './Modal/styles'
10
- import { CheckboxPresets } from './Checkbox/styles'
11
- import { CollapsePresets } from './Collapse/styles'
12
- import { DrawerPresets } from './Drawer/styles'
13
- import { OverlayPresets } from './Overlay/styles'
14
- import { TextInputPresets } from './TextInput/styles'
15
- import { RadioInputPresets } from './RadioInput/styles'
16
- import { SelectPresets } from './Select/styles'
17
- import { ListPresets, PaginationIndicatorStyles } from './List'
18
- import { SliderPresets } from './Slider/styles'
19
- import { LoadingOverlayPresets } from './LoadingOverlay/styles'
20
- import { InputBasePresets } from './InputBase'
21
- import { SwitchPresets } from './Switch/styles'
22
- import { NumberIncrementPresets } from './NumberIncrement/styles'
23
- import { TooltipPresets } from './Tooltip/styles'
24
- import { SegmentedControlPresets } from './SegmentedControl/styles'
25
- import { PagerPresets } from './Pager/styles'
26
- import { EmptyPlaceholderPresets } from './EmptyPlaceholder/styles'
27
- import { GridPresets } from './Grid/styles'
28
- import { BadgePresets } from './Badge/styles'
29
- import { CropPickerPresets } from './CropPicker'
30
- import { TagPresets } from './Tag/styles'
31
- import { SectionFilterPresets } from './SectionFilters/styles'
32
-
33
- export const defaultStyles = {
34
- View: ViewPresets,
35
- Icon: IconPresets,
36
- Touchable: TouchablePresets,
37
- Text: TextPresets,
38
- ActivityIndicator: ActivityIndicatorPresets,
39
- ActionIcon: ActionIconPresets,
40
- Scroll: ScrollPresets,
41
-
42
- Button: ButtonPresets,
43
- Modal: ModalPresets,
44
- Checkbox: CheckboxPresets,
45
- Collapse: CollapsePresets,
46
- Drawer: DrawerPresets,
47
- Overlay: OverlayPresets,
48
- TextInput: TextInputPresets,
49
- RadioInput: RadioInputPresets,
50
- Select: SelectPresets,
51
- List: ListPresets,
52
- Slider: SliderPresets,
53
- LoadingOverlay: LoadingOverlayPresets,
54
- InputBase: InputBasePresets,
55
- Switch: SwitchPresets,
56
- NumberIncrement: NumberIncrementPresets,
57
- Tooltip: TooltipPresets,
58
- SegmentedControlPresets: SegmentedControlPresets,
59
- Pager: PagerPresets,
60
- EmptyPlaceholder: EmptyPlaceholderPresets,
61
- PaginationIndicator: PaginationIndicatorStyles,
62
- Grid: GridPresets,
63
- Badge: BadgePresets,
64
- Dropzone: DropzonePresets,
65
- CropPicker: CropPickerPresets,
66
- Tag: TagPresets,
67
- SectionFilters: SectionFilterPresets,
68
- }
69
-
70
- import createCache from '@emotion/cache'
71
- import { DropzonePresets } from './Dropzone/styles'
72
-
73
- export const createCodeleapWebCache = () => {
74
- return createCache({
75
- key: 'codeleap-web',
76
- })
77
- }
78
-
79
- export const codeleapWebCache = createCodeleapWebCache()