Giter Club home page Giter Club logo

Comments (2)

zernonia avatar zernonia commented on July 24, 2024

You are using useForwardProps wrongly. It should be a computed or a ref, and not object of ref(s).
Check out https://stackblitz.com/edit/vitejs-vite-dgmjpq?file=src%2Fcomponents%2FBox.vue

from radix-vue.

gu-stav avatar gu-stav commented on July 24, 2024

@zernonia Apologies, I just realized my reproduction maybe was a bit too minimal to showcase the problem properly. 🙈

I have created a more realistic and extensive version of it. The following is working in 1.7.4, but can not build in 1.8.x:

1.7.4: https://stackblitz.com/edit/vitejs-vite-4xcuqh?file=src%2Fcomponents%2FText.vue
1.8.2: https://stackblitz.com/edit/vitejs-vite-ksc3vz?file=src%2Fcomponents%2FText.vue

sprinkles() is just a stub for https://vanilla-extract.style/documentation/packages/sprinkles/ for demostration purposes. In reality the code for Text looks something like this:

<script setup lang="ts">
import { defineProps, toRefs } from 'vue'

import { useForwardProps } from 'radix-vue'

import { Box, type BoxProps } from '../Box'

import { sprinkles, type Sprinkles } from '@/styles/sprinkles.css'

export interface TextProps extends BoxProps {
  align?: Sprinkles['textAlign']
}

const props = defineProps<TextProps>()
const { align, ...rest } = toRefs(props)
const forwarded = useForwardProps(rest)
</script>

<template>
  <Box
    v-bind="forwarded"
    :class="
      sprinkles({
        textAlign: align,
      })
    "
  >
    <slot />
  </Box>
</template>

I think pulling out props for Text and passing on the rest (BoxProps) via a spread is a valid usecase for useForwardProps:

const props = defineProps<TextProps>();
const { align, family, ...rest } = toRefs(props);
const forwarded = useForwardProps(rest);

As far as I understand in [email protected] we would be able to replace this with a destructuring assignment:

const { align, family, ...rest } = defineProps<TextProps>();
const forwarded = useForwardProps(rest);

and I believe this also would return every prop of type Ref.

from radix-vue.

Related Issues (20)

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.