@esportsplus/ui 0.0.8 → 0.0.9

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,15 @@
1
+ declare function deactivate(): void;
2
+ declare const _default: {
3
+ deactivate: typeof deactivate;
4
+ error: (messages: string | string[], seconds?: number) => void;
5
+ html: () => () => "" | {
6
+ content: string;
7
+ type: string;
8
+ values: never[];
9
+ };
10
+ info: (messages: string | string[], seconds?: number) => void;
11
+ processing: () => void;
12
+ success: (messages: string | string[], seconds?: number) => void;
13
+ types: readonly ["error", "info", "success"];
14
+ };
15
+ export default _default;
@@ -0,0 +1,150 @@
1
+ import { reactive } from '@esportsplus/reactivity';
2
+ import { html } from '@esportsplus/template';
3
+ let modifiers = {
4
+ error: 'red',
5
+ info: 'black',
6
+ success: 'green'
7
+ }, state = reactive({
8
+ active: false,
9
+ messages: new Set,
10
+ processing: false,
11
+ seconds: 0,
12
+ state: 'activating',
13
+ type: ''
14
+ }), timeout = 250;
15
+ function activate(key, messages, seconds = 0) {
16
+ if (!Array.isArray(messages)) {
17
+ messages = [messages];
18
+ }
19
+ if (!messages.length) {
20
+ return;
21
+ }
22
+ state.messages.clear();
23
+ for (let message of messages) {
24
+ state.messages.add(message);
25
+ }
26
+ state.state = 'activating';
27
+ state.type = key;
28
+ if (state.active) {
29
+ state.active = true;
30
+ state.processing = false;
31
+ if (seconds) {
32
+ if (!state.seconds) {
33
+ state.seconds = seconds;
34
+ }
35
+ setTimeout(() => {
36
+ if (messages && messages.length < (state?.messages?.size || 0)) {
37
+ for (let message of messages) {
38
+ state.messages.delete(message);
39
+ }
40
+ state.messages = state.messages;
41
+ }
42
+ else {
43
+ deactivate();
44
+ }
45
+ }, 400 * seconds);
46
+ }
47
+ else {
48
+ state.seconds = 0;
49
+ }
50
+ return;
51
+ }
52
+ setTimeout(() => {
53
+ state.active = true;
54
+ state.processing = false;
55
+ if (seconds) {
56
+ if (!state.seconds) {
57
+ state.seconds = seconds;
58
+ }
59
+ setTimeout(() => {
60
+ if (messages && messages.length < (state?.messages?.size || 0)) {
61
+ for (let message of messages) {
62
+ state.messages.delete(message);
63
+ }
64
+ state.messages = state.messages;
65
+ }
66
+ else {
67
+ deactivate();
68
+ }
69
+ }, 400 * seconds);
70
+ }
71
+ else {
72
+ state.seconds = 0;
73
+ }
74
+ }, timeout);
75
+ }
76
+ function deactivate() {
77
+ state.state = 'deactivating';
78
+ setTimeout(() => {
79
+ state.active = false;
80
+ state.messages.clear();
81
+ state.processing = false;
82
+ }, timeout);
83
+ }
84
+ const error = (messages, seconds = 0) => activate('error', messages, seconds);
85
+ const info = (messages, seconds = 0) => activate('info', messages, seconds);
86
+ const processing = () => {
87
+ state.state = 'activating';
88
+ state.processing = true;
89
+ setTimeout(() => {
90
+ state.active = true;
91
+ }, timeout);
92
+ };
93
+ const success = (messages, seconds = 0) => activate('success', messages, seconds);
94
+ const h = () => {
95
+ return () => state.active || state.processing ? html `
96
+ <div class='alert anchor anchor--ne ${() => state.active && '--active'} ${() => `alert--${state.state}`}'>
97
+ ${() => !state.processing ? html `
98
+ <div class="alert-close --flex-start --margin-right --margin-100" onclick='${deactivate}'>
99
+ <div class='button --background-state ${() => `--background-${modifiers[state.type] || 'black'}`} --color-state --color-white --flex-center --padding-300'>
100
+ <div class="icon --size-300">
101
+ <svg width="16" height="16" viewBox="0 0 16 16">
102
+ <path d="M3.527 14.948a.176.176 0 01-.248 0L1.051 12.72a.176.176 0 010-.248l11.42-11.419a.176.176 0 01.248 0l2.229 2.228a.174.174 0 010 .248L3.527 14.948z"/>
103
+ <path d="M12.472 14.948c.068.068.18.068.248 0l2.229-2.229a.176.176 0 000-.248L3.528 1.052a.176.176 0 00-.248 0L1.052 3.28a.176.176 0 000 .248l11.42 11.42z"/>
104
+ </svg>
105
+ </div>
106
+ </div>
107
+ </div>
108
+ ` : ''}
109
+
110
+ <div class="card --overflow-hidden" style='--background: var(--color-white-400)'>
111
+ <div class="alert-message ${() => !state.processing && '--active'} --flex-row --padding --padding-horizontal-500 --padding-vertical-400">
112
+ <div class='--flex-row --flex-fill --flex-vertical'>
113
+ <div class="--flex-fill --flex-column --padding-right --padding-400">
114
+ <h5 class="page-title">
115
+ ${() => state.type.charAt(0).toUpperCase() + state.type.slice(1)}
116
+ </h5>
117
+ ${() => state.type && [...state.messages].map((message) => html `
118
+ <p class='--margin-top --margin-border-width-500'>${message}</p>
119
+ `)}
120
+ </div>
121
+
122
+ ${() => !state.processing && state.seconds ? html `
123
+ <svg class='alert-timer' style='--animation-duration: ${state.seconds}s;'>
124
+ <circle class="alert-timer-bg" cx="50%" cy="50%" r="40%" style='--border-color: var(--color-grey-500);' />
125
+ <circle class="alert-timer-meter" cx="50%" cy="50%" r="40%" style='--border-color: var(--color-black-300);' />
126
+ </svg>
127
+ ` : ''}
128
+ </div>
129
+ </div>
130
+
131
+ <div class='alert-processing ${() => state.processing && '--active'} --flex-row --flex-vertical --padding --padding-500'>
132
+ <div class="processing">
133
+ <span class='processing-ring'></span>
134
+ </div>
135
+ <div class='text --flex-fill --margin-left --margin-300 --text-bold' style='--color: var(--color-text-500)'>
136
+ Processing
137
+
138
+ <div class='ellipsis'>
139
+ <span class='ellipsis-dot --margin-left --margin-border-width'>.</span>
140
+ <span class='ellipsis-dot --margin-left --margin-border-width'>.</span>
141
+ <span class='ellipsis-dot --margin-left --margin-border-width'>.</span>
142
+ </div>
143
+ </div>
144
+ </div>
145
+ </div>
146
+ </div>
147
+ ` : '';
148
+ };
149
+ const types = ['error', 'info', 'success'];
150
+ export default { deactivate, error, html: h, info, processing, success, types };
@@ -0,0 +1,6 @@
1
+ import { Action, Reactive } from './types';
2
+ export default function (action: Action, reactive?: Reactive): {
3
+ content: string;
4
+ type: string;
5
+ values: never[];
6
+ };
@@ -0,0 +1,56 @@
1
+ import { response } from '@esportsplus/action';
2
+ import { html } from '@esportsplus/template';
3
+ import alert from '../../components/alert';
4
+ function parse(input) {
5
+ let data = {};
6
+ for (let path in input) {
7
+ let bucket = data, keys = path.indexOf('.') !== -1 ? path.split('.') : [path];
8
+ for (let i = 0; i < keys.length - 1; i++) {
9
+ bucket = bucket[keys[i]] = bucket[keys[i]] || {};
10
+ }
11
+ bucket[keys[keys.length - 1]] = input[path];
12
+ }
13
+ return data;
14
+ }
15
+ ;
16
+ export default function (action, reactive = {}) {
17
+ return html({
18
+ onclick: function (event) {
19
+ let trigger = event.target;
20
+ if (trigger?.type !== 'submit') {
21
+ return;
22
+ }
23
+ event.preventDefault();
24
+ this.dispatchEvent(new SubmitEvent('submit', { cancelable: true, bubbles: true, submitter: trigger }));
25
+ },
26
+ onsubmit: async function (event) {
27
+ event.preventDefault();
28
+ let { errors } = await action({
29
+ alert,
30
+ input: parse(Object.fromEntries(new FormData(this)?.entries())),
31
+ processing: {
32
+ end: (deactivate = true) => {
33
+ if (deactivate) {
34
+ alert.deactivate();
35
+ }
36
+ event?.submitter?.classList.remove('button--processing');
37
+ },
38
+ start: () => {
39
+ alert.processing();
40
+ event?.submitter?.classList.add('button--processing');
41
+ }
42
+ },
43
+ response
44
+ });
45
+ if (errors && 'errors' in reactive) {
46
+ let messages = {};
47
+ for (let i = 0, n = errors.length; i < n; i++) {
48
+ let { message, path } = errors[i];
49
+ messages[path] = `${message[0].toUpperCase()}${message.substring(1)}`;
50
+ }
51
+ reactive.errors = messages;
52
+ }
53
+ }
54
+ });
55
+ }
56
+ ;
@@ -0,0 +1,5 @@
1
+ import action from './action';
2
+ declare const _default: {
3
+ action: typeof action;
4
+ };
5
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import action from './action';
2
+ export default { action };
@@ -0,0 +1,17 @@
1
+ import { layout } from '../../components/page';
2
+ type Data = {
3
+ action?: any;
4
+ button?: {
5
+ class?: string;
6
+ content?: any;
7
+ style?: string;
8
+ };
9
+ content?: any;
10
+ width?: string;
11
+ };
12
+ declare const _default: (data: Data & Parameters<typeof layout>[0]) => {
13
+ content: string;
14
+ type: string;
15
+ values: never[];
16
+ };
17
+ export default _default;
@@ -0,0 +1,17 @@
1
+ import { html } from '@esportsplus/template';
2
+ import { layout } from '../../components/page';
3
+ export default (data) => {
4
+ data.content = html `
5
+ <form class='--margin-top --margin-800' ${data?.action || ''}>
6
+ ${data?.content || ''}
7
+
8
+ ${data?.button ? html `
9
+ <button class="button ${data?.button?.class || ''}" style='${data?.button?.style || ''}'>
10
+ ${data?.button?.content || ''}
11
+ </button>
12
+ ` : ''}
13
+ </form>
14
+ `;
15
+ data.width = data?.width || '480px';
16
+ return layout(data);
17
+ };
@@ -0,0 +1,19 @@
1
+ import { response, Response } from '@esportsplus/action';
2
+ import alert from '../../components/alert';
3
+ type Action = (data: Payload) => Promise<Errors> | Errors;
4
+ type Errors = {
5
+ errors?: Response<unknown>['errors'];
6
+ };
7
+ type Payload = {
8
+ alert: typeof alert;
9
+ input: Record<string, any>;
10
+ response: typeof response;
11
+ processing: {
12
+ end: (deactivate: boolean) => void;
13
+ start: VoidFunction;
14
+ };
15
+ };
16
+ type Reactive = {
17
+ errors?: Record<string, string>;
18
+ };
19
+ export { Action, Errors, Payload, Reactive };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export { default as form } from './form';
2
+ export { default as page } from './page';
3
+ export { default as scrollbar } from './scrollbar';
4
+ export { default as state } from './state';
@@ -0,0 +1,4 @@
1
+ export { default as form } from './form';
2
+ export { default as page } from './page';
3
+ export { default as scrollbar } from './scrollbar';
4
+ export { default as state } from './state';
@@ -0,0 +1,16 @@
1
+ import layout from './layout';
2
+ declare const _default: {
3
+ layout: ({ content, subtitle, suptitle, title, width }: {
4
+ content?: any;
5
+ subtitle?: string | undefined;
6
+ suptitle?: string | undefined;
7
+ title?: string | undefined;
8
+ width?: string | undefined;
9
+ }) => {
10
+ content: string;
11
+ type: string;
12
+ values: never[];
13
+ };
14
+ };
15
+ export default _default;
16
+ export { layout };
@@ -0,0 +1,3 @@
1
+ import layout from './layout';
2
+ export default { layout };
3
+ export { layout };
@@ -0,0 +1,13 @@
1
+ type Data = {
2
+ content?: any;
3
+ subtitle?: string;
4
+ suptitle?: string;
5
+ title?: string;
6
+ width?: string;
7
+ };
8
+ declare const _default: ({ content, subtitle, suptitle, title, width }: Data) => {
9
+ content: string;
10
+ type: string;
11
+ values: never[];
12
+ };
13
+ export default _default;
@@ -0,0 +1,24 @@
1
+ import { html } from '@esportsplus/template';
2
+ export default ({ content, subtitle, suptitle, title, width }) => html `
3
+ <div class="container --slide-in --margin-vertical --margin-900" style="${width && `--max-width: ${width};`}">
4
+ ${suptitle ? html `
5
+ <span class="page-suptitle --text-bold --text-crop --text-uppercase --text-200" style="--color-default: var(--color-primary-400);letter-spacing: 0.24px;">
6
+ ${suptitle}
7
+ </span>
8
+ ` : ''}
9
+
10
+ ${title ? html `
11
+ <h1 class="page-title --line-height-200 --margin-300 ${!subtitle && '--text-crop-bottom'} ${suptitle ? '--margin-top' : '--text-crop-top'}">
12
+ ${title}
13
+ </h1>
14
+ ` : ''}
15
+
16
+ ${subtitle ? html `
17
+ <span class="page-subtitle --margin-top --margin-300 --text-crop-bottom">
18
+ ${subtitle}
19
+ </span>
20
+ ` : ''}
21
+
22
+ ${content || ''}
23
+ </div>
24
+ `;
@@ -0,0 +1,16 @@
1
+ declare const _default: ({ fixed, style }?: {
2
+ fixed?: boolean | undefined;
3
+ style?: string | undefined;
4
+ }) => {
5
+ attributes: {
6
+ content: string;
7
+ type: string;
8
+ values: never[];
9
+ };
10
+ html: {
11
+ content: string;
12
+ type: string;
13
+ values: never[];
14
+ };
15
+ };
16
+ export default _default;
@@ -0,0 +1,36 @@
1
+ import { reactive } from '@esportsplus/reactivity';
2
+ import { html } from '@esportsplus/template';
3
+ let root = document.body, width;
4
+ export default ({ fixed, style } = {}) => {
5
+ let state = reactive({
6
+ height: 100,
7
+ translate: 0
8
+ });
9
+ return {
10
+ attributes: html({
11
+ class: () => {
12
+ return '--scrollbar';
13
+ },
14
+ onscroll: function () {
15
+ if (width === undefined) {
16
+ width = this.offsetWidth - this.clientWidth;
17
+ if (width && width !== 17) {
18
+ root.style.setProperty('--scrollbar-width', `${width}px`);
19
+ }
20
+ }
21
+ state.height = (this.clientHeight / this.scrollHeight) * 100;
22
+ state.translate = (this.scrollTop / this.clientHeight) * 100;
23
+ }
24
+ }),
25
+ html: html `
26
+ <div
27
+ class='scrollbar ${fixed ? 'scrollbar--fixed' : ''} ${() => state.height >= 100 ? 'scrollbar--hidden' : ''}'
28
+ style='${() => `
29
+ ${style || ''}
30
+ --translate: translate3d(0, ${state.translate}%, 0);
31
+ --height: ${state.height}%;
32
+ `}'
33
+ ></div>
34
+ `
35
+ };
36
+ };
@@ -0,0 +1,8 @@
1
+ declare const _default: {
2
+ onfocus: (active?: boolean) => {
3
+ content: string;
4
+ type: string;
5
+ values: never[];
6
+ };
7
+ };
8
+ export default _default;
@@ -0,0 +1,17 @@
1
+ import { reactive } from '@esportsplus/reactivity';
2
+ import { html } from '@esportsplus/template';
3
+ const onfocus = (active = false) => {
4
+ let state = reactive({ active });
5
+ return html({
6
+ class: () => {
7
+ return state.active ? '--active' : '';
8
+ },
9
+ onfocusin: () => {
10
+ state.active = true;
11
+ },
12
+ onfocusout: () => {
13
+ state.active = false;
14
+ }
15
+ });
16
+ };
17
+ export default { onfocus };
@@ -0,0 +1 @@
1
+ export * from './components';
package/build/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './components';
package/package.json CHANGED
@@ -36,5 +36,5 @@
36
36
  "prepublishOnly": "npm run build"
37
37
  },
38
38
  "types": "./build/index.d.ts",
39
- "version": "0.0.8"
39
+ "version": "0.0.9"
40
40
  }