@dynamic-framework/ui-react 1.8.0 → 1.9.0

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/dist/index.js CHANGED
@@ -95,12 +95,7 @@ function DSummaryCard({ title, description, icon, iconSize, iconTheme, Summary,
95
95
  }
96
96
 
97
97
  function DAlert({ type = 'light', icon, iconFamilyClass, iconFamilyPrefix, showIcon = false, showClose, onClose, children, id, className, style, }) {
98
- const generateClasses = React.useMemo(() => ({
99
- alert: true,
100
- [`alert-${type}`]: true,
101
- 'fade show': !!showClose,
102
- className: !!className,
103
- }), [type, showClose, className]);
98
+ const generateClasses = React.useMemo(() => (Object.assign({ alert: true, [`alert-${type}`]: true, 'fade show': !!showClose }, className && { [className]: true })), [type, showClose, className]);
104
99
  const getIcon = React.useMemo(() => icon || ALERT_TYPE_ICON[type] || '', [icon, type]);
105
100
  const generateStyleVariables = React.useMemo(() => (Object.assign(Object.assign(Object.assign({}, style), { [`--${PREFIX_BS}alert-component-separator-opacity`]: '0.3' }), type === 'light' && {
106
101
  [`--${PREFIX_BS}alert-component-icon-color`]: `var(--${PREFIX_BS}secondary)`,
@@ -510,9 +505,9 @@ function useProvidedRefOrCreate(providedRef) {
510
505
  function DInput(_a, ref) {
511
506
  var { id, style, className, label = '', labelIcon, labelIconFamilyClass, labelIconFamilyPrefix, disabled = false, readOnly = false, loading = false, iconFamilyClass, iconFamilyPrefix, iconStart, iconStartFamilyClass, iconStartFamilyPrefix, iconEnd, iconEndFamilyClass, iconEndFamilyPrefix, hint, invalid = false, valid = false, inputStart, value, onChange, onIconStartClick, onIconEndClick } = _a, inputProps = tslib.__rest(_a, ["id", "style", "className", "label", "labelIcon", "labelIconFamilyClass", "labelIconFamilyPrefix", "disabled", "readOnly", "loading", "iconFamilyClass", "iconFamilyPrefix", "iconStart", "iconStartFamilyClass", "iconStartFamilyPrefix", "iconEnd", "iconEndFamilyClass", "iconEndFamilyPrefix", "hint", "invalid", "valid", "inputStart", "value", "onChange", "onIconStartClick", "onIconEndClick"]);
512
507
  const inputRef = useProvidedRefOrCreate(ref);
513
- const handleOnChange = React.useCallback(() => {
514
- onChange === null || onChange === void 0 ? void 0 : onChange(value);
515
- }, [onChange, value]);
508
+ const handleOnChange = React.useCallback((event) => {
509
+ onChange === null || onChange === void 0 ? void 0 : onChange(event.currentTarget.value);
510
+ }, [onChange]);
516
511
  const handleOnIconStartClick = React.useCallback(() => {
517
512
  onIconStartClick === null || onIconStartClick === void 0 ? void 0 : onIconStartClick(value);
518
513
  }, [onIconStartClick, value]);
@@ -613,37 +608,27 @@ const ForwardedDInputCounter = React.forwardRef(DInputCounter);
613
608
  ForwardedDInputCounter.displayName = 'DInputCounter';
614
609
  var DInputCounter$1 = ForwardedDInputCounter;
615
610
 
611
+ function formatValue(value, currencyOptions) {
612
+ if (value === undefined) {
613
+ return '';
614
+ }
615
+ return currency(value, Object.assign(Object.assign({}, currencyOptions), { symbol: '' })).format();
616
+ }
616
617
  function useInputCurrency(currencyOptions, value, onFocus, onChange, onBlur, ref) {
617
618
  const inputRef = useProvidedRefOrCreate(ref);
618
- const valueFormatted = React.useMemo(() => {
619
- if (value === undefined) {
620
- return '';
621
- }
622
- return currency(value, Object.assign(Object.assign({}, currencyOptions), { symbol: '' })).format();
623
- }, [currencyOptions, value]);
624
- const [innerValue, setInnerValue] = React.useState(valueFormatted);
625
619
  const [innerType, setInnerType] = React.useState('text');
620
+ const [innerNumber, setInnerNumber] = React.useState(value);
621
+ const [innerString, setInnerString] = React.useState(formatValue(value, currencyOptions));
626
622
  const handleOnFocus = React.useCallback((event) => {
627
623
  event.stopPropagation();
628
- if (inputRef.current) {
629
- if (event.currentTarget.value) {
630
- const currencyValue = currency(event.currentTarget.value, Object.assign(Object.assign({}, currencyOptions), { symbol: '' }));
631
- setInnerValue((currencyValue.intValue / 100).toString());
632
- }
633
- setInnerType('number');
634
- }
624
+ setInnerType('number');
635
625
  onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
636
- }, [currencyOptions, inputRef, onFocus]);
626
+ }, [onFocus]);
637
627
  const handleOnBlur = React.useCallback((event) => {
638
628
  event.stopPropagation();
639
- if (inputRef.current) {
640
- setInnerType('text');
641
- if (event.currentTarget.value) {
642
- setInnerValue(currency(event.currentTarget.value, Object.assign(Object.assign({}, currencyOptions), { symbol: '' })).format());
643
- }
644
- }
629
+ setInnerType('text');
645
630
  onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
646
- }, [currencyOptions, inputRef, onBlur]);
631
+ }, [onBlur]);
647
632
  const handleOnWheel = React.useCallback((event) => {
648
633
  var _a;
649
634
  event.stopPropagation();
@@ -657,12 +642,27 @@ function useInputCurrency(currencyOptions, value, onFocus, onChange, onBlur, ref
657
642
  color: `var(--${PREFIX_BS}m-input-currency-symbol-color)`,
658
643
  }), []);
659
644
  const handleOnChange = React.useCallback((newValue) => {
660
- setInnerValue(newValue);
661
- onChange === null || onChange === void 0 ? void 0 : onChange(newValue !== undefined ? Number(newValue) : undefined);
662
- }, [onChange]);
645
+ const newNumber = (newValue === undefined || newValue === '')
646
+ ? undefined
647
+ : Number(newValue);
648
+ setInnerNumber(newNumber);
649
+ setInnerString(formatValue(newNumber, currencyOptions));
650
+ }, [currencyOptions]);
663
651
  React.useEffect(() => {
664
- setInnerValue(valueFormatted);
665
- }, [valueFormatted]);
652
+ onChange === null || onChange === void 0 ? void 0 : onChange(innerNumber);
653
+ }, [onChange, innerNumber]);
654
+ React.useEffect(() => {
655
+ setInnerNumber(value);
656
+ }, [value]);
657
+ const innerValue = React.useMemo(() => {
658
+ if (value === undefined || value.toString() === '') {
659
+ return '';
660
+ }
661
+ const valueToUse = innerType === 'number'
662
+ ? innerNumber === null || innerNumber === void 0 ? void 0 : innerNumber.toString()
663
+ : innerString;
664
+ return valueToUse !== null && valueToUse !== void 0 ? valueToUse : '';
665
+ }, [value, innerType, innerNumber, innerString]);
666
666
  return {
667
667
  inputRef,
668
668
  innerValue,
@@ -958,7 +958,7 @@ function DPopover({ children, renderComponent, isOpen, setEventIsOpen, adjustCon
958
958
  setEventIsOpen(value);
959
959
  }
960
960
  }, [setEventIsOpen]);
961
- const { refs, floatingStyles, context } = react.useFloating({
961
+ const { refs, floatingStyles: floatingStylesBase, context, } = react.useFloating({
962
962
  open: innerIsOpen,
963
963
  onOpenChange,
964
964
  middleware: [
@@ -977,6 +977,9 @@ function DPopover({ children, renderComponent, isOpen, setEventIsOpen, adjustCon
977
977
  role,
978
978
  ]);
979
979
  const headingId = react.useId();
980
+ const floatingStyles = React.useMemo(() => (Object.assign(Object.assign({}, floatingStylesBase), adjustContentToRender && {
981
+ [`--${PREFIX_BS}popover-component-min-width`]: 'auto',
982
+ })), [floatingStylesBase, adjustContentToRender]);
980
983
  return (jsxRuntime.jsxs("div", { className: classNames('d-popover', className), style: style, children: [jsxRuntime.jsx("div", Object.assign({ ref: refs.setReference }, getReferenceProps(), { children: renderComponent(innerIsOpen) })), innerIsOpen && (jsxRuntime.jsx(react.FloatingFocusManager, { context: context, modal: false, children: jsxRuntime.jsx("div", Object.assign({ className: classNames('d-popover-content', {
981
984
  'w-100': adjustContentToRender,
982
985
  }), ref: refs.setFloating, style: floatingStyles, "aria-labelledby": headingId }, getFloatingProps(), { children: children })) }))] }));