Skip to content

[Vue] UX Vue.js example for ux.symfony.com #439

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

Merged
merged 1 commit into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ux.symfony.com/assets/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { registerReactControllerComponents } from '@symfony/ux-react';

import {registerVueControllerComponents} from "@symfony/ux-vue";

// any CSS you import will output into a single css file (app.css in this case)
import './styles/app.scss';
Expand All @@ -14,3 +14,4 @@ import Tab from 'bootstrap/js/dist/tab';

// initialize symfony/ux-react
registerReactControllerComponents(require.context('./react/controllers', true, /\.(j|t)sx?$/));
registerVueControllerComponents(require.context('./vue/controllers', true, /\.vue?$/));
6 changes: 6 additions & 0 deletions ux.symfony.com/assets/controllers.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
"enabled": true,
"fetch": "eager"
}
},
"@symfony/ux-vue": {
"vue": {
"enabled": true,
"fetch": "eager"
}
}
},
"entrypoints": []
Expand Down
Binary file added ux.symfony.com/assets/images/vue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions ux.symfony.com/assets/vue/components/PackageList.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<template>
<div v-if="packages.length === 0" class="alert alert-info">Sad trombone... we haven't built any components that
match this search yet!
</div>

<div v-else class="row">
<a
v-for="uxPackage in packages"
:href="uxPackage.url"
class="col-12 col-md-4 col-lg-3 mb-2"
>
<div class="components-container p-2">
<div class="d-flex">
<div
class="live-component-img d-flex justify-content-center align-items-center"
:style="{background: uxPackage.gradient}">
<img width="17" height="17"
:src="uxPackage.imageUrl"
:alt="`Image for the ${uxPackage.humanName} UX package`"
/>
</div>
<h4 class="ubuntu-title ps-2 align-self-center">
{{ uxPackage.humanName }}
</h4>
</div>
</div>
</a>
</div>
</template>

<script setup>
defineProps({
packages: Array,
});
</script>
31 changes: 31 additions & 0 deletions ux.symfony.com/assets/vue/controllers/PackageSearch.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<template>
<div>
<input
v-model="search"
class="form-control"
type="search"
placeholder="This search is built in Vue!"
/>

<div class="mt-3">
<PackageList :packages="filteredPackages" />
</div>
</div>
</template>

<script setup>
import { computed, ref } from 'vue';
import PackageList from "../components/PackageList";

const props = defineProps({
packages: Array,
});

const search = ref('');

const filteredPackages = computed(() => {
return props.packages.filter(
uxPackage => uxPackage.humanName.toLowerCase().includes(search.value.toLowerCase())
);
});
</script>
28 changes: 28 additions & 0 deletions ux.symfony.com/code_snippets/_PackageSearch.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<template>
<div>
<input v-model="search" />

<div class="row">
<a v-for="uxPackage in filteredPackages" :href="uxPackage.url">
<img :src="uxPackage.imageUrl" />
<h4>{{ uxPackage.humanName }}</h4>
</a>
</div>
</div>
</template>

<script setup>
import { computed, ref } from 'vue';

const props = defineProps({
packages: Array,
});

const search = ref('');

const filteredPackages = computed(() => {
return props.packages.filter(
uxPackage => uxPackage.humanName.includes(search.value)
);
});
</script>
11 changes: 11 additions & 0 deletions ux.symfony.com/code_snippets/_vue.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{#
"PackageSearch" mounts assets/vue/controllers/PackageSearch.vue.

"packagesData" is dynamic data, which becomes the "packages" prop!
#}

<div {{ vue_component('PackageSearch', {
packages: packagesData
}) }}>
Loading... <i class="fas fa-cog fa-spin fa-3x"></i>
</div>
1 change: 1 addition & 0 deletions ux.symfony.com/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"symfony/ux-turbo-mercure": "2.x-dev",
"symfony/ux-twig-component": "2.x-dev",
"symfony/ux-typed": "2.x-dev",
"symfony/ux-vue": "2.x-dev",
"symfony/validator": "6.0.*",
"symfony/webpack-encore-bundle": "^1.14",
"symfony/yaml": "6.0.*",
Expand Down
Loading