Core utilities and base functionality for PrimeVue UI component library
52
Quality
Pending
Does it follow best practices?
Impact
52%
1.15xAverage score across 10 eval scenarios
Vue composables providing common functionality for PrimeVue components including ID generation, dynamic styling, and attribute selection utilities.
Dynamic CSS injection composable for loading and managing styles at runtime.
interface UseStyleOptions {
/** Target document for style injection */
document?: Document;
/** Load styles immediately */
immediate?: boolean;
/** Manual loading control */
manual?: boolean;
/** Style element name */
name?: string;
/** Style element ID */
id?: string;
/** Media query for style element */
media?: string;
/** CSP nonce value */
nonce?: string;
/** Insert at beginning of head */
first?: boolean;
/** Callback when style is mounted */
onMounted?: (name: string) => void;
/** Callback when style is updated */
onUpdated?: (name: string) => void;
/** Callback when style is loaded */
onLoad?: (event: Event, options: { name: string }) => void;
/** Additional properties for style element */
props?: Record<string, any>;
}
/**
* Create and manage dynamic CSS styles
* @param css - CSS content to inject
* @param options - Configuration options
* @returns Style management object
*/
declare function useStyle(css: string, options?: UseStyleOptions): {
/** Style element ID */
id: string | undefined;
/** Style element name */
name: string;
/** Style element reference */
el: Ref<HTMLStyleElement | null>;
/** CSS content reference */
css: Ref<string>;
/** Load styles with optional CSS and properties */
load: (css?: string, props?: any) => void;
/** Remove styles from DOM */
unload: () => void;
/** Reactive loading state */
isLoaded: Readonly<Ref<boolean>>;
};Usage Examples:
import { useStyle } from '@primevue/core/usestyle';
// Basic usage
const { load, unload, isLoaded } = useStyle('.my-class { color: red; }');
// With options
const styleManager = useStyle('', {
name: 'custom-styles',
nonce: 'abc123',
onMounted: (name) => console.log(`Styles ${name} mounted`),
onUpdated: (name) => console.log(`Styles ${name} updated`)
});
// Dynamic loading
styleManager.load('.dynamic { background: blue; }');
// Conditional loading
if (condition) {
styleManager.load('.conditional { display: none; }');
} else {
styleManager.unload();
}
// Check loading state
watch(styleManager.isLoaded, (loaded) => {
console.log('Styles loaded:', loaded);
});ID generation composable for creating unique component identifiers.
/**
* Generate unique component ID
* @param initialValue - Optional initial ID value
* @returns Unique ID string
*/
declare function useId(initialValue?: string): string;Usage Examples:
import { useId } from '@primevue/core/useid';
// Generate unique ID
const componentId = useId(); // Returns: 'pv_id_1_2_3'
// With initial value
const customId = useId('my-component'); // Returns: 'my-component'
// In Vue component
export default {
setup() {
const inputId = useId();
const labelId = useId();
return {
inputId, // 'pv_id_1_2_3'
labelId // 'pv_id_4_5_6'
};
}
};Attribute selector generation for component styling and targeting.
/**
* Generate unique attribute selector for component styling
* @returns Unique attribute selector string
*/
declare function useAttrSelector(): string;Usage Examples:
import { useAttrSelector } from '@primevue/core/useattrselector';
// Generate attribute selector
const attrSelector = useAttrSelector(); // Returns: 'pc_1_2_3'
// Use in component
export default {
setup() {
const selector = useAttrSelector();
return {
selector, // Use as data attribute
getScopedClass: (cls) => `[${selector}] .${cls}`
};
},
template: `
<div :[selector]="">
<span class="content">Scoped content</span>
</div>
`
};Event bus service for component communication (re-exported from @primeuix/utils/eventbus).
declare const PrimeVueService: {
/**
* Register event listener
* @param event - Event name
* @param callback - Event callback function
*/
on(event: string, callback: Function): void;
/**
* Remove event listener
* @param event - Event name
* @param callback - Event callback function
*/
off(event: string, callback: Function): void;
/**
* Emit event with data
* @param event - Event name
* @param data - Event data
*/
emit(event: string, data?: any): void;
/**
* Register one-time event listener
* @param event - Event name
* @param callback - Event callback function
*/
once(event: string, callback: Function): void;
/**
* Remove all listeners for event
* @param event - Event name
*/
removeAllListeners(event?: string): void;
};Usage Examples:
import PrimeVueService from '@primevue/core/service';
// Listen for configuration changes
PrimeVueService.on('config:change', ({ newValue, oldValue }) => {
console.log('Config changed:', newValue);
});
// Listen for theme changes
PrimeVueService.on('config:theme:change', ({ newValue, oldValue }) => {
console.log('Theme changed from', oldValue, 'to', newValue);
});
// Emit custom events
PrimeVueService.emit('component:mounted', { component: 'MyComponent' });
// One-time listener
PrimeVueService.once('app:ready', () => {
console.log('Application is ready');
});
// Remove listener
const handleConfigChange = (config) => { /* ... */ };
PrimeVueService.on('config:change', handleConfigChange);
PrimeVueService.off('config:change', handleConfigChange);import { useStyle } from '@primevue/core/usestyle';
import { computed, watch } from 'vue';
export default {
setup(props) {
const { load, unload } = useStyle('', { manual: true });
const styles = computed(() => {
return props.variant === 'primary'
? '.component { background: blue; }'
: '.component { background: gray; }';
});
watch(styles, (newStyles) => {
load(newStyles);
}, { immediate: true });
return { styles };
}
};import { useAttrSelector, useStyle } from '@primevue/core';
export default {
setup() {
const selector = useAttrSelector();
const { load } = useStyle(`
[${selector}] .component {
/* Scoped styles */
}
`);
return { selector };
}
};// Individual composable imports (recommended)
import { useStyle } from '@primevue/core/usestyle';
import { useId } from '@primevue/core/useid';
import { useAttrSelector } from '@primevue/core/useattrselector';
import PrimeVueService from '@primevue/core/service';
// Named imports from main package
import { useStyle, useId } from '@primevue/core';
// All composables
import { useStyle, useId, useAttrSelector } from '@primevue/core';Install with Tessl CLI
npx tessl i tessl/npm-primevue--coreevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10