View UI Plus Documentation

repository·master·Indexed 19 days ago

https://github.com/view-design/viewuiplus

An enterprise-level UI component library for Vue.js 3. View UI Plus provides a wide range of functional components, including layout tools like Col and Row, form elements such as Checkbox and Cascader, and specialized components like Calendar, Carousel, and Notification. It supports TypeScript and can be installed via npm, CDN, or script tags.

Tokens
24.8K
Snippets
156
Records
164
Agent score
65%

What's inside View UI Plus

  1. Understand the View UI Plus style library structure

    master

    The View UI Plus style library is organized into four main functional directories:

    • animation: Contains styles related to component animations.
    • common: Contains global styles and base configurations used across the library.
    • components: Contains specific styles for individual UI components.
    • mixins: Contains reusable style mixins (typically for Sass/Less) to assist in custom styling and theme extensions.
  2. Install View UI Plus via script tag

    master

    For global use without a module bundler, you can include the library via script tags in your HTML file.

    <script type="text/javascript" src="viewuiplus.min.js"></script>
    <link rel="stylesheet" href="dist/styles/viewuiplus.css">
  3. Install View UI Plus via CDN/Global Script

    master

    You can include View UI Plus directly in your HTML using <script> and <link> tags for global reference.

    <script type="text/javascript" src="viewuiplus.min.js"></script>
    <link rel="stylesheet" href="dist/styles/viewuiplus.css">
  4. Understand the align option in scrollIntoView

    master

    The align object determines where the target element is positioned within the visible area of its scrollable parent after the animation completes.

    • top: A value from 0 to 1. 0 aligns the target to the top of the container, 1 to the bottom, and 0.5 (default) centers it vertically.
    • left: A value from 0 to 1. 0 aligns the target to the left, 1 to the right, and 0.5 (default) centers it horizontally.
    • topOffset: A pixel value used to offset the top alignment.
    • leftOffset: A pixel value used to offset the left alignment.
  5. Use global properties and services in View UI Plus

    master

    After installation, View UI Plus attaches several utility services and component references to app.config.globalProperties. You can access these within your Vue components via this (Options API) or via getCurrentInstance (Composition API).

    Global Services:

    • $Spin: The Spin component.
    • $Loading: The LoadingBar component.
    • $Message: The Message service.
    • $Notice: The Notice service.
    • $Modal: The Modal service.
    • $ImagePreview: The ImagePreview service.
    • $Copy: The Copy service.
    • $ScrollIntoView: The ScrollIntoView service.
    • $ScrollTop: The ScrollTop service.
    • $Date: The dayjs library instance.

    Global Configuration:

    • $VIEWUI: An object containing the global configuration settings passed during install (e.g., size, transfer, and component-specific settings like menu.arrow or datePicker.icon).
  6. Install View UI Plus in a Vue application

    master

    To use View UI Plus, use the install function to register all components and directives globally in your Vue application instance. You can also pass an opts object to configure internationalization (i18n), locales, and global component properties like sizes and icons.

    Available configuration options in opts include:

    • locale: Set the locale via localeFile.use(opts.locale).
    • i18n: Set i18n via localeFile.i18n(opts.i18n).
    • size: Global component size.
    • capture: Boolean for capture behavior (defaults to true).
    • transfer: Global transfer setting.
    • Component-specific configurations for cell, menu, modal, tabs, select, colorPicker, cascader, tree, datePicker, timePicker, typography, space, and image (e.g., setting custom arrows, icons, or sizes).
    import { createApp } from 'vue';
    import ViewUIPlus from 'view-ui-plus';
    import 'view-ui-plus/dist/viewuiplus.css';
    
    const app = createApp(App);
    
    app.use(ViewUIPlus, {
        size: 'large',
        locale: myLocaleObject,
        // other options...
    });
    
    app.mount('#app');
  7. Basic Usage Example

    master

    View UI Plus components can be used within Vue components using standard Vue patterns like v-model and setup script syntax. Below is an example of using the Slider component with a range selection.

    <template>
        <Slider v-model="value" range />
    </template>
    <script setup>
        import { ref } from 'vue'
        const value = ref([20, 50])
    </script>
  8. Use View UI Plus with TypeScript

    master

    View UI Plus supports TypeScript. When using <script setup lang="ts">, you can import types from vue to properly type your component state used by View UI Plus components.

    <template>
        <Slider v-model="value" range />
    </template>
    <script setup lang="ts">
        import { ref } from 'vue'
        import type { Ref } from 'vue'
        const value: Ref<number[]> = ref([20, 50])
    </script>
  9. Configure scrollIntoView settings

    master

    When calling scrollIntoView, you can provide a settings object to customize the animation behavior and alignment.

    KeyTypeDefaultDescription
    timenumber1000Duration of the animation in milliseconds.
    easefunction(v) => 1 - Math.pow(1 - v, v / 2)An easing function that receives a value from 0 to 1 and returns a value for the animation progress.
    alignobject{ top: 0.5, left: 0.5 }Alignment configuration for the target element within the scrollable container.
    validTargetfunction() => trueA predicate function (target, parentsScrolled) => boolean. If it returns false, the parent is skipped in the scroll chain.
    isScrollablefunctiondefaultIsScrollableA predicate function (target, defaultIsScrollable) => boolean. Allows overriding the default check for whether an element is scrollable.
    {
      time: 500,
      ease: function(value) {
        return Math.pow(value, 2) - value;
      },
      validTarget: function(target, parentsScrolled) {
        // Example: Only scroll parents that don't have the class 'dontScroll'
        return !target.matches('.dontScroll');
      },
      align: {
        top: 0,        // 0 (top) to 1 (bottom). Default 0.5 (center)
        left: 0.5,     // 0 (left) to 1 (right). Default 0.5 (center)
        topOffset: 0, // Pixels to offset top alignment
        leftOffset: 0 // Pixels to offset left alignment
      },
      isScrollable: function(target, defaultIsScrollable) {
        // Example: Treat elements with class 'scrollable' as scrollable even if overflow is hidden
        return defaultIsScrollable(target) || target.classList.contains('scrollable');
      }
    }