@teambit/compositions 1.0.667 → 1.0.669

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 (35) hide show
  1. package/composition.section.tsx +1 -1
  2. package/compositions.tsx +7 -6
  3. package/compositions.ui.runtime.tsx +11 -7
  4. package/dist/composition.section.d.ts +1 -1
  5. package/dist/composition.section.js.map +1 -1
  6. package/dist/compositions.d.ts +5 -6
  7. package/dist/compositions.graphql.d.ts +2 -2
  8. package/dist/compositions.graphql.js.map +1 -1
  9. package/dist/compositions.js.map +1 -1
  10. package/dist/compositions.main.runtime.d.ts +11 -10
  11. package/dist/compositions.main.runtime.js.map +1 -1
  12. package/dist/compositions.preview-definition.d.ts +5 -5
  13. package/dist/compositions.preview-definition.js.map +1 -1
  14. package/dist/compositions.preview.runtime.d.ts +3 -3
  15. package/dist/compositions.preview.runtime.js.map +1 -1
  16. package/dist/compositions.ui.runtime.d.ts +6 -7
  17. package/dist/compositions.ui.runtime.js.map +1 -1
  18. package/dist/{preview-1753809186996.js → preview-1753848836384.js} +2 -2
  19. package/dist/ui/composition-preview.d.ts +2 -2
  20. package/dist/ui/composition-preview.js.map +1 -1
  21. package/dist/ui/compositions-panel/compositions-panel.d.ts +1 -1
  22. package/dist/ui/compositions-panel/compositions-panel.js.map +1 -1
  23. package/dist/ui/compositions-panel/compositions-panel.module.scss +2 -0
  24. package/dist/ui/compositions-panel/live-control-input.js +62 -38
  25. package/dist/ui/compositions-panel/live-control-input.js.map +1 -1
  26. package/dist/ui/compositions-panel/live-control-panel.js +4 -1
  27. package/dist/ui/compositions-panel/live-control-panel.js.map +1 -1
  28. package/dist/ui/compositions-panel/live-control-panel.module.scss +1 -0
  29. package/package.json +19 -19
  30. package/ui/composition-preview.tsx +3 -2
  31. package/ui/compositions-panel/compositions-panel.module.scss +2 -0
  32. package/ui/compositions-panel/compositions-panel.tsx +1 -1
  33. package/ui/compositions-panel/live-control-input.tsx +111 -42
  34. package/ui/compositions-panel/live-control-panel.module.scss +1 -0
  35. package/ui/compositions-panel/live-control-panel.tsx +4 -1
@@ -1,3 +1,5 @@
1
+ /* eslint-disable no-console */
2
+
1
3
  import React from 'react';
2
4
  import classNames from 'classnames';
3
5
 
@@ -9,6 +11,8 @@ import { ColorPicker } from '@teambit/design.ui.input.color-picker';
9
11
  import { DatePicker } from '@teambit/design.inputs.date-picker';
10
12
  import { Toggle } from '@teambit/design.inputs.toggle-switch';
11
13
 
14
+ import { type SelectOption } from '@teambit/compositions.ui.composition-live-controls';
15
+
12
16
  import styles from './live-control-input.module.scss';
13
17
 
14
18
  type InputComponentProps = {
@@ -20,110 +24,174 @@ type InputComponentProps = {
20
24
 
21
25
  type InputComponent = React.FC<InputComponentProps>;
22
26
 
23
- function ShortTextInput({ id, value, onChange }: InputComponentProps) {
24
- const [inputValue, setInputValue] = React.useState(value);
27
+ function ShortTextInput({ value, onChange }: InputComponentProps) {
28
+ const [inputValue, setInputValue] = React.useState(value || '');
29
+
30
+ React.useEffect(() => {
31
+ setInputValue(value || '');
32
+ }, [value]);
33
+
25
34
  const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
26
35
  const newValue = e.target.value;
27
- onChange(newValue);
28
- setInputValue(newValue);
36
+ onChange(newValue || '');
37
+ setInputValue(newValue || '');
29
38
  };
30
- return <InputText id={id} value={inputValue} onChange={handleChange} />;
39
+
40
+ return <InputText value={inputValue} onChange={handleChange} />;
31
41
  }
32
42
 
33
- function LongTextInput({ id, value, onChange }: InputComponentProps) {
34
- const [inputValue, setInputValue] = React.useState(value);
43
+ function LongTextInput({ value, onChange }: InputComponentProps) {
44
+ const [inputValue, setInputValue] = React.useState(value || '');
45
+
46
+ React.useEffect(() => {
47
+ setInputValue(value || '');
48
+ }, [value]);
49
+
35
50
  const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
36
51
  const newValue = e.target.value;
37
- onChange(newValue);
38
- setInputValue(newValue);
52
+ onChange(newValue || '');
53
+ setInputValue(newValue || '');
39
54
  };
40
- return <TextArea id={id} value={inputValue} onChange={handleChange} />;
55
+
56
+ return <TextArea value={inputValue} onChange={handleChange} />;
41
57
  }
42
58
 
43
- function SelectInput({ id, value, onChange, meta }: InputComponentProps) {
44
- const [selectedValue, setSelectedValue] = React.useState(value);
59
+ function SelectInput({ value, onChange, meta }: InputComponentProps) {
60
+ const [selectedValue, setSelectedValue] = React.useState(value || '');
61
+
62
+ React.useEffect(() => {
63
+ setSelectedValue(value || '');
64
+ }, [value]);
65
+
45
66
  const handleChange = (newValue: any) => {
46
- onChange(newValue);
47
- setSelectedValue(newValue);
67
+ onChange(newValue || '');
68
+ setSelectedValue(newValue || '');
48
69
  };
49
- const placeholderContent = meta.options.find((o: any) => o.value === selectedValue)?.label;
70
+
71
+ const options: {
72
+ label: string;
73
+ value: string;
74
+ }[] = React.useMemo(() => {
75
+ if (!meta || !meta.options) return [];
76
+ return meta.options.map((option: SelectOption) => {
77
+ if (typeof option === 'string') {
78
+ return { label: option, value: option };
79
+ }
80
+ return option;
81
+ });
82
+ }, [meta]);
83
+
84
+ const placeholderContent = options.find((o) => o.value === selectedValue)?.label;
85
+
50
86
  return (
51
87
  <p className={classNames(styles.wrapper)}>
52
- <Dropdown id={id} placeholderContent={placeholderContent}>
53
- {meta.options.map((option: any) => (
54
- <MenuItem
55
- active={option.value === selectedValue}
56
- key={option.value}
57
- onClick={() => handleChange(option.value)}
58
- >
59
- {option.label}
60
- </MenuItem>
61
- ))}
88
+ <Dropdown placeholderContent={placeholderContent}>
89
+ {options.map((option) => {
90
+ return (
91
+ <MenuItem
92
+ active={option.value === selectedValue}
93
+ key={option.value}
94
+ onClick={() => handleChange(option.value)}
95
+ >
96
+ {option.label}
97
+ </MenuItem>
98
+ );
99
+ })}
62
100
  </Dropdown>
63
101
  </p>
64
102
  );
65
103
  }
66
104
 
67
- function NumberInput({ id, value, onChange }: InputComponentProps) {
68
- const [inputValue, setInputValue] = React.useState(value);
105
+ function NumberInput({ value, onChange }: InputComponentProps) {
106
+ const [inputValue, setInputValue] = React.useState(value || 0);
107
+
108
+ React.useEffect(() => {
109
+ setInputValue(value || 0);
110
+ }, [value]);
111
+
69
112
  const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
70
113
  const newValue = e.target.value;
71
114
  if (!isNaN(Number(newValue))) {
72
- onChange(Number(newValue));
73
- setInputValue(Number(newValue));
115
+ onChange(Number(newValue) || 0);
116
+ setInputValue(Number(newValue) || 0);
74
117
  } else {
75
118
  // TODO: render error message
76
119
  // eslint-disable-next-line no-console
77
120
  console.error('Invalid number input', newValue);
78
121
  }
79
122
  };
80
- return <InputText id={id} type="number" value={inputValue} onChange={handleChange} />;
123
+
124
+ return <InputText type="number" value={inputValue} onChange={handleChange} />;
81
125
  }
82
126
 
83
- function ColorInput({ id, value, onChange }: InputComponentProps) {
84
- const [inputValue, setInputValue] = React.useState(value);
127
+ function ColorInput({ value, onChange }: InputComponentProps) {
128
+ const [inputValue, setInputValue] = React.useState(value || '');
129
+
130
+ React.useEffect(() => {
131
+ setInputValue(value || '');
132
+ }, [value]);
133
+
85
134
  const handleChange = (newValue: string) => {
86
- onChange(newValue);
87
- setInputValue(newValue);
135
+ onChange(newValue || '');
136
+ setInputValue(newValue || '');
88
137
  };
138
+
89
139
  return (
90
140
  <p className={classNames(styles.wrapper)}>
91
- <ColorPicker id={id} value={inputValue} onColorSelect={handleChange} allowCustomColor />
141
+ <ColorPicker value={inputValue} onColorSelect={handleChange} allowCustomColor />
92
142
  </p>
93
143
  );
94
144
  }
95
145
 
96
- function DateInput({ id, value, onChange }: InputComponentProps) {
146
+ function DateInput({ value, onChange }: InputComponentProps) {
97
147
  const [inputValue, setInputValue] = React.useState<Date | null>(new Date(value));
148
+
149
+ React.useEffect(() => {
150
+ setInputValue(new Date(value));
151
+ }, [value]);
152
+
98
153
  const handleChange = (newValue: Date | null) => {
99
154
  if (newValue) {
100
155
  onChange(newValue.toISOString().split('T')[0]);
101
156
  }
102
157
  setInputValue(newValue);
103
158
  };
159
+
104
160
  return (
105
161
  <p className={classNames(styles.wrapper)}>
106
- <DatePicker id={id} date={inputValue} onChange={handleChange} />
162
+ <DatePicker date={inputValue} onChange={handleChange} />
107
163
  </p>
108
164
  );
109
165
  }
110
166
 
111
- function ToggleInput({ id, value, onChange }: InputComponentProps) {
112
- const [isChecked, setIsChecked] = React.useState(value);
167
+ function ToggleInput({ value, onChange }: InputComponentProps) {
168
+ const [isChecked, setIsChecked] = React.useState(!!value);
169
+
170
+ React.useEffect(() => {
171
+ setIsChecked(!!value);
172
+ }, [value]);
173
+
113
174
  const handleChange = () => {
114
175
  setIsChecked(!isChecked);
115
176
  onChange(!isChecked);
116
177
  };
178
+
117
179
  return (
118
180
  <p className={classNames(styles.wrapper)}>
119
- <Toggle id={id} defaultChecked={isChecked} onChange={handleChange} />
181
+ <Toggle defaultChecked={isChecked} onChange={handleChange} />
120
182
  </p>
121
183
  );
122
184
  }
123
185
 
124
- function JsonInput({ id, value, onChange }: InputComponentProps) {
186
+ function JsonInput({ value, onChange }: InputComponentProps) {
125
187
  const [inputValue, setInputValue] = React.useState(JSON.stringify(value, null, 2));
188
+
189
+ React.useEffect(() => {
190
+ setInputValue(JSON.stringify(value, null, 2));
191
+ }, [value]);
192
+
126
193
  const [message, setMessage] = React.useState('');
194
+
127
195
  const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
128
196
  const newValue = e.target.value;
129
197
  try {
@@ -135,9 +203,10 @@ function JsonInput({ id, value, onChange }: InputComponentProps) {
135
203
  }
136
204
  setInputValue(newValue);
137
205
  };
206
+
138
207
  return (
139
208
  <div>
140
- <TextArea id={id} value={inputValue} onChange={handleChange} />
209
+ <TextArea value={inputValue} onChange={handleChange} />
141
210
  {message && <div style={{ color: 'red' }}>{message}</div>}
142
211
  </div>
143
212
  );
@@ -11,4 +11,5 @@
11
11
 
12
12
  .label {
13
13
  font-weight: bold;
14
+ color: var(--on-background-color);
14
15
  }
@@ -15,7 +15,10 @@ export function LiveControls({
15
15
  onChange: (key: string, value: any) => void;
16
16
  }) {
17
17
  return (
18
- <ul className={classNames(styles.container)}>
18
+ <ul
19
+ className={classNames(styles.container)}
20
+ style={{ paddingBottom: '20em' /* temp walkaround for cutting popups */ }}
21
+ >
19
22
  {defs.map((field) => {
20
23
  const key = field.id;
21
24
  const InputComponent = getInputComponent(field.input || 'text');