@hero-design/rn-work-uikit 1.5.0 → 1.6.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.
- package/CHANGELOG.md +13 -0
- package/lib/index.js +141 -66
- package/package.json +2 -2
- package/src/components/DatePicker/__tests__/__snapshots__/index.spec.tsx.snap +33 -0
- package/src/components/FormGroup/__tests__/index.spec.tsx +62 -49
- package/src/components/RichTextEditor/RichTextEditor.tsx +15 -24
- package/src/components/RichTextEditor/StyledRichTextEditor.tsx +9 -3
- package/src/components/RichTextEditor/__tests__/RichTextEditor.spec.tsx +81 -0
- package/src/components/RichTextEditor/index.tsx +2 -4
- package/src/components/RichTextEditor/types.ts +12 -1
- package/stats/1.6.0/rn-work-uikit-stats.html +4844 -0
- package/testUtils/setup.tsx +19 -1
- package/src/components/RichTextEditor/__mocks__/hero-editor.js +0 -3
- package/stats/1.5.0/rn-work-uikit-stats.html +0 -4844
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import type { ComponentType, ReactElement } from 'react';
|
|
1
2
|
import React, { useMemo } from 'react';
|
|
2
|
-
import type { ComponentType, ReactElement, Ref } from 'react';
|
|
3
|
-
import type { StyleProp, ViewStyle } from 'react-native';
|
|
4
3
|
|
|
5
4
|
import { plainSerializer } from 'hero-editor';
|
|
6
|
-
import
|
|
5
|
+
import { InternalTextInput } from '../TextInput';
|
|
7
6
|
import RichTextEditorInput from './RichTextEditorInput';
|
|
8
|
-
import type { EditorValue, TextUnit } from './types';
|
|
9
7
|
import { StyledWrapper } from './StyledRichTextEditor';
|
|
8
|
+
import type {
|
|
9
|
+
EditorValue,
|
|
10
|
+
InternalRichTextEditorProps,
|
|
11
|
+
TextUnit,
|
|
12
|
+
} from './types';
|
|
10
13
|
|
|
11
14
|
export interface RichTextEditorRef {
|
|
12
15
|
requestBlur: VoidFunction;
|
|
@@ -15,22 +18,6 @@ export interface RichTextEditorRef {
|
|
|
15
18
|
setReadOnly: (readOnly: boolean) => void;
|
|
16
19
|
}
|
|
17
20
|
|
|
18
|
-
export interface RichTextEditorProps {
|
|
19
|
-
autoFocus?: boolean;
|
|
20
|
-
error?: string;
|
|
21
|
-
value?: EditorValue;
|
|
22
|
-
name: string;
|
|
23
|
-
onChange: (data: EditorValue) => void;
|
|
24
|
-
onCursorChange?: (params: { position: { top: number } }) => void;
|
|
25
|
-
placeholder?: string;
|
|
26
|
-
style?: StyleProp<ViewStyle>;
|
|
27
|
-
label: string;
|
|
28
|
-
helpText?: string;
|
|
29
|
-
required?: boolean;
|
|
30
|
-
testID?: string;
|
|
31
|
-
forwardedRef?: Ref<RichTextEditorRef>;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
21
|
const defaultValue: EditorValue = [
|
|
35
22
|
{
|
|
36
23
|
type: 'paragraph',
|
|
@@ -38,7 +25,7 @@ const defaultValue: EditorValue = [
|
|
|
38
25
|
},
|
|
39
26
|
];
|
|
40
27
|
|
|
41
|
-
const RichTextEditor: ComponentType<
|
|
28
|
+
const RichTextEditor: ComponentType<InternalRichTextEditorProps> = ({
|
|
42
29
|
autoFocus = true,
|
|
43
30
|
name,
|
|
44
31
|
placeholder = '',
|
|
@@ -46,18 +33,20 @@ const RichTextEditor: ComponentType<RichTextEditorProps> = ({
|
|
|
46
33
|
onCursorChange,
|
|
47
34
|
error = '',
|
|
48
35
|
style = {},
|
|
36
|
+
textStyle,
|
|
49
37
|
label,
|
|
50
38
|
helpText,
|
|
51
39
|
required,
|
|
52
40
|
testID,
|
|
53
41
|
forwardedRef,
|
|
54
42
|
value = defaultValue,
|
|
55
|
-
|
|
43
|
+
groupStyleEnabled = false,
|
|
44
|
+
}: InternalRichTextEditorProps): ReactElement => {
|
|
56
45
|
const plain = useMemo(() => plainSerializer(value), [value]);
|
|
57
46
|
|
|
58
47
|
return (
|
|
59
|
-
<StyledWrapper>
|
|
60
|
-
<
|
|
48
|
+
<StyledWrapper groupStyleEnabled={groupStyleEnabled}>
|
|
49
|
+
<InternalTextInput
|
|
61
50
|
autoFocus={autoFocus}
|
|
62
51
|
error={error}
|
|
63
52
|
label={label}
|
|
@@ -66,7 +55,9 @@ const RichTextEditor: ComponentType<RichTextEditorProps> = ({
|
|
|
66
55
|
placeholder={placeholder}
|
|
67
56
|
value={plain}
|
|
68
57
|
style={style}
|
|
58
|
+
textStyle={textStyle}
|
|
69
59
|
helpText={helpText}
|
|
60
|
+
groupStyleEnabled={groupStyleEnabled}
|
|
70
61
|
renderInputValue={(inputProps, ref) => (
|
|
71
62
|
<RichTextEditorInput
|
|
72
63
|
{...inputProps}
|
|
@@ -2,9 +2,15 @@ import { styled } from '@hero-design/rn';
|
|
|
2
2
|
import { View } from 'react-native';
|
|
3
3
|
import { WebView } from 'react-native-webview';
|
|
4
4
|
|
|
5
|
-
export const StyledWrapper = styled(View)
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export const StyledWrapper = styled(View)<{ groupStyleEnabled?: boolean }>(
|
|
6
|
+
({ theme, groupStyleEnabled }) => ({
|
|
7
|
+
...(groupStyleEnabled
|
|
8
|
+
? {}
|
|
9
|
+
: {
|
|
10
|
+
marginBottom: theme.__hd__.richTextEditor.space.wrapperMarginBottom,
|
|
11
|
+
}),
|
|
12
|
+
})
|
|
13
|
+
);
|
|
8
14
|
|
|
9
15
|
export const StyledWebView = styled(WebView)(({ theme }) => ({
|
|
10
16
|
minHeight: theme.__hd__.richTextEditor.sizes.editorMinHeight,
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import RichTextEditor from '../RichTextEditor';
|
|
3
|
+
import renderWithTheme from '../../../../testUtils/renderWithTheme';
|
|
4
|
+
|
|
5
|
+
const initialValue = [
|
|
6
|
+
{ type: 'paragraph', children: [{ text: 'Hello world' }] },
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
describe('RichTextEditor zIndex', () => {
|
|
10
|
+
it('applies correct zIndex logic when groupStyleEnabled is true', () => {
|
|
11
|
+
const { getByTestId } = renderWithTheme(
|
|
12
|
+
<RichTextEditor
|
|
13
|
+
label="Test Editor"
|
|
14
|
+
value={initialValue}
|
|
15
|
+
onChange={jest.fn()}
|
|
16
|
+
name="test-editor"
|
|
17
|
+
testID="rich-text-editor"
|
|
18
|
+
groupStyleEnabled
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const container = getByTestId('rich-text-editor');
|
|
23
|
+
|
|
24
|
+
// Initially should have zIndex 0 (normal state)
|
|
25
|
+
expect(container.props.style.flat()).toEqual(
|
|
26
|
+
expect.arrayContaining([
|
|
27
|
+
expect.objectContaining({
|
|
28
|
+
zIndex: 0,
|
|
29
|
+
}),
|
|
30
|
+
])
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('applies correct zIndex when has error', () => {
|
|
35
|
+
const { getByTestId } = renderWithTheme(
|
|
36
|
+
<RichTextEditor
|
|
37
|
+
label="Test Editor"
|
|
38
|
+
value={initialValue}
|
|
39
|
+
onChange={jest.fn()}
|
|
40
|
+
name="test-editor"
|
|
41
|
+
testID="rich-text-editor"
|
|
42
|
+
error="This is an error"
|
|
43
|
+
groupStyleEnabled
|
|
44
|
+
/>
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const container = getByTestId('rich-text-editor');
|
|
48
|
+
|
|
49
|
+
// Should have zIndex 1 when has error (medium priority)
|
|
50
|
+
expect(container.props.style.flat()).toEqual(
|
|
51
|
+
expect.arrayContaining([
|
|
52
|
+
expect.objectContaining({
|
|
53
|
+
zIndex: 1,
|
|
54
|
+
}),
|
|
55
|
+
])
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('does not apply zIndex when groupStyleEnabled is false', () => {
|
|
60
|
+
const { getByTestId } = renderWithTheme(
|
|
61
|
+
<RichTextEditor
|
|
62
|
+
label="Test Editor"
|
|
63
|
+
value={initialValue}
|
|
64
|
+
onChange={jest.fn()}
|
|
65
|
+
name="test-editor"
|
|
66
|
+
testID="rich-text-editor"
|
|
67
|
+
groupStyleEnabled={false}
|
|
68
|
+
error="This is an error"
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const container = getByTestId('rich-text-editor');
|
|
73
|
+
|
|
74
|
+
// Should not have zIndex applied when groupStyleEnabled is false
|
|
75
|
+
const containerStyle = container.props.style.flat();
|
|
76
|
+
const hasZIndex = containerStyle.some(
|
|
77
|
+
(style: Record<string, unknown>) => style && style.zIndex !== undefined
|
|
78
|
+
);
|
|
79
|
+
expect(hasZIndex).toBe(false);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react';
|
|
2
|
-
import RichTextEditor, {
|
|
3
|
-
RichTextEditorProps,
|
|
4
|
-
RichTextEditorRef,
|
|
5
|
-
} from './RichTextEditor';
|
|
2
|
+
import RichTextEditor, { RichTextEditorRef } from './RichTextEditor';
|
|
6
3
|
import MentionList from './MentionList';
|
|
4
|
+
import type { RichTextEditorProps } from './types';
|
|
7
5
|
|
|
8
6
|
import Toolbar from './EditorToolbar';
|
|
9
7
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StyleProp, ViewStyle } from 'react-native';
|
|
1
|
+
import type { StyleProp, ViewStyle, TextStyle } from 'react-native';
|
|
2
2
|
|
|
3
3
|
import { Ref } from 'react';
|
|
4
4
|
import type { TextInputProps } from '../TextInput';
|
|
@@ -83,5 +83,16 @@ export interface RichTextEditorProps {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
export interface InternalRichTextEditorProps extends RichTextEditorProps {
|
|
86
|
+
/**
|
|
87
|
+
* Input text style
|
|
88
|
+
*/
|
|
89
|
+
textStyle?: StyleProp<TextStyle>;
|
|
90
|
+
/**
|
|
91
|
+
* Whether the component is used within a FormGroup
|
|
92
|
+
*/
|
|
93
|
+
groupStyleEnabled?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Custom TextInput component to be used instead of the default one
|
|
96
|
+
*/
|
|
86
97
|
TextInputComponent?: React.ComponentType<TextInputProps>;
|
|
87
98
|
}
|