0.5.3 • Published 10 months ago

vue-simple-props v0.5.3

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

vue-simple-props npm

Unit Test

Remove emits, slots, and attrs concepts in Vue.

Features

  • 🤐 No need to define props, emits, slots, and attrs in runtime.
  • 🦾 Fully TypeScript support.
  • 👾 Non-invasive.

Install

npm i vue-simple-props

Usage

Conventions

  • Starts with on for event handlers.
  • Starts with render for slots.
  • Others are props.

Functional Component (Stateful)

import { defineFunctionalComponent, useClassAndStyle } from 'vue-simple-props'

interface Props {
  foo: string
  onClick: () => void
  renderDefault?: () => JSX.Element
}

const Comp = defineFunctionalComponent(
  (props: Props) => {
    const styles = useClassAndStyle()
    return () => <div {...styles}>...</div>
  },
  {
    // other options, e.g. name, inheritAttrs, etc.
  },
)
<!-- parent.vue -->
<template>
  <Comp foo="bar" @click="handleClick">slot</Comp>
</template>

Options Component

import {
  defineSimpleComponent,
  useClassAndStyle,
  useProps,
} from 'vue-simple-props'

interface Props {
  foo: string
  onClick: () => void
  renderDefault?: () => JSX.Element
}

export const Comp = defineSimpleComponent<Props>({
  setup() {
    const props = useProps<Props>()
    const styles = useClassAndStyle()
    return () => <div {...props}>...</div>
  },
})

HMR support

// vite.config.ts
import vueJsx from '@vitejs/plugin-vue-jsx'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [
    // ...
    vueJsx({
      defineComponentName: [
        'defineComponent',
        'defineFunctionalComponent',
        'defineSimpleComponent',
      ],
    }),
  ],
})

Caveats

  • inheritAttrs is false by default.

Sponsors

License

MIT License © 2023-PRESENT 三咲智子 Kevin Deng

0.5.3

10 months ago

0.5.2

10 months ago

0.5.1

11 months ago

0.5.0

11 months ago

0.4.1

11 months ago

0.4.0

11 months ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago

0.0.0-alpha.0

2 years ago