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

NEXT: Tailwind Plugin #2360

Closed
26 of 27 tasks
endigo9740 opened this issue Dec 26, 2023 · 10 comments
Closed
26 of 27 tasks

NEXT: Tailwind Plugin #2360

endigo9740 opened this issue Dec 26, 2023 · 10 comments
Assignees
Labels
enhancement New feature or request feature request Request a feature or introduce and update to the project.
Milestone

Comments

@endigo9740
Copy link
Contributor

endigo9740 commented Dec 26, 2023

This will act as a hub to centralize for this information.

See Also

The following updates will likely need to be handled in coordination.

Tailwind Directive Layers

  • base - global styles, resets, etc
  • components - for opt-in element styles, like .btn
  • utilities - general purpose utility classes
  • variants - to append new variants, like hover: and md:

Maintainer Requests

The following requests are coming straight from the Skeleton team. These are highly likely be implemented:

Design Tokens:

  • Revisit the token prefix/suffix concept after implementing with theme.extend
  • Design token background styles should follow Material Design's naming scheme (ex: Ghost -> Tonal)
  • The concept of "Variants" should be revisited; consider folding these into design tokens
  • We need to make the concept of "color pairings" more clear; lots of confusion around these

Tailwind Components (aka "Elements")

NOTE: expect many minor revisions to all element styles provided by Skeleton.

  • Revisit Input-Groups; these have never quite worked as expected
  • Revisit Button-Groups these have never quite worked as expected
  • The table component will be retired in favor of the Table elements; consider making this more piecemeal

Cookbook (replaces "Blocks")

  • Chat
  • Gradient Headings
  • Image Layouts
  • Scroll Containers

Community Requests

The following requests have come from the community and are under consideration:

Bugs and Issues

Feedback

If you have additional updates or requests for this feature, please do so in the comments section below.

@endigo9740 endigo9740 added enhancement New feature or request feature request Request a feature or introduce and update to the project. labels Dec 26, 2023
@endigo9740 endigo9740 added this to the v3.0 (Next) milestone Dec 26, 2023
@endigo9740 endigo9740 changed the title NEXT: Core package and Tailwind plugin improvements NEXT: Project Scaffolding Jan 3, 2024
@endigo9740 endigo9740 changed the title NEXT: Project Scaffolding NEXT: Tailwind Plugin Jan 3, 2024
@endigo9740 endigo9740 pinned this issue Jan 3, 2024
@Silvallis

This comment was marked as resolved.

@AdrianGonz97
Copy link
Member

AdrianGonz97 commented Jan 16, 2024

Follow-up after the discussion in this thread: https://discord.com/channels/1003691521280856084/1196891462302957608

A change we can do is to expose all of the preset themes in an ESM format (so that they are importable in the user's app) and change the plugin api that registers them.

So rather than doing this (current):

// tailwind.config.js

// user's custom themes
import { myCustomTheme1, myCustomTheme2 } from "./customThemes.js";

/** @type {import('tailwindcss').Config} */
export default {
	// ...
	plugins: [
		skeleton({
			themes: {
				custom: [
					myCustomTheme1,
					myCustomTheme2
				],
				preset: [
					{ name: 'crimson', enhancements: true },
					{ name: 'gold-nouveau', enhancements: true },
					{ name: 'hamlindigo', enhancements: true },
					{ name: 'modern', enhancements: true },
					{ name: 'rocket', enhancements: true },
					{ name: 'sahara', enhancements: true },
					{ name: 'seafoam', enhancements: true },
					{ name: 'skeleton', enhancements: true },
					{ name: 'vintage', enhancements: true },
					{ name: 'wintry', enhancements: true }
				]
			}
		})
	]
};

We can instead unify the api such that custom themes and presets are registered to the same interface (v3):

// tailwind.config.js

// they can all be imported via an import glob
import * as themes from "@skeletonlabs/skeleton/themes";
// or imported individually like so:
import { modern, rocket } from "@skeletonlabs/skeleton/themes";

// user's custom themes
import { myCustomTheme1, myCustomTheme2 } from "./customThemes.js";

/** @type {import('tailwindcss').Config} */
export default {
	// ...
	plugins: [
		skeleton({
			themes: [ 
				myCustomTheme1,
				myCustomTheme2,
				themes.crimson, 
				themes.goldNouveau, 
				themes.hamindigo,
				modern,
				rocket,
				// etc..
			]
		})
	]
};

@endigo9740
Copy link
Contributor Author

@AdrianGonz97 I love it. Huge quality of life improvement there because it's one less thing to think about. Themes are just themes. I've added it to the list in the OP.

@endigo9740

This comment was marked as resolved.

@AdrianGonz97

This comment was marked as resolved.

@endigo9740

This comment was marked as resolved.

@endigo9740

This comment was marked as resolved.

@endigo9740

This comment was marked as resolved.

@niktek
Copy link
Contributor

niktek commented Mar 13, 2024

In regards to the darkMode issue - basically we need TW to generate different sets of classes depending on the darkMode strategy selected (also note that there has been an update https://tailwindcss.com/docs/dark-mode#toggling-dark-mode-manually to the names). As this is a build time artefact and will be static for our end-users, we can create two TW configs here for embedding into the package.

Then on end-user load of the skeleton plugin, we need to get the darkMode setting for their project and use that to determine which generated CSSinJS module we import to pass back to TW.

TW does not pass the full config settings to the plugins, either via withOptions or by destructuring the theme on plugin init.

Considering the myriad of project setups/frameworks/monorepos etc that could come into play to try and find the tailwind config file to then parse, the safest option I can see is to parse the callStack and get the calling file from there:

in packages/skeleton/src/plugin/core.ts

export function getSkeletonClasses() {
	// try/catch because it will throw when generated-classes.js isn't generated yet
	try {
		const error = new Error();
		// Extract stack trace from the Error object
		const stackTrace = error.stack ?? 'not found';
		const regex = /at registerPlugins \(([^()]+?)\/node_modules/g;
		const match = regex.exec(stackTrace);
		let path = '';
		if (match) {
			path = match[1];
		}
		const config = readFileSync(path + '/tailwind.config.ts', 'utf-8');
		writeFileSync('/Users/Shared/blah.txt', path, 'utf-8'); //purely for debug as console.log is trapped in the child process 

		const { components, base } = require('./generated/generated-classes.cjs');

This returns an absolute path to the folder containing the tailwind.config for me on macOS node and bun. It needs further testing on other platforms etc.

We should then be able to import/parse it and get the mode to then know which generated file to return from above.

Gut feeling says it would be bad to require() the users tailwind config in case of side effects. It is also not guaranteed to just be 'selector' | 'media' as can be seen here

@endigo9740
Copy link
Contributor Author

@AdrianGonz97 @niktek we've completed pretty much everything slated for the Tailwind plugin in this ticket, minus the issues Nik brought up above. If you guys want to suss that out separately then please go for it. Feel free to create a standalone ticket.

To everyone -
We'll likely continue to tweak/adjust/add themes, CSS styles, etc., however I think we can consider the plugin to be in a solid place. As such I'm going to go ahead and close this ticket. This is a huge milestone towards v3, so thanks for all the help on this one!

@endigo9740 endigo9740 unpinned this issue Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature request Request a feature or introduce and update to the project.
Projects
None yet
4 participants