ShareLink

ShareLink control

A button that presents the native macOS share sheet, allowing users to share text, URLs, or files through system sharing services. The share sheet displays available targets such as AirDrop, Mail, Messages, and third-party apps.

Constructor

nib.ShareLink(
    items,
    content=None,
    label=None,
    icon=None,
    subject=None,
    message=None,
    **modifiers,
)

Parameters

Parameter Type Default Description
items list[str] (required) Items to share. Can be strings (plain text), URLs, or file paths.
content View None Custom view to use as the button label. Overrides label and icon.
label str None Button label text. Used when content is not provided.
icon str None SF Symbol name for the button icon. Used alongside label when content is not provided.
subject str None Subject line for email shares.
message str None Pre-filled message body for social shares.
**modifiers Common view modifiers: padding, background, foreground_color, opacity, etc.

Mutable Properties

Property Type Description
items list[str] Get or set the items to share.
content View Get or set the custom button view.
label str Get or set the button label text.
icon str Get or set the SF Symbol icon name.

Examples

Share text with label

sharelink_share_text_label

import nib


def main(app: nib.App):
    app.title = "Quote"
    app.icon = nib.SFSymbol("quote.bubble")
    app.width = 340

    quote = "Simplicity is the ultimate sophistication."

    app.build(
        nib.VStack(
            controls=[
                nib.Text(quote, font=nib.Font.TITLE3),
                nib.Text("Leonardo da Vinci", foreground_color=nib.Color.SECONDARY),
                nib.ShareLink(
                    items=[quote], label="Share quote", icon="square.and.arrow.up"
                ),
            ],
            spacing=12,
            padding=20,
            width=300,
        )
    )


nib.run(main)

Share a URL with custom content

sharelink_share_url_custom

import nib


def main(app: nib.App):
    app.title = "Article"
    app.icon = nib.SFSymbol("newspaper")

    app.build(
        nib.VStack(
            controls=[
                nib.Text("Building menu bar apps in Python", font=nib.Font.HEADLINE),
                nib.Text("8 min read", foreground_color=nib.Color.SECONDARY),
                nib.ShareLink(
                    items=["https://edo.codeberg.page/nib/"],
                    subject="Worth a read",
                    message="This is how I built my menu bar app.",
                    content=nib.HStack(
                        controls=[
                            nib.SFSymbol("paperplane"),
                            nib.Text("Send to a friend"),
                        ],
                        spacing=6,
                    ),
                ),
            ],
            spacing=10,
            padding=20,
            alignment=nib.Alignment.LEADING,
        )
    )


nib.run(main)