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(VDataTable): enhance data-table "color" prop #19700

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

cmgdragon
Copy link

@cmgdragon cmgdragon commented Apr 26, 2024

Description

Makes it easier to change the color of the selection checkboxes, the loader and the selected item in the pages dropdown.

The color prop in v-data-table is being underused. So far it's only changing the color of the header badges when multi-sort is enabled.

When I set the color prop it's because I want to customize the appareance of the table to match the desired color wherever it makes sense and not only to a very specific -almost hidden- part of it. It gives the feeling that the color prop isn't changing anything.

In V2 we had a checkboxColor prop for changing the color of the selection checkboxes, but I think this could be just handled by the color prop itself.

In addition, I have made the loader component follow the color while still respecting the value you pass to the loading prop if a color is provided.

Lastly I made the page dropdown also follow the color for the current page selected.

Using the color prop in these three addtional places will provide a quick look and feel customization of the data-tables enhancing the usage of the prop.

Markup:

<template>
  <v-app>
    <v-container>

      <div class="text-center">
        <v-btn
          :disabled="loading"
          append-icon="mdi-refresh"
          text="Refresh"
          @click="onClick"
        ></v-btn>
      </div>

      <v-data-table
        color="red-darken-3"
        :loading="loading"
        v-model="selected"
        :items="items"
        item-value="name"
        show-select
      ></v-data-table>

      <v-data-table
        color="#1A237E"
        :loading="loading"
        :group-by="groupBy"
        :headers="headers"
        :items="desserts"
        item-value="name"
        show-select
        v-model="selected2"
      >
        <template v-slot:group-header="{ item, columns, toggleGroup, isGroupOpen }">
          <tr>
            <td :colspan="columns.length">
              <VBtn
                :icon="isGroupOpen(item) ? '$expand' : '$next'"
                size="small"
                variant="text"
                @click="toggleGroup(item)"
              ></VBtn>
              {{ item.value ? 'Contains gluten' : 'Gluten free' }}
            </td>
          </tr>
        </template>
      </v-data-table>

    </v-container>
  </v-app>
</template>

<script setup>
  import { ref } from 'vue'

  const loading = ref(false)

  function onClick () {
    loading.value = true
    setTimeout(() => {
      loading.value = false
    }, 2000)
  }

  const selected = ref([])
  const selected2 = ref([])
  const items = [
    {
      name: '馃崕 Apple',
      location: 'Washington',
      height: '0.1',
      base: '0.07',
      volume: '0.0001',
    },
    {
      name: '馃崒 Banana',
      location: 'Ecuador',
      height: '0.2',
      base: '0.05',
      volume: '0.0002',
    },
    {
      name: '馃崌 Grapes',
      location: 'Italy',
      height: '0.02',
      base: '0.02',
      volume: '0.00001',
    }
  ]

  const groupBy = ref([
    {
      key: 'gluten',
      order: 'asc',
    },
  ])

  const headers = [
    {
      title: 'Dessert (100g serving)',
      align: 'start',
      sortable: false,
      key: 'name',
    },
    { title: 'Calories', key: 'calories' },
    { title: 'Fat (g)', key: 'fat' },
    { title: 'Carbs (g)', key: 'carbs' },
    { title: 'Protein (g)', key: 'protein' },
    { title: 'Iron (%)', key: 'iron' },
  ]
  const desserts = [
    {
      name: 'Frozen Yogurt',
      calories: 159,
      fat: 6,
      carbs: 24,
      protein: 4,
      iron: '1%',
      gluten: false,
    },
    {
      name: 'Ice cream sandwich',
      calories: 237,
      fat: 9,
      carbs: 37,
      protein: 4.3,
      iron: '1%',
      gluten: false,
    },
    {
      name: 'Eclair',
      calories: 262,
      fat: 16,
      carbs: 23,
      protein: 6,
      iron: '7%',
      gluten: true,
    },
    {
      name: 'Cupcake',
      calories: 305,
      fat: 3.7,
      carbs: 67,
      protein: 4.3,
      iron: '8%',
      gluten: true,
    },
  ]
</script>

@cmgdragon cmgdragon force-pushed the feat/v-data-table-color-prop-enhance branch from 2a5765a to 58c93b9 Compare April 26, 2024 12:40
@cmgdragon cmgdragon force-pushed the feat/v-data-table-color-prop-enhance branch from 2fc7a09 to 8e4489b Compare April 27, 2024 17:48
@MajesticPotatoe MajesticPotatoe added T: feature A new feature C: VDataTable VDatatable labels Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: VDataTable VDatatable T: feature A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants