@konomi-app/ui 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 adachi
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.
@@ -0,0 +1 @@
1
+ export * from './loading-overlay';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './loading-overlay';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,25 @@
1
+ type ConstructorProps = Readonly<Partial<{
2
+ label: string;
3
+ progress: number;
4
+ }>>;
5
+ export declare class LoadingOverlay {
6
+ #private;
7
+ constructor(props?: ConstructorProps);
8
+ show(): void;
9
+ /**
10
+ * @deprecated このメソッドは非推奨です。代わりに`show`メソッドを使用してください。
11
+ */
12
+ start(): void;
13
+ hide(): void;
14
+ /**
15
+ * @deprecated このメソッドは非推奨です。代わりに`hide`メソッドを使用してください。
16
+ */
17
+ stop(): void;
18
+ set label(label: string);
19
+ set progress(progress: number);
20
+ private render;
21
+ /** JavaScript中にページを離れようとした場合にアラートを表示します */
22
+ private beforeunload;
23
+ private addStyle;
24
+ }
25
+ export {};
@@ -0,0 +1,182 @@
1
+ import { css } from '@emotion/css';
2
+ export class LoadingOverlay {
3
+ #shown;
4
+ #label;
5
+ #html;
6
+ #progress;
7
+ #root;
8
+ #loaderElement;
9
+ #progressElement;
10
+ #contentElement;
11
+ constructor(props = {}) {
12
+ this.#shown = false;
13
+ this.#label = props.label || '';
14
+ this.#html = '';
15
+ this.#progress = props.progress ?? null;
16
+ const root = document.createElement('div');
17
+ this.#root = root;
18
+ document.body.append(root);
19
+ const container = document.createElement('div');
20
+ container.classList.add('__c');
21
+ this.#root.append(container);
22
+ const loaderElement = document.createElement('div');
23
+ loaderElement.classList.add('__l');
24
+ this.#loaderElement = loaderElement;
25
+ container.append(loaderElement);
26
+ const progressElement = document.createElement('div');
27
+ progressElement.classList.add('__p');
28
+ this.#progressElement = progressElement;
29
+ container.append(progressElement);
30
+ const contentElement = document.createElement('div');
31
+ this.#contentElement = contentElement;
32
+ container.append(contentElement);
33
+ this.addStyle();
34
+ this.render();
35
+ }
36
+ show() {
37
+ this.#shown = true;
38
+ this.#loaderElement.style.animationName = 'spin';
39
+ window.removeEventListener('beforeunload', this.beforeunload);
40
+ document.body.style.overflow = 'hidden';
41
+ this.render();
42
+ }
43
+ /**
44
+ * @deprecated このメソッドは非推奨です。代わりに`show`メソッドを使用してください。
45
+ */
46
+ start() {
47
+ this.show();
48
+ }
49
+ hide() {
50
+ this.#shown = false;
51
+ this.#progress = 0;
52
+ this.#loaderElement.style.animationName = 'none';
53
+ window.removeEventListener('beforeunload', this.beforeunload);
54
+ document.body.style.overflow = 'auto';
55
+ this.render();
56
+ }
57
+ /**
58
+ * @deprecated このメソッドは非推奨です。代わりに`hide`メソッドを使用してください。
59
+ */
60
+ stop() {
61
+ this.hide();
62
+ }
63
+ set label(label) {
64
+ this.#label = label;
65
+ this.render();
66
+ }
67
+ set progress(progress) {
68
+ this.#progress = progress;
69
+ this.render();
70
+ }
71
+ render() {
72
+ this.#root.style.opacity = this.#shown ? '1' : '0';
73
+ this.#root.style.pointerEvents = this.#shown ? 'all' : 'none';
74
+ this.#progressElement.style.width = `${this.#progress}%`;
75
+ if (this.#html) {
76
+ this.#contentElement.innerHTML = this.#html;
77
+ }
78
+ else {
79
+ if (this.#label instanceof Array) {
80
+ this.#contentElement.innerHTML = `<div>${this.#label.join('</div><div>')}</div>`;
81
+ }
82
+ else {
83
+ this.#contentElement.innerText = this.#label;
84
+ }
85
+ }
86
+ }
87
+ /** JavaScript中にページを離れようとした場合にアラートを表示します */
88
+ beforeunload(event) {
89
+ event.preventDefault();
90
+ event.returnValue = '';
91
+ }
92
+ addStyle() {
93
+ this.#root.classList.add(css `
94
+ font-family: 'Yu Gothic Medium', '游ゴシック', YuGothic, 'メイリオ',
95
+ 'Hiragino Kaku Gothic ProN', Meiryo, sans-serif;
96
+ color: #356;
97
+ font-size: 17px;
98
+
99
+ overflow: hidden;
100
+ background-color: #fff6;
101
+ backdrop-filter: blur(10px);
102
+ box-sizing: content-box;
103
+
104
+ position: fixed;
105
+ inset: 0;
106
+ width: 100vw;
107
+ height: 100vh;
108
+
109
+ display: grid;
110
+ place-items: center;
111
+ transition: all 250ms ease;
112
+ z-index: 1000;
113
+ opacity: 0;
114
+ transition: all 250ms ease;
115
+
116
+ .__c {
117
+ display: flex;
118
+ flex-direction: column;
119
+ align-items: center;
120
+ justify-content: center;
121
+ gap: 32px;
122
+ padding: 32px 64px;
123
+ background-color: #fffc;
124
+ border-radius: 8px;
125
+ box-shadow: 0 5px 24px -6px #0002;
126
+ min-width: 300px;
127
+ max-width: 90vw;
128
+ min-height: 200px;
129
+ position: relative;
130
+ overflow: hidden;
131
+ }
132
+
133
+ .__l {
134
+ font-size: 48px;
135
+ width: 1em;
136
+ height: 1em;
137
+ position: relative;
138
+ border: 2px solid #2563ebaa;
139
+ border-radius: 1em;
140
+ animation-duration: 2s;
141
+ animation-timing-function: ease;
142
+ animation-delay: 0s;
143
+ animation-iteration-count: infinite;
144
+ animation-direction: normal;
145
+ animation-fill-mode: none;
146
+ animation-play-state: running;
147
+ }
148
+
149
+ .__p {
150
+ position: absolute;
151
+ bottom: 0px;
152
+ left: 0;
153
+ width: 0%;
154
+ height: 3px;
155
+ background-color: #2563eb;
156
+ transition: all 250ms ease;
157
+ }
158
+
159
+ @keyframes spin {
160
+ 0% {
161
+ transform: rotate(0deg);
162
+ border-radius: 1em;
163
+ }
164
+ 20% {
165
+ transform: rotate(0deg);
166
+ }
167
+ 30%,
168
+ 60% {
169
+ border-radius: 0.25em;
170
+ }
171
+ 70% {
172
+ transform: rotate(180deg);
173
+ }
174
+ 100% {
175
+ transform: rotate(180deg);
176
+ border-radius: 1em;
177
+ }
178
+ }
179
+ `);
180
+ }
181
+ }
182
+ //# sourceMappingURL=loading-overlay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loading-overlay.js","sourceRoot":"","sources":["../src/loading-overlay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAInC,MAAM,OAAO,cAAc;IACzB,MAAM,CAAU;IAChB,MAAM,CAAoB;IAC1B,KAAK,CAAS;IACd,SAAS,CAAgB;IAEzB,KAAK,CAAiB;IACtB,cAAc,CAAiB;IAC/B,gBAAgB,CAAiB;IACjC,eAAe,CAAiB;IAEhC,YAAmB,QAA0B,EAAE;QAC7C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;QAChC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC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AK,CAAC,KAAK,GAAG,GAAG,IAAI,CAAC,SAAS,GAAG,CAAC;QAEzD,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,IAAI,CAAC,eAAe,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC;SAC7C;aAAM;YACL,IAAI,IAAI,CAAC,MAAM,YAAY,KAAK,EAAE;gBAChC,IAAI,CAAC,eAAe,CAAC,SAAS,GAAG,QAAQ,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC;aAClF;iBAAM;gBACL,IAAI,CAAC,eAAe,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC;aAC9C;SACF;IACH,CAAC;IAED,2CAA2C;IACnC,YAAY,CAAC,KAAwB;QAC3C,KAAK,CAAC,cAAc,EAAE,CAAC;QACvB,KAAK,CAAC,WAAW,GAAG,EAAE,CAAC;IACzB,CAAC;IAEO,QAAQ;QACd,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAsF3B,CAAC,CAAC;IACL,CAAC;CACF"}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@konomi-app/ui",
3
+ "version": "0.1.0",
4
+ "main": "index.js",
5
+ "repository": "https://github.com/local-bias/ui.git",
6
+ "author": "adachi",
7
+ "license": "MIT",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "prepare": "yarn run build"
11
+ },
12
+ "dependencies": {
13
+ "@emotion/css": "^11.10.6"
14
+ },
15
+ "devDependencies": {
16
+ "typescript": "^4.9.5"
17
+ },
18
+ "prettier": {
19
+ "printWidth": 100,
20
+ "arrowParens": "always",
21
+ "singleQuote": true,
22
+ "jsxSingleQuote": true,
23
+ "tabWidth": 2,
24
+ "trailingComma": "es5",
25
+ "endOfLine": "lf"
26
+ }
27
+ }