0.1.11 • Published 1 year ago

reuse-ui v0.1.11

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

Reuse UI

A collection of reusable React components

Index

Installation

Install Reuse UI from npm

Using npm:

npm install reuse-ui

Using yarn:

yarn add reuse-ui

Usage

Selection Area

The <SelectionArea /> component is a component for displaying selectable list items. The list items can be an array of the following types:

  • string
  • number
  • {name: string, value: any}

Example #1

import { useState } from "react";

function App() {
	const selections = ["Michael", "Ashley", "Christopher", "Jessica"];
	const [selected, setSelected] = useState(selections[0]);
	return <SelectionArea selections={SELECTIONS} selected={selected} setSelected={setSelected} />;
}

Example #2

import { useEffect, useState } from "react";

const URL = "https://jsonplaceholder.typicode.com/users";

function App() {
	const [selections, setSelections] = useState([]);
	const [selected, setSelected] = useState("");

	useEffect(() => {
		fetch(URL)
			.then((res) => res.json())
			.then((data) => {
				const users = data.map((user) => ({
					name: user.name,
					value: { id: user.id, name: user.name, email: user.email },
				}));
				setSelections(users);
				setSelected(users[0]);
			});
	}, []);

	const updateSelected = async (newSelected) => {
		fetch(URL, {
			method: "POST",
			headers: {
				"Content-Type": "application/json",
			},
			body: JSON.stringify({ user: newSelected.value }),
			mode: "cors",
		});

		setSelected(newSelected);
	};

	return <SelectionArea selections={selections} selected={selected} setSelected={updateSelected} />;
}

Selection Area Arguments

ArgumentDescription
selectionsArray of list items to display (string[], number[], or {name: string, value: any}[])
selectedSelected value
setSelectedFunction for setting value of selected and performing other actions
dimensionObject to set width and height of Selection Area ({width: string, height: string})
idSet ID of Selection Area
classNameSet classes of Selection Area
styleCSS style to apply to Selection Area
0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago