@gravity-ui/dynamic-forms 2.3.0 → 2.4.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/build/cjs/lib/kit/components/Layouts/Transparent/Transparent.css +0 -3
- package/build/cjs/lib/kit/components/TogglerCard/TogglerCard.css +18 -0
- package/build/cjs/lib/kit/components/TogglerCard/TogglerCard.js +17 -0
- package/build/cjs/lib/kit/components/TogglerCard/index.js +4 -0
- package/build/cjs/lib/kit/components/ViewLayouts/ViewTransparent/ViewTransparent.css +1 -0
- package/build/cjs/lib/kit/components/index.js +1 -0
- package/build/cjs/lib/kit/hooks/useOneOf/useOneOf.css +10 -0
- package/build/cjs/lib/kit/hooks/useOneOf/useOneOf.js +34 -9
- package/build/esm/lib/core/types/specs.d.ts +1 -1
- package/build/esm/lib/kit/components/Layouts/Transparent/Transparent.css +0 -3
- package/build/esm/lib/kit/components/TogglerCard/TogglerCard.css +18 -0
- package/build/esm/lib/kit/components/TogglerCard/TogglerCard.d.ts +12 -0
- package/build/esm/lib/kit/components/TogglerCard/TogglerCard.js +13 -0
- package/build/esm/lib/kit/components/TogglerCard/index.d.ts +1 -0
- package/build/esm/lib/kit/components/TogglerCard/index.js +1 -0
- package/build/esm/lib/kit/components/ViewLayouts/ViewTransparent/ViewTransparent.css +1 -0
- package/build/esm/lib/kit/components/index.d.ts +1 -0
- package/build/esm/lib/kit/components/index.js +1 -0
- package/build/esm/lib/kit/hooks/useOneOf/useOneOf.css +10 -0
- package/build/esm/lib/kit/hooks/useOneOf/useOneOf.js +34 -9
- package/package.json +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
.df-toggler-card {
|
|
2
|
+
width: 254px;
|
|
3
|
+
padding: 10px;
|
|
4
|
+
height: 88px;
|
|
5
|
+
}
|
|
6
|
+
.df-toggler-card__header {
|
|
7
|
+
display: flex;
|
|
8
|
+
justify-content: space-between;
|
|
9
|
+
align-items: baseline;
|
|
10
|
+
}
|
|
11
|
+
.df-toggler-card__text {
|
|
12
|
+
margin-top: 12px;
|
|
13
|
+
display: block;
|
|
14
|
+
margin-right: 15px;
|
|
15
|
+
height: 36px;
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
text-overflow: ellipsis;
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TogglerCard = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const components_1 = require("@gravity-ui/components");
|
|
7
|
+
const uikit_1 = require("@gravity-ui/uikit");
|
|
8
|
+
const utils_1 = require("../../utils");
|
|
9
|
+
const b = (0, utils_1.block)('toggler-card');
|
|
10
|
+
const TogglerCard = ({ description, title, text, onClick, disabled, selected, }) => {
|
|
11
|
+
return (react_1.default.createElement(uikit_1.Card, { onClick: onClick, type: "selection", disabled: disabled ? !selected : disabled, selected: selected, size: "m", className: b() },
|
|
12
|
+
react_1.default.createElement("div", { className: b('header') },
|
|
13
|
+
react_1.default.createElement(uikit_1.Text, { variant: "subheader-2", ellipsis: true }, title),
|
|
14
|
+
description ? (react_1.default.createElement(components_1.HelpPopover, { htmlContent: description, placement: ['bottom', 'top'] })) : null),
|
|
15
|
+
react_1.default.createElement(uikit_1.Text, { variant: "body-1", color: "secondary", className: b('text') }, text)));
|
|
16
|
+
};
|
|
17
|
+
exports.TogglerCard = TogglerCard;
|
|
@@ -10,5 +10,6 @@ tslib_1.__exportStar(require("./Inputs"), exports);
|
|
|
10
10
|
tslib_1.__exportStar(require("./Layouts"), exports);
|
|
11
11
|
tslib_1.__exportStar(require("./LongValue"), exports);
|
|
12
12
|
tslib_1.__exportStar(require("./SimpleVerticalAccordeon"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./TogglerCard"), exports);
|
|
13
14
|
tslib_1.__exportStar(require("./Views"), exports);
|
|
14
15
|
tslib_1.__exportStar(require("./ViewLayouts"), exports);
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
.df-use-oneof__toggler_radio > .df-row {
|
|
2
2
|
width: unset;
|
|
3
3
|
max-width: unset;
|
|
4
|
+
}
|
|
5
|
+
.df-use-oneof__toggler_card + .df-group-indent > .df-use-search:not(.df-group-indent) {
|
|
6
|
+
padding-top: 0px;
|
|
7
|
+
margin-top: 15px;
|
|
8
|
+
}
|
|
9
|
+
.df-use-oneof__card {
|
|
10
|
+
display: flex;
|
|
11
|
+
}
|
|
12
|
+
.df-use-oneof__card > :first-child {
|
|
13
|
+
margin-right: 8px;
|
|
4
14
|
}
|
|
@@ -5,6 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
6
|
const uikit_1 = require("@gravity-ui/uikit");
|
|
7
7
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
8
|
+
const components_1 = require("../../components");
|
|
8
9
|
const utils_1 = require("../../utils");
|
|
9
10
|
const b = (0, utils_1.block)('use-oneof');
|
|
10
11
|
const MAX_TAB_TITLE_LENGTH = 20;
|
|
@@ -41,28 +42,52 @@ const useOneOf = ({ props, onTogglerChange }) => {
|
|
|
41
42
|
content: title,
|
|
42
43
|
};
|
|
43
44
|
}), [spec.description, spec.viewSpec.order, specProperties]);
|
|
44
|
-
const
|
|
45
|
-
var _a, _b;
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
const togglerType = react_1.default.useMemo(() => {
|
|
46
|
+
var _a, _b, _c;
|
|
47
|
+
if (((_a = spec.viewSpec.oneOfParams) === null || _a === void 0 ? void 0 : _a.toggler) === 'card' && options.length < 3) {
|
|
48
|
+
return 'card';
|
|
49
|
+
}
|
|
50
|
+
if (((_b = spec.viewSpec.oneOfParams) === null || _b === void 0 ? void 0 : _b.toggler) !== 'radio' &&
|
|
51
|
+
(((_c = spec.viewSpec.oneOfParams) === null || _c === void 0 ? void 0 : _c.toggler) === 'select' ||
|
|
48
52
|
options.length > 3 ||
|
|
49
|
-
lodash_1.default.some(options, ({ title }) => title.length > MAX_TAB_TITLE_LENGTH))
|
|
53
|
+
lodash_1.default.some(options, ({ title }) => title.length > MAX_TAB_TITLE_LENGTH))) {
|
|
54
|
+
return 'select';
|
|
55
|
+
}
|
|
56
|
+
return 'radio';
|
|
50
57
|
}, [options, (_a = spec.viewSpec.oneOfParams) === null || _a === void 0 ? void 0 : _a.toggler]);
|
|
51
58
|
const togglerInput = react_1.default.useMemo(() => {
|
|
52
|
-
if (
|
|
59
|
+
if (togglerType === 'card') {
|
|
60
|
+
return (react_1.default.createElement("div", { className: b('card') }, options.map(({ value }) => {
|
|
61
|
+
var _a, _b, _c;
|
|
62
|
+
const onClick = () => {
|
|
63
|
+
onOneOfChange([value]);
|
|
64
|
+
};
|
|
65
|
+
return (react_1.default.createElement(components_1.TogglerCard, { title: ((_a = specProperties[value]) === null || _a === void 0 ? void 0 : _a.viewSpec.layoutTitle) || '', disabled: spec.viewSpec.disabled, text: ((_b = spec.description) === null || _b === void 0 ? void 0 : _b[value]) || '', description: (_c = specProperties[value]) === null || _c === void 0 ? void 0 : _c.viewSpec.layoutDescription, onClick: onClick, selected: oneOfValue === value, key: value }));
|
|
66
|
+
})));
|
|
67
|
+
}
|
|
68
|
+
if (togglerType === 'select') {
|
|
53
69
|
return (react_1.default.createElement(uikit_1.Select, { width: "max", value: [oneOfValue], onUpdate: onOneOfChange, options: options, disabled: spec.viewSpec.disabled, filterable: options.length > 7, qa: name }));
|
|
54
70
|
}
|
|
55
71
|
return (react_1.default.createElement(uikit_1.RadioButton, { value: oneOfValue, onChange: (event) => onOneOfChange([event.target.value]), disabled: spec.viewSpec.disabled, qa: name }, options.map((option) => (react_1.default.createElement(uikit_1.RadioButton.Option, { key: option.value, value: option.value }, option.title)))));
|
|
56
|
-
}, [
|
|
72
|
+
}, [
|
|
73
|
+
togglerType,
|
|
74
|
+
oneOfValue,
|
|
75
|
+
spec.viewSpec.disabled,
|
|
76
|
+
name,
|
|
77
|
+
options,
|
|
78
|
+
onOneOfChange,
|
|
79
|
+
specProperties,
|
|
80
|
+
]);
|
|
57
81
|
const toggler = react_1.default.useMemo(() => {
|
|
58
82
|
if (Layout) {
|
|
59
83
|
return (react_1.default.createElement("div", { className: b('toggler', {
|
|
60
|
-
radio:
|
|
84
|
+
radio: togglerType === 'radio',
|
|
85
|
+
card: togglerType === 'card',
|
|
61
86
|
}) },
|
|
62
87
|
react_1.default.createElement(Layout, Object.assign({}, props), togglerInput)));
|
|
63
88
|
}
|
|
64
89
|
return react_1.default.createElement("div", null, togglerInput);
|
|
65
|
-
}, [Layout, togglerInput,
|
|
90
|
+
}, [Layout, togglerInput, togglerType, props]);
|
|
66
91
|
return { oneOfValue, specProperties, toggler, togglerInput };
|
|
67
92
|
};
|
|
68
93
|
exports.useOneOf = useOneOf;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
.df-toggler-card {
|
|
2
|
+
width: 254px;
|
|
3
|
+
padding: 10px;
|
|
4
|
+
height: 88px;
|
|
5
|
+
}
|
|
6
|
+
.df-toggler-card__header {
|
|
7
|
+
display: flex;
|
|
8
|
+
justify-content: space-between;
|
|
9
|
+
align-items: baseline;
|
|
10
|
+
}
|
|
11
|
+
.df-toggler-card__text {
|
|
12
|
+
margin-top: 12px;
|
|
13
|
+
display: block;
|
|
14
|
+
margin-right: 15px;
|
|
15
|
+
height: 36px;
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
text-overflow: ellipsis;
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './TogglerCard.css';
|
|
3
|
+
interface TogglerCardProps {
|
|
4
|
+
description?: string;
|
|
5
|
+
title: string;
|
|
6
|
+
text: string;
|
|
7
|
+
onClick: () => void;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
selected: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const TogglerCard: React.FC<TogglerCardProps>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { HelpPopover } from '@gravity-ui/components';
|
|
3
|
+
import { Card, Text } from '@gravity-ui/uikit';
|
|
4
|
+
import { block } from '../../utils';
|
|
5
|
+
import './TogglerCard.css';
|
|
6
|
+
const b = block('toggler-card');
|
|
7
|
+
export const TogglerCard = ({ description, title, text, onClick, disabled, selected, }) => {
|
|
8
|
+
return (React.createElement(Card, { onClick: onClick, type: "selection", disabled: disabled ? !selected : disabled, selected: selected, size: "m", className: b() },
|
|
9
|
+
React.createElement("div", { className: b('header') },
|
|
10
|
+
React.createElement(Text, { variant: "subheader-2", ellipsis: true }, title),
|
|
11
|
+
description ? (React.createElement(HelpPopover, { htmlContent: description, placement: ['bottom', 'top'] })) : null),
|
|
12
|
+
React.createElement(Text, { variant: "body-1", color: "secondary", className: b('text') }, text)));
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TogglerCard';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TogglerCard';
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
.df-use-oneof__toggler_radio > .df-row {
|
|
2
2
|
width: unset;
|
|
3
3
|
max-width: unset;
|
|
4
|
+
}
|
|
5
|
+
.df-use-oneof__toggler_card + .df-group-indent > .df-use-search:not(.df-group-indent) {
|
|
6
|
+
padding-top: 0px;
|
|
7
|
+
margin-top: 15px;
|
|
8
|
+
}
|
|
9
|
+
.df-use-oneof__card {
|
|
10
|
+
display: flex;
|
|
11
|
+
}
|
|
12
|
+
.df-use-oneof__card > :first-child {
|
|
13
|
+
margin-right: 8px;
|
|
4
14
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { RadioButton, Select } from '@gravity-ui/uikit';
|
|
3
3
|
import _ from 'lodash';
|
|
4
|
+
import { TogglerCard } from '../../components';
|
|
4
5
|
import { block } from '../../utils';
|
|
5
6
|
import './useOneOf.css';
|
|
6
7
|
const b = block('use-oneof');
|
|
@@ -38,27 +39,51 @@ export const useOneOf = ({ props, onTogglerChange }) => {
|
|
|
38
39
|
content: title,
|
|
39
40
|
};
|
|
40
41
|
}), [spec.description, spec.viewSpec.order, specProperties]);
|
|
41
|
-
const
|
|
42
|
-
var _a, _b;
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
const togglerType = React.useMemo(() => {
|
|
43
|
+
var _a, _b, _c;
|
|
44
|
+
if (((_a = spec.viewSpec.oneOfParams) === null || _a === void 0 ? void 0 : _a.toggler) === 'card' && options.length < 3) {
|
|
45
|
+
return 'card';
|
|
46
|
+
}
|
|
47
|
+
if (((_b = spec.viewSpec.oneOfParams) === null || _b === void 0 ? void 0 : _b.toggler) !== 'radio' &&
|
|
48
|
+
(((_c = spec.viewSpec.oneOfParams) === null || _c === void 0 ? void 0 : _c.toggler) === 'select' ||
|
|
45
49
|
options.length > 3 ||
|
|
46
|
-
_.some(options, ({ title }) => title.length > MAX_TAB_TITLE_LENGTH))
|
|
50
|
+
_.some(options, ({ title }) => title.length > MAX_TAB_TITLE_LENGTH))) {
|
|
51
|
+
return 'select';
|
|
52
|
+
}
|
|
53
|
+
return 'radio';
|
|
47
54
|
}, [options, (_a = spec.viewSpec.oneOfParams) === null || _a === void 0 ? void 0 : _a.toggler]);
|
|
48
55
|
const togglerInput = React.useMemo(() => {
|
|
49
|
-
if (
|
|
56
|
+
if (togglerType === 'card') {
|
|
57
|
+
return (React.createElement("div", { className: b('card') }, options.map(({ value }) => {
|
|
58
|
+
var _a, _b, _c;
|
|
59
|
+
const onClick = () => {
|
|
60
|
+
onOneOfChange([value]);
|
|
61
|
+
};
|
|
62
|
+
return (React.createElement(TogglerCard, { title: ((_a = specProperties[value]) === null || _a === void 0 ? void 0 : _a.viewSpec.layoutTitle) || '', disabled: spec.viewSpec.disabled, text: ((_b = spec.description) === null || _b === void 0 ? void 0 : _b[value]) || '', description: (_c = specProperties[value]) === null || _c === void 0 ? void 0 : _c.viewSpec.layoutDescription, onClick: onClick, selected: oneOfValue === value, key: value }));
|
|
63
|
+
})));
|
|
64
|
+
}
|
|
65
|
+
if (togglerType === 'select') {
|
|
50
66
|
return (React.createElement(Select, { width: "max", value: [oneOfValue], onUpdate: onOneOfChange, options: options, disabled: spec.viewSpec.disabled, filterable: options.length > 7, qa: name }));
|
|
51
67
|
}
|
|
52
68
|
return (React.createElement(RadioButton, { value: oneOfValue, onChange: (event) => onOneOfChange([event.target.value]), disabled: spec.viewSpec.disabled, qa: name }, options.map((option) => (React.createElement(RadioButton.Option, { key: option.value, value: option.value }, option.title)))));
|
|
53
|
-
}, [
|
|
69
|
+
}, [
|
|
70
|
+
togglerType,
|
|
71
|
+
oneOfValue,
|
|
72
|
+
spec.viewSpec.disabled,
|
|
73
|
+
name,
|
|
74
|
+
options,
|
|
75
|
+
onOneOfChange,
|
|
76
|
+
specProperties,
|
|
77
|
+
]);
|
|
54
78
|
const toggler = React.useMemo(() => {
|
|
55
79
|
if (Layout) {
|
|
56
80
|
return (React.createElement("div", { className: b('toggler', {
|
|
57
|
-
radio:
|
|
81
|
+
radio: togglerType === 'radio',
|
|
82
|
+
card: togglerType === 'card',
|
|
58
83
|
}) },
|
|
59
84
|
React.createElement(Layout, Object.assign({}, props), togglerInput)));
|
|
60
85
|
}
|
|
61
86
|
return React.createElement("div", null, togglerInput);
|
|
62
|
-
}, [Layout, togglerInput,
|
|
87
|
+
}, [Layout, togglerInput, togglerType, props]);
|
|
63
88
|
return { oneOfValue, specProperties, toggler, togglerInput };
|
|
64
89
|
};
|