Refactor #3965 - For Chip

pull/3997/head
Bahadır Sofuoğlu 2023-05-24 10:39:02 +03:00
parent 2d2b2dff1e
commit ae43587f19
3 changed files with 92 additions and 63 deletions

View File

@ -0,0 +1,80 @@
<script>
import BaseComponent from 'primevue/basecomponent';
import { useStyle } from 'primevue/usestyle';
const styles = `
.p-chip {
display: inline-flex;
align-items: center;
}
.p-chip-text {
line-height: 1.5;
}
.p-chip-icon.pi {
line-height: 1.5;
}
.p-chip-remove-icon {
line-height: 1.5;
cursor: pointer;
}
.p-chip img {
border-radius: 50%;
}
`;
const classes = {
root: ({ props }) => [
'p-chip p-component',
{
'p-chip-image': props.image != null
}
],
icon: ({ props }) => ['p-chip-icon', props.icon],
label: 'p-chip-text',
removeIcon: ({ props }) => ['p-chip-remove-icon', props.removeIcon]
};
const { load: loadStyle } = useStyle(styles, { id: 'primevue_divider_style', manual: true });
export default {
name: 'BaseAvatar',
extends: BaseComponent,
props: {
label: {
type: String,
default: null
},
icon: {
type: String,
default: null
},
image: {
type: String,
default: null
},
removable: {
type: Boolean,
default: false
},
removeIcon: {
type: String,
default: undefined
}
},
css: {
classes
},
watch: {
isUnstyled: {
immediate: true,
handler(newValue) {
!newValue && loadStyle();
}
}
}
};
</script>

View File

@ -97,6 +97,11 @@ export interface ChipProps {
* @type {ChipPassThroughOptions} * @type {ChipPassThroughOptions}
*/ */
pt?: ChipPassThroughOptions; pt?: ChipPassThroughOptions;
/**
* When enabled, it removes component related styles in the core.
* @defaultValue false
*/
unstyled?: boolean;
} }
/** /**

View File

@ -1,47 +1,25 @@
<template> <template>
<div v-if="visible" :class="containerClass" :aria-label="label" v-bind="ptm('root')"> <div v-if="visible" :class="cx('root')" :aria-label="label" v-bind="ptm('root')">
<slot> <slot>
<img v-if="image" :src="image" v-bind="ptm('image')" /> <img v-if="image" :src="image" v-bind="ptm('image')" />
<component v-else-if="$slots.icon" :is="$slots.icon" class="p-chip-icon" v-bind="ptm('icon')" /> <component v-else-if="$slots.icon" :is="$slots.icon" :class="cx('icon')" v-bind="ptm('icon')" />
<span v-else-if="icon" :class="['p-chip-icon', icon]" v-bind="ptm('icon')" /> <span v-else-if="icon" :class="cx('icon')" v-bind="ptm('icon')" />
<div v-if="label" class="p-chip-text" v-bind="ptm('label')">{{ label }}</div> <div v-if="label" :class="cx('label')" v-bind="ptm('label')">{{ label }}</div>
</slot> </slot>
<slot v-if="removable" name="removeicon" :onClick="close" :onKeydown="onKeydown"> <slot v-if="removable" name="removeicon" :onClick="close" :onKeydown="onKeydown">
<component :is="removeIcon ? 'span' : 'TimesCircleIcon'" tabindex="0" :class="['p-chip-remove-icon', removeIcon]" @click="close" @keydown="onKeydown" v-bind="ptm('removeIcon')"></component> <component :is="removeIcon ? 'span' : 'TimesCircleIcon'" tabindex="0" :class="cx('removeIcon')" @click="close" @keydown="onKeydown" v-bind="ptm('removeIcon')"></component>
</slot> </slot>
</div> </div>
</template> </template>
<script> <script>
import BaseComponent from 'primevue/basecomponent'; import BaseChip from './BaseChip.vue';
import TimesCircleIcon from 'primevue/icons/timescircle'; import TimesCircleIcon from 'primevue/icons/timescircle';
export default { export default {
name: 'Chip', name: 'Chip',
extends: BaseComponent, extends: BaseChip,
emits: ['remove'], emits: ['remove'],
props: {
label: {
type: String,
default: null
},
icon: {
type: String,
default: null
},
image: {
type: String,
default: null
},
removable: {
type: Boolean,
default: false
},
removeIcon: {
type: String,
default: undefined
}
},
data() { data() {
return { return {
visible: true visible: true
@ -58,42 +36,8 @@ export default {
this.$emit('remove', event); this.$emit('remove', event);
} }
}, },
computed: {
containerClass() {
return [
'p-chip p-component',
{
'p-chip-image': this.image != null
}
];
}
},
components: { components: {
TimesCircleIcon TimesCircleIcon
} }
}; };
</script> </script>
<style>
.p-chip {
display: inline-flex;
align-items: center;
}
.p-chip-text {
line-height: 1.5;
}
.p-chip-icon.pi {
line-height: 1.5;
}
.p-chip-remove-icon {
line-height: 1.5;
cursor: pointer;
}
.p-chip img {
border-radius: 50%;
}
</style>