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
ef122411
Unverified
Commit
ef122411
authored
2 years ago
by
Kagami Sascha Rosylight
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
refactor(client): fix TypeScript errors from MkPageHeader (#9400)
parent
e4374aba
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/global/MkPageHeader.vue
+20
-17
20 additions, 17 deletions
packages/client/src/components/global/MkPageHeader.vue
with
20 additions
and
17 deletions
packages/client/src/components/global/MkPageHeader.vue
+
20
−
17
View file @
ef122411
...
...
@@ -21,7 +21,7 @@
</div>
</div>
<div
v-if=
"!narrow || hideTitle"
class=
"tabs"
>
<button
v-for=
"tab in tabs"
:ref=
"(el) => tabRefs[tab.key] = el"
v-tooltip.noDelay=
"tab.title"
class=
"tab _button"
:class=
"
{ active: tab.key != null
&&
tab.key === props.tab }" @mousedown="(ev) => onTabMousedown(tab, ev)" @click="(ev) => onTabClick(tab, ev)">
<button
v-for=
"tab in tabs"
:ref=
"(el) => tabRefs[tab.key] =
(
el
as HTMLElement)
"
v-tooltip.noDelay=
"tab.title"
class=
"tab _button"
:class=
"
{ active: tab.key != null
&&
tab.key === props.tab }" @mousedown="(ev) => onTabMousedown(tab, ev)" @click="(ev) => onTabClick(tab, ev)">
<i
v-if=
"tab.icon"
class=
"icon"
:class=
"tab.icon"
></i>
<span
v-if=
"!tab.iconOnly"
class=
"title"
>
{{
tab
.
title
}}
</span>
</button>
...
...
@@ -37,34 +37,36 @@
</template>
<
script
lang=
"ts"
setup
>
import
{
computed
,
onMounted
,
onUnmounted
,
ref
,
inject
,
watch
,
shallowReactive
,
nextTick
,
reactive
}
from
'
vue
'
;
import
{
onMounted
,
onUnmounted
,
ref
,
inject
,
watch
,
nextTick
}
from
'
vue
'
;
import
tinycolor
from
'
tinycolor2
'
;
import
{
popupMenu
}
from
'
@/os
'
;
import
{
scrollToTop
}
from
'
@/scripts/scroll
'
;
import
{
i18n
}
from
'
@/i18n
'
;
import
{
globalEvents
}
from
'
@/events
'
;
import
{
injectPageMetadata
}
from
'
@/scripts/page-metadata
'
;
import
{
$i
}
from
'
@/account
'
;
type
Tab
=
{
key
?
:
string
|
null
;
key
:
string
;
title
:
string
;
icon
?:
string
;
iconOnly
?:
boolean
;
onClick
?:
(
ev
:
MouseEvent
)
=>
void
;
};
const
props
=
defineProps
<
{
const
props
=
withDefaults
(
defineProps
<
{
tabs
?:
Tab
[];
tab
?:
string
;
actions
?:
{
text
:
string
;
icon
:
string
;
highlighted
?:
boolean
;
handler
:
(
ev
:
MouseEvent
)
=>
void
;
}[];
thin
?:
boolean
;
displayMyAvatar
?:
boolean
;
}
>
();
}
>
(),
{
tabs
:
()
=>
([]
as
Tab
[])
});
const
emit
=
defineEmits
<
{
(
ev
:
'
update:tab
'
,
key
:
string
);
...
...
@@ -75,13 +77,12 @@ const metadata = injectPageMetadata();
const
hideTitle
=
inject
(
'
shouldOmitHeaderTitle
'
,
false
);
const
thin_
=
props
.
thin
||
inject
(
'
shouldHeaderThin
'
,
false
);
const
el
=
$ref
<
HTMLElement
|
null
>
(
null
);
const
tabRefs
=
{};
const
el
=
$ref
<
HTMLElement
|
undefined
>
(
undefined
);
const
tabRefs
:
Record
<
string
,
HTMLElement
|
null
>
=
{};
const
tabHighlightEl
=
$ref
<
HTMLElement
|
null
>
(
null
);
const
bg
=
ref
(
null
);
const
bg
=
ref
<
string
|
undefined
>
(
undefined
);
let
narrow
=
$ref
(
false
);
const
height
=
ref
(
0
);
const
hasTabs
=
$computed
(()
=>
props
.
tabs
&&
props
.
tabs
.
length
>
0
);
const
hasTabs
=
$computed
(()
=>
props
.
tabs
.
length
>
0
);
const
hasActions
=
$computed
(()
=>
props
.
actions
&&
props
.
actions
.
length
>
0
);
const
show
=
$computed
(()
=>
{
return
!
hideTitle
||
hasTabs
||
hasActions
;
...
...
@@ -100,7 +101,7 @@ const showTabsPopup = (ev: MouseEvent) => {
onTabClick
(
tab
,
ev
);
},
}));
popupMenu
(
menu
,
ev
.
currentTarget
??
ev
.
targe
t
);
popupMenu
(
menu
,
ev
.
currentTarget
!
as
HTMLElemen
t
);
};
const
preventDrag
=
(
ev
:
TouchEvent
)
=>
{
...
...
@@ -108,7 +109,9 @@ const preventDrag = (ev: TouchEvent) => {
};
const
onClick
=
()
=>
{
scrollToTop
(
el
,
{
behavior
:
'
smooth
'
});
if
(
el
)
{
scrollToTop
(
el
as
HTMLElement
,
{
behavior
:
'
smooth
'
});
}
};
function
onTabMousedown
(
tab
:
Tab
,
ev
:
MouseEvent
):
void
{
...
...
@@ -144,8 +147,8 @@ onMounted(() => {
watch
(()
=>
[
props
.
tab
,
props
.
tabs
],
()
=>
{
nextTick
(()
=>
{
const
tabEl
=
tabRefs
[
props
.
tab
];
if
(
tabEl
&&
tabHighlightEl
)
{
const
tabEl
=
props
.
tab
?
tabRefs
[
props
.
tab
]
:
undefined
;
if
(
tabEl
&&
tabHighlightEl
&&
tabEl
.
parentElement
)
{
// offsetWidth や offsetLeft は少数を丸めてしまうため getBoundingClientRect を使う必要がある
// https://developer.mozilla.org/ja/docs/Web/API/HTMLElement/offsetWidth#%E5%80%A4
const
parentRect
=
tabEl
.
parentElement
.
getBoundingClientRect
();
...
...
@@ -161,11 +164,11 @@ onMounted(() => {
if
(
el
&&
el
.
parentElement
)
{
narrow
=
el
.
parentElement
.
offsetWidth
<
500
;
ro
=
new
ResizeObserver
((
entries
,
observer
)
=>
{
if
(
el
.
parentElement
&&
document
.
body
.
contains
(
el
))
{
if
(
el
.
parentElement
&&
document
.
body
.
contains
(
el
as
HTMLElement
))
{
narrow
=
el
.
parentElement
.
offsetWidth
<
500
;
}
});
ro
.
observe
(
el
.
parentElement
);
ro
.
observe
(
el
.
parentElement
as
HTMLElement
);
}
});
...
...
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