Git Product home page Git Product logo

Comments (3)

AdrianGonz97 avatar AdrianGonz97 commented on September 7, 2024 1

What are your thoughts on a possible union $$Props type for the button @AdrianGonz97 ?

@huntabyte Totally. We can discriminate on the href and have something like this:

type Props = {
    class?: string | null;
    variant?: VariantProps<typeof buttonVariants>["variant"];
    size?: VariantProps<typeof buttonVariants>["size"];
};

interface AnchorElement extends Props, HTMLAnchorAttributes {
    href?: HTMLAnchorAttributes["href"];
    type?: never;
}

interface ButtonElement extends Props, HTMLButtonAttributes {
    type?: HTMLButtonAttributes["type"];
    href?: never;
}

type $$Props = AnchorElement | ButtonElement;

Autocomplete for data-sveltekit-preload-data and all that fun stuff should work then. It also has the added bonus of yelling at the user if they specify both an href and a type.

from shadcn-svelte.

jycouet avatar jycouet commented on September 7, 2024

It's working.
It's just that we don't have auto-complete as VSCode doesn't know "Button" and this attribute.

Maybe you could make it explicit?
If you feel that it's not the right thing to do, feel free to close the ticket 👍

from shadcn-svelte.

huntabyte avatar huntabyte commented on September 7, 2024

The issue I was running into with that was due to the button being able to act as a link OR a button, each of which have their own props.

Let me look into a union type or possible splitting <a> tags into their own component, something I don't really want to do unless it's a dealbreaker for the community.

What are your thoughts on a possible union $$Props type for the button @AdrianGonz97 ?

from shadcn-svelte.

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.