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

Add support for literal values in --value('…') and --modifier('…') #17304

Merged
merged 7 commits into from
Mar 20, 2025

Conversation

RobinMalfait
Copy link
Member

This PR adds support for literal values inside the --value('…') and --modifier('…') functions. This allows you to safelist some known values you want to use:

E.g.:

@utility tab-* {
  tab-size: --value('revert', 'initial');
}

This allows you to use tab-revert and tab-initial for example.

@RobinMalfait RobinMalfait requested a review from a team as a code owner March 20, 2025 15:01
@thecrypticace
Copy link
Contributor

Can we either add these to suggest() or make a note to do so later?

@RobinMalfait
Copy link
Member Author

Can we either add these to suggest() or make a note to do so later?

@thecrypticace good idea, added support for that 👍

values.push(value)
}
for (let value of designSystem.theme.keysInNamespaces(valueThemeKeys)) {
values.push(value.replaceAll('_', '.'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't we drop the .replaceAll(…) thing elsewhere in the codebase or no? I forget… I just remember something about that changing at some point

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm maybe? I copied it from the existing suggestions. Have to double check if this actually still matters or not. 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep is covered in the suggest function itself.

This was removed earlier, see `suggest()` function itself.
@RobinMalfait RobinMalfait enabled auto-merge (squash) March 20, 2025 19:01
@RobinMalfait RobinMalfait merged commit a3316f2 into main Mar 20, 2025
6 checks passed
@RobinMalfait RobinMalfait deleted the feat/allow-literal-in-modifier branch March 20, 2025 19:02
RobinMalfait added a commit that referenced this pull request Mar 20, 2025
…17308)

This PR adds suggestions to CSS based functional utilities when the
`--spacing(…)` function is used.

Given this CSS:

```css
@import "tailwindcss";

@theme {
  --spacing: 0.25rem;
  --spacing-custom: 123px;
}

@Utility with-custom-spacing-* {
  size: --value(--spacing);
}

@Utility with-integer-spacing-* {
  size: --spacing(--value(integer));
}

@Utility with-number-spacing-* {
  size: --spacing(--value(number));
}
```
    
And this HTML:
    
```html
<div class="with-custom-spacing-custom"></div>
<div class="with-custom-spacing-0"></div>
<div class="with-custom-spacing-0.5"></div>
<div class="with-custom-spacing-1"></div>
<div class="with-custom-spacing-1.5"></div>

<div class="with-integer-spacing-custom"></div>
<div class="with-integer-spacing-0"></div>
<div class="with-integer-spacing-0.5"></div>
<div class="with-integer-spacing-1"></div>
<div class="with-integer-spacing-1.5"></div>

<div class="with-number-spacing-custom"></div>
<div class="with-number-spacing-0"></div>
<div class="with-number-spacing-0.5"></div>
<div class="with-number-spacing-1"></div>
<div class="with-number-spacing-1.5"></div>
```
    
Play: https://play.tailwindcss.com/tYDaSNiNtS


Then you will see the following suggestions:

```json
[
  "with-custom-spacing-custom",

  "with-integer-spacing-0",
  "with-integer-spacing-1",
  "with-integer-spacing-2",
  "with-integer-spacing-3",
  "with-integer-spacing-4",
  "with-integer-spacing-5",
  "with-integer-spacing-6",
  "with-integer-spacing-7",
  "with-integer-spacing-8",
  "with-integer-spacing-9",
  "with-integer-spacing-10",
  "with-integer-spacing-11",
  "with-integer-spacing-12",
  "with-integer-spacing-14",
  "with-integer-spacing-16",
  "with-integer-spacing-20",
  "with-integer-spacing-24",
  "with-integer-spacing-28",
  "with-integer-spacing-32",
  "with-integer-spacing-36",
  "with-integer-spacing-40",
  "with-integer-spacing-44",
  "with-integer-spacing-48",
  "with-integer-spacing-52",
  "with-integer-spacing-56",
  "with-integer-spacing-60",
  "with-integer-spacing-64",
  "with-integer-spacing-72",
  "with-integer-spacing-80",
  "with-integer-spacing-96",

  "with-number-spacing-0",
  "with-number-spacing-0.5",
  "with-number-spacing-1",
  "with-number-spacing-1.5",
  "with-number-spacing-2",
  "with-number-spacing-2.5",
  "with-number-spacing-3",
  "with-number-spacing-3.5",
  "with-number-spacing-4",
  "with-number-spacing-5",
  "with-number-spacing-6",
  "with-number-spacing-7",
  "with-number-spacing-8",
  "with-number-spacing-9",
  "with-number-spacing-10",
  "with-number-spacing-11",
  "with-number-spacing-12",
  "with-number-spacing-14",
  "with-number-spacing-16",
  "with-number-spacing-20",
  "with-number-spacing-24",
  "with-number-spacing-28",
  "with-number-spacing-32",
  "with-number-spacing-36",
  "with-number-spacing-40",
  "with-number-spacing-44",
  "with-number-spacing-48",
  "with-number-spacing-52",
  "with-number-spacing-56",
  "with-number-spacing-60",
  "with-number-spacing-64",
  "with-number-spacing-72",
  "with-number-spacing-80",
  "with-number-spacing-96"
]
```

This is because `--spacing(--value(number))` will include all default
spacing scale suggestions we use. And `--pacing(--value(integer))` will
include the same list but without the floating point numbers.

Follow up PR for: #17304
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.

None yet

2 participants