React.js UIコンポーネント「Elementz」を使用する

React.js UIコンポーネント「Elementz」を使用する

わずか約500kbのUIコンポーネント「Elementz」を使用するための手順と簡単な使い方を記述してます。

環境

  • OS  Rocky Linux release 8.4 (Green Obsidian)
  • node v14.17.3
  • npm 7.19.1
  • yarn 1.22.10
  • React 17.0.2

react.js環境構築

下記のコマンドで構築してます。ここでは、react-appという名前でプロジェクトを作成してます。

yarn global add create-react-app
npx create-react-app react-app

Elementzインストール

作成したプロジェクトに移動して、インストールします。

## 作成したプロジェクトに移動
cd react-app
 
## インストール
yarn add Elementz

Elementz使い方

srcディレクトリにsample.jsと名前で、以下のコードを記述します。

import React from 'react'
import {Button, Alert} from 'elementz'

const Sample = () => {

    return (
        <div>
            <Button.Group space>
                <Button>I'm basic</Button>
                <Button primary>Primary</Button>
                <Button secondary>Secondary</Button>
                <Button warning>I'm warning you</Button>
                <Button 
                    danger 
                    effect='icon-buzz' 
                    iconRight='sad' 
                    onClick={()=> Alert.danger("So dangerous")}
                    >I'm dangerous</Button>
                <Button success>I'm successful</Button>
            </Button.Group>
        </div>
    );
};

export default Sample;

次に、srcディレクトリ配下にあるApp.jsを下記のように編集します。

import React from 'react';
import Sample from './sample';
import './App.css';

function App() {
  const style = {
    width: "30%",
    margin: "0 auto",
    marginTop: 250,
  };
  return (
    <div className="App">
      <div style={style}>
        <Sample />
      </div>
    </div>
  );
}

export default App;

実行します。

yarn start

ブラウザから http://プライベートIP:3000にアクセスすると、buttonが作成されていることが確認できます。

その他のコンポーネントはこちらで確認できます。