backpack-ui
Version:
Lonely Planet's Components
167 lines (163 loc) • 2.43 kB
JavaScript
// https://react-legacy.netlify.com/docs/dom-elements.html
const standardAttributes = [
"accept",
"acceptCharset",
"accessKey",
"action",
"allowFullScreen",
"allowTransparency",
"alt",
"async",
"autoComplete",
"autoFocus",
"autoPlay",
"capture",
"cellPadding",
"cellSpacing",
"challenge",
"charSet",
"checked",
"cite",
"classID",
"className",
"colSpan",
"cols",
"content",
"contentEditable",
"contextMenu",
"controls",
"controlsList",
"coords",
"crossOrigin",
"data",
"dateTime",
"default",
"defer",
"dir",
"disabled",
"download",
"draggable",
"encType",
"form",
"formAction",
"formEncType",
"formMethod",
"formNoValidate",
"formTarget",
"frameBorder",
"headers",
"height",
"hidden",
"high",
"href",
"hrefLang",
"htmlFor",
"httpEquiv",
"icon",
"id",
"inputMode",
"integrity",
"is",
"keyParams",
"keyType",
"kind",
"label",
"lang",
"list",
"loop",
"low",
"manifest",
"marginHeight",
"marginWidth",
"max",
"maxLength",
"media",
"mediaGroup",
"method",
"min",
"minLength",
"multiple",
"muted",
"name",
"noValidate",
"nonce",
"open",
"optimum",
"pattern",
"placeholder",
"poster",
"preload",
"profile",
"radioGroup",
"readOnly",
"rel",
"required",
"reversed",
"role",
"rowSpan",
"rows",
"sandbox",
"scope",
"scoped",
"scrolling",
"seamless",
"selected",
"shape",
"size",
"sizes",
"span",
"spellCheck",
"src",
"srcDoc",
"srcLang",
"srcSet",
"start",
"step",
"style",
"summary",
"tabIndex",
"target",
"title",
"type",
"useMap",
"value",
"width",
"wmode",
"wrap",
];
const nonStandardAttributes = [
"about",
"datatype",
"inlist",
"prefix",
"property",
"resource",
"typeof",
"vocab",
"autoCapitalize",
"autoCorrect",
"color",
"itemProp",
"itemScope",
"itemType",
"itemRef",
"itemID",
"security",
"unselectable",
"results",
"autoSave",
];
export const validReactAttributes = attrs => {
const regexAttributes = /((data-|aria-))\w+/g;
return Object.entries(attrs).reduce((iterator, [key, value]) => {
if (
regexAttributes.test(key) ||
standardAttributes.includes(key) ||
nonStandardAttributes.includes(key)
) {
iterator[key] = value;
}
return iterator;
}, {});
};
export default { validReactAttributes };