Refactor #3922 - For Slider

pull/3938/head
Bahadır Sofuoğlu 2023-05-07 13:54:26 +03:00
parent 0f6803631f
commit a760c56aef
6 changed files with 157 additions and 5 deletions

View File

@ -9,6 +9,49 @@
*/
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
export declare type SliderPassThroughOptionType = SliderPassThroughAttributes | ((options: SliderPassThroughMethodOptions) => SliderPassThroughAttributes) | null | undefined;
/**
* Custom passthrough(pt) option method.
*/
export interface SliderPassThroughMethodOptions {
props: SliderProps;
}
/**
* Custom passthrough(pt) options.
* @see {@link SliderProps.pt}
*/
export interface SliderPassThroughOptions {
/**
* Uses to pass attributes to the root's DOM element.
*/
root?: SliderPassThroughOptionType;
/**
* Uses to pass attributes to the range's DOM element.
*/
range?: SliderPassThroughOptionType;
/**
* Uses to pass attributes to the handle's DOM element.
*/
handle?: SliderPassThroughOptionType;
/**
* Uses to pass attributes to the start handler's DOM element.
*/
startHandler?: SliderPassThroughOptionType;
/**
* Uses to pass attributes to the end handler's DOM element.
*/
endHandler?: SliderPassThroughOptionType;
}
/**
* Custom passthrough attributes for each DOM elements
*/
export interface SliderPassThroughAttributes {
[key: string]: any;
}
/**
* Custom slide end event.
* @see {@link SliderEmits.slideend}
@ -74,6 +117,11 @@ export interface SliderProps {
* Used to define a string that labels the element.
*/
'aria-label'?: string | undefined;
/**
* Uses to pass attributes to DOM elements inside the component.
* @type {SliderPassThroughOptions}
*/
pt?: SliderPassThroughOptions;
}
/**

View File

@ -1,6 +1,6 @@
<template>
<div :class="containerClass" @click="onBarClick">
<span class="p-slider-range" :style="rangeStyle"></span>
<div :class="containerClass" @click="onBarClick" v-bind="ptm('root')">
<span class="p-slider-range" :style="rangeStyle" v-bind="ptm('range')"></span>
<span
v-if="!range"
class="p-slider-handle"
@ -18,6 +18,7 @@
:aria-labelledby="ariaLabelledby"
:aria-label="ariaLabel"
:aria-orientation="orientation"
v-bind="ptm('handle')"
></span>
<span
v-if="range"
@ -36,6 +37,7 @@
:aria-labelledby="ariaLabelledby"
:aria-label="ariaLabel"
:aria-orientation="orientation"
v-bind="ptm('startHandler')"
></span>
<span
v-if="range"
@ -54,15 +56,18 @@
:aria-labelledby="ariaLabelledby"
:aria-label="ariaLabel"
:aria-orientation="orientation"
v-bind="ptm('endHandler')"
></span>
</div>
</template>
<script>
import BaseComponent from 'primevue/basecomponent';
import { DomHandler } from 'primevue/utils';
export default {
name: 'Slider',
extends: BaseComponent,
emits: ['update:modelValue', 'change', 'slideend'],
props: {
modelValue: [Number, Array],

49
doc/slider/pt/PTDoc.vue Normal file
View File

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

41
doc/slider/pt/index.vue Normal file
View File

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

View File

@ -1,5 +1,5 @@
<template>
<DocComponent title="Vue Slider Component" header="Slider" description="Slider is a component to provide input with a drag handle." :componentDocs="docs" :apiDocs="['Slider']" />
<DocComponent title="Vue Slider Component" header="Slider" description="Slider is a component to provide input with a drag handle." :componentDocs="docs" :apiDocs="['Slider']" :ptTabComponent="ptComponent" />
</template>
<script>
@ -11,7 +11,7 @@ import RangeDoc from '@/doc/slider/RangeDoc';
import StepDoc from '@/doc/slider/StepDoc';
import StyleDoc from '@/doc/slider/StyleDoc';
import VerticalDoc from '@/doc/slider/VerticalDoc';
import PTComponent from '@/doc/slider/pt/index.vue';
export default {
data() {
return {
@ -56,7 +56,8 @@ export default {
label: 'Accessibility',
component: AccessibilityDoc
}
]
],
ptComponent: PTComponent
};
}
};