0.1.88 • Published 4 days ago

@s3_dse/v-tail-vue3 v0.1.88

Weekly downloads
-
License
MIT
Repository
github
Last release
4 days ago

v-tail-vue3

A component library for Vue 3 using Tailwind CSS.

Installation

Install the library via npm install --save @s3_dse/v-tail-vue3.

Add the following to your entry point (e.g. main.js):

import VTail from '@s3_dse/v-tail-vue3'

import { createApp } from 'vue'
import App from './App.vue'
const app = createApp(App)
app.use(VTail)

app.mount('#app')

Components

Table Component

A table that supports

  • filtering
  • pagination
  • custom column and cell rendering
  • fixed top row(s) (e.g. for comparisons)
  • fixed bottom row(s) (e.g. for summaries)

Usage

We will use the following lines to illustrate the usage of the table component:

<template>
    <table-component
        title="A Table"
        :items="data"
        :top-rows="topRows"
        :bottom-rows="summaryRows"
        :fields="header"
        :paginate="true"
        :configurablePageSize="true"
        :per-page="5"
        @after-sort="afterSort"
        @after-page-change="afterPageChange"
        @after-filter="afterFilter"
        :pagination-previous-label="'<'"
        :pagination-next-label="'>'"
    >
        <template #cell(ip_address)="{ value }">
            <p class="tw-text-navy-500">{{ value }}</p>
        </template>
        <template #pagination-label="{ perPage, currentPage, totalEntries }">
            I am currently showing entries 
            {{ perPage * currentPage - perPage + 1 }} to
            {{ perPage * currentPage }} of {{ totalEntries }} entries.
        </template>
        <template #page-size-label="data">
            Current Page Size: {{ data.pageSize }}
        </template>
    </table-component>
</template>
<script>
export default {
    name: 'App',
    data() {
        return {
            data: [
                { id: 1, name: 'John Doe', share: 0.51, ip_address: '111.222.47.186', last_login: '2023-01-31' },
                { id: 2, name: 'Jane Doe', share: 0.08, ip_address: '71.190.227.13', last_login: '2023-04-10' }
            ],
            topRows: [
                { id: 3, name: 'Patricia Smith', share: 0.89, ip_address: '25.7.58.72', last_login: '2023-04-10'},
                { id: 4, name: 'Douglas Holland', share: 0.72, ip_address: '105.171.14.146', last_login: '2023-03-24'}
            ],
            bottomRows: [
                {id: 5, name: 'Jordan Winsley', share: 0.81, ip_address: '141.147.221.67', last_login: '2023-04-28'}
            ],
            fields: [
                { key: 'id' }, 
                { key: 'name' },
                { key: 'share',
                  thClassList: 'tw-text-right tw-px-2',
                  tdClassList: 'tw-text-right tw-px-2',
                  tdTopRowClassList: 'tw-text-right tw-px-2 tw-italic',
                  tdBottomRowClassList: 'tw-text-right tw-px-2 tw-font-semibold',
                  formatter: value =>
                          value
                              ? (parseFloat(value) * 100).toLocaleString(navigator.language, {
                                  minimumFractionDigits: 0,
                                  maximumFractionDigits: 2
                              }) + '%'
                              : ''
                }
                { key: 'ip_address',
                  thClassList: 'tw-text-center tw-px-2',
                  tdClassList: 'tw-text-center tw-px-2',
                  tdTopRowClassList: 'tw-text-center tw-px-2 tw-italic',
                  tdBottomRowClassList: 'tw-text-right tw-px-2 tw-font-semibold'
                }
            ]
        }
    }
}
</script>
<style>
@import '@s3_dse/v-tail-vue3/dist/style.css';
</style>

We pass the table data as an array of objects via the :items attribute. The same applies to the optional :top-rows and :bottom-rows. The entries of all three data arrays need to have the same structure. The :fields attribute takes an array of objects with details regarding the rendering of particular fields. Field entries have a key to refer to a data entry's property. The remaining field properties are metadata to customize the rendering of the column:

  • thClassList: classes for styling the column's <th> content (only applied to :items records)
  • tdClassList: classes for styling the column's <td> content (only applied to :items records)
  • tdTopRowClassList: classes for styling the column's <td> content (only applied to :top-rows records)
  • tdBottomRowClassList: classes for styling the column's <td> content (only applied to :bottom-rows records)
  • formatter: a function defining a formatting logic for the values of that field/column

Only those attributes present in the field array will be displayed in the resulting table.

Pagination

The page navigation can be enabled/disabled via the :paginate attribute. This will toggle pagination in general. The page size configurator can be enabled/disabled via the :configurable-page-size attribute. Both these attributes take boolean values and are true by default. They are part of the above example only for illustration.

Cell Rendering

The above example shows how to use the #cell() slot to customize the rendering of individual cells. The slot is dynamic and takes a field key as argument. It provides an object holding the actual cell value, the item (or record) of the :items array, and the field of the :fields array.

Credits

The component is heavily inspired by the Bootstrap Vue Table component. Have a look: https://github.com/bootstrap-vue/bootstrap-vue

Dialog Component (Radix Vue)

A component for displaying modal dialogs.

Usage

<script setup>
...
const validateAndSubmit = () => {
    const selection = document.querySelector('.custom-select').selectedOptions[0].innerText
    if (selection === 'a') {
        console.log('Error: Option "a" is not allowed!')
        return false
    } else {
        console.log('success')
        submitLogic()
        return true

    }

}
</script>
<template>
    ...
    <dialog-component title="Testing Dialog" description="A dialog..." @cancel="test" :pre-confirm="validateAndSubmit">
        <template #content>
            <div class="un-flex un-gap-4 un-flex-col un-text-gray-900 dark:un-text-gray-100 un-px-4 un-pt-3 un-pb-5">
                <div>Some content</div>
            </div>
            <select class="custom-select"><option>a</option><option>b</option></select>
        </template>
    </dialog-component>
</template>

Props

PropDescription
classesObject with styles keyed by component part. Optional. See styles.
titleThe dialog title. Optional.
descriptionThe dialog description. Optional.
preConfirmThe function to call before closing via confirmation (not cancellation). Returns true to continue confirmation, false to abort. Optional.

Styling

The classes prop allows to modify the styling of the

  • Dialog-Trigger
  • Overlay
  • Title
  • Description
  • Content Container.

E.g.

<dialog-component :classes="{title: 'text-4xl text-green'}">
    ...
</dialog-component>

See the default style map for reference.

Select Component (Radix Vue)

A component wrapping an HTML select.

Usage

<script setup>
import { ref } from 'vue'
import { SelectComponent } from '@/components'

const options = [
    { name: 'Record A', value: 'a' },
    { name: 'Record B', value: 'b' },
    { name: 'Record C', value: 'c' },
    { name: 'Record D', value: 'd' },
    { name: 'Record E', value: 'e' },
    { name: 'Record F', value: 'f' }
]

const selection = ref(options[0])
</script>
<template>
    <select-component
        v-model="selection"
        :options="options"
        label-key="name"
        aria-label="Select option"
    ></select-component>
    <div class="un-text-gray-900 dark:un-text-gray-100">{{ selection }}</div>
</template>

Props

PropDescription
classesObject with styles keyed by component part. Optional. See styles.
optionsArray of options (complex or primitive). Required.
labelKeyA key (String) to access the label property of an option. Optional.
placeholderA placeholder (String) when there is no default selection given. Default: 'Select option'.
modelValueThe value (String|Boolean|Number|Object) holding the currently selected option. Optional.

Styling

The trigger widget is styled via plain HTML attributes on the component. Additionally, the classes prop allows to modify the styling of the

  • trigger
  • content container
  • item.

E.g.

<select-component
        v-model="selection"
        :options="options"
        label-key="name"
        aria-label="Select option"
        class="un-w-full"
        :classes="{trigger: 'un-bg-green-400'}"
    ></select-component>

Pagination Component

Dropdown Component

License

MIT License

Copyright (c) 2023 Sebastian Doerl

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0.1.86

4 days ago

0.1.87

4 days ago

0.1.88

4 days ago

0.1.85

4 months ago

0.1.80

4 months ago

0.1.81

4 months ago

0.1.82

4 months ago

0.1.83

4 months ago

0.1.84

4 months ago

0.1.78

4 months ago

0.1.79

4 months ago

0.1.52

8 months ago

0.1.53

7 months ago

0.1.54

7 months ago

0.1.55

7 months ago

0.1.56

7 months ago

0.1.57

6 months ago

0.1.58

6 months ago

0.1.59

6 months ago

0.1.50

8 months ago

0.1.51

8 months ago

0.1.49

8 months ago

0.1.41

8 months ago

0.1.42

8 months ago

0.1.43

8 months ago

0.1.44

8 months ago

0.1.45

8 months ago

0.1.46

8 months ago

0.1.47

8 months ago

0.1.40

8 months ago

0.1.38

8 months ago

0.1.39

8 months ago

0.1.74

5 months ago

0.1.30

8 months ago

0.1.75

5 months ago

0.1.31

8 months ago

0.1.76

5 months ago

0.1.32

8 months ago

0.1.77

5 months ago

0.1.33

8 months ago

0.1.34

8 months ago

0.1.35

8 months ago

0.1.36

8 months ago

0.1.37

8 months ago

0.1.70

6 months ago

0.1.71

6 months ago

0.1.72

6 months ago

0.1.73

5 months ago

0.1.63

6 months ago

0.1.64

6 months ago

0.1.65

6 months ago

0.1.66

6 months ago

0.1.67

6 months ago

0.1.68

6 months ago

0.1.69

6 months ago

0.1.60

6 months ago

0.1.61

6 months ago

0.1.62

6 months ago

0.1.29

12 months ago

0.1.28

12 months ago

0.1.27

12 months ago

0.1.26

12 months ago

0.1.25

12 months ago

0.1.24

12 months ago

0.1.23

12 months ago

0.1.22

12 months ago

0.1.21

12 months ago

0.1.20

12 months ago

0.1.19

12 months ago

0.1.18

1 year ago

0.1.17

1 year ago

0.1.16

1 year ago

0.1.15

1 year ago

0.1.14

1 year ago

0.1.13

1 year ago

0.1.12

1 year ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago