Skip to content

Commit 4bd2de9

Browse files
committed
feat: Update SelectPicker constants for font size, icon size, and control size
1 parent 56e246a commit 4bd2de9

File tree

3 files changed

+28
-44
lines changed

3 files changed

+28
-44
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ComponentSizeType } from '@Shared/constants'
2+
import { SelectPickerProps } from './type'
3+
4+
export const SELECT_PICKER_FONT_SIZE_MAP: Record<SelectPickerProps['size'], string> = {
5+
[ComponentSizeType.small]: '12px',
6+
[ComponentSizeType.medium]: '13px',
7+
[ComponentSizeType.large]: '13px',
8+
}
9+
10+
export const SELECT_PICKER_ICON_SIZE_MAP: Record<SelectPickerProps['size'], { width: string; height: string }> = {
11+
[ComponentSizeType.small]: { width: '12px', height: '12px' },
12+
[ComponentSizeType.medium]: { width: '16px', height: '16px' },
13+
[ComponentSizeType.large]: { width: '16px', height: '16px' },
14+
}
15+
16+
export const SELECT_PICKER_CONTROL_SIZE_MAP: Record<SelectPickerProps['size'], string> = {
17+
[ComponentSizeType.small]: 'auto',
18+
[ComponentSizeType.medium]: 'auto',
19+
[ComponentSizeType.large]: '36px',
20+
}

src/Shared/Components/SelectPicker/utils.ts

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import { CHECKBOX_VALUE } from '@Common/Types'
1818
import { ComponentSizeType } from '@Shared/constants'
1919
import { GroupBase, MultiValue, OptionsOrGroups, StylesConfig } from 'react-select'
20-
import { getComponentSizeMagnitude } from '@Shared/Helpers'
2120
import { SelectPickerOptionType, SelectPickerProps, SelectPickerVariantType } from './type'
21+
import { SELECT_PICKER_CONTROL_SIZE_MAP, SELECT_PICKER_FONT_SIZE_MAP, SELECT_PICKER_ICON_SIZE_MAP } from './constants'
2222

2323
const getMenuWidthFromSize = <OptionValue, IsMulti extends boolean>(
2424
menuSize: SelectPickerProps<OptionValue, IsMulti>['menuSize'],
@@ -78,24 +78,6 @@ const getOptionBgColor = <OptionValue>(
7878
return 'var(--N0)'
7979
}
8080

81-
const getFontSize = (size: ComponentSizeType): string => {
82-
switch (size) {
83-
case ComponentSizeType.small:
84-
return '12px'
85-
default:
86-
return '13px'
87-
}
88-
}
89-
90-
const getIconSize = (size: ComponentSizeType): { width: string; height: string } => {
91-
switch (size) {
92-
case ComponentSizeType.small:
93-
return { width: '12px', height: '12px' }
94-
default:
95-
return { width: '16px', height: '16px' }
96-
}
97-
}
98-
9981
export const getCommonSelectStyle = <OptionValue, IsMulti extends boolean>({
10082
error,
10183
size,
@@ -136,8 +118,7 @@ export const getCommonSelectStyle = <OptionValue, IsMulti extends boolean>({
136118
}),
137119
control: (base, state) => ({
138120
...base,
139-
minHeight:
140-
getComponentSizeMagnitude(size) <= getComponentSizeMagnitude(ComponentSizeType.medium) ? 'auto' : '36px',
121+
minHeight: SELECT_PICKER_CONTROL_SIZE_MAP[size],
141122
minWidth: '56px',
142123
boxShadow: 'none',
143124
backgroundColor: 'var(--N50)',
@@ -185,7 +166,7 @@ export const getCommonSelectStyle = <OptionValue, IsMulti extends boolean>({
185166
}),
186167
dropdownIndicator: (base, state) => ({
187168
...base,
188-
...getIconSize(size),
169+
...SELECT_PICKER_ICON_SIZE_MAP[size],
189170
display: 'flex',
190171
alignItems: 'center',
191172
flexShrink: '0',
@@ -196,8 +177,8 @@ export const getCommonSelectStyle = <OptionValue, IsMulti extends boolean>({
196177
}),
197178
clearIndicator: (base) => ({
198179
...base,
180+
...SELECT_PICKER_ICON_SIZE_MAP[size],
199181
padding: 0,
200-
...getIconSize(size),
201182
display: 'flex',
202183
alignItems: 'center',
203184
flexShrink: '0',
@@ -302,7 +283,7 @@ export const getCommonSelectStyle = <OptionValue, IsMulti extends boolean>({
302283
margin: 0,
303284
padding: 0,
304285
color: 'var(--N900)',
305-
size: getFontSize(size),
286+
size: '13px',
306287
fontWeight: 400,
307288
lineHeight: '20px',
308289
overflow: 'hidden',
@@ -312,7 +293,7 @@ export const getCommonSelectStyle = <OptionValue, IsMulti extends boolean>({
312293
placeholder: (base) => ({
313294
...base,
314295
color: 'var(--N500)',
315-
fontSize: getFontSize(size),
296+
fontSize: SELECT_PICKER_FONT_SIZE_MAP[size],
316297
lineHeight: '20px',
317298
fontWeight: 400,
318299
margin: 0,
@@ -329,7 +310,7 @@ export const getCommonSelectStyle = <OptionValue, IsMulti extends boolean>({
329310
...base,
330311
margin: 0,
331312
color: 'var(--N900)',
332-
fontSize: getFontSize(size),
313+
fontSize: SELECT_PICKER_FONT_SIZE_MAP[size],
333314
fontWeight: 400,
334315
lineHeight: '20px',
335316
...(getVariantOverrides(variant)?.singleValue(base, state) || {}),

src/Shared/Helpers.tsx

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import {
4242
import { ReactComponent as ICPullRequest } from '../Assets/Icon/ic-pull-request.svg'
4343
import { ReactComponent as ICTag } from '../Assets/Icon/ic-tag.svg'
4444
import { ReactComponent as ICWebhook } from '../Assets/Icon/ic-webhook.svg'
45-
import { ComponentSizeType, DEPLOYMENT_STATUS, TIMELINE_STATUS } from './constants'
45+
import { DEPLOYMENT_STATUS, TIMELINE_STATUS } from './constants'
4646
import {
4747
AggregatedNodes,
4848
DeploymentStatusDetailsBreakdownDataType,
@@ -821,20 +821,3 @@ export const getDefaultValueFromType = (value: unknown) => {
821821
return null
822822
}
823823
}
824-
825-
export const getComponentSizeMagnitude = (size: ComponentSizeType): number => {
826-
switch (size) {
827-
case ComponentSizeType.xs:
828-
return 1
829-
case ComponentSizeType.small:
830-
return 2
831-
case ComponentSizeType.medium:
832-
return 3
833-
case ComponentSizeType.large:
834-
return 4
835-
case ComponentSizeType.xl:
836-
return 5
837-
default:
838-
return 0
839-
}
840-
}

0 commit comments

Comments
 (0)