Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrating base-rating component using defineComponent sintax #1419

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 46 additions & 42 deletions packages/x-components/src/components/base-rating.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
</template>

<script lang="ts">
import Vue from 'vue';
import { Component, Prop } from 'vue-property-decorator';
import { defineComponent } from 'vue';
import StarIcon from './icons/star.vue';

/**
Expand All @@ -34,49 +33,54 @@
*
* @public
*/
@Component({
export default defineComponent({
name: 'BaseRating',
components: {
DefaultIcon: StarIcon
},
props: {
/**
* Numeric value used to calculates the width of the filled elements.
*
* @public
*/
value: {
type: Number,
required: true
},
/**
* Maximum number of elements to paint.
*
* @public
*/
max: {
type: Number,
default: 5
}
},
computed: {
/**
* Calculates the width of the filled elements wrapper.
*
* @returns The % of the wrapper width.
*
* @internal
*/
calculateFilledWrapperWidth(): string {
return this.value < 0 ? '0%' : `${(this.value * 100) / this.max}%`;
},
/**
* Creates the aria label for accessibility purpose.
*
* @returns The aria label.
*
* @internal
*/
ariaLabel(): string {
return `${this.value}/${this.max}`;
}
}
})
export default class BaseRating extends Vue {
/**
* Numeric value used to calculates the width of the filled elements.
*
* @public
*/
@Prop({ required: true })
protected value!: number;
/**
* Maximum number of elements to paint.
*
* @public
*/
@Prop({ default: 5 })
protected max!: number;

/**
* Calculates the width of the filled elements wrapper.
*
* @returns The % of the wrapper width.
*
* @internal
*/
protected get calculateFilledWrapperWidth(): string {
return this.value < 0 ? '0%' : `${(this.value * 100) / this.max}%`;
}

/**
* Creates the aria label for accessibility purpose.
*
* @returns The aria label.
*
* @internal
*/
protected get ariaLabel(): string {
return `${this.value}/${this.max}`;
}
}
});
</script>

<style lang="scss" scoped>
Expand Down
Loading