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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refactor Vue code snippets to use <script setup> #3070

Open
icarusgk opened this issue Aug 5, 2023 · 3 comments
Open

feat: refactor Vue code snippets to use <script setup> #3070

icarusgk opened this issue Aug 5, 2023 · 3 comments
Labels
content Issues related to the contents of the documentation website

Comments

@icarusgk
Copy link

icarusgk commented Aug 5, 2023

Describe Problem

Hello Ionic team! 馃槃
Most, if not all, of the current Vue code snippets are written in a verbose way.

<template>
  <ion-page>
    <ion-header>
      <ion-toolbar>
        <ion-title>Details</ion-title>
      </ion-toolbar>
    </ion-header>

    <ion-content> Detail ID: {{ id }} </ion-content>
  </ion-page>
</template>

<script lang="ts">
  import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar } from '@ionic/vue';
  import { defineComponent } from 'vue';
  import { useRoute } from 'vue-router';

  export default defineComponent({
    name: 'Detail',
    components: {
      IonContent,
      IonHeader,
      IonPage,
      IonTitle,
      IonToolbar,
    },
    setup() {
      const route = useRoute();
      const { id } = route.params;
      return { id };
    },
  });
</script>

Describe Preferred Solution

Vue 3 offers <script setup> a compile-time syntactic sugar which allows for more succinct code with less boilerplate. The above piece of code could be simplified as follows.

<template>
  <ion-page>
    <ion-header>
      <ion-toolbar>
        <ion-title>Details</ion-title>
      </ion-toolbar>
    </ion-header>

    <ion-content> Detail ID: {{ id }} </ion-content>
  </ion-page>
</template>

<script setup lang="ts">
  import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar } from '@ionic/vue';
  import { defineComponent } from 'vue';
  import { useRoute } from 'vue-router';
  
  const route = useRoute();
  const { id } = route.params;
</script>

Describe Alternatives

It is also possible to re-arrange the order of the tags to make the code snippet more readable.

<script setup lang="ts">
import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar } from '@ionic/vue';
import { defineComponent } from 'vue';
import { useRoute } from 'vue-router';
  
const route = useRoute();
const { id } = route.params;
</script>

<template>
  <ion-page>
    <ion-header>
      <ion-toolbar>
        <ion-title>Details</ion-title>
      </ion-toolbar>
    </ion-header>

    <ion-content> Detail ID: {{ id }} </ion-content>
  </ion-page>
</template>

Additional Information

I would like to offer my help to refactor said code snippets in case this feature request is approved 馃槃

@icarusgk icarusgk added the triage New issues label Aug 5, 2023
@mapsandapps mapsandapps added the content Issues related to the contents of the documentation website label Aug 7, 2023
@ionitron-bot ionitron-bot bot removed the triage New issues label Aug 7, 2023
@mapsandapps
Copy link
Contributor

Hi, thank you for submitting this issue! I've just merged a PR that refactors the snippets for some of the components to use <script setup>. We would like to get more refactored, so the examples will be more consistent throughout the docs.

I spoke with the team about this, and please note that for now, we are only interested in refactoring snippets that only have a setup function. For example, more complex snippets like this one should not be refactored at this time.

Also, at this time, we would like to keep the <template> tag above the <script> tag in the code, to keep it aligned with our vanilla JavaScript code samples and to keep it aligned with the Vue Ionic starter apps (that you create via ionic start) which are already using <script setup>.

@icarusgk
Copy link
Author

icarusgk commented Aug 7, 2023

that PR looks awesome! 馃憖 You're absolutely right, refactoring to target setup() function components makes perfect sense since the logic can easily be transferred to the <script setup> tag. And I agree with you, having the <template> tag first, just like in Vue Ionic starter apps, will definitely help keep things more consistent.

if you need any help or additional contributions for this PR, count me in! I'd be more than happy to lend a hand and collaborate with you on making this even better. Just let me know how I can assist.

@mapsandapps
Copy link
Contributor

mapsandapps commented Aug 16, 2023

Here is a list of all the docs sections that we would like to rewrite to use script setup syntax:

Components:

  • accordion I have this done in a branch
  • action-sheet I have this done in a branch
  • avatar
  • back-button
  • backdrop
  • badge
  • breadcrumbs
  • button
  • card
  • checkbox
  • chip
  • content
  • datetime
  • fab
  • footer
  • grid
  • header
  • icon
  • img
  • infinite-scroll
  • input
  • item
  • item-divider
  • item-group
  • item-sliding
  • label
  • list
  • list-header
  • loading
  • menu
  • nav (nav-link only, not modal-navigation)
  • note
  • picker
  • popover
  • progress-bar
  • radio
  • range
  • refresher
  • reorder
  • ripple-effect
  • searchbar
  • segment
  • segment-button
  • select
  • skeleton-text
  • spinner
  • split-pane
  • tabs
  • text
  • textarea
  • thumbnail
  • title
  • toast
  • toggle
  • toolbar

Other:

  • animations
  • gestures
  • keyboard
  • theming

Feel free to pick up one of these components to refactor to script setup, just leave a note here with the one you're working on.

Notes:

  • Changes should apply only to the current docs, not docs for Ionic Framework versions 5 or 6.
  • Complicated snippets (e.g. those with a methods object, like this one) should not be refactored for now.
  • For now, we are leaving the template tag above the script tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content Issues related to the contents of the documentation website
Projects
None yet
Development

No branches or pull requests

2 participants