From ea15e21cdcba00e21302415829113e8c6def8a6e Mon Sep 17 00:00:00 2001 From: Stijn Slats <47820758+stijns96@users.noreply.github.com> Date: Thu, 26 Dec 2024 11:11:02 +0100 Subject: [PATCH] feat(module): handle `tailwindMerge` config from `app.config` (#2902) Co-authored-by: Benjamin Canac --- docs/content/1.getting-started/3.theming.md | 46 +++++++++++++++++++ src/module.ts | 2 + src/runtime/components/data/Table.vue | 2 +- src/runtime/components/elements/Alert.vue | 4 +- src/runtime/components/elements/Avatar.vue | 4 +- .../components/elements/AvatarGroup.ts | 4 +- src/runtime/components/elements/Badge.vue | 4 +- src/runtime/components/elements/Button.vue | 4 +- .../components/elements/ButtonGroup.ts | 4 +- src/runtime/components/elements/Carousel.vue | 3 +- src/runtime/components/elements/Dropdown.vue | 4 +- src/runtime/components/elements/Kbd.vue | 4 +- src/runtime/components/elements/MeterGroup.ts | 2 +- src/runtime/components/forms/Checkbox.vue | 4 +- src/runtime/components/forms/Input.vue | 4 +- src/runtime/components/forms/InputMenu.vue | 4 +- src/runtime/components/forms/Radio.vue | 4 +- src/runtime/components/forms/RadioGroup.vue | 2 +- src/runtime/components/forms/Range.vue | 4 +- src/runtime/components/forms/Select.vue | 4 +- src/runtime/components/forms/SelectMenu.vue | 4 +- src/runtime/components/forms/Textarea.vue | 4 +- src/runtime/components/forms/Toggle.vue | 4 +- src/runtime/components/layout/Card.vue | 4 +- src/runtime/components/layout/Container.vue | 4 +- src/runtime/components/layout/Divider.vue | 4 +- src/runtime/components/layout/Skeleton.vue | 4 +- .../components/navigation/Breadcrumb.vue | 4 +- .../navigation/HorizontalNavigation.vue | 4 +- .../navigation/VerticalNavigation.vue | 4 +- .../components/overlays/ContextMenu.vue | 4 +- .../components/overlays/Notification.vue | 4 +- .../components/overlays/Notifications.vue | 4 +- src/runtime/utils/index.ts | 8 ++-- 34 files changed, 111 insertions(+), 62 deletions(-) diff --git a/docs/content/1.getting-started/3.theming.md b/docs/content/1.getting-started/3.theming.md index 9fe689a0..8ff1be46 100644 --- a/docs/content/1.getting-started/3.theming.md +++ b/docs/content/1.getting-started/3.theming.md @@ -221,6 +221,52 @@ export default defineAppConfig({ }) ``` +### Extend Tailwind Merge + +Tailwind Merge is a library that allows you to efficiently merge Tailwind CSS classes. It is used by this module to merge the classes from the `ui` prop, the `class` attribute, and the default classes. + +::callout{icon="i-heroicons-light-bulb" to="https://github.com/dcastil/tailwind-merge" target="_blank"} +Learn more about Tailwind Merge. +:: + +By default, Tailwind Merge doesn't handle custom Tailwind CSS configuration like custom colors, spacing, or other utilities you may have defined. You'll need to extend it to handle your custom configuration. + +You can extend Tailwind Merge by using the `tailwindMerge` option in your `app.config.ts`: + +::code-group +```ts [app.config.ts] +export default defineAppConfig({ + ui: { + tailwindMerge: { + extend: { + theme: { + spacing: ['sm', 'md', 'lg', 'xl', '2xl'] + } + } + } + } +}) +``` + +```ts [tailwind.config.ts] +import type { Config } from 'tailwindcss' + +export default >{ + theme: { + extend: { + spacing: { + sm: '0.5rem', + md: '1rem', + lg: '1.5rem', + xl: '2rem', + '2xl': '2.5rem' + } + } + } +} +``` +:: + ## Dark mode All the components are styled with dark mode in mind. diff --git a/src/module.ts b/src/module.ts index f5d36f5d..928d0904 100644 --- a/src/module.ts +++ b/src/module.ts @@ -1,5 +1,6 @@ import { createRequire } from 'node:module' import { defineNuxtModule, installModule, addComponentsDir, addImportsDir, createResolver, addPlugin } from '@nuxt/kit' +import type { ConfigExtension, DefaultClassGroupIds, DefaultThemeGroupIds } from 'tailwind-merge' import { name, version } from '../package.json' import createTemplates from './templates' import type * as config from './runtime/ui.config' @@ -20,6 +21,7 @@ type UI = { gray?: string colors?: string[] strategy?: Strategy + tailwindMerge?: ConfigExtension [key: string]: any } & DeepPartial diff --git a/src/runtime/components/data/Table.vue b/src/runtime/components/data/Table.vue index 07d1e4ea..57c9906f 100644 --- a/src/runtime/components/data/Table.vue +++ b/src/runtime/components/data/Table.vue @@ -144,7 +144,7 @@ import UButton from '../elements/Button.vue' import UProgress from '../elements/Progress.vue' import UCheckbox from '../forms/Checkbox.vue' import { useUI } from '../../composables/useUI' -import { mergeConfig, get } from '../../utils' +import { get, mergeConfig } from '../../utils' import type { TableRow, TableColumn, Strategy, Button, ProgressColor, ProgressAnimation, DeepPartial, Expanded } from '../../types/index' // @ts-expect-error import appConfig from '#build/app.config' diff --git a/src/runtime/components/elements/Alert.vue b/src/runtime/components/elements/Alert.vue index f3be56e4..4d038855 100644 --- a/src/runtime/components/elements/Alert.vue +++ b/src/runtime/components/elements/Alert.vue @@ -42,13 +42,13 @@