GithubHelp home page GithubHelp logo

vasturiano / react-kapsule Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 2.0 315 KB

React wrapper for kapsule-style web components

License: MIT License

HTML 32.00% JavaScript 68.00%
kapsule react-hoc web-component reusable-components

react-kapsule's Introduction

react-kapsule

NPM package Build Size NPM Downloads

A React wrapper for kapsule-style web components.

Quick start

import fromKapsule from 'react-kapsule';

or using a script tag

<script src="//unpkg.com/react-kapsule"></script>

Usage example

Given a kapsule component:

const myKapsule = Kapsule({ 
  props: {
    prop1: {},
    prop2: {}
  },
  ...
});

Render it in React:

const MyKapsuleComponent = fromKapsule(myKapsule);

ReactDOM.render(
  <MyKapsuleComponent
    prop1="a value"
    prop2="another value"
  />,
  myDOMElement
);

API reference

const MyComponent = fromKapsule(kapsuleComponent, options);

Returns

A React component that includes the methods of the kapsule component available as props.

Arguments

  • kapsuleComponent

Any closure based functional component which accepts prop changes as functional methods. Following the spec in reusable charts pattern. Can be conveniently defined using the Kapsule framework.

  • options

An object with configuration options that can be used to define the React component. For example:

{
  wrapperElementType: 'span'
}
Option Type Default Description
wrapperElementType string or React component 'div' The type of DOM element used by the underlying React createElement to mount the component. Can be either a tag name string (such as 'div' or 'span') or a React component type (a class or a function).
nodeMapper function node => node A mapping function that allows to convert the DOM node into an object understood by the kapsule component.
methodNames array of strings [] The list of kapsule component methods that should be available as React component bound methods, instead of direct props. Generally these methods will be called via the component ref, i.e. myComponentRef.current.myMethod(...).
initPropNames array of strings [] The list of props that are intended to be passed as configuration options to the kapsule component's instantiation call. Modifying the values of these props after the initial mount of the React component will have no effect.

react-kapsule's People

Contributors

vasturiano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-kapsule's Issues

Building problem

Hello,
using Yarn workspaces, building my project where react-force-graph is a subproject dependency, I'm encountering a build error:
_

Creating an optimized production build...
Failed to compile.

/Users/aboschini/WebstormProjects/monorepo/node_modules/react-kapsule/dist/react-kapsule.module.js
Attempted import error: 'fromentries' does not contain a default export (imported as 'fromEntries').

_

Manually solved by fixing the import.
thanks

Incorrect use of hooks

Warning: An effect function must not return anything besides a function, which is used for clean-up. You returned: false

// @ts-ignore No typedefs yet
import SunburstChart from 'sunburst-chart';
// @ts-ignore No typedefs yet
import fromKapsule from 'react-kapsule';
const ReactSunburst = fromKapsule(SunburstChart)

How to add custom behaviour on click event to sunburst component built with react-kapsule?

When sunburst component is used in react built with react-kapsule, how can I add custom behavior on click event of any slice of sunburst.

From suggestion here, I tried something like this:

  <ReactSunburst
    //...
    data={data}
    onClick={(node) => {
      myChart.focusOnNode(node);
      console.log("clicked");
    }}
  /> 

The problem I faced is that myChart is undefined inside the onClick handler of react component. So, this gives myChart is not defined error and the chart does not perform the default zooming behavior. If I omit the first line, "clicked" gets printed to the console.
Codesandbox link.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.