Skip to content

Instantly share code, notes, and snippets.

@jongan69
Last active February 15, 2023 23:39
Show Gist options
  • Select an option

  • Save jongan69/91964be9f11dc81132f1158f7c9928c5 to your computer and use it in GitHub Desktop.

Select an option

Save jongan69/91964be9f11dc81132f1158f7c9928c5 to your computer and use it in GitHub Desktop.

CheckBox

Checkbox is a React component used to allow users to select or deselect an option.

Usage

To use the CheckBox component, import it into your React component:

import CheckBox from 'react-checkbox';

Then, you can use the component like this:

<CheckBox 
  description="This is a checkbox" 
  id="checkbox-example" 
  onUpdate={() => doSomething()} 
/>

This will render a checkbox with the given description. When the user checks or unchecks the box, the onUpdate callback will be called.

License

CheckBox is released under the MIT license.

Form

This React component renders a custom form given a set of user-defined inputs.

Properties

Property Type Description
dataType {String} The type of data to be submitted.
description {String} The description of the form.
inputs {Array} An array of user-defined inputs.
name {String} The name of the form.
operation {String} The type of operation to be performed on the data.

Inputs

The form supports the following types of inputs:

  • Input
  • Checkbox
  • Radio

Input

The Input component renders a simple HTML input element.

Properties

Property Type Description
description {String} The description of the input.
format {Function} A function used to format the value of the input.
onUpdate {Function} A function called when the value of the input changes

Input

Input is a React component that allows users to enter data into a form. It takes the following props:

  • description: a placeholder string that describes the type of data expected
  • format: a string that defines the data type for number inputs
  • onUpdate: a callback function to handle changes to the input
  • required: a boolean value that determines if the input is required or not
  • type: the type of data (e.g. text, number, etc.)

Usage

Input can be used by simply passing the required props to the component:

<Input 
  description="Enter your name"
  required={true}
  type="text"
  onUpdate={(e) => handleNameChange(e.target.value)}
/>

For number inputs, you can also specify a format prop to handle ints vs floats:

<Input 
  description="Enter your age"
  required={true}
  type="number"
  format="float"
  onUpdate={(e) => handleAgeChange(e.target.value)}
/>

Radio

Radio is a React component that allows users to select a radio button.

Usage

The Radio component takes two props: onUpdate and value.

onUpdate is a function that is called when the radio button is changed.

value is the value of the radio button.

import React from 'react';
import Radio from './Radio';

const onUpdate = (value) => {
  // do something with value
}

const App = () => {
  return (
    <Radio onUpdate={onUpdate} value="Option A" />
  );
}

This will render a radio button with the value of "Option A". When the radio button is changed, the onUpdate function will be called with the new value.

Title

Title is a React component that displays a title.

Usage

To use the component, import the component into your React project and render it:

import React from 'react';
import Title from 'title-component';

const App = () => {
  return (
    <div>
      <Title title="My Title" />
    </div>
  )
};

export default App;

This will render a title with the text "My Title".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment