@sima-land/moleculas 16.0.0-alpha.1 → 16.0.0-alpha.2

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.
@@ -0,0 +1,46 @@
1
+ import { AnchorHTMLAttributes } from 'react';
2
+ interface TextContent {
3
+ type: 'text';
4
+ text: string;
5
+ }
6
+ interface ColorContent {
7
+ type: 'color';
8
+ color: string;
9
+ }
10
+ interface ImageContent {
11
+ type: 'image';
12
+ src: string;
13
+ }
14
+ export type ModifierContent = TextContent | ColorContent | ImageContent;
15
+ export interface ModifierProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
16
+ /** Вывести выбранным. */
17
+ active?: boolean;
18
+ /** Вывести отключенным. */
19
+ disabled?: boolean;
20
+ /** Вывести зачеркнутым. */
21
+ crossedOut?: boolean;
22
+ /** Содержимое. */
23
+ content: ModifierContent;
24
+ /** Высота по дизайн-гайдам. */
25
+ size?: 's' | 'm';
26
+ /** Кол-во. */
27
+ count?: number;
28
+ /** Идентификатор для систем автоматизированного тестирования. */
29
+ 'data-testid'?: string;
30
+ }
31
+ export type MoreButtonProps = Omit<ModifierProps, 'content' | 'crossedOut' | 'active' | 'count'> & {
32
+ count: number;
33
+ };
34
+ /**
35
+ * Кнопка модификатора (аналога товара).
36
+ * @param props Свойства.
37
+ * @return Элемент.
38
+ */
39
+ export declare function Modifier({ size, active, crossedOut, disabled, content, count, className, 'data-testid': testId, ...props }: ModifierProps): JSX.Element;
40
+ /**
41
+ * Кнопка "+N" для показа полного списка модификаторов.
42
+ * @param props Свойства.
43
+ * @return Элемент.
44
+ */
45
+ export declare function MoreButton({ count, className, 'data-testid': testId, ...rest }: MoreButtonProps): JSX.Element;
46
+ export {};
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __rest = (this && this.__rest) || function (s, e) {
26
+ var t = {};
27
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
28
+ t[p] = s[p];
29
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
30
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
31
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
32
+ t[p[i]] = s[p[i]];
33
+ }
34
+ return t;
35
+ };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.MoreButton = exports.Modifier = void 0;
41
+ const react_1 = __importStar(require("react"));
42
+ const hint_1 = require("@sima-land/ui-nucleons/hint");
43
+ const bind_1 = __importDefault(require("classnames/bind"));
44
+ const modifiers_module_scss_1 = __importDefault(require("./modifiers.module.scss"));
45
+ const cx = bind_1.default.bind(modifiers_module_scss_1.default);
46
+ /**
47
+ * Кнопка модификатора (аналога товара).
48
+ * @param props Свойства.
49
+ * @return Элемент.
50
+ */
51
+ function Modifier(_a) {
52
+ var { size = 'm', active, crossedOut, disabled, content, count, className, 'data-testid': testId = 'modifier' } = _a, props = __rest(_a, ["size", "active", "crossedOut", "disabled", "content", "count", "className", 'data-testid']);
53
+ // текст хинта
54
+ const [hint, setHint] = (0, react_1.useState)('');
55
+ // состояние хинта
56
+ const [open, setOpen] = (0, react_1.useState)(false);
57
+ // позиционирование хинта
58
+ const _b = (0, hint_1.useHintFloating)({ open, onOpenChange: setOpen }), { refs } = _b, floating = __rest(_b, ["refs"]);
59
+ // пользовательское взаимодействие для хинта
60
+ const { getReferenceProps, getFloatingProps } = (0, hint_1.useHintOnHover)(floating);
61
+ // определение необходимости активации хинта
62
+ (0, react_1.useEffect)(() => {
63
+ const textElement = refs.reference.current;
64
+ if (!(textElement instanceof HTMLElement) || content.type !== 'text') {
65
+ return;
66
+ }
67
+ // eslint-disable-next-line require-jsdoc
68
+ const defineHint = () => setHint(isTruncated(textElement) ? content.text : '');
69
+ defineHint();
70
+ const observer = new ResizeObserver(defineHint);
71
+ observer.observe(textElement);
72
+ return () => observer.disconnect();
73
+ }, [content.text]);
74
+ return (react_1.default.createElement(react_1.default.Fragment, null,
75
+ react_1.default.createElement("a", Object.assign({}, props, { className: cx('root', `size-${size}`, { active, disabled }, className), "data-testid": testId }),
76
+ content.type === 'color' && (react_1.default.createElement("span", { className: cx('color'), role: 'banner', style: { background: content.color } })),
77
+ content.type === 'image' && (react_1.default.createElement("span", { className: cx('image'), role: 'banner', style: { backgroundImage: `url(${content.src})` } })),
78
+ content.type === 'text' && (react_1.default.createElement("span", Object.assign({ ref: refs.setReference, className: cx('text') }, getReferenceProps()), content.text)),
79
+ typeof count === 'number' && (react_1.default.createElement("span", { className: cx('counter') }, count > 99 ? '99+' : count)),
80
+ crossedOut && (react_1.default.createElement("svg", { width: '100%', height: '100%', className: cx('diagonal') },
81
+ react_1.default.createElement("line", { x1: '0', y1: '100%', x2: '100%', y2: '0', stroke: 'var(--modifier-border-color)' })))),
82
+ hint && (react_1.default.createElement(hint_1.Hint, Object.assign({ open: open, hintRef: refs.setFloating, arrowRef: refs.setArrow }, getFloatingProps()), hint))));
83
+ }
84
+ exports.Modifier = Modifier;
85
+ /**
86
+ * Кнопка "+N" для показа полного списка модификаторов.
87
+ * @param props Свойства.
88
+ * @return Элемент.
89
+ */
90
+ function MoreButton(_a) {
91
+ var { count, className, 'data-testid': testId = 'more-modifiers' } = _a, rest = __rest(_a, ["count", "className", 'data-testid']);
92
+ return (react_1.default.createElement(Modifier, Object.assign({ role: 'button', "aria-label": '\u041F\u043E\u043A\u0430\u0437\u0430\u0442\u044C \u0432\u0441\u0435 \u0430\u043D\u0430\u043B\u043E\u0433\u0438' }, rest, { className: cx('more', className), content: { type: 'text', text: `+${count}` }, "data-testid": testId })));
93
+ }
94
+ exports.MoreButton = MoreButton;
95
+ /**
96
+ * Определяет, обрезан ли текст в элементе.
97
+ * @param el Элемент.
98
+ * @return Обрезан ли текст в элементе.
99
+ */
100
+ function isTruncated(el) {
101
+ return el.scrollWidth > el.clientWidth;
102
+ }
@@ -0,0 +1,121 @@
1
+ @use 'node_modules/@sima-land/ui-nucleons/colors';
2
+
3
+ .root {
4
+ display: inline-block;
5
+ text-decoration: none;
6
+ position: relative;
7
+ color: var(--modifier-text-color);
8
+ border-radius: 4px;
9
+ min-width: var(--modifier-size);
10
+ min-height: var(--modifier-size);
11
+ font-size: 14px;
12
+ line-height: 20px;
13
+ text-align: center;
14
+ --modifier-text-color: #{colors.$basic-gray87};
15
+ --modifier-border-width: 1px;
16
+ --modifier-border-color: #{colors.$basic-gray12};
17
+ &.active {
18
+ --modifier-border-color: #{colors.$basic-blue};
19
+ }
20
+ &:hover:not(.disabled) {
21
+ cursor: pointer;
22
+ }
23
+ &:hover:not(.disabled):not(.active) {
24
+ --modifier-border-width: 2px;
25
+ }
26
+ &.disabled {
27
+ --modifier-media-opacity: 0.24;
28
+ --modifier-overlay-color: rgba(0, 0, 0, 0.04);
29
+ --modifier-border-width: 0;
30
+ --modifier-text-color: #{colors.$basic-gray38};
31
+ }
32
+ &::after {
33
+ content: '';
34
+ display: block;
35
+ pointer-events: none;
36
+ position: absolute;
37
+ top: 0;
38
+ left: 0;
39
+ width: 100%;
40
+ height: 100%;
41
+ border-radius: inherit;
42
+ box-shadow: inset 0 0 0 var(--modifier-border-width) var(--modifier-border-color);
43
+ background: var(--modifier-overlay-color);
44
+ }
45
+ &.more {
46
+ width: var(--modifier-size);
47
+ --modifier-text-color: #{colors.$basic-blue};
48
+ &.size-s {
49
+ --modifier-padding: 10px 0;
50
+ }
51
+ &.size-m {
52
+ --modifier-padding: 14px 0;
53
+ }
54
+ }
55
+ }
56
+
57
+ .size-s {
58
+ --modifier-size: 40px;
59
+ --modifier-padding: 10px;
60
+ }
61
+
62
+ .size-m {
63
+ --modifier-size: 48px;
64
+ --modifier-padding: 14px 15px;
65
+ }
66
+
67
+ .diagonal {
68
+ position: absolute;
69
+ top: 0;
70
+ left: 0;
71
+ width: 100%;
72
+ height: 100%;
73
+ overflow: hidden;
74
+ border-radius: inherit;
75
+ }
76
+
77
+ .color,
78
+ .image {
79
+ border-radius: inherit;
80
+ display: block;
81
+ position: absolute;
82
+ top: 0;
83
+ left: 0;
84
+ width: 100%;
85
+ height: 100%;
86
+ opacity: var(--modifier-media-opacity);
87
+ }
88
+
89
+ .image {
90
+ background-position: center;
91
+ background-size: cover;
92
+ }
93
+
94
+ .text {
95
+ padding: var(--modifier-padding);
96
+ display: block;
97
+ max-width: 100%;
98
+ white-space: nowrap;
99
+ text-overflow: ellipsis;
100
+ overflow: hidden;
101
+
102
+ // ВАЖНО: чтобы диагональная черта была под текстом
103
+ position: relative;
104
+ z-index: 1;
105
+ }
106
+
107
+ .counter {
108
+ font-weight: 600;
109
+ font-size: 12px;
110
+ line-height: 14px;
111
+ height: 14px;
112
+ overflow: hidden;
113
+ padding: 0 4px;
114
+ background: colors.$additional-teal;
115
+ color: #fff;
116
+ position: absolute;
117
+ right: -2px;
118
+ top: -2px;
119
+ border-radius: 32px;
120
+ z-index: 1;
121
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sima-land/moleculas",
3
- "version": "16.0.0-alpha.1",
3
+ "version": "16.0.0-alpha.2",
4
4
  "repository": "ssh://git@github.com:sima-land/moleculas.git",
5
5
  "author": "www.sima-land.ru team",
6
6
  "license": "Apache-2.0",
@@ -31,7 +31,7 @@
31
31
  "react-transition-group": "^4.4.5"
32
32
  },
33
33
  "peerDependencies": {
34
- "@sima-land/ui-nucleons": "^45.0.0-alpha.0",
34
+ "@sima-land/ui-nucleons": "^45.0.0-alpha.3",
35
35
  "@sima-land/ui-quarks": "^3.6.0",
36
36
  "react": ">=17",
37
37
  "react-dom": ">=17"
@@ -56,7 +56,9 @@
56
56
  "@svgr/plugin-jsx": "^6.5.1",
57
57
  "@svgr/plugin-svgo": "^6.5.1",
58
58
  "@svgr/webpack": "^6.5.1",
59
+ "@testing-library/dom": "^9.2.0",
59
60
  "@testing-library/react": "^12.1.0",
61
+ "@testing-library/user-event": "^14.4.3",
60
62
  "@types/enzyme": "^3.10.12",
61
63
  "@types/jest": "^29.4.0",
62
64
  "@types/lodash": "^4.14.191",