@koslibs/components 1.3.0 → 1.5.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/CHANGELOG.md +53 -0
- package/dist/components/Button/button.js +1 -0
- package/dist/components/Input/index.d.ts +2 -0
- package/dist/components/Input/index.js +1 -0
- package/dist/components/Input/index.module.js +25 -0
- package/dist/components/Input/index_module.css +312 -0
- package/dist/components/Input/input.d.ts +29 -0
- package/dist/components/Input/input.js +179 -0
- package/dist/components/Input/types.d.ts +115 -0
- package/dist/components/Input/types.js +0 -0
- package/dist/components/Input/vars.css +32 -0
- package/dist/components/Modal/colors.module.js +5 -0
- package/dist/components/Modal/colors_module.css +10 -0
- package/dist/components/Modal/components/content/index.d.ts +15 -0
- package/dist/components/Modal/components/content/index.js +19 -0
- package/dist/components/Modal/components/content/index.module.js +5 -0
- package/dist/components/Modal/components/content/index_module.css +12 -0
- package/dist/components/Modal/components/controls/index.d.ts +56 -0
- package/dist/components/Modal/components/controls/index.js +24 -0
- package/dist/components/Modal/components/controls/index.module.js +19 -0
- package/dist/components/Modal/components/controls/index_module.css +52 -0
- package/dist/components/Modal/components/footer/index.d.ts +15 -0
- package/dist/components/Modal/components/footer/index.js +19 -0
- package/dist/components/Modal/components/footer/index.module.js +5 -0
- package/dist/components/Modal/components/footer/index_module.css +9 -0
- package/dist/components/Modal/components/header/index.d.ts +43 -0
- package/dist/components/Modal/components/header/index.js +54 -0
- package/dist/components/Modal/components/header/index.module.js +8 -0
- package/dist/components/Modal/components/header/index_module.css +31 -0
- package/dist/components/Modal/components/modal-surface/index.d.ts +4 -0
- package/dist/components/Modal/components/modal-surface/index.js +81 -0
- package/dist/components/Modal/context.d.ts +6 -0
- package/dist/components/Modal/context.js +3 -0
- package/dist/components/Modal/index.d.ts +10 -0
- package/dist/components/Modal/index.js +5 -0
- package/dist/components/Modal/index.module.js +15 -0
- package/dist/components/Modal/index_module.css +46 -0
- package/dist/components/Modal/modal.d.ts +10 -0
- package/dist/components/Modal/modal.js +13 -0
- package/dist/components/Modal/types.d.ts +41 -0
- package/dist/components/Modal/types.js +0 -0
- package/dist/components/Modal/utils/lock-scroll.d.ts +1 -0
- package/dist/components/Modal/utils/lock-scroll.js +31 -0
- package/dist/components/Modal/vars.css +9 -0
- package/dist/components/Popover/popover.js +9 -7
- package/dist/components/Portal/index.d.ts +2 -0
- package/dist/components/Portal/index.js +1 -0
- package/dist/components/Portal/portal.d.ts +2 -0
- package/dist/components/Portal/portal.js +19 -0
- package/dist/components/Portal/types.d.ts +18 -0
- package/dist/components/Portal/types.js +0 -0
- package/dist/hooks/use-data-test-id.d.ts +5 -0
- package/dist/hooks/use-data-test-id.js +7 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +3 -0
- package/package.json +2 -2
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { Modal, Modal as ModalComponent } from './modal.js';
|
|
2
|
+
export type { ModalProps } from './types.js';
|
|
3
|
+
export { Header, Header as ModalHeader } from './components/header/index.js';
|
|
4
|
+
export type { HeaderProps } from './components/header/index.js';
|
|
5
|
+
export { Content, Content as ModalContent } from './components/content/index.js';
|
|
6
|
+
export type { ContentProps } from './components/content/index.js';
|
|
7
|
+
export { Footer, Footer as ModalFooter } from './components/footer/index.js';
|
|
8
|
+
export type { FooterProps } from './components/footer/index.js';
|
|
9
|
+
export { Controls, Controls as ModalControls } from './components/controls/index.js';
|
|
10
|
+
export type { ControlsProps } from './components/controls/index.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Modal, Modal as ModalComponent } from "./modal.js";
|
|
2
|
+
export { Header, Header as ModalHeader } from "./components/header/index.js";
|
|
3
|
+
export { Content, Content as ModalContent } from "./components/content/index.js";
|
|
4
|
+
export { Footer, Footer as ModalFooter } from "./components/footer/index.js";
|
|
5
|
+
export { Controls, Controls as ModalControls } from "./components/controls/index.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import "./index_module.css";
|
|
2
|
+
const index_module = {
|
|
3
|
+
component: "component-kCkvk3",
|
|
4
|
+
"size-480": "size-480-fXx4Vl",
|
|
5
|
+
size480: "size-480-fXx4Vl",
|
|
6
|
+
"size-600": "size-600-X9nvTO",
|
|
7
|
+
size600: "size-600-X9nvTO",
|
|
8
|
+
"size-720": "size-720-_guzbs",
|
|
9
|
+
size720: "size-720-_guzbs",
|
|
10
|
+
"size-960": "size-960-I8vXpb",
|
|
11
|
+
size960: "size-960-I8vXpb",
|
|
12
|
+
"size-fullscreen": "size-fullscreen-exf2cb",
|
|
13
|
+
sizeFullscreen: "size-fullscreen-exf2cb"
|
|
14
|
+
};
|
|
15
|
+
export default index_module;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
@import "../../styles/theme.css";
|
|
2
|
+
@import "./vars.css";
|
|
3
|
+
|
|
4
|
+
.component-kCkvk3 {
|
|
5
|
+
border-radius: var(--border-radius-12, 12px);
|
|
6
|
+
max-width: calc(100vw - var(--size-32, 32px));
|
|
7
|
+
max-height: calc(100dvh - var(--size-32, 32px));
|
|
8
|
+
box-sizing: border-box;
|
|
9
|
+
min-width: 0;
|
|
10
|
+
font-family: var(--font-primary);
|
|
11
|
+
box-shadow: var(--modal-shadow);
|
|
12
|
+
border: none;
|
|
13
|
+
margin: auto;
|
|
14
|
+
padding: 0;
|
|
15
|
+
overflow: hidden;
|
|
16
|
+
|
|
17
|
+
&[open] {
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
display: flex;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.size-480-fXx4Vl {
|
|
24
|
+
width: 480px;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.size-600-X9nvTO {
|
|
28
|
+
width: 600px;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.size-720-_guzbs {
|
|
32
|
+
width: 720px;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.size-960-I8vXpb {
|
|
36
|
+
width: 960px;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.size-fullscreen-exf2cb {
|
|
40
|
+
border-radius: 0;
|
|
41
|
+
width: 100vw;
|
|
42
|
+
max-width: none;
|
|
43
|
+
height: 100dvh;
|
|
44
|
+
max-height: none;
|
|
45
|
+
}
|
|
46
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const Modal: import("react").ForwardRefExoticComponent<Omit<import("react").DialogHTMLAttributes<HTMLDialogElement>, "open" | "onClose" | "onCancel"> & {
|
|
2
|
+
open: boolean;
|
|
3
|
+
onClose?: VoidFunction;
|
|
4
|
+
size?: 480 | 600 | 720 | 960 | "fullscreen";
|
|
5
|
+
escapeKeyDown?: boolean;
|
|
6
|
+
backdropClick?: boolean;
|
|
7
|
+
lockScroll?: boolean;
|
|
8
|
+
getPortalContainer?: () => Element | null;
|
|
9
|
+
dataTestId?: string;
|
|
10
|
+
} & import("react").RefAttributes<HTMLDialogElement>>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { Portal } from "../Portal/index.js";
|
|
4
|
+
import { ModalSurface } from "./components/modal-surface/index.js";
|
|
5
|
+
const Modal = /*#__PURE__*/ forwardRef(({ open, getPortalContainer, ...restProps }, ref)=>open ? /*#__PURE__*/ jsx(Portal, {
|
|
6
|
+
getPortalContainer: getPortalContainer,
|
|
7
|
+
children: /*#__PURE__*/ jsx(ModalSurface, {
|
|
8
|
+
...restProps,
|
|
9
|
+
ref: ref
|
|
10
|
+
})
|
|
11
|
+
}) : null);
|
|
12
|
+
Modal.displayName = 'Modal';
|
|
13
|
+
export { Modal };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { DialogHTMLAttributes } from 'react';
|
|
2
|
+
export type ModalProps = Omit<DialogHTMLAttributes<HTMLDialogElement>, 'open' | 'onClose' | 'onCancel'> & {
|
|
3
|
+
/**
|
|
4
|
+
* Видимость окна. Закрытие запрашивается через onClose.
|
|
5
|
+
*/
|
|
6
|
+
open: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Обработчик запроса закрытия. Обновите open в вызывающем компоненте.
|
|
9
|
+
* Вызывается в том числе кнопкой закрытия Header.
|
|
10
|
+
*/
|
|
11
|
+
onClose?: VoidFunction;
|
|
12
|
+
/**
|
|
13
|
+
* Ширина в пикселях или окно на весь экран.
|
|
14
|
+
* @default 720
|
|
15
|
+
*/
|
|
16
|
+
size?: 480 | 600 | 720 | 960 | 'fullscreen';
|
|
17
|
+
/**
|
|
18
|
+
* Разрешить закрытие по Escape.
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
escapeKeyDown?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Разрешить закрытие по подложке.
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
26
|
+
backdropClick?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Блокировать прокрутку страницы.
|
|
29
|
+
* @default true
|
|
30
|
+
*/
|
|
31
|
+
lockScroll?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Контейнер портала. По умолчанию используется body текущего документа.
|
|
34
|
+
*/
|
|
35
|
+
getPortalContainer?: () => Element | null;
|
|
36
|
+
/**
|
|
37
|
+
* Идентификатор для автоматизированных тестов.
|
|
38
|
+
* Части наследуют его с суффиксами -header, -content, -footer и -controls.
|
|
39
|
+
*/
|
|
40
|
+
dataTestId?: string;
|
|
41
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function lockScroll(document: Document): () => void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const locks = new WeakMap();
|
|
2
|
+
function lockScroll(document) {
|
|
3
|
+
const { body, documentElement, defaultView } = document;
|
|
4
|
+
const existing = locks.get(document);
|
|
5
|
+
if (existing) existing.count += 1;
|
|
6
|
+
else {
|
|
7
|
+
locks.set(document, {
|
|
8
|
+
count: 1,
|
|
9
|
+
overflow: body.style.overflow,
|
|
10
|
+
paddingRight: body.style.paddingRight
|
|
11
|
+
});
|
|
12
|
+
const scrollbarWidth = (defaultView?.innerWidth ?? 0) - documentElement.clientWidth;
|
|
13
|
+
const hasStableGutter = defaultView?.getComputedStyle(documentElement).scrollbarGutter?.split(/\s+/).includes('stable');
|
|
14
|
+
if (scrollbarWidth > 0 && defaultView && !hasStableGutter) {
|
|
15
|
+
const paddingRight = parseFloat(defaultView.getComputedStyle(body).paddingRight) || 0;
|
|
16
|
+
body.style.paddingRight = `${paddingRight + scrollbarWidth}px`;
|
|
17
|
+
}
|
|
18
|
+
body.style.overflow = 'hidden';
|
|
19
|
+
}
|
|
20
|
+
return ()=>{
|
|
21
|
+
const lock = locks.get(document);
|
|
22
|
+
if (!lock) return;
|
|
23
|
+
lock.count -= 1;
|
|
24
|
+
if (0 === lock.count) {
|
|
25
|
+
body.style.overflow = lock.overflow;
|
|
26
|
+
body.style.paddingRight = lock.paddingRight;
|
|
27
|
+
locks.delete(document);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export { lockScroll };
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { Portal } from "../Portal/index.js";
|
|
4
4
|
import { PopoverSurface } from "./components/popover-surface/index.js";
|
|
5
5
|
const Popover = /*#__PURE__*/ forwardRef(({ open, anchorElement, getPortalContainer, ...restProps }, ref)=>{
|
|
6
6
|
if (!open || !anchorElement) return null;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
return /*#__PURE__*/ jsx(Portal, {
|
|
8
|
+
getPortalContainer: getPortalContainer ?? (()=>anchorElement.ownerDocument.body),
|
|
9
|
+
children: /*#__PURE__*/ jsx(PopoverSurface, {
|
|
10
|
+
...restProps,
|
|
11
|
+
anchorElement: anchorElement,
|
|
12
|
+
ref: ref
|
|
13
|
+
})
|
|
14
|
+
});
|
|
13
15
|
});
|
|
14
16
|
Popover.displayName = 'Popover';
|
|
15
17
|
export { Popover };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Portal } from "./portal.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
|
|
2
|
+
import { createPortal } from "react-dom";
|
|
3
|
+
function getBody() {
|
|
4
|
+
return "u" < typeof document ? null : document.body;
|
|
5
|
+
}
|
|
6
|
+
const Portal = /*#__PURE__*/ forwardRef(({ children, getPortalContainer = getBody, immediateMount = true }, ref)=>{
|
|
7
|
+
const [deferredContainer, setDeferredContainer] = useState(null);
|
|
8
|
+
let container = deferredContainer;
|
|
9
|
+
if (immediateMount) container = "u" < typeof document ? null : getPortalContainer() ?? null;
|
|
10
|
+
useEffect(()=>{
|
|
11
|
+
if (!immediateMount) setDeferredContainer(getPortalContainer() ?? null);
|
|
12
|
+
});
|
|
13
|
+
useImperativeHandle(ref, ()=>container, [
|
|
14
|
+
container
|
|
15
|
+
]);
|
|
16
|
+
return container ? /*#__PURE__*/ createPortal(children, container) : null;
|
|
17
|
+
});
|
|
18
|
+
Portal.displayName = 'Portal';
|
|
19
|
+
export { Portal };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export type PortalProps = {
|
|
3
|
+
/**
|
|
4
|
+
* Содержимое, которое будет перенесено в контейнер портала без дополнительной обёртки.
|
|
5
|
+
*/
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
/**
|
|
8
|
+
* Контейнер портала. По умолчанию используется body текущего документа.
|
|
9
|
+
* Если функция возвращает null или undefined, содержимое не рендерится.
|
|
10
|
+
*/
|
|
11
|
+
getPortalContainer?: () => Element | null | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Рендерить содержимое сразу, если контейнер уже существует.
|
|
14
|
+
* При false контейнер определяется после монтирования, чтобы дождаться DOM-контейнера из ref.
|
|
15
|
+
* @default true
|
|
16
|
+
*/
|
|
17
|
+
immediateMount?: boolean;
|
|
18
|
+
};
|
|
File without changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { Button } from './components/Button/index.js';
|
|
2
2
|
export type { ButtonProps } from './components/Button/index.js';
|
|
3
|
+
export { Input } from './components/Input/index.js';
|
|
4
|
+
export type { InputProps } from './components/Input/index.js';
|
|
3
5
|
export { Spinner } from './components/Spinner/index.js';
|
|
4
6
|
export type { SpinnerProps } from './components/Spinner/index.js';
|
|
5
7
|
export { Typography, TypographyText, TypographyTitle, Text, Title } from './components/Typography/index.js';
|
|
@@ -8,3 +10,7 @@ export { Popover } from './components/Popover/index.js';
|
|
|
8
10
|
export type { PopoverProps, PopoverPosition } from './components/Popover/index.js';
|
|
9
11
|
export { Collapse } from './components/Collapse/index.js';
|
|
10
12
|
export type { CollapseProps } from './components/Collapse/index.js';
|
|
13
|
+
export { Modal, ModalComponent, ModalHeader, ModalContent, ModalFooter, ModalControls, } from './components/Modal/index.js';
|
|
14
|
+
export { Portal } from './components/Portal/index.js';
|
|
15
|
+
export type { PortalProps } from './components/Portal/index.js';
|
|
16
|
+
export type { ModalProps, HeaderProps as ModalHeaderProps, ContentProps as ModalContentProps, FooterProps as ModalFooterProps, ControlsProps as ModalControlsProps, } from './components/Modal/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export { Button } from "./components/Button/index.js";
|
|
2
|
+
export { Input } from "./components/Input/index.js";
|
|
2
3
|
export { Spinner } from "./components/Spinner/index.js";
|
|
3
4
|
export { Text, Title, Typography, TypographyText, TypographyTitle } from "./components/Typography/index.js";
|
|
4
5
|
export { Popover } from "./components/Popover/index.js";
|
|
5
6
|
export { Collapse } from "./components/Collapse/index.js";
|
|
7
|
+
export { Modal, ModalComponent, ModalContent, ModalControls, ModalFooter, ModalHeader } from "./components/Modal/index.js";
|
|
8
|
+
export { Portal } from "./components/Portal/index.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koslibs/components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Shared React components for koslibs projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"react-dom": "^18.3.1 || ^19.0.0"
|
|
81
81
|
},
|
|
82
82
|
"dependencies": {
|
|
83
|
-
"@koslibs/icons": "1.0
|
|
83
|
+
"@koslibs/icons": "1.2.0",
|
|
84
84
|
"@popperjs/core": "2.11.8",
|
|
85
85
|
"classnames": "2.5.1"
|
|
86
86
|
}
|