From 97e27ad77a8e540aa242df87a59901177f03bc48 Mon Sep 17 00:00:00 2001 From: Mert Sincan Date: Fri, 18 Oct 2024 16:57:59 +0100 Subject: [PATCH] Add form support to `Rating` --- packages/primevue/src/rating/BaseRating.vue | 12 ++----- packages/primevue/src/rating/Rating.vue | 33 ++++++++++--------- .../primevue/src/rating/style/RatingStyle.js | 22 ++++++++++--- 3 files changed, 37 insertions(+), 30 deletions(-) diff --git a/packages/primevue/src/rating/BaseRating.vue b/packages/primevue/src/rating/BaseRating.vue index b2ac1890d..09e822ea5 100644 --- a/packages/primevue/src/rating/BaseRating.vue +++ b/packages/primevue/src/rating/BaseRating.vue @@ -1,19 +1,11 @@ diff --git a/packages/primevue/src/rating/style/RatingStyle.js b/packages/primevue/src/rating/style/RatingStyle.js index 21497887c..5a7ced729 100644 --- a/packages/primevue/src/rating/style/RatingStyle.js +++ b/packages/primevue/src/rating/style/RatingStyle.js @@ -43,6 +43,10 @@ const theme = ({ dt }) => ` .p-rating-option-active .p-rating-icon { color: ${dt('rating.icon.active.color')}; } + +.p-rating-icon.p-invalid { /* @todo */ + stroke: ${dt('rating.invalid.icon.color')}; +} `; const classes = { @@ -53,15 +57,25 @@ const classes = { 'p-disabled': props.disabled } ], - option: ({ instance, props, value }) => [ + option: ({ instance, value }) => [ 'p-rating-option', { - 'p-rating-option-active': value <= props.modelValue, + 'p-rating-option-active': value <= instance.d_value, 'p-focus-visible': value === instance.focusedOptionIndex && instance.isFocusVisibleItem } ], - onIcon: 'p-rating-icon p-rating-on-icon', - offIcon: 'p-rating-icon p-rating-off-icon' + onIcon: ({ instance }) => [ + 'p-rating-icon p-rating-on-icon', + { + 'p-invalid': instance.$invalid + } + ], + offIcon: ({ instance }) => [ + 'p-rating-icon p-rating-off-icon', + { + 'p-invalid': instance.$invalid + } + ] }; export default BaseStyle.extend({