Giter VIP home page Giter VIP logo

crate-builder-component-react's Introduction

Describo Crate Builder Component for react

This is a wrapper for the Vue Crate Builder Component for applications using React.

Installation

npm install --save @describo/crate-builder-component-react

or

yarn add @describo/crate-builder-component-react

Usage

import React, {useState} from 'react';
import {DescriboCrateBuilder, JSONObject} from "@describo/crate-builder-component-react";
import "@describo/crate-builder-component-react/style.css";

const exampleCrate = {
  "@context": "https://w3id.org/ro/crate/1.1/context",
  "@graph": [
    {
      "@type": "CreativeWork",
      "@id": "ro-crate-metadata.json",
      "conformsTo": {"@id": "https://w3id.org/ro/crate/1.1"},
      "about": {"@id": "./"}
    },
    {
      "@id": "./",
      "identifier": "https://doi.org/10.4225/59/11111111",
      "@type": "Dataset",
      "datePublished": "2017",
      "name": "Dataset name",
      "description": "Dataset description",
    }
  ]
}

function App() {
  const [crate, setCrate] = useState<JSONObject>(exampleCrate)
  return (
    <>
      <DescriboCrateBuilder crate={exampleCrate} onSaveCrate={(crateValue) => setCrate(crateValue.crate)} />
      <pre>
        {JSON.stringify(crate, null, 2)}
      </pre>
    </>
  );
}

export default App;

Note: in the example above we set the inital value of the crate from exampleCrate and not crate so that we don't update the Vue component's crate vaue whenever onSaveCrate() is called, which will cause reloading of teh component and will result in flickering.

Testing

To try the component you can use the included storybook:

npm i
npm run storybook

CSS customization of the crate builder

You can customize some aspects of the crate builder by overriding CSS of various elements. For example, to make the layout tab texts smaller and green you can create a styles.css:

.el-tabs__header * {
    font-size: 1rem;
    color: forestgreen;
}

and use it in App.tsx like this:

import React, {useState} from 'react';
import {DescriboCrateBuilder, JSONObject} from "@describo/crate-builder-component-react";
import "@describo/crate-builder-component-react/style.css";
import "./styles.css";

...

crate-builder-component-react's People

Contributors

beepsoft avatar

Stargazers

Janne Jensen avatar

Watchers

 avatar  avatar Zoltán Tóth avatar Andras Micsik avatar

crate-builder-component-react's Issues

0.25.3 released

When you build a new version of this component can you please bump the version to 0.25.3 so that it's in sync with the vue component?

Can we please add a licence

@beepsoft

All of my code has to be GPLv3 to satisfy funding requirements but since this is your repo; the licence you apply is up to you. All I would ask is that it's a suitably permissive licence if possible.

React component without Web Component

The current implementation of the React component depends on the Web Component build of crate builder Vue component. We used this approach because there was no well established way to use Vue3 in React, only some example for Vue2. Web Component was a compromise, because it makes the Vue component usable in any javascript frontend environment, including React. However, the Vue Web Component builder also has some issues and results in a huge bundle.

Once a Vue component is built it becomes just a javascript function, so it should be possible to use it like that, as vanilla JS without the .vue compilation magic in any JS app.

So, I try to get rid of Web Component and use the Vue crate builder component "directly" in the React component.

Possible solutions:

@marcolarosa, what do you think?

0.29.6 release

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.