@codeleap/web 3.1.2 → 3.2.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.
Files changed (41) hide show
  1. package/package.json +13 -10
  2. package/src/components/ActionIcon/index.tsx +24 -15
  3. package/src/components/ActivityIndicator/index.tsx +39 -46
  4. package/src/components/ActivityIndicator/styles.ts +7 -11
  5. package/src/components/Button/index.tsx +17 -21
  6. package/src/components/Checkbox/index.tsx +103 -96
  7. package/src/components/Collapse/index.tsx +4 -3
  8. package/src/components/Drawer/index.tsx +25 -17
  9. package/src/components/FileInput.tsx +60 -32
  10. package/src/components/Icon/index.tsx +6 -5
  11. package/src/components/InputBase/index.tsx +9 -4
  12. package/src/components/InputBase/types.ts +1 -0
  13. package/src/components/List/index.tsx +3 -0
  14. package/src/components/LoadingOverlay/index.tsx +36 -23
  15. package/src/components/Modal/index.tsx +260 -88
  16. package/src/components/Modal/styles.ts +3 -4
  17. package/src/components/NumberIncrement/index.tsx +2 -0
  18. package/src/components/Overlay/index.tsx +11 -10
  19. package/src/components/Pager/index.tsx +166 -0
  20. package/src/components/Pager/styles.ts +14 -0
  21. package/src/components/RadioInput/index.tsx +21 -19
  22. package/src/components/Scroll/index.tsx +6 -3
  23. package/src/components/SegmentedControl/SegmentedControlOption.tsx +78 -0
  24. package/src/components/SegmentedControl/index.tsx +161 -0
  25. package/src/components/SegmentedControl/styles.ts +26 -0
  26. package/src/components/Select/index.tsx +13 -11
  27. package/src/components/Select/types.ts +23 -23
  28. package/src/components/Slider/index.tsx +77 -72
  29. package/src/components/Switch/index.tsx +96 -93
  30. package/src/components/Text/index.tsx +18 -33
  31. package/src/components/TextInput/index.tsx +14 -8
  32. package/src/components/Tooltip/index.tsx +1 -1
  33. package/src/components/Touchable/index.tsx +16 -18
  34. package/src/components/View/index.tsx +49 -25
  35. package/src/components/View/styles.ts +0 -1
  36. package/src/components/components.ts +2 -2
  37. package/src/components/defaultStyles.ts +16 -3
  38. package/src/lib/OSAlert.tsx +1 -1
  39. package/src/types/utility.ts +31 -2
  40. package/src/components/Link/index.tsx +0 -69
  41. package/src/components/Link/styles.ts +0 -11
@@ -1,8 +1,12 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react'
3
+
1
4
  import {
2
5
  AnyFunction,
3
6
  ComponentVariants,
4
7
  IconPlaceholder,
5
8
  onUpdate,
9
+ TypeGuards,
6
10
  useDefaultComponentStyle,
7
11
  } from '@codeleap/common'
8
12
  import { CSSObject } from '@emotion/react'
@@ -13,6 +17,7 @@ import { Text } from '../Text'
13
17
  import { Button } from '../Button'
14
18
  import { StylesOf } from '../../types/utility'
15
19
  import { DrawerComposition, DrawerPresets } from './styles'
20
+ import { ActionIcon } from '../ActionIcon'
16
21
 
17
22
  const axisMap = {
18
23
  top: [-1, 'Y'],
@@ -54,7 +59,7 @@ const resolveHiddenDrawerPosition = (
54
59
  return [css, translateAxis, positioning]
55
60
  }
56
61
 
57
- export const Drawer: React.FC<DrawerProps> = ({ ...rawProps }) => {
62
+ export const Drawer = ({ ...rawProps }:DrawerProps) => {
58
63
  const {
59
64
  open,
60
65
  toggle,
@@ -119,21 +124,24 @@ export const Drawer: React.FC<DrawerProps> = ({ ...rawProps }) => {
119
124
  ...variantStyles.box,
120
125
  }}
121
126
  >
122
- <View
123
- component='header'
124
- variants={['justifySpaceBetween']}
125
- css={variantStyles.header}
126
- >
127
- {typeof title === 'string' ? <Text text={title} /> : title}
128
- {showCloseButton && (
129
- <Button
130
- onPress={toggle}
131
- icon={'close' as IconPlaceholder}
132
- variants={['icon']}
133
- css={variantStyles.headerCloseButton}
134
- />
135
- )}
136
- </View>
127
+ {
128
+ !TypeGuards.isNil(title) || showCloseButton && (
129
+ <View
130
+ component='header'
131
+ variants={['justifySpaceBetween']}
132
+ css={variantStyles.header}
133
+ >
134
+ {typeof title === 'string' ? <Text text={title} /> : title}
135
+ {showCloseButton && (
136
+ <ActionIcon
137
+ onPress={toggle}
138
+ icon={'close' as IconPlaceholder}
139
+ css={variantStyles.headerCloseButton}
140
+ />
141
+ )}
142
+ </View>
143
+ )
144
+ }
137
145
  <View css={variantStyles.body}>{children}</View>
138
146
  {footer && (
139
147
  <View component='footer' css={variantStyles.footer}>
@@ -145,4 +153,4 @@ export const Drawer: React.FC<DrawerProps> = ({ ...rawProps }) => {
145
153
  )
146
154
  }
147
155
 
148
- export * from './styles'
156
+ export * from './styles'
@@ -1,51 +1,79 @@
1
+ /** @jsx jsx */
2
+ import { jsx, CSSObject } from '@emotion/react'
1
3
  import React, {
2
- ComponentPropsWithoutRef,
3
4
  useImperativeHandle,
4
5
  useRef,
5
6
  } from 'react'
6
7
  import { WebInputFile } from '@codeleap/common'
8
+ import { HTMLProps } from '../types'
7
9
 
8
10
  export type FileInputRef = {
9
- openFilePicker: () => void
11
+ openFilePicker: () => Promise<WebInputFile[]>
10
12
  }
11
13
 
12
- export type FileInputProps = Omit<ComponentPropsWithoutRef<'input'>, 'type'> & {
13
- onFileSelect(files: WebInputFile[]): void
14
+ export type FileInputProps = Omit<HTMLProps<'input'>, 'type'|'ref'> & {
15
+ onFileSelect?: (files: WebInputFile[]) => void
14
16
  }
15
17
 
16
- export const FileInput = React.forwardRef<FileInputRef, FileInputProps>(
17
- (inputProps, ref) => {
18
- const inputRef = useRef<HTMLInputElement>(null)
18
+ export const _FileInput = (inputProps: FileInputProps, ref:React.Ref<FileInputRef>) => {
19
+ const inputRef = useRef<HTMLInputElement>(null)
19
20
 
20
- const { onFileSelect, ...props } = inputProps
21
+ const { onFileSelect, ...props } = inputProps
21
22
 
22
- useImperativeHandle(ref, () => ({
23
- openFilePicker: () => {
24
- inputRef.current.click()
25
- },
26
- }))
23
+ const resolveWithFile = useRef<(file:WebInputFile[]) => any>()
24
+
25
+ useImperativeHandle(ref, () => ({
26
+ openFilePicker: () => {
27
+ inputRef.current.click()
28
+
29
+ return new Promise<WebInputFile[]>((resolve) => {
30
+ resolveWithFile.current = resolve
31
+ })
32
+ },
33
+ }))
27
34
 
28
- function handleChange(e: React.ChangeEvent<HTMLInputElement>) {
29
- if (!e.target.files.length) return
30
- inputProps.onChange && inputProps.onChange(e)
31
- const fileArray = Array.from(e.target?.files || []) as File[]
35
+ function handleChange(e: React.ChangeEvent<HTMLInputElement>) {
36
+ if (!e.target.files.length) return
37
+ inputProps.onChange && inputProps.onChange(e)
38
+ const fileArray = Array.from(e.target?.files || []) as File[]
32
39
 
33
- const files: WebInputFile[] = fileArray.map((obj) => ({
34
- file: obj,
35
- preview: URL.createObjectURL(obj),
36
- }))
40
+ const files: WebInputFile[] = fileArray.map((obj) => ({
41
+ file: obj,
42
+ preview: URL.createObjectURL(obj),
43
+ }))
44
+
45
+ onFileSelect && onFileSelect(files)
37
46
 
38
- onFileSelect && onFileSelect(files)
47
+ if (resolveWithFile.current) {
48
+ resolveWithFile.current(files)
49
+ resolveWithFile.current = undefined
39
50
  }
51
+ }
40
52
 
41
- return (
42
- <input
43
- type={'file'}
44
- css={{ visibility: 'hidden', width: 0, height: 0, opacity: 0, display: 'none' }}
45
- {...props}
46
- ref={inputRef}
47
- onChange={handleChange}
48
- />
49
- )
50
- },
53
+ return (
54
+ <input
55
+ type={'file'}
56
+ css={{ visibility: 'hidden', width: 0, height: 0, opacity: 0, display: 'none' }}
57
+ {...props}
58
+ ref={inputRef}
59
+ onChange={handleChange}
60
+ />
61
+ )
62
+ }
63
+
64
+ export const FileInput = React.forwardRef<FileInputRef, FileInputProps>(_FileInput) as unknown as (
65
+ (props: FileInputProps & { ref?: React.MutableRefObject<FileInputRef> | React.Ref<FileInputRef> }) => JSX.Element
51
66
  )
67
+
68
+ export const useFileInput = () => {
69
+ const inputRef = useRef<FileInputRef|null>(null)
70
+
71
+ const openFilePicker = () => {
72
+ return inputRef.current?.openFilePicker()
73
+ }
74
+
75
+ return {
76
+ openFilePicker,
77
+ ref: inputRef,
78
+ }
79
+ }
@@ -1,6 +1,6 @@
1
- import React from 'react'
2
1
  /** @jsx jsx */
3
2
  import { CSSObject, jsx } from '@emotion/react'
3
+ import { CSSInterpolation } from '@emotion/css'
4
4
  import {
5
5
  ComponentVariants,
6
6
  IconPlaceholder,
@@ -8,8 +8,7 @@ import {
8
8
  useDefaultComponentStyle,
9
9
  useCodeleapContext,
10
10
  } from '@codeleap/common'
11
- import { View, ViewProps } from '../View'
12
- import { CSSInterpolation } from '@emotion/css'
11
+ import { View } from '../View'
13
12
 
14
13
  export * from './styles'
15
14
 
@@ -17,11 +16,11 @@ export type IconProps = {
17
16
  name: IconPlaceholder
18
17
  style?: any
19
18
  renderEmptySpace?: boolean
20
- css?: Array<React.CSSProperties>
21
19
  forceStyle?: CSSObject | CSSInterpolation | React.CSSProperties
20
+ css?: any
22
21
  } & ComponentVariants<typeof IconStyles>
23
22
 
24
- export const Icon: React.FC<IconProps> = ({ name, style, variants, renderEmptySpace, ...otherProps }) => {
23
+ const IconCP = ({ name, style, variants, renderEmptySpace, ...otherProps }:IconProps) => {
25
24
  const { Theme, logger } = useCodeleapContext()
26
25
  const Component = Theme?.icons?.[name]
27
26
 
@@ -51,3 +50,5 @@ export const Icon: React.FC<IconProps> = ({ name, style, variants, renderEmptySp
51
50
  }
52
51
  return <Component css={variantStyles.icon} {...otherProps}/>
53
52
  }
53
+
54
+ export const Icon = IconCP as ((props: IconProps) => jsx.JSX.Element)
@@ -1,3 +1,5 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react'
1
3
  import React from 'react'
2
4
  import { TypeGuards, getRenderedComponent } from '@codeleap/common'
3
5
  import { ActionIcon, ActionIconProps } from '../ActionIcon'
@@ -17,7 +19,7 @@ export const InputBaseDefaultOrder:InputBaseProps['order'] = [
17
19
  'error',
18
20
  ]
19
21
  const KeyPassthrough = (props: React.PropsWithChildren<any>) => {
20
- return <>{props.children}</>
22
+ return <React.Fragment>{props.children}</React.Fragment>
21
23
  }
22
24
 
23
25
  export const InputBase = React.forwardRef<unknown, InputBaseProps>((props, ref) => {
@@ -38,6 +40,7 @@ export const InputBase = React.forwardRef<unknown, InputBaseProps>((props, ref)
38
40
  disabled = false,
39
41
  order = InputBaseDefaultOrder,
40
42
  style,
43
+ noError = false,
41
44
  labelAsRow = false,
42
45
  innerWrapperRef,
43
46
  ...otherProps
@@ -81,9 +84,11 @@ export const InputBase = React.forwardRef<unknown, InputBaseProps>((props, ref)
81
84
  {children}
82
85
  {_rightIcon}
83
86
  </InnerWrapperComponent>,
84
- error: _error || <Text children={<>
85
- &nbsp;
86
- </>} css={_styles.errorStyle}/>,
87
+ error: noError ? null : (
88
+ _error || <Text children={<React.Fragment>
89
+ &nbsp;
90
+ </React.Fragment>} css={_styles.errorStyle}/>
91
+ ),
87
92
  }
88
93
 
89
94
  return (
@@ -24,5 +24,6 @@ export type InputBaseProps = React.PropsWithChildren<{
24
24
  order?: OrderedParts[]
25
25
  style?: any
26
26
  labelAsRow?: boolean
27
+ noError?: boolean
27
28
  innerWrapperRef?: React.MutableRefObject<HTMLDivElement | null>
28
29
  }>
@@ -1,3 +1,6 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react'
3
+
1
4
  import { VariableSizeList as VirtualList , VariableSizeListProps} from 'react-window'
2
5
  import { ComponentProps, CSSProperties, ReactElement } from 'react'
3
6
  import AutoSizer from 'react-virtualized-auto-sizer'
@@ -1,34 +1,47 @@
1
- import { ComponentVariants, useDefaultComponentStyle } from "@codeleap/common"
2
- import React from "react"
3
- import { StylesOf } from "../.."
4
- import { LoadingOverlayComposition, LoadingOverlayPresets } from "./styles"
5
- import {View} from '../View'
6
- import { ActivityIndicator } from "../ActivityIndicator"
1
+ import { ComponentVariants, getNestedStylesByKey, useDefaultComponentStyle } from '@codeleap/common'
2
+ import React from 'react'
3
+ import { StylesOf } from '../..'
4
+ import { LoadingOverlayComposition, LoadingOverlayPresets } from './styles'
5
+ import { View, ViewProps } from '../View'
6
+ import { ActivityIndicator, ActivityIndicatorProps } from '../ActivityIndicator'
7
7
 
8
- export type LoadingOverlayProps = React.PropsWithChildren<{
8
+ export type LoadingOverlayProps = Partial<ViewProps<'div'>> & {
9
9
  visible?: boolean
10
10
  styles?: StylesOf<LoadingOverlayComposition>
11
- }> & ComponentVariants<typeof LoadingOverlayPresets>
12
-
11
+ style?: React.CSSProperties
12
+ indicatorProps?: ActivityIndicatorProps
13
+ children?: React.ReactNode
14
+ } & ComponentVariants<typeof LoadingOverlayPresets>
13
15
 
14
16
  export const LoadingOverlay = (props: LoadingOverlayProps) => {
15
- const { visible, children, styles, variants,responsiveVariants } = props
17
+ const {
18
+ visible,
19
+ children,
20
+ styles = {},
21
+ variants = [],
22
+ responsiveVariants = {},
23
+ style = {},
24
+ indicatorProps,
25
+ ...rest
26
+ } = props
16
27
 
17
28
  const variantStyles = useDefaultComponentStyle<'u:LoadingOverlay', typeof LoadingOverlayPresets>('u:LoadingOverlay', {
18
- variants, styles, responsiveVariants, rootElement: 'wrapper'
29
+ variants,
30
+ styles,
31
+ responsiveVariants,
32
+ rootElement: 'wrapper',
19
33
  })
20
34
 
21
- return <View css={[variantStyles.wrapper, visible && variantStyles["wrapper:visible"]]}>
22
- <ActivityIndicator
23
- styles={{
24
- wrapper: [variantStyles.indicatorWrapper, visible && variantStyles["indicatorWrapper:visible"]],
25
- backCircle: [variantStyles.indicatorBackCircle, visible && variantStyles["indicatorBackCircle:visible"]],
26
- frontCircle: [variantStyles.indicatorFrontCircle, visible && variantStyles["indicatorFrontCircle:visible"]],
27
- circle: [variantStyles.indicatorCircle, visible && variantStyles["indicatorCircle:visible"]],
28
- }}
29
- />
30
- {children}
31
- </View>
35
+ const indicatorStyles = React.useMemo(() => {
36
+ return getNestedStylesByKey('indicator', variantStyles)
37
+ }, [variantStyles])
38
+
39
+ return (
40
+ <View css={[variantStyles.wrapper, visible && variantStyles['wrapper:visible'], style]} {...rest}>
41
+ <ActivityIndicator {...indicatorProps} styles={indicatorStyles} />
42
+ {children}
43
+ </View>
44
+ )
32
45
  }
33
46
 
34
- export * from './styles'
47
+ export * from './styles'