Skip to content

Commit

Permalink
Refactor #3922 - For Slider
Browse files Browse the repository at this point in the history
  • Loading branch information
bahadirsofuoglu committed May 7, 2023
1 parent 0f68036 commit a760c56
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 5 deletions.
48 changes: 48 additions & 0 deletions components/lib/slider/Slider.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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;
}

/**
Expand Down
9 changes: 7 additions & 2 deletions components/lib/slider/Slider.vue
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -18,6 +18,7 @@
:aria-labelledby="ariaLabelledby"
:aria-label="ariaLabel"
:aria-orientation="orientation"
v-bind="ptm('handle')"
></span>
<span
v-if="range"
Expand All @@ -36,6 +37,7 @@
:aria-labelledby="ariaLabelledby"
:aria-label="ariaLabel"
:aria-orientation="orientation"
v-bind="ptm('startHandler')"
></span>
<span
v-if="range"
Expand All @@ -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],
Expand Down
49 changes: 49 additions & 0 deletions doc/slider/pt/PTDoc.vue
Original file line number Diff line number Diff line change
@@ -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>
8 changes: 8 additions & 0 deletions doc/slider/pt/PTImage.vue
Original file line number Diff line number Diff line change
@@ -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 changes: 41 additions & 0 deletions doc/slider/pt/index.vue
Original file line number Diff line number Diff line change
@@ -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>
7 changes: 4 additions & 3 deletions pages/slider/index.vue
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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 {
Expand Down Expand Up @@ -56,7 +56,8 @@ export default {
label: 'Accessibility',
component: AccessibilityDoc
}
]
],
ptComponent: PTComponent
};
}
};
Expand Down

0 comments on commit a760c56

Please sign in to comment.