@farm-investimentos/front-mfe-components-vue3 0.0.1 → 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.
Files changed (25) hide show
  1. package/dist/front-mfe-components.common.js +28 -28
  2. package/dist/front-mfe-components.common.js.map +1 -1
  3. package/dist/front-mfe-components.umd.js +28 -28
  4. package/dist/front-mfe-components.umd.js.map +1 -1
  5. package/dist/front-mfe-components.umd.min.js +1 -1
  6. package/dist/front-mfe-components.umd.min.js.map +1 -1
  7. package/package.json +3 -3
  8. package/src/components/DialogPrompt/index.ts +77 -0
  9. package/src/components/DialogPrompt/utils/bootstrap.ts +20 -0
  10. package/src/components/DialogPrompt/utils/index.ts +5 -0
  11. package/src/components/DialogPrompt/utils/modalFooter.ts +41 -0
  12. package/src/components/DialogPrompt/utils/modalHeader.ts +21 -0
  13. package/src/examples/Colors.stories.js +4 -4
  14. package/src/examples/{VuetifyDialog.stories.js → Dialog.stories.js} +34 -3
  15. package/src/plugins/DialogPrompt/index.ts +71 -0
  16. package/src/plugins/DialogPrompt/utils/bootstrap.ts +28 -0
  17. package/src/plugins/DialogPrompt/utils/index.ts +5 -0
  18. package/src/plugins/DialogPrompt/utils/modalFooter.ts +41 -0
  19. package/src/plugins/DialogPrompt/utils/modalHeader.ts +13 -0
  20. package/src/scss/DialogPrompt.scss +5 -0
  21. package/src/scss/VuejsDialog.scss +0 -93
  22. /package/src/configurations/{_theme-colors-background.scss → _theme-colors-background.module.scss} +0 -0
  23. /package/src/configurations/{_theme-colors-stroke.scss → _theme-colors-stroke.module.scss} +0 -0
  24. /package/src/configurations/{_theme-colors-text.scss → _theme-colors-text.module.scss} +0 -0
  25. /package/src/configurations/{_theme-colors-variations.scss → _theme-colors-variations.module.scss} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm-investimentos/front-mfe-components-vue3",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "author": "farm investimentos",
5
5
  "private": false,
6
6
  "main": "./dist/front-mfe-components.common.js",
@@ -63,6 +63,7 @@
63
63
  "husky": "^8.0.0",
64
64
  "jest": "^29.0.0",
65
65
  "jest-environment-jsdom": "^29.0.0",
66
+ "promise-polyfill": "^8.3.0",
66
67
  "sass": "~1.32.0",
67
68
  "sass-loader": "^10.0.0",
68
69
  "storybook": "^7.0.6",
@@ -70,8 +71,7 @@
70
71
  "ts-jest": "^29.0.0",
71
72
  "typescript": "~4.1.5",
72
73
  "v-mask": "^2.3.0",
73
- "vue-loader": "^16.8.3",
74
- "vuejs-dialog": "^1.4.2"
74
+ "vue-loader": "^16.8.3"
75
75
  },
76
76
  "browserslist": [
77
77
  "> 1%",
@@ -0,0 +1,77 @@
1
+ import Icon from '../Icon';
2
+ import { bootstrap, modalFooter, modalHeader } from './utils';
3
+
4
+ export interface IDialogPromptOptions {
5
+ title: string;
6
+ body: string;
7
+ alert: boolean;
8
+ }
9
+
10
+ export interface IDialogPromptConfiguration {
11
+ html?: boolean;
12
+ okText?: string;
13
+ cancelText?: string;
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
+ dialog.destroy();
24
+ });
25
+
26
+ const content = document.createElement('div');
27
+ content.className = 'farm-modal--content';
28
+ content.innerHTML = `<div style="margin-top: 64px; margin-bottom: 84px; max-height: calc(100vh - 164px);">
29
+ <div style="font-size: 12px;
30
+ line-height: 20px;
31
+ word-break: break-word;">
32
+ ${options.body}
33
+ </div>
34
+ </div>`;
35
+ modal.appendChild(content);
36
+
37
+ return new Promise((resolve, reject) => {
38
+ modalFooter(
39
+ modal,
40
+ options,
41
+ configuration,
42
+ () => {
43
+ resolve(true);
44
+ dialog.destroy();
45
+ },
46
+ () => {
47
+ reject(true);
48
+ dialog.destroy();
49
+ }
50
+ );
51
+ // alert(2);
52
+ /*
53
+ okButton.onclick = () => {
54
+ alert(2);
55
+ resolve(true);
56
+ dialog.destroy();
57
+ };
58
+ */
59
+ });
60
+ },
61
+
62
+ alert: (options: IDialogPromptOptions, configuration: IDialogPromptConfiguration) => {
63
+ return dialog.confirm({ ...options, alert: true }, configuration);
64
+ },
65
+
66
+ destroy: () => {
67
+ if (dialog.container) document.body.removeChild(dialog.container);
68
+ },
69
+ };
70
+
71
+ export default {
72
+ install: app => {
73
+ // app.component('DialogPrompt', DialogPrompt);
74
+ app.config.globalProperties.$dialog = dialog;
75
+ app.provide('$dialog', dialog);
76
+ },
77
+ };
@@ -0,0 +1,20 @@
1
+ export default function (): { container: HTMLElement; backdrop: HTMLElement; modal: HTMLElement } {
2
+ const container = document.createElement('div');
3
+ container.className = 'farm-modal';
4
+
5
+ const backdrop = document.createElement('div');
6
+ backdrop.className = 'farm-modal--overlay';
7
+
8
+ const modal = document.createElement('div');
9
+ modal.className = 'farm-modal--container';
10
+
11
+ modal.style.width = '98%';
12
+ modal.style.maxWidth = '400px';
13
+
14
+ container.appendChild(modal);
15
+ container.appendChild(backdrop);
16
+
17
+ document.body.appendChild(container);
18
+
19
+ return { container, backdrop, modal };
20
+ }
@@ -0,0 +1,5 @@
1
+ import bootstrap from "./bootstrap";
2
+ import modalFooter from "./modalFooter";
3
+ import modalHeader from "./modalHeader";
4
+
5
+ export { bootstrap, modalFooter, modalHeader }
@@ -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,21 @@
1
+ import { IDialogPromptOptions } from '..';
2
+
3
+ export default function (modal: HTMLElement, options: IDialogPromptOptions, callback: Function) {
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
+ <button type="button" size="default" title="Fechar" class="farm-dialog-header__close farm-btn farm-btn--round farm-btn--icon farm-btn--primary farm-btn--variation-base">
12
+ <span class="farm-btn__content">
13
+ <i size="24px" role="button" class="farm-icon farm-icon--primary mdi mdi-window-close" style="font-size: 24px;"></i>
14
+ </span>
15
+ </button>
16
+ </header>`;
17
+ modal.appendChild(header);
18
+
19
+ const closeButton = header.querySelector('.farm-dialog-header__close');
20
+ closeButton.addEventListener('click', callback as EventListenerOrEventListenerObject);
21
+ }
@@ -1,9 +1,9 @@
1
1
  import baseThemeColors from '../configurations/_theme-colors-base.module.scss';
2
- import textThemeColors from '../configurations/_theme-colors-text.scss';
3
- import strokeThemeColors from '../configurations/_theme-colors-stroke.scss';
2
+ import textThemeColors from '../configurations/_theme-colors-text.module.scss';
3
+ import strokeThemeColors from '../configurations/_theme-colors-stroke.module.scss';
4
4
  import bwThemeColors from '../configurations/_theme-colors-bw.module.scss';
5
- import backgroundThemeColors from '../configurations/_theme-colors-background.scss';
6
- import variationThemeColors from '../configurations/_theme-colors-variations.scss';
5
+ import backgroundThemeColors from '../configurations/_theme-colors-background.module.scss';
6
+ import variationThemeColors from '../configurations/_theme-colors-variations.module.scss';
7
7
  import('./Colors.stories.scss');
8
8
 
9
9
  export default {
@@ -1,7 +1,7 @@
1
1
  // import { withDesign } from 'storybook-addon-designs';
2
2
 
3
3
  export default {
4
- title: 'Display/Dialog/Vuejs-dialog',
4
+ title: 'Display/Dialog/Prompt',
5
5
  // decorators: [withDesign],
6
6
  parameters: {
7
7
  viewMode: 'docs',
@@ -55,7 +55,6 @@ export const ErrorColor = () => ({
55
55
  {
56
56
  html: true,
57
57
  okText: 'OK',
58
- customClass: 'dg-parent-error',
59
58
  }
60
59
  )
61
60
  .then(() => {
@@ -84,6 +83,7 @@ export const NoFooter = () => ({
84
83
  html: true,
85
84
  okText: '',
86
85
  customClass: 'dg-parent-nofooter',
86
+ removeFooter: true,
87
87
  }
88
88
  )
89
89
  .then(() => {})
@@ -105,7 +105,7 @@ export const CustomHtml = () => ({
105
105
  methods: {
106
106
  openDialog() {
107
107
  this.$dialog
108
- .alert(
108
+ .confirm(
109
109
  {
110
110
  title: 'Dialog title',
111
111
  body: `This is a text with <strong>html markup</strong> and<br />break line!<br />
@@ -126,4 +126,35 @@ export const CustomHtml = () => ({
126
126
  Open
127
127
  </farm-btn>
128
128
  </div>`,
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>`,
129
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,5 @@
1
+ import bootstrap from "./bootstrap";
2
+ import modalFooter from "./modalFooter";
3
+ import modalHeader from "./modalHeader";
4
+
5
+ export { bootstrap, modalFooter, modalHeader }
@@ -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,93 +0,0 @@
1
- @import 'vuejs-dialog/dist/vuejs-dialog.min';
2
- @import '../components/Buttons/DefaultButton/DefaultButton.scss';
3
-
4
- .dg-main-content {
5
- font-family: 'Manrope', sans-serif !important;
6
- }
7
-
8
- .dg-content-body {
9
- border-bottom: 1px solid var(--farm-gray-lighten);
10
- margin: 0 -15px;
11
- padding: 0 16px;
12
- color: var(--farm-text-base);
13
- font-size: 12px;
14
- }
15
-
16
- .dg-title {
17
- margin: 0 -15px;
18
- border-bottom: 0;
19
- padding: 0 16px;
20
- color: var(--farm-bw-black-80);
21
- height: 32px;
22
- font-size: 12px;
23
- font-weight: 600;
24
- }
25
-
26
- .dg-content-body--has-title .dg-content,
27
- .dg-content {
28
- margin: 24px 0;
29
- font-size: 12px;
30
- line-height: 20px;
31
- word-break: break-word;
32
-
33
- ul {
34
- margin-left: 16px;
35
- }
36
- }
37
-
38
- .dg-content-footer {
39
- display: flex;
40
- flex-direction: row;
41
- justify-content: flex-end;
42
- }
43
-
44
- .dg-btn {
45
- @extend .farm-btn;
46
- border: 0;
47
- }
48
-
49
- .dg-btn--ok {
50
- @extend .farm-btn--primary;
51
- }
52
-
53
- .dg-btn--cancel {
54
- @extend .farm-btn--primary;
55
- @extend .farm-btn--plain;
56
- margin-right: 8px;
57
-
58
- &:hover{
59
- text-decoration: underline;
60
- text-underline-offset: 6px;
61
- opacity: 0.86;
62
- }
63
- }
64
-
65
- .dg-backdrop {
66
- background-color: rgba(0, 0, 0, 0.46);
67
- }
68
-
69
- .dg-parent-nofooter {
70
- .dg-content-footer {
71
- display: none;
72
- }
73
-
74
- .dg-content-body {
75
- border-bottom: none;
76
- padding-bottom: 0;
77
- }
78
-
79
- .dg-content-body--has-title .dg-content,
80
- .dg-content {
81
- margin-bottom: 8px;
82
- }
83
- }
84
-
85
- .dg-parent-error {
86
- .dg-btn--ok {
87
- @extend .farm-btn--error;
88
- }
89
-
90
- .dg-title {
91
- color: var(--farm-error-base);
92
- }
93
- }