uikit-react-public 0.29.5 → 0.29.6

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,11 +1,24 @@
1
1
  import { css, cx } from '@emotion/css';
2
2
  import { useTheme } from '../../../theme';
3
+ import type { SelectDropdownWidth } from '../Select.types';
3
4
 
4
5
  const NAME = 'ucl-uikit-select__panel';
5
6
 
6
- type PanelProps = React.ComponentPropsWithoutRef<'div'>;
7
+ type PanelProps = React.ComponentPropsWithoutRef<'div'> & {
8
+ dropdownWidth?: SelectDropdownWidth;
9
+ referenceWidth?: number;
10
+ availableHeight?: number;
11
+ maxWidth?: number;
12
+ };
7
13
 
8
- const Panel = ({ className, ...props }: PanelProps) => {
14
+ const Panel = ({
15
+ className,
16
+ dropdownWidth = 'content',
17
+ referenceWidth,
18
+ availableHeight,
19
+ maxWidth,
20
+ ...props
21
+ }: PanelProps) => {
9
22
  const [theme] = useTheme();
10
23
 
11
24
  const handleClick = (event: React.MouseEvent) => {
@@ -13,15 +26,22 @@ const Panel = ({ className, ...props }: PanelProps) => {
13
26
  event.stopPropagation();
14
27
  };
15
28
 
29
+ const referenceWidthValue =
30
+ typeof referenceWidth === 'number' ? `${referenceWidth}px` : '100%';
31
+ const maxWidthValue =
32
+ typeof maxWidth === 'number'
33
+ ? `min(${maxWidth}px, calc(100vw - (${theme.margin.m32} * 2)))`
34
+ : `calc(100vw - (${theme.margin.m32} * 2))`;
35
+ const maxHeightValue =
36
+ typeof availableHeight === 'number'
37
+ ? `min(400px, ${availableHeight}px)`
38
+ : '400px';
39
+
16
40
  const baseStyle = css`
17
- position: absolute;
18
- top: 46px;
19
- left: -1px; // -1px to align with the border of the field
20
- z-index: 10; // Required: panel must be 'above' subsquent DOM elements
21
- min-width: 100%;
41
+ min-width: ${referenceWidthValue};
22
42
  width: fit-content;
23
- max-width: calc(100vw - 64px);
24
- max-height: 400px;
43
+ max-width: ${maxWidthValue};
44
+ max-height: ${maxHeightValue};
25
45
  overflow-y: auto;
26
46
  overflow-x: hidden;
27
47
  box-sizing: content-box;
@@ -30,7 +50,17 @@ const Panel = ({ className, ...props }: PanelProps) => {
30
50
  background-color: ${theme.colour.fill.inverse};
31
51
  `;
32
52
 
33
- const style = cx(NAME, baseStyle, className);
53
+ const matchSelectWidthStyle = css`
54
+ width: ${referenceWidthValue};
55
+ max-width: ${referenceWidthValue};
56
+ `;
57
+
58
+ const style = cx(
59
+ NAME,
60
+ baseStyle,
61
+ dropdownWidth === 'match-select' && matchSelectWidthStyle,
62
+ className
63
+ );
34
64
 
35
65
  return (
36
66
  <div
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "uikit-react-public",
3
3
  "private": false,
4
4
  "license": "UNLICENSED",
5
- "version": "0.29.5",
5
+ "version": "0.29.6",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",