@@ -23,7 +23,7 @@ type SegmentTooltipProps = Omit<
2323 'alwaysShowTippyOnHover' | 'showOnTruncate' | 'shortcutKeyCombo' | 'placement'
2424>
2525
26- export type SegmentType = Pick < SelectPickerOptionType , 'value' > & {
26+ export type SegmentType < T = string | number > = {
2727 /**
2828 * If true, the segment will be in error state with error icon
2929 */
@@ -32,44 +32,48 @@ export type SegmentType = Pick<SelectPickerOptionType, 'value'> & {
3232 * If true, the segment will be in disabled state
3333 */
3434 isDisabled ?: boolean
35+ /**
36+ * Value for the segment
37+ */
38+ value : T
3539} & (
36- | ( {
37- /**
38- * Label for the segment
39- *
40- * Note: Either of label or icon is required
41- */
42- label : SelectPickerOptionType [ 'label' ]
43- /**
44- * Icon for the segment
45- *
46- * Note: Either of label or icon is required
47- */
48- icon ?: IconsProps [ 'name' ]
49- /**
50- * Tooltip props for the segment
51- *
52- * Note: Required if only icon is provided
53- */
54- tooltipProps ?: SegmentTooltipProps
55- ariaLabel ?: never
56- } & Pick < SelectPickerOptionType , 'label' > )
57- | {
58- label ?: never
59- tooltipProps : SegmentTooltipProps
60- icon : IconsProps [ 'name' ]
61- /**
62- * Aria label for the segment
63- */
64- ariaLabel : string
65- }
66- )
40+ | ( {
41+ /**
42+ * Label for the segment
43+ *
44+ * Note: Either of label or icon is required
45+ */
46+ label : SelectPickerOptionType [ 'label' ]
47+ /**
48+ * Icon for the segment
49+ *
50+ * Note: Either of label or icon is required
51+ */
52+ icon ?: IconsProps [ 'name' ]
53+ /**
54+ * Tooltip props for the segment
55+ *
56+ * Note: Required if only icon is provided
57+ */
58+ tooltipProps ?: SegmentTooltipProps
59+ ariaLabel ?: never
60+ } & Pick < SelectPickerOptionType , 'label' > )
61+ | {
62+ label ?: never
63+ tooltipProps : SegmentTooltipProps
64+ icon : IconsProps [ 'name' ]
65+ /**
66+ * Aria label for the segment
67+ */
68+ ariaLabel : string
69+ }
70+ )
6771
68- export type SegmentedControlProps = {
72+ export type SegmentedControlProps < T = string | number > = {
6973 /**
7074 * List of segments to be displayed
7175 */
72- segments : SegmentType [ ]
76+ segments : SegmentType < T > [ ]
7377 /**
7478 * Please make sure this is unique
7579 */
@@ -86,19 +90,19 @@ export type SegmentedControlProps = {
8690 /**
8791 * On change handler for the component
8892 */
89- onChange ?: ( selectedSegment : SegmentType ) => void
93+ onChange ?: ( selectedSegment : SegmentType < T > ) => void
9094 }
9195 | {
9296 /**
9397 * If defined, the component is controlled and onChange needs to be handled by the parent
9498 */
95- value : SegmentType [ 'value' ]
96- onChange : ( selectedSegment : SegmentType ) => void
99+ value : SegmentType < T > [ 'value' ]
100+ onChange : ( selectedSegment : SegmentType < T > ) => void
97101 }
98102)
99103
100- export interface SegmentProps
101- extends Required < Pick < SegmentedControlProps , 'name' | 'onChange' | 'fullWidth' | 'size' | 'disabled' > > {
104+ export interface SegmentProps < T >
105+ extends Required < Pick < SegmentedControlProps < T > , 'name' | 'onChange' | 'fullWidth' | 'size' | 'disabled' > > {
102106 isSelected : boolean
103- segment : SegmentType
107+ segment : SegmentType < T >
104108}
0 commit comments