UNPKG

react-radio-checkbox-z

Version:

React UI Check/Radio [RadioGroup, Checkbox(s)] (CUSTOMIZE ALL)

2 lines (1 loc) 14.4 kB
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react"),require("styled-components")):"function"==typeof define&&define.amd?define(["react","styled-components"],e):(n=n||self).RadioCheckBox=e(n.React,n.styled)}(this,(function(n,e){"use strict";var t="default"in n?n.default:n,r="default"in e?e.default:e;function o(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}function c(n,e,t){return n(t={path:e,exports:{},require:function(n,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&t.path)}},t.exports),t.exports}var i=c((function(n){function e(t){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?(n.exports=e=function(n){return typeof n},n.exports.default=n.exports,n.exports.__esModule=!0):(n.exports=e=function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},n.exports.default=n.exports,n.exports.__esModule=!0),e(t)}n.exports=e,n.exports.default=n.exports,n.exports.__esModule=!0})),u=o(i),l=c((function(n){n.exports=function(n,e){(null==e||e>n.length)&&(e=n.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=n[t];return r},n.exports.default=n.exports,n.exports.__esModule=!0}));o(l);var a=c((function(n){n.exports=function(n){if(Array.isArray(n))return l(n)},n.exports.default=n.exports,n.exports.__esModule=!0}));o(a);var s=c((function(n){n.exports=function(n){if("undefined"!=typeof Symbol&&null!=n[Symbol.iterator]||null!=n["@@iterator"])return Array.from(n)},n.exports.default=n.exports,n.exports.__esModule=!0}));o(s);var f=c((function(n){n.exports=function(n,e){if(n){if("string"==typeof n)return l(n,e);var t=Object.prototype.toString.call(n).slice(8,-1);return"Object"===t&&n.constructor&&(t=n.constructor.name),"Map"===t||"Set"===t?Array.from(n):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?l(n,e):void 0}},n.exports.default=n.exports,n.exports.__esModule=!0}));o(f);var d=c((function(n){n.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},n.exports.default=n.exports,n.exports.__esModule=!0}));o(d);var p=o(c((function(n){n.exports=function(n){return a(n)||s(n)||f(n)||d()},n.exports.default=n.exports,n.exports.__esModule=!0}))),x=c((function(n){n.exports=function(n){if(Array.isArray(n))return n},n.exports.default=n.exports,n.exports.__esModule=!0}));o(x);var h=c((function(n){n.exports=function(n,e){var t=null==n?null:"undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(null!=t){var r,o,c=[],i=!0,u=!1;try{for(t=t.call(n);!(i=(r=t.next()).done)&&(c.push(r.value),!e||c.length!==e);i=!0);}catch(n){u=!0,o=n}finally{try{i||null==t.return||t.return()}finally{if(u)throw o}}return c}},n.exports.default=n.exports,n.exports.__esModule=!0}));o(h);var m=c((function(n){n.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},n.exports.default=n.exports,n.exports.__esModule=!0}));o(m);var b=o(c((function(n){n.exports=function(n,e){return x(n)||h(n,e)||f(n,e)||m()},n.exports.default=n.exports,n.exports.__esModule=!0}))),v=o(c((function(n){n.exports=function(n,e){return e||(e=n.slice(0)),Object.freeze(Object.defineProperties(n,{raw:{value:Object.freeze(e)}}))},n.exports.default=n.exports,n.exports.__esModule=!0})));function k(){var n=v(["\n display: flex;\n flex-wrap: wrap;\n flex-direction: ",";\n\n box-sizing: initial;\n * {\n box-sizing: initial;\n &::before {\n box-sizing: initial;\n }\n }\n"]);return k=function(){return n},n}function y(){var n=v(["\n i.rc-option-tick {\n background-color: ",";\n }\n "]);return y=function(){return n},n}function g(){var n=v(["\n i.rc-option-tick {\n background-color: ",";\n }\n &:hover i.rc-option-tick {\n background-color: ",";\n }\n ","\n "]);return g=function(){return n},n}function C(){var n=v(["\n i.rc-option-tick {\n border-color: ",";\n }\n "]);return C=function(){return n},n}function S(){var n=v(["\n i.rc-option-tick {\n color: ",";\n span.rc-option-icon {\n background-color: ",";\n }\n }\n label.rc-option-label {\n color: ",";\n }\n "]);return S=function(){return n},n}function _(){var n=v(["\n i.rc-option-tick {\n color: ",";\n background-color: ",";\n border-color: ",";\n }\n label.rc-option-label {\n color: ",";\n }\n "]);return _=function(){return n},n}function A(){var n=v(["\n i.rc-option-tick {\n color: ",";\n border-color: ",";\n }\n label.rc-option-label {\n color: ",";\n }\n "]);return A=function(){return n},n}function w(){var n=v(["\n content: '✔'\n "]);return w=function(){return n},n}function M(){var n=v(["\n background: url(",") no-repeat center;\n "]);return M=function(){return n},n}function E(){var n=v(["\n span.rc-option-icon {\n ","\n &::before {\n ","\n }\n }\n "]);return E=function(){return n},n}function j(){var n=v(["\n content: '✘'\n "]);return j=function(){return n},n}function I(){var n=v(["\n background: url(",") no-repeat center;\n "]);return I=function(){return n},n}function z(){var n=v(["\n span.rc-option-icon {\n ","\n &::before {\n ","\n }\n }\n "]);return z=function(){return n},n}function N(){var n=v(["\n ","\n\n ","\n\n ","\n\n ","\n\n ","\n\n ","\n "]);return N=function(){return n},n}function O(){var n=v(["\n &:hover {\n label.rc-option-label {\n color: ",";\n }\n i.rc-option-tick {\n border-color: ",";\n }\n }\n "]);return O=function(){return n},n}function F(){var n=v(["\n cursor: default !important;\n pointer-events: none;\n i.rc-option-tick {\n opacity: 0.5 !important;\n }\n i.rc-option-input {\n cursor: default !important;\n }\n "]);return F=function(){return n},n}function R(){var n=v(["\n display: flex;\n min-height: ",";\n align-items: center;\n margin-right: 1.5rem;\n cursor: pointer;\n\n // disabled\n ","\n\n // when hasTheme\n ","\n\n ","\n\n ","\n"]);return R=function(){return n},n}function q(){var n=v(["\n display: flex;\n align-items: center;\n justify-content: center;\n width: 60%;\n height: 60%;\n border-radius: ",";\n transition: background-color 0.25s linear;\n -webkit-transition: background-color 0.25s linear;\n\n &::before {\n font-size: ",";\n }\n"]);return q=function(){return n},n}function B(){var n=v(["\n position: relative;\n display: ",";\n opacity: ",";\n justify-content: center;\n align-items: center;\n border: 0.2rem solid ",";\n border-radius: ",";\n width: ",";\n height: ",";\n margin-right: 0.5rem;\n font-style: normal;\n"]);return B=function(){return n},n}function T(){var n=v(["\n opacity: 0.65;\n cursor: default !important;\n "]);return T=function(){return n},n}function P(){var n=v(["\n cursor: pointer;\n margin-top: 1px;\n margin-bottom: 1px;\n\n ","\n"]);return P=function(){return n},n}function D(){var n=v(["\n position: absolute;\n cursor: pointer;\n width: 1% !important;\n height: 1% !important;\n opacity: 0;\n\n &:focus + i.rc-option-tick {\n box-shadow: 0 0 4px 2px ",";\n }\n "]);return D=function(){return n},n}function $(){var n=v(["\n display: flex;\n justify-content: center;\n align-items: center;\n padding: 0;\n margin: 0;\n margin-right: 0.5rem;\n\n ","\n"]);return $=function(){return n},n}var U=function(n){return n.unselectColor||"#cbd1d8"},G=function(n){var e=n.selectColor;return e||"#4169E1"},H=function(n){var e=n.hoverColor;return e||"#4169E1"},J=function(n){return n.tickColor||"#fff"},K={fill:"ldk-theme-fill",in:"ldk-theme-in",out:"ldk-theme-out",tick:"ldk-theme-tick-check",tickFill:"ldk-theme-tick-check-fill","tick-fill":"ldk-theme-tick-check-fill","tick-fill-in":"ldk-theme-tick-check-fill-in",x:"ldk-theme-x-check","x-fill":"ldk-theme-x-check-fill","x-fill-in":"ldk-theme-x-check-fill-in"},L=r.input($(),(function(n){return n.active&&e.css(D(),n.tabFocusColor||"#000000")})),Q=r.label(P(),(function(n){return n.disabled&&e.css(T())})),V=r.i(B(),(function(n){return n.active?"flex":"none"}),(function(n){return n.active?1:0}),(function(n){return U(n)}),(function(n){return n.isRadio?"100%":"10%"}),(function(n){return n.boxSize}),(function(n){return n.boxSize})),W=r.span(q(),(function(n){return n.isRadio?"100%":"10%"}),(function(n){return n.tickSize})),X=r.span(R(),(function(n){return n.height}),(function(n){return n.disabled&&e.css(F())}),(function(n){return n.active&&e.css(O(),H(n),H(n))}),(function(n){return n.checked&&e.css(N(),(t=n.theme,"".concat(t).includes("x-check")&&e.css(z(),n.checkedIcon&&e.css(I(),n.checkedIcon),!n.checkedIcon&&e.css(j()))),function(n){return"".concat(n).includes("tick-check")}(n.theme)&&e.css(E(),n.checkedIcon&&e.css(M(),n.checkedIcon),!n.checkedIcon&&e.css(w())),function(n){return["ldk-theme-x-check","ldk-theme-tick-check"].includes(n)}(n.theme)&&e.css(A(),n.tickColor||"#4169E1",G(n),G(n)),function(n){return-1!=="".concat(n).indexOf("fill")}(n.theme)&&e.css(_(),J(n),G(n),G(n),G(n)),function(n){return"".concat(n).includes("theme-in")||"".concat(n).includes("theme-out")}(n.theme)&&e.css(S(),J(n),G(n),G(n)),function(n){return"".concat(n).includes("theme-in")}(n.theme)&&e.css(C(),G(n)));var t}),(function(n){return t=n.theme,-1!=="".concat(t).indexOf("fill-in")&&e.css(g(),U(n),H(n),n.checked&&e.css(y(),G(n)));var t})),Y=r.div(k(),(function(n){return n.vertical?"column":"row"})),Z=function(e){var r=e.className,o=e.groupName,c=e.theme,i=e.disabled,l=e.height,a=e.boxSize,s=e.selectColor,f=e.unSelectColor,d=e.tickColor,x=e.hoverColor,h=e.tabFocusColor,m=e.checkedIcon,v=e.vertical,k=e.displayBox,y=e.value,g=e.options,C=e.checkBox,S=e.style,_=e.onChange,A=n.useState("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx-".concat(+new Date).replace(/[xy]/g,(function(n){var e=16*Math.random()|0;return("x"===n?e:3&e|8).toString(16)}))),w=b(A,2),M=w[0],E=(w[1],n.useState((function(){return en(y)?[]:nn(y,C)}))),j=b(E,2),I=j[0],z=j[1],N=n.useState(!1),O=b(N,2),F=O[0],R=O[1],q=n.useCallback((function(){return en(y)}),[y]),B=n.useCallback((function(){return o||"group-name-".concat(M)}),[o]),T=n.useCallback((function(){return K["".concat(c).trim()]}),[c]),P=n.useCallback((function(){return void 0!==T()}),[T]),D=n.useCallback((function(){return tn(a)}),[a]),$=n.useCallback((function(){return"".concat(Math.floor(.8*parseInt(a)),"px")}),[a]),U=n.useCallback((function(){return tn(l)}),[l]);return n.useEffect((function(){!q()&&z((function(){return nn(y,C)}))}),[]),n.useEffect((function(){F?R(!1):q()||0===y.length&&0===I.length||z((function(){return nn(y,C)}))}),[y]),t.createElement(Y,{className:"ldk-rc ldk-rc-radio-checkbox ".concat(r||"").trim(),style:S,vertical:v},g.map((function(n,e){var r,o,c=function(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],t=arguments.length>2?arguments[2]:void 0;if(en(n))return;if(rn(u(n)))return{label:"".concat(n),value:n,checked:e.includes(n),disabledAll:t};return n.checked=e.includes(n.value),n.disabledAll=t||n.disabled,n}(n,I,i);return c?t.createElement(X,{key:e,active:P(),disabled:c.disabledAll,className:(r=c,o=["rc-option-item",r.className||"",r.disabledAll?"rc-option-disabled":"rc-option-none",r.checked?"rc-option-checked":"rc-option-none"],Array.from(new Set(o)).filter((function(n){return n})).join(" ").trim()),checked:c.checked,height:U(),selectColor:s,checkedIcon:c.checkedIcon||m,unSelectColor:f,tickColor:d,hoverColor:x||s,theme:T(),onClick:function(n){return function(n,e){var t=e.currentTarget;if(!n.disabledAll){var r=t.closest("span.rc-option-item");if(r){var o=r.querySelector("input.rc-option-input");o&&o.focus()}var c=[n.value];C&&(c=t.checked?p(I).filter((function(e){return e!==n.value})):[].concat(p(I),[n.value])),z(c),R(!0),"function"==typeof _&&_(q()||Array.isArray(y)?c:n.value)}}(c,n)}},P()?t.createElement(t.Fragment,null,t.createElement(L,{id:"".concat(M,"-").concat(c.label),active:!0,type:C?"checkbox":"radio",name:B(),className:"rc-option-input",value:c.value,disabled:c.disabledAll,checked:c.checked,tabFocusColor:h,onChange:function(){}}),t.createElement(V,{active:!0,className:"rc-option-tick",unSelectColor:f,isRadio:!k,boxSize:D()},t.createElement(W,{className:"rc-option-icon",isRadio:!C,tickSize:$()}))):t.createElement(L,{id:"".concat(M,"-").concat(c.label),type:C?"checkbox":"radio",name:B(),className:"rc-option-input",value:c.value,disabled:c.disabledAll,checked:c.checked,onChange:function(){}}),c.jsx?c.jsx:t.createElement(Q,{className:"rc-option-label ".concat(c.labelClassName||"").trim(),disabled:c.disabledAll},c.label)):t.createElement(t.Fragment,null)})))};Z.defaultProps={className:void 0,groupName:void 0,theme:void 0,disabled:!1,height:24,boxSize:16,selectColor:void 0,unSelectColor:void 0,tickColor:void 0,hoverColor:void 0,tabFocusColor:void 0,checkedIcon:void 0,vertical:!1,displayBox:!1,value:null,options:[],checkBox:!1,style:{},onChange:void 0};var nn=function(n,e){return Array.isArray(n)?e?n:n.slice(0,1):[n]},en=function(n){return null==n},tn=function(n){return/^\d*$/.test(n)?"".concat(n,"px"):n},rn=function(n){return["string","number","boolean"].includes(n)};return Z}));