Git Product home page Git Product logo

react-known-props's Introduction

React Known Props Tweet

Build Status Latest version code style: prettier downloads/month


About 700 props React recognizes.

  • HTML & SVG props valid on any element (global props).
  • HTML & SVG element specific props.
  • ARIA props (includes role).
  • React event props.
  • React specific props.
  • Options you can set.

HTML attributes and React Properties are mixed together, the rationale is that if react accepts the prop, we include it. see #25 for more info

Install

install with

yarn add react-known-props
npm i react-known-props

then use with

import {
  getAllProps,
  getElementProps,
  getEventProps,
  getGlobalProps
} from "react-known-props";
const {
  getAllProps,
  getElementProps,
  getEventProps,
  getGlobalProps
} = require("react-known-props");

API

Functions provided

All functions return the props as strings in an array.

Element names are case-sensitive

  • HTML elements are all lowercase
  • SVG elements are lowercase and camelCase

See options below.

getAllProps

Gets all possible props: Global props, element specific props, event props and ARIA props including role.

// argument 1 (optional): an options object.

getAllProps();
getAllProps({ legacy: true });

// this
getAllProps().length;

// returns
675;

getElementProps

Gets all props valid on the HTML/SVG element provided as argument, plus all ARIA props, including role. Doesn't include event props.

// argument 1: string. Element to get props for.
// argument 2: (optional) an options object.

getElementProps("img")
getElementProps("iframe")
getElementProps("ellipse")
getElementProps("table", {legacy: true})
getElementProps("audio", {onlyReact: true})
getElementProps("polygon", {onlyReact: true})

// this
getElementProps("img")

// returns
[ 'align',
      'alt',
      'crossOrigin',
      'crossorigin',
      'height',
      'isMap',
      'ismap',
      'sizes',
      (...)
]

getEventProps

Gets React's event props only.

// arguments: none.

// this
getEventProps()

// returns
[ 'onBlur',
      'onChange',
      'onClick',
      'onContextMenu',
      'onCopy',
      'onCut',
      (...)
]

getGlobalProps

Gets all HTML and SVG props valid on any element, plus all ARIA props including role.

// argument 1 (optional): an options object.

getGlobalProps()
getGlobalProps({onlyReact: true})

// this
getGlobalProps()

// returns
[
  'accessKey',
  'accesskey',
  'autoCapitalize',
  'autocapitalize',
  'className',
  'class',
  'contentEditable',
  'contenteditable',
  (...)
]

Options

legacy

Default: false.

Whether or not to return deprecated HTML props bgcolor, border and color for the elements that still use them.

// examples:

// will include bgcolor in the props
getAllProps({ legacy: true });

// will omit legacy props
getAllProps({ legacy: false });

// same as {legacy: false}
getAllProps();

onlyReact

Default: false.

Whether to return only the React prop, or the HTML prop and the React prop. In React, some HTML props are renamed to camelCase (e.g. class -> className) and using the HTML lowercase name will show a warning. The same happens with SVG. Since the warning can be educational this option is off by default.

// examples:

// will include class and className, for and htmlFor, etc...
getElementProps("label");

// same as above
getElementProps("label", { onlyReact: false });

// no duplication, only React props are returned (itemID, tabIndex, autoCapitalize, className, htmlFor, etc...)
getGlobalProps({ onlyReact: true });

sort

Default: false*.

Sort the props alphabetically before returning them. It uses Array.prototype.sort.
*Not supported on getEventProps. Please sort it manually.

// examples:

getAllProps();
// not sorted
[
  (...)
  'aria-valuetext',
  'role',
  'accessKey',
  'accesskey',
  'autoCapitalize',
  'autocapitalize',
  'className',
  'class',
  (...)
]

// sorted
getAllProps({ sort: true });
getGlobalProps({ sort: true });

Incompatible SVG props not included.

React doesn't like all SVG props, some prevent it from compiling and print an error to the console. They are:

  • Props prefixed by xml:
  • Props prefixed by xlink:
  • Props prefixed by on (events)
  • ev:event

Need more props?

I'd use these packages:

  • Void HTML elements (self closing, e.g. <img/>): yarn add void-elements
  • Css props: yarn add known-css-properties

Contributing

Fork, make changes, run the build:lists script and send a PR. build:lists takes the stuff in src/generator and makes the files in src/generated. This is for performance reasons.

All data pulled from MDN web docs, official React docs, the ARIA specification and SVG specification. MDN can be a deep website to dig for info, I'm sure there are more props (specially legacy) waiting to be added by someone willing to look into every element page.

โš›๏ธ React is awesome ๐Ÿ’ซ

react-known-props's People

Contributors

dependabot[bot] avatar diegohaz avatar tcodes0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

react-known-props's Issues

Are there new props?

This lib is just a collection of props react knows about (for web). It's been about a year I collected the props. Are there new props? ๐Ÿค”

Some changes

First, I think we should get rid of html-attributes, since the repository doesn't exist anymore.

Second, we should provide methods to get global props and element props.

Attributes reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes

import { getAllProps, getGlobalProps, getElementProps } from "react-known-props";

// get all props including legacy ones
getAllProps({ legacy: true });

// get props that can be attached to any element (according to the reference, there's no legacy global props)
getGlobalProps();

// get global props plus the ones that can be attached to img, including legacy ones
getElementProps("img", { legacy: true });

Use babel

Some old browsers don't support const and other syntaxes we're using here. We need to start using babel or get rid of them.

Html textarea does not accept value property

About

Html textarea properties (source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea), value is not a valid one:

autocapitalize

Note: This [autocapitalize] is a non-standard attribute supported by WebKit on iOS (therefore nearly all browsers running on iOS, including Safari, Firefox, and Chrome), which controls whether and how the text value should be automatically capitalized as it is entered/edited by the user. The non-deprecated values are available in iOS 5 and later

autocomplete
autofocus
cols
disabled
form
maxlength
minlength
name
placeholder
readonly
required
rows
spellcheck
wrap

textarea also accepts global attributes: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes.

Possible solution

The correct attributes need to be added here https://github.com/Thomazella/react-known-props/blob/90885fbbcdac6eb4b88f74e195f8a8b48fbc1e0f/src/generated/reactHtmlElementsToPropsMap.js#L309-L331

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.