@farm-investimentos/front-mfe-components-vue3 0.0.2 → 0.0.3
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/package.json +1 -1
- package/src/examples/Dialog.stories.js +34 -2
- package/src/plugins/DialogPrompt/index.ts +71 -0
- package/src/plugins/DialogPrompt/utils/bootstrap.ts +28 -0
- package/src/plugins/DialogPrompt/utils/index.ts +5 -0
- package/src/plugins/DialogPrompt/utils/modalFooter.ts +41 -0
- package/src/plugins/DialogPrompt/utils/modalHeader.ts +13 -0
- package/src/scss/DialogPrompt.scss +5 -0
- package/src/scss/VuejsDialog.scss +0 -98
package/package.json
CHANGED
|
@@ -83,6 +83,7 @@ export const NoFooter = () => ({
|
|
|
83
83
|
html: true,
|
|
84
84
|
okText: '',
|
|
85
85
|
customClass: 'dg-parent-nofooter',
|
|
86
|
+
removeFooter: true,
|
|
86
87
|
}
|
|
87
88
|
)
|
|
88
89
|
.then(() => {})
|
|
@@ -104,7 +105,7 @@ export const CustomHtml = () => ({
|
|
|
104
105
|
methods: {
|
|
105
106
|
openDialog() {
|
|
106
107
|
this.$dialog
|
|
107
|
-
.
|
|
108
|
+
.confirm(
|
|
108
109
|
{
|
|
109
110
|
title: 'Dialog title',
|
|
110
111
|
body: `This is a text with <strong>html markup</strong> and<br />break line!<br />
|
|
@@ -125,4 +126,35 @@ export const CustomHtml = () => ({
|
|
|
125
126
|
Open
|
|
126
127
|
</farm-btn>
|
|
127
128
|
</div>`,
|
|
128
|
-
|
|
129
|
+
<<<<<<< HEAD
|
|
130
|
+
});
|
|
131
|
+
=======
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
export const DisabledHtml = () => ({
|
|
135
|
+
methods: {
|
|
136
|
+
openDialog() {
|
|
137
|
+
this.$dialog
|
|
138
|
+
.confirm(
|
|
139
|
+
{
|
|
140
|
+
title: 'Dialog title',
|
|
141
|
+
body: `This is a text with <strong>html markup</strong> and<br />break line!<br />
|
|
142
|
+
Also with an <i class="mdi mdi-book"></i>book icon<br />
|
|
143
|
+
and some <span style="color: var(--farm-warning-base)">color</span>`,
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
html: false,
|
|
147
|
+
okText: 'Button',
|
|
148
|
+
}
|
|
149
|
+
)
|
|
150
|
+
.then(() => {})
|
|
151
|
+
.catch(() => {});
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
template: `<div style="display: flex; flex-direction: column; max-width: 160px; width: 100%;">
|
|
155
|
+
<farm-btn @click="openDialog">
|
|
156
|
+
Open
|
|
157
|
+
</farm-btn>
|
|
158
|
+
</div>`,
|
|
159
|
+
});
|
|
160
|
+
>>>>>>> vuejsdialog
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { bootstrap, modalFooter, modalHeader } from './utils';
|
|
2
|
+
|
|
3
|
+
export interface IDialogPromptOptions {
|
|
4
|
+
title: string;
|
|
5
|
+
body: string;
|
|
6
|
+
alert: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface IDialogPromptConfiguration {
|
|
10
|
+
html?: boolean;
|
|
11
|
+
okText?: string;
|
|
12
|
+
cancelText?: string;
|
|
13
|
+
removeFooter?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const dialog = {
|
|
17
|
+
container: null,
|
|
18
|
+
confirm: (options: IDialogPromptOptions, configuration: IDialogPromptConfiguration) => {
|
|
19
|
+
const { container, modal } = bootstrap();
|
|
20
|
+
dialog.container = container;
|
|
21
|
+
|
|
22
|
+
modalHeader(modal, options);
|
|
23
|
+
|
|
24
|
+
const content = document.createElement('div');
|
|
25
|
+
content.className = 'farm-modal--content';
|
|
26
|
+
content.innerHTML = `<div style="margin-top: 64px; margin-bottom: ${
|
|
27
|
+
configuration.removeFooter ? 24 : 84
|
|
28
|
+
}px; max-height: calc(100vh - 164px);">
|
|
29
|
+
<div style="font-size: 12px;
|
|
30
|
+
line-height: 20px;
|
|
31
|
+
word-break: break-word;">
|
|
32
|
+
${configuration.html ? options.body : options.body.replace(/\n|<.*?>/g, '')}
|
|
33
|
+
</div>
|
|
34
|
+
</div>`;
|
|
35
|
+
modal.appendChild(content);
|
|
36
|
+
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
if (configuration.removeFooter) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
modalFooter(
|
|
42
|
+
modal,
|
|
43
|
+
options,
|
|
44
|
+
configuration,
|
|
45
|
+
() => {
|
|
46
|
+
resolve(true);
|
|
47
|
+
dialog.destroy();
|
|
48
|
+
},
|
|
49
|
+
() => {
|
|
50
|
+
reject(true);
|
|
51
|
+
dialog.destroy();
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
alert: (options: IDialogPromptOptions, configuration: IDialogPromptConfiguration) => {
|
|
58
|
+
return dialog.confirm({ ...options, alert: true }, configuration);
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
destroy: () => {
|
|
62
|
+
if (dialog.container) document.body.removeChild(dialog.container);
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export default {
|
|
67
|
+
install: app => {
|
|
68
|
+
app.config.globalProperties.$dialog = dialog;
|
|
69
|
+
app.provide('$dialog', dialog);
|
|
70
|
+
},
|
|
71
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const DIALOG_ID = 'farm-dialog-prompt-identifier';
|
|
2
|
+
|
|
3
|
+
export default function (): { container: HTMLElement; backdrop: HTMLElement; modal: HTMLElement } {
|
|
4
|
+
let container;
|
|
5
|
+
if (document.getElementById(DIALOG_ID)) {
|
|
6
|
+
container = document.getElementById(DIALOG_ID);
|
|
7
|
+
} else {
|
|
8
|
+
container = document.createElement('div');
|
|
9
|
+
container.className = 'farm-modal';
|
|
10
|
+
container.id = DIALOG_ID;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const backdrop = document.createElement('div');
|
|
14
|
+
backdrop.className = 'farm-modal--overlay';
|
|
15
|
+
|
|
16
|
+
const modal = document.createElement('div');
|
|
17
|
+
modal.className = 'farm-modal--container';
|
|
18
|
+
|
|
19
|
+
modal.style.width = '98%';
|
|
20
|
+
modal.style.maxWidth = '400px';
|
|
21
|
+
|
|
22
|
+
container.appendChild(modal);
|
|
23
|
+
container.appendChild(backdrop);
|
|
24
|
+
|
|
25
|
+
document.body.appendChild(container);
|
|
26
|
+
|
|
27
|
+
return { container, backdrop, modal };
|
|
28
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { IDialogPromptConfiguration, IDialogPromptOptions } from '..';
|
|
2
|
+
|
|
3
|
+
export default function (
|
|
4
|
+
modal: HTMLElement,
|
|
5
|
+
options: IDialogPromptOptions,
|
|
6
|
+
configuration: IDialogPromptConfiguration,
|
|
7
|
+
callbackConfirm: Function,
|
|
8
|
+
callbackCancel: Function
|
|
9
|
+
) {
|
|
10
|
+
const footer = document.createElement('footer');
|
|
11
|
+
footer.className = 'farm-modal--footer';
|
|
12
|
+
footer.innerHTML = `<div class="farm-dialog__footer">
|
|
13
|
+
${
|
|
14
|
+
configuration.cancelText
|
|
15
|
+
? `<button type="button" size="default" class="farm-btn farm-btn--primary farm-btn--variation-base farm-btn--plain farm-btn__cancel">
|
|
16
|
+
<span class="farm-btn__content">
|
|
17
|
+
${configuration.cancelText || 'Confirmar'}
|
|
18
|
+
</span>
|
|
19
|
+
</button> `
|
|
20
|
+
: ''
|
|
21
|
+
}
|
|
22
|
+
<button type="button" size="default" title="Confirmar" class="farm-btn farm-btn--${
|
|
23
|
+
options.alert ? 'error' : 'primary'
|
|
24
|
+
} farm-btn--variation-base farm-btn__confirm">
|
|
25
|
+
<span class="farm-btn__content">
|
|
26
|
+
${configuration.okText || 'Confirmar'}
|
|
27
|
+
</span>
|
|
28
|
+
</button>
|
|
29
|
+
</div>`;
|
|
30
|
+
modal.appendChild(footer);
|
|
31
|
+
|
|
32
|
+
const okButton = footer.querySelector('.farm-btn__confirm');
|
|
33
|
+
okButton.addEventListener('click', callbackConfirm as EventListenerOrEventListenerObject);
|
|
34
|
+
|
|
35
|
+
const cancelButton = footer.querySelector('.farm-btn__cancel');
|
|
36
|
+
if (cancelButton)
|
|
37
|
+
cancelButton.addEventListener(
|
|
38
|
+
'click',
|
|
39
|
+
callbackCancel as EventListenerOrEventListenerObject
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IDialogPromptOptions } from '..';
|
|
2
|
+
|
|
3
|
+
export default function (modal: HTMLElement, options: IDialogPromptOptions) {
|
|
4
|
+
const style = options.alert ? 'color: var(--farm-error-base)!important' : '';
|
|
5
|
+
const header = document.createElement('div');
|
|
6
|
+
header.className = 'farm-modal--header';
|
|
7
|
+
header.innerHTML = `<header>
|
|
8
|
+
<p class="farm-typography farm-typography--sm farm-typography--weight-600 farm-caption farm-caption--semiBold" style="${style}">
|
|
9
|
+
${options.title}
|
|
10
|
+
</p>
|
|
11
|
+
</header>`;
|
|
12
|
+
modal.appendChild(header);
|
|
13
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
@import '../components/Modal/Modal.scss';
|
|
2
|
+
@import '../components/DialogHeader/DialogHeader.scss';
|
|
3
|
+
@import '../components/DialogFooter/DialogFooter.scss';
|
|
4
|
+
@import '../components/Typography/Typography.scss';
|
|
5
|
+
@import '../components/Buttons/DefaultButton/DefaultButton.scss';
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
@import '../components/Modal/Modal.scss';
|
|
2
|
-
@import '../components/DialogHeader/DialogHeader.scss';
|
|
3
|
-
@import '../components/DialogFooter/DialogFooter.scss';
|
|
4
|
-
@import '../components/Typography/Typography.scss';
|
|
5
|
-
@import '../components/Buttons/DefaultButton/DefaultButton.scss';
|
|
6
|
-
|
|
7
|
-
/*
|
|
8
|
-
.dg-main-content {
|
|
9
|
-
font-family: 'Manrope', sans-serif !important;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
.dg-content-body {
|
|
13
|
-
border-bottom: 1px solid var(--farm-gray-lighten);
|
|
14
|
-
margin: 0 -15px;
|
|
15
|
-
padding: 0 16px;
|
|
16
|
-
color: var(--farm-text-base);
|
|
17
|
-
font-size: 12px;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
.dg-title {
|
|
21
|
-
margin: 0 -15px;
|
|
22
|
-
border-bottom: 0;
|
|
23
|
-
padding: 0 16px;
|
|
24
|
-
color: var(--farm-bw-black-80);
|
|
25
|
-
height: 32px;
|
|
26
|
-
font-size: 12px;
|
|
27
|
-
font-weight: 600;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
.dg-content-body--has-title .dg-content,
|
|
31
|
-
.dg-content {
|
|
32
|
-
margin: 24px 0;
|
|
33
|
-
font-size: 12px;
|
|
34
|
-
line-height: 20px;
|
|
35
|
-
word-break: break-word;
|
|
36
|
-
|
|
37
|
-
ul {
|
|
38
|
-
margin-left: 16px;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
.dg-content-footer {
|
|
43
|
-
display: flex;
|
|
44
|
-
flex-direction: row;
|
|
45
|
-
justify-content: flex-end;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
.dg-btn {
|
|
49
|
-
@extend .farm-btn;
|
|
50
|
-
border: 0;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
.dg-btn--ok {
|
|
54
|
-
@extend .farm-btn--primary;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
.dg-btn--cancel {
|
|
58
|
-
@extend .farm-btn--primary;
|
|
59
|
-
@extend .farm-btn--plain;
|
|
60
|
-
margin-right: 8px;
|
|
61
|
-
|
|
62
|
-
&:hover{
|
|
63
|
-
text-decoration: underline;
|
|
64
|
-
text-underline-offset: 6px;
|
|
65
|
-
opacity: 0.86;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
.dg-backdrop {
|
|
70
|
-
background-color: rgba(0, 0, 0, 0.46);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
.dg-parent-nofooter {
|
|
74
|
-
.dg-content-footer {
|
|
75
|
-
display: none;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
.dg-content-body {
|
|
79
|
-
border-bottom: none;
|
|
80
|
-
padding-bottom: 0;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
.dg-content-body--has-title .dg-content,
|
|
84
|
-
.dg-content {
|
|
85
|
-
margin-bottom: 8px;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
.dg-parent-error {
|
|
90
|
-
.dg-btn--ok {
|
|
91
|
-
@extend .farm-btn--error;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
.dg-title {
|
|
95
|
-
color: var(--farm-error-base);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
*/
|