@massimo-cassandro/minimo 1.4.13 → 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.
@@ -0,0 +1,38 @@
1
+ // -----------------------------------------------------------------------
2
+ // Generated file — do not edit manually.
3
+ // This file is produced by the design-token build pipeline.
4
+ // Source of truth: the token files in the project source directory.
5
+ // Re-generate with: node build-tokens.mjs --config <path/to/config>
6
+ // -----------------------------------------------------------------------
7
+ {
8
+ "modal-popup": {
9
+ "drop-shadow": {
10
+ "$type": "shadow",
11
+ "$value": [
12
+ {
13
+ "offsetX": "0",
14
+ "offsetY": "0",
15
+ "blur": "12px",
16
+ "spread": "2px",
17
+ "color": "rgba(0 0 0 / .25)"
18
+ }
19
+ ]
20
+ },
21
+ "backdrop-color": {
22
+ "$type": "color",
23
+ "$value": "rgb(0 0 0 / .6)"
24
+ },
25
+ "border": {
26
+ "radius": {
27
+ "$type": "dimension",
28
+ "$value": "{size.base}"
29
+ }
30
+ },
31
+ "btn-close": {
32
+ "size": {
33
+ "$type": "dimension",
34
+ "$value": "1.6rem"
35
+ }
36
+ }
37
+ }
38
+ }
@@ -0,0 +1,34 @@
1
+ export default {
2
+ 'modal-popup': {
3
+ 'drop-shadow': {
4
+ $type: 'shadow',
5
+ $value: [
6
+ {
7
+ offsetX: '0',
8
+ offsetY: '0',
9
+ blur: '12px',
10
+ spread: '2px',
11
+ color: 'rgba(0 0 0 / .25)'
12
+ }
13
+ ]
14
+ },
15
+ 'backdrop-color': {
16
+ $value: 'rgb(0 0 0 / .6)',
17
+ $type: 'color',
18
+ },
19
+ border: {
20
+ radius: {
21
+ $type: 'dimension',
22
+ $value: '{size.base}',
23
+ }
24
+ },
25
+
26
+ 'btn-close': {
27
+ size: {
28
+ $type: 'dimension',
29
+ $value: '1.6rem'
30
+ }
31
+
32
+ }
33
+ }
34
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@massimo-cassandro/minimo",
3
- "version": "1.4.13",
3
+ "version": "1.5.0",
4
4
  "description": "Light css framework & utilities",
5
5
  "type": "module",
6
6
  "homepage": "https://github.com/massimo-cassandro/minimo#readme",
@@ -1,152 +1,200 @@
1
- import { domBuilder, classnames } from '../index.js';
2
- import { spinner } from '@minimo/spinner.js';
3
- import * as styles from './modal-content.module.css?inline';
1
+ import { domBuilder } from '../../utilities/dom-builder/dom-builder.js';
2
+ import { classnames } from '../../utilities/classnames.js';
3
+ import { spinner } from '../spinner/spinner.js';
4
+ import * as styles from './modal-popup.module.css';
4
5
 
5
6
 
7
+ // https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement
6
8
 
9
+ let dialogEl, dialogContentEl;
7
10
 
8
- // https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement
11
+ function closeDialog() {
12
+ dialogEl.classList.remove(styles.on);
13
+
14
+ dialogEl.addEventListener('transitionend', () => {
15
+ dialogEl.close();
16
+ }, { once: true });
17
+ }
9
18
 
10
- export function modalContent({
19
+ /**
20
+ * modalPopup
21
+ * Mostra un popup con il contenuto indicato
22
+ * il contentuo può essere in forma di:
23
+ * - array domBuilder oppure plain text oppure HTML (parametro `content`)
24
+ * - contenuto caricato via Ajax (parametri `ajaxUrl` e `ajaxCallback`)
25
+ * - iframe (parametro `iframeUrl`)
26
+ *
27
+ * in presenza di più impostazioni in conflitto, viene scelta la prima opzione utile
28
+ * nell'ordine di priorità riportato nella lista precedente.
29
+ */
11
30
 
12
- /** iframe | content */
13
- mode = 'iframe',
31
+ export function modalPopup({
14
32
 
15
33
  /** dialog extra class */
16
- dialogClassName = null,
34
+ dialogExtraClassName = null,
35
+
36
+ /** extra classname added to dialogInner */
37
+ contentExtraClassName = null,
17
38
 
18
39
  /** iframe url */
19
40
  iframeUrl = null,
20
41
 
21
- /** content string (markup) o array */
42
+ /** content: plain text, html or domBuilder array */
22
43
  content = null,
23
44
 
24
- /** content extra classname */
25
- contentClassName = null,
45
+ /** url ajax e relatuva funzione di callback.
46
+ * Quest'ultima viene invocata con argomenti i dati restituiti dalla chiamata ajax
47
+ * e con l''elemento contenitore (`ajaxCallback(data, dialogContentEl)`)
48
+ */
49
+ ajaxUrl = null,
50
+ ajaxCallback = null,
51
+
52
+ /** eventuale callback da invocare alla chiusra del dialog
53
+ * Viene invocato con il le'elento dialog (`closeCallback(dialogEl)`)
54
+ * NB: `dialogEl` viene eliminato subito dopo
55
+ */
56
+ closeCallback = null,
57
+ addScrollbarPadding = false, // aggiunge un padding extra a destra per la barra di scorrimento
58
+
59
+ /** header content: plain text or HTML */
60
+ headerContent = null,
61
+
62
+ /** footer content: plain text or HTML */
63
+ footerContent = null,
64
+ }) {
26
65
 
27
- /** dimensione modal: full, large, medium o small */
28
- size = 'large',
29
66
 
30
- /** padding: std (var(--size-md) 0) o none */
31
- padding = 'std'
32
- }) {
33
67
 
34
- if(!['content', 'iframe'].includes(mode)) {
35
- throw `modalContent: parametro 'mode' non corretto (${mode})`;
36
- }
37
- if(!iframeUrl && mode === 'iframe') {
38
- throw 'modalContent: parametro `iframeUrl` mancante';
39
- }
40
- if(content == null && mode === 'content') {
41
- throw 'modalContent: parametro `content` mancante';
42
- }
43
- if(!['full', 'large', 'medium', 'small'].includes(size)) {
44
- throw `modalContent: parametro 'size' non corretto (${size})`;
45
- }
46
- if(!['std', 'none'].includes(padding)) {
47
- throw `modalContent: parametro 'padding' non corretto (${padding})`;
68
+ if(content == null && (ajaxUrl == null || ajaxCallback == null) && iframeUrl == null) {
69
+ throw '[modalContent] parametri `content`, `ajaxUrl`/ `ajaxCallback` e `iframeUrl` mancanti';
48
70
  }
49
71
 
50
- let dialog_element, dialog_inner, iframe_element = null, content_element = null;
51
- const iframeLoadEventHandler = () => {
52
- dialog_element.classList.add(styles.on);
53
- };
72
+ let mode;
73
+ if(content != null && Array.isArray(content)) {
74
+ mode = 'domBuilder';
54
75
 
55
- if(!dialog_element) {
76
+ } else if (content != null) {
77
+ mode = 'html';
56
78
 
57
- domBuilder([
58
- {
59
- tag: 'dialog',
60
- className: styles.dialog,
61
- attrs: {
62
- 'closedby': 'any'
63
- },
64
- children: [
65
- {
66
- tag: 'button',
67
- className: styles.closeButton, // TODO standardizzare close btn
68
- attrs: {
69
- 'aria-label': 'Chiudi'
70
- }
71
- },
72
- {
73
- className: styles.dialogInner,
74
- children: [
75
- {
76
- className: styles.modalSpinner,
77
- content: spinner({container: null, withOverlay: false })
78
- }
79
-
80
- ]
81
- }
82
- ]
83
- }
84
- ], document.body);
79
+ } else if (ajaxUrl != null && ajaxCallback != null) {
80
+ mode = 'ajax';
85
81
 
82
+ } else {
83
+ mode = 'iframe';
84
+ }
86
85
 
87
- dialog_element = document.querySelector(`.${styles.dialog}`);
88
- dialog_inner = dialog_element.querySelector(`.${styles.dialogInner}`);
86
+ domBuilder([
87
+ {
88
+ tag: 'dialog',
89
+ className: classnames(styles.dialog, dialogExtraClassName, addScrollbarPadding && styles.scrollBarPadding),
90
+ attrs: {
91
+ 'closedby': 'any'
92
+ },
93
+ callback: el => dialogEl = el,
94
+ children: [
95
+ {
96
+ tag: 'button',
97
+ className: classnames('btn-close', styles.closeButton),
98
+ attrs: {
99
+ type: 'button',
100
+ 'aria-label': 'Chiudi'
101
+ }
102
+ },
103
+ {
104
+ className: styles.contentWrapper,
105
+ children: [
106
+ {
107
+ classname: styles.header,
108
+ condition: headerContent != null,
109
+ content: headerContent
110
+ },
111
+ {
112
+ className: classnames(styles.content, contentExtraClassName),
113
+
114
+ content: mode === 'html'
115
+ ? content
116
+ : mode === 'ajax'
117
+ ? spinner()
118
+ : null,
119
+
120
+ children: [
121
+ ...(mode === 'domBuilder'? content : []),
122
+ {
123
+ condition: mode === 'iframe',
124
+ className: styles.iframe,
125
+ tag: 'iframe',
126
+ attrs: {
127
+ src: iframeUrl
128
+ }
129
+ }
130
+ ],
131
+ callback: el => {
132
+ dialogContentEl = el;
133
+
134
+ if(mode === 'ajax') {
135
+ try {
136
+
137
+ (async () => {
138
+ const response = await fetch(ajaxUrl),
139
+ data = await response.json();
140
+
141
+ ajaxCallback(data, dialogContentEl);
142
+ })();
143
+
144
+ } catch(err) {
145
+ /* eslint-disable no-console */
146
+ console.error(ajaxUrl);
147
+ console.error(err);
148
+ /* eslint-enable no-console */
149
+ }
150
+ }
151
+
152
+ },
153
+ },
154
+ {
155
+ classname: styles.footer,
156
+ condition: footerContent != null,
157
+ content: footerContent
158
+ },
159
+ ]
160
+ }
161
+ ]
162
+ }
163
+ ], document.body);
89
164
 
90
- dialog_element.querySelector(`.${styles.closeButton}`).addEventListener('click', () => {
91
- dialog_element.close();
92
- }, false);
93
165
 
94
- // listener chiusura
95
- dialog_element.addEventListener('close', () => {
166
+ // listener sul pulsante di chiusura
167
+ dialogEl.querySelector(`.${styles.closeButton}`).addEventListener('click', () => {
168
+ closeDialog();
169
+ }, false);
96
170
 
97
- iframe_element?.removeEventListener('load', iframeLoadEventHandler, false);
98
- iframe_element?.remove();
99
- content_element?.remove();
171
+ // // Esc e clic sul backdrop
172
+ // dialogEl.addEventListener('cancel', (e) => {
173
+ // e.preventDefault();
174
+ // closeDialog();
175
+ // }, false);
100
176
 
101
- document.body.classList.remove('overflow-hidden');
102
- dialog_element.classList.remove(styles.on);
103
- }, false);
104
177
 
105
- }
106
178
 
179
+ dialogEl.addEventListener('close', () => {
107
180
 
108
- // aggiunta classi extra
109
- dialog_element.className = classnames(
110
- styles.dialog,
111
- dialogClassName,
112
- styles[`size-${size}`],
113
- styles[`padding-${padding}`]
114
- );
181
+ document.body.classList.remove('overflow-hidden');
115
182
 
116
- domBuilder([
117
- {
118
- condition: mode === 'iframe',
119
- className: styles.iframeEl,
120
- tag: 'iframe',
121
- attrs: {
122
- src: ''
123
- }
124
- },
125
- {
126
- condition: mode === 'content',
127
- className: classnames(styles.contentEl, contentClassName),
128
- content: (content && !Array.isArray(content))? content : null,
129
- children: (content && Array.isArray(content))? content : null
183
+ if(closeCallback) {
184
+ closeCallback(dialogEl);
130
185
  }
131
- ], dialog_inner);
186
+ dialogEl.remove();
132
187
 
188
+ }, false);
133
189
 
134
- document.body.classList.add('overflow-hidden');
135
- dialog_element.showModal();
136
- dialog_element.focus();
137
190
 
191
+ document.body.classList.add('overflow-hidden');
192
+ dialogEl.showModal();
193
+ dialogEl.focus();
138
194
 
139
- if(mode === 'iframe') {
140
- iframe_element = dialog_element.querySelector(`.${styles.iframeEl}`);
141
- iframe_element.src = iframeUrl;
142
-
143
- // listener load per i frame
144
- iframe_element?.addEventListener('load', iframeLoadEventHandler, false);
195
+ dialogEl.classList.add(styles.on);
145
196
 
146
197
 
147
- } else if (mode === 'content') {
148
- content_element = dialog_element.querySelector(`.${styles.contentEl}`);
149
- dialog_element.classList.add(styles.on);
150
- }
198
+ return dialogEl;
151
199
 
152
200
  }
@@ -1,142 +1,88 @@
1
- /* TODO custom props nel file generale */
2
- /* TODO prevedere opzione con bordo del pulsante di chiusura (NB: si disallinea) */
3
- /* TODO cambiare icona chiusura con svg? */
4
- /* TODO aggiungere wrapper intorno a dialogInner (a filo con il dialog) per la scroll bar */
1
+ /*
2
+ NB:
3
+ `--_modal-popup-width` and `--_modal-popup-height` are used with a fallback value
4
+ but can be set with a desired value caso per caso
5
+
6
+ */
7
+ .dialog {
5
8
 
6
- .dialog { /* dialog */
7
- --modal-border-radius: var(--radius-md, 1.2rem);
8
9
  position: fixed;
9
- max-width: 80dvw;
10
+
11
+ display: block;
12
+
13
+ width: var(--_modal-popup-width, max-content);
14
+ min-width: 400px;
15
+ max-width: 98dvw;
16
+ height: var(--_modal-popup-height, max-content);
17
+ min-height: 300px;
10
18
  max-height: 90dvh;
11
19
  padding: 0;
12
20
  margin: auto;
13
21
  overflow: visible;
14
- background-color: var(--body-bg-color, #fff);
22
+ background-color: var(--body-background-color);
15
23
  border: none;
16
- border-radius: var(--modal-border-radius);
17
- box-shadow: 0 0 2rem .5rem rgb(0 0 0 / .5);
24
+ border-radius: var(--modal-popup-border-radius);
25
+ box-shadow: var(--modal-popup-drop-shadow);
18
26
  scale: 0;
19
27
  transition: scale .2s ease-out;
20
28
 
21
- /* stylelint-disable selector-class-pattern */
22
- &.size-full {
23
- width: 80dvw;
24
- height: 90dvh;
25
- }
26
- /* dimensioni std -> size == 'large' */
27
- &.size-large {
28
- width: 50rem; /* 800px */
29
- height: auto;
30
- }
31
- &.size-medium {
32
- width: 37.5rem; /* 600px */
33
- height: 37.5rem;
34
- }
35
- &.size-small {
36
- width: 32rem; /* ~500 x 400 */
37
- height: 25rem;
29
+ &::backdrop {
30
+ overscroll-behavior: contain;
31
+ background-color: var(--modal-popup-backdrop-color);
38
32
  }
39
- /* stylelint-enable selector-class-pattern */
40
33
 
41
34
  &.on {
42
35
  scale: 1;
43
36
  }
44
37
 
45
- &::backdrop {
46
- overscroll-behavior: contain;
47
- background-color: rgb(0 0 0 / .7);
48
- }
38
+ }
39
+
40
+ .closeButton {
49
41
 
42
+ position: absolute;
43
+ top: calc(-1 * var(--modal-popup-btn-close-size) / 3);
44
+ right: calc(-1 * var(--modal-popup-btn-close-size) / 3);
45
+ }
46
+
47
+ .contentWrapper {
48
+ display: flex;
49
+ flex-flow: column nowrap;
50
+ gap: 0;
51
+ align-items: flex-start;
52
+ justify-content: flex-start;
50
53
  }
51
54
 
52
- .dialogInner {
55
+
56
+ .content {
57
+ flex: 1;
53
58
  width: 100%;
54
59
  height: 100%;
55
- padding-inline-end: var(--size-md);
60
+ min-height: 0;
61
+ padding: var(--size-base) var(--size-sm) var(--size-sm);
56
62
  overflow-x: hidden;
57
63
  overflow-y: auto;
58
- /* scrollbar-gutter: stable; */
59
- border-radius: var(--modal-border-radius);
64
+ scrollbar-gutter: stable;
60
65
 
61
- /* stylelint-disable selector-class-pattern */
62
- .padding-std & {
63
- padding: var(--size-md) 0;
64
- }
65
- .padding-none & {
66
- padding: 0;
66
+ .scrollBarPadding & {
67
+ padding-inline-end: var(--size-md);
67
68
  }
68
- /* stylelint-enable selector-class-pattern */
69
- }
70
-
71
- .modalSpinner {
72
- position: relative;
73
- padding-block-start: var(--size-2xl);
74
69
 
75
- .dialog.on & {
76
- display: none;
77
- }
78
70
  }
79
71
 
80
- .iframeEl, .contentEl {
72
+ .iframe {
81
73
  width: 100%;
82
- overscroll-behavior: contain;
83
- }
84
-
85
- .iframeEl {
86
74
  height: 100%;
87
75
  padding: 0;
88
76
  margin: 0;
77
+ overscroll-behavior: contain;
89
78
  border: none;
90
79
  }
91
80
 
92
- .contentEl {
93
- min-height: 100%;
94
- }
95
81
 
96
- .closeButton {
97
- --btn-color: var(--secondary-fg, #000);
98
- --btn-bg-color: var(--secondary, #fff);
99
- --btn-hover-color: var(--secondary, #fff);
100
- --btn-hover-bg-color: var(--secondary-fg, #000);
101
- --icon-size: 2.5rem;
102
- --btn-padding: var(--size-xs, .5rem);
103
- --icon-bars-thickness: 3px;
104
-
105
- position: absolute;
106
- top: calc(-1 * var(--icon-size) / 3);
107
- right: calc(-1 * var(--icon-size) / 3);
108
- display: block;
109
- width: var(--icon-size);
110
- height: var(--icon-size);
111
- padding: var(--btn-padding);
112
- color: var(--btn-color);
113
- cursor: pointer;
114
- background-color: var(--btn-bg-color);
115
- /* border: var(--icon-bars-thickness) solid currentColor; */
116
- border: none;
117
- border-radius: 50%;
82
+ .header {
118
83
 
84
+ }
119
85
 
120
- &:hover {
121
- --btn-color: var(--btn-hover-color);
122
- --btn-bg-color: var(--btn-hover-bg-color);
123
- }
86
+ .footer {
124
87
 
125
- &::before, &::after {
126
- position: absolute;
127
- top: 50%;
128
- left: var(--btn-padding);
129
- display: block;
130
- width: calc(var(--icon-size) - (var(--btn-padding) * 2));
131
- height: var(--icon-bars-thickness);
132
- content: '';
133
- background: currentColor;
134
- }
135
- &::before {
136
- transform: translateY(-50%) rotate(45deg);
137
- }
138
- &::after {
139
- transform: translateY(-50%) rotate(-45deg);
140
- }
141
88
  }
142
-
@@ -0,0 +1,8 @@
1
+ import * as styles from './spinner.module.css';
2
+
3
+ // NB la classe spinner è legata al tipo di spinner che si decide di usare, il cui file va incluso
4
+ // TODO sistema per coinfigurare il tipo di spinner da utilizzare, per permettere l'uso di più tipi di spinner nello stesso progetto
5
+
6
+ export function spinner() {
7
+ return `<div class="${styles.spinnerWrapper}"><div class="spinner">Loading...</div></div>`;
8
+ }
@@ -0,0 +1,5 @@
1
+ .spinnerWrapper {
2
+ display: grid;
3
+ place-content: center;
4
+ padding: 2rem;
5
+ }
@@ -190,6 +190,10 @@
190
190
  --link-focus-outline-color: var(--link-color);
191
191
  --link-focus-outline-width: .125rem;
192
192
  --link-visited-color: #ae0da3;
193
+ --modal-popup-backdrop-color: rgb(0 0 0 / .6);
194
+ --modal-popup-border-radius: var(--size-base);
195
+ --modal-popup-btn-close-size: 1.6rem;
196
+ --modal-popup-drop-shadow: 0 0 .75rem .125rem rgb(0 0 0 / .25);
193
197
  --neutral-100: #666;
194
198
  --neutral-100-fg: #fff;
195
199
  --overlay-color: rgb(0 0 0 / .6);
package/src/minimo.css CHANGED
@@ -41,3 +41,6 @@
41
41
  @import '@minimo/css/position.css';
42
42
  @import '@minimo/css/visibility.css';
43
43
 
44
+
45
+ /* spinner: include the css of the choosen spinner only */
46
+ @import '@minimo/components/spinner/spinner-circle-basic.css';
@@ -120,7 +120,7 @@ export function parseCols(col_obj){
120
120
 
121
121
  } else if(col_obj._renderMode === 'numeric') {
122
122
  return {
123
-
123
+ // TODO implementare merge con classi presenti nei parametri definiti dall'utente
124
124
  cellClass: 'text-end text-numeric',
125
125
  headerClass: 'text-end text-numeric', // NB: usata anche per il footer
126
126
  };