Skip to content

Commit 04cd0e3

Browse files
committed
feat: add basic small variant for SelectPicker
1 parent 70e548c commit 04cd0e3

File tree

4 files changed

+55
-9
lines changed

4 files changed

+55
-9
lines changed

src/Shared/Components/SelectPicker/common.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const SelectPickerDropdownIndicator = <OptionValue,>(
4646

4747
return (
4848
<components.DropdownIndicator {...props}>
49-
<ICCaretDown className={`icon-dim-16 ${isDisabled ? 'scn-3' : 'scn-6'} dc__no-shrink`} />
49+
<ICCaretDown className={isDisabled ? 'scn-3' : 'scn-6'} />
5050
</components.DropdownIndicator>
5151
)
5252
}
@@ -55,7 +55,7 @@ export const SelectPickerClearIndicator = <OptionValue,>(
5555
props: ClearIndicatorProps<SelectPickerOptionType<OptionValue>>,
5656
) => (
5757
<components.ClearIndicator {...props}>
58-
<ICClose className="icon-dim-16 icon-use-fill-n6 dc__no-shrink" />
58+
<ICClose className="icon-use-fill-n6" />
5959
</components.ClearIndicator>
6060
)
6161

@@ -100,6 +100,7 @@ export const SelectPickerValueContainer = <OptionValue, IsMulti extends boolean>
100100
<div className="flex left">
101101
<components.ValueContainer {...props} />
102102
</div>
103+
{/* Size will not work here need to go in details later when prioritized */}
103104
{showSelectedOptionsCount && selectedOptionsLength > 0 && (
104105
<div className="bcb-50 dc__border eb-2 dc__border-radius-4-imp pl-5 pr-5 cb-5 fs-12 fw-6 lh-18 dc__truncate dc__no-shrink">
105106
{selectedOptionsLength}

src/Shared/Components/SelectPicker/type.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ export type SelectPickerProps<OptionValue = number | string, IsMulti extends boo
136136
*/
137137
customSelectedOptionsCount?: number
138138
/**
139-
* Height of the dropdown
139+
* Size of select
140140
*
141141
* @default 'ComponentSizeType.medium'
142142
*/
143-
size?: Extract<ComponentSizeType, ComponentSizeType.medium | ComponentSizeType.large>
143+
size?: Extract<ComponentSizeType, ComponentSizeType.medium | ComponentSizeType.large | ComponentSizeType.small>
144144
/**
145145
* Content to be shown in a tippy when disabled
146146
*/

src/Shared/Components/SelectPicker/utils.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
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'
2021
import { SelectPickerOptionType, SelectPickerProps, SelectPickerVariantType } from './type'
2122

2223
const getMenuWidthFromSize = <OptionValue, IsMulti extends boolean>(
@@ -77,6 +78,24 @@ const getOptionBgColor = <OptionValue>(
7778
return 'var(--N0)'
7879
}
7980

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+
8099
export const getCommonSelectStyle = <OptionValue, IsMulti extends boolean>({
81100
error,
82101
size,
@@ -117,7 +136,8 @@ export const getCommonSelectStyle = <OptionValue, IsMulti extends boolean>({
117136
}),
118137
control: (base, state) => ({
119138
...base,
120-
minHeight: size === ComponentSizeType.medium ? 'auto' : '36px',
139+
minHeight:
140+
getComponentSizeMagnitude(size) <= getComponentSizeMagnitude(ComponentSizeType.medium) ? 'auto' : '36px',
121141
minWidth: '56px',
122142
boxShadow: 'none',
123143
backgroundColor: 'var(--N50)',
@@ -165,6 +185,10 @@ export const getCommonSelectStyle = <OptionValue, IsMulti extends boolean>({
165185
}),
166186
dropdownIndicator: (base, state) => ({
167187
...base,
188+
...getIconSize(size),
189+
display: 'flex',
190+
alignItems: 'center',
191+
flexShrink: '0',
168192
color: 'var(--N600)',
169193
padding: '0',
170194
transition: 'all .2s ease',
@@ -173,6 +197,10 @@ export const getCommonSelectStyle = <OptionValue, IsMulti extends boolean>({
173197
clearIndicator: (base) => ({
174198
...base,
175199
padding: 0,
200+
...getIconSize(size),
201+
display: 'flex',
202+
alignItems: 'center',
203+
flexShrink: '0',
176204

177205
'&:hover': {
178206
backgroundColor: 'transparent',
@@ -274,7 +302,7 @@ export const getCommonSelectStyle = <OptionValue, IsMulti extends boolean>({
274302
margin: 0,
275303
padding: 0,
276304
color: 'var(--N900)',
277-
size: '13px',
305+
size: getFontSize(size),
278306
fontWeight: 400,
279307
lineHeight: '20px',
280308
overflow: 'hidden',
@@ -284,7 +312,7 @@ export const getCommonSelectStyle = <OptionValue, IsMulti extends boolean>({
284312
placeholder: (base) => ({
285313
...base,
286314
color: 'var(--N500)',
287-
fontSize: '13px',
315+
fontSize: getFontSize(size),
288316
lineHeight: '20px',
289317
fontWeight: 400,
290318
margin: 0,
@@ -301,7 +329,7 @@ export const getCommonSelectStyle = <OptionValue, IsMulti extends boolean>({
301329
...base,
302330
margin: 0,
303331
color: 'var(--N900)',
304-
fontSize: '13px',
332+
fontSize: getFontSize(size),
305333
fontWeight: 400,
306334
lineHeight: '20px',
307335
...(getVariantOverrides(variant)?.singleValue(base, state) || {}),

src/Shared/Helpers.tsx

Lines changed: 18 additions & 1 deletion
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 { DEPLOYMENT_STATUS, TIMELINE_STATUS } from './constants'
45+
import { ComponentSizeType, DEPLOYMENT_STATUS, TIMELINE_STATUS } from './constants'
4646
import {
4747
AggregatedNodes,
4848
DeploymentStatusDetailsBreakdownDataType,
@@ -821,3 +821,20 @@ 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)