@indico-data/design-system 1.0.53 → 1.0.55

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/lib/index.js CHANGED
@@ -1619,7 +1619,7 @@ function Icon(_a) {
1619
1619
  console.error(`${props.name} is not a valid icon name.`);
1620
1620
  return null;
1621
1621
  }
1622
- return (jsxRuntime$1.jsx("svg", Object.assign({}, iconComponentProps, ariaLabel, dimensions, { role: "img", className: props.className, "data-cy": props['data-cy'], "data-testid": props['data-testid'], fill: props.fill || 'currentColor', id: props.id, style: style, onClick: props.onClick })));
1622
+ return (jsxRuntime$1.jsx("svg", Object.assign({}, iconComponentProps, ariaLabel, dimensions, { ref: props.ref, role: "img", className: props.className, "data-cy": props['data-cy'], "data-testid": props['data-testid'], fill: props.fill || 'currentColor', id: props.id, style: style, onClick: props.onClick })));
1623
1623
  }
1624
1624
  function returnDimensions(sizeProp) {
1625
1625
  if (sizeProp.length > 1) {
@@ -23115,12 +23115,22 @@ const StyledNoInputDatePicker = styled__default.default.div `
23115
23115
 
23116
23116
  function CustomCaption(props) {
23117
23117
  const { goToMonth, nextMonth, previousMonth } = useNavigation();
23118
- return (jsxRuntime$1.jsxs("div", { className: "custom__caption", children: [jsxRuntime$1.jsx("button", { className: "custom__caption__action__button", disabled: !previousMonth, onClick: () => previousMonth && goToMonth(previousMonth), children: jsxRuntime$1.jsx(Icon, { size: [10], ariaLabel: "Previous Month", name: "chevron-left" }) }), jsxRuntime$1.jsx("h2", { className: "custom__caption__text", children: format(props.displayMonth, 'MMM yyyy') }), jsxRuntime$1.jsx("button", { className: "custom__caption__action__button", disabled: !nextMonth, onClick: () => nextMonth && goToMonth(nextMonth), children: jsxRuntime$1.jsx(Icon, { size: [10], ariaLabel: "Next Month", name: "chevron-right" }) })] }));
23118
+ return (jsxRuntime$1.jsxs("div", { className: "custom__caption", children: [jsxRuntime$1.jsx("button", { className: "custom__caption__action__button", disabled: !previousMonth, onClick: (event) => {
23119
+ event.preventDefault();
23120
+ if (previousMonth) {
23121
+ goToMonth(previousMonth);
23122
+ }
23123
+ }, children: jsxRuntime$1.jsx(Icon, { size: [10], ariaLabel: "Previous Month", name: "chevron-left" }) }), jsxRuntime$1.jsx("h2", { className: "custom__caption__text", children: format(props.displayMonth, 'MMM yyyy') }), jsxRuntime$1.jsx("button", { className: "custom__caption__action__button", disabled: !nextMonth, onClick: (event) => {
23124
+ event.preventDefault();
23125
+ if (nextMonth) {
23126
+ goToMonth(nextMonth);
23127
+ }
23128
+ }, children: jsxRuntime$1.jsx(Icon, { size: [10], ariaLabel: "Next Month", name: "chevron-right" }) })] }));
23119
23129
  }
23120
23130
  const NoInputDatePicker = (props) => {
23121
- const { ariaLabel, className, disabled, disableBeforeDate, disableAfterDate, id, label, onChange, selected, triggerIcon, triggerIconSize, isRangePicker, isOpen, } = props;
23131
+ const { ariaLabel, className, disabled, disableBeforeDate, disableAfterDate, id, label, onChange, selected, triggerIcon, triggerIconSize, isRangePicker, selectedRange, isOpen, clearOnClose, } = props;
23122
23132
  const [localSelected, setLocalSelected] = React$1.useState(selected || undefined);
23123
- const [range, setRange] = React$1.useState(undefined);
23133
+ const [localSelectedRange, setLocalSelectedRange] = React$1.useState(selectedRange || undefined);
23124
23134
  const [isPopperOpen, setIsPopperOpen] = React$1.useState(isOpen || false);
23125
23135
  const [popperElement, setPopperElement] = React$1.useState(null);
23126
23136
  const popperRef = React$1.useRef(null);
@@ -23136,17 +23146,34 @@ const NoInputDatePicker = (props) => {
23136
23146
  ],
23137
23147
  });
23138
23148
  const [isTrapActive, setIsTrapActive] = React$1.useState(false);
23149
+ const datePickerRef = React$1.useRef(null);
23150
+ // Addresses clickout side bug when implementing in an application
23139
23151
  React$1.useEffect(() => {
23152
+ const handleClickOutside = (event) => {
23153
+ // Close the date picker only when clicked outside
23154
+ if (datePickerRef.current &&
23155
+ event.target instanceof Node &&
23156
+ !datePickerRef.current.contains(event.target)) {
23157
+ closePopper();
23158
+ }
23159
+ };
23160
+ document.addEventListener('mousedown', handleClickOutside);
23161
+ return () => {
23162
+ document.removeEventListener('mousedown', handleClickOutside);
23163
+ };
23164
+ }, []);
23165
+ // Allow datepicker to load before setting active trap
23166
+ React$1.useLayoutEffect(() => {
23140
23167
  if (isOpen) {
23141
- // Delay the activation of the FocusTrap to allow the DayPicker to render
23142
- const timeoutId = setTimeout(() => setIsTrapActive(true), 0);
23143
- return () => clearTimeout(timeoutId);
23168
+ setIsTrapActive(true);
23144
23169
  }
23145
23170
  else {
23146
23171
  setIsTrapActive(false);
23147
23172
  }
23148
23173
  }, [isOpen]);
23149
23174
  const closePopper = () => {
23175
+ clearOnClose && setLocalSelected(undefined);
23176
+ clearOnClose && setLocalSelectedRange(undefined);
23150
23177
  setIsPopperOpen(false);
23151
23178
  };
23152
23179
  const handleDaySelect = (date) => {
@@ -23160,7 +23187,7 @@ const NoInputDatePicker = (props) => {
23160
23187
  }
23161
23188
  };
23162
23189
  const handleRangeSelect = (range) => {
23163
- setRange(range);
23190
+ setLocalSelectedRange(range);
23164
23191
  if ((range === null || range === void 0 ? void 0 : range.from) && (range === null || range === void 0 ? void 0 : range.to)) {
23165
23192
  onChange(range);
23166
23193
  closePopper();
@@ -23169,14 +23196,15 @@ const NoInputDatePicker = (props) => {
23169
23196
  onChange(range);
23170
23197
  }
23171
23198
  };
23172
- return (jsxRuntime$1.jsxs(StyledNoInputDatePicker, { className: className, "aria-label": ariaLabel || 'date select', "aria-describedby": `picker-label--${id}`, "data-cy": props['data-cy'], "data-testid": props['data-testid'], id: id, children: [label ? (jsxRuntime$1.jsx("div", { id: `picker-label--${id}`, className: "visually-hidden", children: label })) : null, jsxRuntime$1.jsx("div", { ref: popperRef, className: "no__input__date__picker-inputParent", children: jsxRuntime$1.jsx(Icon, { "aria-label": "Open date picker", name: triggerIcon, size: triggerIconSize, className: "date__picker__trigger", "data-testid": `datepicker-trigger-for-${id}`, onClick: () => setIsPopperOpen(!isPopperOpen) }) }), isPopperOpen && (jsxRuntime$1.jsx(FocusTrap$1, { active: isTrapActive, focusTrapOptions: {
23199
+ return (jsxRuntime$1.jsxs(StyledNoInputDatePicker, { className: className, "aria-label": ariaLabel || 'date select', "aria-describedby": `picker-label--${id}`, "data-cy": props['data-cy'], "data-testid": props['data-testid'], id: id, ref: datePickerRef, children: [label ? (jsxRuntime$1.jsx("div", { id: `picker-label--${id}`, className: "visually-hidden", children: label })) : null, jsxRuntime$1.jsx("div", { ref: popperRef, className: "no__input__date__picker-inputParent", children: jsxRuntime$1.jsx(Icon, { "aria-label": "Open date picker", name: triggerIcon, size: triggerIconSize, className: "date__picker__trigger", "data-testid": `datepicker-trigger-for-${id}`, onClick: () => setIsPopperOpen(!isPopperOpen) }) }), isPopperOpen && (jsxRuntime$1.jsx(FocusTrap$1, { active: isTrapActive, focusTrapOptions: {
23173
23200
  initialFocus: false,
23174
23201
  allowOutsideClick: true,
23175
23202
  clickOutsideDeactivates: true,
23176
23203
  onDeactivate: closePopper,
23204
+ fallbackFocus: popperRef.current || undefined,
23177
23205
  }, children: jsxRuntime$1.jsx("div", Object.assign({ tabIndex: -1, style: popper.styles.popper, className: "DayPickerInput-Overlay" }, popper.attributes.popper, { ref: setPopperElement, role: "dialog", "aria-label": "DayPicker calendar", "data-testid": "datepicker-dialog", children: isRangePicker ? (jsxRuntime$1.jsx(DayPicker, { components: {
23178
23206
  Caption: CustomCaption,
23179
- }, disabled: disabled, mode: 'range', defaultMonth: localSelected, selected: range, onSelect: handleRangeSelect, fromDate: disableBeforeDate, toDate: disableAfterDate, "data-testid": "range-datepicker" })) : (jsxRuntime$1.jsx(DayPicker, { components: {
23207
+ }, disabled: disabled, mode: 'range', defaultMonth: localSelected, selected: localSelectedRange, onSelect: handleRangeSelect, fromDate: disableBeforeDate, toDate: disableAfterDate, "data-testid": "range-datepicker" })) : (jsxRuntime$1.jsx(DayPicker, { components: {
23180
23208
  Caption: CustomCaption,
23181
23209
  }, disabled: disabled, mode: 'single', defaultMonth: localSelected, selected: localSelected, onSelect: handleDaySelect, fromDate: disableBeforeDate, toDate: disableAfterDate, "data-testid": "single-datepicker" })) })) }))] }));
23182
23210
  };
@@ -25787,6 +25815,96 @@ function TextTruncate({ string, maxChars, children }) {
25787
25815
  return string.length > maxChars ? (jsxRuntime$1.jsxs(StyledTextTruncate, { title: string, children: [`${string.substring(0, maxChars)}...`, children] })) : (jsxRuntime$1.jsxs(StyledTextTruncate, { children: [string, children] }));
25788
25816
  }
25789
25817
 
25818
+ const StyledToggle = styled__default.default.label `
25819
+ position: relative;
25820
+ display: inline-block;
25821
+ width: 28px;
25822
+ height: 18px;
25823
+ border: 2px solid ${allColors.defaultFontColor};
25824
+ border-radius: 34px;
25825
+ margin-bottom: 0;
25826
+ cursor: pointer;
25827
+
25828
+ & input {
25829
+ display: none;
25830
+ }
25831
+
25832
+ &.disabled {
25833
+ cursor: not-allowed;
25834
+ opacity: 0.5;
25835
+ }
25836
+
25837
+ .slider {
25838
+ position: absolute;
25839
+ top: 0;
25840
+ left: -1px;
25841
+ right: 0;
25842
+ bottom: 0;
25843
+ transition: 0.4s;
25844
+ border-radius: 34px;
25845
+ }
25846
+
25847
+ .slider:before {
25848
+ position: absolute;
25849
+ content: '';
25850
+ height: 17px;
25851
+ width: 17px;
25852
+ left: -1px;
25853
+ bottom: -1px;
25854
+ background-color: ${allColors.clay};
25855
+ transition: 0.4s;
25856
+ border: 2px solid ${allColors.defaultFontColor};
25857
+ border-radius: 50%;
25858
+ }
25859
+
25860
+ input:checked + .slider {
25861
+ background-color: ${allColors.defaultFontColor};
25862
+ width: 100%;
25863
+ }
25864
+
25865
+ input:checked + .slider:before {
25866
+ transform: translateX(12px);
25867
+ }
25868
+
25869
+ p {
25870
+ position: relative;
25871
+ left: 35px;
25872
+ bottom: 2px;
25873
+ }
25874
+
25875
+ .checked-icon,
25876
+ .not-checked-icon {
25877
+ position: absolute;
25878
+ pointer-events: none;
25879
+ top: 50%;
25880
+ transform: translateY(-50%);
25881
+ }
25882
+
25883
+ .checked-icon {
25884
+ fill: #fff;
25885
+ display: none;
25886
+ left: 3px;
25887
+ }
25888
+
25889
+ .not-checked-icon {
25890
+ right: 3px;
25891
+ }
25892
+
25893
+ input:checked ~ .not-checked-icon {
25894
+ display: none;
25895
+ }
25896
+ input:checked ~ .checked-icon {
25897
+ display: block;
25898
+ }
25899
+ `;
25900
+
25901
+ const Toggle = (props) => {
25902
+ const { disabled, onChange, value, className, id, checkedIconName, notCheckedIconName, iconSize, } = props;
25903
+ return (jsxRuntime$1.jsxs(StyledToggle, { className: classNames(className, {
25904
+ disabled,
25905
+ }), "data-cy": props['data-cy'], id: id, children: [jsxRuntime$1.jsx("input", { "aria-label": props['aria-label'], type: "checkbox", disabled: disabled, checked: value, onChange: onChange }), jsxRuntime$1.jsx("span", { className: "slider round" }), checkedIconName && (jsxRuntime$1.jsx(Icon, { name: checkedIconName, size: [iconSize || 5], className: "checked-icon" })), notCheckedIconName && (jsxRuntime$1.jsx(Icon, { name: notCheckedIconName, size: [iconSize || 5], className: "not-checked-icon" }))] }));
25906
+ };
25907
+
25790
25908
  exports.ANIMATION = animation;
25791
25909
  exports.AbstractRadio = Radio$1;
25792
25910
  exports.AbstractRadioGroup = RadioGroup$1;
@@ -25835,6 +25953,7 @@ exports.StyledWizard = StyledWizard;
25835
25953
  exports.TYPOGRAPHY = typography;
25836
25954
  exports.TextInput = TextInput;
25837
25955
  exports.TextTruncate = TextTruncate;
25956
+ exports.Toggle = Toggle;
25838
25957
  exports.Wizard = Wizard;
25839
25958
  exports.WizardCard = WizardCard;
25840
25959
  exports.WizardSection = WizardSection;