Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dima Krasner
Sharkey
Commits
149edaec
Commit
149edaec
authored
3 years ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
refactor(client): use setup sugar
parent
6eeb7a92
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/client/src/components/ui/tooltip.vue
+62
-79
62 additions, 79 deletions
packages/client/src/components/ui/tooltip.vue
with
62 additions
and
79 deletions
packages/client/src/components/ui/tooltip.vue
+
62
−
79
View file @
149edaec
<
template
>
<transition
:name=
"$store.state.animation ? 'tooltip' : ''"
appear
@
after-leave=
"
$
emit('closed')"
>
<transition
:name=
"$store.state.animation ? 'tooltip' : ''"
appear
@
after-leave=
"emit('closed')"
>
<div
v-show=
"showing"
ref=
"el"
class=
"buebdbiu _acrylic _shadow"
:style=
"
{ zIndex, maxWidth: maxWidth + 'px' }">
<slot>
{{
text
}}
</slot>
</div>
</transition>
</
template
>
<
script
lang=
"ts"
>
import
{
defineComponent
,
nextTick
,
onMounted
,
onUnmounted
,
ref
}
from
'
vue
'
;
<
script
lang=
"ts"
setup
>
import
{
nextTick
,
onMounted
,
onUnmounted
,
ref
}
from
'
vue
'
;
import
*
as
os
from
'
@/os
'
;
export
default
defineComponent
({
props
:
{
showing
:
{
type
:
Boolean
,
required
:
true
,
},
source
:
{
required
:
true
,
},
text
:
{
type
:
String
,
required
:
false
},
maxWidth
:
{
type
:
Number
,
required
:
false
,
default
:
250
,
},
},
emits
:
[
'
closed
'
],
setup
(
props
,
context
)
{
const
el
=
ref
<
HTMLElement
>
();
const
zIndex
=
os
.
claimZIndex
(
'
high
'
);
const
setPosition
=
()
=>
{
if
(
el
.
value
==
null
)
return
;
const
rect
=
props
.
source
.
getBoundingClientRect
();
const
contentWidth
=
el
.
value
.
offsetWidth
;
const
contentHeight
=
el
.
value
.
offsetHeight
;
let
left
=
rect
.
left
+
window
.
pageXOffset
+
(
props
.
source
.
offsetWidth
/
2
);
let
top
=
rect
.
top
+
window
.
pageYOffset
-
contentHeight
;
left
-=
(
el
.
value
.
offsetWidth
/
2
);
if
(
left
+
contentWidth
-
window
.
pageXOffset
>
window
.
innerWidth
)
{
left
=
window
.
innerWidth
-
contentWidth
+
window
.
pageXOffset
-
1
;
}
if
(
top
-
window
.
pageYOffset
<
0
)
{
top
=
rect
.
top
+
window
.
pageYOffset
+
props
.
source
.
offsetHeight
;
el
.
value
.
style
.
transformOrigin
=
'
center top
'
;
}
el
.
value
.
style
.
left
=
left
+
'
px
'
;
el
.
value
.
style
.
top
=
top
+
'
px
'
;
};
const
props
=
withDefaults
(
defineProps
<
{
showing
:
boolean
;
source
:
HTMLElement
;
text
?:
string
;
maxWidth
?;
number
;
}
>
(),
{
maxWidth
:
250
,
});
onMounted
(()
=>
{
nextTick
(()
=>
{
if
(
props
.
source
==
null
)
{
context
.
emit
(
'
closed
'
);
return
;
}
const
emit
=
defineEmits
<
{
(
ev
:
'
closed
'
):
void
;
}
>
();
setPosition
();
const
el
=
ref
<
HTMLElement
>
();
const
zIndex
=
os
.
claimZIndex
(
'
high
'
);
let
loopHandler
;
const
setPosition
=
()
=>
{
if
(
el
.
value
==
null
)
return
;
const
loop
=
()
=>
{
loopHandler
=
window
.
requestAnimationFrame
(()
=>
{
setPosition
();
loop
();
});
};
const
rect
=
props
.
source
.
getBoundingClientRect
();
loop
();
const
contentWidth
=
el
.
value
.
offsetWidth
;
const
contentHeight
=
el
.
value
.
offsetHeight
;
onUnmounted
(()
=>
{
window
.
cancelAnimationFrame
(
loopHandler
);
});
});
});
let
left
=
rect
.
left
+
window
.
pageXOffset
+
(
props
.
source
.
offsetWidth
/
2
);
let
top
=
rect
.
top
+
window
.
pageYOffset
-
contentHeight
;
left
-=
(
el
.
value
.
offsetWidth
/
2
);
if
(
left
+
contentWidth
-
window
.
pageXOffset
>
window
.
innerWidth
)
{
left
=
window
.
innerWidth
-
contentWidth
+
window
.
pageXOffset
-
1
;
}
if
(
top
-
window
.
pageYOffset
<
0
)
{
top
=
rect
.
top
+
window
.
pageYOffset
+
props
.
source
.
offsetHeight
;
el
.
value
.
style
.
transformOrigin
=
'
center top
'
;
}
el
.
value
.
style
.
left
=
left
+
'
px
'
;
el
.
value
.
style
.
top
=
top
+
'
px
'
;
};
return
{
el
,
zIndex
,
onMounted
(()
=>
{
nextTick
(()
=>
{
if
(
props
.
source
==
null
)
{
emit
(
'
closed
'
);
return
;
}
setPosition
();
let
loopHandler
;
const
loop
=
()
=>
{
loopHandler
=
window
.
requestAnimationFrame
(()
=>
{
setPosition
();
loop
();
});
};
},
})
loop
();
onUnmounted
(()
=>
{
window
.
cancelAnimationFrame
(
loopHandler
);
});
});
});
</
script
>
<
style
lang=
"scss"
scoped
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment