Skip to content

Instantly share code, notes, and snippets.

@JEbertPrime
Last active June 6, 2023 20:34
Show Gist options
  • Save JEbertPrime/29411f9f5d50030ad8134c7c003772fe to your computer and use it in GitHub Desktop.
Save JEbertPrime/29411f9f5d50030ad8134c7c003772fe to your computer and use it in GitHub Desktop.
Random HTML component
import {tags, voids} from './tags.js'
export default function RandomElement (props) {
var value = props.value ? props.value : Math.floor(Math.random()*tags.length)
var Tag = tags[value]
if(voids[Tag]){
return(
<Tag/>
)
}
else{
return(
<Tag>{props.children}</Tag>
)
}
}
const tags = [
'a',
'abbr',
'address',
'article',
'aside',
'b',
'bdi',
'bdo',
'blockquote',
'button',
'canvas',
'caption',
'cite',
'code',
'details',
'dfn',
'dialog',
'div',
'em',
'footer',
'form',
'header',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'i',
'input',
'ins',
'kbd',
'keygen',
'label',
'legend',
'li',
'main',
'mark',
'menu',
'nav',
'noscript',
'object',
'ol',
'optgroup',
'output',
'p',
'param',
'pre',
'progress',
'q',
's',
'samp',
'section',
'select',
'small',
'span',
'strong',
'sub',
'sup',
'table',
'tbody',
'td',
'textarea',
'tfoot',
'th',
'thead',
'time',
'title',
'tr',
'u',
'ul'
]
const voids = {
'area',
'base',
'input',
'meta',
'param',
'keygen'
}
export {tags, voids}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment