@pushwoosh/dumb-components 1.0.31 → 1.0.32

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.
@@ -1,5 +1,6 @@
1
- import { autoPlacement, offset, useFloating } from '@floating-ui/react-dom';
2
- import React, { useEffect, useState } from 'react';
1
+ import { autoPlacement, size, offset, useFloating } from '@floating-ui/react-dom';
2
+ import React, { useState, useEffect } from 'react';
3
+ import { flushSync } from 'react-dom';
3
4
  import { Place } from './styles';
4
5
  import { DropdownContext } from '../../context';
5
6
  const defaultPlacements = ['top-start', 'top-end', 'bottom-start', 'bottom-end'];
@@ -9,14 +10,24 @@ export const DropdownMenu = ({
9
10
  isScrollable,
10
11
  menuZIndex,
11
12
  menuPlacement,
13
+ fullWidth,
12
14
  children
13
15
  }) => {
14
16
  const [isOpen, setIsOpen] = useState(false);
17
+ const [width, setWidth] = useState(null);
15
18
  const {
16
19
  refs,
17
20
  floatingStyles
18
21
  } = useFloating({
19
- middleware: [offset(4), autoPlacement({
22
+ middleware: [size({
23
+ apply({
24
+ rects
25
+ }) {
26
+ if (fullWidth) {
27
+ flushSync(() => setWidth(rects.reference.width));
28
+ }
29
+ }
30
+ }), offset(4), autoPlacement({
20
31
  allowedPlacements: menuPlacement ? [menuPlacement] : defaultPlacements
21
32
  })]
22
33
  });
@@ -44,6 +55,7 @@ export const DropdownMenu = ({
44
55
  ref: refs.setFloating,
45
56
  style: floatingStyles,
46
57
  "$color": color,
58
+ "$width": width,
47
59
  "$scrollable": isScrollable,
48
60
  "$zIndex": menuZIndex
49
61
  }, typeof children === 'function' ? children() : children));
@@ -12,6 +12,7 @@ export declare const Place: import("styled-components").StyledComponent<"div", a
12
12
  $gridAutoFlow: string;
13
13
  } & {
14
14
  $color?: string;
15
+ $width: number | null;
15
16
  $zIndex?: number;
16
17
  $scrollable?: boolean;
17
18
  }, "$gridAutoFlow">;
@@ -5,9 +5,11 @@ const scrollableCss = css(["max-height:248px;overflow-y:auto;"]);
5
5
  export const Place = styled(Vertical).withConfig({
6
6
  displayName: "Place",
7
7
  componentId: "sc-ij8wqc-0"
8
- })(["border:1px solid ", ";background:", ";min-width:140px;", " border-radius:", ";box-shadow:", ";z-index:", ";"], Color.FORM, ({
8
+ })(["border:1px solid ", ";background:", ";width:", ";min-width:140px;max-width:480px;", " border-radius:", ";box-shadow:", ";z-index:", ";"], Color.FORM, ({
9
9
  $color
10
10
  }) => $color || Color.FROZEN, ({
11
+ $width
12
+ }) => $width ? `${$width}px` : 'auto', ({
11
13
  $scrollable
12
14
  }) => $scrollable && scrollableCss, ShapeRadius.CONTROL, Shadow.REGULAR, ({
13
15
  $zIndex
@@ -2,15 +2,16 @@ import type { ReferenceType, Placement } from '@floating-ui/react-dom';
2
2
  import type { ReactNode } from 'react';
3
3
  import type { Color } from '@pushwoosh/kit-constants';
4
4
  export type HandlerProps = {
5
- onClick: () => void;
6
- ref: (el: ReferenceType | null) => void;
7
5
  isOpen: boolean;
6
+ ref: (el: ReferenceType | null) => void;
7
+ onClick: () => void;
8
8
  };
9
9
  export type DropdownMenuProps = {
10
- renderHandler: (args: HandlerProps) => ReactNode;
11
- children: (() => ReactNode) | ReactNode;
12
10
  color?: Color.CLEAR | Color.FROZEN;
13
11
  isScrollable?: boolean;
14
12
  menuZIndex?: number;
15
13
  menuPlacement?: Placement;
14
+ fullWidth?: boolean;
15
+ renderHandler: (args: HandlerProps) => ReactNode;
16
+ children: (() => ReactNode) | ReactNode;
16
17
  };
@@ -45,10 +45,10 @@ export function FieldBox(props) {
45
45
  "$alignItems": "center",
46
46
  "$gap": Spacing.S1
47
47
  }, actions)), children, description && !error && React.createElement(Text, {
48
- "$variant": "h5",
48
+ "$variant": "footnote",
49
49
  "$color": Color.LOCKED
50
50
  }, description), error && React.createElement(Text, {
51
- "$variant": "h5",
51
+ "$variant": "footnote",
52
52
  "$color": Color.DANGER
53
53
  }, error));
54
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/dumb-components",
3
- "version": "1.0.31",
3
+ "version": "1.0.32",
4
4
  "description": "React components to build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",