Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make a whole card or image as a link? #99

Open
Haibo-Zhou opened this issue Jul 26, 2024 · 2 comments
Open

How to make a whole card or image as a link? #99

Haibo-Zhou opened this issue Jul 26, 2024 · 2 comments

Comments

@Haibo-Zhou
Copy link

Haibo-Zhou commented Jul 26, 2024

I dig around ignite yesterday, and decide to replace my personal website with it. How to make a whole card or an image as a link? Below is my current achieved, I want to make a HStack to represent my apps in AppStore, and hit each of app image, it goes to relatived app intro page.

Screenshot 2024-07-26 at 09 49 53
    Section {
            Card {
                Image(decorative: "/images/products/movie-fans/movie-fans-logo.png")
                    .resizable()
                    .cornerRadius(24)
                Spacer()
                Link("Movie Fans", target: "/products/ohmusic/oh-music-privacy-policy")
                    .linkStyle(.button)
                    .role(.primary)
            }
            .frame(maxWidth: 200)
            .role(.light)
            .cardStyle(.solid)
            .horizontalAlignment(.center)
            
            Card {
                Image(decorative: "/images/products/movie-fans/movie-fans-logo.png")
                    .resizable()
                    .cornerRadius(24)
                Spacer()
                Link("Movie Fans", target: "/products/ohmusic/oh-music-privacy-policy")
                    .linkStyle(.button)
                    .role(.primary)
            }
            .frame(maxWidth: 200)
            .role(.light)
            .cardStyle(.solid)
            .horizontalAlignment(.center)
            
            
            Card {
                Image(decorative: "/images/products/oh-music/oh-music-logo.png")
                    .resizable()
                    .cornerRadius(24)
                Spacer()
                Link("Oh Music", target: "/products/ohmusic/oh-music-privacy-policy")
                    .linkStyle(.button)
                    .role(.dark)
            }
            .frame(maxWidth: 200)
            .role(.light)
            .cardStyle(.solid)
            .horizontalAlignment(.center)
            
            Spacer(size: .extraLarge)
            Spacer(size: .extraLarge)
            Spacer(size: .extraLarge)
        }
@Haibo-Zhou Haibo-Zhou changed the title How to apply card or image to link? How to make a whole card or image as a link? Jul 26, 2024
@markstamer
Copy link
Collaborator

Hi @Haibo-Zhou, I see you struggle here. Link only supports InlineElement not PageElement. For now you could try to use the onClick modifier in combination with a CustomAction. Also to achieve a pointer when hovering over the card try if you can use the style cursor: pointer;. In summary, see if something like this works:

Card {
    ...
} 
.style("cursor: pointer")
.onClick(CustomAction(""window.location.href='https://www.example.com';")

@vdhamer
Copy link
Contributor

vdhamer commented Sep 3, 2024

Hi @Haibo-Zhou, I see you struggle here. Link only supports InlineElement not PageElement. For now you could try to use the onClick modifier in combination with a CustomAction. Also to achieve a pointer when hovering over the card try if you can use the style cursor: pointer;. In summary, see if something like this works:

Card {
    ...
} 
.style("cursor: pointer")
.onClick(CustomAction(""window.location.href='https://www.example.com';")

This works (at least I tried it on an Image):

.style("cursor: pointer")
.onClick { CustomAction("window.location.href=\"https://www.example.com\";") }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants