@chem-po/react-web 0.0.29 → 0.0.31
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/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/form/input/Editable.tsx +46 -8
- package/src/components/form/input/select/index.tsx +13 -4
- package/src/components/loading/LoadingImage.tsx +7 -2
- package/src/components/modal/DesktopModal.tsx +12 -8
- package/src/index.ts +1 -0
- package/src/types/forms.ts +5 -0
- package/src/types/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chem-po/react-web",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.31",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"author": "",
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@chem-po/core": "0.0.
|
|
20
|
-
"@chem-po/react": "0.0.
|
|
19
|
+
"@chem-po/core": "0.0.31",
|
|
20
|
+
"@chem-po/react": "0.0.31",
|
|
21
21
|
"@chakra-ui/anatomy": "^2.3.4",
|
|
22
22
|
"@chakra-ui/icons": "^2.2.4",
|
|
23
23
|
"@chakra-ui/react": "^2.10.7",
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { CheckIcon, CloseIcon, EditIcon } from '@chakra-ui/icons'
|
|
2
2
|
import { Flex, IconButton } from '@chakra-ui/react'
|
|
3
3
|
import { palette } from '@chem-po/core'
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
CustomEditableViewProps,
|
|
6
|
+
EditableProps,
|
|
7
|
+
Field,
|
|
8
|
+
useColorModeValue,
|
|
9
|
+
useEditable,
|
|
10
|
+
} from '@chem-po/react'
|
|
11
|
+
import React, { CSSProperties, useCallback, useEffect, useMemo } from 'react'
|
|
12
|
+
import { CustomInputProps } from '../../../types/forms'
|
|
6
13
|
import { LoadingOverlay } from '../../loading/Loading'
|
|
7
14
|
import { UploadProgress } from '../UploadProgress'
|
|
8
15
|
import { FieldView } from '../view'
|
|
@@ -16,7 +23,11 @@ export const Editable = <T extends Field>({
|
|
|
16
23
|
style,
|
|
17
24
|
onEditClose,
|
|
18
25
|
onEditOpen,
|
|
19
|
-
|
|
26
|
+
CustomInput,
|
|
27
|
+
CustomView,
|
|
28
|
+
containerStyle,
|
|
29
|
+
size,
|
|
30
|
+
}: EditableProps<CSSProperties, CSSProperties, T>) => {
|
|
20
31
|
const {
|
|
21
32
|
inputRef,
|
|
22
33
|
setValue,
|
|
@@ -38,7 +49,10 @@ export const Editable = <T extends Field>({
|
|
|
38
49
|
onEditOpen,
|
|
39
50
|
onEditClose,
|
|
40
51
|
})
|
|
41
|
-
const alwaysEditing = useMemo(
|
|
52
|
+
const alwaysEditing = useMemo(
|
|
53
|
+
() => field && (field._type === 'file' || field._type === 'boolean'),
|
|
54
|
+
[field],
|
|
55
|
+
)
|
|
42
56
|
useEffect(() => {
|
|
43
57
|
if (isEditing) {
|
|
44
58
|
inputRef.current?.focus()
|
|
@@ -47,12 +61,35 @@ export const Editable = <T extends Field>({
|
|
|
47
61
|
|
|
48
62
|
const editingBorderColor = useColorModeValue('#00000055', '#ffffff55')
|
|
49
63
|
|
|
64
|
+
const RenderInput = useCallback(
|
|
65
|
+
(props: CustomInputProps<T['defaultValue']>) => {
|
|
66
|
+
if (CustomInput) {
|
|
67
|
+
return <CustomInput {...props} />
|
|
68
|
+
}
|
|
69
|
+
if (!field) throw new Error('Editable component must have a field OR a CustomInput')
|
|
70
|
+
return <StandaloneInput field={field} {...props} />
|
|
71
|
+
},
|
|
72
|
+
[CustomInput, field],
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
const RenderView = useCallback(
|
|
76
|
+
(props: CustomEditableViewProps<T['defaultValue']>) => {
|
|
77
|
+
if (CustomView) {
|
|
78
|
+
return <CustomView {...props} />
|
|
79
|
+
}
|
|
80
|
+
if (!field) throw new Error('Editable component must have a field OR a CustomView')
|
|
81
|
+
return <FieldView style={style} field={field} value={value} {...props} />
|
|
82
|
+
},
|
|
83
|
+
[CustomView, field, style, value],
|
|
84
|
+
)
|
|
85
|
+
|
|
50
86
|
return (
|
|
51
87
|
<Flex
|
|
52
88
|
borderRadius={4}
|
|
53
89
|
border={`1px dashed ${editHovered && !isEditing ? editingBorderColor : 'transparent'}`}
|
|
54
90
|
flexFlow="column"
|
|
55
|
-
w="100%"
|
|
91
|
+
w="100%"
|
|
92
|
+
style={containerStyle}>
|
|
56
93
|
<Flex align="center" px={1} position="relative" w="100%">
|
|
57
94
|
<Flex
|
|
58
95
|
opacity={isLoading ? 0 : 1}
|
|
@@ -62,16 +99,17 @@ export const Editable = <T extends Field>({
|
|
|
62
99
|
flex={1}
|
|
63
100
|
minW="0">
|
|
64
101
|
{isEditing || alwaysEditing ? (
|
|
65
|
-
<
|
|
102
|
+
<RenderInput
|
|
66
103
|
ref={inputRef}
|
|
67
104
|
value={value}
|
|
68
105
|
inEditable
|
|
69
|
-
field={field}
|
|
70
106
|
style={{ padding: 0, ...style }}
|
|
107
|
+
size={size}
|
|
71
108
|
onChange={alwaysEditing ? v => submitValue(v) : setValue}
|
|
109
|
+
inputStyle={style}
|
|
72
110
|
/>
|
|
73
111
|
) : (
|
|
74
|
-
<
|
|
112
|
+
<RenderView inEditable size={size} value={value} />
|
|
75
113
|
)}
|
|
76
114
|
</Flex>
|
|
77
115
|
{alwaysEditing ? null : (
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Button,
|
|
3
3
|
Popover,
|
|
4
|
-
PopoverArrow,
|
|
5
4
|
PopoverBody,
|
|
6
5
|
PopoverContent,
|
|
7
6
|
PopoverTrigger,
|
|
@@ -9,7 +8,7 @@ import {
|
|
|
9
8
|
useColorMode,
|
|
10
9
|
} from '@chakra-ui/react'
|
|
11
10
|
import { InputRef, RenderSelectOptionProps } from '@chem-po/core'
|
|
12
|
-
import { SelectField } from '@chem-po/react'
|
|
11
|
+
import { SelectField, useBackgroundColor } from '@chem-po/react'
|
|
13
12
|
import React, { forwardRef, useImperativeHandle, useMemo } from 'react'
|
|
14
13
|
import { useInputStyles } from '../hooks/useInputStyles'
|
|
15
14
|
import { InputContainer } from '../shared/InputContainer'
|
|
@@ -31,6 +30,7 @@ export const SelectComponent = forwardRef<InputRef, FieldProps<SelectField>>(
|
|
|
31
30
|
onBlur()
|
|
32
31
|
},
|
|
33
32
|
}))
|
|
33
|
+
const menuBg = useBackgroundColor(150)
|
|
34
34
|
|
|
35
35
|
const DefaultRenderOption = (props: RenderSelectOptionProps) => {
|
|
36
36
|
return <Text style={text}>{props.option.label}</Text>
|
|
@@ -66,7 +66,13 @@ export const SelectComponent = forwardRef<InputRef, FieldProps<SelectField>>(
|
|
|
66
66
|
</InputContainer>
|
|
67
67
|
</Button>
|
|
68
68
|
</PopoverTrigger>
|
|
69
|
-
<PopoverContent
|
|
69
|
+
<PopoverContent
|
|
70
|
+
w="100%"
|
|
71
|
+
overflowY="auto"
|
|
72
|
+
maxH="300px"
|
|
73
|
+
bg={menuBg}
|
|
74
|
+
border="none"
|
|
75
|
+
boxShadow="0 0 8px rgba(0, 0, 0, 0.3)">
|
|
70
76
|
<PopoverBody p={0}>
|
|
71
77
|
{options.map(o => (
|
|
72
78
|
<Button
|
|
@@ -78,6 +84,10 @@ export const SelectComponent = forwardRef<InputRef, FieldProps<SelectField>>(
|
|
|
78
84
|
onChange(o.value)
|
|
79
85
|
onBlur()
|
|
80
86
|
}}
|
|
87
|
+
display="flex"
|
|
88
|
+
justifyContent="flex-start"
|
|
89
|
+
alignItems="center"
|
|
90
|
+
px={3}
|
|
81
91
|
_hover={{ bg: 'blackAlpha.100' }}
|
|
82
92
|
_dark={{
|
|
83
93
|
_hover: { bg: 'whiteAlpha.100' },
|
|
@@ -92,7 +102,6 @@ export const SelectComponent = forwardRef<InputRef, FieldProps<SelectField>>(
|
|
|
92
102
|
</Button>
|
|
93
103
|
))}
|
|
94
104
|
</PopoverBody>
|
|
95
|
-
<PopoverArrow />
|
|
96
105
|
</PopoverContent>
|
|
97
106
|
</Popover>
|
|
98
107
|
)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BoxProps, Center, IconButton, Image, ImageProps } from '@chakra-ui/react'
|
|
2
|
-
import { useMounted } from '@chem-po/react'
|
|
2
|
+
import { useColorModeValue, useMounted } from '@chem-po/react'
|
|
3
3
|
import React, { SyntheticEvent, useCallback, useEffect, useRef, useState } from 'react'
|
|
4
4
|
import { ImageViewOverlay } from '../overlay/ImageViewOverlay'
|
|
5
5
|
import { LoadingLogo } from './Loading'
|
|
@@ -52,6 +52,11 @@ export const LoadingImage = ({
|
|
|
52
52
|
if (src) setPrevSrc(src)
|
|
53
53
|
}, [src, prevSrc])
|
|
54
54
|
|
|
55
|
+
const fullViewButtonFilter = useColorModeValue(
|
|
56
|
+
'none',
|
|
57
|
+
'brightness(300%) drop-shadow(1px 1px 3px #00000066)',
|
|
58
|
+
)
|
|
59
|
+
|
|
55
60
|
const loading = imageLoading || !!loadingOverride
|
|
56
61
|
return (
|
|
57
62
|
<Center
|
|
@@ -97,7 +102,7 @@ export const LoadingImage = ({
|
|
|
97
102
|
height="20px"
|
|
98
103
|
src="/icons/open_in_full.svg"
|
|
99
104
|
opacity={0.8}
|
|
100
|
-
filter=
|
|
105
|
+
filter={fullViewButtonFilter}
|
|
101
106
|
/>
|
|
102
107
|
}
|
|
103
108
|
onClick={() => setViewing(true)}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { Box, Modal, ModalContent, ModalOverlay } from '@chakra-ui/react'
|
|
2
|
+
import { useBackgroundColor } from '@chem-po/react'
|
|
2
3
|
import React from 'react'
|
|
3
4
|
import { DefaultModalProps } from './type'
|
|
4
5
|
|
|
5
|
-
export const DesktopModal = ({ children, isOpen, contentProps, ...props }: DefaultModalProps) =>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
<
|
|
9
|
-
<
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
export const DesktopModal = ({ children, isOpen, contentProps, ...props }: DefaultModalProps) => {
|
|
7
|
+
const bg = useBackgroundColor(100)
|
|
8
|
+
return (
|
|
9
|
+
<Modal scrollBehavior="inside" isCentered isOpen={isOpen} {...props}>
|
|
10
|
+
<ModalOverlay />
|
|
11
|
+
<ModalContent position="relative" overflowY="auto" bg={bg} {...contentProps}>
|
|
12
|
+
<Box>{children}</Box>
|
|
13
|
+
</ModalContent>
|
|
14
|
+
</Modal>
|
|
15
|
+
)
|
|
16
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BaseCustomInput, BaseCustomInputProps } from '@chem-po/react'
|
|
2
|
+
import { CSSProperties } from 'react'
|
|
3
|
+
|
|
4
|
+
export type CustomInput<Value> = BaseCustomInput<Value, CSSProperties, CSSProperties>
|
|
5
|
+
export type CustomInputProps<Value> = BaseCustomInputProps<Value, CSSProperties, CSSProperties>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './forms'
|