Refactor #3797 - Fieldset updates

pull/3841/head
Tuğçe Küçükoğlu 2023-03-24 18:07:46 +03:00
parent 1ccf0f13b9
commit 02307960ec
3 changed files with 96 additions and 9 deletions

View File

@ -22,6 +22,12 @@ const FieldsetProps = [
type: 'string', type: 'string',
default: 'null', default: 'null',
description: 'Uses to pass the custom value to read for the AnchorHTMLAttributes inside the component.' description: 'Uses to pass the custom value to read for the AnchorHTMLAttributes inside the component.'
},
{
name: 'pt',
type: 'any',
default: 'null',
description: 'Uses to pass attributes to DOM elements inside the component.'
} }
]; ];
@ -47,7 +53,11 @@ const FieldsetEvents = [
const FieldsetSlots = [ const FieldsetSlots = [
{ {
name: 'legend', name: 'legend',
description: "Custom content for the component's header" description: 'Custom legend template.'
},
{
name: 'togglericon',
description: 'Custom toggler icon template.'
} }
]; ];

View File

@ -10,6 +10,16 @@
import { AnchorHTMLAttributes, VNode } from 'vue'; import { AnchorHTMLAttributes, VNode } from 'vue';
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers'; import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
export declare type FieldsetPassThroughOptionType = FieldsetPassThroughAttributes | ((options: FieldsetPassThroughMethodOptions) => FieldsetPassThroughAttributes) | null | undefined;
/**
* Custom passthrough(pt) option method.
*/
export interface FieldsetPassThroughMethodOptions {
props: FieldsetProps;
state: FieldsetState;
}
/** /**
* Custom toggle event. * Custom toggle event.
* @see {@link FieldsetEmits.toggle} * @see {@link FieldsetEmits.toggle}
@ -25,6 +35,59 @@ export interface FieldsetToggleEvent {
value: boolean; value: boolean;
} }
/**
* Custom passthrough(pt) options.
* @see {@link FieldsetProps.pt}
*/
export interface FieldsetPassThroughOptions {
/**
* Uses to pass attributes to the root's DOM element.
*/
root?: FieldsetPassThroughOptionType;
/**
* Uses to pass attributes to the legend's DOM element.
*/
legend?: FieldsetPassThroughOptionType;
/**
* Uses to pass attributes to the legend title's DOM element.
*/
legendtitle?: FieldsetPassThroughOptionType;
/**
* Uses to pass attributes to the toggler's DOM element.
*/
toggler?: FieldsetPassThroughOptionType;
/**
* Uses to pass attributes to the toggler icon's DOM element.
*/
togglericon?: FieldsetPassThroughOptionType;
/**
* Uses to pass attributes to the toggleable content's DOM element.
*/
toggleablecontent?: FieldsetPassThroughOptionType;
/**
* Uses to pass attributes to the content's DOM element.
*/
content?: FieldsetPassThroughOptionType;
}
/**
* Custom passthrough attributes for each DOM elements
*/
export interface FieldsetPassThroughAttributes {
[key: string]: any;
}
/**
* Defines current inline state in Fieldset component.
*/
export interface FieldsetState {
/**
* Current collapsed state as a boolean.
* @defaultValue false
*/
d_collapsed: boolean;
}
/** /**
* Defines valid properties in Fieldset component. * Defines valid properties in Fieldset component.
*/ */
@ -45,8 +108,14 @@ export interface FieldsetProps {
collapsed?: boolean | undefined; collapsed?: boolean | undefined;
/** /**
* Uses to pass the custom value to read for the AnchorHTMLAttributes inside the component. * Uses to pass the custom value to read for the AnchorHTMLAttributes inside the component.
* @deprecated since v3.26.0. Use 'pt' property instead.
*/ */
toggleButtonProps?: AnchorHTMLAttributes | undefined; toggleButtonProps?: AnchorHTMLAttributes | undefined;
/**
* Uses to pass attributes to DOM elements inside the component.
* @type {FieldsetPassThroughOptions}
*/
pt?: FieldsetPassThroughOptions;
} }
/** /**
@ -61,6 +130,10 @@ export interface FieldsetSlots {
* Custom legend template. * Custom legend template.
*/ */
legend: () => VNode[]; legend: () => VNode[];
/**
* Custom toggler icon template.
*/
togglericon: () => VNode[];
} }
/** /**

View File

@ -1,8 +1,8 @@
<template> <template>
<fieldset :class="['p-fieldset p-component', { 'p-fieldset-toggleable': toggleable }]"> <fieldset :class="['p-fieldset p-component', { 'p-fieldset-toggleable': toggleable }]" v-bind="ptm('root')">
<legend class="p-fieldset-legend"> <legend class="p-fieldset-legend" v-bind="ptm('legend')">
<slot v-if="!toggleable" name="legend"> <slot v-if="!toggleable" name="legend">
<span :id="ariaId + '_header'" class="p-fieldset-legend-text">{{ legend }}</span> <span :id="ariaId + '_header'" class="p-fieldset-legend-text" v-bind="ptm('legendtitle')">{{ legend }}</span>
</slot> </slot>
<a <a
v-if="toggleable" v-if="toggleable"
@ -15,17 +15,19 @@
:aria-label="buttonAriaLabel" :aria-label="buttonAriaLabel"
@click="toggle" @click="toggle"
@keydown="onKeyDown" @keydown="onKeyDown"
v-bind="toggleButtonProps" v-bind="{ ...toggleButtonProps, ...ptm('toggler') }"
> >
<span :class="iconClass"></span> <slot name="togglericon" :collapsed="d_collapsed">
<span :class="iconClass" v-bind="ptm('togglericon')"></span>
</slot>
<slot name="legend"> <slot name="legend">
<span class="p-fieldset-legend-text">{{ legend }}</span> <span class="p-fieldset-legend-text" v-bind="ptm('legendtitle')">{{ legend }}</span>
</slot> </slot>
</a> </a>
</legend> </legend>
<transition name="p-toggleable-content"> <transition name="p-toggleable-content">
<div v-show="!d_collapsed" :id="ariaId + '_content'" class="p-toggleable-content" role="region" :aria-labelledby="ariaId + '_header'"> <div v-show="!d_collapsed" :id="ariaId + '_content'" class="p-toggleable-content" role="region" :aria-labelledby="ariaId + '_header'" v-bind="ptm('toggleablecontent')">
<div class="p-fieldset-content"> <div class="p-fieldset-content" v-bind="ptm('content')">
<slot></slot> <slot></slot>
</div> </div>
</div> </div>
@ -34,11 +36,13 @@
</template> </template>
<script> <script>
import ComponentBase from 'primevue/base';
import Ripple from 'primevue/ripple'; import Ripple from 'primevue/ripple';
import { UniqueComponentId } from 'primevue/utils'; import { UniqueComponentId } from 'primevue/utils';
export default { export default {
name: 'Fieldset', name: 'Fieldset',
extends: ComponentBase,
emits: ['update:collapsed', 'toggle'], emits: ['update:collapsed', 'toggle'],
props: { props: {
legend: String, legend: String,