Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README-ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ 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
iconSize?: number | string; // deprecated: not applied, set the size on the icon element
handler?: (item: ConfigItem) => void; // custom item action handler
visible?: (item: ConfigItem) => boolean; // optional visibility handler for filtering menu items
className?: string; // custom class property
Expand All @@ -401,6 +401,13 @@ type MenuItem = {
DashKit.setSettings({menu: [] as Array<MenuItem>});
```

Встроенные пункты — `copy`, `delete` и `settings` (`MenuItems`):

- строкой `copy` и `delete` получают текст и действие по умолчанию, в том числе рядом с пользовательскими
пунктами в любом порядке; `settings` строкой не показывается, потому что настройки открывает кнопка с шестерёнкой;
- объектом без `title` встроенный пункт получает текст по умолчанию, а без `handler` — и действие по умолчанию;
так показывается и `settings`.

### Перетаскиваемые элементы из `ActionPanel`

#### `DashKitDnDWrapper`
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ 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
iconSize?: number | string; // deprecated: not applied, set the size on the icon element
handler?: (item: ConfigItem) => void; // custom item action handler
visible?: (item: ConfigItem) => boolean; // optional visibility handler for filtering menu items
className?: string; // custom class property
Expand All @@ -475,6 +475,13 @@ type MenuItem = {
DashKit.setSettings({menu: [] as Array<MenuItem>});
```

Default items are `copy`, `delete` and `settings` (`MenuItems`):

- given as a string, `copy` and `delete` keep their default text and action, also next to custom items in any
order; `settings` as a string is not shown, because the gear button opens the settings;
- given as an object without `title`, a default item gets its default text, and without `handler` its default
action; this way `settings` is shown too.

### Draggable items from ActionPanel

#### DashKitDnDWrapper
Expand Down
55 changes: 48 additions & 7 deletions docs/migration-to-v11.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ and what to do about each change.
| `react`, `react-dom` | `^16.8.0 \|\| ^17 \|\| ^18 \|\| ^19` | `^18.0.0 \|\| ^19.0.0` |

Upgrade the application to uikit 8 first: see the
[uikit migration guide](https://github.com/gravity-ui/uikit/blob/main/docs/migration-to-v8.md). Two uikit
majors in one bundle are two sets of providers, and DashKit would not see the theme of the application.
[uikit migration guide](https://github.com/gravity-ui/uikit/blob/main/docs/migration-to-v8.md), also installed
as `node_modules/@gravity-ui/uikit/build/docs/guides/migration-to-v8.md`. Two uikit majors in one bundle are two
sets of providers, and DashKit would not see the theme of the application.

## Theme provider

Expand All @@ -27,10 +28,15 @@ The menu behind the "…" button of a widget is the uikit 8 `Menu` instead of th
DashKit did not change: `overlayMenuItems`, `Settings.menu`, and the `title`, `handler`, `visible`, `className` and
`qa` of a custom item work as before.

`iconSize` of a menu item is deprecated: the menu never applied it. Set the size on the icon element. `iconSize`
of an `overlayControls` button still works.

What changes is the markup, so check your CSS overrides and tests:

- Items are `button.g-menu-item[role="menuitem"]` inside `.g-menu`. The `.g-dropdown-menu__*` classes and the
`li > div[role="menuitem"]` structure are gone.
- `role="menu"` is on the popup element around `.g-menu`, not on `.g-menu` itself: find the menu by its role
(`getByRole('menu')`), not with `.g-menu[role="menu"]`.
- `qa` of a custom item is the `data-qa` of that button.
- `icon` of a custom item is rendered inside `div.g-menu-item__icon`, a 16px box. An `<Icon>` without `size` and an
`<svg>` without `width` and `height` get 16px. Items without an icon are indented to line up with the ones that
Expand All @@ -56,6 +62,11 @@ DashKit texts (the overlay menu, the error of the Text plugin) follow the langua
Without `lang` on a `Provider` they follow `configure({lang})`, as before. An application that only calls
`configure` needs no change.

The texts now re-render when the language changes, from either source. A DashKit 10 application had to remount
DashKit or pass it a new `context` to see the new language; for the texts of DashKit itself that workaround can be
removed. The texts of the application, such as the titles of its menu items or plugins that take the language from
`context`, stay its own.

## ActionPanel

The default hover background of an item is `--g-color-base-contrast-light-simple-hover`: uikit 8 removed
Expand All @@ -69,10 +80,40 @@ The default hover background of an item is `--g-color-base-contrast-light-simple
- `lodash` is replaced with `es-toolkit`. `es-toolkit`, `tslib` and `@gravity-ui/i18n` are dependencies of DashKit,
so nothing has to be installed next to it.
- Unit tests are no longer published in the package.
- The types of DashKit compile with `skipLibCheck: false`; DashKit 10 needed `skipLibCheck: true`. They need
`@types/react` 18.2.6 or later (they use `React.JSX`), and with `moduleResolution: node10` also
`esModuleInterop` or `allowSyntheticDefaultImports`, because they default-import `react` and
`react-grid-layout`; `bundler`, `node16` and `nodenext` work as they are.
- `@types/react-grid-layout` is a dependency: the public types import `react-grid-layout`. It accepts any
`@types/react`; if the package manager installs a second copy of `@types/react` for it next to the application's
one, dedupe it (`overrides` in npm, `resolutions` in yarn).
- uikit 8 brings two dependencies that ship only ES modules, `colors-named` and `colors-named-hex`, and they load
with any import of `@gravity-ui/uikit`. Bundlers are not affected.
- In Jest, a test that imports `@gravity-ui/uikit` or DashKit without mocking uikit fails with "Unexpected token
'export'". Let Jest transform these two packages to CommonJS: take them out of `transformIgnorePatterns` and
make sure the transformer handles `.js` files of `node_modules` (`babel-jest` does, `ts-jest` does not).
- In Node, the CommonJS build needs `require(esm)` for them (Node 20.19 or 22.12 and later). As before, the main
entry also needs a DOM; `@gravity-ui/dashkit/helpers` does not.

- In Jest, a test that imports `@gravity-ui/uikit` or DashKit without mocking uikit fails to load them: Jest 29
reports "SyntaxError: Unexpected token 'export'", Jest 30 "Must use import to load ES Module". Take the two
packages out of `transformIgnorePatterns` and let a transformer that turns ES modules into CommonJS handle
their `.js` files. Keep the rest of the configuration, such as the CSS stub and jsdom. Transformers that do it:

- `ts-jest` 29.3.2 or later, by itself; 29.3.0 and 29.3.1 only with `"isolatedModules": true`; older versions
leave the files as they are;
- `babel-jest` with `@babel/preset-env` or `@babel/plugin-transform-modules-commonjs` 7.x in a project-wide
`babel.config.js`: a `.babelrc` does not apply to files in `node_modules`;
- a small transformer for these two packages only, which works with any `ts-jest`; `jest/esmTransform.js` in
the DashKit repository is one (it calls `typescript.transpileModule`).

```js
// jest.config.js (jest.config.cjs in a package with "type": "module"), with ts-jest 29.3.2 or later
module.exports = {
transform: {
'^.+\\.[jt]sx?$': 'ts-jest',
},
transformIgnorePatterns: ['/node_modules/(?!(colors-named|colors-named-hex)/)'],
// with pnpm, whose packages live in node_modules/.pnpm:
// transformIgnorePatterns: ['/node_modules/\\.pnpm/(?!(colors-named|colors-named-hex)@)'],
};
```

- In Node, the CommonJS build needs `require(esm)` for them (Node 20.19 or 22.12 and later). The main entry
also imports CSS and needs a DOM, so it loads only under a bundler or a test runner that stubs CSS;
`@gravity-ui/dashkit/helpers` loads in plain Node.
4 changes: 1 addition & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"dependencies": {
"@bem-react/classname": "^1.6.0",
"@gravity-ui/i18n": "^1.8.0",
"@types/react-grid-layout": "^1.3.5",
"es-toolkit": "^1.53.2",
"hashids": "^2.2.8",
"immutability-helper": "^3.1.1",
Expand Down Expand Up @@ -114,7 +115,6 @@
"@types/jest": "^29.5.14",
"@types/react": "^19.2.16",
"@types/react-dom": "^19.2.3",
"@types/react-grid-layout": "^1.3.5",
"@types/react-transition-group": "^4.4.12",
"copyfiles": "^2.4.1",
"eslint": "^8.57.1",
Expand Down
Loading
Loading