-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(tooltip): support tooltip positions - add to button and tool…
…tip-icon components
- Loading branch information
Showing
7 changed files
with
231 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
testgen/ui/components/frontend/js/components/tooltip.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
// Code modified from vanjs-ui | ||
// https://www.npmjs.com/package/vanjs-ui | ||
// https://cdn.jsdelivr.net/npm/vanjs-ui@0.10.0/dist/van-ui.nomodule.js | ||
|
||
/** | ||
* @typedef Properties | ||
* @type {object} | ||
* @property {string} text | ||
* @property {boolean} show | ||
* @property {('top-left' | 'top' | 'top-right' | 'right' | 'bottom-right' | 'bottom' | 'bottom-left' | 'left')?} position | ||
*/ | ||
import van from '../van.min.js'; | ||
import { getValue, loadStylesheet } from '../utils.js'; | ||
|
||
const { div, span } = van.tags; | ||
const defaultPosition = 'top'; | ||
|
||
const Tooltip = (/** @type Properties */ props) => { | ||
loadStylesheet('tooltip', stylesheet); | ||
|
||
return span( | ||
{ | ||
class: () => `tg-tooltip ${getValue(props.position) || defaultPosition} ${getValue(props.show) ? '' : 'hidden'}`, | ||
style: () => `opacity: ${getValue(props.show) ? 1 : 0};`, | ||
}, | ||
props.text, | ||
div({ class: 'tg-tooltip--triangle' }), | ||
); | ||
}; | ||
|
||
const stylesheet = new CSSStyleSheet(); | ||
stylesheet.replace(` | ||
.tg-tooltip { | ||
width: max-content; | ||
max-width: 400px; | ||
position: absolute; | ||
z-index: 1; | ||
border-radius: 4px; | ||
background-color: var(--tooltip-color); | ||
padding: 4px 8px; | ||
color: white; | ||
font-size: 13px; | ||
font-family: 'Roboto', 'Helvetica Neue', sans-serif; | ||
text-align: center; | ||
text-wrap: wrap; | ||
transition: opacity 0.3s; | ||
} | ||
.tg-tooltip--triangle { | ||
width: 0; | ||
height: 0; | ||
position: absolute; | ||
border: solid transparent; | ||
} | ||
.tg-tooltip.top-left { | ||
right: 50%; | ||
bottom: 125%; | ||
transform: translateX(20px); | ||
} | ||
.top-left .tg-tooltip--triangle { | ||
bottom: -5px; | ||
right: 20px; | ||
margin-right: -5px; | ||
border-width: 5px 5px 0; | ||
border-top-color: var(--tooltip-color); | ||
} | ||
.tg-tooltip.top { | ||
left: 50%; | ||
bottom: 125%; | ||
transform: translateX(-50%); | ||
} | ||
.top .tg-tooltip--triangle { | ||
bottom: -5px; | ||
left: 50%; | ||
margin-left: -5px; | ||
border-width: 5px 5px 0; | ||
border-top-color: var(--tooltip-color); | ||
} | ||
.tg-tooltip.top-right { | ||
left: 50%; | ||
bottom: 125%; | ||
transform: translateX(-20px); | ||
} | ||
.top-right .tg-tooltip--triangle { | ||
bottom: -5px; | ||
left: 20px; | ||
margin-left: -5px; | ||
border-width: 5px 5px 0; | ||
border-top-color: var(--tooltip-color); | ||
} | ||
.tg-tooltip.right { | ||
left: 125%; | ||
} | ||
.right .tg-tooltip--triangle { | ||
top: 50%; | ||
left: -5px; | ||
margin-top: -5px; | ||
border-width: 5px 5px 5px 0; | ||
border-right-color: var(--tooltip-color); | ||
} | ||
.tg-tooltip.bottom-right { | ||
left: 50%; | ||
top: 125%; | ||
transform: translateX(-20px); | ||
} | ||
.bottom-right .tg-tooltip--triangle { | ||
top: -5px; | ||
left: 20px; | ||
margin-left: -5px; | ||
border-width: 0 5px 5px; | ||
border-bottom-color: var(--tooltip-color); | ||
} | ||
.tg-tooltip.bottom { | ||
top: 125%; | ||
left: 50%; | ||
transform: translateX(-50%); | ||
} | ||
.bottom .tg-tooltip--triangle { | ||
top: -5px; | ||
left: 50%; | ||
margin-left: -5px; | ||
border-width: 0 5px 5px; | ||
border-bottom-color: var(--tooltip-color); | ||
} | ||
.tg-tooltip.bottom-left { | ||
right: 50%; | ||
top: 125%; | ||
transform: translateX(20px); | ||
} | ||
.bottom-left .tg-tooltip--triangle { | ||
top: -5px; | ||
right: 20px; | ||
margin-right: -5px; | ||
border-width: 0 5px 5px; | ||
border-bottom-color: var(--tooltip-color); | ||
} | ||
.tg-tooltip.left { | ||
right: 125%; | ||
} | ||
.left .tg-tooltip--triangle { | ||
top: 50%; | ||
right: -5px; | ||
margin-top: -5px; | ||
border-width: 5px 0 5px 5px; | ||
border-left-color: var(--tooltip-color); | ||
} | ||
`); | ||
|
||
export { Tooltip }; |
45 changes: 45 additions & 0 deletions
45
testgen/ui/components/frontend/js/components/tooltip_icon.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* @typedef Properties | ||
* @type {object} | ||
* @property {string} icon | ||
* @property {number?} iconSize | ||
* @property {string} tooltip | ||
* @property {('top-left' | 'top' | 'top-right' | 'right' | 'bottom-right' | 'bottom' | 'bottom-left' | 'left')?} tooltipPosition | ||
* @property {string} classes | ||
*/ | ||
import { getValue, loadStylesheet } from '../utils.js'; | ||
import van from '../van.min.js'; | ||
import { Tooltip } from './tooltip.js'; | ||
|
||
const { i } = van.tags; | ||
const defaultIconSize = 20; | ||
|
||
const TooltipIcon = (/** @type Properties */ props) => { | ||
loadStylesheet('tooltipIcon', stylesheet); | ||
const showTooltip = van.state(false); | ||
|
||
return i( | ||
{ | ||
class: () => `material-symbols-rounded tg-tooltip-icon text-secondary ${getValue(props.classes)}`, | ||
style: () => `font-size: ${getValue(props.iconSize) || defaultIconSize}px;`, | ||
onmouseenter: () => showTooltip.val = true, | ||
onmouseleave: () => showTooltip.val = false, | ||
}, | ||
props.icon, | ||
Tooltip({ | ||
text: props.tooltip, | ||
show: showTooltip, | ||
position: props.tooltipPosition, | ||
}), | ||
); | ||
}; | ||
|
||
const stylesheet = new CSSStyleSheet(); | ||
stylesheet.replace(` | ||
.tg-tooltip-icon { | ||
position: relative; | ||
cursor: default; | ||
} | ||
`); | ||
|
||
export { TooltipIcon }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.