react-cosmos-ui 6.0.0-alpha.0 → 6.0.0-alpha.11
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/components/ValueInputTree/ValueInput/StringValueInput.js +19 -5
- package/dist/playground.bundle.js +35 -35
- package/dist/playground.bundle.js.map +1 -1
- package/dist/playground.js +6 -1
- package/dist/plugins/ContentOverlay/RendererNotResponding.js +1 -1
- package/dist/plugins/ContentOverlay/WelcomeCosmos.js +1 -1
- package/dist/plugins/FullScreenButton/index.js +1 -1
- package/dist/plugins/RendererPreview/checkRendererStatus.js +1 -1
- package/package.json +7 -4
|
@@ -1,18 +1,32 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
2
|
import { useFocus } from '../../../hooks/useFocus.js';
|
|
3
3
|
import { blue, grey248, grey8 } from '../../../style/colors.js';
|
|
4
4
|
import { TextContainer, TextField, TextInputContainer, TextMirror, } from '../../inputs/shared.js';
|
|
5
5
|
import { Label, ValueDataContainer } from './shared.js';
|
|
6
6
|
export function StringValueInput({ id, name, data, onChange }) {
|
|
7
7
|
const { focused, onFocus, onBlur } = useFocus();
|
|
8
|
-
|
|
8
|
+
// The data state is duplicated locally to solve the jumping cursor bug
|
|
9
|
+
// that occurs in controlled React inputs that don't immediately re-render
|
|
10
|
+
// with the new input value on change (because they await for the parent to
|
|
11
|
+
// propagate the changed value back down).
|
|
12
|
+
// https://github.com/facebook/react/issues/955
|
|
13
|
+
// https://github.com/react-cosmos/react-cosmos/issues/1372
|
|
14
|
+
const [localData, setLocalData] = useState(data);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!focused)
|
|
17
|
+
setLocalData(data);
|
|
18
|
+
}, [data, focused]);
|
|
19
|
+
const onInputChange = React.useCallback((e) => {
|
|
20
|
+
setLocalData(e.currentTarget.value);
|
|
21
|
+
onChange(e.currentTarget.value);
|
|
22
|
+
}, [onChange]);
|
|
9
23
|
// Mirror textarea behavior and add an extra row after user adds a new line
|
|
10
|
-
const mirrorText = focused ?
|
|
24
|
+
const mirrorText = focused ? localData.replace(/\n$/, `\n `) : localData;
|
|
11
25
|
return (React.createElement(React.Fragment, null,
|
|
12
26
|
React.createElement(Label, { title: name, htmlFor: id }, name),
|
|
13
27
|
React.createElement(ValueDataContainer, null,
|
|
14
28
|
React.createElement(TextInputContainer, { focused: focused, focusedBg: grey8, focusedBoxShadow: `0 0 0.5px 1px ${blue}` },
|
|
15
29
|
React.createElement(TextContainer, null,
|
|
16
|
-
React.createElement(TextMirror, { minWidth: 64, focused: focused },
|
|
17
|
-
React.createElement(TextField, { rows: 1, id: id, value:
|
|
30
|
+
React.createElement(TextMirror, { minWidth: 64, focused: focused }, localData.length > 0 || focused ? mirrorText : React.createElement("em", null, "empty")),
|
|
31
|
+
React.createElement(TextField, { rows: 1, id: id, value: localData, focused: focused, color: grey248, onChange: onInputChange, onFocus: onFocus, onBlur: onBlur }))))));
|
|
18
32
|
}
|