Convert Figma logo to code with AI

krakenjs logozoid

Cross domain components

2,008
248
2,008
84

Top Related Projects

please submit Issues about the PayPal JS SDK here: https://github.com/paypal/paypal-js/issues

3,696

🚀 State Management Tailored-Made for JS Applications

A browser based code editor

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

11,181

The most scalable and customizable identity server on the market. Replace your Homegrown, Auth0, Okta, Firebase with better UX and DX. Has all the tablestakes: Passkeys, Social Sign In, Multi-Factor Auth, SMS, SAML, TOTP, and more. Written in Go, cloud native, headless, API-first. Available as a service on Ory Network and for self-hosters.

Quick Overview

Zoid is a cross-domain component library that allows you to create and embed reusable UI components across different domains. It provides a seamless way to build and integrate components that can communicate between parent windows and iframes, making it ideal for developing modular and scalable web applications.

Pros

  • Enables cross-domain component communication without security risks
  • Supports multiple rendering strategies (iframe, popup, or direct render)
  • Provides a simple and intuitive API for component creation and integration
  • Offers built-in error handling and logging capabilities

Cons

  • Learning curve for developers new to cross-domain component architecture
  • Limited community support compared to more mainstream UI libraries
  • May introduce additional complexity for simple applications that don't require cross-domain functionality
  • Performance overhead due to cross-domain communication

Code Examples

  1. Creating a basic Zoid component:
import { create } from 'zoid';

const MyComponent = create({
    tag: 'my-component',
    url: 'https://www.example.com/component.html'
});
  1. Rendering a Zoid component in the parent window:
MyComponent({
    prop1: 'value1',
    prop2: 'value2',
    onEvent: (data) => {
        console.log('Event received:', data);
    }
}).render('#container');
  1. Implementing the component in the child window:
import { Component } from 'zoid/dist/zoid.frameworks';

window.xprops.onEvent({ type: 'custom', data: 'Hello from component!' });

export default Component({
    render({ props }) {
        return <div>Hello, {props.name}!</div>;
    }
});

Getting Started

  1. Install Zoid:

    npm install zoid
    
  2. Create a component:

    import { create } from 'zoid';
    
    const MyComponent = create({
        tag: 'my-component',
        url: 'https://www.example.com/component.html'
    });
    
  3. Render the component:

    MyComponent({ prop: 'value' }).render('#container');
    
  4. Implement the component in a separate HTML file:

    <script src="https://www.paypal.com/sdk/js?client-id=test"></script>
    <script>
        window.xprops.onRender();
    </script>
    

For more detailed instructions and advanced usage, refer to the Zoid documentation.

Competitor Comparisons

please submit Issues about the PayPal JS SDK here: https://github.com/paypal/paypal-js/issues

Pros of PayPal Checkout Components

  • Specifically designed for PayPal integration, offering a more tailored solution for PayPal-related functionalities
  • Provides a comprehensive set of components for various PayPal payment scenarios
  • Includes built-in localization support for multiple languages and regions

Cons of PayPal Checkout Components

  • Limited to PayPal-specific use cases, less versatile for general cross-domain component needs
  • Potentially steeper learning curve for developers not familiar with PayPal's ecosystem
  • May have more dependencies and a larger footprint compared to Zoid's lightweight approach

Code Comparison

PayPal Checkout Components:

paypal.Buttons({
    createOrder: function(data, actions) {
        return actions.order.create({
            purchase_units: [{
                amount: {
                    value: '0.01'
                }
            }]
        });
    }
}).render('#paypal-button-container');

Zoid:

let MyComponent = zoid.create({
    tag: 'my-component',
    url: 'https://www.example.com/component'
});

MyComponent({
    foo: 'bar'
}).render('#container');

Both libraries aim to simplify cross-domain component integration, but PayPal Checkout Components focuses on PayPal-specific implementations, while Zoid offers a more general-purpose solution for creating and rendering cross-domain components. The code examples demonstrate the different approaches, with PayPal Checkout Components providing a more specialized API for PayPal transactions, and Zoid offering a flexible framework for creating custom components.

3,696

🚀 State Management Tailored-Made for JS Applications

Pros of Akita

  • More active development with recent updates and releases
  • Larger community support with more stars and contributors
  • Comprehensive documentation and examples for easier adoption

Cons of Akita

  • Steeper learning curve due to its more complex state management approach
  • Primarily focused on Angular, which may limit its use in other frameworks
  • Heavier bundle size compared to Zoid's lightweight approach

Code Comparison

Akita (Entity Store Creation):

export interface Product {
  id: number;
  title: string;
  price: number;
}

@StoreConfig({ name: 'products' })
export class ProductsStore extends EntityStore<ProductsState> {
  constructor() {
    super();
  }
}

Zoid (Component Creation):

let MyComponent = zoid.create({
    tag: 'my-component',
    url: 'https://www.mysite.com/mycomponent'
});

MyComponent.render({
    container: '#container'
});

Summary

Akita offers a robust state management solution with strong community support, particularly for Angular applications. It provides more features but comes with a steeper learning curve. Zoid, on the other hand, focuses on cross-domain components and offers a simpler API, making it easier to integrate but with potentially fewer advanced features for complex state management scenarios.

A browser based code editor

Pros of monaco-editor

  • More comprehensive and feature-rich code editor with syntax highlighting, autocomplete, and other advanced features
  • Larger community and more frequent updates, being backed by Microsoft
  • Better documentation and examples for integration

Cons of monaco-editor

  • Larger file size and potentially heavier resource usage
  • Steeper learning curve for implementation and customization
  • May be overkill for simple text editing needs

Code Comparison

monaco-editor:

import * as monaco from 'monaco-editor';

const editor = monaco.editor.create(document.getElementById('container'), {
    value: 'function hello() {\n\tconsole.log("Hello world!");\n}',
    language: 'javascript'
});

zoid:

import { create } from 'zoid';

const MyComponent = create({
    tag: 'my-component',
    url: 'https://www.example.com/component'
});

Summary

monaco-editor is a powerful code editor component with extensive features, while zoid is a cross-domain component framework. monaco-editor is better suited for code editing tasks, offering syntax highlighting and autocomplete. zoid, on the other hand, focuses on creating reusable components across different domains. The choice between them depends on the specific requirements of your project.

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

Pros of Jitsi Meet

  • Full-featured video conferencing solution with real-time communication capabilities
  • Open-source and self-hostable, providing greater control and customization options
  • Active community and regular updates, ensuring ongoing improvements and support

Cons of Jitsi Meet

  • More complex setup and deployment compared to lightweight cross-domain component libraries
  • Larger codebase and resource requirements, which may be overkill for simple use cases
  • Steeper learning curve for developers not familiar with WebRTC and video conferencing technologies

Code Comparison

Jitsi Meet (React component):

import { JitsiMeeting } from '@jitsi/react-sdk';

<JitsiMeeting
    domain = { "meet.jit.si" }
    roomName = { "MyMeetingRoom" }
    configOverwrite = {{
        startWithAudioMuted: true,
        disableModeratorIndicator: true,
        startScreenSharing: true,
        enableEmailInStats: false
    }}
    interfaceConfigOverwrite = {{
        TOOLBAR_BUTTONS: ['microphone', 'camera', 'closedcaptions', 'desktop', 'fullscreen',
            'fodeviceselection', 'hangup', 'profile', 'chat', 'recording',
            'livestreaming', 'etherpad', 'sharedvideo', 'settings', 'raisehand',
            'videoquality', 'filmstrip', 'invite', 'feedback', 'stats', 'shortcuts',
            'tileview', 'videobackgroundblur', 'download', 'help', 'mute-everyone',
            'security'
        ],
    }}
    userInfo = {{
        displayName: 'John Doe'
    }}
    onApiReady = { (externalApi) => {
        // here you can attach custom event listeners to the Jitsi Meet External API
        // you can also use the external API to control the widget
    } }
/>

Zoid (Component definition):

import { create } from 'zoid';

const MyComponent = create({
    tag: 'my-component',
    url: 'https://www.mysite.com/component',
    props: {
        onButtonClick: {
            type: 'function'
        }
    }
});
11,181

The most scalable and customizable identity server on the market. Replace your Homegrown, Auth0, Okta, Firebase with better UX and DX. Has all the tablestakes: Passkeys, Social Sign In, Multi-Factor Auth, SMS, SAML, TOTP, and more. Written in Go, cloud native, headless, API-first. Available as a service on Ory Network and for self-hosters.

Pros of Kratos

  • Comprehensive identity and user management system
  • Supports multiple authentication methods (passwords, social logins, etc.)
  • Designed for cloud-native environments and scalability

Cons of Kratos

  • More complex setup and configuration compared to Zoid
  • Steeper learning curve for developers new to identity management
  • May be overkill for simple cross-domain component needs

Code Comparison

Kratos (Go):

import "github.com/ory/kratos/x"

func initializeKratos() {
    reg := driver.NewDefaultRegistry()
    kratos, err := reg.Kratos()
    // ... error handling and further setup
}

Zoid (JavaScript):

import { create } from 'zoid';

const MyComponent = create({
    tag: 'my-component',
    url: 'https://www.example.com/component'
});

Summary

Kratos is a robust identity and access management solution, while Zoid focuses on cross-domain components. Kratos offers more comprehensive features for user management but requires more setup. Zoid is simpler to implement for basic cross-domain needs but lacks advanced identity features. Choose based on your project's specific requirements and complexity.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

zoid


build status code coverage npm version

A cross-domain component toolkit, supporting:

  • Render an iframe or popup on a different domain, and pass down props, including objects and functions
  • Call callbacks natively from the child window without worrying about post-messaging or cross-domain restrictions
  • Create and expose components to share functionality from your site to others!
  • Render your component directly as a React, Vue or Angular component!

It's 'data-down, actions up' style components, but 100% cross-domain using iframes and popups!


API Docs

Public options and methods supported by zoid

Demos

Working demos of different zoid patterns

Demo App

Forkable demo app with build, test, publishing and demos pre-configured.

Example

A full example of a cross-domain component using zoid


Quick example

Define a component to be put on both the parent and child pages:

var MyLoginComponent = zoid.create({
  tag: "my-login-component",
  url: "http://www.my-site.com/my-login-component",
});

Render the component on the parent page:

<div id="container"></div>

<script src="script-where-my-login-component-is-defined.js"></script>
<script>
    MyLoginComponent({

        prefilledEmail: 'foo@bar.com',

        onLogin: function(email) {
            console.log('User logged in with email:', email);
        }

    }).render('#container');
</script>

Implement the component in the iframe:

<input type="text" id="email" />
<input type="password" id="password" />
<button id="login">Log In</button>

<script src="script-where-my-login-component-is-defined.js"></script>
<script>
    var email = document.querySelector('#email');
    var password = document.querySelector('#password');
    var button = document.querySelector('#login');

    email.value = window.xprops.prefilledEmail;

    function validUser (email, password) {
      return email && password;
    }

    button.addEventListener('click', function() {
        if (validUser(email.value, password.value)) {
            window.xprops.onLogin(email.value);
        }
    });
</script>

Useful Links

Framework Specific

Rationale

Writing cross domain components is tricky.

Consider this: I own foo.com, you own bar.com, and I have some functionality I want to share on your page. I could just give you some javascript to load in your page. But then:

  • What if I've written a component in React, but you're using some other framework?
  • What if I have secure form fields, or secure data I don't want your site to spy on?
  • What if I need to make secure calls to my back-end, without resorting to CORS?

What about an iframe?

You could just use a vanilla iframe for all of this. But:

  • You have to pass data down in the url, or with a post-message.
  • You need to set up post-message listeners to get events back up from the child.
  • You need to deal with error cases, like if your iframe fails to load or doesn't respond to a post-message.
  • You need to think carefully about how to expose all this functionality behind a simple, clear interface.

zoid solves all of these problems.

  • You pass data and callbacks down as a javascript object
  • zoid renders the component and passes down the data
  • The child calls your callbacks when it's ready

It will even automatically generate React and Angular bindings, so people can drop-in your component anywhere and not worry about iframes or post-messages.

FAQ

  • Do I need to use a particular framework like React to use zoid?

    No, zoid is framework agnostic. You can:

    • Use it with vanilla javascript.
    • Use it with any framework of your choice.
    • Use it with React or Angular and take advantage of the automatic bindings on the parent page
  • Why write another ui / component library?

    This isn't designed to replace libraries like React, which are responsible for rendering same-domain components. In fact, the only real rendering zoid does is iframes and popups; the rest is up to you! You can build your components using any framework, library or pattern you want, then use zoid to expose your components cross-domain. It should play nicely with any other framework!

  • Aren't iframes really slow?

    Yes, but there are a few things to bear in mind here:

    • zoid isn't designed for building components for your own site. For that you should use native component libraries like React, which render quickly onto your page. Use zoid to share functionality with other sites, that you can't share native-javascript components with

    • zoid also provides mechanisms for pre-rendering html and css into iframes and popups, so you can at least render a loading spinner, or maybe something more advanced, while the new window loads its content.

  • I don't want to bother with popups, can I get zoid with just the iframe support?

    You can indeed. There's an zoid.frame.js and zoid.frame.min.js in the dist/ folder. There's a lot of magic that's needed to make popups work with IE, and that's all trimmed out.

  • Can I contribute?

    By all means! But please raise an issue first if it's more than a small change, to discuss the feasibility.

  • Is this different to react-frame-component?

    Yes. react-frame-component allows you to render html into a sandboxed iframe on the same domain. zoid is geared around sharing functionality from one domain to another, in a cross-domain iframe.

Browser Support

  • Internet Explorer 9+
  • Chrome 27+
  • Firefox 30+
  • Safari 5.1+
  • Opera 23+

NPM DownloadsLast 30 Days