mirror of
https://github.com/primefaces/primevue.git
synced 2025-05-10 17:32: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
145
components/lib/accordionpanel/AccordionPanel.d.ts
vendored
Executable file
145
components/lib/accordionpanel/AccordionPanel.d.ts
vendored
Executable file
|
@ -0,0 +1,145 @@
|
|||
/**
|
||||
*
|
||||
* AccordionPanel is a helper component for Accordion component.
|
||||
*
|
||||
* [Live Demo](https://www.primevue.org/accordion/)
|
||||
*
|
||||
* @module accordionpanel
|
||||
*
|
||||
*/
|
||||
import { VNode } from 'vue';
|
||||
import { ComponentHooks } from '../basecomponent';
|
||||
import { PassThroughOptions } from '../passthrough';
|
||||
import { ClassComponent, DesignToken, GlobalComponentConstructor, PassThrough } from '../ts-helpers';
|
||||
|
||||
export declare type AccordionPanelPassThroughOptionType = AccordionPanelPassThroughAttributes | ((options: AccordionPanelPassThroughMethodOptions) => AccordionPanelPassThroughAttributes | string) | string | null | undefined;
|
||||
|
||||
/**
|
||||
* Custom passthrough(pt) option method.
|
||||
*/
|
||||
export interface AccordionPanelPassThroughMethodOptions {
|
||||
/**
|
||||
* Defines instance.
|
||||
*/
|
||||
instance: any;
|
||||
/**
|
||||
* Defines valid properties.
|
||||
*/
|
||||
props: AccordionPanelProps;
|
||||
/**
|
||||
* Defines current options.
|
||||
*/
|
||||
context: AccordionPanelContext;
|
||||
/**
|
||||
* 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 AccordionPanelProps.pt}
|
||||
*/
|
||||
export interface AccordionPanelPassThroughOptions {
|
||||
/**
|
||||
* Used to pass attributes to the root's DOM element.
|
||||
*/
|
||||
root?: AccordionPanelPassThroughOptionType;
|
||||
/**
|
||||
* Used to manage all lifecycle hooks.
|
||||
* @see {@link BaseComponent.ComponentHooks}
|
||||
*/
|
||||
hooks?: ComponentHooks;
|
||||
}
|
||||
|
||||
export interface AccordionPanelPassThroughAttributes {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines valid properties in AccordionPanel component.
|
||||
*/
|
||||
export interface AccordionPanelProps {
|
||||
/**
|
||||
* Unique value of item.
|
||||
*/
|
||||
value: string;
|
||||
/**
|
||||
* Whether the item is disabled.
|
||||
* @defaultValue false
|
||||
*/
|
||||
disabled?: boolean | undefined;
|
||||
/**
|
||||
* 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 {AccordionPanelPassThroughOptions}
|
||||
*/
|
||||
pt?: PassThrough<AccordionPanelPassThroughOptions>;
|
||||
/**
|
||||
* Used to configure passthrough(pt) options of the component.
|
||||
* @type {PassThroughOptions}
|
||||
*/
|
||||
ptOptions?: PassThroughOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines current options in AccordionPanel component.
|
||||
*/
|
||||
export interface AccordionPanelContext {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines valid slots in AccordionPanel slots.
|
||||
*/
|
||||
export interface AccordionPanelSlots {
|
||||
/**
|
||||
* Custom content template.
|
||||
*/
|
||||
default(): VNode[];
|
||||
}
|
||||
|
||||
export interface AccordionPanelEmits {}
|
||||
|
||||
/**
|
||||
* **PrimeVue - AccordionPanel**
|
||||
*
|
||||
* _AccordionPanel is a helper component for Accordion component._
|
||||
*
|
||||
* [Live Demo](https://www.primevue.org/accordion/)
|
||||
* --- ---
|
||||
* 
|
||||
*
|
||||
* @group Component
|
||||
*
|
||||
*/
|
||||
declare class AccordionPanel extends ClassComponent<AccordionPanelProps, AccordionPanelSlots, AccordionPanelEmits> {}
|
||||
|
||||
declare module 'vue' {
|
||||
export interface GlobalComponents {
|
||||
AccordionPanel: GlobalComponentConstructor<AccordionPanel>;
|
||||
}
|
||||
}
|
||||
|
||||
export default AccordionPanel;
|
40
components/lib/accordionpanel/AccordionPanel.vue
Normal file
40
components/lib/accordionpanel/AccordionPanel.vue
Normal file
|
@ -0,0 +1,40 @@
|
|||
<template>
|
||||
<component v-if="!asChild" :is="as" v-ripple :class="cx('root')" v-bind="attrs">
|
||||
<slot></slot>
|
||||
</component>
|
||||
<slot v-else :class="cx('root')" :active="active" :a11yAttrs="a11yAttrs"></slot>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mergeProps } from 'vue';
|
||||
import BaseAccordionPanel from './BaseAccordionPanel.vue';
|
||||
|
||||
export default {
|
||||
name: 'AccordionPanel',
|
||||
extends: BaseAccordionPanel,
|
||||
inheritAttrs: false,
|
||||
inject: ['$pcAccordion'],
|
||||
computed: {
|
||||
active() {
|
||||
return this.$pcAccordion.isItemActive(this.value);
|
||||
},
|
||||
attrs() {
|
||||
return mergeProps(this.a11yAttrs, this.ptmi('root', this.ptParams));
|
||||
},
|
||||
a11yAttrs() {
|
||||
return {
|
||||
'data-pc-name': 'accordionpanel',
|
||||
'data-p-disabled': this.disabled,
|
||||
'data-p-active': this.active
|
||||
};
|
||||
},
|
||||
ptParams() {
|
||||
return {
|
||||
context: {
|
||||
active: this.active
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
34
components/lib/accordionpanel/BaseAccordionPanel.vue
Normal file
34
components/lib/accordionpanel/BaseAccordionPanel.vue
Normal file
|
@ -0,0 +1,34 @@
|
|||
<script>
|
||||
import AccordionPanelStyle from 'primevue/accordionpanel/style';
|
||||
import BaseComponent from 'primevue/basecomponent';
|
||||
|
||||
export default {
|
||||
name: 'BaseAccordionPanel',
|
||||
extends: BaseComponent,
|
||||
props: {
|
||||
value: {
|
||||
type: String,
|
||||
default: undefined
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
as: {
|
||||
type: String,
|
||||
default: 'DIV'
|
||||
},
|
||||
asChild: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
style: AccordionPanelStyle,
|
||||
provide() {
|
||||
return {
|
||||
$pcAccordionPanel: this,
|
||||
$parentInstance: this
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
9
components/lib/accordionpanel/package.json
Normal file
9
components/lib/accordionpanel/package.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"main": "./accordionpanel.cjs.js",
|
||||
"module": "./accordionpanel.esm.js",
|
||||
"unpkg": "./accordionpanel.min.js",
|
||||
"types": "./AccordionPanel.d.ts",
|
||||
"browser": {
|
||||
"./sfc": "./AccordionPanel.vue"
|
||||
}
|
||||
}
|
3
components/lib/accordionpanel/style/AccordionPanelStyle.d.ts
vendored
Normal file
3
components/lib/accordionpanel/style/AccordionPanelStyle.d.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
import { BaseStyle } from '../../base/style/BaseStyle';
|
||||
|
||||
export interface AccordionPanelStyle extends BaseStyle {}
|
16
components/lib/accordionpanel/style/AccordionPanelStyle.js
Normal file
16
components/lib/accordionpanel/style/AccordionPanelStyle.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
import BaseStyle from 'primevue/base/style';
|
||||
|
||||
const classes = {
|
||||
root: ({ instance, props }) => [
|
||||
'p-accordionpanel',
|
||||
{
|
||||
'p-active': instance.active,
|
||||
'p-disabled': props.disabled
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
export default BaseStyle.extend({
|
||||
name: 'accordionpanel',
|
||||
classes
|
||||
});
|
6
components/lib/accordionpanel/style/package.json
Normal file
6
components/lib/accordionpanel/style/package.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"main": "./accordionpanelstyle.cjs.js",
|
||||
"module": "./accordionpanelstyle.esm.js",
|
||||
"unpkg": "./accordionpanelstyle.min.js",
|
||||
"types": "./AccordionPanelStyle.d.ts"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue