stripe-stenciljs v0.0.8
Stencil Component Starter
This is a starter project for building a standalone Web Component using Stencil.
Stencil is also great for building entire apps. For that, use the stencil-app-starter instead.
Stencil
Stencil is a compiler for building fast web apps using Web Components.
Stencil combines the best concepts of the most popular frontend frameworks into a compile-time rather than run-time tool. Stencil takes typescript, JSX, a tiny virtual DOM layer, efficient one-way data binding, an asynchronous rendering pipeline (similar to React Fiber), and lazy-loading out of the box, and generates 100% standards-based Web Components that run in any browser supporting the Custom Elements v1 spec.
Stencil components are just Web Components, so they work in any major framework or with no framework at all.
Getting Started
The following list contains the framework integrations that have been started. All of them are not yet completed:
Angular
Using a Stencil built web component collection within an Angular CLI project is a two-step process. We need to:
AppModule.ts 1. Include the CUSTOM_ELEMENTS_SCHEMA in the modules that use the components
import { BrowserModule } from '@angular/platform-browser';
+ import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { SharedModule } from './shared/shared.module';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, FormsModule, SharedModule],
bootstrap: [AppComponent],
+ schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class AppModule {}
The CUSTOM_ELEMENTS_SCHEMA needs to be included in any module that uses custom elements.
Main.ts 1. Call defineCustomElements(window) from main.ts (or some other appropriate place)
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
+ import { defineCustomElements } from 'stripe-stenciljs/dist/loader';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));
+ defineCustomElements(window);
Using this component
In your specified component
import 'stripe-stenciljs';
In your component html
<stripe-component></stripe-component>
This component uses stripe so in your index.html add this in the tag.
<script rel=preload src="http://js.stripe.com/v3/"></script>
<script type="text/javascript">
var stripe = Stripe('stripe key in here'); // use your test publishable key
var elements = stripe.elements();
</script>
Notes
If you get errors in your component for keyword stripe or elements add this to your typings.d.ts
declare var stripe: any;
declare var elements: any;
React
Index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
// test-component is the name of our made up Web Component that we have
// published to npm:
+ import { defineCustomElements } from 'stripe-stenciljs/dist/loader';
ReactDOM.render(<App />, document.getElementById('root'));
+ defineCustomElements(window);
Index.html
<script rel=preload src="http://js.stripe.com/v3/"></script>
<script type="text/javascript">
var stripe = Stripe('stripe key in here'); // use your test publishable key
var elements = stripe.elements();
</script>
In component JSX Section
add
return (
...
<stripe-component />
)
Script tag
- Put a script tag similar to this
<script src='https://unpkg.com/my-component@0.0.1/dist/mycomponent.js'></script>
in the head of your index.html - Then you can use the element anywhere in your template, JSX, html etc
Node Modules
- Run
npm install my-component --save
- Put a script tag similar to this
<script src='node_modules/my-component/dist/mycomponent.js'></script>
in the head of your index.html - Then you can use the element anywhere in your template, JSX, html etc