Refactor #3911 - For Chart

pull/3919/head
Tuğçe Küçükoğlu 2023-05-02 10:18:02 +03:00
parent aedc26d859
commit fba71b1864
3 changed files with 47 additions and 2 deletions

View File

@ -34,6 +34,12 @@ const ChartProps = [
type: 'number', type: 'number',
default: '150', default: '150',
description: 'Height of the chart in non-responsive mode.' description: 'Height of the chart in non-responsive mode.'
},
{
name: 'pt',
type: 'any',
default: 'null',
description: 'Uses to pass attributes to DOM elements inside the component.'
} }
]; ];

View File

@ -10,6 +10,37 @@
import { CanvasHTMLAttributes } from 'vue'; import { CanvasHTMLAttributes } from 'vue';
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers'; import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
export declare type ChartPassThroughOptionType = ChartPassThroughAttributes | ((options: ChartPassThroughMethodOptions) => ChartPassThroughAttributes) | null | undefined;
/**
* Custom passthrough(pt) option method.
*/
export interface ChartPassThroughMethodOptions {
props: ChartProps;
}
/**
* Custom passthrough(pt) options.
* @see {@link ChartProps.pt}
*/
export interface ChartPassThroughOptions {
/**
* Uses to pass attributes to the root's DOM element.
*/
root?: ChartPassThroughOptionType;
/**
* Uses to pass attributes to the canvas's DOM element.
*/
canvas?: ChartPassThroughOptionType;
}
/**
* Custom passthrough attributes for each DOM elements
*/
export interface ChartPassThroughAttributes {
[key: string]: any;
}
/** /**
* Custom select event. * Custom select event.
* @see {@link ChartEmits.select} * @see {@link ChartEmits.select}
@ -63,6 +94,11 @@ export interface ChartProps {
* Uses to pass all properties of the CanvasHTMLAttributes to canvas element inside the component. * Uses to pass all properties of the CanvasHTMLAttributes to canvas element inside the component.
*/ */
canvasProps?: CanvasHTMLAttributes | undefined; canvasProps?: CanvasHTMLAttributes | undefined;
/**
* Uses to pass attributes to DOM elements inside the component.
* @type {ChartPassThroughOptions}
*/
pt?: ChartPassThroughOptions;
} }
export interface ChartSlots {} export interface ChartSlots {}

View File

@ -1,12 +1,15 @@
<template> <template>
<div class="p-chart"> <div class="p-chart" v-bind="ptm('root')">
<canvas ref="canvas" :width="width" :height="height" @click="onCanvasClick($event)" v-bind="canvasProps"></canvas> <canvas ref="canvas" :width="width" :height="height" @click="onCanvasClick($event)" v-bind="{ ...canvasProps, ...ptm('canvas') }"></canvas>
</div> </div>
</template> </template>
<script> <script>
import BaseComponent from 'primevue/basecomponent';
export default { export default {
name: 'Chart', name: 'Chart',
extends: BaseComponent,
emits: ['select', 'loaded'], emits: ['select', 'loaded'],
props: { props: {
type: String, type: String,