@oslokommune/punkt-react 0.20.21 → 0.22.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/CONTRIBUTING.md +67 -0
- package/LICENSE +16 -17
- package/README.md +31 -18
- package/dist/button/Button.d.ts +10 -0
- package/dist/header/Header.d.ts +13 -0
- package/dist/icon/Icon.d.ts +7 -0
- package/dist/index.d.ts +9 -0
- package/dist/input/Input.d.ts +21 -0
- package/dist/punkt-react.es.js +806 -0
- package/dist/punkt-react.umd.js +31 -0
- package/dist/radio/Radio.d.ts +9 -0
- package/dist/radioGroup/RadioGroup.d.ts +8 -0
- package/dist/table/Table.d.ts +11 -0
- package/dist/table/TableData.d.ts +6 -0
- package/dist/table/TableHeader.d.ts +6 -0
- package/dist/textarea/Textarea.d.ts +7 -0
- package/package.json +47 -29
- package/src/components/button/Button.tsx +39 -0
- package/src/components/header/Header.tsx +81 -0
- package/src/components/icon/Icon.tsx +21 -0
- package/src/components/index.ts +9 -0
- package/src/components/input/Input.tsx +36 -0
- package/src/components/radio/Radio.tsx +23 -0
- package/src/components/radioGroup/RadioGroup.tsx +16 -0
- package/src/components/table/Table.test.tsx +105 -0
- package/src/components/table/Table.tsx +35 -0
- package/src/components/table/TableData.tsx +7 -0
- package/src/components/table/TableHeader.tsx +7 -0
- package/src/components/textarea/Textarea.tsx +21 -0
- package/dist/cjs/index.js +0 -6
- package/dist/cjs/index.js.map +0 -1
- package/dist/esm/index.js +0 -6
- package/dist/esm/index.js.map +0 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
(function(_,x){typeof exports=="object"&&typeof module<"u"?x(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],x):(_=typeof globalThis<"u"?globalThis:_||self,x(_["punkt-react"]={},_.React))})(this,function(_,x){"use strict";var W={},De={get exports(){return W},set exports(n){W=n}},Y={};/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react-jsx-runtime.production.min.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/var ae;function Ae(){if(ae)return Y;ae=1;var n=x,c=Symbol.for("react.element"),p=Symbol.for("react.fragment"),u=Object.prototype.hasOwnProperty,v=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,d={key:!0,ref:!0,__self:!0,__source:!0};function k(R,m,C){var E,w={},j=null,V=null;C!==void 0&&(j=""+C),m.key!==void 0&&(j=""+m.key),m.ref!==void 0&&(V=m.ref);for(E in m)u.call(m,E)&&!d.hasOwnProperty(E)&&(w[E]=m[E]);if(R&&R.defaultProps)for(E in m=R.defaultProps,m)w[E]===void 0&&(w[E]=m[E]);return{$$typeof:c,type:R,key:j,ref:V,props:w,_owner:v.current}}return Y.Fragment=p,Y.jsx=k,Y.jsxs=k,Y}var $={};/**
|
|
10
|
+
* @license React
|
|
11
|
+
* react-jsx-runtime.development.js
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/var ne;function Ie(){return ne||(ne=1,process.env.NODE_ENV!=="production"&&function(){var n=x,c=Symbol.for("react.element"),p=Symbol.for("react.portal"),u=Symbol.for("react.fragment"),v=Symbol.for("react.strict_mode"),d=Symbol.for("react.profiler"),k=Symbol.for("react.provider"),R=Symbol.for("react.context"),m=Symbol.for("react.forward_ref"),C=Symbol.for("react.suspense"),E=Symbol.for("react.suspense_list"),w=Symbol.for("react.memo"),j=Symbol.for("react.lazy"),V=Symbol.for("react.offscreen"),ue=Symbol.iterator,He="@@iterator";function Je(e){if(e===null||typeof e!="object")return null;var r=ue&&e[ue]||e[He];return typeof r=="function"?r:null}var D=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function g(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),a=1;a<r;a++)t[a-1]=arguments[a];ze("error",e,t)}}function ze(e,r,t){{var a=D.ReactDebugCurrentFrame,l=a.getStackAddendum();l!==""&&(r+="%s",t=t.concat([l]));var f=t.map(function(i){return String(i)});f.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,f)}}var qe=!1,Ke=!1,Xe=!1,Ze=!1,Qe=!1,ce;ce=Symbol.for("react.module.reference");function er(e){return!!(typeof e=="string"||typeof e=="function"||e===u||e===d||Qe||e===v||e===C||e===E||Ze||e===V||qe||Ke||Xe||typeof e=="object"&&e!==null&&(e.$$typeof===j||e.$$typeof===w||e.$$typeof===k||e.$$typeof===R||e.$$typeof===m||e.$$typeof===ce||e.getModuleId!==void 0))}function rr(e,r,t){var a=e.displayName;if(a)return a;var l=r.displayName||r.name||"";return l!==""?t+"("+l+")":t}function fe(e){return e.displayName||"Context"}function O(e){if(e==null)return null;if(typeof e.tag=="number"&&g("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case u:return"Fragment";case p:return"Portal";case d:return"Profiler";case v:return"StrictMode";case C:return"Suspense";case E:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case R:var r=e;return fe(r)+".Consumer";case k:var t=e;return fe(t._context)+".Provider";case m:return rr(e,e.render,"ForwardRef");case w:var a=e.displayName||null;return a!==null?a:O(e.type)||"Memo";case j:{var l=e,f=l._payload,i=l._init;try{return O(i(f))}catch{return null}}}return null}var N=Object.assign,L=0,de,pe,ve,me,he,be,_e;function ke(){}ke.__reactDisabledLog=!0;function tr(){{if(L===0){de=console.log,pe=console.info,ve=console.warn,me=console.error,he=console.group,be=console.groupCollapsed,_e=console.groupEnd;var e={configurable:!0,enumerable:!0,value:ke,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}L++}}function ar(){{if(L--,L===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:N({},e,{value:de}),info:N({},e,{value:pe}),warn:N({},e,{value:ve}),error:N({},e,{value:me}),group:N({},e,{value:he}),groupCollapsed:N({},e,{value:be}),groupEnd:N({},e,{value:_e})})}L<0&&g("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var q=D.ReactCurrentDispatcher,K;function U(e,r,t){{if(K===void 0)try{throw Error()}catch(l){var a=l.stack.trim().match(/\n( *(at )?)/);K=a&&a[1]||""}return`
|
|
18
|
+
`+K+e}}var X=!1,B;{var nr=typeof WeakMap=="function"?WeakMap:Map;B=new nr}function ge(e,r){if(!e||X)return"";{var t=B.get(e);if(t!==void 0)return t}var a;X=!0;var l=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var f;f=q.current,q.current=null,tr();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(i,[])}catch(S){a=S}Reflect.construct(e,[],i)}else{try{i.call()}catch(S){a=S}e.call(i.prototype)}}else{try{throw Error()}catch(S){a=S}e()}}catch(S){if(S&&a&&typeof S.stack=="string"){for(var o=S.stack.split(`
|
|
19
|
+
`),y=a.stack.split(`
|
|
20
|
+
`),h=o.length-1,b=y.length-1;h>=1&&b>=0&&o[h]!==y[b];)b--;for(;h>=1&&b>=0;h--,b--)if(o[h]!==y[b]){if(h!==1||b!==1)do if(h--,b--,b<0||o[h]!==y[b]){var P=`
|
|
21
|
+
`+o[h].replace(" at new "," at ");return e.displayName&&P.includes("<anonymous>")&&(P=P.replace("<anonymous>",e.displayName)),typeof e=="function"&&B.set(e,P),P}while(h>=1&&b>=0);break}}}finally{X=!1,q.current=f,ar(),Error.prepareStackTrace=l}var I=e?e.displayName||e.name:"",Fe=I?U(I):"";return typeof e=="function"&&B.set(e,Fe),Fe}function or(e,r,t){return ge(e,!1)}function ir(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function G(e,r,t){if(e==null)return"";if(typeof e=="function")return ge(e,ir(e));if(typeof e=="string")return U(e);switch(e){case C:return U("Suspense");case E:return U("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case m:return or(e.render);case w:return G(e.type,r,t);case j:{var a=e,l=a._payload,f=a._init;try{return G(f(l),r,t)}catch{}}}return""}var H=Object.prototype.hasOwnProperty,ye={},Re=D.ReactDebugCurrentFrame;function J(e){if(e){var r=e._owner,t=G(e.type,e._source,r?r.type:null);Re.setExtraStackFrame(t)}else Re.setExtraStackFrame(null)}function sr(e,r,t,a,l){{var f=Function.call.bind(H);for(var i in e)if(f(e,i)){var o=void 0;try{if(typeof e[i]!="function"){var y=Error((a||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw y.name="Invariant Violation",y}o=e[i](r,i,a,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(h){o=h}o&&!(o instanceof Error)&&(J(l),g("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",a||"React class",t,i,typeof o),J(null)),o instanceof Error&&!(o.message in ye)&&(ye[o.message]=!0,J(l),g("Failed %s type: %s",t,o.message),J(null))}}}var lr=Array.isArray;function Z(e){return lr(e)}function ur(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function cr(e){try{return Ee(e),!1}catch{return!0}}function Ee(e){return""+e}function Pe(e){if(cr(e))return g("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",ur(e)),Ee(e)}var M=D.ReactCurrentOwner,fr={key:!0,ref:!0,__self:!0,__source:!0},Te,we,Q;Q={};function dr(e){if(H.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function pr(e){if(H.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function vr(e,r){if(typeof e.ref=="string"&&M.current&&r&&M.current.stateNode!==r){var t=O(M.current.type);Q[t]||(g('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',O(M.current.type),e.ref),Q[t]=!0)}}function mr(e,r){{var t=function(){Te||(Te=!0,g("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function hr(e,r){{var t=function(){we||(we=!0,g("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var br=function(e,r,t,a,l,f,i){var o={$$typeof:c,type:e,key:r,ref:t,props:i,_owner:f};return o._store={},Object.defineProperty(o._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(o,"_self",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.defineProperty(o,"_source",{configurable:!1,enumerable:!1,writable:!1,value:l}),Object.freeze&&(Object.freeze(o.props),Object.freeze(o)),o};function _r(e,r,t,a,l){{var f,i={},o=null,y=null;t!==void 0&&(Pe(t),o=""+t),pr(r)&&(Pe(r.key),o=""+r.key),dr(r)&&(y=r.ref,vr(r,l));for(f in r)H.call(r,f)&&!fr.hasOwnProperty(f)&&(i[f]=r[f]);if(e&&e.defaultProps){var h=e.defaultProps;for(f in h)i[f]===void 0&&(i[f]=h[f])}if(o||y){var b=typeof e=="function"?e.displayName||e.name||"Unknown":e;o&&mr(i,b),y&&hr(i,b)}return br(e,o,y,l,a,M.current,i)}}var ee=D.ReactCurrentOwner,xe=D.ReactDebugCurrentFrame;function A(e){if(e){var r=e._owner,t=G(e.type,e._source,r?r.type:null);xe.setExtraStackFrame(t)}else xe.setExtraStackFrame(null)}var re;re=!1;function te(e){return typeof e=="object"&&e!==null&&e.$$typeof===c}function Oe(){{if(ee.current){var e=O(ee.current.type);if(e)return`
|
|
22
|
+
|
|
23
|
+
Check the render method of \``+e+"`."}return""}}function kr(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),t=e.lineNumber;return`
|
|
24
|
+
|
|
25
|
+
Check your code at `+r+":"+t+"."}return""}}var Se={};function gr(e){{var r=Oe();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
|
|
26
|
+
|
|
27
|
+
Check the top-level render call using <`+t+">.")}return r}}function Ce(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=gr(r);if(Se[t])return;Se[t]=!0;var a="";e&&e._owner&&e._owner!==ee.current&&(a=" It was passed a child from "+O(e._owner.type)+"."),A(e),g('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,a),A(null)}}function je(e,r){{if(typeof e!="object")return;if(Z(e))for(var t=0;t<e.length;t++){var a=e[t];te(a)&&Ce(a,r)}else if(te(e))e._store&&(e._store.validated=!0);else if(e){var l=Je(e);if(typeof l=="function"&&l!==e.entries)for(var f=l.call(e),i;!(i=f.next()).done;)te(i.value)&&Ce(i.value,r)}}}function yr(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===m||r.$$typeof===w))t=r.propTypes;else return;if(t){var a=O(r);sr(t,e.props,"prop",a,e)}else if(r.PropTypes!==void 0&&!re){re=!0;var l=O(r);g("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",l||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&g("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Rr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var a=r[t];if(a!=="children"&&a!=="key"){A(e),g("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",a),A(null);break}}e.ref!==null&&(A(e),g("Invalid attribute `ref` supplied to `React.Fragment`."),A(null))}}function Ne(e,r,t,a,l,f){{var i=er(e);if(!i){var o="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(o+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var y=kr(l);y?o+=y:o+=Oe();var h;e===null?h="null":Z(e)?h="array":e!==void 0&&e.$$typeof===c?(h="<"+(O(e.type)||"Unknown")+" />",o=" Did you accidentally export a JSX literal instead of a component?"):h=typeof e,g("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",h,o)}var b=_r(e,r,t,l,f);if(b==null)return b;if(i){var P=r.children;if(P!==void 0)if(a)if(Z(P)){for(var I=0;I<P.length;I++)je(P[I],e);Object.freeze&&Object.freeze(P)}else g("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else je(P,e)}return e===u?Rr(b):yr(b),b}}function Er(e,r,t){return Ne(e,r,t,!0)}function Pr(e,r,t){return Ne(e,r,t,!1)}var Tr=Pr,wr=Er;$.Fragment=u,$.jsx=Tr,$.jsxs=wr}()),$}(function(n){process.env.NODE_ENV==="production"?n.exports=Ae():n.exports=Ie()})(De);const oe=W.Fragment,s=W.jsx,T=W.jsxs,F=({className:n,name:c,viewBox:p="0 0 32 32",...u})=>{const v=[n,"balle"].filter(Boolean).join(" ");return s("svg",{...u,className:v,viewBox:p,children:s("use",{href:`#${c}`})})},We=({children:n,className:c,iconName:p="user",size:u="medium",skin:v="primary",type:d="button",variant:k="label-only",...R})=>{const m=[c,"pkt-btn",u&&`pkt-btn--${u}`,v&&`pkt-btn--${v}`,k&&`pkt-btn--${k}`].filter(Boolean).join(" ");return T("button",{...R,className:m,type:d,children:[s(F,{className:"pkt-btn__icon",name:p}),s("span",{className:"pkt-btn__text",children:n})]})},Ye=({children:n,className:c,logoLink:p="https://www.oslo.kommune.no/",isLoggedIn:u=!1,representing:v="",canChangeRepresentation:d=!1,showLogInButton:k=!0,onLogIn:R,onLogOut:m,onChangeRepresentation:C,...E})=>{const w=[c,"pkt-header"].filter(Boolean).join(" ");return T("header",{id:"pkt-header",className:w,"aria-label":"Topp",children:[s("div",{className:"pkt-header__logo",children:s("a",{"aria-label":"Tilbake til forside",className:"pkt-header__logo-link",href:p,children:s(F,{name:"oslologo",className:"pkt-header__logo-svg",viewBox:"0 0 60 31","aria-hidden":"true"})})}),T("div",{className:"pkt-header__actions",children:[u&&d&&T("button",{className:"pkt-btn pkt-btn--secondary pkt-btn--icon-right","aria-label":`Bytt bruker fra ${v}`,onClick:C,children:[s(F,{name:"user",className:"pkt-btn__icon pkt-show-tablet-up"}),s("span",{className:"pkt-header__action-change pkt-hide pkt-show-tablet-up ml-size-15",children:"Endre"}),s("span",{className:"pkt-btn__text pkt-hide-tablet-up",children:"Endre"}),s("span",{className:"pkt-btn__text--representing pkt-hide pkt-show-tablet-up",children:v})]}),u&&!d&&T("div",{className:"pkt-header__action",children:[s("span",{className:"pkt-header__action-text",children:s("span",{className:"pkt-btn__text pkt-header__action-textrow text-row-inline truncate-text",children:v})}),s("span",{className:"pkt-header__action-icon pkt-show-phablet-up",children:s(F,{name:"user"})})]}),k&&u&&T("button",{className:"pkt-btn pkt-btn--flat pkt-btn--icon-right","aria-label":"Logg ut",onClick:m,children:[s(F,{className:"pkt-btn__icon pkt-show-tablet-up",name:"exit"}),s("span",{className:"pkt-btn__text",children:"Logg ut"})]}),k&&!u&&T("button",{className:"pkt-btn pkt-btn--flat pkt-btn--icon-right","aria-label":"Logg inn",onClick:R,children:[s(F,{className:"pkt-btn__icon",name:"user"}),s("span",{className:"pkt-btn__text",children:"Logg inn"})]})]})]})},ie=x.forwardRef(({label:n,id:c,children:p,...u},v)=>T("div",{className:"pkt-form-group",children:[s("label",{htmlFor:c,className:"pkt-form-label",children:n}),s("input",{className:"pkt-form-input",id:c,...u,ref:v}),p]}));ie.displayName="PktInput";const se=x.forwardRef(({id:n,label:c,...p},u)=>T("div",{className:"pkt-form-group",children:[s("label",{htmlFor:n,className:"pkt-form-label",children:c}),s("textarea",{className:"pkt-form-textarea",id:n,ref:u,...p})]}));se.displayName="PktTextarea";const le=x.forwardRef(({id:n,name:c,label:p,value:u,...v},d)=>T("div",{className:"pkt-form-group",children:[s("input",{type:"radio",className:"pkt-form-check-input",id:n,name:c,value:u,ref:d,...v}),s("label",{className:"pkt-form-label",htmlFor:n,children:p})]}));le.displayName="PktRadio";const $e=({label:n,children:c})=>T(oe,{children:[s("p",{children:n}),s("div",{className:"pkt-form-group",children:c})]});var z={},Le={get exports(){return z},set exports(n){z=n}};/*!
|
|
28
|
+
Copyright (c) 2018 Jed Watson.
|
|
29
|
+
Licensed under the MIT License (MIT), see
|
|
30
|
+
http://jedwatson.github.io/classnames
|
|
31
|
+
*/(function(n){(function(){var c={}.hasOwnProperty;function p(){for(var u=[],v=0;v<arguments.length;v++){var d=arguments[v];if(d){var k=typeof d;if(k==="string"||k==="number")u.push(d);else if(Array.isArray(d)){if(d.length){var R=p.apply(null,d);R&&u.push(R)}}else if(k==="object"){if(d.toString!==Object.prototype.toString&&!d.toString.toString().includes("[native code]")){u.push(d.toString());continue}for(var m in d)c.call(d,m)&&d[m]&&u.push(m)}}}return u.join(" ")}n.exports?(p.default=p,n.exports=p):window.classNames=p})()})(Le);const Me=z,Ve=({isResponsive:n,children:c})=>n?s("div",{className:"pkt-table-container",children:c}):s(oe,{children:c}),Ue=({isResponsive:n,modifiers:{info:c=!1,success:p=!1,strong:u=!1,shadow:v=!1}={},children:d})=>s(Ve,{isResponsive:n,children:s("table",{className:Me("pkt-table",{"pkt-table--info":c,"pkt-table--success":p,"pkt-table--strong":u,"pkt-table--shadow":v}),children:d})}),Be=({children:n})=>s("td",{className:"pkt-table__th",children:n}),Ge=({children:n})=>s("th",{className:"pkt-table__th",children:n});_.PktButton=We,_.PktHeader=Ye,_.PktInput=ie,_.PktRadio=le,_.PktRadioGroup=$e,_.PktTable=Ue,_.PktTableData=Be,_.PktTableHeader=Ge,_.PktTextarea=se,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface RadioProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
value: string;
|
|
6
|
+
label?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const PktRadio: React.ForwardRefExoticComponent<RadioProps & React.RefAttributes<HTMLInputElement>>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React, { ReactElement } from 'react';
|
|
2
|
+
import { PktRadio } from '../radio/Radio';
|
|
3
|
+
interface RadioGroupProps {
|
|
4
|
+
label?: string;
|
|
5
|
+
children: ReactElement<typeof PktRadio> | ReactElement<typeof PktRadio>[];
|
|
6
|
+
}
|
|
7
|
+
export declare const PktRadioGroup: ({ label, children }: RadioGroupProps) => React.ReactElement;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type ModifierName = 'info' | 'success' | 'strong' | 'shadow';
|
|
3
|
+
interface TableProps {
|
|
4
|
+
isResponsive?: boolean;
|
|
5
|
+
modifiers?: {
|
|
6
|
+
[key in ModifierName]?: boolean;
|
|
7
|
+
};
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
export declare const PktTable: ({ isResponsive, modifiers: { info, success, strong, shadow }, children, }: TableProps) => JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React, { TextareaHTMLAttributes } from 'react';
|
|
2
|
+
interface TextareaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const PktTextarea: React.ForwardRefExoticComponent<TextareaProps & React.RefAttributes<HTMLTextAreaElement>>;
|
|
7
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,45 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.2",
|
|
4
4
|
"description": "React komponentbibliotek til Punkt, et designsystem laget av Oslo Origo",
|
|
5
5
|
"homepage": "https://punkt.oslo.kommune.no",
|
|
6
6
|
"author": "Team Designsystem, Oslo Origo",
|
|
7
|
-
"main": "dist/
|
|
8
|
-
"module": "dist/
|
|
7
|
+
"main": "dist/punkt-react.umd.js",
|
|
8
|
+
"module": "dist/punkt-react.es.js",
|
|
9
9
|
"files": [
|
|
10
|
-
"dist"
|
|
10
|
+
"/dist",
|
|
11
|
+
"src/components/**/*",
|
|
12
|
+
"CHANGELOG.md",
|
|
13
|
+
"CONTRIBUTING.md"
|
|
11
14
|
],
|
|
15
|
+
"type": "module",
|
|
12
16
|
"types": "dist/index.d.ts",
|
|
13
|
-
"
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"import": "./dist/punkt-react.es.js",
|
|
20
|
+
"require": "./dist/punkt-react.umd.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
14
23
|
"scripts": {
|
|
15
|
-
"
|
|
16
|
-
"build": "
|
|
17
|
-
"
|
|
24
|
+
"dev": "vite",
|
|
25
|
+
"build": "tsc && vite build",
|
|
26
|
+
"build-app": "tsc && vite build --config vite.config-app.ts",
|
|
27
|
+
"lint": "eslint 'src/**/*.{js,jsx,ts,tsx}'",
|
|
28
|
+
"lint:fix": "eslint --fix 'src/**/*.{jsx,ts,tsx}'",
|
|
29
|
+
"format": "prettier --write src//**/*.{ts,tsx,css} --config ./.prettierrc",
|
|
30
|
+
"preview": "vite preview"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"react": "^18.2.0",
|
|
34
|
+
"react-dom": "^18.2.0"
|
|
18
35
|
},
|
|
19
36
|
"devDependencies": {
|
|
20
|
-
"@
|
|
21
|
-
"@
|
|
22
|
-
"@testing-library/react": "
|
|
23
|
-
"@types/jest": "^29.
|
|
24
|
-
"@types/
|
|
25
|
-
"@types/react
|
|
37
|
+
"@oslokommune/punkt-assets": "^0.22.2",
|
|
38
|
+
"@oslokommune/punkt-css": "^0.22.2",
|
|
39
|
+
"@testing-library/react": "^14.0.0",
|
|
40
|
+
"@types/jest": "^29.4.0",
|
|
41
|
+
"@types/node": "^18.14.1",
|
|
42
|
+
"@types/react": "^18.0.27",
|
|
43
|
+
"@types/react-dom": "^18.0.10",
|
|
44
|
+
"@vitejs/plugin-react": "^3.1.0",
|
|
26
45
|
"classnames": "^2.3.2",
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"react": "^
|
|
31
|
-
"react-dom": "^
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"rollup-plugin-postcss": "^4.0.2",
|
|
37
|
-
"tslib": "^2.4.1",
|
|
38
|
-
"typescript": "^4.9.4"
|
|
46
|
+
"eslint": "^8.34.0",
|
|
47
|
+
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
48
|
+
"prettier": "^2.8.4",
|
|
49
|
+
"react-hooks": "^1.0.1",
|
|
50
|
+
"react-router-dom": "^6.8.1",
|
|
51
|
+
"sass": "^1.58.3",
|
|
52
|
+
"typescript": "^4.9.3",
|
|
53
|
+
"vite": "^4.1.0",
|
|
54
|
+
"vite-plugin-dts": "^2.0.2"
|
|
39
55
|
},
|
|
40
56
|
"peerDependencies": {
|
|
41
|
-
"
|
|
42
|
-
"
|
|
57
|
+
"@oslokommune/punkt-assets": ">=0.22.0",
|
|
58
|
+
"@oslokommune/punkt-css": ">=0.22.0",
|
|
59
|
+
"react": ">=18.2.0",
|
|
60
|
+
"react-dom": ">=18.2.0"
|
|
43
61
|
},
|
|
44
62
|
"engines": {
|
|
45
63
|
"node": ">=16.15.0"
|
|
@@ -66,5 +84,5 @@
|
|
|
66
84
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
67
85
|
},
|
|
68
86
|
"license": "MIT",
|
|
69
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "7450d854b9de0aed9f41ce138fbf27db8f215a4a"
|
|
70
88
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { PktIcon } from '../icon/Icon'
|
|
3
|
+
|
|
4
|
+
export interface IPktButton extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
5
|
+
iconName?: string
|
|
6
|
+
mode?: 'light' | 'dark'
|
|
7
|
+
size?: 'small' | 'medium' | 'large'
|
|
8
|
+
skin?: 'primary' | 'secondary' | 'tertiary' | 'flat' | 'primary-confirm'
|
|
9
|
+
state?: 'normal' | 'focus' | 'hover' | 'active'
|
|
10
|
+
variant?: 'label-only' | 'icon-left' | 'icon-right' | 'icon-only'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const PktButton: React.FC<IPktButton> = ({
|
|
14
|
+
children,
|
|
15
|
+
className,
|
|
16
|
+
iconName = 'user',
|
|
17
|
+
size = 'medium',
|
|
18
|
+
skin = 'primary',
|
|
19
|
+
type = 'button',
|
|
20
|
+
variant = 'label-only',
|
|
21
|
+
...props
|
|
22
|
+
}) => {
|
|
23
|
+
const classes = [
|
|
24
|
+
className,
|
|
25
|
+
'pkt-btn',
|
|
26
|
+
size && `pkt-btn--${size}`,
|
|
27
|
+
skin && `pkt-btn--${skin}`,
|
|
28
|
+
variant && `pkt-btn--${variant}`,
|
|
29
|
+
]
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
.join(' ')
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<button {...props} className={classes} type={type}>
|
|
35
|
+
<PktIcon className="pkt-btn__icon" name={iconName}></PktIcon>
|
|
36
|
+
<span className="pkt-btn__text">{children}</span>
|
|
37
|
+
</button>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { PktIcon } from '../icon/Icon'
|
|
3
|
+
|
|
4
|
+
type HeaderProps = React.HTMLAttributes<HTMLDivElement> & {
|
|
5
|
+
logoLink?: string
|
|
6
|
+
isLoggedIn?: boolean
|
|
7
|
+
representing?: string
|
|
8
|
+
canChangeRepresentation?: boolean
|
|
9
|
+
showLogInButton?: boolean
|
|
10
|
+
onLogIn?: () => void
|
|
11
|
+
onLogOut?: () => void
|
|
12
|
+
onChangeRepresentation?: () => void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const PktHeader: React.FC<HeaderProps> = ({
|
|
16
|
+
children,
|
|
17
|
+
className,
|
|
18
|
+
logoLink = 'https://www.oslo.kommune.no/',
|
|
19
|
+
isLoggedIn = false,
|
|
20
|
+
representing = '',
|
|
21
|
+
canChangeRepresentation = false,
|
|
22
|
+
showLogInButton = true,
|
|
23
|
+
onLogIn,
|
|
24
|
+
onLogOut,
|
|
25
|
+
onChangeRepresentation,
|
|
26
|
+
...props
|
|
27
|
+
}) => {
|
|
28
|
+
const classNames = [className, 'pkt-header'].filter(Boolean).join(' ')
|
|
29
|
+
return (
|
|
30
|
+
<header id="pkt-header" className={classNames} aria-label="Topp">
|
|
31
|
+
<div className="pkt-header__logo">
|
|
32
|
+
<a aria-label="Tilbake til forside" className="pkt-header__logo-link" href={logoLink}>
|
|
33
|
+
<PktIcon name="oslologo" className="pkt-header__logo-svg" viewBox="0 0 60 31" aria-hidden="true" />
|
|
34
|
+
</a>
|
|
35
|
+
</div>
|
|
36
|
+
<div className="pkt-header__actions">
|
|
37
|
+
{isLoggedIn && canChangeRepresentation && (
|
|
38
|
+
<button
|
|
39
|
+
className="pkt-btn pkt-btn--secondary pkt-btn--icon-right"
|
|
40
|
+
aria-label={`Bytt bruker fra ${representing}`}
|
|
41
|
+
onClick={onChangeRepresentation}
|
|
42
|
+
>
|
|
43
|
+
<PktIcon name="user" className="pkt-btn__icon pkt-show-tablet-up" />
|
|
44
|
+
|
|
45
|
+
<span className="pkt-header__action-change pkt-hide pkt-show-tablet-up ml-size-15">Endre</span>
|
|
46
|
+
|
|
47
|
+
<span className="pkt-btn__text pkt-hide-tablet-up">Endre</span>
|
|
48
|
+
<span className="pkt-btn__text--representing pkt-hide pkt-show-tablet-up">{representing}</span>
|
|
49
|
+
</button>
|
|
50
|
+
)}
|
|
51
|
+
|
|
52
|
+
{isLoggedIn && !canChangeRepresentation && (
|
|
53
|
+
<div className="pkt-header__action">
|
|
54
|
+
<span className="pkt-header__action-text">
|
|
55
|
+
<span className="pkt-btn__text pkt-header__action-textrow text-row-inline truncate-text">
|
|
56
|
+
{representing}
|
|
57
|
+
</span>
|
|
58
|
+
</span>
|
|
59
|
+
<span className="pkt-header__action-icon pkt-show-phablet-up">
|
|
60
|
+
<PktIcon name="user" />
|
|
61
|
+
</span>
|
|
62
|
+
</div>
|
|
63
|
+
)}
|
|
64
|
+
|
|
65
|
+
{showLogInButton && isLoggedIn && (
|
|
66
|
+
<button className="pkt-btn pkt-btn--flat pkt-btn--icon-right" aria-label="Logg ut" onClick={onLogOut}>
|
|
67
|
+
<PktIcon className="pkt-btn__icon pkt-show-tablet-up" name="exit" />
|
|
68
|
+
<span className="pkt-btn__text">Logg ut</span>
|
|
69
|
+
</button>
|
|
70
|
+
)}
|
|
71
|
+
|
|
72
|
+
{showLogInButton && !isLoggedIn && (
|
|
73
|
+
<button className="pkt-btn pkt-btn--flat pkt-btn--icon-right" aria-label="Logg inn" onClick={onLogIn}>
|
|
74
|
+
<PktIcon className="pkt-btn__icon" name="user" />
|
|
75
|
+
<span className="pkt-btn__text">Logg inn</span>
|
|
76
|
+
</button>
|
|
77
|
+
)}
|
|
78
|
+
</div>
|
|
79
|
+
</header>
|
|
80
|
+
)
|
|
81
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
interface IPktIcon extends React.SVGProps<SVGSVGElement> {
|
|
4
|
+
name: string
|
|
5
|
+
viewBox?: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const PktIcon: React.FC<IPktIcon> = ({
|
|
9
|
+
className,
|
|
10
|
+
name,
|
|
11
|
+
viewBox = '0 0 32 32',
|
|
12
|
+
...props
|
|
13
|
+
}) => {
|
|
14
|
+
const classes = [className, 'balle'].filter(Boolean).join(' ')
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<svg {...props} className={classes} viewBox={viewBox}>
|
|
18
|
+
<use href={`#${name}`} />
|
|
19
|
+
</svg>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { PktButton } from './button/Button'
|
|
2
|
+
export { PktHeader } from './header/Header'
|
|
3
|
+
export { PktInput } from './input/Input'
|
|
4
|
+
export { PktTextarea } from './textarea/Textarea'
|
|
5
|
+
export { PktRadio } from './radio/Radio'
|
|
6
|
+
export { PktRadioGroup } from './radioGroup/RadioGroup'
|
|
7
|
+
export { PktTable } from './table/Table'
|
|
8
|
+
export { PktTableData } from './table/TableData'
|
|
9
|
+
export { PktTableHeader } from './table/TableHeader'
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React, { ForwardedRef } from 'react'
|
|
2
|
+
|
|
3
|
+
interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
4
|
+
/** The input's label */
|
|
5
|
+
label?: string
|
|
6
|
+
/** The input's id */
|
|
7
|
+
id: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Input component
|
|
12
|
+
* @param {string} label - Label for the input
|
|
13
|
+
* @param {string} id - Id for the input
|
|
14
|
+
* @param {string} validationMessage - Validation message for the input
|
|
15
|
+
* @param {React.InputHTMLAttributes<HTMLInputElement>} props - Other props to pass to the input
|
|
16
|
+
* @returns {React.ReactElement} - React element
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* <Input label="First name" id="firstName" validationMessage="First name is required" />
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export const PktInput = React.forwardRef(
|
|
23
|
+
({ label, id, children, ...props }: InputProps, ref: ForwardedRef<HTMLInputElement>): React.ReactElement => {
|
|
24
|
+
return (
|
|
25
|
+
<div className="pkt-form-group">
|
|
26
|
+
<label htmlFor={id} className="pkt-form-label">
|
|
27
|
+
{label}
|
|
28
|
+
</label>
|
|
29
|
+
<input className="pkt-form-input" id={id} {...props} ref={ref} />
|
|
30
|
+
{children}
|
|
31
|
+
</div>
|
|
32
|
+
)
|
|
33
|
+
},
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
PktInput.displayName = 'PktInput'
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React, { ForwardedRef, forwardRef } from 'react'
|
|
2
|
+
|
|
3
|
+
interface RadioProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
4
|
+
id: string
|
|
5
|
+
name: string
|
|
6
|
+
value: string
|
|
7
|
+
label?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const PktRadio = forwardRef(
|
|
11
|
+
({ id, name, label, value, ...props }: RadioProps, ref: ForwardedRef<HTMLInputElement>): React.ReactElement => {
|
|
12
|
+
return (
|
|
13
|
+
<div className="pkt-form-group">
|
|
14
|
+
<input type="radio" className="pkt-form-check-input" id={id} name={name} value={value} ref={ref} {...props} />
|
|
15
|
+
<label className="pkt-form-label" htmlFor={id}>
|
|
16
|
+
{label}
|
|
17
|
+
</label>
|
|
18
|
+
</div>
|
|
19
|
+
)
|
|
20
|
+
},
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
PktRadio.displayName = 'PktRadio'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React, { ReactElement } from 'react'
|
|
2
|
+
import { PktRadio } from '../radio/Radio'
|
|
3
|
+
|
|
4
|
+
interface RadioGroupProps {
|
|
5
|
+
label?: string
|
|
6
|
+
children: ReactElement<typeof PktRadio> | ReactElement<typeof PktRadio>[]
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const PktRadioGroup = ({ label, children }: RadioGroupProps): React.ReactElement => {
|
|
10
|
+
return (
|
|
11
|
+
<>
|
|
12
|
+
<p>{label}</p>
|
|
13
|
+
<div className="pkt-form-group">{children}</div>
|
|
14
|
+
</>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { render } from '@testing-library/react'
|
|
3
|
+
|
|
4
|
+
import { PktTable } from './Table'
|
|
5
|
+
import { PktTableHeader } from './TableHeader'
|
|
6
|
+
|
|
7
|
+
describe('<Table />', () => {
|
|
8
|
+
it('renders correctly without modifiers', () => {
|
|
9
|
+
const { asFragment } = render(
|
|
10
|
+
<PktTable>
|
|
11
|
+
<thead>
|
|
12
|
+
<tr>
|
|
13
|
+
<PktTableHeader>Header 1</PktTableHeader>
|
|
14
|
+
<PktTableHeader>Header 2</PktTableHeader>
|
|
15
|
+
</tr>
|
|
16
|
+
</thead>
|
|
17
|
+
<tbody>
|
|
18
|
+
<tr>
|
|
19
|
+
<td>Table data</td>
|
|
20
|
+
<td>Table data</td>
|
|
21
|
+
</tr>
|
|
22
|
+
</tbody>
|
|
23
|
+
</PktTable>,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
expect(asFragment()).toMatchSnapshot()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('renders correctly with modifier values true', () => {
|
|
30
|
+
const { asFragment } = render(
|
|
31
|
+
<PktTable
|
|
32
|
+
modifiers={{
|
|
33
|
+
info: true,
|
|
34
|
+
success: true,
|
|
35
|
+
strong: true,
|
|
36
|
+
shadow: true,
|
|
37
|
+
}}
|
|
38
|
+
>
|
|
39
|
+
<thead>
|
|
40
|
+
<tr>
|
|
41
|
+
<PktTableHeader>Header 1</PktTableHeader>
|
|
42
|
+
<PktTableHeader>Header 2</PktTableHeader>
|
|
43
|
+
</tr>
|
|
44
|
+
</thead>
|
|
45
|
+
<tbody>
|
|
46
|
+
<tr>
|
|
47
|
+
<td>Table data</td>
|
|
48
|
+
<td>Table data</td>
|
|
49
|
+
</tr>
|
|
50
|
+
</tbody>
|
|
51
|
+
</PktTable>,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
expect(asFragment()).toMatchSnapshot()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('renders correctly with modifier values false', () => {
|
|
58
|
+
const { asFragment } = render(
|
|
59
|
+
<PktTable
|
|
60
|
+
modifiers={{
|
|
61
|
+
info: false,
|
|
62
|
+
success: false,
|
|
63
|
+
strong: false,
|
|
64
|
+
shadow: false,
|
|
65
|
+
}}
|
|
66
|
+
>
|
|
67
|
+
<thead>
|
|
68
|
+
<tr>
|
|
69
|
+
<PktTableHeader>Header 1</PktTableHeader>
|
|
70
|
+
<PktTableHeader>Header 2</PktTableHeader>
|
|
71
|
+
</tr>
|
|
72
|
+
</thead>
|
|
73
|
+
<tbody>
|
|
74
|
+
<tr>
|
|
75
|
+
<td>Table data</td>
|
|
76
|
+
<td>Table data</td>
|
|
77
|
+
</tr>
|
|
78
|
+
</tbody>
|
|
79
|
+
</PktTable>,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
expect(asFragment()).toMatchSnapshot()
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('renders with responsive container', () => {
|
|
86
|
+
const { asFragment } = render(
|
|
87
|
+
<PktTable isResponsive={true}>
|
|
88
|
+
<thead>
|
|
89
|
+
<tr>
|
|
90
|
+
<PktTableHeader>Header 1</PktTableHeader>
|
|
91
|
+
<PktTableHeader>Header 2</PktTableHeader>
|
|
92
|
+
</tr>
|
|
93
|
+
</thead>
|
|
94
|
+
<tbody>
|
|
95
|
+
<tr>
|
|
96
|
+
<td>Table data</td>
|
|
97
|
+
<td>Table data</td>
|
|
98
|
+
</tr>
|
|
99
|
+
</tbody>
|
|
100
|
+
</PktTable>,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
expect(asFragment()).toMatchSnapshot()
|
|
104
|
+
})
|
|
105
|
+
})
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import classNames from 'classnames'
|
|
3
|
+
|
|
4
|
+
export type ModifierName = 'info' | 'success' | 'strong' | 'shadow'
|
|
5
|
+
|
|
6
|
+
interface TableProps {
|
|
7
|
+
isResponsive?: boolean
|
|
8
|
+
modifiers?: { [key in ModifierName]?: boolean }
|
|
9
|
+
children: React.ReactNode
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const ResponsiveWrapper = ({ isResponsive, children }: TableProps) => {
|
|
13
|
+
return isResponsive ? <div className="pkt-table-container">{children}</div> : <>{children}</>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const PktTable = ({
|
|
17
|
+
isResponsive,
|
|
18
|
+
modifiers: { info = false, success = false, strong = false, shadow = false } = {},
|
|
19
|
+
children,
|
|
20
|
+
}: TableProps) => {
|
|
21
|
+
return (
|
|
22
|
+
<ResponsiveWrapper isResponsive={isResponsive}>
|
|
23
|
+
<table
|
|
24
|
+
className={classNames('pkt-table', {
|
|
25
|
+
'pkt-table--info': info,
|
|
26
|
+
'pkt-table--success': success,
|
|
27
|
+
'pkt-table--strong': strong,
|
|
28
|
+
'pkt-table--shadow': shadow,
|
|
29
|
+
})}
|
|
30
|
+
>
|
|
31
|
+
{children}
|
|
32
|
+
</table>
|
|
33
|
+
</ResponsiveWrapper>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React, { ForwardedRef, forwardRef, TextareaHTMLAttributes } from 'react'
|
|
2
|
+
|
|
3
|
+
interface TextareaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
|
|
4
|
+
id: string
|
|
5
|
+
label: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const PktTextarea = forwardRef(
|
|
9
|
+
({ id, label, ...props }: TextareaProps, ref: ForwardedRef<HTMLTextAreaElement>): React.ReactElement => {
|
|
10
|
+
return (
|
|
11
|
+
<div className="pkt-form-group">
|
|
12
|
+
<label htmlFor={id} className="pkt-form-label">
|
|
13
|
+
{label}
|
|
14
|
+
</label>
|
|
15
|
+
<textarea className="pkt-form-textarea" id={id} ref={ref} {...props}></textarea>
|
|
16
|
+
</div>
|
|
17
|
+
)
|
|
18
|
+
},
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
PktTextarea.displayName = 'PktTextarea'
|