Skip to content

Commit

Permalink
➕ Use plugwind.js
Browse files Browse the repository at this point in the history
  • Loading branch information
siguici committed Aug 11, 2024
1 parent b410b28 commit 2f51fd6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,8 @@
"vite": "^5.4.0",
"vite-tsconfig-paths": "^5.0.1",
"vitest": "^2.0.5"
},
"dependencies": {
"plugwind.js": "^0.4.1"
}
}
25 changes: 13 additions & 12 deletions plugin/plugger.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import type {
EdgeOptions,
LinkOptions,
PluginWithOptions,
PluginWithoutOptions,
RequiredEdgeOptions,
RequiredLinkOptions,
RequiredUIOptions,
UIOptions,
} from "./types";

import plugin from "tailwindcss/plugin";
import type { PluginAPI } from "tailwindcss/types/config";
import plug, {
type PluginAPI,
type PluginCreator,
type PluginCreatorWithOptions,
} from "plugwind.js";
import { Colors } from "./colors";
import { Edges } from "./edges";
import { Links } from "./links";
Expand All @@ -21,8 +22,8 @@ export const DEFAULT_OPTIONS: RequiredUIOptions = {
buttonClass: "button",
};

export function plugUI(): PluginWithOptions<UIOptions> {
return plugin.withOptions((options: UIOptions = DEFAULT_OPTIONS) => (api) => {
export function plugUI(): PluginCreatorWithOptions<UIOptions> {
return plug.with((options: UIOptions = DEFAULT_OPTIONS) => (api) => {
useColors(api);
useLinks(api, {
linkClass: options.linkClass || DEFAULT_OPTIONS.linkClass,
Expand All @@ -34,12 +35,12 @@ export function plugUI(): PluginWithOptions<UIOptions> {
});
}

export function plugColors(): PluginWithoutOptions {
return plugin((api) => useColors(api));
export function plugColors(): PluginCreator {
return plug((api) => useColors(api));
}

export function plugLinks(): PluginWithOptions<LinkOptions> {
return plugin.withOptions(
export function plugLinks(): PluginCreatorWithOptions<LinkOptions> {
return plug.with(
(
options: LinkOptions = {
linkClass: DEFAULT_OPTIONS.linkClass,
Expand All @@ -50,8 +51,8 @@ export function plugLinks(): PluginWithOptions<LinkOptions> {
);
}

export function plugEdges(): PluginWithOptions<EdgeOptions> {
return plugin.withOptions(
export function plugEdges(): PluginCreatorWithOptions<EdgeOptions> {
return plug.with(
(
options: EdgeOptions = {
entryClass: DEFAULT_OPTIONS.entryClass,
Expand Down
18 changes: 0 additions & 18 deletions plugin/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
import type { Config, PluginCreator } from "tailwindcss/types/config";
import type { ClassName } from "./styles";

export type PluginWithoutOptions =
| PluginCreator
| {
handler: PluginCreator;
config?: Partial<Config>;
};
export type PluginWithOptions<T> = {
(
options: T,
): {
handler: PluginCreator;
config?: Partial<Config> | undefined;
};
__isOptionsFunction: true;
};

export interface RequiredLinkOptions {
linkClass: ClassName;
}
Expand All @@ -38,5 +22,3 @@ export type DarkMode = [DarkModeStrategy, DarkModeQuery];

export * from "./styles";
export * from "./colors";

export default PluginWithOptions;
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2f51fd6

Please sign in to comment.