mirror of
https://github.com/primefaces/primevue.git
synced 2025-05-09 00:42:36 +00:00
Fixed #5643 - Reimplement: Accordion
This commit is contained in:
parent
6cbb5e0993
commit
10f530f7b1
30 changed files with 1049 additions and 243 deletions
147
components/lib/accordioncontent/AccordionContent.d.ts
vendored
Executable file
147
components/lib/accordioncontent/AccordionContent.d.ts
vendored
Executable file
|
@ -0,0 +1,147 @@
|
|||
/**
|
||||
*
|
||||
* AccordionContent is a helper component for Accordion component.
|
||||
*
|
||||
* [Live Demo](https://www.primevue.org/accordion/)
|
||||
*
|
||||
* @module accordioncontent
|
||||
*
|
||||
*/
|
||||
import { VNode } from 'vue';
|
||||
import { ComponentHooks } from '../basecomponent';
|
||||
import { PassThroughOptions } from '../passthrough';
|
||||
import { ClassComponent, DesignToken, GlobalComponentConstructor, PassThrough } from '../ts-helpers';
|
||||
|
||||
export declare type AccordionContentPassThroughOptionType = AccordionContentPassThroughAttributes | ((options: AccordionContentPassThroughMethodOptions) => AccordionContentPassThroughAttributes | string) | string | null | undefined;
|
||||
|
||||
/**
|
||||
* Custom passthrough(pt) option method.
|
||||
*/
|
||||
export interface AccordionContentPassThroughMethodOptions {
|
||||
/**
|
||||
* Defines instance.
|
||||
*/
|
||||
instance: any;
|
||||
/**
|
||||
* Defines valid properties.
|
||||
*/
|
||||
props: AccordionContentProps;
|
||||
/**
|
||||
* Defines current options.
|
||||
*/
|
||||
context: AccordionContentContext;
|
||||
/**
|
||||
* Defines valid attributes.
|
||||
*/
|
||||
attrs: any;
|
||||
/**
|
||||
* Defines parent options.
|
||||
*/
|
||||
parent: any;
|
||||
/**
|
||||
* Defines passthrough(pt) options in global config.
|
||||
*/
|
||||
global: object | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom passthrough(pt) options.
|
||||
* @see {@link AccordionContentProps.pt}
|
||||
*/
|
||||
export interface AccordionContentPassThroughOptions {
|
||||
/**
|
||||
* Used to pass attributes to the root's DOM element.
|
||||
*/
|
||||
root?: AccordionContentPassThroughOptionType;
|
||||
/**
|
||||
* Used to pass attributes to the transition's DOM element.
|
||||
*/
|
||||
transition?: AccordionContentPassThroughOptionType;
|
||||
/**
|
||||
* Used to pass attributes to the content's DOM element.
|
||||
*/
|
||||
content?: AccordionContentPassThroughOptionType;
|
||||
/**
|
||||
* Used to manage all lifecycle hooks.
|
||||
* @see {@link BaseComponent.ComponentHooks}
|
||||
*/
|
||||
hooks?: ComponentHooks;
|
||||
}
|
||||
|
||||
export interface AccordionContentPassThroughAttributes {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines valid properties in AccordionContent component.
|
||||
*/
|
||||
export interface AccordionContentProps {
|
||||
/**
|
||||
* Use to change the HTML tag of root element.
|
||||
* @defaultValue DIV
|
||||
*/
|
||||
as?: string | undefined;
|
||||
/**
|
||||
* When enabled, it changes the default rendered element for the one passed as a child element.
|
||||
* @defaultValue false
|
||||
*/
|
||||
asChild?: boolean | undefined;
|
||||
/**
|
||||
* It generates scoped CSS variables using design tokens for the component.
|
||||
*/
|
||||
dt?: DesignToken<any>;
|
||||
/**
|
||||
* Used to pass attributes to DOM elements inside the component.
|
||||
* @type {AccordionContentPassThroughOptions}
|
||||
*/
|
||||
pt?: PassThrough<AccordionContentPassThroughOptions>;
|
||||
/**
|
||||
* Used to configure passthrough(pt) options of the component.
|
||||
* @type {PassThroughOptions}
|
||||
*/
|
||||
ptOptions?: PassThroughOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines current options in AccordionContent component.
|
||||
*/
|
||||
export interface AccordionContentContext {
|
||||
/**
|
||||
* Whether the item is active.
|
||||
*/
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines valid slots in AccordionContent slots.
|
||||
*/
|
||||
export interface AccordionContentSlots {
|
||||
/**
|
||||
* Custom content template.
|
||||
*/
|
||||
default(): VNode[];
|
||||
}
|
||||
|
||||
export interface AccordionContentEmits {}
|
||||
|
||||
/**
|
||||
* **PrimeVue - AccordionContent**
|
||||
*
|
||||
* _AccordionContent is a helper component for Accordion component._
|
||||
*
|
||||
* [Live Demo](https://www.primevue.org/accordion/)
|
||||
* --- ---
|
||||
* 
|
||||
*
|
||||
* @group Component
|
||||
*
|
||||
*/
|
||||
declare class AccordionContent extends ClassComponent<AccordionContentProps, AccordionContentSlots, AccordionContentEmits> {}
|
||||
|
||||
declare module 'vue' {
|
||||
export interface GlobalComponents {
|
||||
AccordionContent: GlobalComponentConstructor<AccordionContent>;
|
||||
}
|
||||
}
|
||||
|
||||
export default AccordionContent;
|
52
components/lib/accordioncontent/AccordionContent.vue
Executable file
52
components/lib/accordioncontent/AccordionContent.vue
Executable file
|
@ -0,0 +1,52 @@
|
|||
<template>
|
||||
<template v-if="!asChild">
|
||||
<transition name="p-toggleable-content" v-bind="ptm('transition', ptParams)">
|
||||
<component v-if="$pcAccordion.lazy ? $pcAccordionPanel.active : true" v-show="$pcAccordion.lazy ? true : $pcAccordionPanel.active" :is="as" :class="cx('root')" v-bind="attrs">
|
||||
<div :class="cx('content')" v-bind="ptm('content', ptParams)">
|
||||
<slot></slot>
|
||||
</div>
|
||||
</component>
|
||||
</transition>
|
||||
</template>
|
||||
|
||||
<slot v-else :class="cx('root')" :active="active" :a11yAttrs="a11yAttrs"></slot>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mergeProps } from 'vue';
|
||||
import BaseAccordionContent from './BaseAccordionContent.vue';
|
||||
|
||||
export default {
|
||||
name: 'AccordionContent',
|
||||
extends: BaseAccordionContent,
|
||||
inheritAttrs: false,
|
||||
inject: ['$pcAccordion', '$pcAccordionPanel'],
|
||||
computed: {
|
||||
id() {
|
||||
return `${this.$pcAccordion.id}_accordioncontent_${this.$pcAccordionPanel.value}`;
|
||||
},
|
||||
ariaLabelledby() {
|
||||
return `${this.$pcAccordion.id}_accordionheader_${this.$pcAccordionPanel.value}`;
|
||||
},
|
||||
attrs() {
|
||||
return mergeProps(this.a11yAttrs, this.ptmi('root', this.ptParams));
|
||||
},
|
||||
a11yAttrs() {
|
||||
return {
|
||||
id: this.id,
|
||||
role: 'region',
|
||||
'aria-labelledby': this.ariaLabelledby,
|
||||
'data-pc-name': 'accordioncontent',
|
||||
'data-p-active': this.$pcAccordionPanel.active
|
||||
};
|
||||
},
|
||||
ptParams() {
|
||||
return {
|
||||
context: {
|
||||
active: this.$pcAccordionPanel.active
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
20
components/lib/accordioncontent/BaseAccordionContent.vue
Normal file
20
components/lib/accordioncontent/BaseAccordionContent.vue
Normal file
|
@ -0,0 +1,20 @@
|
|||
<script>
|
||||
import AccordionContentStyle from 'primevue/accordioncontent/style';
|
||||
import BaseComponent from 'primevue/basecomponent';
|
||||
|
||||
export default {
|
||||
name: 'BaseAccordionContent',
|
||||
extends: BaseComponent,
|
||||
props: {
|
||||
as: {
|
||||
type: String,
|
||||
default: 'DIV'
|
||||
},
|
||||
asChild: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
style: AccordionContentStyle
|
||||
};
|
||||
</script>
|
9
components/lib/accordioncontent/package.json
Normal file
9
components/lib/accordioncontent/package.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"main": "./accordioncontent.cjs.js",
|
||||
"module": "./accordioncontent.esm.js",
|
||||
"unpkg": "./accordioncontent.min.js",
|
||||
"types": "./AccordionContent.d.ts",
|
||||
"browser": {
|
||||
"./sfc": "./AccordionContent.vue"
|
||||
}
|
||||
}
|
3
components/lib/accordioncontent/style/AccordionContentStyle.d.ts
vendored
Normal file
3
components/lib/accordioncontent/style/AccordionContentStyle.d.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
import { BaseStyle } from '../../base/style/BaseStyle';
|
||||
|
||||
export interface AccordionContentStyle extends BaseStyle {}
|
|
@ -0,0 +1,11 @@
|
|||
import BaseStyle from 'primevue/base/style';
|
||||
|
||||
const classes = {
|
||||
root: 'p-accordioncontent',
|
||||
content: 'p-accordioncontent-content'
|
||||
};
|
||||
|
||||
export default BaseStyle.extend({
|
||||
name: 'accordioncontent',
|
||||
classes
|
||||
});
|
6
components/lib/accordioncontent/style/package.json
Normal file
6
components/lib/accordioncontent/style/package.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"main": "./accordioncontentstyle.cjs.js",
|
||||
"module": "./accordioncontentstyle.esm.js",
|
||||
"unpkg": "./accordioncontentstyle.min.js",
|
||||
"types": "./AccordionContentStyle.d.ts"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue