@codeleap/web 2.4.6 → 3.0.2

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 (212) hide show
  1. package/package.json +20 -19
  2. package/src/components/ActionIcon/index.tsx +59 -0
  3. package/src/components/ActionIcon/styles.ts +9 -0
  4. package/src/components/ActivityIndicator/index.tsx +78 -0
  5. package/src/components/ActivityIndicator/styles.ts +11 -0
  6. package/src/components/Button/index.tsx +125 -0
  7. package/src/components/Button/styles.ts +22 -0
  8. package/src/components/Checkbox/index.tsx +138 -0
  9. package/src/components/Checkbox/styles.ts +20 -0
  10. package/src/components/Collapse/index.tsx +87 -0
  11. package/src/components/Collapse/styles.ts +8 -0
  12. package/src/components/Drawer/index.tsx +148 -0
  13. package/src/components/Drawer/styles.ts +8 -0
  14. package/src/components/FileInput.tsx +51 -0
  15. package/src/components/Icon/index.tsx +53 -0
  16. package/src/components/Icon/styles.ts +9 -0
  17. package/src/components/InputBase/index.tsx +104 -0
  18. package/src/components/InputBase/styles.ts +167 -0
  19. package/src/components/InputBase/types.ts +28 -0
  20. package/src/components/InputBase/utils.ts +41 -0
  21. package/src/components/Link/index.tsx +69 -0
  22. package/src/components/Link/styles.ts +11 -0
  23. package/src/components/List/index.tsx +103 -0
  24. package/src/components/List/styles.ts +8 -0
  25. package/src/components/LoadingOverlay/index.tsx +34 -0
  26. package/src/components/LoadingOverlay/styles.ts +12 -0
  27. package/src/components/Modal/index.tsx +189 -0
  28. package/src/components/Modal/styles.ts +26 -0
  29. package/src/components/NumberIncrement/index.tsx +292 -0
  30. package/src/components/NumberIncrement/styles.ts +15 -0
  31. package/src/components/Overlay/index.tsx +42 -0
  32. package/src/components/Overlay/styles.ts +8 -0
  33. package/src/components/RadioInput/index.tsx +155 -0
  34. package/src/components/RadioInput/styles.ts +14 -0
  35. package/src/components/Scroll/index.tsx +29 -0
  36. package/src/components/Scroll/styles.ts +8 -0
  37. package/src/components/Select/index.tsx +438 -0
  38. package/src/components/Select/styles.ts +179 -0
  39. package/src/components/Select/types.ts +100 -0
  40. package/src/components/Slider/index.tsx +303 -0
  41. package/src/components/Slider/styles.ts +11 -0
  42. package/src/components/Switch/index.tsx +128 -0
  43. package/src/components/Switch/styles.ts +20 -0
  44. package/src/components/Text/index.tsx +62 -0
  45. package/src/components/Text/styles.ts +9 -0
  46. package/src/components/TextInput/index.tsx +253 -0
  47. package/src/components/TextInput/mask.tsx +165 -0
  48. package/src/components/TextInput/styles.ts +15 -0
  49. package/src/components/Tooltip/index.tsx +155 -0
  50. package/src/components/Tooltip/styles.ts +9 -0
  51. package/src/components/Touchable/index.tsx +72 -0
  52. package/src/components/Touchable/styles.ts +11 -0
  53. package/src/components/View/index.tsx +94 -0
  54. package/src/components/View/styles.ts +8 -0
  55. package/src/components/components.ts +29 -0
  56. package/src/components/defaultStyles.ts +51 -0
  57. package/src/index.ts +6 -0
  58. package/src/lib/OSAlert.tsx +190 -0
  59. package/src/lib/Toast.ts +23 -0
  60. package/src/lib/hooks.ts +340 -0
  61. package/src/lib/index.ts +2 -0
  62. package/src/lib/logger.ts +13 -0
  63. package/src/lib/utils/cookies.ts +13 -0
  64. package/src/lib/utils/index.ts +4 -0
  65. package/src/lib/utils/pollyfils/scroll.ts +65 -0
  66. package/src/lib/utils/stopPropagation.ts +15 -0
  67. package/src/types/index.ts +1 -0
  68. package/src/types/utility.ts +3 -0
  69. package/dist/components/ActivityIndicator/index.d.ts +0 -12
  70. package/dist/components/ActivityIndicator/index.js +0 -57
  71. package/dist/components/ActivityIndicator/index.js.map +0 -1
  72. package/dist/components/ActivityIndicator/styles.d.ts +0 -53
  73. package/dist/components/ActivityIndicator/styles.js +0 -22
  74. package/dist/components/ActivityIndicator/styles.js.map +0 -1
  75. package/dist/components/Button.d.ts +0 -18
  76. package/dist/components/Button.js +0 -67
  77. package/dist/components/Button.js.map +0 -1
  78. package/dist/components/CenterWrapper.d.ts +0 -7
  79. package/dist/components/CenterWrapper.js +0 -28
  80. package/dist/components/CenterWrapper.js.map +0 -1
  81. package/dist/components/Checkbox/index.d.ts +0 -12
  82. package/dist/components/Checkbox/index.js +0 -58
  83. package/dist/components/Checkbox/index.js.map +0 -1
  84. package/dist/components/Checkbox/styles.d.ts +0 -53
  85. package/dist/components/Checkbox/styles.js +0 -64
  86. package/dist/components/Checkbox/styles.js.map +0 -1
  87. package/dist/components/Collapse.d.ts +0 -20
  88. package/dist/components/Collapse.js +0 -68
  89. package/dist/components/Collapse.js.map +0 -1
  90. package/dist/components/ContentView.d.ts +0 -10
  91. package/dist/components/ContentView.js +0 -52
  92. package/dist/components/ContentView.js.map +0 -1
  93. package/dist/components/Drawer.d.ts +0 -23
  94. package/dist/components/Drawer.js +0 -73
  95. package/dist/components/Drawer.js.map +0 -1
  96. package/dist/components/FileInput.d.ts +0 -8
  97. package/dist/components/FileInput.js +0 -69
  98. package/dist/components/FileInput.js.map +0 -1
  99. package/dist/components/HorizontalScroll.d.ts +0 -3
  100. package/dist/components/HorizontalScroll.js +0 -42
  101. package/dist/components/HorizontalScroll.js.map +0 -1
  102. package/dist/components/Icon.d.ts +0 -8
  103. package/dist/components/Icon.js +0 -55
  104. package/dist/components/Icon.js.map +0 -1
  105. package/dist/components/Link.d.ts +0 -7
  106. package/dist/components/Link.js +0 -63
  107. package/dist/components/Link.js.map +0 -1
  108. package/dist/components/List.d.ts +0 -18
  109. package/dist/components/List.js +0 -52
  110. package/dist/components/List.js.map +0 -1
  111. package/dist/components/Modal/index.d.ts +0 -21
  112. package/dist/components/Modal/index.js +0 -116
  113. package/dist/components/Modal/index.js.map +0 -1
  114. package/dist/components/Modal/styles.d.ts +0 -56
  115. package/dist/components/Modal/styles.js +0 -36
  116. package/dist/components/Modal/styles.js.map +0 -1
  117. package/dist/components/Overlay.d.ts +0 -10
  118. package/dist/components/Overlay.js +0 -41
  119. package/dist/components/Overlay.js.map +0 -1
  120. package/dist/components/RadioInput/index.d.ts +0 -21
  121. package/dist/components/RadioInput/index.js +0 -55
  122. package/dist/components/RadioInput/index.js.map +0 -1
  123. package/dist/components/RadioInput/styles.d.ts +0 -54
  124. package/dist/components/RadioInput/styles.js +0 -44
  125. package/dist/components/RadioInput/styles.js.map +0 -1
  126. package/dist/components/RouterPage/Menu.d.ts +0 -10
  127. package/dist/components/RouterPage/Menu.js +0 -36
  128. package/dist/components/RouterPage/Menu.js.map +0 -1
  129. package/dist/components/RouterPage/MenuItem.d.ts +0 -12
  130. package/dist/components/RouterPage/MenuItem.js +0 -42
  131. package/dist/components/RouterPage/MenuItem.js.map +0 -1
  132. package/dist/components/RouterPage/Router.d.ts +0 -8
  133. package/dist/components/RouterPage/Router.js +0 -27
  134. package/dist/components/RouterPage/Router.js.map +0 -1
  135. package/dist/components/RouterPage/index.d.ts +0 -29
  136. package/dist/components/RouterPage/index.js +0 -85
  137. package/dist/components/RouterPage/index.js.map +0 -1
  138. package/dist/components/RouterPage/styles.d.ts +0 -54
  139. package/dist/components/RouterPage/styles.js +0 -87
  140. package/dist/components/RouterPage/styles.js.map +0 -1
  141. package/dist/components/Scroll.d.ts +0 -5
  142. package/dist/components/Scroll.js +0 -24
  143. package/dist/components/Scroll.js.map +0 -1
  144. package/dist/components/Select/Custom.d.ts +0 -8
  145. package/dist/components/Select/Custom.js +0 -104
  146. package/dist/components/Select/Custom.js.map +0 -1
  147. package/dist/components/Select/Multi.d.ts +0 -3
  148. package/dist/components/Select/Multi.js +0 -105
  149. package/dist/components/Select/Multi.js.map +0 -1
  150. package/dist/components/Select/Native.d.ts +0 -17
  151. package/dist/components/Select/Native.js +0 -44
  152. package/dist/components/Select/Native.js.map +0 -1
  153. package/dist/components/Select/index.d.ts +0 -12
  154. package/dist/components/Select/index.js +0 -40
  155. package/dist/components/Select/index.js.map +0 -1
  156. package/dist/components/Select/styles.d.ts +0 -5
  157. package/dist/components/Select/styles.js +0 -57
  158. package/dist/components/Select/styles.js.map +0 -1
  159. package/dist/components/Select/types.d.ts +0 -49
  160. package/dist/components/Select/types.js +0 -3
  161. package/dist/components/Select/types.js.map +0 -1
  162. package/dist/components/Slider.d.ts +0 -5
  163. package/dist/components/Slider.js +0 -39
  164. package/dist/components/Slider.js.map +0 -1
  165. package/dist/components/Text.d.ts +0 -9
  166. package/dist/components/Text.js +0 -43
  167. package/dist/components/Text.js.map +0 -1
  168. package/dist/components/TextInput.d.ts +0 -150
  169. package/dist/components/TextInput.js +0 -125
  170. package/dist/components/TextInput.js.map +0 -1
  171. package/dist/components/Tooltip.d.ts +0 -12
  172. package/dist/components/Tooltip.js +0 -122
  173. package/dist/components/Tooltip.js.map +0 -1
  174. package/dist/components/Touchable.d.ts +0 -15
  175. package/dist/components/Touchable.js +0 -52
  176. package/dist/components/Touchable.js.map +0 -1
  177. package/dist/components/View.d.ts +0 -10
  178. package/dist/components/View.js +0 -62
  179. package/dist/components/View.js.map +0 -1
  180. package/dist/components/index.d.ts +0 -24
  181. package/dist/components/index.js +0 -37
  182. package/dist/components/index.js.map +0 -1
  183. package/dist/index.d.ts +0 -6
  184. package/dist/index.js +0 -25
  185. package/dist/index.js.map +0 -1
  186. package/dist/lib/OSAlert.d.ts +0 -21
  187. package/dist/lib/OSAlert.js +0 -140
  188. package/dist/lib/OSAlert.js.map +0 -1
  189. package/dist/lib/Toast.d.ts +0 -13
  190. package/dist/lib/Toast.js +0 -32
  191. package/dist/lib/Toast.js.map +0 -1
  192. package/dist/lib/hooks.d.ts +0 -28
  193. package/dist/lib/hooks.js +0 -183
  194. package/dist/lib/hooks.js.map +0 -1
  195. package/dist/lib/logger.d.ts +0 -2
  196. package/dist/lib/logger.js +0 -16
  197. package/dist/lib/logger.js.map +0 -1
  198. package/dist/lib/utils/cookies.d.ts +0 -6
  199. package/dist/lib/utils/cookies.js +0 -15
  200. package/dist/lib/utils/cookies.js.map +0 -1
  201. package/dist/lib/utils/index.d.ts +0 -4
  202. package/dist/lib/utils/index.js +0 -23
  203. package/dist/lib/utils/index.js.map +0 -1
  204. package/dist/lib/utils/pollyfils/scroll.d.ts +0 -1
  205. package/dist/lib/utils/pollyfils/scroll.js +0 -66
  206. package/dist/lib/utils/pollyfils/scroll.js.map +0 -1
  207. package/dist/lib/utils/stopPropagation.d.ts +0 -1
  208. package/dist/lib/utils/stopPropagation.js +0 -20
  209. package/dist/lib/utils/stopPropagation.js.map +0 -1
  210. package/dist/types/utility.d.ts +0 -2
  211. package/dist/types/utility.js +0 -3
  212. package/dist/types/utility.js.map +0 -1
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@codeleap/web",
3
- "version": "2.4.6",
4
- "main": "dist/index.js",
5
- "types": "dist/index.d.ts",
3
+ "version": "3.0.2",
4
+ "main": "src/index.ts",
6
5
  "repository": {
7
6
  "url": "https://github.com/codeleap-uk/internal-libs-monorepo.git",
8
7
  "type": "git",
@@ -11,37 +10,39 @@
11
10
  "license": "UNLICENSED",
12
11
  "devDependencies": {
13
12
  "@codeleap/config": "*",
14
- "@emotion/react": "11.9.0",
15
- "@types/react-dom": "17.0.11",
16
- "@types/react-window": "1.8.5",
17
- "@emotion/css": "^11.7.1",
18
- "@codeleap/common": "*",
19
- "@reach/router": "^1.3.4",
20
- "react-helmet": "^6.1.0",
21
- "gatsby": "^4.4.0"
13
+ "@emotion/react": "11.10.6",
14
+ "@types/react-window": "1.8.5"
22
15
  },
23
16
  "scripts": {
24
- "build": "tsc --build",
17
+ "build": "rm -rf ./dist && tsc --build",
25
18
  "lint": "eslint -c .eslintrc.js --fix \"./src/**/*.{ts,tsx,js,jsx}\""
26
19
  },
27
20
  "dependencies": {
21
+ "@radix-ui/react-slider": "1.1.1",
22
+ "framer-motion": "^10.10.0",
23
+ "js-cookie": "^3.0.1",
28
24
  "rc-slider": "^9.7.5",
29
25
  "react-autosize-textarea": "^7.1.0",
26
+ "react-number-format": "^5.2.1",
27
+ "react-input-mask": "^2.0.4",
30
28
  "react-toastify": "^8.2.0",
31
29
  "react-virtualized-auto-sizer": "^1.0.6",
32
30
  "react-window": "1.8.5",
33
- "url-parse": "^1.5.4",
31
+ "url-parse": "^1.5.10",
34
32
  "uuid": "^8.3.2",
35
- "js-cookie": "^3.0.1"
33
+ "react-select": "^5.7.3"
36
34
  },
37
35
  "peerDependencies": {
38
36
  "@codeleap/common": "*",
39
- "@emotion/css": "^11.7.1",
40
- "@emotion/react": "^11.7.1",
37
+ "@emotion/css": "11.9.0",
38
+ "@emotion/react": "11.10.6",
41
39
  "@reach/router": "^1.3.4",
42
- "axios": "^0.24.0",
40
+ "axios": "^1.1.3",
43
41
  "gatsby-plugin-intl": "^0.3.3",
44
- "react": "17.0.2",
45
- "react-dom": "17.0.2"
42
+ "react": "18.1.0",
43
+ "react-dom": "18.1.0",
44
+ "react-helmet": "^6.1.0",
45
+ "react-select": "*",
46
+ "typescript": "4.5.4"
46
47
  }
47
48
  }
@@ -0,0 +1,59 @@
1
+ import React from 'react'
2
+ import { ComponentVariants, TypeGuards, useDefaultComponentStyle } from '@codeleap/common'
3
+ import { StylesOf } from '../../types'
4
+ import { Icon, IconProps } from '../Icon'
5
+ import { Touchable, TouchableProps } from '../Touchable'
6
+ import { View } from '../View'
7
+ import { ActionIconComposition, ActionIconPresets } from './styles'
8
+
9
+ export type ActionIconProps = {
10
+ disabled?: boolean
11
+ iconProps?: Partial<IconProps>
12
+ icon?: IconProps['name']
13
+ name?: IconProps['name']
14
+ styles?: StylesOf<ActionIconComposition>
15
+ } & Omit<TouchableProps, 'styles' | 'variants'> & ComponentVariants<typeof ActionIconPresets>
16
+
17
+ export const ActionIcon:React.FC<ActionIconProps> = (props) => {
18
+ const { icon, name, iconProps, onPress, variants, styles, children, disabled, ...touchableProps } = props
19
+
20
+ const variantStyles = useDefaultComponentStyle<'u:ActionIcon', typeof ActionIconPresets>('u:ActionIcon', {
21
+ variants,
22
+ styles
23
+ })
24
+
25
+ const isPressable = TypeGuards.isFunction(onPress) && !disabled
26
+
27
+ const WrapperComponent: any = isPressable ? Touchable : View
28
+
29
+ const handlePress = () => {
30
+ if (!isPressable) return
31
+
32
+ if (onPress) onPress?.()
33
+ }
34
+
35
+ return (
36
+ <WrapperComponent
37
+ onPress={handlePress}
38
+ css={[
39
+ variantStyles.wrapper,
40
+ disabled && variantStyles['wrapper:disabled'],
41
+ isPressable && variantStyles['wrapper:cursor']
42
+ ]}
43
+ disabled={disabled}
44
+ {...touchableProps}
45
+ >
46
+ <Icon
47
+ name={icon ?? name}
48
+ css={[
49
+ variantStyles.icon,
50
+ disabled && variantStyles['icon:disabled'],
51
+ ]}
52
+ {...iconProps}
53
+ />
54
+ {children}
55
+ </WrapperComponent>
56
+ )
57
+ }
58
+
59
+ export * from './styles'
@@ -0,0 +1,9 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+ import { TouchableComposition } from '../Touchable'
3
+
4
+ export type ActionIconParts = 'icon' | TouchableComposition
5
+ export type ActionIconStates = ':disabled' | ':cursor' | ''
6
+ export type ActionIconComposition = `${ActionIconParts}${ActionIconStates}`
7
+ const createActionIconStyle = createDefaultVariantFactory<ActionIconComposition>()
8
+
9
+ export const ActionIconPresets = includePresets((style) => createActionIconStyle(() => ({ wrapper: style })))
@@ -0,0 +1,78 @@
1
+ import { View } from '../View'
2
+ import { CSSObject, keyframes } from '@emotion/react'
3
+ import {
4
+ useDefaultComponentStyle,
5
+ ComponentVariants,
6
+ ActivityIndicatorStyles,
7
+ ActivityIndicatorComposition,
8
+ TypeGuards,
9
+ } from '@codeleap/common'
10
+ import { StylesOf } from '../../types/utility'
11
+ import { ActivityIndicatorPresets } from './styles'
12
+
13
+ export * from './styles'
14
+
15
+ const spin = keyframes`
16
+ from {
17
+ transform: rotate(0deg);
18
+ }
19
+ to {
20
+ transform: rotate(360deg);
21
+ }
22
+ `
23
+
24
+ export type ActivityIndicatorProps = {
25
+ animating?: boolean
26
+ hidesWhenStopped?: boolean
27
+ styles?: StylesOf<ActivityIndicatorComposition>
28
+ css?: CSSObject
29
+ size?: number
30
+ } & ComponentVariants<typeof ActivityIndicatorStyles>
31
+
32
+ export const ActivityIndicator: React.FC<ActivityIndicatorProps> = (props) => {
33
+ const {
34
+ animating = true,
35
+ hidesWhenStopped = true,
36
+ variants,
37
+ responsiveVariants,
38
+ styles,
39
+ size = null,
40
+ ...viewProps
41
+ } = props
42
+
43
+ const variantStyles = useDefaultComponentStyle<'u:ActivityIndicator', typeof ActivityIndicatorPresets>(
44
+ 'u:ActivityIndicator',
45
+ {
46
+ styles,
47
+ responsiveVariants,
48
+ variants,
49
+ }
50
+ )
51
+
52
+ const _size = TypeGuards.isNumber(size) && {
53
+ height: size,
54
+ width: size,
55
+ borderWidth: size * 0.25,
56
+ }
57
+
58
+ return (
59
+ <View
60
+ {...viewProps}
61
+ css={[
62
+ variantStyles.wrapper,
63
+ (!animating && hidesWhenStopped) && { visibility: 'hidden' },
64
+ _size,
65
+ ]}
66
+ >
67
+ <View css={{ ...variantStyles.circle, ...variantStyles.backCircle }} />
68
+ <View
69
+ css={{
70
+ ...variantStyles.circle,
71
+ ...variantStyles.frontCircle,
72
+ animation: `${spin} 1s infinite`,
73
+ animationPlayState: animating ? 'running' : 'paused',
74
+ }}
75
+ />
76
+ </View>
77
+ )
78
+ }
@@ -0,0 +1,11 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+
3
+ export type ActivityIndicatorComposition =
4
+ | 'wrapper'
5
+ | 'backCircle'
6
+ | 'frontCircle'
7
+ | 'circle'
8
+
9
+ const createActivityIndicatorStyle = createDefaultVariantFactory<ActivityIndicatorComposition>()
10
+
11
+ export const ActivityIndicatorPresets = includePresets((styles) => createActivityIndicatorStyle(() => ({ wrapper: styles })))
@@ -0,0 +1,125 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react'
3
+ import {
4
+ useDefaultComponentStyle,
5
+ ButtonStyles,
6
+ ComponentVariants,
7
+ ButtonComposition,
8
+ ButtonParts,
9
+ optionalObject,
10
+ AnyFunction,
11
+ } from '@codeleap/common'
12
+ import React, { ComponentPropsWithRef } from 'react'
13
+ import { StylesOf } from '../../types/utility'
14
+ import { Text } from '../Text'
15
+ import { Touchable, TouchableProps } from '../Touchable'
16
+ import { Icon } from '../Icon'
17
+ import { ActivityIndicator } from '../ActivityIndicator'
18
+ import { IconPlaceholder, useNestedStylesByKey } from '@codeleap/common'
19
+ import { LoadingOverlay } from '../LoadingOverlay'
20
+
21
+ type NativeButtonProps = ComponentPropsWithRef<'button'>
22
+
23
+ export type ButtonProps = NativeButtonProps &
24
+ ComponentVariants<typeof ButtonStyles> & {
25
+ text?: string
26
+ rightIcon?: IconPlaceholder
27
+ icon?: IconPlaceholder
28
+ onPress?: AnyFunction
29
+ styles?: StylesOf<ButtonComposition>
30
+ loading?: boolean
31
+ debugName?: string
32
+ debounce?: number
33
+ } & Partial<TouchableProps<any>>
34
+
35
+ export const Button: React.FC<ButtonProps> = (buttonProps) => {
36
+ const {
37
+ variants = [],
38
+ responsiveVariants = {},
39
+ children,
40
+ icon,
41
+ text,
42
+ loading,
43
+ styles,
44
+ onPress,
45
+ disabled,
46
+ rightIcon,
47
+ debounce = 600,
48
+ ...props
49
+ } = buttonProps
50
+ const [pressed, setPressed] = React.useState(false)
51
+ const variantStyles = useDefaultComponentStyle('Button', {
52
+ responsiveVariants,
53
+ variants,
54
+ styles,
55
+ })
56
+
57
+ function handlePress(e: Parameters<ButtonProps['onPress']>[0]) {
58
+ if (!pressed) {
59
+ props?.onClick?.(e)
60
+
61
+ setPressed(true)
62
+
63
+ setTimeout(() => setPressed(false), debounce)
64
+
65
+ onPress && onPress()
66
+ }
67
+ }
68
+
69
+ function getStyles(key:ButtonParts) {
70
+
71
+ return {
72
+ ...variantStyles[key],
73
+ ...optionalObject(disabled, variantStyles[key + ':disabled'], {}),
74
+ }
75
+ }
76
+ const iconStyle = getStyles('icon')
77
+
78
+ const loaderStyle = useNestedStylesByKey('loading', variantStyles)
79
+
80
+ return (
81
+ <Touchable
82
+ css={getStyles('wrapper')}
83
+ component='button'
84
+ debugComponent='Button'
85
+
86
+ onPress={handlePress}
87
+ {...props}
88
+ >
89
+ <LoadingOverlay
90
+ visible={loading}
91
+ styles={loaderStyle}
92
+
93
+ />
94
+ {!loading && (
95
+ <Icon
96
+ name={icon}
97
+ style={{ ...iconStyle, ...getStyles('leftIcon') }}
98
+
99
+ />
100
+ )}
101
+ {children || (
102
+ <Text
103
+ text={text}
104
+ styles={{
105
+ text: getStyles('text'),
106
+ }}
107
+ />
108
+ )}
109
+
110
+ <Icon
111
+ name={rightIcon}
112
+ style={{ ...iconStyle, ...getStyles('rightIcon') }}
113
+
114
+ />
115
+ {loading && <ActivityIndicator styles={{
116
+ 'wrapper': getStyles('loaderWrapper'),
117
+ 'backCircle': getStyles('loaderBackCircle'),
118
+ 'frontCircle': getStyles('loaderFrontCircle'),
119
+ 'circle': getStyles('loaderCircle'),
120
+ }} css={getStyles('loader')}/>}
121
+ </Touchable>
122
+ )
123
+ }
124
+
125
+ export * from './styles'
@@ -0,0 +1,22 @@
1
+ import { createDefaultVariantFactory, includePresets, StylesOf } from '@codeleap/common'
2
+ import { LoadingOverlayComposition } from '../LoadingOverlay'
3
+
4
+ export type ButtonStates = 'disabled'
5
+ export type ButtonParts =
6
+ | 'text'
7
+ | 'inner'
8
+ | 'wrapper'
9
+ | 'icon'
10
+ | 'leftIcon'
11
+ | 'rightIcon'
12
+ | `loading${Capitalize<LoadingOverlayComposition>}`
13
+ | 'badgeText'
14
+ | 'badgeWrapper'
15
+
16
+ export type ButtonComposition = `${ButtonParts}:${ButtonStates}` | ButtonParts
17
+
18
+
19
+
20
+ const createButtonStyle = createDefaultVariantFactory<ButtonComposition>()
21
+
22
+ export const ButtonPresets = includePresets((styles) => createButtonStyle(() => ({ wrapper: styles })))
@@ -0,0 +1,138 @@
1
+ import * as React from 'react'
2
+ import {
3
+ ComponentVariants,
4
+ useDefaultComponentStyle,
5
+ StylesOf,
6
+ PropsOf,
7
+ } from '@codeleap/common'
8
+ import { View } from '../View'
9
+ import { CheckboxPresets, CheckboxComposition } from './styles'
10
+ import { InputBase, InputBaseDefaultOrder, InputBaseProps, selectInputBaseProps } from '../InputBase'
11
+ import { useAnimatedVariantStyles } from '../..'
12
+ import { Icon } from '../Icon'
13
+ import { motion } from 'framer-motion'
14
+
15
+ export * from './styles'
16
+
17
+ export type CheckboxProps = Pick<
18
+ InputBaseProps,
19
+ 'debugName' | 'disabled' | 'label'
20
+ > & {
21
+ variants?: ComponentVariants<typeof CheckboxPresets>['variants']
22
+ styles?: StylesOf<CheckboxComposition>
23
+ value: boolean
24
+ onValueChange: (value: boolean) => void
25
+ style?: PropsOf<typeof View>['style']
26
+ checkboxOnLeft?: boolean
27
+ }
28
+
29
+ const reversedOrder = [...InputBaseDefaultOrder].reverse()
30
+
31
+ export const Checkbox = (props: CheckboxProps) => {
32
+ const {
33
+ inputBaseProps,
34
+ others
35
+ } = selectInputBaseProps(props)
36
+
37
+ const {
38
+ variants = [],
39
+ style = {},
40
+ styles = {},
41
+ value,
42
+ disabled,
43
+ debugName,
44
+ onValueChange,
45
+ checkboxOnLeft,
46
+ } = others
47
+
48
+ const variantStyles = useDefaultComponentStyle<'u:Checkbox', typeof CheckboxPresets>('u:Checkbox', {
49
+ variants,
50
+ styles,
51
+ rootElement: 'wrapper',
52
+ })
53
+
54
+ const boxAnimation = useAnimatedVariantStyles({
55
+ variantStyles,
56
+ animatedProperties: ['box:unchecked','box:disabled', 'box:checked', 'box:disabled-checked', 'box:disabled-unchecked'],
57
+ updater: () =>{
58
+ 'worklet'
59
+ let disabledStyle = {}
60
+ if(disabled){
61
+ disabledStyle = value ? variantStyles['box:disabled-checked'] : variantStyles['box:disabled-unchecked']
62
+ }
63
+ const style = value ? variantStyles['box:checked'] : variantStyles['box:unchecked']
64
+
65
+ return {
66
+ ...style,
67
+ ...disabledStyle
68
+ }
69
+
70
+ },
71
+ dependencies: [value, disabled],
72
+ })
73
+
74
+ const checkmarkWrapperAnimation = useAnimatedVariantStyles({
75
+ variantStyles,
76
+ animatedProperties: ['checkmarkWrapper:unchecked','checkmarkWrapper:disabled', 'checkmarkWrapper:checked', 'checkmarkWrapper:disabled-unchecked', 'checkmarkWrapper:disabled-checked'],
77
+ updater: () =>{
78
+ 'worklet'
79
+ let disabledStyle = {}
80
+ if(disabled){
81
+ disabledStyle = value ? variantStyles['checkmarkWrapper:disabled-checked'] : variantStyles['checkmarkWrapper:disabled-unchecked']
82
+ }
83
+ const style = value ? variantStyles['checkmarkWrapper:checked'] : variantStyles['checkmarkWrapper:unchecked']
84
+ return {
85
+ ...style,
86
+ ...disabledStyle
87
+ }
88
+
89
+ },
90
+ dependencies: [value, disabled],
91
+ })
92
+
93
+ const _checkboxOnLeft = checkboxOnLeft ?? variantStyles['__props']?.checkboxOnLeft
94
+
95
+ const handleChange = () => {
96
+ if (disabled) return
97
+ if(onValueChange) onValueChange?.(!value)
98
+ }
99
+
100
+ return <InputBase
101
+ {...inputBaseProps}
102
+ debugName={debugName}
103
+ styles={{
104
+ ...variantStyles,
105
+ innerWrapper: [
106
+ variantStyles.innerWrapper,
107
+ ],
108
+ }}
109
+ order={_checkboxOnLeft ? reversedOrder : InputBaseDefaultOrder}
110
+ style={style}
111
+ >
112
+ <motion.div
113
+ css={[
114
+ variantStyles.box,
115
+ disabled && variantStyles['box:disabled'],
116
+ ]}
117
+ initial={false}
118
+ animate={boxAnimation}
119
+ transition={variantStyles['box:transition']}
120
+ onClick={handleChange}
121
+ >
122
+ <motion.div
123
+ css={[
124
+ variantStyles.checkmarkWrapper,
125
+ disabled && variantStyles['checkmarkWrapper:disabled'],
126
+ ]}
127
+ initial={false}
128
+ animate={checkmarkWrapperAnimation}
129
+ transition={variantStyles['checkmarkWrapper:transition']}
130
+ >
131
+ <Icon
132
+ name={'checkbox-checkmark' as any}
133
+ css={[variantStyles.checkmark, disabled && variantStyles['checkmark:disabled']]}
134
+ />
135
+ </motion.div>
136
+ </motion.div>
137
+ </InputBase>
138
+ }
@@ -0,0 +1,20 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
2
+ import { InputBaseParts, InputBaseStates } from '../InputBase'
3
+
4
+ type AnimatableParts = 'checkmarkWrapper' | 'box'
5
+ export type CheckboxParts = InputBaseParts | AnimatableParts | 'checkmark'
6
+
7
+ export type CheckboxAnimationStates = 'checked' | 'unchecked' | 'disabled-checked' | 'disabled-unchecked'
8
+
9
+ export type CheckboxStates = InputBaseStates
10
+
11
+ export type CheckboxComposition =
12
+ | CheckboxParts
13
+ | `${CheckboxParts}:${CheckboxStates}`
14
+ | `${AnimatableParts}:transition`
15
+ | `${AnimatableParts}:${CheckboxAnimationStates}`
16
+ | '__props'
17
+
18
+ const createCheckboxStyle = createDefaultVariantFactory<CheckboxComposition>()
19
+
20
+ export const CheckboxPresets = includePresets((styles) => createCheckboxStyle(() => ({ wrapper: styles })))
@@ -0,0 +1,87 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react'
3
+
4
+ import { capitalize, TypeGuards } from '@codeleap/common'
5
+ import { Scroll } from '../Scroll'
6
+ import { View, ViewProps } from '../View'
7
+ import { ElementType } from 'react'
8
+
9
+ export type CollapseAxis = 'horizontal' | 'vertical'
10
+
11
+ export type GetCollapseStylesArgs = {
12
+ direction?: CollapseAxis
13
+ value: string | number
14
+ animation?: string
15
+ scroll ?: boolean
16
+ }
17
+
18
+ type CollapseComposition = 'wrapper' | 'wrapper:open' |'wrapper:hidden'
19
+
20
+ export function getCollapseStyles<
21
+ TCSS = React.CSSProperties,
22
+ Return extends Record<CollapseComposition, TCSS> = Record<CollapseComposition, TCSS>
23
+ >(
24
+ args: GetCollapseStylesArgs,
25
+ ): Return {
26
+ const {
27
+ direction = 'vertical',
28
+ value,
29
+ animation = '0.3s ease',
30
+ scroll = false,
31
+
32
+ } = args
33
+
34
+ const dimension = direction === 'horizontal' ? 'width' : 'height'
35
+ const capitalizedDimension = capitalize(dimension)
36
+ const overflowOpen = scroll ? 'auto' : 'hidden'
37
+ const axis = direction === 'vertical' ? 'Y' : 'X'
38
+ return {
39
+ 'wrapper:closed': {
40
+ [`max${capitalizedDimension}`]: '0px',
41
+ [`overflow${axis}`]: 'hidden',
42
+ },
43
+ 'wrapper:open': {
44
+ [`max${capitalizedDimension}`]: TypeGuards.isString(value) ? value : `${value}px`,
45
+ [`overflow${axis}`]: overflowOpen,
46
+ },
47
+ wrapper: {
48
+ height: 'auto',
49
+ transition: `max-${dimension} ${animation}`,
50
+ },
51
+ } as unknown as Return
52
+ }
53
+
54
+ export type CollapseProps<T extends ElementType = 'div'> = ViewProps<T> & {
55
+ open: boolean
56
+ scroll?: boolean
57
+ size?: string | number
58
+ direction?: CollapseAxis
59
+ animation?: string
60
+ }
61
+
62
+ export const Collapse:React.FC<CollapseProps> = ({
63
+ open,
64
+ size = 1000,
65
+ scroll = false,
66
+ children,
67
+ direction,
68
+ animation,
69
+ ...props
70
+ }) => {
71
+
72
+ const Component = scroll ? Scroll : View
73
+ const styles = getCollapseStyles({
74
+ value: size,
75
+ direction,
76
+ animation,
77
+ })
78
+ // @ts-ignore
79
+ return <Component css={[
80
+ styles.wrapper,
81
+ open ? styles['wrapper:open'] : styles['wrapper:closed'],
82
+ ]} {...props}>
83
+ {children}
84
+ </Component>
85
+ }
86
+
87
+ export * from './styles'
@@ -0,0 +1,8 @@
1
+ import { createDefaultVariantFactory, includePresets } from "@codeleap/common"
2
+ import { ViewComposition } from "../View"
3
+
4
+ export type CollapseComposition = ViewComposition
5
+
6
+ const createCollapseStyle = createDefaultVariantFactory<CollapseComposition>()
7
+
8
+ export const CollapsePresets = includePresets((styles) => createCollapseStyle(() => ({ wrapper: styles })))