Refactor #3922 - For Rating
parent
9d9f568ce9
commit
510d4b2918
|
@ -10,6 +10,84 @@
|
|||
import { VNode } from 'vue';
|
||||
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
|
||||
|
||||
export declare type RatingPassThroughOptionType = RatingPassThroughAttributes | ((options: RatingPassThroughMethodOptions) => RatingPassThroughAttributes) | null | undefined;
|
||||
|
||||
/**
|
||||
* Custom passthrough(pt) option method.
|
||||
*/
|
||||
export interface RatingPassThroughMethodOptions {
|
||||
props: RatingProps;
|
||||
state: RatingState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom passthrough(pt) options.
|
||||
* @see {@link RatingProps.pt}
|
||||
*/
|
||||
export interface RatingPassThroughOptions {
|
||||
/**
|
||||
* Uses to pass attributes to the root's DOM element.
|
||||
*/
|
||||
root?: RatingPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the cancel item's DOM element.
|
||||
*/
|
||||
cancelItem?: RatingPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the input aria's DOM element.
|
||||
*/
|
||||
cancelInputAria?: RatingPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the cancel input's DOM element.
|
||||
*/
|
||||
cancelInput?: RatingPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the cancel icon's DOM element.
|
||||
*/
|
||||
cancelIcon?: RatingPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the item's DOM element.
|
||||
*/
|
||||
item?: RatingPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the item input aria's DOM element.
|
||||
*/
|
||||
itemInputAria?: RatingPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the item input's DOM element.
|
||||
*/
|
||||
itemInput?: RatingPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the on icon's DOM element.
|
||||
*/
|
||||
onIcon?: RatingPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the off icon's DOM element.
|
||||
*/
|
||||
offIcon?: RatingPassThroughOptionType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom passthrough attributes for each DOM elements
|
||||
*/
|
||||
export interface RatingPassThroughAttributes {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines current inline state in Rating component.
|
||||
*/
|
||||
export interface RatingState {
|
||||
/**
|
||||
* name state as a number.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* focusedOptionIndex state as a number.
|
||||
*/
|
||||
focusedOptionIndex: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom change event.
|
||||
* @see {@link RatingEmits.change}
|
||||
|
@ -72,6 +150,11 @@ export interface RatingProps {
|
|||
* @deprecated since v3.27.0. Use 'cancelicon' slot.
|
||||
*/
|
||||
cancelIcon?: string | undefined;
|
||||
/**
|
||||
* Uses to pass attributes to DOM elements inside the component.
|
||||
* @type {RatingPassThroughOptions}
|
||||
*/
|
||||
pt?: RatingPassThroughOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,16 +1,28 @@
|
|||
<template>
|
||||
<div :class="containerClass">
|
||||
<div v-if="cancel" :class="['p-rating-item p-rating-cancel-item', { 'p-focus': focusedOptionIndex === 0 }]" @click="onOptionClick($event, 0)">
|
||||
<span class="p-hidden-accessible">
|
||||
<input type="radio" value="0" :name="name" :checked="modelValue === 0" :disabled="disabled" :readonly="readonly" :aria-label="cancelAriaLabel()" @focus="onFocus($event, 0)" @blur="onBlur" @change="onChange($event, 0)" />
|
||||
<div :class="containerClass" v-bind="ptm('root')">
|
||||
<div v-if="cancel" :class="['p-rating-item p-rating-cancel-item', { 'p-focus': focusedOptionIndex === 0 }]" @click="onOptionClick($event, 0)" v-bind="ptm('cancelItem')">
|
||||
<span class="p-hidden-accessible" v-bind="ptm('cancelInputAria')">
|
||||
<input
|
||||
type="radio"
|
||||
value="0"
|
||||
:name="name"
|
||||
:checked="modelValue === 0"
|
||||
:disabled="disabled"
|
||||
:readonly="readonly"
|
||||
:aria-label="cancelAriaLabel()"
|
||||
@focus="onFocus($event, 0)"
|
||||
@blur="onBlur"
|
||||
@change="onChange($event, 0)"
|
||||
v-bind="ptm('cancelInput')"
|
||||
/>
|
||||
</span>
|
||||
<slot name="cancelicon">
|
||||
<component :is="cancelIcon ? 'span' : 'BanIcon'" :class="['p-rating-icon p-rating-cancel', cancelIcon]" />
|
||||
<component :is="cancelIcon ? 'span' : 'BanIcon'" :class="['p-rating-icon p-rating-cancel', cancelIcon]" v-bind="ptm('cancelIcon')" />
|
||||
</slot>
|
||||
</div>
|
||||
<template v-for="value in stars" :key="value">
|
||||
<div :class="['p-rating-item', { 'p-rating-item-active': value <= modelValue, 'p-focus': value === focusedOptionIndex }]" @click="onOptionClick($event, value)">
|
||||
<span class="p-hidden-accessible">
|
||||
<div :class="['p-rating-item', { 'p-rating-item-active': value <= modelValue, 'p-focus': value === focusedOptionIndex }]" @click="onOptionClick($event, value)" v-bind="ptm('item')">
|
||||
<span class="p-hidden-accessible" v-bind="ptm('itemInputAria')">
|
||||
<input
|
||||
type="radio"
|
||||
:value="value"
|
||||
|
@ -22,13 +34,14 @@
|
|||
@focus="onFocus($event, value)"
|
||||
@blur="onBlur"
|
||||
@change="onChange($event, value)"
|
||||
v-bind="ptm('itemInput')"
|
||||
/>
|
||||
</span>
|
||||
<slot v-if="value <= modelValue" name="onicon" :value="value">
|
||||
<component :is="onIcon ? 'span' : 'StarFillIcon'" :class="['p-rating-icon', onIcon]" />
|
||||
<component :is="onIcon ? 'span' : 'StarFillIcon'" :class="['p-rating-icon', onIcon]" v-bind="ptm('onIcon')" />
|
||||
</slot>
|
||||
<slot v-else name="officon" :value="value">
|
||||
<component :is="onIcon ? 'span' : 'StarIcon'" :class="['p-rating-icon', offIcon]" />
|
||||
<component :is="onIcon ? 'span' : 'StarIcon'" :class="['p-rating-icon', offIcon]" v-bind="ptm('offIcon')" />
|
||||
</slot>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -36,6 +49,7 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import BaseComponent from 'primevue/basecomponent';
|
||||
import BanIcon from 'primevue/icons/ban';
|
||||
import StarIcon from 'primevue/icons/star';
|
||||
import StarFillIcon from 'primevue/icons/starfill';
|
||||
|
@ -43,6 +57,7 @@ import { DomHandler, UniqueComponentId } from 'primevue/utils';
|
|||
|
||||
export default {
|
||||
name: 'Rating',
|
||||
extends: BaseComponent,
|
||||
emits: ['update:modelValue', 'change', 'focus', 'blur'],
|
||||
props: {
|
||||
modelValue: {
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
<template>
|
||||
<DocSectionText v-bind="$attrs"> </DocSectionText>
|
||||
<div class="card flex justify-content-center">
|
||||
<Rating v-model="value" />
|
||||
</div>
|
||||
<DocSectionCode :code="code" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
value: null,
|
||||
code: {
|
||||
basic: `
|
||||
<Rating v-model="value" />`,
|
||||
options: `
|
||||
<template>
|
||||
<div class="card flex justify-content-center">
|
||||
<Rating v-model="value" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
value: null
|
||||
}
|
||||
}
|
||||
};
|
||||
<\/script>`,
|
||||
composition: `
|
||||
<template>
|
||||
<div class="card flex justify-content-center">
|
||||
<Rating v-model="value" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
|
||||
const value = ref(null);
|
||||
<\/script>`
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
|
@ -0,0 +1,8 @@
|
|||
<template>
|
||||
<DocSectionText v-bind="$attrs">
|
||||
<p>{{ $attrs.description }}</p>
|
||||
</DocSectionText>
|
||||
<div class="card">
|
||||
<img class="w-full" src="https://primefaces.org/cdn/primevue/images/pt/wireframe-placeholder.jpg" />
|
||||
</div>
|
||||
</template>
|
|
@ -0,0 +1,41 @@
|
|||
<template>
|
||||
<div class="doc-main">
|
||||
<div class="doc-intro">
|
||||
<h1>Rating Pass Through</h1>
|
||||
</div>
|
||||
<DocSections :docs="docs" />
|
||||
</div>
|
||||
<DocSectionNav :docs="docs" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import DocApiTable from '@/components/doc/DocApiTable.vue';
|
||||
import { getPTOption } from '@/components/doc/helpers/PTHelper.js';
|
||||
import PtDoc from './PTDoc.vue';
|
||||
import PTImage from './PTImage.vue';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
docs: [
|
||||
{
|
||||
id: 'pt.image',
|
||||
label: 'Wireframe',
|
||||
component: PTImage
|
||||
},
|
||||
{
|
||||
id: 'pt.doc.steps',
|
||||
label: 'Rating PT Options',
|
||||
component: DocApiTable,
|
||||
data: getPTOption('Rating')
|
||||
},
|
||||
{
|
||||
id: 'pt.demo',
|
||||
label: 'Demo',
|
||||
component: PtDoc
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<DocComponent title="Vue Rating Component" header="Rating" description="Rating component is a star based selection input." :componentDocs="docs" :apiDocs="['Rating']" />
|
||||
<DocComponent title="Vue Rating Component" header="Rating" description="Rating component is a star based selection input." :componentDocs="docs" :apiDocs="['Rating']" :ptTabComponent="ptComponent" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
@ -12,6 +12,7 @@ import ReadOnlyDoc from '@/doc/rating/ReadOnlyDoc.vue';
|
|||
import StyleDoc from '@/doc/rating/StyleDoc.vue';
|
||||
import TemplateDoc from '@/doc/rating/TemplateDoc.vue';
|
||||
import WithoutCancelDoc from '@/doc/rating/WithoutCancelDoc.vue';
|
||||
import PTComponent from '@/doc/rating/pt/index.vue';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
|
@ -62,7 +63,8 @@ export default {
|
|||
label: 'Accessibility',
|
||||
component: AccessibilityDoc
|
||||
}
|
||||
]
|
||||
],
|
||||
ptComponent: PTComponent
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue