Skip to content

Commit

Permalink
Add BButton component as base for AsyncButton, 2.18.2
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Jan 15, 2025
1 parent 9855edc commit c547483
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 6 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.18.2] - 2025-01-15

### Added

- Internal `BButton` component as base for `AsyncButton`

## [2.18.1] - 2025-01-05

### Added
Expand Down Expand Up @@ -692,7 +698,11 @@ First stable release.
Please see the [Releases](https://github.com/Open-EO/openeo-vue-components/releases) for changelogs prior to v1.0.0.


[Unreleased]: https://github.com/Open-EO/openeo-vue-components/compare/v2.16.0...HEAD
[Unreleased]: https://github.com/Open-EO/openeo-vue-components/compare/v2.18.2...HEAD
[2.18.2]: https://github.com/Open-EO/openeo-vue-components/compare/v2.18.1...v2.18.2
[2.18.1]: https://github.com/Open-EO/openeo-vue-components/compare/v2.18.0...v2.18.1
[2.18.0]: https://github.com/Open-EO/openeo-vue-components/compare/v2.17.1...v2.18.0
[2.17.0]: https://github.com/Open-EO/openeo-vue-components/compare/v2.16.0...v2.17.0
[2.16.0]: https://github.com/Open-EO/openeo-vue-components/compare/v2.15.1...v2.16.0
[2.15.1]: https://github.com/Open-EO/openeo-vue-components/compare/v2.15.0...v2.15.1
[2.15.0]: https://github.com/Open-EO/openeo-vue-components/compare/v2.14.1...v2.15.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A set of [Vue](https://vuejs.org) components for [openEO](http://openeo.org).

This library's version is [**2.18.1**](CHANGELOG.md) and supports **openEO API versions 1.x.x**.
This library's version is [**2.18.2**](CHANGELOG.md) and supports **openEO API versions 1.x.x**.
Legacy versions supporting API version 0.x are available as [releases](https://github.com/Open-EO/openeo-vue-components/releases).

npm: [@openeo/vue-components](https://www.npmjs.com/package/@openeo/vue-components)
Expand Down
15 changes: 12 additions & 3 deletions components/internal/AsyncButton.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<button type="button" v-show="fn" :title="title" :disabled="disabled" class="async-button" :class="{awesome: fa}" @click="update">
<BButton type="button" v-show="fn" :title="title" :disabled="disabled" class="async-button" :class="{awesome: fa}" @click="update">
<span class="button-content">
<span v-if="loading" class="icon loading">
<i v-if="fa" :class="loadingClasses"></i>
Expand All @@ -20,13 +20,17 @@
</span>
<span class="text"><slot></slot></span>
</span>
</button>
</BButton>
</template>

<script>
import LoadingIcon from './LoadingIcon.vue';
import BButton from './BButton.vue';
export default {
components: { LoadingIcon },
components: {
BButton,
LoadingIcon
},
name: "AsyncButton",
props: {
fn: {
Expand Down Expand Up @@ -64,6 +68,11 @@ export default {
// Whether the button should show the same icon for the loading animation
type: Boolean,
default: false
},
nativeTooltip: {
// Whether to use the native browser tooltip
type: Boolean,
default: false
}
},
data() {
Expand Down
155 changes: 155 additions & 0 deletions components/internal/BButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<template>
<button ref="button" type="button" :title="nativeTitle" :disabled="disabled" :name="name" :value="value"
@click="click" @mouseover="mouseover" @mouseleave="mouseleave" @focus="focus" @blur="blur">
<slot>{{ text }}</slot>
</button>
</template>

<script>
export default {
name: "BButton",
props: {
type: {
type: String,
default: 'button'
},
text: {
type: String,
default: ""
},
title: {
type: String,
default: null
},
disabled: {
type: Boolean,
default: false
},
name: {
type: String,
default: null
},
value: {
type: String,
default: null
},
nativeTooltip: {
// Whether to use the native browser tooltip
type: Boolean,
default: false
}
},
data() {
return {
showTooltip: false,
nativeTooltip_: this.nativeTooltip,
element: null,
container: null
};
},
mounted() {
this.container = document.getElementsByName('body')[0];
if (!this.container) {
this.container = this.$refs.button.parentNode;
if (!this.container) {
this.nativeTooltip_ = true;
}
}
},
beforeDestroy() {
this.removeTooltip();
},
computed: {
nativeTitle() {
return this.nativeTooltip_ ? this.title : null;
}
},
watch: {
nativeTooltip(newValue) {
this.nativeTooltip_ = newValue;
},
showTooltip(newValue) {
if (this.nativeTooltip_) {
return;
}
if (newValue) {
this.createTooltip();
}
else {
this.removeTooltip();
}
}
},
methods: {
createTooltip() {
if (!this.container) {
return;
}
if (this.element) {
this.removeTooltip();
}
this.element = document.createElement('div');
this.element.className = 'openeo-vue-tooltip';
this.element.innerText = this.title;
this.container.appendChild(this.element);
this.updateTooltip();
},
updateTooltip() {
if (!this.element) {
return;
}
const el = this.$refs.button;
const pos = el.getBoundingClientRect();
this.element.style.top = Math.max(0, (pos.top + el.offsetHeight)) + 1 + 'px';
this.element.style.left = Math.max(0, (pos.left + (el.offsetWidth / 2) - (this.element.offsetWidth / 2))) + 1 + 'px';
},
removeTooltip() {
if (!this.container || !this.element) {
return;
}
document.removeEventListener('scroll', this.removeTooltip);
if (this.container.contains(this.element)) {
this.container.removeChild(this.element);
}
},
click(event) {
this.$emit('click', event);
},
mousemove(event) {
this.updateTooltip();
this.$emit('mousemove', event);
},
mouseover(event) {
this.showTooltip = true;
this.$emit('mouseover', event);
},
mouseleave(event) {
this.showTooltip = false;
this.$emit('mouseleave', event);
},
focus(event) {
this.showTooltip = true;
this.$emit('focus', event);
},
blur(event) {
this.showTooltip = false;
this.$emit('blur', event);
}
}
}
</script>

<style lang="scss">
.openeo-vue-tooltip {
display: inline-block;
position: absolute;
background-color: #333;
color: white;
padding: 5px;
border-radius: 5px;
z-index: 1000;
font-size: 0.9em;
border: 1px solid #000;
text-align: center;
}
</style>
2 changes: 2 additions & 0 deletions dev/Examples.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<script>
import EXAMPLES from './examples';
import BButton from '../components/internal/BButton.vue';
import BillingPlans from '../components/BillingPlans.vue';
import Capabilities from '../components/Capabilities.vue';
import Collection from '../components/Collection.vue';
Expand Down Expand Up @@ -57,6 +58,7 @@ import UdfRuntimes from '../components/UdfRuntimes.vue';
export default {
name: 'Examples',
components: {
BButton,
BillingPlans,
Capabilities,
Collection,
Expand Down
6 changes: 6 additions & 0 deletions dev/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ let asyncFn = () => new Promise(resolve => setTimeout(() => {
}, 3000))

module.exports = {
"b-button": {
"example": {
"title": "This is a test tooltip!",
"text": "i"
}
},
"billing-plans": {
"api": {
"billing": capabilities.billing
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openeo/vue-components",
"version": "2.18.1",
"version": "2.18.2",
"author": "openEO Consortium",
"contributors": [
{
Expand Down

0 comments on commit c547483

Please sign in to comment.