Git Product home page Git Product logo

koji-react-beta-components's Introduction

koji-react-beta-components

Installation

npm install --save @arist0tl3/koji-react-beta-components

Usage

See below for a basic example. You can also check out https://withkoji.com/~seane/text-component-test for a live example.

/* eslint-disable jsx-a11y/click-events-have-key-events */
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
import React, { useState } from 'react';
import styled from 'styled-components';

import get from 'utils/get';
import useStore from 'Store/useStore';
import { InstantRemixing } from '@withkoji/vcc';

import { EditTextModal } from '@arist0tl3/koji-react-beta-components';

const Container = styled.div`
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #333333;
  color: #ffffff;
`;

const Remix = () => {
  const instantRemixing = new InstantRemixing();

  const [isEditingTitle, setIsEditingTitle] = useState(false);

  const [title, setTitle] = useState(instantRemixing.get(['strings', 'title']));
  const [titleColor, setTitleColor] = useState(instantRemixing.get(['strings', 'titleColor']));
  const [titleFontFamily, setTitleFontFamily] = useState(instantRemixing.get(['strings', 'titleFontFamily']));
  const [titleStyle, setTitleStyle] = useState(instantRemixing.get(['strings', 'titleStyle']));

  useEffect(() => {
    instantRemixing.onValueChanged(() => {
      // Handle state updates
    });

    instantRemixing.ready();
  }, []);

  return (
    <Container>
      <h1
        onClick={() => setIsEditingTitle(true)}
        style={{
          color: titleColor,
          fontFamily: titleFontFamily,
          ...titleStyle,
        }}
      >
        {title}
      </h1>
      <EditTextModal
        fontValue={{
          fontFamily: titleFontFamily,
          style: titleStyle,
        }}
        onColorChange={(color) => {
          instantRemixing.onSetValue(['strings', 'titleColor'], color);
        }}
        onFontChange={({ fontFamily, style = {} }) => {
          instantRemixing.onSetValue(['strings', 'titleFontFamily'], fontFamily);
        }}
        onTextBlur={(val) => {
          instantRemixing.onSetValue(['strings', 'title'], val);
        }}
        onCloseModal={() => setIsEditingTitle(false)}
        open={isEditingTitle}
        textValue={title}
      />
    </Container>
  );
};

export default Remix;

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.