@gravity-ui/dashkit 8.23.0 → 8.24.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.
@@ -1,15 +1,13 @@
1
1
  import React from 'react';
2
2
  import { Plugin, PluginWidgetProps } from '../../typings';
3
- export type PluginTitleSize = 'xl' | 'l' | 'm' | 's' | 'xs';
3
+ import type { PluginTitleSize, TitleFontParams } from './types';
4
4
  export interface PluginTitleProps extends PluginWidgetProps {
5
5
  data: {
6
- size: PluginTitleSize;
6
+ size: PluginTitleSize | TitleFontParams;
7
7
  text: string;
8
8
  showInTOC: boolean;
9
9
  } & PluginWidgetProps['data'];
10
10
  }
11
- export declare class PluginTitle extends React.Component<PluginTitleProps> {
12
- render(): JSX.Element;
13
- }
11
+ export declare const PluginTitle: React.ForwardRefExoticComponent<PluginTitleProps & React.RefAttributes<HTMLDivElement>>;
14
12
  declare const plugin: Plugin<PluginTitleProps>;
15
13
  export default plugin;
@@ -5,22 +5,28 @@ const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const cn_1 = require("../../utils/cn");
7
7
  const constants_1 = require("../constants");
8
+ const constants_2 = require("./constants");
9
+ const utils_1 = require("./utils");
8
10
  const b = (0, cn_1.cn)('dashkit-plugin-title');
9
- class PluginTitle extends react_1.default.Component {
10
- render() {
11
- const { data } = this.props;
12
- const text = data.text ? data.text : '';
13
- const size = data.size ? data.size : false;
14
- const id = data.showInTOC && text ? encodeURIComponent(text) : undefined;
15
- return (react_1.default.createElement("div", { id: id, className: b({ size }), [constants_1.PLUGIN_ROOT_ATTR_NAME]: 'title' }, text));
16
- }
17
- }
18
- exports.PluginTitle = PluginTitle;
11
+ exports.PluginTitle = react_1.default.forwardRef(function PluginTitleForwardRef(props, ref) {
12
+ var _a, _b;
13
+ const { data } = props;
14
+ const text = data.text ? data.text : '';
15
+ const size = (0, utils_1.isCustomSize)(data.size) ? false : data.size;
16
+ const styles = (0, utils_1.isCustomSize)(data.size) && ((_a = data.size) === null || _a === void 0 ? void 0 : _a.fontSize)
17
+ ? {
18
+ fontSize: data.size.fontSize,
19
+ lineHeight: (_b = data.size.lineHeight) !== null && _b !== void 0 ? _b : constants_2.RECCOMMENDED_LINE_HEIGHT_MULTIPLIER,
20
+ }
21
+ : undefined;
22
+ const id = data.showInTOC && text ? encodeURIComponent(text) : undefined;
23
+ return (react_1.default.createElement("div", { ref: ref, id: id, style: styles, className: b({ size }), [constants_1.PLUGIN_ROOT_ATTR_NAME]: 'title' }, text));
24
+ });
19
25
  const plugin = {
20
26
  type: 'title',
21
27
  defaultLayout: { w: 36, h: 2 },
22
28
  renderer(props, forwardedRef) {
23
- return react_1.default.createElement(PluginTitle, Object.assign({}, props, { ref: forwardedRef }));
29
+ return react_1.default.createElement(exports.PluginTitle, Object.assign({}, props, { ref: forwardedRef }));
24
30
  },
25
31
  };
26
32
  exports.default = plugin;
@@ -0,0 +1,3 @@
1
+ import { PluginTitleSize, TitleFontParams } from './types';
2
+ export declare const TITLE_DEFAULT_SIZES: Record<PluginTitleSize, TitleFontParams>;
3
+ export declare const RECCOMMENDED_LINE_HEIGHT_MULTIPLIER = 1.25;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RECCOMMENDED_LINE_HEIGHT_MULTIPLIER = exports.TITLE_DEFAULT_SIZES = void 0;
4
+ exports.TITLE_DEFAULT_SIZES = {
5
+ xl: {
6
+ fontSize: '32px',
7
+ lineHeight: '40px',
8
+ },
9
+ l: {
10
+ fontSize: '24px',
11
+ lineHeight: '28px',
12
+ },
13
+ m: {
14
+ fontSize: '20px',
15
+ lineHeight: '24px',
16
+ },
17
+ s: {
18
+ fontSize: '17px',
19
+ lineHeight: '24px',
20
+ },
21
+ xs: {
22
+ fontSize: '15px',
23
+ lineHeight: '20px',
24
+ },
25
+ };
26
+ exports.RECCOMMENDED_LINE_HEIGHT_MULTIPLIER = 1.25;
@@ -1,2 +1,4 @@
1
1
  export * from './Title';
2
2
  export { default as pluginTitle } from './Title';
3
+ export { PluginTitleSize, TitleFontParams } from './types';
4
+ export { TITLE_DEFAULT_SIZES } from './constants';
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pluginTitle = void 0;
3
+ exports.TITLE_DEFAULT_SIZES = exports.pluginTitle = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  tslib_1.__exportStar(require("./Title"), exports);
6
6
  var Title_1 = require("./Title");
7
7
  Object.defineProperty(exports, "pluginTitle", { enumerable: true, get: function () { return tslib_1.__importDefault(Title_1).default; } });
8
+ var constants_1 = require("./constants");
9
+ Object.defineProperty(exports, "TITLE_DEFAULT_SIZES", { enumerable: true, get: function () { return constants_1.TITLE_DEFAULT_SIZES; } });
@@ -0,0 +1,5 @@
1
+ export type PluginTitleSize = 'xl' | 'l' | 'm' | 's' | 'xs';
2
+ export interface TitleFontParams {
3
+ fontSize: string;
4
+ lineHeight?: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import type { PluginTitleSize, TitleFontParams } from './types';
2
+ export declare function isCustomSize(size: PluginTitleSize | TitleFontParams): size is TitleFontParams;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCustomSize = void 0;
4
+ function isCustomSize(size) {
5
+ return typeof size === 'object';
6
+ }
7
+ exports.isCustomSize = isCustomSize;
@@ -1,16 +1,14 @@
1
1
  import React from 'react';
2
2
  import { Plugin, PluginWidgetProps } from '../../typings';
3
+ import type { PluginTitleSize, TitleFontParams } from './types';
3
4
  import './Title.css';
4
- export type PluginTitleSize = 'xl' | 'l' | 'm' | 's' | 'xs';
5
5
  export interface PluginTitleProps extends PluginWidgetProps {
6
6
  data: {
7
- size: PluginTitleSize;
7
+ size: PluginTitleSize | TitleFontParams;
8
8
  text: string;
9
9
  showInTOC: boolean;
10
10
  } & PluginWidgetProps['data'];
11
11
  }
12
- export declare class PluginTitle extends React.Component<PluginTitleProps> {
13
- render(): JSX.Element;
14
- }
12
+ export declare const PluginTitle: React.ForwardRefExoticComponent<PluginTitleProps & React.RefAttributes<HTMLDivElement>>;
15
13
  declare const plugin: Plugin<PluginTitleProps>;
16
14
  export default plugin;
@@ -1,17 +1,24 @@
1
1
  import React from 'react';
2
2
  import { cn } from '../../utils/cn';
3
3
  import { PLUGIN_ROOT_ATTR_NAME } from '../constants';
4
+ import { RECCOMMENDED_LINE_HEIGHT_MULTIPLIER } from './constants';
5
+ import { isCustomSize } from './utils';
4
6
  import './Title.css';
5
7
  const b = cn('dashkit-plugin-title');
6
- export class PluginTitle extends React.Component {
7
- render() {
8
- const { data } = this.props;
9
- const text = data.text ? data.text : '';
10
- const size = data.size ? data.size : false;
11
- const id = data.showInTOC && text ? encodeURIComponent(text) : undefined;
12
- return (React.createElement("div", { id: id, className: b({ size }), [PLUGIN_ROOT_ATTR_NAME]: 'title' }, text));
13
- }
14
- }
8
+ export const PluginTitle = React.forwardRef(function PluginTitleForwardRef(props, ref) {
9
+ var _a, _b;
10
+ const { data } = props;
11
+ const text = data.text ? data.text : '';
12
+ const size = isCustomSize(data.size) ? false : data.size;
13
+ const styles = isCustomSize(data.size) && ((_a = data.size) === null || _a === void 0 ? void 0 : _a.fontSize)
14
+ ? {
15
+ fontSize: data.size.fontSize,
16
+ lineHeight: (_b = data.size.lineHeight) !== null && _b !== void 0 ? _b : RECCOMMENDED_LINE_HEIGHT_MULTIPLIER,
17
+ }
18
+ : undefined;
19
+ const id = data.showInTOC && text ? encodeURIComponent(text) : undefined;
20
+ return (React.createElement("div", { ref: ref, id: id, style: styles, className: b({ size }), [PLUGIN_ROOT_ATTR_NAME]: 'title' }, text));
21
+ });
15
22
  const plugin = {
16
23
  type: 'title',
17
24
  defaultLayout: { w: 36, h: 2 },
@@ -0,0 +1,3 @@
1
+ import { PluginTitleSize, TitleFontParams } from './types';
2
+ export declare const TITLE_DEFAULT_SIZES: Record<PluginTitleSize, TitleFontParams>;
3
+ export declare const RECCOMMENDED_LINE_HEIGHT_MULTIPLIER = 1.25;
@@ -0,0 +1,23 @@
1
+ export const TITLE_DEFAULT_SIZES = {
2
+ xl: {
3
+ fontSize: '32px',
4
+ lineHeight: '40px',
5
+ },
6
+ l: {
7
+ fontSize: '24px',
8
+ lineHeight: '28px',
9
+ },
10
+ m: {
11
+ fontSize: '20px',
12
+ lineHeight: '24px',
13
+ },
14
+ s: {
15
+ fontSize: '17px',
16
+ lineHeight: '24px',
17
+ },
18
+ xs: {
19
+ fontSize: '15px',
20
+ lineHeight: '20px',
21
+ },
22
+ };
23
+ export const RECCOMMENDED_LINE_HEIGHT_MULTIPLIER = 1.25;
@@ -1,2 +1,4 @@
1
1
  export * from './Title';
2
2
  export { default as pluginTitle } from './Title';
3
+ export { PluginTitleSize, TitleFontParams } from './types';
4
+ export { TITLE_DEFAULT_SIZES } from './constants';
@@ -1,2 +1,3 @@
1
1
  export * from './Title';
2
2
  export { default as pluginTitle } from './Title';
3
+ export { TITLE_DEFAULT_SIZES } from './constants';
@@ -0,0 +1,5 @@
1
+ export type PluginTitleSize = 'xl' | 'l' | 'm' | 's' | 'xs';
2
+ export interface TitleFontParams {
3
+ fontSize: string;
4
+ lineHeight?: string;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { PluginTitleSize, TitleFontParams } from './types';
2
+ export declare function isCustomSize(size: PluginTitleSize | TitleFontParams): size is TitleFontParams;
@@ -0,0 +1,3 @@
1
+ export function isCustomSize(size) {
2
+ return typeof size === 'object';
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dashkit",
3
- "version": "8.23.0",
3
+ "version": "8.24.0",
4
4
  "description": "Library for rendering dashboard grid layout",
5
5
  "license": "MIT",
6
6
  "repository": {