@gravity-ui/dashkit 8.1.0-beta.8 → 8.2.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/README.md CHANGED
@@ -29,6 +29,7 @@ interface DashKitProps {
29
29
  editMode: boolean;
30
30
  onItemEdit: ({id}: {id: string}) => void;
31
31
  onChange: (data: {config: Config; itemsStateAndParams: ItemsStateAndParams}) => void;
32
+ onDrop: (dropProps: ItemDropProps) => void;
32
33
  defaultGlobalParams: GlobalParams;
33
34
  globalParams: GlobalParams;
34
35
  itemsStateAndParams: ItemsStateAndParams;
@@ -36,6 +37,8 @@ interface DashKitProps {
36
37
  context: ContextProps;
37
38
  overlayControls?: Record<string, OverlayControlItem[]>;
38
39
  noOverlay?: boolean;
40
+ focusable?: boolean;
41
+ draggableHandleClassName?: string;
39
42
  }
40
43
  ```
41
44
 
@@ -43,6 +46,7 @@ interface DashKitProps {
43
46
  - **editMode**: Whether edit mode is enabled.
44
47
  - **onItemEdit**: Called when you click to edit a widget.
45
48
  - **onChange**: Called when config or [itemsStateAndParams](#temsStateAndParams) are changed.
49
+ - **onDrop**: Called when item dropped from ActionPanel using (#DashKitDnDWrapper)
46
50
  - **defaultGlobalParams**, **globalParams**: [Parameters](#Params) that affect all widgets. In DataLens, `defaultGlobalParams` are global parameters set in the dashboard settings. `globalParams` are globals parameters that can be set in the url.
47
51
  - **itemsStateAndParams**: [itemsStateAndParams](#temsStateAndParams).
48
52
  - **settings**: DashKit settings.
@@ -208,6 +212,23 @@ const config: DashKitProps['config'] = {
208
212
  Add a new item to the config:
209
213
 
210
214
  ```ts
215
+ const newLayout = updateLayout: [
216
+ {
217
+ h: 6,
218
+ i: 'Ea',
219
+ w: 12,
220
+ x: 0,
221
+ y: 6,
222
+ },
223
+ {
224
+ h: 4,
225
+ i: 'Dk',
226
+ w: 8,
227
+ x: 0,
228
+ y: 12,
229
+ },
230
+ ];
231
+
211
232
  const newConfig = DashKit.setItem({
212
233
  item: {
213
234
  data: {
@@ -215,8 +236,19 @@ const newConfig = DashKit.setItem({
215
236
  },
216
237
  namespace: 'default',
217
238
  type: 'text',
239
+ // Optional. If new item needed to be inserted in current layout with predefined dimensions
240
+ layout: { // Current item inseterted before 'Ea'
241
+ h: 6,
242
+ w: 12,
243
+ x: 0,
244
+ y: 2,
245
+ },,
218
246
  },
219
247
  config: config,
248
+ options: {
249
+ // Optional. New layout values for existing items when new element is dropped from ActionPanel
250
+ updateLayout: newLayout,
251
+ },
220
252
  });
221
253
  ```
222
254
 
@@ -314,6 +346,69 @@ type MenuItem = {
314
346
  DashKit.setSettings({menu: [] as Array<MenuItem>});
315
347
  ```
316
348
 
349
+ ### Draggable items from ActionPanel
350
+
351
+ #### DashKitDnDWrapper
352
+
353
+ ```ts
354
+ interface DashKitDnDWrapperProps {
355
+ dragImageSrc?: string;
356
+ onDragStart?: (dragProps: ItemDragProps) => void;
357
+ onDragEnd?: () => void;
358
+ }
359
+ ```
360
+
361
+ - **dragImageSrc**: Drag image preview, by default used transparent 1px png base64
362
+ - **onDragStart**: Callback called when element is dragged from ActionPanel
363
+ - **onDragEnd**: Callback called when element dropped or drag canceled
364
+
365
+ ```ts
366
+ type ItemDragProps = {
367
+ type: string; // Plugin type
368
+ layout?: { // Optional. Layout item size for preview and init
369
+ w?: number;
370
+ h?: number;
371
+ };
372
+ extra?: any; // Custom user context
373
+ };
374
+ ```
375
+
376
+ ```ts
377
+ type ItemDropProps = {
378
+ commit: () => void; // Callback should be called after all config operations are made
379
+ dragProps: ItemDragProps; // Item drag props
380
+ itemLayout: ConfigLayout; // Calculated item layout dimensions
381
+ newLayout: ConfigLayout[]; // New layout after element is dropped
382
+ };
383
+ ```
384
+
385
+
386
+ #### Example:
387
+
388
+ ```jsx
389
+ const menuItems = [
390
+ {
391
+ id: 'chart',
392
+ icon: <Icon data={ChartColumn} />,
393
+ title: 'Chart',
394
+ qa: 'chart',
395
+ dragProps: { // ItemDragProps
396
+ type: 'custom', // Registered plugin type
397
+ },
398
+ }
399
+ ]
400
+
401
+ const onDrop = (dropProps: ItemDropProps) => {
402
+ // ... add element to your config
403
+ dropProps.commit();
404
+ }
405
+
406
+ <DashKitDnDWrapper>
407
+ <DashKit editMode={true} config={config} onChange={onChange} onDrop={onDrop} />
408
+ <ActionPanel items={menuItems} />
409
+ </DashKitDnDWrapper>
410
+ ```
411
+
317
412
  ### CSS API
318
413
 
319
414
  | Name | Description |
@@ -55,7 +55,7 @@ function useMemoStateContext(props) {
55
55
  }
56
56
  else {
57
57
  if (temporaryLayout) {
58
- setTemporaryLayout(Object.assign(Object.assign({}, temporaryLayout), { data: temporaryLayout.filter(({ i }) => i !== id) }));
58
+ setTemporaryLayout(Object.assign(Object.assign({}, temporaryLayout), { data: temporaryLayout.data.filter(({ i }) => i !== id) }));
59
59
  }
60
60
  onChange(utils_1.UpdateManager.removeItem({
61
61
  id,
@@ -51,7 +51,7 @@ function useMemoStateContext(props) {
51
51
  }
52
52
  else {
53
53
  if (temporaryLayout) {
54
- setTemporaryLayout(Object.assign(Object.assign({}, temporaryLayout), { data: temporaryLayout.filter(({ i }) => i !== id) }));
54
+ setTemporaryLayout(Object.assign(Object.assign({}, temporaryLayout), { data: temporaryLayout.data.filter(({ i }) => i !== id) }));
55
55
  }
56
56
  onChange(UpdateManager.removeItem({
57
57
  id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dashkit",
3
- "version": "8.1.0-beta.8",
3
+ "version": "8.2.0",
4
4
  "description": "Library for rendering dashboard grid layout",
5
5
  "license": "MIT",
6
6
  "repository": {