Coder Social home page Coder Social logo

ohbarye / react-kana-provider Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 104 KB

A tiny React context provider to build better Japanese form

Home Page: https://www.npmjs.com/package/react-kana-provider

JavaScript 4.22% TypeScript 65.08% HTML 6.51% CSS 24.20%
react react-context react-hooks japanese kana furigana

react-kana-provider's Introduction

[DEPRECATED] React Kana Provider

Please use https://github.com/ohbarye/react-use-kana , React hook version of this library.

A tiny context provider to build a better Japanese form. With this library, you can implement a feature to automatically fill in kana in your form.

demo

NOTE: This library is experimental. API, specification or anything can change in the future.

In-browser playground

Usage

You can see an example code in https://github.com/ohbarye/react-kana-provider/tree/master/example.

Installation

npm install react-kana-provider
# or
yarn add react-kana-provider

Basic

Let's see the easiest example.

basic

import React from "react";
import ReactDOM from "react-dom";
import { KanaProvider, KanaDispatcher, KanaConsumer } from "react-kana-provider";

const App = () => (
  <KanaProvider fieldNames={["last_name"]}>
    <KanaDispatcher>
      {({ setKana }) => (
        <input
          type="text"
          onChange={e => setKana("last_name", e.target.value)}
        />
      )}
    </KanaDispatcher>
    <KanaConsumer>
      {({ kana }) => (
        <input
          type="text"
          value={kana.last_name}
        />
      )}
    </KanaConsumer>
  </KanaProvider>
);

ReactDOM.render(<App />, document.getElementById("root"));

As like above, react-kana-provider serves 3 components.

  1. KanaProvider
    • KanaProvider is a provider of context. You need to pass field names as props so that the context can have multiple kana. I believe it's very common that a Japanese form has two kana fields for last name and first name.
  2. KanaDispatcher
    • KanaDispatcher is a consumer of context, but it serves dispatch method to let the context update kana which corresponds to the given field name.
  3. KanaConsumer
    • KanaConsumer is a consumer of context to receive an object which contains kana.

TypeScript

KanaDispatcherProps and KanaConsumerProps are available to give type definition.

import * as React from "react";
import * as ReactDOM from "react-dom";
import {
  KanaProvider,
  KanaDispatcher,
  KanaConsumer,
  KanaDispatcherProps,
  KanaConsumerProps
} from "react-kana-provider";

const App = () => (
  <KanaProvider fieldNames={["last_name"]}>
    <KanaDispatcher>
      {({ setKana }: KanaDispatcherProps) => (
        <input
          type="text"
          onChange={e => setKana("last_name", e.target.value)}
        />
      )}
    </KanaDispatcher>
    <KanaConsumer>
      {({ kana }: KanaConsumerProps) => (
        <input
          type="text"
          value={kana.last_name}
         />
      )}
    </KanaConsumer>
  </KanaProvider>
  );
);

ReactDOM.render(<App />, document.getElementById("root"));

Feature

This library uses:

Requirement

  • react >= 16.8

react-kana-provider's People

Contributors

ohbarye avatar

Watchers

 avatar  avatar  avatar

react-kana-provider's Issues

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.