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

feat(examples): add tailwind preset example #1344

Merged
merged 2 commits into from
Dec 8, 2024

Conversation

jessicalynch
Copy link
Contributor

@jessicalynch jessicalynch commented Sep 19, 2024

Adds example for building a Tailwind preset from tokens.

Screenshot 2024-11-19 at 5 27 30 PM

Original PR: #1036

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@jessicalynch jessicalynch requested a review from a team as a code owner September 19, 2024 04:38
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-1344.d16eby4ekpss5y.amplifyapp.com

Copy link
Collaborator

@jorenbroekema jorenbroekema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general, comments are pretty easy ones to address I think.

Thanks for taking the effort to rebase your earlier PR to SD v4 :) much appreciated.

examples/advanced/tailwind-preset/config.js Outdated Show resolved Hide resolved
examples/advanced/tailwind-preset/config.js Outdated Show resolved Hide resolved
examples/advanced/tailwind-preset/config/format.js Outdated Show resolved Hide resolved
examples/advanced/tailwind-preset/config/transform.js Outdated Show resolved Hide resolved
examples/advanced/tailwind-preset/package.json Outdated Show resolved Hide resolved
examples/advanced/tailwind-preset/package.json Outdated Show resolved Hide resolved
examples/advanced/tailwind-preset/README.md Show resolved Hide resolved
@JamesIves
Copy link
Contributor

JamesIves commented Nov 13, 2024

@jessicalynch Is there anything I can help with here to move this along? Keen to use this functionality so I don't mind contributing some of the remaining PR feedback!

@jessicalynch
Copy link
Contributor Author

@jessicalynch Is there anything I can help with here to move this along? Keen to use this functionality so I don't mind contributing some of the remaining PR feedback!

Hey, thanks, I should be able to push my updates this weekend. This is just an example, though, so feel free to use the pattern anytime!

Copy link
Collaborator

@jorenbroekema jorenbroekema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome job, just some final minor remarks, should be pretty easy to resolve. npx changeset locally with a minor bump would be appreciated, since this example is basically a new feature that would have to be released on NPM as well. If you're limited time-wise I can also resolve these things and wrap this PR up later this week, just let me know!

.editorconfig Outdated Show resolved Hide resolved
examples/advanced/tailwind-preset/README.md Outdated Show resolved Hide resolved
examples/advanced/tailwind-preset/README.md Outdated Show resolved Hide resolved
examples/advanced/tailwind-preset/config/transform.js Outdated Show resolved Hide resolved
@jessicalynch jessicalynch force-pushed the add-tailwind-example-v4 branch from 0bf2888 to b800806 Compare November 19, 2024 23:50
@jessicalynch
Copy link
Contributor Author

Awesome job, just some final minor remarks, should be pretty easy to resolve. npx changeset locally with a minor bump would be appreciated, since this example is basically a new feature that would have to be released on NPM as well. If you're limited time-wise I can also resolve these things and wrap this PR up later this week, just let me know!

Done- thank you for all the feedback!

Copy link
Collaborator

@jorenbroekema jorenbroekema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet!

I've also forwarded the GH markdown issue to my GH contact and he contacted the team responsible for markdown parsing to html rendering for GH, they'll probably pick it up at some point.

I've also raised #1396 to make sure we change the old formats to using tabs for v5 major when we get to that.

@dbanksdesign dbanksdesign merged commit 5aad797 into amzn:main Dec 8, 2024
5 checks passed
tkgroot pushed a commit to tkgroot/style-dictionary that referenced this pull request Dec 9, 2024
@kaelig
Copy link
Contributor

kaelig commented Dec 11, 2024

This example doesn't allow for alpha values to be passed.

Example: `bg-red/50' should have an opacity of 50% (documentation).

To do so, please add / <alpha-value> to the output.

Here's what the output should look like:

### themeColors.js

Tailwind theme color values that reference the plugin [css vars](https://tailwindcss.com/docs/customizing-colors#using-css-variables).

```js
export default {
	'sd-text-base': 'rgb(var(--sd-text-base) / <alpha-value>)',
	'sd-text-secondary': 'rgb(var(--sd-text-secondary) / <alpha-value>)',
	'sd-text-tertiary': 'rgb(var(--sd-text-tertiary) / <alpha-value>)',
	'sd-text-neutral': 'rgb(var(--sd-text-neutral))', // this one already has an opacity
	'sd-theme': 'rgb(var(--sd-theme) / <alpha-value>)',
	'sd-theme-light': 'rgb(var(--sd-theme-light) / <alpha-value>)',
	'sd-theme-dark': 'rgb(var(--sd-theme-dark) / <alpha-value>)',
	'sd-theme-secondary': 'rgb(var(--sd-theme-secondary) / <alpha-value>)',
	'sd-theme-secondary-dark': 'rgb(var(--sd-theme-secondary-dark) / <alpha-value>)',
	'sd-theme-secondary-light': 'rgb(var(--sd-theme-secondary-light) / <alpha-value>)',
};
```

@jessicalynch
Copy link
Contributor Author

jessicalynch commented Dec 11, 2024

This example doesn't allow for alpha values to be passed.

Example: `bg-red/50' should have an opacity of 50% (documentation).

To do so, please add / <alpha-value> to the output.

Here's what the output should look like:

### themeColors.js

Tailwind theme color values that reference the plugin [css vars](https://tailwindcss.com/docs/customizing-colors#using-css-variables).

```js
export default {
	'sd-text-base': 'rgb(var(--sd-text-base) / <alpha-value>)',
	'sd-text-secondary': 'rgb(var(--sd-text-secondary) / <alpha-value>)',
	'sd-text-tertiary': 'rgb(var(--sd-text-tertiary) / <alpha-value>)',
	'sd-text-neutral': 'rgb(var(--sd-text-neutral))', // this one already has an opacity
	'sd-theme': 'rgb(var(--sd-theme) / <alpha-value>)',
	'sd-theme-light': 'rgb(var(--sd-theme-light) / <alpha-value>)',
	'sd-theme-dark': 'rgb(var(--sd-theme-dark) / <alpha-value>)',
	'sd-theme-secondary': 'rgb(var(--sd-theme-secondary) / <alpha-value>)',
	'sd-theme-secondary-dark': 'rgb(var(--sd-theme-secondary-dark) / <alpha-value>)',
	'sd-theme-secondary-light': 'rgb(var(--sd-theme-secondary-light) / <alpha-value>)',
};

Hm.. it's working for the text-* classes, but I see it's not working for bg-* classes... will have to look into that.

Edit: it's working for me for bg-classes, too... I tried bg-sd-text-neutral/50 first, but that specific value already has an alpha value defined in the token. I can do some more investigation, though. Are you trying with the default tailwind red palette and having an issue with bg-red/50?

@jessicalynch
Copy link
Contributor Author

@kaelig, here's the tailwindcss reference I used- https://tailwindcss.com/docs/customizing-colors#using-css-variables

If using CSS variables, they suggest defining them as channels without the color space function:

  :root {
    --color-primary: 255 115 179;
    --color-secondary: 111 114 185;
  }
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
  colors: {
    primary: 'rgb(var(--color-primary))',
    secondary: 'rgb(var(--color-secondary))',
  }
}
}

...but I do remember seeing that <alpha-value> syntax and originally had it in this PR...

I wasn't able to find it again in the docs and realized the modifiers worked without it, so I removed it:

Screenshot 2024-12-11 at 6 38 09 PM Screenshot 2024-12-11 at 6 38 03 PM

@kaelig
Copy link
Contributor

kaelig commented Dec 12, 2024

That's what I did at Netlify to enable support for the alpha modifier.

Does the opacity modifier now work without alpha-value in the theme?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants