2022-09-09 20:41:18 +00:00
< template >
2022-12-12 20:26:59 +00:00
< ClientOnly
> < AppDoc name = "RatingDemo" :sources ="sources" github = "rating/RatingDemo.vue" >
< h5 > Import via Module < / h5 >
< pre v -code .script > < code >
2022-09-09 20:41:18 +00:00
import Rating from 'primevue/rating' ;
< / code > < / pre >
2022-12-12 20:26:59 +00:00
< h5 > Import via CDN < / h5 >
< pre v-code > < code >
2022-09-09 20:41:18 +00:00
& lt ; script src = "https://unpkg.com/primevue@^3/core/core.min.js" & gt ; & lt ; / s c r i p t & g t ;
& lt ; script src = "https://unpkg.com/primevue@^3/rating/rating.min.js" & gt ; & lt ; / s c r i p t & g t ;
< / code > < / pre >
2022-12-12 20:26:59 +00:00
< h5 > Getting Started < / h5 >
< p > Two - way value binding is defined using v - model . < / p >
< pre v-code > < code >
2022-09-09 20:41:18 +00:00
& lt ; Rating v - model = "val" / & gt ;
< / code > < / pre >
2022-12-12 20:26:59 +00:00
< h5 > Number of Stars < / h5 >
< p > Number of stars to display is defined with < i > stars < / i > property , default is 5. < / p >
< pre v-code > < code >
2022-09-09 20:41:18 +00:00
& lt ; Rating v - model = "val" : stars = "7" / & gt ;
< / code > < / pre >
2022-12-12 20:26:59 +00:00
< h5 > Cancel < / h5 >
< p > A cancel icon is displayed to reset the value by default , set < i > cancel < / i > as false to remove this option . < / p >
< pre v-code > < code >
2022-09-09 20:41:18 +00:00
& lt ; Rating v - model = "val" : cancel = "false" / & gt ;
< / code > < / pre >
2022-12-12 20:26:59 +00:00
< h5 > Templating < / h5 >
< p > Templating allows customizing the content where the icon instance is available as the implicit variable . < / p >
< pre v-code > < code > < template v-pre >
2022-12-08 12:26:57 +00:00
& lt ; Rating : modelValue = "3" >
& lt ; template # cancelicon & gt ;
2022-12-09 07:52:51 +00:00
& lt ; img src = "/demo/images/rating/cancel.png" height = "24" width = "24" & gt ;
2022-12-08 12:26:57 +00:00
& lt ; / t e m p l a t e & g t ;
& lt ; template # onicon & gt ;
2022-12-09 07:52:51 +00:00
& lt ; img src = "/demo/images/rating/custom-onicon.png" height = "24" width = "24" & gt ;
2022-12-08 12:26:57 +00:00
& lt ; / t e m p l a t e & g t ;
& lt ; template # officon & gt ;
2022-12-09 07:52:51 +00:00
& lt ; img src = "/demo/images/rating/custom-officon.png" height = "24" width = "24" & gt ;
2022-12-08 12:26:57 +00:00
& lt ; / t e m p l a t e & g t ;
& lt ; / R a t i n g & g t ;
< / template >
< / code > < / pre >
2022-12-12 20:26:59 +00:00
< h5 > Properties < / h5 >
< p > Any property as style and class are passed to the main container element . Following are the additional properties to configure the component . < / p >
< div class = "doc-tablewrapper" >
< table class = "doc-table" >
< thead >
< tr >
< th > Name < / th >
< th > Type < / th >
< th > Default < / th >
< th > Description < / th >
< / tr >
< / thead >
< tbody >
< tr >
< td > modelValue < / td >
< td > number < / td >
< td > null < / td >
< td > Value of the rating . < / td >
< / tr >
< tr >
< td > disabled < / td >
< td > boolean < / td >
< td > false < / td >
< td > When present , it specifies that the element should be disabled . < / td >
< / tr >
< tr >
< td > readonly < / td >
< td > boolean < / td >
< td > false < / td >
< td > When present , it specifies that component is read - only . < / td >
< / tr >
< tr >
< td > stars < / td >
< td > number < / td >
< td > 5 < / td >
< td > Number of stars . < / td >
< / tr >
< tr >
< td > cancel < / td >
< td > boolean < / td >
< td > true < / td >
< td > When specified a cancel icon is displayed to allow clearing the value . < / td >
< / tr >
< tr >
< td > onIcon < / td >
< td > string < / td >
< td > pi pi - star < / td >
< td > Icon for the on state . < / td >
< / tr >
< tr >
< td > offIcon < / td >
< td > string < / td >
< td > pi pi - star - fill < / td >
< td > Icon for the off state . < / td >
< / tr >
< tr >
< td > cancelIcon < / td >
< td > string < / td >
< td > pi pi - ban < / td >
< td > Icon for the cancelable state . < / td >
< / tr >
< / tbody >
< / table >
< / div >
2022-12-08 12:26:57 +00:00
2022-12-12 20:26:59 +00:00
< h5 > Events < / h5 >
< div class = "doc-tablewrapper" >
< table class = "doc-table" >
< thead >
< tr >
< th > Name < / th >
< th > Parameters < / th >
< th > Description < / th >
< / tr >
< / thead >
< tbody >
< tr >
< td > change < / td >
< td >
event . originalEvent : Original event < br / >
event . value : Selected option value
< / td >
< td > Callback to invoke on value change . < / td >
< / tr >
< tr >
< td > focus < / td >
< td > event < / td >
< td > Callback to invoke when the component receives focus . < / td >
< / tr >
< tr >
< td > blur < / td >
< td > event < / td >
< td > Callback to invoke when the component loses focus . < / td >
< / tr >
< / tbody >
< / table >
< / div >
2022-12-08 12:26:57 +00:00
2022-12-12 20:26:59 +00:00
< h5 > Slots < / h5 >
< div class = "doc-tablewrapper" >
< table class = "doc-table" >
< thead >
< tr >
< th > Name < / th >
< th > Parameters < / th >
< / tr >
< / thead >
< tbody >
< tr >
< td > cancelicon < / td >
< td > - < / td >
< / tr >
< tr >
< td > onicon < / td >
< td > value : Item value < / td >
< / tr >
< tr >
< td > officon < / td >
< td > value : Item value < / td >
< / tr >
< / tbody >
< / table >
< / div >
2022-12-08 12:26:57 +00:00
2022-12-12 20:26:59 +00:00
< h5 > Styling < / h5 >
< p > Following is the list of structural style classes , for theming classes visit < router -link to = "/theming" > theming < / r o u t e r - l i n k > p a g e . < / p >
< div class = "doc-tablewrapper" >
< table class = "doc-table" >
< thead >
< tr >
< th > Name < / th >
< th > Element < / th >
< / tr >
< / thead >
< tbody >
< tr >
< td > p - rating < / td >
< td > Container element < / td >
< / tr >
< tr >
< td > p - rating - item < / td >
< td > Each item element < / td >
< / tr >
< tr >
< td > p - rating - item - active < / td >
< td > Selected item elements . < / td >
< / tr >
< tr >
< td > p - rating - cancel - item < / td >
< td > Cancel item element . < / td >
< / tr >
< / tbody >
< / table >
< / div >
2022-12-08 12:26:57 +00:00
2022-12-12 20:26:59 +00:00
< h5 > Accessibility < / h5 >
< h6 > Screen Reader < / h6 >
< p >
Rating component internally uses radio buttons that are only visible to screen readers . The value to read for item is retrieved from the < router -link to = "/locale" > locale < /router-link> API via <i>star</i > and < i > stars < / i > of the
< i > aria < / i > property .
< / p >
2022-12-08 12:26:57 +00:00
2022-12-12 20:26:59 +00:00
< h6 > Keyboard Support < / h6 >
< p > Keyboard interaction is derived from the native browser handling of radio buttons in a group . < / p >
< div class = "doc-tablewrapper" >
< table class = "doc-table" >
< thead >
< tr >
< th > Key < / th >
< th > Function < / th >
< / tr >
< / thead >
< tbody >
< tr >
< td > < i > tab < / i > < / td >
< td > Moves focus to the star representing the value , if there is none then first star receives the focus . < / td >
< / tr >
< tr >
< td >
< span class = "inline-flex flex-column" >
< i class = "mb-1" > left arrow < / i >
< i > up arrow < / i >
< / span >
< / td >
< td > Moves focus to the previous star , if there is none then last radio button receives the focus . < / td >
< / tr >
< tr >
< td >
< span class = "inline-flex flex-column" >
< i class = "mb-1" > right arrow < / i >
< i > down arrow < / i >
< / span >
< / td >
< td > Moves focus to the next star , if there is none then first star receives the focus . < / td >
< / tr >
< tr >
< td > < i > space < / i > < / td >
< td > If the focused star does not represent the value , changes the value to the star value . < / td >
< / tr >
< / tbody >
< / table >
< / div >
2022-12-08 12:26:57 +00:00
2022-12-12 20:26:59 +00:00
< h5 > Dependencies < / h5 >
< p > None . < / p >
< / AppDoc > < / C l i e n t O n l y
>
2022-09-09 20:41:18 +00:00
< / template >
< script >
export default {
data ( ) {
return {
sources : {
'options-api' : {
tabName : 'Options API Source' ,
content : `
< template >
< div >
< h5 > Basic { { val1 } } < / h5 >
2022-12-08 12:26:57 +00:00
< Rating v -model = " val1 " / >
2022-09-09 20:41:18 +00:00
< h5 > Without Cancel < / h5 >
2022-12-08 12:26:57 +00:00
< Rating v -model = " val2 " :cancel ="false" / >
2022-09-09 20:41:18 +00:00
< h5 > ReadOnly < / h5 >
2022-12-08 12:26:57 +00:00
< Rating :modelValue ="5" :readonly ="true" :stars ="10" :cancel ="false" / >
2022-09-09 20:41:18 +00:00
< h5 > Disabled < / h5 >
2022-12-08 12:26:57 +00:00
< Rating :modelValue ="8" :disabled ="true" :stars ="10" / >
< h5 > Custom Icons < / h5 >
< Rating v -model = " val3 " :stars ="5" onIcon = "pi pi-heart-fill" offIcon = "pi pi-heart" cancelIcon = "pi pi-times" / >
< h5 > Templating < / h5 >
< Rating v-model ="val4" >
< template # cancelicon >
2022-12-09 07:52:51 +00:00
< img src = "/demo/images/rating/cancel.png" @ error = "(e) => e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'" height = "24" width = "24" / >
2022-12-08 12:26:57 +00:00
< / template >
< template # onicon >
2022-12-09 07:52:51 +00:00
< img src = "/demo/images/rating/custom-onicon.png" @ error = "(e) => e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'" height = "24" width = "24" / >
2022-12-08 12:26:57 +00:00
< / template >
< template # officon >
2022-12-09 07:52:51 +00:00
< img src = "/demo/images/rating/custom-officon.png" @ error = "(e) => e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'" height = "24" width = "24" / >
2022-12-08 12:26:57 +00:00
< / template >
< / Rating >
2022-09-09 20:41:18 +00:00
< / div >
< / template >
< script >
export default {
data ( ) {
return {
val1 : null ,
val2 : 3 ,
2022-12-08 12:26:57 +00:00
val3 : 2 ,
val4 : 2
2022-09-09 20:41:18 +00:00
}
}
}
< \ \ / script >
2022-12-08 12:26:57 +00:00
2022-09-09 20:41:18 +00:00
`
} ,
'composition-api' : {
tabName : 'Composition API Source' ,
content : `
< template >
< div >
< h5 > Basic { { val1 } } < / h5 >
2022-12-08 12:26:57 +00:00
< Rating v -model = " val1 " / >
2022-09-09 20:41:18 +00:00
< h5 > Without Cancel < / h5 >
2022-12-08 12:26:57 +00:00
< Rating v -model = " val2 " :cancel ="false" / >
2022-09-09 20:41:18 +00:00
< h5 > ReadOnly < / h5 >
2022-12-08 12:26:57 +00:00
< Rating :modelValue ="5" :readonly ="true" :stars ="10" :cancel ="false" / >
2022-09-09 20:41:18 +00:00
< h5 > Disabled < / h5 >
2022-12-08 12:26:57 +00:00
< Rating :modelValue ="8" :disabled ="true" :stars ="10" / >
< h5 > Custom Icons < / h5 >
< Rating v -model = " val3 " :stars ="5" onIcon = "pi pi-heart-fill" offIcon = "pi pi-heart" cancelIcon = "pi pi-times" / >
< h5 > Templating < / h5 >
< Rating v-model ="val4" >
< template # cancelicon >
2022-12-09 07:52:51 +00:00
< img src = "/demo/images/rating/cancel.png" @ error = "(e) => e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'" height = "24" width = "24" / >
2022-12-08 12:26:57 +00:00
< / template >
< template # onicon >
2022-12-09 07:52:51 +00:00
< img src = "/demo/images/rating/custom-onicon.png" @ error = "(e) => e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'" height = "24" width = "24" / >
2022-12-08 12:26:57 +00:00
< / template >
< template # officon >
2022-12-09 07:52:51 +00:00
< img src = "/demo/images/rating/custom-officon.png" @ error = "(e) => e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'" height = "24" width = "24" / >
2022-12-08 12:26:57 +00:00
< / template >
< / Rating >
2022-09-09 20:41:18 +00:00
< / div >
< / template >
< script >
import { ref } from 'vue' ;
export default {
setup ( ) {
const val1 = ref ( ) ;
const val2 = ref ( 3 ) ;
2022-12-08 12:26:57 +00:00
const val3 = ref ( 2 ) ;
const val4 = ref ( 2 ) ;
2022-09-09 20:41:18 +00:00
return { val1 , val2 }
}
}
< \ \ / script >
2022-12-08 12:26:57 +00:00
2022-09-09 20:41:18 +00:00
`
} ,
'browser-source' : {
tabName : 'Browser Source' ,
imports : ` <script src="https://unpkg.com/primevue@^3/rating/rating.min.js">< \\ /script> ` ,
content : ` <div id="app">
< h5 > Basic { { val1 } } < / h5 >
2022-12-08 12:26:57 +00:00
< p -rating v-model ="val1" > < / p -rating >
2022-09-09 20:41:18 +00:00
< h5 > Without Cancel < / h5 >
2022-12-08 12:26:57 +00:00
< p -rating v-model ="val2" :cancel ="false" > < / p -rating >
2022-09-09 20:41:18 +00:00
< h5 > ReadOnly < / h5 >
2022-12-08 12:26:57 +00:00
< p -rating :modelValue ="5" :readonly ="true" :stars ="10" :cancel ="false" > < / p - r a t i n g >
2022-09-09 20:41:18 +00:00
< h5 > Disabled < / h5 >
2022-12-08 12:26:57 +00:00
< p -rating :modelValue ="8" :disabled ="true" :stars ="10" > < / p - r a t i n g >
< h5 > Custom Icons < / h5 >
< p -rating v-model ="val3" :stars="5" on-icon="pi pi-heart-fill" off-icon="pi pi-heart" cancel-icon="pi pi-times" > < / p -rating >
< h5 > Templating < / h5 >
< p -rating v-model ="val4" >
< template # cancelicon >
2022-12-09 07:52:51 +00:00
< img src = "/demo/images/rating/cancel.png" @ error = "(e) => e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'" height = "24" width = "24" / >
2022-12-08 12:26:57 +00:00
< / template >
< template # onicon >
2022-12-09 07:52:51 +00:00
< img src = "/demo/images/rating/custom-onicon.png" @ error = "(e) => e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'" height = "24" width = "24" / >
2022-12-08 12:26:57 +00:00
< / template >
< template # officon >
2022-12-09 07:52:51 +00:00
< img src = "/demo/images/rating/custom-officon.png" @ error = "(e) => e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'" height = "24" width = "24" / >
2022-12-08 12:26:57 +00:00
< / template >
< / p - r a t i n g >
2022-09-09 20:41:18 +00:00
< / div >
< script type = "module" >
const { createApp , ref } = Vue ;
const App = {
setup ( ) {
const val1 = ref ( ) ;
const val2 = ref ( 3 ) ;
2022-12-08 12:26:57 +00:00
const val3 = ref ( 2 ) ;
const val4 = ref ( 2 ) ;
2022-09-09 20:41:18 +00:00
return { val1 , val2 }
} ,
components : {
"p-rating" : primevue . rating
}
} ;
createApp ( App )
. use ( primevue . config . default )
. mount ( "#app" ) ;
< \ \ / script >
2022-12-08 12:26:57 +00:00
2022-09-09 20:41:18 +00:00
`
}
}
} ;
}
} ;
< / script >