@devtron-labs/devtron-fe-common-lib 0.0.7-beta-37 → 0.0.7-beta-39

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.
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import './radioGroup.scss';
3
+ interface RadioGroupInterface {
4
+ name: string;
5
+ onChange: any;
6
+ className?: string;
7
+ initialTab: string;
8
+ disabled: boolean;
9
+ showTippy?: boolean;
10
+ tippyContent?: any;
11
+ dataTestId?: string;
12
+ }
13
+ interface RadioGroupComposition {
14
+ Radio?: React.FC<any>;
15
+ }
16
+ declare const RadioGroup: React.FC<RadioGroupInterface> & RadioGroupComposition;
17
+ export default RadioGroup;
@@ -28,3 +28,4 @@ export { default as EmptyState } from './EmptyState/EmptyState';
28
28
  export { default as GenericEmptyState } from './EmptyState/GenericEmptyState';
29
29
  export { default as Toggle } from './Toggle/Toggle';
30
30
  export { default as ScanVulnerabilitiesTable } from './Security/ScanVulnerabilitiesTable';
31
+ export { default as StyledRadioGroup } from './RadioGroup/RadioGroup';
package/dist/index.js CHANGED
@@ -500,8 +500,8 @@ function styleInject(css, ref) {
500
500
  }
501
501
  }
502
502
 
503
- var css_248z$5 = ".empty-state {\n height: 100%;\n}\n.empty-state img {\n height: 40%;\n max-height: 200px;\n width: auto;\n max-width: 250px;\n}\n.empty-state svg {\n height: 40%;\n max-height: 200px;\n width: auto;\n}\n.empty-state h1,\n.empty-state h2,\n.empty-state h3,\n.empty-state h4,\n.empty-state h5,\n.empty-state h6 {\n color: var(--N900);\n}\n.empty-state .subtitle {\n font-size: 13px;\n width: 300px;\n font-weight: 400;\n text-align: center;\n line-height: 1.5;\n margin-bottom: 20px;\n}\n.empty-state .cta {\n height: 36px;\n}\n.empty-state p {\n width: 300px;\n text-align: center;\n font-size: 13px;\n color: var(--N700);\n}\n.empty-state strong {\n font-size: 16px;\n margin-bottom: 4px;\n color: var(--N900);\n font-weight: normal;\n}\n.empty-state .select-popup {\n height: min-content;\n max-height: 250px;\n overflow: auto;\n padding: 8px 0;\n}\n.empty-state .empty-state__loader {\n width: 34px;\n height: 34px;\n margin-bottom: 16px;\n}\n.empty-state .empty-state__loading-text {\n font-size: 12px;\n width: 200px;\n font-weight: normal;\n font-stretch: normal;\n font-style: normal;\n line-height: 1.5;\n letter-spacing: normal;\n text-align: center;\n color: var(--N900);\n}\n.empty-state .button__icon {\n width: 16px;\n height: 16px;\n margin-left: 8px;\n}";
504
- styleInject(css_248z$5);
503
+ var css_248z$6 = ".empty-state {\n height: 100%;\n}\n.empty-state img {\n height: 40%;\n max-height: 200px;\n width: auto;\n max-width: 250px;\n}\n.empty-state svg {\n height: 40%;\n max-height: 200px;\n width: auto;\n}\n.empty-state h1,\n.empty-state h2,\n.empty-state h3,\n.empty-state h4,\n.empty-state h5,\n.empty-state h6 {\n color: var(--N900);\n}\n.empty-state .subtitle {\n font-size: 13px;\n width: 300px;\n font-weight: 400;\n text-align: center;\n line-height: 1.5;\n margin-bottom: 20px;\n}\n.empty-state .cta {\n height: 36px;\n}\n.empty-state p {\n width: 300px;\n text-align: center;\n font-size: 13px;\n color: var(--N700);\n}\n.empty-state strong {\n font-size: 16px;\n margin-bottom: 4px;\n color: var(--N900);\n font-weight: normal;\n}\n.empty-state .select-popup {\n height: min-content;\n max-height: 250px;\n overflow: auto;\n padding: 8px 0;\n}\n.empty-state .empty-state__loader {\n width: 34px;\n height: 34px;\n margin-bottom: 16px;\n}\n.empty-state .empty-state__loading-text {\n font-size: 12px;\n width: 200px;\n font-weight: normal;\n font-stretch: normal;\n font-style: normal;\n line-height: 1.5;\n letter-spacing: normal;\n text-align: center;\n color: var(--N900);\n}\n.empty-state .button__icon {\n width: 16px;\n height: 16px;\n margin-left: 8px;\n}";
504
+ styleInject(css_248z$6);
505
505
 
506
506
  var _g$2;
507
507
  function _extends$a() { _extends$a = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$a.apply(this, arguments); }
@@ -4117,8 +4117,8 @@ var VisibleModal = /** @class */ (function (_super) {
4117
4117
  return VisibleModal;
4118
4118
  }(React.Component));
4119
4119
 
4120
- var css_248z$4 = ".drawer {\n position: absolute;\n overflow: hidden;\n}\n.drawer.left, .drawer.right {\n top: 0;\n bottom: 0;\n width: 0;\n transition: width 200ms;\n}\n.drawer.left.show, .drawer.right.show {\n min-width: var(--minWidth);\n width: var(--width);\n max-width: var(--maxWidth);\n}\n.drawer.top, .drawer.bottom {\n left: 0;\n right: 0;\n height: 0;\n transition: height 200ms;\n}\n.drawer.top.show, .drawer.bottom.show {\n height: var(--height);\n}\n.drawer.right {\n right: 0;\n}\n.drawer.left {\n left: 0;\n}\n.drawer.top {\n top: 0;\n}\n.drawer.bottom {\n bottom: 0;\n}";
4121
- styleInject(css_248z$4);
4120
+ var css_248z$5 = ".drawer {\n position: absolute;\n overflow: hidden;\n}\n.drawer.left, .drawer.right {\n top: 0;\n bottom: 0;\n width: 0;\n transition: width 200ms;\n}\n.drawer.left.show, .drawer.right.show {\n min-width: var(--minWidth);\n width: var(--width);\n max-width: var(--maxWidth);\n}\n.drawer.top, .drawer.bottom {\n left: 0;\n right: 0;\n height: 0;\n transition: height 200ms;\n}\n.drawer.top.show, .drawer.bottom.show {\n height: var(--height);\n}\n.drawer.right {\n right: 0;\n}\n.drawer.left {\n left: 0;\n}\n.drawer.top {\n top: 0;\n}\n.drawer.bottom {\n bottom: 0;\n}";
4121
+ styleInject(css_248z$5);
4122
4122
 
4123
4123
  var Drawer = function (_a) {
4124
4124
  var children = _a.children, position = _a.position, height = _a.height, width = _a.width, minWidth = _a.minWidth, maxWidth = _a.maxWidth, parentClassName = _a.parentClassName, onEscape = _a.onEscape;
@@ -4356,7 +4356,7 @@ var RadioGroupItem = /** @class */ (function (_super) {
4356
4356
  };
4357
4357
  return RadioGroupItem;
4358
4358
  }(React.Component));
4359
- var RadioGroup = /** @class */ (function (_super) {
4359
+ var RadioGroup$1 = /** @class */ (function (_super) {
4360
4360
  __extends(RadioGroup, _super);
4361
4361
  function RadioGroup() {
4362
4362
  return _super !== null && _super.apply(this, arguments) || this;
@@ -8500,8 +8500,8 @@ var index = /*#__PURE__*/forwardRef( /*#__PURE__*/TippyGenerator(tippy));
8500
8500
 
8501
8501
  var Tippy = index;
8502
8502
 
8503
- var css_248z$3 = ".tippy-box[data-animation=shift-toward-subtle][data-state=hidden]{opacity:0}.tippy-box[data-animation=shift-toward-subtle][data-state=hidden][data-placement^=top][data-state=hidden]{transform:translateY(-5px)}.tippy-box[data-animation=shift-toward-subtle][data-state=hidden][data-placement^=bottom][data-state=hidden]{transform:translateY(5px)}.tippy-box[data-animation=shift-toward-subtle][data-state=hidden][data-placement^=left][data-state=hidden]{transform:translateX(-5px)}.tippy-box[data-animation=shift-toward-subtle][data-state=hidden][data-placement^=right][data-state=hidden]{transform:translateX(5px)}";
8504
- styleInject(css_248z$3);
8503
+ var css_248z$4 = ".tippy-box[data-animation=shift-toward-subtle][data-state=hidden]{opacity:0}.tippy-box[data-animation=shift-toward-subtle][data-state=hidden][data-placement^=top][data-state=hidden]{transform:translateY(-5px)}.tippy-box[data-animation=shift-toward-subtle][data-state=hidden][data-placement^=bottom][data-state=hidden]{transform:translateY(5px)}.tippy-box[data-animation=shift-toward-subtle][data-state=hidden][data-placement^=left][data-state=hidden]{transform:translateX(-5px)}.tippy-box[data-animation=shift-toward-subtle][data-state=hidden][data-placement^=right][data-state=hidden]{transform:translateX(5px)}";
8504
+ styleInject(css_248z$4);
8505
8505
 
8506
8506
  // This component will handle some of the new tippy designs and interactions
8507
8507
  // So this can be updated to support further for new features or interactions
@@ -16442,8 +16442,8 @@ var CustomSelect = function (props) {
16442
16442
  return jsxRuntime.jsx(Select, __assign({}, props));
16443
16443
  };
16444
16444
 
16445
- var css_248z$2 = ".info-bar-container .info_text .success {\n background-color: var(--G100);\n}\n.info-bar-container .warn {\n background: var(--Y100);\n border: solid var(--Y200);\n}\n.info-bar-container .warn .warning-icon path:nth-child(2) {\n fill: var(--Y700);\n}\n.info-bar-container .info_bar {\n background-color: var(--B100);\n border: 1px solid var(--B200);\n}\n.info-bar-container .error_bar {\n background-color: var(--R100);\n border: 1px solid var(--R200);\n}\n.info-bar-container .question-bar {\n background-color: var(--V100);\n border: 1px solid var(--V200);\n}";
16446
- styleInject(css_248z$2);
16445
+ var css_248z$3 = ".info-bar-container .info_text .success {\n background-color: var(--G100);\n}\n.info-bar-container .warn {\n background: var(--Y100);\n border: solid var(--Y200);\n}\n.info-bar-container .warn .warning-icon path:nth-child(2) {\n fill: var(--Y700);\n}\n.info-bar-container .info_bar {\n background-color: var(--B100);\n border: 1px solid var(--B200);\n}\n.info-bar-container .error_bar {\n background-color: var(--R100);\n border: 1px solid var(--R200);\n}\n.info-bar-container .question-bar {\n background-color: var(--V100);\n border: 1px solid var(--V200);\n}";
16446
+ styleInject(css_248z$3);
16447
16447
 
16448
16448
  function InfoColourBar(_a) {
16449
16449
  var message = _a.message, classname = _a.classname, Icon = _a.Icon, iconClass = _a.iconClass, iconSize = _a.iconSize, renderActionButton = _a.renderActionButton, linkText = _a.linkText, redirectLink = _a.redirectLink, linkOnClick = _a.linkOnClick, linkClass = _a.linkClass, internalLink = _a.internalLink, styles = _a.styles;
@@ -16503,8 +16503,8 @@ var Checkbox = /** @class */ (function (_super) {
16503
16503
  return Checkbox;
16504
16504
  }(React.Component));
16505
16505
 
16506
- var css_248z$1 = ".toggle__switch {\n position: relative;\n display: inline-block;\n width: 100%;\n height: 100%;\n}\n.toggle__switch.disabled {\n cursor: not-allowed;\n}\n.toggle__switch.disabled .toggle__slider {\n cursor: not-allowed;\n}\n\n/* Hide default HTML checkbox */\n.toggle__switch input {\n opacity: 0;\n width: 0;\n height: 0;\n}\n\n/* The slider */\n.toggle__slider {\n position: absolute;\n cursor: pointer;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background-color: #ccc;\n transition: all 0.4s ease;\n}\n\n.toggle__slider:before {\n position: absolute;\n content: \"\";\n height: calc(100% - 8px);\n width: calc(50% - 4px);\n left: 4px;\n bottom: 4px;\n background-color: white;\n transition: all 0.4s ease;\n}\n\ninput:checked + .toggle__slider {\n background-color: var(--color);\n}\n\ninput:focus + .toggle__slider {\n box-shadow: 0 0 1px var(--color);\n}\n\ninput:checked + .toggle__slider:before {\n transform: translateX(100%);\n}\n\n/* Rounded sliders */\n.toggle__slider.round {\n border-radius: 34px;\n}\n\n.toggle__slider.round:before {\n border-radius: 50%;\n}";
16507
- styleInject(css_248z$1);
16506
+ var css_248z$2 = ".toggle__switch {\n position: relative;\n display: inline-block;\n width: 100%;\n height: 100%;\n}\n.toggle__switch.disabled {\n cursor: not-allowed;\n}\n.toggle__switch.disabled .toggle__slider {\n cursor: not-allowed;\n}\n\n/* Hide default HTML checkbox */\n.toggle__switch input {\n opacity: 0;\n width: 0;\n height: 0;\n}\n\n/* The slider */\n.toggle__slider {\n position: absolute;\n cursor: pointer;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background-color: #ccc;\n transition: all 0.4s ease;\n}\n\n.toggle__slider:before {\n position: absolute;\n content: \"\";\n height: calc(100% - 8px);\n width: calc(50% - 4px);\n left: 4px;\n bottom: 4px;\n background-color: white;\n transition: all 0.4s ease;\n}\n\ninput:checked + .toggle__slider {\n background-color: var(--color);\n}\n\ninput:focus + .toggle__slider {\n box-shadow: 0 0 1px var(--color);\n}\n\ninput:checked + .toggle__slider:before {\n transform: translateX(100%);\n}\n\n/* Rounded sliders */\n.toggle__slider.round {\n border-radius: 34px;\n}\n\n.toggle__slider.round:before {\n border-radius: 50%;\n}";
16507
+ styleInject(css_248z$2);
16508
16508
 
16509
16509
  var Toggle = function (_a) {
16510
16510
  var _b;
@@ -16528,8 +16528,8 @@ var Toggle = function (_a) {
16528
16528
  return (jsxRuntime.jsxs("label", __assign({}, props, { className: "".concat(rootClassName, " toggle__switch ").concat(disabled ? 'disabled' : ''), style: (_b = {}, _b['--color'] = color, _b) }, { children: [jsxRuntime.jsx("input", { type: "checkbox", checked: !!active, onChange: handleClick, className: "toggle__input" }), jsxRuntime.jsx("span", { className: "toggle__slider round", "data-testid": dataTestId })] })));
16529
16529
  };
16530
16530
 
16531
- var css_248z = ".modal-body--scan-details {\n position: fixed;\n top: 0;\n right: 0;\n background: var(--N000);\n width: 800px;\n}\n\n.security-tab__table {\n width: 100%;\n}\n\n.security-tab__table-header {\n border-bottom: solid 1px var(--N200);\n}\n\n.security-cell-header {\n font-size: 12px;\n font-weight: 600;\n line-height: 1.5;\n letter-spacing: normal;\n text-transform: uppercase;\n color: var(--N500);\n}\n\n.dc__security-tab__table-row {\n font-size: 13px;\n font-weight: normal;\n line-height: 1.54;\n letter-spacing: normal;\n color: var(--N900);\n box-shadow: inset 0 -1px 0 0 #f5f5f5;\n}\n\n.security-tab__cell-cve,\n.security-tab__cell-severity,\n.security-tab__cell-package,\n.security-tab__cell-current-ver,\n.security-tab__cell-fixed-ver,\n.security-tab__cell-policy {\n padding: 10px;\n}\n\n.security-tab__cell-cve {\n padding-left: 0px;\n text-align: left;\n width: 20%;\n}\n\n.security-tab__cell-policy {\n padding-right: 0px;\n}\n\n.security-tab__cell-policy--whitelist,\n.security-tab__cell-policy--whitelisted {\n color: var(--G500);\n text-transform: capitalize;\n}\n\n.security-tab__cell-policy--block {\n color: var(--R500);\n text-transform: capitalize;\n}\n\n.scanned-object__results {\n margin: 0 20px;\n}";
16532
- styleInject(css_248z);
16531
+ var css_248z$1 = ".modal-body--scan-details {\n position: fixed;\n top: 0;\n right: 0;\n background: var(--N000);\n width: 800px;\n}\n\n.security-tab__table {\n width: 100%;\n}\n\n.security-tab__table-header {\n border-bottom: solid 1px var(--N200);\n}\n\n.security-cell-header {\n font-size: 12px;\n font-weight: 600;\n line-height: 1.5;\n letter-spacing: normal;\n text-transform: uppercase;\n color: var(--N500);\n}\n\n.dc__security-tab__table-row {\n font-size: 13px;\n font-weight: normal;\n line-height: 1.54;\n letter-spacing: normal;\n color: var(--N900);\n box-shadow: inset 0 -1px 0 0 #f5f5f5;\n}\n\n.security-tab__cell-cve,\n.security-tab__cell-severity,\n.security-tab__cell-package,\n.security-tab__cell-current-ver,\n.security-tab__cell-fixed-ver,\n.security-tab__cell-policy {\n padding: 10px;\n}\n\n.security-tab__cell-cve {\n padding-left: 0px;\n text-align: left;\n width: 20%;\n}\n\n.security-tab__cell-policy {\n padding-right: 0px;\n}\n\n.security-tab__cell-policy--whitelist,\n.security-tab__cell-policy--whitelisted {\n color: var(--G500);\n text-transform: capitalize;\n}\n\n.security-tab__cell-policy--block {\n color: var(--R500);\n text-transform: capitalize;\n}\n\n.scanned-object__results {\n margin: 0 20px;\n}";
16532
+ styleInject(css_248z$1);
16533
16533
 
16534
16534
  function ScanVulnerabilitiesTable(_a) {
16535
16535
  var vulnerabilities = _a.vulnerabilities;
@@ -16544,6 +16544,40 @@ function ScanVulnerabilitiesTable(_a) {
16544
16544
  })] }) })));
16545
16545
  }
16546
16546
 
16547
+ var css_248z = ".radio-group {\n height: 30px;\n background: white;\n display: flex;\n justify-content: center;\n align-items: center;\n padding: 4px;\n border-radius: 4px;\n}\n.radio-group .label,\n.radio-group .radio,\n.radio-group .checkbox {\n margin: 0;\n}\n.radio-group .radio {\n height: 100%;\n width: auto;\n color: var(--N400);\n display: flex;\n align-items: center;\n}\n.radio-group .radio + .radio {\n margin-top: 0;\n}\n.radio-group input[type=checkbox] {\n display: contents;\n overflow: hidden;\n max-width: 0px;\n height: 0;\n opacity: 0;\n margin: unset;\n}\n.radio-group input + .radio__item-label {\n padding: 4px 6px;\n height: 100%;\n width: 100%;\n display: flex;\n align-items: center;\n transition: all 0.5s;\n cursor: pointer;\n}\n.radio-group input[type=checkbox]:checked + .radio__item-label {\n background: #2c3354;\n color: white;\n border-radius: 4px;\n}";
16548
+ styleInject(css_248z);
16549
+
16550
+ var RadioContext = React.createContext(null);
16551
+ function useRadioContext() {
16552
+ var context = React.useContext(RadioContext);
16553
+ if (!context) {
16554
+ throw new Error("Radio compound components cannot be rendered outside the Toggle component");
16555
+ }
16556
+ return context;
16557
+ }
16558
+ var RadioGroup = React.memo(function RadioGroup(_a) {
16559
+ var name = _a.name, onChange = _a.onChange, children = _a.children, _b = _a.className, className = _b === void 0 ? '' : _b, initialTab = _a.initialTab, _c = _a.disabled, disabled = _c === void 0 ? false : _c; _a.dataTestId;
16560
+ var _d = __read(React.useState(null), 2), selected = _d[0], select = _d[1];
16561
+ React.useEffect(function () {
16562
+ if (initialTab === selected)
16563
+ return;
16564
+ select(initialTab);
16565
+ }, [initialTab]);
16566
+ return (jsxRuntime.jsx(RadioContext.Provider, __assign({ value: { name: name, selected: selected, select: select, disabled: disabled, onChange: onChange } }, { children: jsxRuntime.jsx("div", __assign({ className: "".concat(className, " radio-group") }, { children: children })) })));
16567
+ });
16568
+ function Radio(_a) {
16569
+ var value = _a.value, children = _a.children, _b = _a.className, className = _b === void 0 ? '' : _b, _c = _a.showTippy, showTippy = _c === void 0 ? false : _c, _d = _a.tippyContent, tippyContent = _d === void 0 ? '' : _d, _e = _a.canSelect, canSelect = _e === void 0 ? true : _e, _f = _a.isDisabled, isDisabled = _f === void 0 ? false : _f, _g = _a.tippyClass, tippyClass = _g === void 0 ? '' : _g, dataTestId = _a.dataTestId;
16570
+ var _h = useRadioContext(), name = _h.name, selected = _h.selected, select = _h.select, disabled = _h.disabled, onChange = _h.onChange;
16571
+ return (jsxRuntime.jsx(ConditionalWrap, __assign({ condition: showTippy, wrap: function (children) { return (jsxRuntime.jsx(Tippy, __assign({ className: "default-tt w-250 ".concat(tippyClass), arrow: false, placement: "bottom", content: tippyContent }, { children: children }))); } }, { children: jsxRuntime.jsxs("label", __assign({ className: "".concat(className, " radio ").concat((isDisabled || disabled) ? 'disabled' : '') }, { children: [jsxRuntime.jsx("input", { type: "checkbox", value: value, name: name, checked: value === selected, onChange: function (e) {
16572
+ e.persist();
16573
+ if (canSelect) {
16574
+ select(e.target.value);
16575
+ }
16576
+ onChange(e);
16577
+ }, disabled: isDisabled || disabled }), jsxRuntime.jsx("span", __assign({ className: "radio__item-label", "data-testid": dataTestId }, { children: children }))] })) })));
16578
+ }
16579
+ RadioGroup.Radio = Radio;
16580
+
16547
16581
  exports.BreadCrumb = BreadCrumb;
16548
16582
  exports.BreadcrumbStore = Store;
16549
16583
  exports.CDModalTab = CDModalTab;
@@ -16579,7 +16613,7 @@ exports.PopupMenu = PopupMenu;
16579
16613
  exports.Progressing = Progressing;
16580
16614
  exports.PropagateTagInfo = PropagateTagInfo;
16581
16615
  exports.ROUTES = ROUTES;
16582
- exports.RadioGroup = RadioGroup;
16616
+ exports.RadioGroup = RadioGroup$1;
16583
16617
  exports.RadioGroupItem = RadioGroupItem;
16584
16618
  exports.Reload = Reload;
16585
16619
  exports.RequestTimeout = RequestTimeout;
@@ -16588,6 +16622,7 @@ exports.ScanVulnerabilitiesTable = ScanVulnerabilitiesTable;
16588
16622
  exports.ServerError = ServerError;
16589
16623
  exports.ServerErrors = ServerErrors;
16590
16624
  exports.SingleSelectOption = SingleSelectOption;
16625
+ exports.StyledRadioGroup = RadioGroup;
16591
16626
  exports.TOAST_ACCESS_DENIED = TOAST_ACCESS_DENIED;
16592
16627
  exports.TOKEN_COOKIE_NAME = TOKEN_COOKIE_NAME;
16593
16628
  exports.TagDetails = TagDetails;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtron-labs/devtron-fe-common-lib",
3
- "version": "0.0.7-beta-37",
3
+ "version": "0.0.7-beta-39",
4
4
  "description": "Supporting common component library",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -0,0 +1,88 @@
1
+ import Tippy from '@tippyjs/react'
2
+ import React, { useState, useEffect } from 'react'
3
+ import { ConditionalWrap } from '../Helper'
4
+ import './radioGroup.scss'
5
+
6
+ const RadioContext = React.createContext(null)
7
+
8
+ function useRadioContext() {
9
+ const context = React.useContext(RadioContext)
10
+ if (!context) {
11
+ throw new Error(`Radio compound components cannot be rendered outside the Toggle component`)
12
+ }
13
+ return context
14
+ }
15
+
16
+ interface RadioGroupInterface {
17
+ name: string
18
+ onChange: any
19
+ className?: string
20
+ initialTab: string
21
+ disabled: boolean
22
+ showTippy?: boolean
23
+ tippyContent?: any
24
+ dataTestId?: string
25
+ }
26
+
27
+ interface RadioGroupComposition {
28
+ Radio?: React.FC<any>
29
+ }
30
+
31
+ const RadioGroup: React.FC<RadioGroupInterface> & RadioGroupComposition = React.memo(function RadioGroup({
32
+ name,
33
+ onChange,
34
+ children,
35
+ className = '',
36
+ initialTab,
37
+ disabled = false,
38
+ dataTestId
39
+ }) {
40
+ const [selected, select] = useState(null)
41
+
42
+ useEffect(() => {
43
+ if (initialTab === selected) return
44
+ select(initialTab)
45
+ }, [initialTab])
46
+
47
+ return (
48
+ <RadioContext.Provider value={{ name, selected, select, disabled, onChange }}>
49
+ <div className={`${className} radio-group`}>{children}</div>
50
+ </RadioContext.Provider>
51
+ )
52
+ })
53
+
54
+ function Radio({ value, children, className = '', showTippy = false, tippyContent = '', canSelect = true, isDisabled = false, tippyClass = '', dataTestId }) {
55
+ const { name, selected, select, disabled, onChange } = useRadioContext()
56
+ return (
57
+ <ConditionalWrap
58
+ condition={showTippy}
59
+ wrap={(children) => (
60
+ <Tippy className={`default-tt w-250 ${tippyClass}`} arrow={false} placement="bottom" content={tippyContent}>
61
+ {children}
62
+ </Tippy>
63
+ )}
64
+ >
65
+ <label className={`${className} radio ${(isDisabled || disabled)? 'disabled': ''}`}>
66
+ <input
67
+ type="checkbox"
68
+ value={value}
69
+ name={name}
70
+
71
+ checked={value === selected}
72
+ onChange={(e) => {
73
+ e.persist()
74
+ if (canSelect) {
75
+ select(e.target.value)
76
+ }
77
+ onChange(e)
78
+ }}
79
+ disabled={isDisabled || disabled}
80
+ />
81
+ <span className="radio__item-label" data-testid={dataTestId}>{children}</span>
82
+ </label>
83
+ </ConditionalWrap>
84
+ )
85
+ }
86
+
87
+ RadioGroup.Radio = Radio
88
+ export default RadioGroup
@@ -0,0 +1,46 @@
1
+ .radio-group {
2
+ .label,
3
+ .radio,
4
+ .checkbox {
5
+ margin: 0;
6
+ }
7
+ height: 30px;
8
+ background: white;
9
+ display: flex;
10
+ justify-content: center;
11
+ align-items: center;
12
+ padding: 4px;
13
+ border-radius: 4px;
14
+ .radio {
15
+ height: 100%;
16
+ width: auto;
17
+ color: var(--N400);
18
+ display: flex;
19
+ align-items: center;
20
+ }
21
+ .radio+.radio {
22
+ margin-top: 0;
23
+ }
24
+ input[type=checkbox] {
25
+ display: contents;
26
+ overflow: hidden;
27
+ max-width: 0px;
28
+ height: 0;
29
+ opacity: 0;
30
+ margin: unset;
31
+ }
32
+ input+.radio__item-label {
33
+ padding: 4px 6px;
34
+ height: 100%;
35
+ width: 100%;
36
+ display: flex;
37
+ align-items: center;
38
+ transition: all 0.5s;
39
+ cursor: pointer;
40
+ }
41
+ input[type=checkbox]:checked+.radio__item-label {
42
+ background: #2c3354;
43
+ color: white;
44
+ border-radius: 4px;
45
+ }
46
+ }
@@ -26,5 +26,6 @@ export * from './Common.service'
26
26
  export * from './Checkbox'
27
27
  export { default as EmptyState } from './EmptyState/EmptyState'
28
28
  export { default as GenericEmptyState } from './EmptyState/GenericEmptyState'
29
- export { default as Toggle } from './Toggle/Toggle'
30
- export { default as ScanVulnerabilitiesTable } from './Security/ScanVulnerabilitiesTable'
29
+ export { default as Toggle } from './Toggle/Toggle'
30
+ export { default as ScanVulnerabilitiesTable } from './Security/ScanVulnerabilitiesTable'
31
+ export { default as StyledRadioGroup } from './RadioGroup/RadioGroup'