This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce OcResourceLink to reduce code duplication...
... and fix icons/thumbnails not being shown if the resource is not clickable.
- Loading branch information
Showing
3 changed files
with
134 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<template> | ||
<component | ||
:is="componentType" | ||
v-bind="componentProps" | ||
v-if="isResourceClickable" | ||
:target="linkTargetBlank" | ||
:aria-describedby="opensInNewWindowDescriptionId" | ||
@click.stop="emitClick" | ||
@click.native.stop | ||
> | ||
<slot :opensInNewWindowDescriptionId="opensInNewWindowDescriptionId" /> | ||
</component> | ||
<span v-else> | ||
<slot /> | ||
</span> | ||
</template> | ||
|
||
<script> | ||
import uniqueId from "../../../utils/uniqueId" | ||
/** | ||
* Wraps content in a resource link | ||
*/ | ||
export default { | ||
name: "OcResourceLink", | ||
status: "prototype", | ||
release: "unreleased", | ||
props: { | ||
/** | ||
* The resource folder link | ||
*/ | ||
folderLink: { | ||
type: Object, | ||
required: false, | ||
default: null, | ||
}, | ||
/** | ||
* The resource to be displayed | ||
*/ | ||
resource: { | ||
type: Object, | ||
required: true, | ||
}, | ||
/** | ||
* Asserts whether clicking on the resource name triggers any action | ||
*/ | ||
isResourceClickable: { | ||
type: Boolean, | ||
required: false, | ||
default: true, | ||
}, | ||
}, | ||
computed: { | ||
isFolder() { | ||
return this.resource.isFolder | ||
}, | ||
componentType() { | ||
return this.isFolder ? "router-link" : "oc-button" | ||
}, | ||
componentProps() { | ||
if (!this.isRouterLink) { | ||
return { | ||
appearance: "raw", | ||
gapSize: "none", | ||
justifyContent: "left", | ||
} | ||
} | ||
return { | ||
to: this.folderLink, | ||
} | ||
}, | ||
opensInNewWindowDescriptionId() { | ||
if (this.resource.opensInNewWindow) { | ||
return uniqueId("oc-link-description-") | ||
} | ||
return null | ||
}, | ||
isRouterLink() { | ||
return this.isResourceClickable && this.isFolder | ||
}, | ||
linkTargetBlank() { | ||
if (this.isRouterLink && this.resource.opensInNewWindow) { | ||
return "_blank" | ||
} | ||
return null | ||
}, | ||
}, | ||
methods: { | ||
emitClick() { | ||
if (this.isFolder) { | ||
return | ||
} | ||
/** | ||
* Triggered when the resource is a file and the name is clicked | ||
*/ | ||
this.$emit("click") | ||
}, | ||
}, | ||
} | ||
</script> |
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