Commit Graph

1417 Commits

Author SHA1 Message Date
Fabien Potencier 7a4f6ea6ff Update docs 2024-08-23 09:25:12 +02:00
Fabien Potencier 787aaed923 Remove versionadded in docs 2024-08-18 17:54:42 +02:00
Fabien Potencier d9f52db503 Merge branch '3.x' into 4.x
* 3.x:
  Fix typos in CHANGELOG
2024-08-18 17:54:12 +02:00
Fabien Potencier 84116e5ff7 Fix typos in CHANGELOG 2024-08-18 17:52:16 +02:00
Fabien Potencier 3f99f250d7 Remove versionadded in docs 2024-08-18 09:41:01 +02:00
Fabien Potencier 9e48502555 Merge branch '3.x' into 4.x
* 3.x:
  Fix html_cva docs
  Fix html_cva docs
  Introduce CVA to html-extra
  Move some methods to static calls
2024-08-18 09:40:33 +02:00
Fabien Potencier 1d5a8dc98b Fix html_cva docs 2024-08-18 09:38:48 +02:00
Fabien Potencier e85519fcd9 Fix html_cva docs 2024-08-18 09:38:02 +02:00
Fabien Potencier 0bfef5b300 feature #4006 Introduce CVA to html-extra (WebMamba)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Introduce CVA to html-extra

Hey! This PR introduces CVA to Twig. All of this has already been merged into SymfonyUX (https://github.com/symfony/ux/pull/1416), but `@kbond` suggested that this repo can be a better place for this feature.

Here is a description from the PR merged in to SymfonyUX:

------------------------------

This PR introduces a new concept CVA (Class Variance Authority), by adding a1 twig function, to help you manage your class in your component.

Let's take an example an Alert component. In your app, an alert can have a lot of different styles one for success, one for alert, one for warning, and different sizes, with icons or not... You need something that lets you completely change the style of your component without creating a new component, and without creating too much complexity in your template.

Here is the reason came CVA.

Your Alert component can now look like this:

```twig
{% props color = 'blue', size = 'md' %}

{% set alert =  html_cva(
      'alert rounded-lg',
     {
        color: {
            blue: 'text-blue-800 bg-blue-50 dark:bg-gray-800 dark:text-blue-400',
            red: 'text-red-800 bg-red-50 dark:bg-gray-800 dark:text-red-400',
            green: 'text-green-800 bg-green-50 dark:bg-gray-800 dark:text-green-400',
            yellow: 'text-yellow-800 bg-yellow-50 dark:bg-gray-800 dark:text-yellow-400',
        },
        size: {
            sm: 'px-4 py-3 text-sm',
            md: 'px-6 py-4 text-base',
            lg: 'px-8 py-5 text-lg',
        }
    },
    [{
           color: ['red'],
           size: ['lg'],
          class: 'font-semibold'
    }],
   {
           rounded: 'md'
    }
}) %}

<div class="{{ cva.apply({color, size}, attribute.render('class'), 'flex p-4') }}">
    ...
</div>
```

So here you have a `cva` function that lets you define different variants of your component.

You can now use your component like this:
```twig
<twig:Alert color="red" size="md"/>

<twig:Alert color="green" size="sm"/>

<twig:Alert color="yellow" size="lg"/>

<twig:Alert color="red" size="md" class="dark:bg-gray-800"/>
```

And then you get the following result:

<img width="1269" alt="Capture d’écran 2024-01-24 à 00 52 33" src="https://github.com/symfony/ux/assets/32077734/6a5e25be-5b81-4ae7-8385-0fa5422d0396">

If you want to know more about the concept I implement here you can look at:
- CVA (js version): https://cva.style/docs
- tailwind merge: https://github.com/gehrisandro/tailwind-merge-php, https://github.com/dcastil/tailwind-merge
- this implementation by using tailwind-merge and cva is inspired a lot by: https://ui.shadcn.com/ (shadcn is the most starred library on github in 2023)
- a really good article that explains the philosophy behind https://manupa.dev/blog/anatomy-of-shadcn-ui
- this PR works great in a LASTstack: https://symfonycasts.com/screencast/last-stack/last-stack

Tell me what you think about it! Thanks for your time! Cheers 🧡

------------

Commits
-------

e3ac14e1 Introduce CVA to html-extra
2024-08-18 09:36:20 +02:00
Matheo Daninos e3ac14e1c8 Introduce CVA to html-extra 2024-08-18 09:36:16 +02:00
Simon André 21f08dcfe2 Add return types missed in #4211 2024-08-17 23:34:44 +02:00
Fabien Potencier 22ff3f4f22 Merge branch '3.x' into 4.x
* 3.x:
  Fix typos in CHANGELOG
  Fix typo
  Fix some minor issues
  Add support for named arguments on special functions
2024-08-17 18:03:35 +02:00
Fabien Potencier dbc934ba78 Fix typo 2024-08-17 11:28:14 +02:00
Fabien Potencier 0c30e78b1c Add support for named arguments on special functions 2024-08-16 08:37:24 +02:00
Fabien Potencier 3156d8093e Move FunctionExpression/FilterExpression/TestExpression attributes from compilation time to parsing time 2024-08-14 18:45:35 +02:00
Fabien Potencier 91f29731d4 Merge branch '3.x' into 4.x
* 3.x:
  Optimize stripcslashes
  (minor) Prefer `className` over `classname`
  Remove escape
  Deprecate unnecessary escape characters
  Micro-micro optimization
  Simplify tests
2024-08-12 09:28:43 +02:00
Ruud Kamphuis c6656cf5d0 Deprecate unnecessary escape characters
See #4123 #2712

This allows to change the implementation in v4 so that we no longer have to escape backslashes.
2024-08-11 16:21:05 +02:00
Fabien Potencier 4a2fb5b460 Merge branch '3.x' into 4.x
* 3.x:
  Add the notion of a Twig callable
  Drop support for 8.0
  Add more tests to the Lexer
  Add a note about how to escape a string interpolation in a string
  Bump version to 3.12
  Implement the enum_cases function
  Remove deprecation arg
  Fix integration tests when a test has more than on data/expect section and deprecations
  Bump version
  Prepare the 3.11.0 release
  Update CHANGELOG
2024-08-10 18:01:24 +02:00
Fabien Potencier c070cd719c Drop support for 8.0 2024-08-10 12:32:24 +02:00
Fabien Potencier 346749b8c1 minor #4189 Add a note about how to escape a string interpolation in a string (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Add a note about how to escape a string interpolation in a string

Commits
-------

38e47a3e Add a note about how to escape a string interpolation in a string
2024-08-10 12:19:46 +02:00
Fabien Potencier 38e47a3e94 Add a note about how to escape a string interpolation in a string 2024-08-10 11:32:28 +02:00
Christophe Coevoet ff4d01f940 Implement the enum_cases function
The implementation contains an optimized implementation of the function
for the common case of using a string literal as the argument. It will
validate the enum existence during compilation and compile the code to
use `MyEnum::cases()` directly.
2024-08-09 21:21:58 +02:00
Fabien Potencier fbc1032fd0 Remove versionadded from docs 2024-08-08 14:47:37 +02:00
Fabien Potencier eafbee52e3 Merge branch '3.x' into 4.x
* 3.x:
  Use trigger_deprecation() instead of trigger_error() for deprecations
  Tweak docs
  clarify that macros shadow other macros/functions
2024-08-08 14:47:26 +02:00
Fabien Potencier 90fbb9acbc feature #4183 Add support for package/version on deprecations (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Add support for package/version on deprecations

Commits
-------

0ce79df5 Use trigger_deprecation() instead of trigger_error() for deprecations
2024-08-08 14:46:03 +02:00
Fabien Potencier 0ce79df5c4 Use trigger_deprecation() instead of trigger_error() for deprecations 2024-08-08 14:28:28 +02:00
Fabien Potencier 839da16d04 Tweak docs 2024-08-08 11:12:39 +02:00
Christian Flothmann e1a9448190 clarify that macros shadow other macros/functions 2024-08-08 09:25:31 +02:00
Fabien Potencier a159617f3c Merge branch '3.x' into 4.x
* 3.x:
  Add a recipe about how to mark a node as safe
  Mark ConstantExpression as @final
2024-08-07 21:02:32 +02:00
Fabien Potencier 230e31d384 Add a recipe about how to mark a node as safe 2024-08-07 21:01:18 +02:00
Fabien Potencier 2be34fc0ce Merge branch '3.x' into 4.x
* 3.x:
  Introduce ChainCache and ReadOnlyFilesystemCache
  Add a note about how macros can override existing functions
  Fix dumping callables on Node::__toString()
2024-08-07 14:41:48 +02:00
Fabien Potencier cea1714331 Add a note about how macros can override existing functions 2024-08-07 11:25:44 +02:00
Fabien Potencier 0707f16cf3 Merge branch '3.x' into 4.x
* 3.x:
  Add new "find" filter
2024-08-04 13:40:16 +02:00
Simon André 4e26251193 Add new "find" filter 2024-08-04 13:39:10 +02:00
Fabien Potencier bc11e375f6 Simplify accessing outer loop objects example 2024-07-28 10:33:30 +02:00
Fabien Potencier e19f056326 feature #4153 Add support for recursive loops (fabpot)
This PR was squashed before being merged into the 4.x branch.

Discussion
----------

Add support for recursive loops

Fixes #3416
Fixes #4144

Commits
-------

481e7f0d Prevent infinite loops
fa1a217f Add another test
036c9943 Don't unset loop when it's not defined
1b9baa76 Remove usage of the internal _parent context variable in loops
c28f68f8 Add support for Escaper and Sandbox for Generator nodes
c1933323 Simplify implementation
8c5dd39b Use loop() to recurse instead of loop.recurse()
e95d6b2f Add support for recursive loops
2024-07-28 10:21:08 +02:00
Fabien Potencier de7767814b Remove deprecate feature in docs 2024-07-28 10:14:39 +02:00
Fabien Potencier c097774d99 Remove deprecated code 2024-07-28 10:14:26 +02:00
Fabien Potencier e95d6b2f21 Add support for recursive loops 2024-07-28 10:08:35 +02:00
Fabien Potencier 69f9367573 Remove a feature from the future 2024-07-28 10:04:03 +02:00
Fabien Potencier d6add5ebde Reorganize the for tag docs 2024-07-28 10:01:20 +02:00
Fabien Potencier 3c52cd9814 feature #4148 Deprecate NameExpression internal methods (smnandre)
This PR was merged into the 3.x branch.

Discussion
----------

Deprecate NameExpression internal methods

Deprecate two methods from `Twig\Node\Expression\NameExpression`:
* `isSimple()`: did not find any usage in Twig (or even Symfony) repositories
* `isSpecial()`: inlined for better performance ($name is available in the method)

Commits
-------

3531f959 Deprecate NameExpression internal methods
2024-07-27 15:43:19 +02:00
Simon André 343fefae10 [Doc] Fix code syntax in deprecated.rst
Add missing backticks
2024-07-27 14:21:54 +02:00
Fabien Potencier 76dcc75982 Merge branch '3.x' into 4.x
* 3.x:
  Replace template loader mocks by ArrayLoader
  [Doc] Fix javascript code-block
2024-07-24 09:53:24 +02:00
Simon André 3531f959d3 Deprecate NameExpression internal methods
Deprecate two methods from NameExpression:
* isSimple(): did not find any usage in Twig (or even Symfony) repositories
* isSpecial(): inlined for better performance ($name is available in the method)
2024-07-22 01:25:30 +02:00
Simon André b0cd5dc5a8 [Doc] Fix javascript code-block
Fix code-block syntax (double space)
2024-07-21 21:05:07 +02:00
Tomas 934439ac4e Fix doc 2024-07-17 14:46:39 +03:00
Fabien Potencier 4afc66cc82 Merge branch '3.x' into 4.x
* 3.x:
  Make compatible with PHP<8
  Extract ReflectionCallable to make it reusable
  Make a small optimization
  [Doc] Fix `do` tag label in link
2024-07-14 12:17:41 +02:00
Fabien Potencier 55b414c497 Add more precise types 2024-07-12 18:05:50 +02:00
Fabien Potencier 65b4ea4394 Add loop.changed, loop.previous, loop.next, and loop.cycle variables 2024-07-12 11:13:02 +02:00