Refactor #3922 - For ToggleButton

pull/3938/head
Bahadır Sofuoğlu 2023-05-07 14:38:47 +03:00
parent 8e281f2a41
commit 7a26836c60
7 changed files with 170 additions and 9 deletions

View File

@ -10,6 +10,60 @@
import { InputHTMLAttributes, VNode } from 'vue'; import { InputHTMLAttributes, VNode } from 'vue';
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers'; import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
export declare type ToggleButtonPassThroughOptionType = ToggleButtonPassThroughAttributes | ((options: ToggleButtonPassThroughMethodOptions) => ToggleButtonPassThroughAttributes) | null | undefined;
/**
* Custom passthrough(pt) option method.
*/
export interface ToggleButtonPassThroughMethodOptions {
props: ToggleButtonProps;
state: ToggleButtonState;
}
/**
* Custom passthrough(pt) options.
* @see {@link ToggleButtonProps.pt}
*/
export interface ToggleButtonPassThroughOptions {
/**
* Uses to pass attributes to the root's DOM element.
*/
root?: ToggleButtonPassThroughOptionType;
/**
* Uses to pass attributes to the input aria's DOM element.
*/
inputAria?: ToggleButtonPassThroughOptionType;
/**
* Uses to pass attributes to the input's DOM element.
*/
input?: ToggleButtonPassThroughOptionType;
/**
* Uses to pass attributes to the icon's DOM element.
*/
icon?: ToggleButtonPassThroughOptionType;
/**
* Uses to pass attributes to the label's DOM element.
*/
label?: ToggleButtonPassThroughOptionType;
}
/**
* Custom passthrough attributes for each DOM elements
*/
export interface ToggleButtonPassThroughAttributes {
[key: string]: any;
}
/**
* Defines current inline state in ToggleButton component.
*/
export interface ToggleButtonState {
/**
* Focused state as a number.
*/
focused: boolean;
}
/** /**
* Defines valid properties in ToggleButton component. * Defines valid properties in ToggleButton component.
*/ */
@ -77,6 +131,11 @@ export interface ToggleButtonProps {
* Establishes a string value that labels the component. * Establishes a string value that labels the component.
*/ */
'aria-label'?: string | undefined; 'aria-label'?: string | undefined;
/**
* Uses to pass attributes to DOM elements inside the component.
* @type {ToggleButtonPassThroughOptions}
*/
pt?: ToggleButtonPassThroughOptions;
} }
/** /**

View File

@ -1,6 +1,6 @@
<template> <template>
<div ref="container" v-ripple :class="buttonClass" @click="onClick($event)"> <div ref="container" v-ripple :class="buttonClass" @click="onClick($event)" v-bind="ptm('root')">
<span class="p-hidden-accessible"> <span class="p-hidden-accessible" v-bind="ptm('inputAria')">
<input <input
:id="inputId" :id="inputId"
type="checkbox" type="checkbox"
@ -13,21 +13,23 @@
:aria-label="ariaLabel" :aria-label="ariaLabel"
@focus="onFocus($event)" @focus="onFocus($event)"
@blur="onBlur($event)" @blur="onBlur($event)"
v-bind="inputProps" v-bind="{ ...inputProps, ...ptm('input') }"
/> />
</span> </span>
<slot name="icon" :value="modelValue" :class="iconClass"> <slot name="icon" :value="modelValue" :class="iconClass">
<span v-if="onIcon || offIcon" :class="iconClass" /> <span v-if="onIcon || offIcon" :class="iconClass" v-bind="ptm('icon')" />
</slot> </slot>
<span class="p-button-label">{{ label }}</span> <span class="p-button-label" v-bind="ptm('label')">{{ label }}</span>
</div> </div>
</template> </template>
<script> <script>
import BaseComponent from 'primevue/basecomponent';
import Ripple from 'primevue/ripple'; import Ripple from 'primevue/ripple';
export default { export default {
name: 'ToggleButton', name: 'ToggleButton',
extends: BaseComponent,
emits: ['update:modelValue', 'change', 'click', 'focus', 'blur'], emits: ['update:modelValue', 'change', 'click', 'focus', 'blur'],
props: { props: {
modelValue: Boolean, modelValue: Boolean,

View File

@ -0,0 +1,49 @@
<template>
<DocSectionText v-bind="$attrs"> </DocSectionText>
<div class="card flex justify-content-center">
<ToggleButton v-model="checked" class="w-8rem" />
</div>
<DocSectionCode :code="code" />
</template>
<script>
export default {
data() {
return {
checked: false,
code: {
basic: `
<ToggleButton v-model="checked" />`,
options: `
<template>
<div class="card flex justify-content-center">
<ToggleButton v-model="checked" class="w-8rem" />
</div>
</template>
<script>
export default {
data() {
return {
checked: false
}
}
};
<\/script>`,
composition: `
<template>
<div class="card flex justify-content-center">
<ToggleButton v-model="checked" class="w-8rem" />
</div>
</template>
<script setup>
import { ref } from 'vue';
const checked = ref(false);
<\/script>`
}
};
}
};
</script>

View File

@ -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>

View File

@ -0,0 +1,41 @@
<template>
<div class="doc-main">
<div class="doc-intro">
<h1>ToggleButton 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: 'ToggleButton PT Options',
component: DocApiTable,
data: getPTOption('ToggleButton')
},
{
id: 'pt.demo',
label: 'Demo',
component: PtDoc
}
]
};
}
};
</script>

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="doc-main"> <div class="doc-main">
<div class="doc-intro"> <div class="doc-intro">
<h1>Rating Pass Through</h1> <h1>TriStateCheckbox Pass Through</h1>
</div> </div>
<DocSections :docs="docs" /> <DocSections :docs="docs" />
</div> </div>
@ -25,7 +25,7 @@ export default {
}, },
{ {
id: 'pt.doc.steps', id: 'pt.doc.steps',
label: 'Rating PT Options', label: 'TriStateCheckbox PT Options',
component: DocApiTable, component: DocApiTable,
data: getPTOption('TriStateCheckbox') data: getPTOption('TriStateCheckbox')
}, },

View File

@ -1,5 +1,5 @@
<template> <template>
<DocComponent title="Vue ToggleButton Component" header="ToggleButton" description="ToggleButton is used to select a boolean value using a button." :componentDocs="docs" :apiDocs="['ToggleButton']" /> <DocComponent title="Vue ToggleButton Component" header="ToggleButton" description="ToggleButton is used to select a boolean value using a button." :componentDocs="docs" :apiDocs="['ToggleButton']" :ptTabComponent="ptComponent" />
</template> </template>
<script> <script>
@ -10,6 +10,7 @@ import DisabledDoc from '@/doc/togglebutton/DisabledDoc.vue';
import VeeValidateDoc from '@/doc/togglebutton/form/VeeValidateDoc.vue'; import VeeValidateDoc from '@/doc/togglebutton/form/VeeValidateDoc.vue';
import ImportDoc from '@/doc/togglebutton/ImportDoc.vue'; import ImportDoc from '@/doc/togglebutton/ImportDoc.vue';
import StyleDoc from '@/doc/togglebutton/StyleDoc.vue'; import StyleDoc from '@/doc/togglebutton/StyleDoc.vue';
import PTComponent from '@/doc/togglebutton/pt/index.vue';
export default { export default {
data() { data() {
@ -57,7 +58,8 @@ export default {
label: 'Accessibility', label: 'Accessibility',
component: AccessibilityDoc component: AccessibilityDoc
} }
] ],
ptComponent: PTComponent
}; };
} }
}; };