39 |
40 |
50 |
grommet designer
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/src/Properties/ComponentInput.js:
--------------------------------------------------------------------------------
1 | import React, { useCallback, useContext } from 'react';
2 | import { Box, Button } from 'grommet';
3 | import { Add, Close, Edit } from 'grommet-icons';
4 | import { getComponent, removeComponent } from '../design2';
5 | import SelectionContext from '../SelectionContext';
6 |
7 | const ComponentInput = ({ id, htmlId, name, onChange, value }) => {
8 | const [, setSelection, { setLocation }] = useContext(SelectionContext);
9 |
10 | const onChangeAndSet = useCallback(
11 | (nextValue) => {
12 | onChange(nextValue);
13 | // update location so Tree knows about the new value to start with
14 | setLocation({ property: { id, value: nextValue, onChangeAndSet } });
15 | },
16 | [id, onChange, setLocation],
17 | );
18 |
19 | if (value && typeof value === 'string') return null;
20 | // if we have a value ensure we have a component there. if not, clear it
21 | if (value && !getComponent(value)) onChange(undefined);
22 |
23 | return (
24 |