@yandex-cloud/dashkit
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -25,2 +25,3 @@ import React from 'react'; | ||
handler?: (item: ConfigItem) => void; | ||
visible?: (item: ConfigItem) => boolean; | ||
className?: string; | ||
@@ -27,0 +28,0 @@ } |
@@ -159,8 +159,14 @@ "use strict"; | ||
} | ||
// custom menu dropdown item filter | ||
if (item.visible && !item.visible(this.props.configItem)) { | ||
return null; | ||
} | ||
const itemHandler = item.handler; | ||
const itemAction = typeof itemHandler === 'function' | ||
? () => itemHandler(this.props.configItem) | ||
: ((_a = this.getDropDownMenuItemConfig(item.id)) === null || _a === void 0 ? void 0 : _a.action) || (() => { }); | ||
return { | ||
text: item.title || (0, i18n_1.default)(item.id), | ||
icon: item.icon, | ||
action: typeof item.handler === 'function' | ||
? item.handler | ||
: ((_a = this.getDropDownMenuItemConfig(item.id)) === null || _a === void 0 ? void 0 : _a.action) || (() => { }), | ||
action: itemAction, | ||
className: item.className, | ||
@@ -167,0 +173,0 @@ }; |
@@ -26,2 +26,3 @@ import React from 'react'; | ||
handler?: (item: ConfigItem) => void; | ||
visible?: (item: ConfigItem) => boolean; | ||
className?: string; | ||
@@ -28,0 +29,0 @@ } |
@@ -156,8 +156,14 @@ import React from 'react'; | ||
} | ||
// custom menu dropdown item filter | ||
if (item.visible && !item.visible(this.props.configItem)) { | ||
return null; | ||
} | ||
const itemHandler = item.handler; | ||
const itemAction = typeof itemHandler === 'function' | ||
? () => itemHandler(this.props.configItem) | ||
: ((_a = this.getDropDownMenuItemConfig(item.id)) === null || _a === void 0 ? void 0 : _a.action) || (() => { }); | ||
return { | ||
text: item.title || i18n(item.id), | ||
icon: item.icon, | ||
action: typeof item.handler === 'function' | ||
? item.handler | ||
: ((_a = this.getDropDownMenuItemConfig(item.id)) === null || _a === void 0 ? void 0 : _a.action) || (() => { }), | ||
action: itemAction, | ||
className: item.className, | ||
@@ -164,0 +170,0 @@ }; |
# Changelog | ||
## [1.2.0](https://github.com/yandex-cloud/dashkit/compare/v1.1.0...v1.2.0) (2022-08-08) | ||
### Features | ||
* add custom dropdown menu item filter in edit mode ([#8](https://github.com/yandex-cloud/dashkit/issues/8)) ([5c2824a](https://github.com/yandex-cloud/dashkit/commit/5c2824a4a9a25174eff69b2f0b7b04b74cf74e0c)) | ||
## [1.1.0](https://github.com/yandex-cloud/dashkit/compare/v1.0.0...v1.1.0) (2022-08-02) | ||
@@ -4,0 +11,0 @@ |
{ | ||
"name": "@yandex-cloud/dashkit", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Library for rendering dashboard grid layout", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -60,3 +60,3 @@ # DashKit | ||
Used for global DashKit settings (such as margins between widgets and default widget sizes) | ||
Used for global DashKit settings (such as margins between widgets, default widget sizes and widget overlay menu) | ||
@@ -69,2 +69,3 @@ ```js | ||
isMobile: true, | ||
// menu: [] as Array<MenuItem>, | ||
}); | ||
@@ -289,2 +290,21 @@ ``` | ||
### Menu | ||
You can specify custom DashKit widget overlay menu in edit mode | ||
```ts | ||
type MenuItem = { | ||
id: string; // uniq id | ||
title?: string; // string title | ||
icon?: ReactNode; // node of icon | ||
iconSize?: number | string; // icon size in px as number or as string with units | ||
handler?: (item: ConfigItem) => void; // custom item action handler | ||
visible?: (item: ConfigItem) => boolean; // optional visibility handler for filtering menu items | ||
className?: string; // custom class property | ||
}; | ||
// use array of menu items in settings | ||
DashKit.setSettings({menu: [] as Array<MenuItem>}); | ||
``` | ||
## Development | ||
@@ -291,0 +311,0 @@ |
307195
7225
345