From d4096c6351eb6c55a5f56b70fc5a4aa8bb78b356 Mon Sep 17 00:00:00 2001 From: SutuSebastian Date: Tue, 15 Oct 2024 13:08:18 +0300 Subject: [PATCH] expose all plugin internals --- packages/ui/package.json | 10 +++++----- packages/ui/src/tailwind/config.ts | 18 ++++++++++++++++++ packages/ui/src/tailwind/index.ts | 10 ++-------- 3 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 packages/ui/src/tailwind/config.ts diff --git a/packages/ui/package.json b/packages/ui/package.json index ee84f9931..da1b40c62 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -40,16 +40,16 @@ "import": "./dist/esm/hooks/*/index.mjs", "require": "./dist/cjs/hooks/*/index.cjs" }, - "./tailwind": { - "types": "./dist/types/tailwind/index.d.ts", - "import": "./dist/esm/tailwind/index.mjs", - "require": "./dist/cjs/tailwind/index.cjs" - }, "./tailwind/*": { "types": "./dist/types/tailwind/*.d.ts", "import": "./dist/esm/tailwind/*.mjs", "require": "./dist/cjs/tailwind/*.cjs" }, + "./tailwind": { + "types": "./dist/types/tailwind/index.d.ts", + "import": "./dist/esm/tailwind/index.mjs", + "require": "./dist/cjs/tailwind/index.cjs" + }, "./package.json": "./package.json" }, "main": "dist/cjs/index.cjs", diff --git a/packages/ui/src/tailwind/config.ts b/packages/ui/src/tailwind/config.ts new file mode 100644 index 000000000..da5ba9d45 --- /dev/null +++ b/packages/ui/src/tailwind/config.ts @@ -0,0 +1,18 @@ +import { theme } from "./theme"; +import type { PluginOptions } from "./types"; +import { resolveClassList, resolvePrefix } from "./utils"; + +import type { Config } from "tailwindcss"; + +export function getConfig(options: PluginOptions = {}): Partial { + return { + safelist: getSafelist(options), + theme: { + extend: theme, + }, + }; +} + +export function getSafelist(options: PluginOptions = {}): Config["safelist"] { + return resolvePrefix(resolveClassList(options.components), options.prefix, options.separator); +} diff --git a/packages/ui/src/tailwind/index.ts b/packages/ui/src/tailwind/index.ts index b0826cea3..b6f4bc8a4 100644 --- a/packages/ui/src/tailwind/index.ts +++ b/packages/ui/src/tailwind/index.ts @@ -1,16 +1,10 @@ import plugin from "tailwindcss/plugin"; -import { theme } from "./theme"; +import { getConfig } from "./config"; import { PluginOptions } from "./types"; -import { resolveClassList, resolvePrefix } from "./utils"; export default plugin.withOptions( // plugin () => () => {}, // config - ({ prefix, separator, components } = {}) => ({ - safelist: resolvePrefix(resolveClassList(components), prefix, separator), - theme: { - extend: theme, - }, - }), + (options) => getConfig(options), );