lukejacksonn / oceanwind

Compiles tailwind shorthand into css at runtime. Succeeded by Twind.
https://twind.dev
264 stars 12 forks source link

Accept input as an array, string, literal or object #20

Closed lukejacksonn closed 3 years ago

lukejacksonn commented 3 years ago

Fixes #13

Perviously it was only possible to invoke oceanwind via a tagged template literal with no dynamic parts (or mimicking this with oceanwind([rules])). The changes here allows for oceanwind to be invoked in 4 ways:

  1. Tag Template Literal
ow`bg-red-500 rounded`;
ow`bg-red-500 ${false && 'rounded'}`; // falsey interpolations will be omitted
  1. Function call passing a string
ow('bg-red-500 rounded');
  1. Function call passing an array
ow(['bg-red-500', 'rounded']);
ow(['bg-red-500', false && 'rounded']); // falsey items will be omitted
  1. Function call passing an object
ow({ 'bg-red-500': true, rounded: false }); // keys with falsey values will be omitted

The first improvement is the dynamic parts. The second, being able to pass strings without having to wrap in an array. The last is being able to pass rules or rule sets that are to be applied conditionally (kinda like clsx).

Still need to update the README to document this change.

bebraw commented 3 years ago

Does the second option cover for applying multiple class names? I have an array of strings and I then apply Oceanwind against that. I imagine it would be ow(classes.split(' ')) which isn't bad.

If that's possible, big 👍 then.

lukejacksonn commented 3 years ago

I was trying to account for your case whereby you were inputting classes.join(' ') but perhaps I misunderstood and actually you wanted to input an array without having to join it into a string.

I'm already using an array check to infer a template literal being used, so it might conflict 🤔

bebraw commented 3 years ago

@lukejacksonn Yeah, so at the moment I do some tricks to adapt to your API. The ideal would be if it accepted an array of strings out of the box but I can also resolve my data to any form that the API accepts.

From my point of view, ow(['bg-red-500', 'p-4']) would likely be the ideal as then I wouldn't have to transform the data at all.

lukejacksonn commented 3 years ago

Ok, well it turns out I got this all wrong anyway so I'm going to start a fresh. Will be back with a solution shortly.

bebraw commented 3 years ago

@lukejacksonn No worries, ping me if you need any help. 👍

bebraw commented 3 years ago

The proposed API looks great.

lukejacksonn commented 3 years ago

Great! Well I'm happy with the additional flexibility and it wasn't that hard to support all these other variants either. Thanks for creating the issue and reviewing 🙇