fleetcor-lwc 1.3.0 → 1.4.1

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/README.md CHANGED
@@ -68,17 +68,30 @@ Icon:
68
68
 
69
69
  <flt-icon icon="arrow-left"></flt-icon>
70
70
 
71
- arrow-left | ev | carwash | car |
72
- van | unleaded | fuel | driver |
73
- vehicle | both | shared-card | ev-and-fuel |
74
- oil | key | blocked | multiple-users |
75
- arrow-right |
71
+ arrow-left | ev | carwash | car | van | unleaded | fuel | driver | vehicle |
72
+ both | shared-card | ev-and-fuel | oil | key | blocked | multiple-users |
73
+ arrow-right | ...
74
+ ```
75
+
76
+ ```html
77
+ Tooltip:
78
+
79
+ <flt-tooltip content="Text description info" corner="12">
80
+ <!-- Any html element -->
81
+ <flt-icon icon="arrow-left"></flt-icon>
82
+ </flt-tooltip>
83
+
76
84
  ...
77
85
  ```
78
86
 
79
87
  ```scss
80
88
  /* mixins.scss */
81
89
 
90
+ // TOOLTIP ->
91
+ $FLT_TOOLTIP_BG_COLOR: var(--flt-tooltip-bg-color, #374151);
92
+ $FLT_TOOLTIP_COLOR: var(--flt-tooltip-bg-color, #f9fafb);
93
+ // <- TOOLTIP
94
+
82
95
  /* ICON START */
83
96
  $FLT_ICON_COLOR: var(--flt-icon-color, #111827);
84
97
  /* ICON END */
@@ -116,6 +129,16 @@ $FLT_BUTTON_LINK_HOVER_COLOR: var(--flt-button-link-hover-color, #6b7280);
116
129
 
117
130
  ## Release Notes:
118
131
 
132
+ - v.1.4.1
133
+ - Bug fix with empty content and svg max width
134
+
135
+ ---
136
+
137
+ - v.1.4.0
138
+ - Added Component `flt-tooltip`
139
+
140
+ ---
141
+
119
142
  - v.1.3.0
120
143
  - Added Component `flt-icon`
121
144
 
@@ -1,3 +1,8 @@
1
+ // TOOLTIP ->
2
+ $FLT_TOOLTIP_BG_COLOR: var(--flt-tooltip-bg-color, #374151);
3
+ $FLT_TOOLTIP_COLOR: var(--flt-tooltip-bg-color, #f9fafb);
4
+ // <- TOOLTIP
5
+
1
6
  // ICON ->
2
7
  $FLT_ICON_COLOR: var(--flt-icon-color, #111827);
3
8
  // <- ICON
@@ -1,3 +1,8 @@
1
+ // TOOLTIP ->
2
+ $FLT_TOOLTIP_BG_COLOR: var(--flt-tooltip-bg-color, #374151);
3
+ $FLT_TOOLTIP_COLOR: var(--flt-tooltip-bg-color, #F9FAFB);
4
+ // <- TOOLTIP
5
+
1
6
  // ICON ->
2
7
  $FLT_ICON_COLOR: var(--flt-icon-color, #111827);
3
8
  // <- ICON
@@ -0,0 +1,35 @@
1
+ import { createElement } from 'lwc'
2
+ import Tooltip from 'flt/tooltip'
3
+ import Button from 'flt/button'
4
+
5
+ class ResizeObserver {
6
+ observe() {}
7
+ unobserve() {}
8
+ }
9
+
10
+ describe('ui-button', () => {
11
+ window.ResizeObserver = ResizeObserver;
12
+
13
+ afterEach(() => {
14
+ while (document.body.firstChild) {
15
+ document.body.removeChild(document.body.firstChild)
16
+ }
17
+ })
18
+
19
+ it('displays greeting', () => {
20
+ const element_1 = createElement('flt-tooltip', {
21
+ is: Tooltip
22
+ })
23
+ element_1.content = 'Welcome to tooltip world'
24
+
25
+ const element_2 = createElement('flt-button', {
26
+ is: Button
27
+ })
28
+ element_2.label = 'Add'
29
+
30
+ element_1.appendChild(element_2)
31
+ document.body.appendChild(element_1)
32
+
33
+ expect(document.querySelector('.tooltip__text')).toBeDefined()
34
+ })
35
+ })
@@ -0,0 +1,11 @@
1
+ <template lwc:render-mode="light">
2
+ <div class="tooltip" onmouseover={over} ontouchstart={over} onmouseout={out} ontouchend={out}>
3
+ <slot></slot>
4
+ <div if:true={content} class={tooltipVisibility} style={conentStyle}>
5
+ <svg class="tooltip__svg" height={svgH} width={svgW} style={svgStyle}>
6
+ <path class="tooltip__path" d={svgD}></path>
7
+ </svg>
8
+ <p class="tooltip__text" style={textStyle}></p>
9
+ </div>
10
+ </div>
11
+ </template>
@@ -0,0 +1,286 @@
1
+ import './tooltip.scss'
2
+ import { LightningElement, api } from 'lwc'
3
+
4
+ export default class Tooltip extends LightningElement {
5
+ static renderMode = 'light'
6
+
7
+ @api content
8
+ @api corner = 0
9
+
10
+ maxWidth = 240
11
+ svgW = 0
12
+ svgH = 0
13
+ delta = 4
14
+ paddingX = 12
15
+ paddingY = 8
16
+ tip = 8
17
+ active = false
18
+ childElementRect = {}
19
+ leftPosition
20
+ rightPosition = false
21
+ bottomPosition = false
22
+
23
+ get textStyle() {
24
+ let result = `padding:${this.paddingY + this.delta}px ${this.paddingX + this.delta}px ${
25
+ this.paddingY + this.delta + this.tip
26
+ }px; width:${this.minimalWidth}px`
27
+ if (this.bottomPosition) {
28
+ result = `padding:${this.paddingY + this.delta + this.tip}px ${
29
+ this.paddingX + this.delta
30
+ }px ${this.paddingY + this.delta}px`
31
+ }
32
+ return result
33
+ }
34
+
35
+ get svgStyle() {
36
+ let result = `top:0px;`
37
+ if (this.rightPosition) {
38
+ result += `right:0px`
39
+ } else {
40
+ result += `left:0px`
41
+ }
42
+ return result
43
+ }
44
+
45
+ get conentStyle() {
46
+ let result = `top:-${this.svgH}px; width:${this.minimalWidth}px;`
47
+ if (this.bottomPosition) {
48
+ result = `bottom:-${this.svgH}px; width:${this.minimalWidth}px;`
49
+ }
50
+ if (this.rightPosition) {
51
+ result += `right:0px`
52
+ } else {
53
+ result += `left:${this.leftPosition}px`
54
+ }
55
+ return result
56
+ }
57
+
58
+ get tooltipVisibility() {
59
+ return this.active ? 'tooltip__content tooltip__content_visible' : 'tooltip__content'
60
+ }
61
+
62
+ get svgD() {
63
+ let result
64
+
65
+ if (this.bottomPosition && this.rightPosition) {
66
+ result = `
67
+ M ${this.delta} ${this.delta + this.corner + this.tip}
68
+ Q ${this.delta} ${this.delta + this.tip},
69
+ ${this.delta + this.corner} ${this.delta + this.tip}
70
+
71
+ L ${this.svgW - this.tip * 4 + this.tip} ${this.delta + this.tip}
72
+ ${this.svgW - this.tip * 4} ${this.delta}
73
+ ${this.svgW - this.tip * 4 - this.tip} ${this.delta + this.tip}
74
+
75
+ L ${this.svgW - this.delta - this.corner} ${this.delta + this.tip}
76
+ Q ${this.svgW - this.delta} ${this.delta + this.tip},
77
+ ${this.svgW - this.delta} ${this.delta + this.corner + this.tip}
78
+
79
+ L ${this.svgW - this.delta} ${this.svgH - this.delta - this.corner}
80
+ Q ${this.svgW - this.delta} ${this.svgH - this.delta},
81
+ ${this.svgW - this.delta - this.corner} ${this.svgH - this.delta}
82
+
83
+ L ${this.delta + this.corner} ${this.svgH - this.delta}
84
+ Q ${this.delta} ${this.svgH - this.delta},
85
+ ${this.delta} ${this.svgH - this.delta - this.corner}
86
+ Z`
87
+ } else if (this.bottomPosition && this.leftPosition) {
88
+ result = `
89
+ M ${this.delta} ${this.delta + this.corner + this.tip}
90
+ Q ${this.delta} ${this.delta + this.tip},
91
+ ${this.delta + this.corner} ${this.delta + this.tip}
92
+
93
+ L ${this.svgW / 2 + this.tip} ${this.delta + this.tip}
94
+ ${this.svgW / 2} ${this.delta}
95
+ ${this.svgW / 2 - this.tip} ${this.delta + this.tip}
96
+
97
+ L ${this.svgW - this.delta - this.corner} ${this.delta + this.tip}
98
+ Q ${this.svgW - this.delta} ${this.delta + this.tip},
99
+ ${this.svgW - this.delta} ${this.delta + this.corner + this.tip}
100
+
101
+ L ${this.svgW - this.delta} ${this.svgH - this.delta - this.corner}
102
+ Q ${this.svgW - this.delta} ${this.svgH - this.delta},
103
+ ${this.svgW - this.delta - this.corner} ${this.svgH - this.delta}
104
+
105
+ L ${this.delta + this.corner} ${this.svgH - this.delta}
106
+ Q ${this.delta} ${this.svgH - this.delta},
107
+ ${this.delta} ${this.svgH - this.delta - this.corner}
108
+ Z`
109
+ } else if (this.bottomPosition) {
110
+ result = `
111
+ M ${this.delta} ${this.delta + this.corner + this.tip}
112
+ Q ${this.delta} ${this.delta + this.tip},
113
+ ${this.delta + this.corner} ${this.delta + this.tip}
114
+
115
+ L ${this.tip * 4 + this.tip} ${this.delta + this.tip}
116
+ ${this.tip * 4} ${this.delta}
117
+ ${this.tip * 4 - this.tip} ${this.delta + this.tip}
118
+
119
+ L ${this.svgW - this.delta - this.corner} ${this.delta + this.tip}
120
+ Q ${this.svgW - this.delta} ${this.delta + this.tip},
121
+ ${this.svgW - this.delta} ${this.delta + this.corner + this.tip}
122
+
123
+ L ${this.svgW - this.delta} ${this.svgH - this.delta - this.corner}
124
+ Q ${this.svgW - this.delta} ${this.svgH - this.delta},
125
+ ${this.svgW - this.delta - this.corner} ${this.svgH - this.delta}
126
+
127
+ L ${this.delta + this.corner} ${this.svgH - this.delta}
128
+ Q ${this.delta} ${this.svgH - this.delta},
129
+ ${this.delta} ${this.svgH - this.delta - this.corner}
130
+ Z`
131
+ } else if (this.rightPosition) {
132
+ result = `
133
+ M ${this.delta} ${this.delta + this.corner}
134
+ Q ${this.delta} ${this.delta},
135
+ ${this.delta + this.corner} ${this.delta}
136
+
137
+ L ${this.svgW - this.delta - this.corner} ${this.delta}
138
+ Q ${this.svgW - this.delta} ${this.delta},
139
+ ${this.svgW - this.delta} ${this.delta + this.corner}
140
+
141
+ L ${this.svgW - this.delta} ${this.svgH - this.tip - this.delta - this.corner}
142
+ Q ${this.svgW - this.delta} ${this.svgH - this.tip - this.delta},
143
+ ${this.svgW - this.delta - this.corner} ${this.svgH - this.tip - this.delta}
144
+
145
+ L ${this.svgW - this.tip * 4 + this.tip} ${this.svgH - this.tip - this.delta}
146
+ ${this.svgW - this.tip * 4} ${this.svgH - this.tip - this.delta + this.tip}
147
+ ${this.svgW - this.tip * 4 - this.tip} ${this.svgH - this.tip - this.delta}
148
+
149
+ L ${this.delta + this.corner} ${this.svgH - this.tip - this.delta}
150
+ Q ${this.delta} ${this.svgH - this.tip - this.delta},
151
+ ${this.delta} ${this.svgH - this.tip - this.delta - this.corner}
152
+ Z`
153
+ } else if (this.leftPosition) {
154
+ result = `
155
+ M ${this.delta} ${this.delta + this.corner}
156
+ Q ${this.delta} ${this.delta},
157
+ ${this.delta + this.corner} ${this.delta}
158
+
159
+ L ${this.svgW - this.delta - this.corner} ${this.delta}
160
+ Q ${this.svgW - this.delta} ${this.delta},
161
+ ${this.svgW - this.delta} ${this.delta + this.corner}
162
+
163
+ L ${this.svgW - this.delta} ${this.svgH - this.tip - this.delta - this.corner}
164
+ Q ${this.svgW - this.delta} ${this.svgH - this.tip - this.delta},
165
+ ${this.svgW - this.delta - this.corner} ${this.svgH - this.tip - this.delta}
166
+
167
+ L ${this.svgW / 2 + this.tip} ${this.svgH - this.tip - this.delta}
168
+ ${this.svgW / 2} ${this.svgH - this.tip - this.delta + this.tip}
169
+ ${this.svgW / 2 - this.tip} ${this.svgH - this.tip - this.delta}
170
+
171
+ L ${this.delta + this.corner} ${this.svgH - this.tip - this.delta}
172
+ Q ${this.delta} ${this.svgH - this.tip - this.delta},
173
+ ${this.delta} ${this.svgH - this.tip - this.delta - this.corner}
174
+ Z`
175
+ } else {
176
+ result = `
177
+ M ${this.delta} ${this.delta + this.corner}
178
+ Q ${this.delta} ${this.delta},
179
+ ${this.delta + this.corner} ${this.delta}
180
+
181
+ L ${this.svgW - this.delta - this.corner} ${this.delta}
182
+ Q ${this.svgW - this.delta} ${this.delta},
183
+ ${this.svgW - this.delta} ${this.delta + this.corner}
184
+
185
+ L ${this.svgW - this.delta} ${this.svgH - this.tip - this.delta - this.corner}
186
+ Q ${this.svgW - this.delta} ${this.svgH - this.tip - this.delta},
187
+ ${this.svgW - this.delta - this.corner} ${this.svgH - this.tip - this.delta}
188
+
189
+ L ${this.tip * 4 + this.tip} ${this.svgH - this.tip - this.delta}
190
+ ${this.tip * 4} ${this.svgH - this.tip - this.delta + this.tip}
191
+ ${this.tip * 4 - this.tip} ${this.svgH - this.tip - this.delta}
192
+
193
+ L ${this.delta + this.corner} ${this.svgH - this.tip - this.delta}
194
+ Q ${this.delta} ${this.svgH - this.tip - this.delta},
195
+ ${this.delta} ${this.svgH - this.tip - this.delta - this.corner}
196
+ Z`
197
+ }
198
+
199
+ return result
200
+ }
201
+
202
+ connectedCallback() {
203
+ if (this.content) {
204
+ this.resizeObserver = new ResizeObserver(this.update.bind(this))
205
+ }
206
+ }
207
+
208
+ update() {
209
+ if (this.content) {
210
+ const text = this.firstChild.querySelector('.tooltip__text')
211
+ text.innerHTML = this.content
212
+ this.createTooltip()
213
+ }
214
+ }
215
+
216
+ over() {
217
+ if (!this.active && this.content) {
218
+ this.active = true
219
+ this.createTooltip()
220
+ }
221
+ }
222
+
223
+ out() {
224
+ if (this.active && this.content) {
225
+ this.active = false
226
+ this.childElementRect = this.firstChild.firstChild.getBoundingClientRect()
227
+ this.leftPosition = (this.childElementRect.width - this.svgW) / 2
228
+ this.rightPosition = false
229
+ this.bottomPosition = false
230
+ }
231
+ }
232
+
233
+ createTooltip() {
234
+ // 1. find width of tooltip
235
+ const text = this.firstChild.querySelector('.tooltip__text')
236
+ this.minimalWidth = getLineWidth(text)
237
+ if (this.minimalWidth < this.maxWidth) {
238
+ this.minimalWidth = this.minimalWidth + this.paddingX * 2 + 2 * this.delta
239
+ this.svgW = this.minimalWidth
240
+ } else {
241
+ this.minimalWidth = this.maxWidth
242
+ this.svgW = this.minimalWidth
243
+ }
244
+ this.svgH = text.offsetHeight
245
+
246
+ // 2. find position left or right
247
+
248
+ const textPosition = text.getBoundingClientRect()
249
+ const bodyPosition = document.body.getBoundingClientRect()
250
+
251
+ if (textPosition.right > bodyPosition.width - 12) {
252
+ this.leftPosition = 0
253
+ this.rightPosition = true
254
+ } else if (textPosition.x < 12) {
255
+ this.leftPosition = 0
256
+ this.rightPosition = false
257
+ } else {
258
+ this.childElementRect = this.firstChild.firstChild.getBoundingClientRect()
259
+ this.leftPosition = (this.childElementRect.width - this.svgW) / 2
260
+ }
261
+
262
+ // 3. find position top or bottom
263
+ if (textPosition.top < 12) {
264
+ this.bottomPosition = true
265
+ }
266
+ }
267
+
268
+ renderedCallback() {
269
+ if (this.content) {
270
+ this.resizeObserver.observe(this.firstChild)
271
+ }
272
+ }
273
+ }
274
+
275
+ function getLineWidth(el) {
276
+ let temp = document.createElement(el.nodeName),
277
+ ret
278
+ temp.setAttribute('style', 'position:fixed;margin:0;padding:0;font-size:inherit;')
279
+ temp.innerHTML = el.innerHTML
280
+
281
+ document.body.appendChild(temp)
282
+ ret = temp.clientWidth
283
+ document.body.removeChild(temp)
284
+
285
+ return ret
286
+ }
@@ -0,0 +1,46 @@
1
+ @import './../../../common/mixins_aquamarine';
2
+ /* mixins */
3
+
4
+ .tooltip {
5
+ display: inline-block;
6
+ cursor: pointer;
7
+ position: relative;
8
+ max-width: initial;
9
+
10
+ &__content {
11
+ position: absolute;
12
+ z-index: 999999;
13
+ cursor: initial;
14
+ visibility: hidden;
15
+ opacity: 0;
16
+ font-size: 16px;
17
+ line-height: 1.3;
18
+ max-width: initial;
19
+ transition: opacity 0.3s ease-out;
20
+
21
+ &_visible {
22
+ visibility: visible;
23
+ opacity: 1;
24
+ }
25
+ }
26
+
27
+ &__text {
28
+ position: relative;
29
+ color: $FLT_TOOLTIP_COLOR;
30
+ float: left;
31
+ margin: 0;
32
+ max-width: 240px;
33
+ box-sizing: border-box;
34
+ }
35
+
36
+ &__svg {
37
+ position: absolute;
38
+ max-width: initial;
39
+ }
40
+
41
+ &__path {
42
+ fill: $FLT_TOOLTIP_BG_COLOR;
43
+ -webkit-filter: drop-shadow(0px 1px 3px rgba(16, 24, 40, 0.1));
44
+ filter: drop-shadow(0px 1px 3px rgba(16, 24, 40, 0.1));
45
+ }
46
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetcor-lwc",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "description": "LWC framework by Fleetcor",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,7 +21,8 @@
21
21
  ],
22
22
  "expose": [
23
23
  "flt/button",
24
- "flt/icon"
24
+ "flt/icon",
25
+ "flt/tooltip"
25
26
  ]
26
27
  },
27
28
  "keywords": [