Skip to content

Commit 2090bf9

Browse files
committed
feat: add support for variable menu sizes
1 parent a788c7e commit 2090bf9

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

src/Shared/Components/SelectPicker/SelectPicker.component.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const SelectPicker = ({
2828
size = ComponentSizeType.medium,
2929
disabledTippyContent,
3030
showSelectedOptionsCount = false,
31+
menuSize,
3132
...props
3233
}: SelectPickerProps) => {
3334
const { inputId, required, isDisabled } = props
@@ -37,8 +38,9 @@ const SelectPicker = ({
3738
getCommonSelectStyle({
3839
error,
3940
size,
41+
menuSize,
4042
}),
41-
[error, size],
43+
[error, size, menuSize],
4244
)
4345

4446
const renderControl = useCallback(

src/Shared/Components/SelectPicker/type.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface SelectPickerProps
2828
| 'isDisabled'
2929
| 'isLoading'
3030
| 'required'
31+
| 'menuIsOpen'
3132
>,
3233
Required<Pick<SelectProps, 'classNamePrefix' | 'inputId' | 'name'>> {
3334
icon?: ReactElement
@@ -58,4 +59,12 @@ export interface SelectPickerProps
5859
* @default 'false'
5960
*/
6061
showSelectedOptionsCount?: boolean
62+
/**
63+
* Width of the menu list
64+
*
65+
* Note: the overflow needs to be handled explicitly for non-small variants
66+
*
67+
* @default 'ComponentSizeType.small'
68+
*/
69+
menuSize?: ComponentSizeType
6170
}

src/Shared/Components/SelectPicker/utils.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
import { ComponentSizeType } from '@Shared/constants'
22
import { SelectPickerProps } from './type'
33

4-
export const getCommonSelectStyle = ({ error, size }: Pick<SelectPickerProps, 'error' | 'size'>) => ({
4+
const getMenuWidthFromSize = (menuSize: SelectPickerProps['menuSize']) => {
5+
switch (menuSize) {
6+
case ComponentSizeType.medium:
7+
return '125%'
8+
case ComponentSizeType.large:
9+
return '150%'
10+
case ComponentSizeType.small:
11+
default:
12+
return '100%'
13+
}
14+
}
15+
16+
export const getCommonSelectStyle = ({
17+
error,
18+
size,
19+
menuSize,
20+
}: Pick<SelectPickerProps, 'error' | 'size' | 'menuSize'>) => ({
521
container: (base, state) => ({
622
...base,
723
...(state.isDisabled && {
@@ -16,6 +32,7 @@ export const getCommonSelectStyle = ({ error, size }: Pick<SelectPickerProps, 'e
1632
backgroundColor: 'var(--N0)',
1733
border: '1px solid var(--N200)',
1834
boxShadow: '0px 2px 4px 0px rgba(0, 0, 0, 0.20)',
35+
width: getMenuWidthFromSize(menuSize),
1936
}),
2037
menuList: (base) => ({
2138
...base,

src/Shared/constants.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ export enum K8sResourcePayloadAppType {
411411
EXTERNAL_ARGO_APP = 2,
412412
}
413413

414+
/**
415+
* Size variants for components
416+
*/
414417
export enum ComponentSizeType {
415418
small = 'small',
416419
medium = 'medium',

0 commit comments

Comments
 (0)