-
-
Notifications
You must be signed in to change notification settings - Fork 355
[Svelte] Introduce Svelte UX component #498
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
Conversation
that's really a great PR . as you said this could be simplified by mergin this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great - thanks for this! Before I do a deeper review, could you reorganize the directories to match, for example, the Autocomplete component? I'm talking specifically about having a src/
directory inside of the component and moving the assets into assets/
instead of Resources/assets
. We have some inconsistency right now and I'd like to move things to the way that Autocomplete looks. So we should just get this component organized like that from the start :)
Reorganization done :) I have issues setting up multiple tests in the same file with jest, Svelte seems not happy when the DOM is cleared before his $destroy method is called, and it crash when it happens two times in a row, haven't figured out why yet ... |
Hello. Any news on this? This PR looks amazing 😃 |
Sorry for the delay on this! @ChqThomas could you also update |
src/Svelte/doc/index.rst
Outdated
fullySpecified: false | ||
} | ||
} | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use Encore.enableSvelte()
now that it exists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the new Encore.enableSvelte()
works perfectly !
@weaverryan Thanks for the review, I added them ! Expected : Do you have any idea on how to handle both versions? |
You can just bump the minimum-required version of Encore in your |
Done 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great!
/.symfony.bundle.yaml export-ignore | ||
/assets/.gitignore export-ignore | ||
/assets/jest.config.js export-ignore | ||
/assets/test export-ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add:
/assets/src/*.ts export-ignore
That's a relatively new addition to the packages :)
src/Svelte/.symfony.bundle.yaml
Outdated
@@ -0,0 +1,3 @@ | |||
branches: ["2.x"] | |||
maintained_branches: ["2.x"] | |||
doc_dir: "src/Resources/doc" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc_dir: "src/Resources/doc" | |
doc_dir: "doc" |
src/Svelte/assets/package.json
Outdated
"controllers": { | ||
"svelte": { | ||
"main": "dist/render_controller.js", | ||
"webpackMode": "eager", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this line - it's legacy, so not needed for new stuff.
intro: this.intro, | ||
...payload, | ||
}; | ||
this.dispatch(name, { detail, prefix: 'svelte' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You even noticed this recent change in the other UX packages and updated this PR - I'm very impressed!
<script> | ||
import { fade } from "svelte/transition" | ||
|
||
export let name = "without props"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor, but can we use spaces here instead of tabs?
src/Svelte/doc/index.rst
Outdated
Svelte components located in the directory ``assets/svelte/controllers`` are registered as | ||
Svelte controller components. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the extra line break
src/Svelte/doc/index.rst
Outdated
Svelte controller components. | ||
|
||
|
||
You can then render any Svelte controller component in Twig using the ``svelte_component``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can then render any Svelte controller component in Twig using the ``svelte_component``. | |
You can then render any Svelte controller component in Twig using the ``svelte_component()`` function: |
The remove For Example:
below
src/Svelte/src/SvelteBundle.php
Outdated
* | ||
* @final | ||
* | ||
* @experimental |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove the @experimental
. I think we'll release this NOT as experimental.
src/Svelte/.gitignore
Outdated
/composer.lock | ||
/phpunit.xml | ||
/vendor/ | ||
/var/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is /var/
needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small comment for the docs. But I've tested this locally - it's ready to go :)
src/Svelte/doc/index.rst
Outdated
$ npm install svelte-loader@^3.0.0 --save-dev | ||
|
||
# or use yarn | ||
$ yarn add svelte-loader@^3.0.0 --dev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the version from both of these commands.
Also, add svelte
itself, as that will also be needed.
Great ! 😁 |
is this ready to be used? |
Hopefully soon! @weaverryan Should I start writing the example page for ux.symfony.com ? |
@ChqThomas Sorry for the delay! Yes please! I rebased your work over to #789 but will merge very shortly. Thank you! |
This PR introduces a UX Svelte component which allows to render Svelte components inside Twig templates, with the ability to pass down props to Svelte components from Twig. It is implemented in the same way as the UX React component and the UX Vue component for coherence.
svelte-loader
:Enable it in your
webpack.config.js
file :This part could be simplified by adding a.enableSvelteLoader()
method to the webpack-encore API.Now that symfony/webpack-encore#781 is merged you cas use
.enableSvelte()
registerSvelteControllerComponents
inapp.js
to register Svelte componentsHello.svelte
) inside the folder specified above (hereassets/svelte/controllers
)In the same way than the UX React and UX Vue components, there is a Twig helper function provided by the bundle : the first parameter is the name of your component, the second are the props that will be passed down :
There is also an optional third parameter called
intro
that tells the Svelte component to play transitions on initial renderThe implementation was heavily inspired by the work from @tgalopin in #329 and from @t-richard in #426 !