@avakhula/ui 0.0.196 → 0.0.197

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avakhula/ui",
3
- "version": "0.0.196",
3
+ "version": "0.0.197",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.umd.cjs",
6
6
  "source": "src/index.js",
package/src/App.vue CHANGED
@@ -1,59 +1,30 @@
1
1
  <template>
2
- <div class="hello">
3
- <div v-for="item in items" :key="item.id">
4
- {{ item.name }}
2
+ <div style="padding-left: 200px;padding-top: 200px;">
5
3
 
6
- <ib-icon-button @click="deleteItem(item.id)" v-tooltip="'DELETE'">
7
- <ib-icon name="close-outline" />
8
- </ib-icon-button>
9
- </div>
4
+ <ib-sorting
5
+ title="'test'"
6
+ class="table-sorting"
7
+ view="table-sorting"
8
+ table-name="user-list-table"
9
+ toggle-tip-title="some title"
10
+ >
11
+ <template #toggleTipBody>
12
+ hello
13
+ </template>
14
+
15
+ <template #toggleTipButtons>
16
+ some buttons
17
+ </template>
18
+ </ib-sorting>
10
19
  </div>
11
20
  </template>
12
21
 
13
22
  <script>
14
- import { TextOverflowTooltipDirective as TextOverflowTooltip } from "./directives/tooltip/textOverflowTooltip";
15
- import { TooltipDirective as Tooltip } from "./directives/tooltip/tooltip";
23
+ import IbSorting from "./components/Sorting/Sorting.vue";
16
24
 
17
- import IbIconButton from "./components/IconButton/IconButton.vue";
18
- import IbIcon from "./components/Icon.vue"
19
25
  export default {
20
- data() {
21
- return {
22
- items: [
23
- { id: 1, name: "Item 1" },
24
- { id: 2, name: "Item 2" },
25
- { id: 3, name: "Item 3" },
26
- { id: 4, name: "Item 4" },
27
- { id: 5, name: "Item 5" },
28
- ],
29
- };
30
- },
31
- methods: {
32
- deleteItem(id) {
33
- const idx = this.items.findIndex((item) => item.id === id);
34
- this.items.splice(idx, 1);
35
- },
36
- },
37
- directives: {
38
- TextOverflowTooltip,
39
- Tooltip
40
- },
41
26
  components: {
42
- IbIconButton,
43
- IbIcon
27
+ IbSorting,
44
28
  }
45
- };
46
- </script>
47
-
48
- <style lang="scss">
49
- @import "./assets/scss/mixins.scss";
50
-
51
- .hello {
52
- padding: 200px;
53
- }
54
-
55
- .test {
56
- max-width: 20px;
57
- @include lineClamp(1);
58
29
  }
59
- </style>
30
+ </script>
@@ -16,7 +16,7 @@ export default {
16
16
  },
17
17
  tooltipPosition: {
18
18
  control: { type: "select" },
19
- options: Object.values(popoverPosition),
19
+ options: Object.keys(popoverPosition),
20
20
  },
21
21
  },
22
22
  };
@@ -8,32 +8,46 @@
8
8
  }"
9
9
  v-if="view === sortingTypesView.TABLE_VIEW"
10
10
  >
11
- <button class="sorting-label" type="button">
12
- {{ title }}
13
- <ib-tooltip
14
- v-if="tooltipText"
15
- :text="tooltipText"
16
- :position="tooltipPosition"
11
+ <div>
12
+ <button
13
+ v-tooltip:[tooltipPosition]="tooltipText"
14
+ class="sorting-label"
15
+ type="button"
16
+ @click="isOpenToggleTip = true"
17
17
  >
18
- </ib-tooltip>
19
- </button>
20
- <ib-icon-button kind="white" size="s" @click="clickHandler">
21
- <ion-icon :name="iconType"></ion-icon>
22
- <ib-tooltip
23
- v-if="tooltipIconSorting"
24
- :text="tooltipIconSorting"
25
- :position="tooltipPosition"
18
+ {{ title }}
19
+ </button>
20
+
21
+ <ib-toggle-tip
22
+ v-if="hasToggleTip"
23
+ :is-open="isOpenToggleTip"
24
+ :title="toggleTipTitle"
25
+ @close="isOpenToggleTip = false"
26
26
  >
27
- </ib-tooltip>
27
+ <slot name="toggleTipBody"></slot>
28
+ <template #buttons>
29
+ <slot name="toggleTipButtons"></slot>
30
+ </template>
31
+ </ib-toggle-tip>
32
+ </div>
33
+
34
+ <ib-icon-button
35
+ v-tooltip="tooltipIconText"
36
+ kind="white"
37
+ size="s"
38
+ @click="clickHandler"
39
+ >
40
+ <ion-icon :name="iconType"></ion-icon>
28
41
  </ib-icon-button>
29
42
  </div>
30
43
 
31
44
  <button
32
45
  v-else
46
+ v-tooltip:[tooltipPosition]="tooltipText"
33
47
  class="sorting-button"
34
48
  type="button"
35
- :aria-label="sort"
36
49
  @click="clickHandler"
50
+ :aria-label="sort"
37
51
  :class="{
38
52
  active: currentTypeSort,
39
53
  disabled: disable,
@@ -41,12 +55,6 @@
41
55
  >
42
56
  {{ title }}
43
57
  <ib-icon v-if="iconType" :name="iconType"></ib-icon>
44
- <ib-tooltip
45
- v-if="tooltipText"
46
- :text="tooltipText"
47
- :position="tooltipPosition"
48
- >
49
- </ib-tooltip>
50
58
  </button>
51
59
  </div>
52
60
  </template>
@@ -54,9 +62,9 @@
54
62
  <script>
55
63
  import IbIcon from "../Icon.vue";
56
64
  import IbIconButton from "../IconButton/IconButton.vue";
57
- import IbTooltip from "../Tooltip/Tooltip.vue";
65
+ import IbToggleTip from "../ToggleTip/ToggleTip.vue";
58
66
  import { typesSorting, typesSortingView } from "./constants.js";
59
-
67
+ import { TooltipDirective as Tooltip } from "../../directives/tooltip/tooltip";
60
68
  export default {
61
69
  name: "IbSorting",
62
70
  props: {
@@ -69,6 +77,9 @@ export default {
69
77
  tooltipIconSorting: {
70
78
  type: String,
71
79
  },
80
+ toggleTipTitle: {
81
+ type: String,
82
+ },
72
83
  title: {
73
84
  type: String,
74
85
  default: "",
@@ -99,6 +110,7 @@ export default {
99
110
  },
100
111
  data() {
101
112
  return {
113
+ isOpenToggleTip: false,
102
114
  sortingTypes: typesSorting,
103
115
  sortingTypesView: typesSortingView,
104
116
  currentTypeSort: this.sort,
@@ -132,11 +144,29 @@ export default {
132
144
  }
133
145
  return null;
134
146
  },
147
+ tooltipIconText() {
148
+ if (this.currentTypeSort === this.sortingTypes.TYPE_ASC) {
149
+ return lang("sort_descending", this.LANG_COMPONENTS?.COMPONENT_SELECT);
150
+ } else if (this.currentTypeSort === this.sortingTypes.TYPE_DESC) {
151
+ return lang("reset_sorting", this.LANG_COMPONENTS?.COMPONENT_SELECT);
152
+ } else if (this.view !== this.sortingTypesView.GRID_VIEW) {
153
+ return lang("sort_ascending", this.LANG_COMPONENTS?.COMPONENT_SELECT);
154
+ }
155
+ return "";
156
+ },
157
+ hasToggleTip() {
158
+ return (
159
+ this.toggleTipTitle &&
160
+ this.$slots.toggleTipBody &&
161
+ this.$slots.toggleTipButtons
162
+ );
163
+ }
135
164
  },
165
+ directives: { Tooltip },
136
166
  components: {
137
167
  IbIcon,
138
168
  IbIconButton,
139
- IbTooltip,
169
+ IbToggleTip,
140
170
  },
141
171
  };
142
172
  </script>
@@ -54,16 +54,16 @@ export default {
54
54
  max-width: 240px;
55
55
  box-shadow: $ib-shadow-1;
56
56
 
57
- &::after {
58
- content: "";
59
- width: 100%;
60
- height: calc(100% + 5px);
61
- position: absolute;
62
- left: 0;
63
- right: 0;
64
- bottom: -5px;
65
- z-index: -1;
66
- }
57
+ // &::after {
58
+ // content: "";
59
+ // width: 100%;
60
+ // height: calc(100% + 5px);
61
+ // position: absolute;
62
+ // left: 0;
63
+ // right: 0;
64
+ // bottom: -5px;
65
+ // z-index: -1;
66
+ // }
67
67
 
68
68
  &.ib-tooltip-large {
69
69
  box-shadow: $ib-shadow-2;
@@ -76,5 +76,99 @@ export default {
76
76
  p {
77
77
  @include Ib-H4-regular;
78
78
  }
79
+
80
+ // Its dublicate
81
+ &::before {
82
+ content: "";
83
+ width: 0;
84
+ height: 0;
85
+ border-style: solid;
86
+ border-width: 4px 4px 0 4px;
87
+ border-color: #fff transparent transparent transparent;
88
+ position: absolute;
89
+ }
90
+
91
+ &.top-left {
92
+ &::before {
93
+ bottom: -4px;
94
+ right: 10px;
95
+ }
96
+ }
97
+ &.top-center {
98
+ &::before {
99
+ bottom: -4px;
100
+ right: 50%;
101
+ transform: translateX(50%);
102
+ }
103
+ }
104
+ &.top-right {
105
+ &::before {
106
+ bottom: -4px;
107
+ left: 10px;
108
+ }
109
+ }
110
+ &.right-top {
111
+ &::before {
112
+ left: -6px;
113
+ bottom: 10px;
114
+ transform: rotate(90deg);
115
+ }
116
+ }
117
+ &.right-center {
118
+ &::before {
119
+ left: -8px;
120
+ top: 50%;
121
+ transform: rotate(90deg) translateY(-50%);
122
+ }
123
+ }
124
+ &.right-bottom {
125
+ &::before {
126
+ top: 10px;
127
+ left: -6px;
128
+ transform: rotate(90deg);
129
+ }
130
+ }
131
+ &.bottom-left {
132
+ &::before {
133
+ top: -4px;
134
+ right: 10px;
135
+ transform: rotate(180deg);
136
+ }
137
+ }
138
+ &.bottom-center {
139
+ &::before {
140
+ top: -4px;
141
+ right: 50%;
142
+ transform: rotate(180deg) translateX(-50%);
143
+ }
144
+ }
145
+ &.bottom-right {
146
+ &::before {
147
+ top: -4px;
148
+ left: 10px;
149
+ transform: rotate(180deg);
150
+ }
151
+ }
152
+ &.left-top {
153
+ &::before {
154
+ right: -6px;
155
+ bottom: 10px;
156
+ transform: rotate(-90deg);
157
+ }
158
+ }
159
+ &.left-center {
160
+ &::before {
161
+ right: -8px;
162
+ top: 50%;
163
+ transform: rotate(-90deg) translateY(-50%);
164
+ }
165
+ }
166
+ &.left-bottom {
167
+ &::before {
168
+ top: 10px;
169
+ right: -6px;
170
+ transform: rotate(-90deg);
171
+ }
172
+ }
79
173
  }
80
174
  </style>
@@ -1,4 +1,5 @@
1
1
  import { createApp } from "vue";
2
+ import { popoverPosition } from "../../components/Popover/constants";
2
3
  import IbTooltip from "../../components/Tooltip/Tooltip.vue";
3
4
  import generateUID from "../../helpers/generateUID";
4
5
 
@@ -25,8 +26,8 @@ export default class Tooltip {
25
26
  this.uuid = "tooltip_" + generateUID();
26
27
  }
27
28
 
28
- createTooltip(el, text) {
29
- if (!text.length) {
29
+ createTooltip(el, text, position) {
30
+ if (!text?.length) {
30
31
  return;
31
32
  }
32
33
 
@@ -46,6 +47,7 @@ export default class Tooltip {
46
47
  text: text,
47
48
  alwaysVisible: true,
48
49
  for: this.uuid,
50
+ class: this.getClassList(position),
49
51
  });
50
52
 
51
53
  this.tooltipInstance.mount(this.tooltipContainer);
@@ -53,19 +55,8 @@ export default class Tooltip {
53
55
  setTimeout(() => {
54
56
  if (this.tooltipContainer?.firstChild) {
55
57
  el.setAttribute("describedby", this.uuid);
56
- const { top, left, width } = el.getBoundingClientRect();
57
- const { width: tooltipWidth, height: tooltipHeight } =
58
- this.tooltipContainer.firstChild.getBoundingClientRect();
59
- const scrollTop = document.documentElement.scrollTop;
60
-
61
- const tooltipStyles = `
62
- left: ${left + width / 2 - tooltipWidth / 2}px!important;
63
- top: ${top - tooltipHeight + scrollTop - 5}px!important;
64
- bottom: auto!important;
65
- right: auto!important;
66
- transform: none!important;
67
- `;
68
58
 
59
+ const tooltipStyles = this.getPositionStyle(el, position);
69
60
  this.tooltipContainer.firstChild.setAttribute("style", tooltipStyles);
70
61
  }
71
62
  }, 100);
@@ -79,4 +70,112 @@ export default class Tooltip {
79
70
  this.tooltipContainer?.remove();
80
71
  this.tooltipContainer = null;
81
72
  }
73
+
74
+ getPositionStyle(el, position) {
75
+ const { top, bottom, left, right, width, height } = el.getBoundingClientRect();
76
+ const { width: tooltipWidth, height: tooltipHeight } =
77
+ this.tooltipContainer.firstChild.getBoundingClientRect();
78
+
79
+ const scrollTop = document.documentElement.scrollTop;
80
+
81
+ let styles = `
82
+ bottom: auto!important;
83
+ right: auto!important;
84
+ transform: none!important;
85
+ `;
86
+
87
+ switch (position) {
88
+ case "bottomCenter":
89
+ styles =
90
+ styles +
91
+ `left: ${left + width / 2 - tooltipWidth / 2}px!important;
92
+ top: ${bottom + scrollTop + 5}px!important;`;
93
+ break;
94
+ case "bottomLeft":
95
+ styles =
96
+ styles +
97
+ `left: ${right - tooltipWidth - width / 2 + 5}px!important;
98
+ top: ${bottom + scrollTop + 5}px!important;`;
99
+ break;
100
+ case "bottomRight":
101
+ styles =
102
+ styles +
103
+ `left: ${left + width / 2 - 5}px!important;
104
+ top: ${bottom + scrollTop + 5}px!important;`;
105
+ break;
106
+ case "topLeft":
107
+ styles =
108
+ styles +
109
+ `left: ${right - tooltipWidth - width / 2 + 5}px!important;
110
+ top: ${top - tooltipHeight + scrollTop - 5}px!important;`;
111
+ break;
112
+ case "topRight":
113
+ styles =
114
+ styles +
115
+ `left: ${left + width / 2 - 5}px!important;
116
+ top: ${top - tooltipHeight + scrollTop - 5}px!important;`;
117
+ break;
118
+ case "leftTop":
119
+ styles =
120
+ styles +
121
+ `left: ${left - tooltipWidth - 5}px!important;
122
+ top: ${
123
+ bottom - tooltipHeight - height / 2 + scrollTop + 9
124
+ }px!important`;
125
+ break;
126
+ case "leftCenter":
127
+ styles =
128
+ styles +
129
+ `left: ${left - tooltipWidth - 5}px!important;
130
+ top: ${
131
+ bottom + scrollTop - tooltipHeight / 2 - height / 2
132
+ }px!important;`;
133
+ break;
134
+ case "leftBottom":
135
+ styles =
136
+ styles +
137
+ `left: ${left - tooltipWidth - 5}px!important;
138
+ top: ${bottom + scrollTop - height / 2 - 9}px!important;`;
139
+ break;
140
+ case "rightTop":
141
+ styles =
142
+ styles +
143
+ `left: ${right + 5}px!important;
144
+ top: ${
145
+ bottom - tooltipHeight - height / 2 + scrollTop + 9
146
+ }px!important`;
147
+ break;
148
+ case "rightCenter":
149
+ styles =
150
+ styles +
151
+ `left: ${right + 5}px!important;
152
+ top: ${
153
+ bottom + scrollTop - tooltipHeight / 2 - height / 2
154
+ }px!important;`;
155
+ break;
156
+
157
+ case "rightBottom":
158
+ styles =
159
+ styles +
160
+ `left: ${right + 5}px!important;
161
+ top: ${bottom + scrollTop - height / 2 - 9}px!important`;
162
+ break;
163
+ default:
164
+ styles =
165
+ styles +
166
+ `left: ${left + width / 2 - tooltipWidth / 2}px!important;
167
+ top: ${top - tooltipHeight + scrollTop - 5}px!important`;
168
+ break;
169
+ }
170
+
171
+ return styles;
172
+ }
173
+
174
+ getClassList(position) {
175
+ if (!position) {
176
+ return popoverPosition.topCenter;
177
+ }
178
+
179
+ return popoverPosition[position];
180
+ }
82
181
  }
@@ -3,7 +3,8 @@ import Tooltip from "./TooltipController";
3
3
  const tooltip = new Tooltip();
4
4
  const createTooltip = (el, binding) => {
5
5
  if (!tooltip.getTooltipContainer()) {
6
- tooltip.createTooltip(el, binding.value);
6
+ const position = Object.keys(binding.modifiers)[0] || binding.arg;
7
+ tooltip.createTooltip(el, binding.value, position);
7
8
  }
8
9
  };
9
10
 
@@ -26,15 +27,33 @@ const destroyTooltip = (event, el) => {
26
27
  }
27
28
  };
28
29
 
30
+ const attachTooltipListeners = (el, binding) => {
31
+ el.__tooltip_create = () => createTooltip(el, binding);
32
+ el.__tooltip_destroy = (e) => destroyTooltip(e, el);
33
+ el.__tooltip_remove_tooltip = () => tooltip.destroyTooltip();
34
+
35
+ el.addEventListener("mouseenter", el.__tooltip_create);
36
+ document.addEventListener("mousemove", el.__tooltip_destroy);
37
+ el.addEventListener("focus", el.__tooltip_create);
38
+ el.addEventListener("blur", el.__tooltip_remove_tooltip);
39
+ };
40
+
41
+ const removeTooltipListeners = (el) => {
42
+ el.removeEventListener("mouseenter", el.__tooltip_create);
43
+ document.removeEventListener("mousemove", el.__tooltip_destroy);
44
+ el.removeEventListener("focus", el.__tooltip_create);
45
+ el.removeEventListener("blur", el.__tooltip_remove_tooltip);
46
+ };
47
+
29
48
  export const TooltipDirective = {
30
49
  mounted(el, binding) {
31
- el.addEventListener("mouseenter", () => createTooltip(el, binding));
32
- document.addEventListener("mousemove", (e) => destroyTooltip(e, el));
50
+ attachTooltipListeners(el, binding);
33
51
  },
34
-
35
- beforeUnmount(el, binding) {
36
- tooltip.destroyTooltip();
37
- el.removeEventListener("mouseenter", () => createTooltip(el, binding));
38
- document.removeEventListener("mousemove", (e) => destroyTooltip(e, el));
52
+ updated(el, binding) {
53
+ removeTooltipListeners(el);
54
+ attachTooltipListeners(el, binding);
55
+ },
56
+ beforeUnmount(el) {
57
+ removeTooltipListeners(el);
39
58
  },
40
59
  };
@@ -18,13 +18,59 @@ const Template = (args) => ({
18
18
  setup() {
19
19
  return { args };
20
20
  },
21
- template: `<ib-button v-tooltip="'Tooltip Content'" v-bind="args">Hover to me</ib-button>`,
21
+ template: `
22
+ <div style="display:flex;flex-wrap:wrap;">
23
+ <div style="margin:20px">
24
+ <ib-button v-tooltip.bottomLeft="'Tooltip Content Content Content Content'" v-bind="args">Hover to me(bottomLeft)</ib-button>
25
+ </div>
26
+ <div style="margin:20px">
27
+ <ib-button v-tooltip.bottomCenter="'Tooltip Content Content Content Content'" v-bind="args">Hover to me(bottomCenter)</ib-button>
28
+ </div>
29
+ <div style="margin:20px">
30
+ <ib-button v-tooltip.bottomRight="'Tooltip Content Content Content Content'" v-bind="args">Hover to me(bottomRight)</ib-button>
31
+ </div>
32
+
33
+ <div style="margin:20px">
34
+ <ib-button v-tooltip.topLeft="'Tooltip Content Content Content Content'" v-bind="args">Hover to me(topLeft)</ib-button>
35
+ </div>
36
+ <div style="margin:20px">
37
+ <ib-button v-tooltip="'Tooltip Content Content Content Content'" v-bind="args">Hover to me(default)</ib-button>
38
+ </div>
39
+ <div style="margin:20px">
40
+ <ib-button v-tooltip.topRight="'Tooltip Content Content Content Content'" v-bind="args">Hover to me(topRight)</ib-button>
41
+ </div>
42
+
43
+ <div style="margin:20px">
44
+ <ib-button v-tooltip.leftTop="'Tooltip Content Content Content Content'" v-bind="args">Hover to me(leftTop)</ib-button>
45
+ </div>
46
+ <div style="margin:20px">
47
+ <ib-button v-tooltip.leftCenter="'Tooltip Content Content Content Content'" v-bind="args">Hover to me(leftCenter)</ib-button>
48
+ </div>
49
+ <div style="margin:20px">
50
+ <ib-button v-tooltip.leftBottom="'Tooltip Content Content Content Content'" v-bind="args">Hover to me(leftBottom)</ib-button>
51
+ </div>
52
+
53
+
54
+ <div style="margin:20px">
55
+ <ib-button v-tooltip.rightTop="'Tooltip Content Content Content Content'" v-bind="args">Hover to me(rightTop)</ib-button>
56
+ </div>
57
+ <div style="margin:20px">
58
+ <ib-button v-tooltip.rightCenter="'Tooltip Content Content Content Content'" v-bind="args">Hover to me(rightCenter)</ib-button>
59
+ </div>
60
+ <div style="margin:20px">
61
+ <ib-button v-tooltip.rightBottom="'Tooltip Content Content Content Content'" v-bind="args">Hover to me(rightBottom)</ib-button>
62
+ </div>
63
+
64
+
65
+ </div>
66
+
67
+ `,
22
68
  });
23
69
 
24
70
  export const Default = Template.bind({});
25
71
  Default.decorators = [
26
72
  () => ({
27
73
  template:
28
- '<div style="display: flex; align-items:center; justify-content: center; width: 400px; height: 400px; margin: 0 auto"><story /></div>',
74
+ '<div style="display: flex; align-items:center; justify-content: center; width: 600px; height: auto; margin: 0 auto"><story /></div>',
29
75
  }),
30
76
  ];