Skip to content

Enhancement: Add Qwik / QwikCity Integration β€” new wrapper component and demo page sectionΒ #57

@coderabbitai

Description

@coderabbitai

🎯 Direction

SocialShareButton is a lightweight, zero-dependency, framework-agnostic social sharing component. Qwik is a resumability-based framework that defers JavaScript execution until user interaction β€” it is the most performance-forward framework available and aligns directly with this library's zero-dependency ethos. Since QwikCity is SSR-first, the wrapper must use useVisibleTask$ (Qwik's client-only lifecycle hook) and guard all browser APIs.

πŸ“Ή See the button in action: https://youtu.be/cLJaT-8rEvQ?si=CLipA0Db4WL0EqKM


πŸ“ Files to Create / Modify

βœ… New File: src/social-share-button-qwik.tsx

A Qwik component wrapping the core vanilla JS library:

import { component$, useVisibleTask$, useSignal, type QRL } from '@builder.io/qwik';

interface Props {
  url?:           string;
  title?:         string;
  description?:   string;
  hashtags?:      string[];
  via?:           string;
  platforms?:     string[];
  theme?:         string;
  buttonText?:    string;
  customClass?:   string;
  onShare?:       QRL<() => void>;
  onCopy?:        QRL<() => void>;
  buttonStyle?:   string;
  modalPosition?: string;
}

export const SocialShareButton = component$<Props>((props) => {
  const containerRef = useSignal<HTMLDivElement>();

  // useVisibleTask$ runs only on the client β€” the correct SSR-safe hook in Qwik
  useVisibleTask$(({ cleanup }) => {
    if (typeof window !== 'undefined' && window.SocialShareButton && containerRef.value) {
      const shareButton = new (window as any).SocialShareButton({
        container:     containerRef.value,
        url:           props.url           || window.location.href,
        title:         props.title         || document.title,
        description:   props.description   || '',
        hashtags:      props.hashtags      || [],
        via:           props.via           || '',
        platforms:     props.platforms     || ['whatsapp','facebook','twitter','linkedin','telegram','reddit'],
        theme:         props.theme         || 'dark',
        buttonText:    props.buttonText    || 'Share',
        customClass:   props.customClass   || '',
        buttonStyle:   props.buttonStyle   || 'default',
        modalPosition: props.modalPosition || 'center'
      });
      cleanup(() => shareButton.destroy());
    }
  });

  return <div ref={containerRef}></div>;
});

βœ… Existing File: index.html β€” Add Qwik Integration Section

Add a new section with:

  • Section heading: ⚑ Qwik / QwikCity Integration
  • Step 1: Include CSS and JS via CDN in src/root.tsx
  • Step 2: Import and use the component in a QwikCity route

Example code snippet to display:

// src/routes/index.tsx
import { component$ } from '@builder.io/qwik';
import { SocialShareButton } from '~/components/social-share-button-qwik';

export default component$(() => (
  <SocialShareButton
    url="https://your-website.com"
    title="Check this out!"
    description="An amazing website"
    theme="dark"
    buttonText="Share"
  />
));

βœ… Acceptance Criteria

  • src/social-share-button-qwik.tsx created using useVisibleTask$ (Qwik's client-only hook)
  • cleanup() callback calls destroy() to prevent memory leaks
  • No browser APIs accessed outside useVisibleTask$
  • index.html updated with a Qwik section containing install + usage code snippets
  • Copy-to-clipboard button present on new code blocks in index.html
  • README updated to list Qwik as a supported framework

⚠️ Planned β€” Not Final
This issue represents a planned enhancement and is not guaranteed to be implemented. It may be dropped if it does not align with the repository's direction. Before opening a pull request, please discuss with the maintainers in this issue thread.

Metadata

Metadata

Assignees

No one assigned

    Labels

    plannedPlanned feature - not final, may be dropped based on repo direction

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions