Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(filter components & add suffix) plugin based #10

Open
github-actions bot opened this issue Nov 19, 2023 · 0 comments
Open

(filter components & add suffix) plugin based #10

github-actions bot opened this issue Nov 19, 2023 · 0 comments
Labels
components Components pkgs scope enhancement New feature or request help wanted Extra attention is needed todo types Types related issue

Comments

@github-actions
Copy link

// TODO: (filter components & add suffix) plugin based

import {
	Plugin,
	Component as VueComponent,
	DefineComponent,
	FunctionalComponent,
	defineCustomElement,
} from "vue";
import _ from "lodash";

import type { tPropertyMapping, iPluginOptions } from "@open-xamu-co/ui-common-types";
import locale from "@open-xamu-co/ui-common-helpers/en";
import { componentNames } from "@open-xamu-co/ui-common-enums";

import * as components from "./components";

export const xamuPlugin: Plugin<
	iPluginOptions<VueComponent | FunctionalComponent | DefineComponent>
> = {
	install(V, options) {
		options = {
			// Set plugin defaults
			globalComponents: true,
			componentPrefix: "xamu",
			mediaQueryPixels: { laptop: 1080, tablet: 768, mobile: 576 },
			locale,
			lang: "en",
			first: 10,
			// override defaults
			...options,
		};

		const { globalComponents, componentPrefix, webComponents } = options;

		// Set plugin options globally
		V.provide("xamu", options);

		if (!globalComponents) return;

		// Filter and register components
		const componentKeys = Array.isArray(globalComponents) ? globalComponents : componentNames;

		// Register components
		componentKeys.forEach((key) => {
			const name = _.capitalize(_.camelCase(componentPrefix)) + key;
			const component = <DefineComponent>components[key];

			/**
			 * There is an issue with custom elements and emits
			 *
			 * @see https://github.com/vuejs/core/issues/7782
			 */
			if (webComponents) {
				// register as a web component
				const webComponent = defineCustomElement(component);

				customElements.define(name, webComponent);
			} else {
				// register as a Vue component
				V.component(name, component);
			}
		});
	},
};

declare module "@vue/runtime-core" {
	// TODO: (filter components & add suffix) plugin based
	export interface GlobalComponents extends tPropertyMapping<typeof components, "xamu"> {}
}
@github-actions github-actions bot added the todo label Nov 19, 2023
@vis97c vis97c added enhancement New feature or request help wanted Extra attention is needed components Components pkgs scope labels Dec 25, 2023
@vis97c vis97c added the types Types related issue label Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
components Components pkgs scope enhancement New feature or request help wanted Extra attention is needed todo types Types related issue
Projects
None yet
Development

No branches or pull requests

1 participant