Coder Social home page Coder Social logo

vonage / vivid-bindings-vue Goto Github PK

View Code? Open in Web Editor NEW
2.0 13.0 0.0 127 KB

Fully automated typescript bindings generated for Vivid web components to be used in VueJS

Home Page: https://www.npmjs.com/package/@vonage/vivid-bindings-vue

TypeScript 100.00%
vivid vuejs webcomponent bindings devex typesafe typescript vuejs3

vivid-bindings-vue's Introduction

vivid-bindings-vue

Typescript bindings for Vivid 3 web components to be used with VueJS 3

What's in the box(i.e. batteries included):

  • Few lines of code convergent initialization routine for Vivid design system
  • 100% Vivid components covered with bindings
  • ~100% automated process for NPM package generation & release. @vonage/vivid package is the release driver/trigger
  • Enhanced DevEx (VS Code intellisense) + Fully sound Typescript type checking for Vivid web components props/events/slots/cssProps/cssParts/etc. contracts
  • Abstraction layer for easier migration to future major versions of Vivid

How to integrate with VueJs App

Vivid can be initialized as easy as few lines of code

main.ts

import { createApp } from 'vue'
import App from './App.vue'
import { vivid3 } from '@vonage/vivid-bindings-vue'

const app = createApp(App)
app.use(vivid3, {
  font: 'oss',
  theme: 'dark'
})
app.mount('#app')

vite.config.ts

import { isCustomElement } from '@vonage/vivid-bindings-vue'

...

  plugins: [
    vue(
      {
        template: {
          compilerOptions: {
            isCustomElement
          },
        },
      }
    )
  ]

...

How to import components

Each Vivid component should be imported using single import statement. The Vivid major version is a part of the import v3. This enables seamless side by side usage of different major versions in a single project for pay as you go future migration path

<script setup lang="ts">
import { Connotation } from '@vonage/vivid'
import VwcButton from '@vonage/vivid-bindings-vue/v3/VwcButton'
import VwcIcon from '@vonage/vivid-bindings-vue/v3/VwcIcon'

function handleClick(e:PointerEvent) {}
</script>

<template>
  <VwcButton
     iconTrailing
     icon="github-mono"
     @click="handleClick"
     appearance='filled'
     label="I'm a Vivid button" />
  <VwcIcon
     name="key-solid"
     :connotation=Connotation.Alert
     :size=5 />
</template>

Releases

This package has a pipeline workflow which is checking for a new Vivid version on a dayly basis and if it detects that new version is out The new bindings are generated and published automatically, reflecting the same package version @vonage/vivid has. So the release driver is @vonage/vivid package itself.

Repository structure

The entire repository is a pure Typescript code, divided onto two main parts

  • ./src - is the Deno territory, contains the generator code, which is effectively generates the NPM package contents on top of the existing template
  • ./package - is the NPM package template

Rationale

  • Vivid web components since version 3.0 are shipped with the custom elements meta data alongside the code itself. Which allows to employ code generation practice to build near 100% automated typescript type safe bindings for VueJs components
  • Maintenance cost should be linear, it's always one component to be rendered, no matter how many elements there are actually in Vivid design system
  • Adds an abstraction layer to mitigate the custom web components namespacing conflicts issue, to enable usage of several major versions of Vivid components in the single application more info here, and how Salesforce Lightning web components are solving that issue here

Official bindings for Vue 2.x/3.x

https://github.com/Vonage/vivid-vue

vivid-bindings-vue's People

Contributors

egor-limenko avatar gresau avatar k-paxian avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vivid-bindings-vue's Issues

Vue warning when rendering `VwcTextField` without explicit `size` prop

Probably caused by #8 (whoops!)

When running in debug mode and rendering a <VwcTextField> without a size prop, a warning similar to the following is logged:

[Vue warn]: Failed setting prop "size" on <vvd3-text-field>: value undefined is invalid.
  DOMException: Failed to set the 'size' property on 'HTMLInputElement': The value provided is 0, which is an invalid size.
    at Decorated.sizeChanged (http://localhost:4200/...)
---snip---
    at ReactiveEffect.run (http://localhost:4200/...) 
  at <VwcTextField icon="search-line" placeholder="Search..." value=""  ... > 

I think this is because size is declared as an optional prop of VwcTextField, so omitting it is equivalent to passing :size="undefined" - but the underlying web component does not accept undefined as a value for size.

I don't think vivid-vue has this problem, because it passes its props to the underlying web component with code of the form:

...(this.size !== undefined ? {'size': this.size } : {})

i.e. if the Vue component's size prop is undefined (or omitted), then it won't forward it into underlying the web component at all

I don't believe this causes any user impact, it's just some unfortunate log spam in the browser console - so we may opt to just ignore it until we eventually migrate to vivid-vue.

Generated components have invalid typescript annotations

I was looking into updating the build scripts to generate .d.ts files next to each generated component, which would fix typescript annotations for projects consuming this package - but I quickly hit a wall because some of the type annotations in generated files are invalid.

e.g. VwcTooltip.vue defines an anchor property with type anchorType | undefined - but it doesn't define or import anchorType.

click for all tsc errors
v3/VwcAccordionItem/VwcAccordionItem.vue:48:10 - error TS2304: Cannot find name 'AccordionItemSize'.

48   size?: AccordionItemSize | undefined
            ~~~~~~~~~~~~~~~~~

v3/VwcAlert/VwcAlert.vue:86:15 - error TS2304: Cannot find name 'AlertPlacement'.

86   placement?: AlertPlacement | undefined
                 ~~~~~~~~~~~~~~

v3/VwcCheckbox/VwcCheckbox.vue:74:17 - error TS2304: Cannot find name 'CheckboxConnotation'.

74   connotation?: CheckboxConnotation | undefined
                   ~~~~~~~~~~~~~~~~~~~

v3/VwcDataGrid/VwcDataGrid.vue:23:19 - error TS2304: Cannot find name 'DataGridSelectionMode'.

23   selectionMode?: DataGridSelectionMode | undefined
                     ~~~~~~~~~~~~~~~~~~~~~

v3/VwcDataGrid/VwcDataGrid.vue:37:36 - error TS2304: Cannot find name 'DataGridSelectionMode'.

37   selectionModeChanged: (oldValue: DataGridSelectionMode) => (element.value as any)?.selectionModeChanged(oldValue),
                                      ~~~~~~~~~~~~~~~~~~~~~

v3/VwcPagination/VwcPagination.vue:20:30 - error TS2300: Duplicate identifier 'Button'.

20 import { registerPagination, Button, Button } from '@vonage/vivid'
                                ~~~~~~

v3/VwcPagination/VwcPagination.vue:20:30 - error TS2305: Module '"@vonage/vivid"' has no exported member 'Button'.

20 import { registerPagination, Button, Button } from '@vonage/vivid'
                                ~~~~~~

v3/VwcPagination/VwcPagination.vue:20:38 - error TS2300: Duplicate identifier 'Button'.

20 import { registerPagination, Button, Button } from '@vonage/vivid'
                                        ~~~~~~

v3/VwcPagination/VwcPagination.vue:20:38 - error TS2305: Module '"@vonage/vivid"' has no exported member 'Button'.

20 import { registerPagination, Button, Button } from '@vonage/vivid'
                                        ~~~~~~

v3/VwcPagination/VwcPagination.vue:27:10 - error TS2304: Cannot find name 'PaginationSize'.

27   size?: PaginationSize | undefined
            ~~~~~~~~~~~~~~

v3/VwcRadio/VwcRadio.vue:77:17 - error TS2304: Cannot find name 'RadioConnotation'.

77   connotation?: RadioConnotation | undefined
                   ~~~~~~~~~~~~~~~~

v3/VwcTabs/VwcTabs.vue:42:17 - error TS2304: Cannot find name 'TabsConnotation'.

42   connotation?: TabsConnotation | undefined
                   ~~~~~~~~~~~~~~~

v3/VwcToggletip/VwcToggletip.vue:45:12 - error TS2304: Cannot find name 'AnchorType'.

45   anchor?: AnchorType
              ~~~~~~~~~~

v3/VwcToggletip/VwcToggletip.vue:53:22 - error TS2304: Cannot find name 'AnchorType'.

53   anchorChanged: (_: AnchorType, newValue: AnchorType) => (element.value as any)?.anchorChanged(_, newValue),
                        ~~~~~~~~~~

v3/VwcToggletip/VwcToggletip.vue:53:44 - error TS2304: Cannot find name 'AnchorType'.

53   anchorChanged: (_: AnchorType, newValue: AnchorType) => (element.value as any)?.anchorChanged(_, newValue),
                                              ~~~~~~~~~~

v3/VwcTooltip/VwcTooltip.vue:37:12 - error TS2304: Cannot find name 'anchorType'.

37   anchor?: anchorType | undefined
              ~~~~~~~~~~

v3/VwcTooltip/VwcTooltip.vue:41:22 - error TS2304: Cannot find name 'anchorType'.

41   anchorChanged: (_: anchorType, newValue: anchorType) => (element.value as any)?.anchorChanged(_, newValue),
                        ~~~~~~~~~~

v3/VwcTooltip/VwcTooltip.vue:41:44 - error TS2304: Cannot find name 'anchorType'.

41   anchorChanged: (_: anchorType, newValue: anchorType) => (element.value as any)?.anchorChanged(_, newValue),
                                              ~~~~~~~~~~

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.