@fullkekw/popup 2.0.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/LICENSE +21 -0
- package/README.md +204 -0
- package/dist/Interfaces.d.ts +69 -0
- package/dist/Package.d.ts +14 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.es.js +783 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +35 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/styles.css +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 fullkekw
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
Headless popup component for React, with built-in typescript types!
|
|
4
|
+
|
|
5
|
+
## đ Installation
|
|
6
|
+
```bash
|
|
7
|
+
$ npm install @fullkekw/popup
|
|
8
|
+
$ pnpm install @fullkekw/popup
|
|
9
|
+
$ yarn add @fullkekw/popup
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Usage
|
|
13
|
+
```tsx
|
|
14
|
+
import { FC } from 'react';
|
|
15
|
+
import '@fullkekw/popup/css'; // Basic styles
|
|
16
|
+
|
|
17
|
+
const Page: FC = (props) => {
|
|
18
|
+
const popupId1 = 'popupId1'
|
|
19
|
+
const popupId2 = 'popupId2'
|
|
20
|
+
|
|
21
|
+
return <div>
|
|
22
|
+
{/* Must be inside <body> tag */}
|
|
23
|
+
<PopupLayer>
|
|
24
|
+
<PopupWindow id={popupId1}>
|
|
25
|
+
Popup Content
|
|
26
|
+
|
|
27
|
+
<PopupButton popupId={popupId1}>
|
|
28
|
+
Close popup
|
|
29
|
+
</PopupButton>
|
|
30
|
+
|
|
31
|
+
<PopupButton popupId={popupId2}>
|
|
32
|
+
Open popup 2
|
|
33
|
+
</PopupButton>
|
|
34
|
+
</PopupWindow>
|
|
35
|
+
</PopupLayer>
|
|
36
|
+
</div>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default Page;
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## ⨠Features
|
|
43
|
+
- Popup can be closed by press escape or by click on layer
|
|
44
|
+
- Synthetic state handling (useState can be passed into the component)
|
|
45
|
+
- Headless component with only basic styling
|
|
46
|
+
- Built-in animations
|
|
47
|
+
- Prevent user from state change (only synthetic)
|
|
48
|
+
- Implement [WAI-ARIA Dialog Pattern](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/)
|
|
49
|
+
- Popups can be nested
|
|
50
|
+
- Will always be on top of the stacking context
|
|
51
|
+
- Hightly customizable (you can even turn off scroll hide!)
|
|
52
|
+
- Does not break elements with sticky position on oveflow hide
|
|
53
|
+
|
|
54
|
+
## đ Examples
|
|
55
|
+
Synthetic state handle. Will be opened by default
|
|
56
|
+
```tsx
|
|
57
|
+
import { FC, useState } from 'react';
|
|
58
|
+
import '@fullkekw/popup/css';
|
|
59
|
+
|
|
60
|
+
const Page: FC = (props) => {
|
|
61
|
+
const popupId1 = 'popupId1'
|
|
62
|
+
|
|
63
|
+
const [state, setState] = useState(true)
|
|
64
|
+
|
|
65
|
+
return <div>
|
|
66
|
+
<PopupLayer>
|
|
67
|
+
<PopupWindow id={popupId1} isOpen={state} setIsOpen={setState}>
|
|
68
|
+
Popup Content
|
|
69
|
+
|
|
70
|
+
<PopupButton popupId={popupId1}>
|
|
71
|
+
Close popup
|
|
72
|
+
</PopupButton>
|
|
73
|
+
</PopupWindow>
|
|
74
|
+
</PopupLayer>
|
|
75
|
+
</div>
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default Page;
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Disable exit on layer & escape
|
|
82
|
+
```tsx
|
|
83
|
+
import { FC, useState } from 'react';
|
|
84
|
+
import '@fullkekw/popup/css';
|
|
85
|
+
|
|
86
|
+
const Page: FC = (props) => {
|
|
87
|
+
const popupId1 = 'popupId1'
|
|
88
|
+
|
|
89
|
+
return <div>
|
|
90
|
+
<PopupLayer>
|
|
91
|
+
<PopupWindow id={popupId1} settings={{exitOnLayer: false, exitOnDocument: false}}>
|
|
92
|
+
Popup Content
|
|
93
|
+
|
|
94
|
+
<PopupButton popupId={popupId1}>
|
|
95
|
+
Close popup
|
|
96
|
+
</PopupButton>
|
|
97
|
+
</PopupWindow>
|
|
98
|
+
</PopupLayer>
|
|
99
|
+
</div>
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export default Page;
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## âī¸ API
|
|
106
|
+
```ts
|
|
107
|
+
export type PopupWindowAnimationType = 'fade' | 'scale' | null
|
|
108
|
+
|
|
109
|
+
export interface PopupSettings {
|
|
110
|
+
/** Prevent state change due to user interactions (only synthetic) */
|
|
111
|
+
preventStateChange?: boolean
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Close popup on Escape
|
|
115
|
+
*
|
|
116
|
+
* @default true
|
|
117
|
+
*/
|
|
118
|
+
exitOnEscape?: boolean
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Close popup on document click
|
|
122
|
+
*
|
|
123
|
+
* @default true
|
|
124
|
+
*/
|
|
125
|
+
exitOnDocument?: boolean
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Disable document scroll when popup open
|
|
129
|
+
*
|
|
130
|
+
* @default true
|
|
131
|
+
*/
|
|
132
|
+
disableScroll?: boolean
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface PopupNode {
|
|
136
|
+
id: string
|
|
137
|
+
open: boolean
|
|
138
|
+
zIndex: number
|
|
139
|
+
settings: PopupSettings
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface PopupContextProps {
|
|
143
|
+
nodes: PopupNode[]
|
|
144
|
+
toggleNode(id: string, state?: boolean): void
|
|
145
|
+
registerNode(node: PopupNode): void
|
|
146
|
+
toggleDocument(id: string, e: React.MouseEvent): void
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
export interface PopupLayerProps {
|
|
152
|
+
children: ReactNode | ReactNode[]
|
|
153
|
+
|
|
154
|
+
className?: string
|
|
155
|
+
settings?: PopupSettings
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
export interface PopupWindowProps extends React.DetailsHTMLAttributes<HTMLDivElement> {
|
|
161
|
+
id: string
|
|
162
|
+
|
|
163
|
+
children?: ReactNode | ReactNode[]
|
|
164
|
+
layerClassName?: string
|
|
165
|
+
settings?: PopupSettings
|
|
166
|
+
|
|
167
|
+
/** Passed useState value */
|
|
168
|
+
isOpen?: boolean
|
|
169
|
+
|
|
170
|
+
/** Passed useState setter */
|
|
171
|
+
setIsOpen?(isOpen: boolean): void
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Popup animation
|
|
175
|
+
*
|
|
176
|
+
* @default "scale"
|
|
177
|
+
*/
|
|
178
|
+
animation?: PopupWindowAnimationType
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
export interface PopupButtonProps extends React.DetailsHTMLAttributes<HTMLElement> {
|
|
184
|
+
popupId: string
|
|
185
|
+
|
|
186
|
+
children?: ReactNode | ReactNode[]
|
|
187
|
+
|
|
188
|
+
onClick?(e: React.MouseEvent): void
|
|
189
|
+
disabled?: boolean
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Tag name
|
|
193
|
+
*
|
|
194
|
+
* @default "button"
|
|
195
|
+
*/
|
|
196
|
+
as?: 'button' | 'div'
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## âī¸ Migration Guides
|
|
201
|
+
- [From @fullkekw/fkw-popup@1.2.5](./docs/migration.md#fullkekwfkw-popup125)
|
|
202
|
+
|
|
203
|
+
## ÂŠī¸ License
|
|
204
|
+
Licensed under MIT
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { default as React, ReactNode } from 'react';
|
|
2
|
+
export type PopupWindowAnimationType = 'fade' | 'scale' | null;
|
|
3
|
+
export interface PopupSettings {
|
|
4
|
+
/** Prevent state change due to user interactions (only synthetic) */
|
|
5
|
+
preventStateChange?: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Close popup on Escape
|
|
8
|
+
*
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
11
|
+
exitOnEscape?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Close popup on document click
|
|
14
|
+
*
|
|
15
|
+
* @default true
|
|
16
|
+
*/
|
|
17
|
+
exitOnDocument?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Disable document scroll when popup open
|
|
20
|
+
*
|
|
21
|
+
* @default true
|
|
22
|
+
*/
|
|
23
|
+
disableScroll?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface PopupNode {
|
|
26
|
+
id: string;
|
|
27
|
+
open: boolean;
|
|
28
|
+
zIndex: number;
|
|
29
|
+
settings: PopupSettings;
|
|
30
|
+
}
|
|
31
|
+
export interface PopupContextProps {
|
|
32
|
+
nodes: PopupNode[];
|
|
33
|
+
toggleNode(id: string, state?: boolean): void;
|
|
34
|
+
registerNode(node: PopupNode): void;
|
|
35
|
+
toggleDocument(id: string, e: React.MouseEvent): void;
|
|
36
|
+
}
|
|
37
|
+
export interface PopupLayerProps {
|
|
38
|
+
children: ReactNode | ReactNode[];
|
|
39
|
+
className?: string;
|
|
40
|
+
settings?: PopupSettings;
|
|
41
|
+
}
|
|
42
|
+
export interface PopupWindowProps extends React.DetailsHTMLAttributes<HTMLDivElement> {
|
|
43
|
+
id: string;
|
|
44
|
+
children?: ReactNode | ReactNode[];
|
|
45
|
+
layerClassName?: string;
|
|
46
|
+
settings?: PopupSettings;
|
|
47
|
+
/** Passed useState value */
|
|
48
|
+
isOpen?: boolean;
|
|
49
|
+
/** Passed useState setter */
|
|
50
|
+
setIsOpen?(isOpen: boolean): void;
|
|
51
|
+
/**
|
|
52
|
+
* Popup animation
|
|
53
|
+
*
|
|
54
|
+
* @default "scale"
|
|
55
|
+
*/
|
|
56
|
+
animation?: PopupWindowAnimationType;
|
|
57
|
+
}
|
|
58
|
+
export interface PopupButtonProps extends React.DetailsHTMLAttributes<HTMLElement> {
|
|
59
|
+
popupId: string;
|
|
60
|
+
children?: ReactNode | ReactNode[];
|
|
61
|
+
onClick?(e: React.MouseEvent): void;
|
|
62
|
+
disabled?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Tag name
|
|
65
|
+
*
|
|
66
|
+
* @default "button"
|
|
67
|
+
*/
|
|
68
|
+
as?: 'button' | 'div';
|
|
69
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { PopupButtonProps, PopupLayerProps, PopupWindowProps } from './Interfaces';
|
|
3
|
+
/**
|
|
4
|
+
* Popup layer. Must be inside body tag
|
|
5
|
+
*/
|
|
6
|
+
export declare const PopupLayer: FC<PopupLayerProps>;
|
|
7
|
+
/**
|
|
8
|
+
* Popup window
|
|
9
|
+
*/
|
|
10
|
+
export declare const PopupWindow: FC<PopupWindowProps>;
|
|
11
|
+
/**
|
|
12
|
+
* Popup trigger button
|
|
13
|
+
*/
|
|
14
|
+
export declare const PopupButton: FC<PopupButtonProps>;
|
package/dist/index.d.ts
ADDED