Refactor #3832 - For Accordion

pull/3841/head
mertsincan 2023-04-03 09:27:59 +01:00
parent 72db159a9d
commit 4a33a1cec4
3 changed files with 12 additions and 10 deletions

View File

@ -20,13 +20,13 @@ const AccordionProps = [
{ {
name: 'expandIcon', name: 'expandIcon',
type: 'string', type: 'string',
default: 'pi-chevron-right', default: 'null',
description: 'Icon of a collapsed tab.' description: 'Icon of a collapsed tab.'
}, },
{ {
name: 'collapseIcon', name: 'collapseIcon',
type: 'string', type: 'string',
default: 'pi-chevron-down', default: 'null',
description: 'Icon of a expanded tab.' description: 'Icon of a expanded tab.'
}, },
{ {

View File

@ -102,12 +102,10 @@ export interface AccordionProps {
lazy?: boolean | undefined; lazy?: boolean | undefined;
/** /**
* Icon of a collapsed tab. * Icon of a collapsed tab.
* @defaultValue pi pi-chevron-right
*/ */
expandIcon?: string | undefined; expandIcon?: string | undefined;
/** /**
* Icon of an expanded tab. * Icon of an expanded tab.
* @defaultValue pi pi-chevron-down
*/ */
collapseIcon?: string | undefined; collapseIcon?: string | undefined;
/** /**

View File

@ -15,7 +15,8 @@
v-bind="{ ...getTabProp(tab, 'headeractionprops'), ...getTabPT(tab, 'headeraction') }" v-bind="{ ...getTabProp(tab, 'headeractionprops'), ...getTabPT(tab, 'headeraction') }"
> >
<component v-if="tab.children && tab.children.headericon" :is="tab.children.headericon" :isTabActive="isTabActive(i)" :index="i"></component> <component v-if="tab.children && tab.children.headericon" :is="tab.children.headericon" :isTabActive="isTabActive(i)" :index="i"></component>
<span v-else :class="getTabHeaderIconClass(i)" aria-hidden="true" v-bind="getTabPT(tab, 'headericon')"></span> <component v-else-if="isTabActive(i)" :is="collapseIcon ? 'span' : 'ChevronDownIcon'" :class="['p-accordion-toggle-icon', collapseIcon]" aria-hidden="true" v-bind="getTabPT(tab, 'headericon')" />
<component v-else :is="expandIcon ? 'span' : 'ChevronRightIcon'" :class="['p-accordion-toggle-icon', expandIcon]" aria-hidden="true" v-bind="getTabPT(tab, 'headericon')" />
<span v-if="tab.props && tab.props.header" class="p-accordion-header-text" v-bind="getTabPT(tab, 'headertitle')">{{ tab.props.header }}</span> <span v-if="tab.props && tab.props.header" class="p-accordion-header-text" v-bind="getTabPT(tab, 'headertitle')">{{ tab.props.header }}</span>
<component v-if="tab.children && tab.children.header" :is="tab.children.header"></component> <component v-if="tab.children && tab.children.header" :is="tab.children.header"></component>
</a> </a>
@ -42,6 +43,8 @@
<script> <script>
import BaseComponent from 'primevue/basecomponent'; import BaseComponent from 'primevue/basecomponent';
import ChevronDownIcon from 'primevue/icon/chevrondown';
import ChevronRightIcon from 'primevue/icon/chevronright';
import Ripple from 'primevue/ripple'; import Ripple from 'primevue/ripple';
import { DomHandler, UniqueComponentId } from 'primevue/utils'; import { DomHandler, UniqueComponentId } from 'primevue/utils';
@ -64,11 +67,11 @@ export default {
}, },
expandIcon: { expandIcon: {
type: String, type: String,
default: 'pi pi-chevron-right' default: undefined
}, },
collapseIcon: { collapseIcon: {
type: String, type: String,
default: 'pi pi-chevron-down' default: undefined
}, },
tabindex: { tabindex: {
type: Number, type: Number,
@ -252,9 +255,6 @@ export default {
} }
]; ];
}, },
getTabHeaderIconClass(i) {
return ['p-accordion-toggle-icon', this.isTabActive(i) ? this.collapseIcon : this.expandIcon];
},
getTabContentClass(tab) { getTabContentClass(tab) {
return ['p-toggleable-content', this.getTabProp(tab, 'contentClass')]; return ['p-toggleable-content', this.getTabProp(tab, 'contentClass')];
} }
@ -276,6 +276,10 @@ export default {
}, []); }, []);
} }
}, },
components: {
ChevronDownIcon,
ChevronRightIcon
},
directives: { directives: {
ripple: Ripple ripple: Ripple
} }