UNPKG

@primer/react

Version:

An implementation of GitHub's Primer Design System using React

11 lines (8 loc) 1.48 kB
'use strict'; /** * @license * Copyright 2018 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const t=new Set(["children","localName","ref","style","className"]),e=new WeakMap,n=(t,n,s,i,o)=>{const l=null==o?void 0:o[n];void 0===l||s===i?null==s&&n in HTMLElement.prototype?t.removeAttribute(n):t[n]=s:((t,n,s)=>{let i=e.get(t);void 0===i&&e.set(t,i=new Map);let o=i.get(n);void 0!==s?void 0===o?(i.set(n,o={handleEvent:s}),t.addEventListener(n,o)):o.handleEvent=s:void 0!==o&&(i.delete(n),t.removeEventListener(n,o));})(t,l,s);};function s(e=window.React,s,i,o,l){let d,c,a;if(void 0===s){const t=e;(({tagName:c,elementClass:a,events:o,displayName:l}=t)),d=t.react;}else d=e,a=i,c=s;const r=d.Component,h=d.createElement,u=new Set(Object.keys(null!=o?o:{}));class f extends r{constructor(){super(...arguments),this.o=null;}t(t){if(null!==this.o)for(const e in this.i)n(this.o,e,this.props[e],t?t[e]:void 0,o);}componentDidMount(){this.t();}componentDidUpdate(t){this.t(t);}render(){const{_$Gl:e,...n}=this.props;this.h!==e&&(this.u=t=>{null!==e&&((t,e)=>{"function"==typeof t?t(e):t.current=e;})(e,t),this.o=t,this.h=e;}),this.i={};const s={ref:this.u};for(const[e,i]of Object.entries(n))t.has(e)?s["className"===e?"class":e]=i:u.has(e)||e in a.prototype?this.i[e]=i:s[e]=i;return h(c,s)}}f.displayName=null!=l?l:a.name;const v=d.forwardRef(((t,e)=>h(f,{...t,_$Gl:e},null==t?void 0:t.children)));return v.displayName=f.displayName,v} exports.createComponent = s;