@hero-design/rn 8.104.1-alpha.2 → 8.105.0
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.
- package/.turbo/turbo-build.log +3 -3
- package/CHANGELOG.md +6 -10
- package/assets/fonts/hero-icons-mobile.ttf +0 -0
- package/es/index.js +683 -402
- package/lib/assets/fonts/hero-icons-mobile.ttf +0 -0
- package/lib/index.js +683 -401
- package/package.json +1 -1
- package/src/components/Calendar/CalendarRange.tsx +35 -117
- package/src/components/Calendar/__tests__/helper.spec.ts +197 -0
- package/src/components/Calendar/constants.ts +9 -0
- package/src/components/Calendar/helpers.ts +112 -0
- package/src/components/Calendar/index.tsx +34 -159
- package/src/components/Calendar/shared/hooks/useCalendarLayout.ts +37 -0
- package/src/components/Calendar/types.ts +62 -0
- package/src/components/DatePicker/DatePickerCalendar.tsx +2 -1
- package/src/components/Icon/HeroIcon/glyphMap.json +1 -1
- package/src/components/Icon/IconList.ts +2 -0
- package/src/components/SegmentedControl/SegmentedItem.tsx +192 -0
- package/src/components/SegmentedControl/StyledSegmentedControl.tsx +62 -0
- package/src/components/SegmentedControl/__tests__/SegmentedItem.spec.tsx +162 -0
- package/src/components/SegmentedControl/__tests__/__snapshots__/SegmentedItem.spec.tsx.snap +131 -0
- package/src/components/SegmentedControl/__tests__/__snapshots__/index.spec.tsx.snap +359 -0
- package/src/components/SegmentedControl/__tests__/index.spec.tsx +247 -0
- package/src/components/SegmentedControl/index.tsx +61 -0
- package/src/components/SegmentedControl/types.ts +46 -0
- package/src/components/Typography/Body/StyledBody.tsx +2 -2
- package/src/components/Typography/Body/__tests__/__snapshots__/index.spec.tsx.snap +51 -0
- package/src/components/Typography/Body/__tests__/index.spec.tsx +1 -0
- package/src/components/Typography/Body/index.tsx +2 -13
- package/src/components/Typography/Caption/StyledCaption.tsx +2 -2
- package/src/components/Typography/Caption/__tests__/__snapshots__/index.spec.tsx.snap +50 -0
- package/src/components/Typography/Caption/__tests__/index.spec.tsx +1 -0
- package/src/components/Typography/Caption/index.tsx +2 -13
- package/src/components/Typography/Label/StyledLabel.tsx +2 -2
- package/src/components/Typography/Label/__tests__/__snapshots__/index.spec.tsx.snap +48 -0
- package/src/components/Typography/Label/__tests__/index.spec.tsx +1 -0
- package/src/components/Typography/Label/index.tsx +2 -13
- package/src/components/Typography/Title/StyledTitle.tsx +2 -2
- package/src/components/Typography/Title/__tests__/__snapshots__/index.spec.tsx.snap +51 -0
- package/src/components/Typography/Title/__tests__/index.spec.tsx +1 -0
- package/src/components/Typography/Title/index.tsx +2 -13
- package/src/components/Typography/types.ts +3 -2
- package/src/index.ts +2 -0
- package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +54 -0
- package/src/theme/components/segmentedControl.ts +60 -0
- package/src/theme/components/typography.ts +1 -0
- package/src/theme/getTheme.ts +3 -0
- package/src/types.ts +2 -0
- package/stats/8.104.0/rn-stats.html +3 -1
- package/stats/8.105.0/rn-stats.html +4844 -0
- package/types/components/Calendar/CalendarRange.d.ts +4 -16
- package/types/components/Calendar/constants.d.ts +4 -0
- package/types/components/Calendar/helpers.d.ts +14 -0
- package/types/components/Calendar/index.d.ts +5 -56
- package/types/components/Calendar/shared/hooks/useCalendarLayout.d.ts +8 -0
- package/types/components/Calendar/types.d.ts +58 -0
- package/types/components/Icon/IconList.d.ts +1 -1
- package/types/components/Icon/index.d.ts +1 -1
- package/types/components/SegmentedControl/SegmentedItem.d.ts +18 -0
- package/types/components/SegmentedControl/StyledSegmentedControl.d.ts +26 -0
- package/types/components/SegmentedControl/index.d.ts +31 -0
- package/types/components/SegmentedControl/types.d.ts +43 -0
- package/types/components/TextInput/index.d.ts +1 -1
- package/types/components/Typography/Body/StyledBody.d.ts +2 -2
- package/types/components/Typography/Body/index.d.ts +2 -1
- package/types/components/Typography/Caption/StyledCaption.d.ts +2 -2
- package/types/components/Typography/Caption/index.d.ts +2 -1
- package/types/components/Typography/Label/StyledLabel.d.ts +2 -2
- package/types/components/Typography/Label/index.d.ts +2 -1
- package/types/components/Typography/Title/StyledTitle.d.ts +2 -2
- package/types/components/Typography/Title/index.d.ts +2 -1
- package/types/components/Typography/types.d.ts +1 -1
- package/types/index.d.ts +2 -1
- package/types/theme/components/segmentedControl.d.ts +46 -0
- package/types/theme/components/typography.d.ts +1 -0
- package/types/theme/getTheme.d.ts +2 -0
- package/types/types.d.ts +2 -1
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
MonthYearPickerViewIOS,
|
|
4
4
|
} from '@hero-design/react-native-month-year-picker';
|
|
5
5
|
import format from 'date-fns/fp/format';
|
|
6
|
-
import React, {
|
|
7
|
-
import {
|
|
6
|
+
import React, { useState } from 'react';
|
|
7
|
+
import { Platform, TouchableOpacity } from 'react-native';
|
|
8
8
|
import { useTheme } from '../../theme';
|
|
9
9
|
import { noop } from '../../utils/functions';
|
|
10
10
|
import Box from '../Box';
|
|
@@ -20,80 +20,16 @@ import {
|
|
|
20
20
|
StyledContainer,
|
|
21
21
|
StyledDisabledCalendarRowItem,
|
|
22
22
|
} from './StyledCalendar';
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
getCalendarButtonState,
|
|
25
|
+
getCalendarDate,
|
|
26
|
+
isEqDate,
|
|
27
|
+
shouldUseMonthPicker,
|
|
28
|
+
} from './helpers';
|
|
24
29
|
import CalendarRange from './CalendarRange';
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
// Sunday last column => 1
|
|
29
|
-
const WEEK_INDEX_OFFSET = 1;
|
|
30
|
-
const SUNDAY_INDEX = 6;
|
|
31
|
-
|
|
32
|
-
// Always render 7 rows x 6 items for consistent layout
|
|
33
|
-
const TOTAL_DATES_ITEMS = 7 * 6;
|
|
34
|
-
|
|
35
|
-
type ParsedMaskedDate = {
|
|
36
|
-
[key: string]: boolean;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export interface CalendarProps {
|
|
40
|
-
/**
|
|
41
|
-
* Selected date value.
|
|
42
|
-
*/
|
|
43
|
-
value?: Date;
|
|
44
|
-
/**
|
|
45
|
-
* Visible date of month that calendar opens to display. Default is now.
|
|
46
|
-
*/
|
|
47
|
-
visibleDate: Date;
|
|
48
|
-
/**
|
|
49
|
-
* Mininum date. Restrict the range of possible date values.
|
|
50
|
-
*/
|
|
51
|
-
minDate?: Date;
|
|
52
|
-
/**
|
|
53
|
-
* Maximum date. Restrict the range of possible date values.
|
|
54
|
-
*/
|
|
55
|
-
maxDate?: Date;
|
|
56
|
-
/**
|
|
57
|
-
* Callback is called when selected date value is changed.
|
|
58
|
-
*/
|
|
59
|
-
onChange?: (date: Date) => void;
|
|
60
|
-
/**
|
|
61
|
-
* Handler to be called when the user taps the previous button.
|
|
62
|
-
*/
|
|
63
|
-
onPreviousPress?: () => void;
|
|
64
|
-
/**
|
|
65
|
-
* Handler to be called when the user taps the next button.
|
|
66
|
-
*/
|
|
67
|
-
onNextPress?: () => void;
|
|
68
|
-
/**
|
|
69
|
-
* Handler to be called when the user taps the title.
|
|
70
|
-
*/
|
|
71
|
-
onTitlePress?: () => void;
|
|
72
|
-
/**
|
|
73
|
-
* Mark dates to display on calendar.
|
|
74
|
-
*/
|
|
75
|
-
markedDates?: Date[];
|
|
76
|
-
/**
|
|
77
|
-
* Testing id of the component.
|
|
78
|
-
*/
|
|
79
|
-
testID?: string;
|
|
80
|
-
/**
|
|
81
|
-
* Callback when header month is changed, passing this prop will disable onTitlePress.
|
|
82
|
-
*/
|
|
83
|
-
onMonthChange?: (date: Date) => void;
|
|
84
|
-
/*
|
|
85
|
-
* Callback when month picker is toggled.
|
|
86
|
-
*/
|
|
87
|
-
onToggleMonthPicker?: (visible: boolean) => void;
|
|
88
|
-
/**
|
|
89
|
-
* Label for the confirm button of the month picker, Android only.
|
|
90
|
-
*/
|
|
91
|
-
monthPickerConfirmLabel?: string;
|
|
92
|
-
/**
|
|
93
|
-
* Label for the cancel button of the month picker, Android only.
|
|
94
|
-
*/
|
|
95
|
-
monthPickerCancelLabel?: string;
|
|
96
|
-
}
|
|
30
|
+
import { DAYS_OF_WEEK } from './constants';
|
|
31
|
+
import { CalendarProps } from './types';
|
|
32
|
+
import { useCalendarLayout } from './shared/hooks/useCalendarLayout';
|
|
97
33
|
|
|
98
34
|
const Calendar = ({
|
|
99
35
|
value,
|
|
@@ -112,98 +48,37 @@ const Calendar = ({
|
|
|
112
48
|
monthPickerCancelLabel,
|
|
113
49
|
}: CalendarProps) => {
|
|
114
50
|
const theme = useTheme();
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const calendarItemWidth = useMemo(
|
|
129
|
-
() =>
|
|
130
|
-
contentWidth > 0
|
|
131
|
-
? Math.floor(
|
|
132
|
-
(contentWidth - theme.__hd__.calendar.space.cellPadding) / 7
|
|
133
|
-
)
|
|
134
|
-
: undefined,
|
|
135
|
-
[contentWidth, theme]
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
const useMonthPicker = onMonthChange !== noop;
|
|
139
|
-
|
|
140
|
-
const firstDateOfMonth = new Date(currentYear, currentMonth, 1);
|
|
141
|
-
const lastDateOfMonth = new Date(currentYear, currentMonth + 1, 0);
|
|
142
|
-
|
|
143
|
-
const lastDateOfPreviousMonth = new Date(currentYear, currentMonth, 0);
|
|
144
|
-
|
|
145
|
-
// Index of day in week is shifted by 1 due to Sunday is the last column
|
|
146
|
-
const firstDayWeekIndexOfMonth =
|
|
147
|
-
firstDateOfMonth.getDay() === 0
|
|
148
|
-
? SUNDAY_INDEX
|
|
149
|
-
: firstDateOfMonth.getDay() - WEEK_INDEX_OFFSET;
|
|
150
|
-
|
|
151
|
-
const lastDayIndexOfCurrentMonth = lastDateOfMonth.getDate();
|
|
152
|
-
const lastDayIndexOfPreviousMonth = lastDateOfPreviousMonth.getDate();
|
|
153
|
-
|
|
154
|
-
const daysOfPreviousMonth = initArray(firstDayWeekIndexOfMonth, (index) => {
|
|
155
|
-
const reversedIndex = firstDayWeekIndexOfMonth - index - 1;
|
|
156
|
-
const count = lastDayIndexOfPreviousMonth - reversedIndex;
|
|
157
|
-
return getValidDate(
|
|
158
|
-
new Date(currentYear, currentMonth - 1, count),
|
|
159
|
-
minDate,
|
|
160
|
-
maxDate
|
|
161
|
-
);
|
|
51
|
+
const { onLayout, contentHeight, contentWidth, calendarItemWidth } =
|
|
52
|
+
useCalendarLayout();
|
|
53
|
+
const {
|
|
54
|
+
parsedMaskedDate,
|
|
55
|
+
daysOfPreviousMonth,
|
|
56
|
+
daysOfCurrentMonth,
|
|
57
|
+
daysOfNextMonth,
|
|
58
|
+
} = getCalendarDate({
|
|
59
|
+
visibleDate,
|
|
60
|
+
markedDates,
|
|
61
|
+
minDate,
|
|
62
|
+
maxDate,
|
|
63
|
+
onMonthChange,
|
|
162
64
|
});
|
|
65
|
+
const { disablePrevButton, disableNextButton } = getCalendarButtonState({
|
|
66
|
+
visibleDate,
|
|
67
|
+
minDate,
|
|
68
|
+
maxDate,
|
|
69
|
+
});
|
|
70
|
+
const shouldShowMonthPicker = shouldUseMonthPicker(onMonthChange);
|
|
163
71
|
|
|
164
|
-
const
|
|
165
|
-
getValidDate(
|
|
166
|
-
new Date(currentYear, currentMonth, index + 1),
|
|
167
|
-
minDate,
|
|
168
|
-
maxDate
|
|
169
|
-
)
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
const daysOfNextMonth = initArray(
|
|
173
|
-
TOTAL_DATES_ITEMS -
|
|
174
|
-
(daysOfPreviousMonth.length + daysOfCurrentMonth.length),
|
|
175
|
-
(index) =>
|
|
176
|
-
getValidDate(
|
|
177
|
-
new Date(currentYear, currentMonth + 1, index + 1),
|
|
178
|
-
minDate,
|
|
179
|
-
maxDate
|
|
180
|
-
)
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
const disablePrevButton =
|
|
184
|
-
minDate === undefined
|
|
185
|
-
? false
|
|
186
|
-
: !daysOfPreviousMonth.some((date) => date !== undefined) &&
|
|
187
|
-
minDate >= firstDateOfMonth;
|
|
188
|
-
|
|
189
|
-
const disableNextButton =
|
|
190
|
-
maxDate === undefined
|
|
191
|
-
? false
|
|
192
|
-
: !daysOfNextMonth.some((date) => date !== undefined) ||
|
|
193
|
-
maxDate <= lastDateOfMonth;
|
|
72
|
+
const [monthPickerVisible, setMonthPickerVisible] = useState(false);
|
|
194
73
|
|
|
195
|
-
const
|
|
196
|
-
const { width, height } = e.nativeEvent.layout;
|
|
197
|
-
setContentHeight(height);
|
|
198
|
-
setContentWidth(width);
|
|
199
|
-
};
|
|
74
|
+
const now = new Date();
|
|
200
75
|
|
|
201
76
|
return (
|
|
202
77
|
<StyledContainer testID={testID}>
|
|
203
78
|
<StyledCalendarHeader>
|
|
204
79
|
<ContentNavigator
|
|
205
80
|
value={
|
|
206
|
-
!
|
|
81
|
+
!shouldShowMonthPicker ? (
|
|
207
82
|
format('MMMM yyyy', visibleDate)
|
|
208
83
|
) : (
|
|
209
84
|
<TouchableOpacity
|
|
@@ -239,7 +114,7 @@ const Calendar = ({
|
|
|
239
114
|
}
|
|
240
115
|
onPreviousPress={onPreviousPress}
|
|
241
116
|
onNextPress={onNextPress}
|
|
242
|
-
onPress={
|
|
117
|
+
onPress={shouldShowMonthPicker ? undefined : onTitlePress}
|
|
243
118
|
previousDisabled={disablePrevButton}
|
|
244
119
|
nextDisabled={disableNextButton}
|
|
245
120
|
fontSize="large"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
2
|
+
import { LayoutChangeEvent } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { useTheme } from '../../../../theme';
|
|
5
|
+
|
|
6
|
+
export const useCalendarLayout = () => {
|
|
7
|
+
const theme = useTheme();
|
|
8
|
+
|
|
9
|
+
const [contentHeight, setContentHeight] = useState(0);
|
|
10
|
+
const calendarItemHeight =
|
|
11
|
+
contentHeight - theme.__hd__.calendar.space.iosPickerMarginVertical * 2;
|
|
12
|
+
|
|
13
|
+
const [contentWidth, setContentWidth] = useState(0);
|
|
14
|
+
const calendarItemWidth = useMemo(
|
|
15
|
+
() =>
|
|
16
|
+
contentWidth > 0
|
|
17
|
+
? Math.floor(
|
|
18
|
+
(contentWidth - theme.__hd__.calendar.space.cellPadding) / 7
|
|
19
|
+
)
|
|
20
|
+
: undefined,
|
|
21
|
+
[contentWidth, theme]
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const onLayout = useCallback((e: LayoutChangeEvent) => {
|
|
25
|
+
const { width, height } = e.nativeEvent.layout;
|
|
26
|
+
setContentHeight(height);
|
|
27
|
+
setContentWidth(width);
|
|
28
|
+
}, []);
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
onLayout,
|
|
32
|
+
contentHeight,
|
|
33
|
+
calendarItemHeight,
|
|
34
|
+
contentWidth,
|
|
35
|
+
calendarItemWidth,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export type ParsedMaskedDate = {
|
|
2
|
+
[key: string]: boolean;
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
export interface CalendarProps {
|
|
6
|
+
/**
|
|
7
|
+
* Selected date value.
|
|
8
|
+
*/
|
|
9
|
+
value?: Date;
|
|
10
|
+
/**
|
|
11
|
+
* Visible date of month that calendar opens to display. Default is now.
|
|
12
|
+
*/
|
|
13
|
+
visibleDate: Date;
|
|
14
|
+
/**
|
|
15
|
+
* Mininum date. Restrict the range of possible date values.
|
|
16
|
+
*/
|
|
17
|
+
minDate?: Date;
|
|
18
|
+
/**
|
|
19
|
+
* Maximum date. Restrict the range of possible date values.
|
|
20
|
+
*/
|
|
21
|
+
maxDate?: Date;
|
|
22
|
+
/**
|
|
23
|
+
* Callback is called when selected date value is changed.
|
|
24
|
+
*/
|
|
25
|
+
onChange?: (date: Date) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Handler to be called when the user taps the previous button.
|
|
28
|
+
*/
|
|
29
|
+
onPreviousPress?: () => void;
|
|
30
|
+
/**
|
|
31
|
+
* Handler to be called when the user taps the next button.
|
|
32
|
+
*/
|
|
33
|
+
onNextPress?: () => void;
|
|
34
|
+
/**
|
|
35
|
+
* Handler to be called when the user taps the title.
|
|
36
|
+
*/
|
|
37
|
+
onTitlePress?: () => void;
|
|
38
|
+
/**
|
|
39
|
+
* Mark dates to display on calendar.
|
|
40
|
+
*/
|
|
41
|
+
markedDates?: Date[];
|
|
42
|
+
/**
|
|
43
|
+
* Testing id of the component.
|
|
44
|
+
*/
|
|
45
|
+
testID?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Callback when header month is changed, passing this prop will disable onTitlePress.
|
|
48
|
+
*/
|
|
49
|
+
onMonthChange?: (date: Date) => void;
|
|
50
|
+
/*
|
|
51
|
+
* Callback when month picker is toggled.
|
|
52
|
+
*/
|
|
53
|
+
onToggleMonthPicker?: (visible: boolean) => void;
|
|
54
|
+
/**
|
|
55
|
+
* Label for the confirm button of the month picker, Android only.
|
|
56
|
+
*/
|
|
57
|
+
monthPickerConfirmLabel?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Label for the cancel button of the month picker, Android only.
|
|
60
|
+
*/
|
|
61
|
+
monthPickerCancelLabel?: string;
|
|
62
|
+
}
|
|
@@ -3,7 +3,8 @@ import { Platform, ScrollView, View } from 'react-native';
|
|
|
3
3
|
|
|
4
4
|
import BottomSheet from '../BottomSheet';
|
|
5
5
|
import Button from '../Button';
|
|
6
|
-
import Calendar
|
|
6
|
+
import Calendar from '../Calendar';
|
|
7
|
+
import type { CalendarProps } from '../Calendar/types';
|
|
7
8
|
import TextInput from '../TextInput';
|
|
8
9
|
import useCalculateDate from './hooks/useCalculateDate';
|
|
9
10
|
import useFormatDate from './hooks/useFormatDate';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"activate":59000,"add-emoji":59001,"add-person":59002,"adjustment":59003,"alignment":59004,"antenna":59005,"archive":59006,"assignment-warning":59007,"bank":59008,"bell":59009,"billing":59010,"bolt":59011,"bookmark-added":59012,"bookmark-checked":59013,"bookmark":59014,"box-check":59015,"box":59016,"bpay":59017,"buildings":59018,"cake":59019,"calendar-clock":59020,"calendar":59021,"candy-box-menu":59022,"caret-down-small":59023,"caret-down":59024,"caret-left-small":59025,"caret-left":59026,"caret-right-small":59027,"caret-right":59028,"caret-up-small":59029,"caret-up":59030,"check-radio":59031,"circle-add":59032,"circle-cancel":59033,"circle-check":59034,"circle-down":59035,"circle-info":59036,"circle-left":59037,"circle-ok":59038,"circle-pencil":59039,"circle-question":59040,"circle-remove":59041,"circle-right":59042,"circle-up":59043,"circle-warning":59044,"clock-3":59045,"clock":59046,"cloud-download":59047,"cloud-upload":59048,"cog":59049,"coin":59050,"contacts":59051,"credit-card":59052,"diamond":59053,"direction-arrows":59054,"directory":59055,"document":59056,"dollar-coin-shine":59057,"dot":59058,"double-buildings":59059,"edit-template":59060,"envelope":59061,"exclude":59062,"expand-content":59063,"expense":59064,"explore_nearby":59065,"eye-circle":59066,"eye-invisible":59067,"eye":59068,"face-meh":59069,"face-sad":59070,"face-smiley":59071,"feed":59072,"feedbacks":59073,"file-certified":59074,"file-clone":59075,"file-copy":59076,"file-csv":59077,"file-dispose":59078,"file-doc":59079,"file-excel":59080,"file-export":59081,"file-lock":59082,"file-pdf":59083,"file-powerpoint":59084,"file-search":59085,"file-secured":59086,"file-sheets":59087,"file-slide":59088,"file-verified":59089,"file-word":59090,"file":59091,"filter":59092,"folder-user":59093,"folder":59094,"format-bold":59095,"format-heading1":59096,"format-heading2":59097,"format-italic":59098,"format-list-bulleted":59099,"format-list-numbered":59100,"format-underlined":59101,"funnel-filter":59102,"global-dollar":59103,"globe":59104,"graduation-cap":59105,"graph":59106,"happy-sun":59107,"health-bag":59108,"heart":59109,"hero-points":59110,"home":59111,"image":59112,"import":59113,"incident-siren":59114,"instapay-daily":59115,"instapay-now":59116,"instapay":59117,"list":59118,"loading-2":59119,"loading":59120,"location-on":59121,"location":59122,"lock":59123,"looks-one":59124,"looks-two":59125,"media-content":59126,"menu":59127,"money-notes":59128,"moneybag":59129,"moon":59130,"multiple-stars":59131,"multiple-users":59132,"near-me":59133,"node":59134,"open-folder":59135,"paperclip-vertical":59136,"paperclip":59137,"payment-summary":59138,"pencil":59139,"phone":59140,"piggy-bank":59141,"plane-up":59142,"plane":59143,"play-arrow":59144,"play-circle":59145,"print":59146,"raising-hands":59147,"reply-arrow":59148,"reply":59149,"reschedule":59150,"rostering":59151,"salary-sacrifice":59152,"save":59153,"schedule-send":59154,"schedule":59155,"search-person":59156,"search":59157,"send":59158,"speaker-active":59159,"speaker":59160,"star-award":59161,"star-badge":59162,"star-circle":59163,"star-medal":59164,"star":59165,"steps-circle":59166,"stopwatch":59167,"suitcase":59168,"surfing":59169,"survey":59170,"swag-pillar-benefit":59171,"swag-pillar-career":59172,"swag-pillar-money":59173,"swag-pillar-work":59174,"swag":59175,"swipe-right":59176,"switch":59177,"tag":59178,"target":59179,"teams":59180,"thumb-down":59181,"timesheet":59182,"touch-id":59183,"trash-bin":59184,"unlock":59185,"user":59186,"video-1":59187,"video-2":59188,"wallet":59189,"warning":59190,"academic-hat-outlined":59191,"accommodation-outlined":59192,"activate-outlined":59193,"add-credit-card-outlined":59194,"add-person-outlined":59195,"add-section-outlined":59196,"add-time-outlined":59197,"add":59198,"adjustment-outlined":59199,"afternoon-outlined":59200,"ai-outlined":59201,"alignment-2-outlined":59202,"alignment-outlined":59203,"all-caps":59204,"application-outlined":59205,"arrow-down":59206,"arrow-downwards":59207,"arrow-left":59208,"arrow-leftwards":59209,"arrow-right":59210,"arrow-rightwards":59211,"arrow-up":59212,"arrow-upwards":59213,"article-outlined":59214,"at-sign":59215,"auto-graph-outlined":59216,"automotive-outlined":59217,"bakery-outlined":59218,"bar-outlined":59219,"beauty-outlined":59220,"beer-outlined":59221,"bell-active-outlined":59222,"bell-outlined":59223,"bell-slash-outlined":59224,"bill-management-outlined":59225,"billing-outlined":59226,"body-outlined":59227,"bold":59228,"bolt-outlined":59229,"book-outlined":59230,"bookmark-added-outlined":59231,"bookmark-checked-outlined":59232,"bookmark-outlined":59233,"box-1-outlined":59234,"box-check-outlined":59235,"box-outlined":59236,"bullet-points":59237,"cake-outlined":59238,"calculator-outlined":59239,"calendar-dates-outlined":59240,"calendar-star-outlined":59241,"call-outlined":59242,"call-split-outlined":59243,"camera-outlined":59244,"cancel":59245,"car-forward-outlined":59246,"cashback-outlined":59247,"charging-station-outlined":59248,"chat-bubble-outlined":59249,"chat-unread-outlined":59250,"checkmark":59251,"circle-add-outlined":59252,"circle-cancel-outlined":59253,"circle-down-outlined":59254,"circle-info-outlined":59255,"circle-left-outlined":59256,"circle-ok-outlined":59257,"circle-question-outlined":59258,"circle-remove-outlined":59259,"circle-right-outlined":59260,"circle-up-outlined":59261,"circle-warning-outlined":59262,"clock-2-outlined":59263,"clock-in-outlined":59264,"clock-out-outlined":59265,"clock-outlined":59266,"cog-outlined":59267,"coin-outlined":59268,"coin-super-outlined":59269,"comment-outlined":59270,"contacts-outlined":59271,"contacts-user-outlined":59272,"credit-card-outlined":59273,"cultural-site-outlined":59274,"cup-outlined":59275,"dentistry-outlined":59276,"direction-arrows-outlined":59277,"directory-outlined":59278,"document-outlined":59279,"dollar-box-outlined":59280,"dollar-card-outlined":59281,"dollar-coin-shine-outlined":59282,"dollar-credit-card-outlined":59283,"dollar-sign":59284,"double-buildings-outlined":59285,"double-left-arrows":59286,"double-right-arrows":59287,"download-box-outlined":59288,"download-outlined":59289,"edit-template-outlined":59290,"electronics-outlined":59291,"email-outlined":59292,"end-break-outlined":59293,"enter-arrow":59294,"entertainment-outlined":59295,"envelope-outlined":59296,"evening-outlined":59297,"expense-approval-outlined":59298,"expense-outlined":59299,"explore-outlined":59300,"extension-outlined":59301,"external-link":59302,"eye-invisible-outlined":59303,"eye-outlined":59304,"face-id":59305,"face-meh-outlined":59306,"face-open-smiley-outlined":59307,"face-sad-outlined":59308,"face-smiley-outlined":59309,"fastfood-outlined":59310,"feed-outlined":59311,"file-certified-outlined":59312,"file-clone-outlined":59313,"file-copy-outlined":59314,"file-dispose-outlined":59315,"file-dollar-certified-outlined":59316,"file-dollar-outlined":59317,"file-download-outlined":59318,"file-export-outlined":59319,"file-lock-outlined":59320,"file-outlined":59321,"file-search-outlined":59322,"file-secured-outlined":59323,"file-statutory-outlined":59324,"file-verified-outlined":59325,"filter-outlined":59326,"fitness-outlined":59327,"folder-outlined":59328,"folder-upload-outlined":59329,"folder-user-outlined":59330,"form-outlined":59331,"funnel-filter-outline":59332,"goal-outlined":59333,"graph-outlined":59334,"grocery-outlined":59335,"hand-holding-user-outlined":59336,"handshake-outlined":59337,"happy-sun-outlined":59338,"health-bag-outlined":59339,"heart-outlined":59340,"home-active-outlined":59341,"home-outlined":59342,"id-card-outlined":59343,"image-outlined":59344,"import-outlined":59345,"instapay-outlined":59346,"italic":59347,"job-search-outlined":59348,"leave-approval-outlined":59349,"link-1":59350,"link-2":59351,"list-outlined":59352,"live-help-outlined":59353,"local_mall_outlined":59354,"location-on-outlined":59355,"location-outlined":59356,"lock-outlined":59357,"locked-file-outlined":59358,"log-out":59359,"mail-outlined":59360,"map-outlined":59361,"media-content-outlined":59362,"menu-close":59363,"menu-expand":59364,"menu-fold-outlined":59365,"menu-unfold-outlined":59366,"moneybag-outlined":59367,"moon-outlined":59368,"more-horizontal":59369,"more-vertical":59370,"morning-outlined":59371,"multiple-folders-outlined":59372,"multiple-users-outlined":59373,"near-me-outlined":59374,"node-outlined":59375,"number-points":59376,"number":59377,"overview-outlined":59378,"park-outlined":59379,"payment-summary-outlined":59380,"payslip-outlined":59381,"pencil-outlined":59382,"percentage":59383,"phone-outlined":59384,"piggy-bank-outlined":59385,"plane-outlined":59386,"play-circle-outlined":59387,"print-outlined":59388,"propane-tank-outlined":59389,"qr-code-outlined":59390,"qualification-outlined":59391,"re-assign":59392,"redeem":59393,"refresh":59394,"remove":59395,"reply-outlined":59396,"restart":59397,"restaurant-outlined":59398,"resume-outlined":59399,"return-arrow":59400,"rostering-outlined":59401,"safety-outlined":59402,"save-outlined":59403,"schedule-outlined":59404,"search-outlined":59405,"search-secured-outlined":59406,"send-outlined":59407,"share-1":59408,"share-2":59409,"share-outlined-2":59410,"share-outlined":59411,"shield-check-outlined":59412,"shop-outlined":59413,"shopping_basket_outlined":59414,"show-chart-outlined":59415,"single-down-arrow":59416,"single-left-arrow":59417,"single-right-arrow":59418,"single-up-arrow":59419,"smart-match-outlined":59420,"sparkle-outlined":59421,"speaker-active-outlined":59422,"speaker-outlined":59423,"star-circle-outlined":59424,"star-outlined":59425,"start-break-outlined":59426,"stash-outlined":59427,"stopwatch-outlined":59428,"strikethrough":59429,"styler-outlined":59430,"suitcase-clock-outlined":59431,"suitcase-outlined":59432,"survey-outlined":59433,"switch-outlined":59434,"sync":59435,"tag-outlined":59436,"target-outlined":59437,"tennis-outlined":59438,"thumb-down-outlined":59439,"ticket-outlined":59440,"timesheet-outlined":59441,"timesheets-outlined":59442,"today-outlined":59443,"transfer":59444,"transportation-outlined":59445,"trash-bin-outlined":59446,"umbrela-outlined":59447,"unavailability-outlined":59448,"unavailable":59449,"underline":59450,"union-outlined":59451,"unlock-outlined":59452,"upload-outlined":59453,"user-circle-outlined":59454,"user-gear-outlined":59455,"user-outlined":59456,"user-rectangle-outlined":59457,"video-1-outlined":59458,"video-2-outlined":59459,"volunteer-outlined":59460,"wallet-outlined":59461,"wellness-outlined":59462}
|
|
1
|
+
{"activate":59000,"add-emoji":59001,"add-person":59002,"adjustment":59003,"alignment":59004,"antenna":59005,"archive":59006,"assignment-warning":59007,"bank":59008,"bell":59009,"billing":59010,"bolt":59011,"bookmark-added":59012,"bookmark-checked":59013,"bookmark":59014,"box-check":59015,"box":59016,"bpay":59017,"buildings":59018,"cake":59019,"calendar-clock":59020,"calendar":59021,"candy-box-menu":59022,"caret-down-small":59023,"caret-down":59024,"caret-left-small":59025,"caret-left":59026,"caret-right-small":59027,"caret-right":59028,"caret-up-small":59029,"caret-up":59030,"check-radio":59031,"circle-add":59032,"circle-cancel":59033,"circle-check":59034,"circle-down":59035,"circle-info":59036,"circle-left":59037,"circle-ok":59038,"circle-pencil":59039,"circle-question":59040,"circle-remove":59041,"circle-right":59042,"circle-up":59043,"circle-warning":59044,"clock-3":59045,"clock":59046,"cloud-download":59047,"cloud-upload":59048,"cog":59049,"coin":59050,"contacts":59051,"credit-card":59052,"diamond":59053,"direction-arrows":59054,"directory":59055,"document":59056,"dollar-coin-shine":59057,"dot":59058,"double-buildings":59059,"edit-template":59060,"envelope":59061,"exclude":59062,"expand-content":59063,"expense":59064,"explore_nearby":59065,"eye-circle":59066,"eye-invisible":59067,"eye":59068,"face-meh":59069,"face-sad":59070,"face-smiley":59071,"feed":59072,"feedbacks":59073,"file-certified":59074,"file-clone":59075,"file-copy":59076,"file-csv":59077,"file-dispose":59078,"file-doc":59079,"file-excel":59080,"file-export":59081,"file-lock":59082,"file-pdf":59083,"file-powerpoint":59084,"file-search":59085,"file-secured":59086,"file-sheets":59087,"file-slide":59088,"file-verified":59089,"file-word":59090,"file":59091,"filter":59092,"folder-user":59093,"folder":59094,"format-bold":59095,"format-heading1":59096,"format-heading2":59097,"format-italic":59098,"format-list-bulleted":59099,"format-list-numbered":59100,"format-underlined":59101,"funnel-filter":59102,"global-dollar":59103,"globe":59104,"graduation-cap":59105,"graph":59106,"happy-sun":59107,"health-bag":59108,"heart":59109,"hero-points":59110,"home":59111,"image":59112,"import":59113,"incident-siren":59114,"instapay-daily":59115,"instapay-now":59116,"instapay":59117,"list":59118,"loading-2":59119,"loading":59120,"location-on":59121,"location":59122,"lock":59123,"looks-one":59124,"looks-two":59125,"media-content":59126,"menu":59127,"money-notes":59128,"moneybag":59129,"moon":59130,"multiple-stars":59131,"multiple-users":59132,"near-me":59133,"node":59134,"open-folder":59135,"paperclip-vertical":59136,"paperclip":59137,"payment-summary":59138,"pencil":59139,"phone":59140,"piggy-bank":59141,"plane-up":59142,"plane":59143,"play-arrow":59144,"play-circle":59145,"print":59146,"raising-hands":59147,"reply-arrow":59148,"reply":59149,"reschedule":59150,"rostering":59151,"salary-sacrifice":59152,"save":59153,"schedule-send":59154,"schedule":59155,"search-person":59156,"search":59157,"send":59158,"speaker-active":59159,"speaker":59160,"star-award":59161,"star-badge":59162,"star-circle":59163,"star-medal":59164,"star":59165,"steps-circle":59166,"stopwatch":59167,"suitcase":59168,"surfing":59169,"survey":59170,"swag-pillar-benefit":59171,"swag-pillar-career":59172,"swag-pillar-money":59173,"swag-pillar-work":59174,"swag":59175,"swipe-right":59176,"switch":59177,"tag":59178,"target":59179,"teams":59180,"thumb-down":59181,"thumb-up":59182,"timesheet":59183,"touch-id":59184,"trash-bin":59185,"unlock":59186,"user":59187,"video-1":59188,"video-2":59189,"wallet":59190,"warning":59191,"academic-hat-outlined":59192,"accommodation-outlined":59193,"activate-outlined":59194,"add-credit-card-outlined":59195,"add-person-outlined":59196,"add-section-outlined":59197,"add-time-outlined":59198,"add":59199,"adjustment-outlined":59200,"afternoon-outlined":59201,"ai-outlined":59202,"alignment-2-outlined":59203,"alignment-outlined":59204,"all-caps":59205,"application-outlined":59206,"arrow-down":59207,"arrow-downwards":59208,"arrow-left":59209,"arrow-leftwards":59210,"arrow-right":59211,"arrow-rightwards":59212,"arrow-up":59213,"arrow-upwards":59214,"article-outlined":59215,"at-sign":59216,"auto-graph-outlined":59217,"automotive-outlined":59218,"bakery-outlined":59219,"bar-outlined":59220,"beauty-outlined":59221,"beer-outlined":59222,"bell-active-outlined":59223,"bell-outlined":59224,"bell-slash-outlined":59225,"bill-management-outlined":59226,"billing-outlined":59227,"body-outlined":59228,"bold":59229,"bolt-outlined":59230,"book-outlined":59231,"bookmark-added-outlined":59232,"bookmark-checked-outlined":59233,"bookmark-outlined":59234,"box-1-outlined":59235,"box-check-outlined":59236,"box-outlined":59237,"bullet-points":59238,"cake-outlined":59239,"calculator-outlined":59240,"calendar-dates-outlined":59241,"calendar-star-outlined":59242,"call-outlined":59243,"call-split-outlined":59244,"camera-outlined":59245,"cancel":59246,"car-forward-outlined":59247,"cashback-outlined":59248,"charging-station-outlined":59249,"chat-bubble-outlined":59250,"chat-unread-outlined":59251,"checkmark":59252,"circle-add-outlined":59253,"circle-cancel-outlined":59254,"circle-down-outlined":59255,"circle-info-outlined":59256,"circle-left-outlined":59257,"circle-ok-outlined":59258,"circle-question-outlined":59259,"circle-remove-outlined":59260,"circle-right-outlined":59261,"circle-up-outlined":59262,"circle-warning-outlined":59263,"clock-2-outlined":59264,"clock-in-outlined":59265,"clock-out-outlined":59266,"clock-outlined":59267,"cog-outlined":59268,"coin-outlined":59269,"coin-super-outlined":59270,"comment-outlined":59271,"contacts-outlined":59272,"contacts-user-outlined":59273,"credit-card-outlined":59274,"cultural-site-outlined":59275,"cup-outlined":59276,"dentistry-outlined":59277,"direction-arrows-outlined":59278,"directory-outlined":59279,"document-outlined":59280,"dollar-box-outlined":59281,"dollar-card-outlined":59282,"dollar-coin-shine-outlined":59283,"dollar-credit-card-outlined":59284,"dollar-sign":59285,"double-buildings-outlined":59286,"double-left-arrows":59287,"double-right-arrows":59288,"download-box-outlined":59289,"download-outlined":59290,"edit-template-outlined":59291,"electronics-outlined":59292,"email-outlined":59293,"end-break-outlined":59294,"enter-arrow":59295,"entertainment-outlined":59296,"envelope-outlined":59297,"evening-outlined":59298,"expense-approval-outlined":59299,"expense-outlined":59300,"explore-outlined":59301,"extension-outlined":59302,"external-link":59303,"eye-invisible-outlined":59304,"eye-outlined":59305,"face-id":59306,"face-meh-outlined":59307,"face-open-smiley-outlined":59308,"face-sad-outlined":59309,"face-smiley-outlined":59310,"fastfood-outlined":59311,"feed-outlined":59312,"file-certified-outlined":59313,"file-clone-outlined":59314,"file-copy-outlined":59315,"file-dispose-outlined":59316,"file-dollar-certified-outlined":59317,"file-dollar-outlined":59318,"file-download-outlined":59319,"file-export-outlined":59320,"file-lock-outlined":59321,"file-outlined":59322,"file-search-outlined":59323,"file-secured-outlined":59324,"file-statutory-outlined":59325,"file-verified-outlined":59326,"filter-outlined":59327,"fitness-outlined":59328,"folder-outlined":59329,"folder-upload-outlined":59330,"folder-user-outlined":59331,"form-outlined":59332,"funnel-filter-outline":59333,"goal-outlined":59334,"graph-outlined":59335,"grocery-outlined":59336,"hand-holding-user-outlined":59337,"handshake-outlined":59338,"happy-sun-outlined":59339,"health-bag-outlined":59340,"heart-outlined":59341,"home-active-outlined":59342,"home-outlined":59343,"id-card-outlined":59344,"image-outlined":59345,"import-outlined":59346,"instapay-outlined":59347,"italic":59348,"job-search-outlined":59349,"leave-approval-outlined":59350,"link-1":59351,"link-2":59352,"list-outlined":59353,"live-help-outlined":59354,"local_mall_outlined":59355,"location-on-outlined":59356,"location-outlined":59357,"lock-outlined":59358,"locked-file-outlined":59359,"log-out":59360,"mail-outlined":59361,"map-outlined":59362,"media-content-outlined":59363,"menu-close":59364,"menu-expand":59365,"menu-fold-outlined":59366,"menu-unfold-outlined":59367,"moneybag-outlined":59368,"moon-outlined":59369,"more-horizontal":59370,"more-vertical":59371,"morning-outlined":59372,"multiple-folders-outlined":59373,"multiple-users-outlined":59374,"near-me-outlined":59375,"node-outlined":59376,"number-points":59377,"number":59378,"overview-outlined":59379,"park-outlined":59380,"payment-summary-outlined":59381,"payslip-outlined":59382,"pencil-outlined":59383,"percentage":59384,"phone-outlined":59385,"piggy-bank-outlined":59386,"plane-outlined":59387,"play-circle-outlined":59388,"print-outlined":59389,"propane-tank-outlined":59390,"qr-code-outlined":59391,"qualification-outlined":59392,"re-assign":59393,"redeem":59394,"refresh":59395,"remove":59396,"reply-outlined":59397,"restart":59398,"restaurant-outlined":59399,"resume-outlined":59400,"return-arrow":59401,"rostering-outlined":59402,"safety-outlined":59403,"save-outlined":59404,"schedule-outlined":59405,"search-outlined":59406,"search-secured-outlined":59407,"send-outlined":59408,"share-1":59409,"share-2":59410,"share-outlined-2":59411,"share-outlined":59412,"shield-check-outlined":59413,"shop-outlined":59414,"shopping_basket_outlined":59415,"show-chart-outlined":59416,"single-down-arrow":59417,"single-left-arrow":59418,"single-right-arrow":59419,"single-up-arrow":59420,"smart-match-outlined":59421,"sparkle-outlined":59422,"speaker-active-outlined":59423,"speaker-outlined":59424,"star-circle-outlined":59425,"star-outlined":59426,"start-break-outlined":59427,"stash-outlined":59428,"stopwatch-outlined":59429,"strikethrough":59430,"styler-outlined":59431,"suitcase-clock-outlined":59432,"suitcase-outlined":59433,"survey-outlined":59434,"switch-outlined":59435,"sync":59436,"tag-outlined":59437,"target-outlined":59438,"tennis-outlined":59439,"thumb-down-outlined":59440,"thumb-up-outlined":59441,"ticket-outlined":59442,"timesheet-outlined":59443,"timesheets-outlined":59444,"today-outlined":59445,"transfer":59446,"transportation-outlined":59447,"trash-bin-outlined":59448,"umbrela-outlined":59449,"unavailability-outlined":59450,"unavailable":59451,"underline":59452,"union-outlined":59453,"unlock-outlined":59454,"upload-outlined":59455,"user-circle-outlined":59456,"user-gear-outlined":59457,"user-outlined":59458,"user-rectangle-outlined":59459,"video-1-outlined":59460,"video-2-outlined":59461,"volunteer-outlined":59462,"wallet-outlined":59463,"wellness-outlined":59464}
|
|
@@ -182,6 +182,7 @@ const IconList = [
|
|
|
182
182
|
'target',
|
|
183
183
|
'teams',
|
|
184
184
|
'thumb-down',
|
|
185
|
+
'thumb-up',
|
|
185
186
|
'timesheet',
|
|
186
187
|
'touch-id',
|
|
187
188
|
'trash-bin',
|
|
@@ -440,6 +441,7 @@ const IconList = [
|
|
|
440
441
|
'target-outlined',
|
|
441
442
|
'tennis-outlined',
|
|
442
443
|
'thumb-down-outlined',
|
|
444
|
+
'thumb-up-outlined',
|
|
443
445
|
'ticket-outlined',
|
|
444
446
|
'timesheet-outlined',
|
|
445
447
|
'timesheets-outlined',
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import React, { ComponentProps } from 'react';
|
|
2
|
+
import Badge from '../Badge';
|
|
3
|
+
import Icon from '../Icon';
|
|
4
|
+
import Typography from '../Typography';
|
|
5
|
+
import {
|
|
6
|
+
StyledSegmentedItem,
|
|
7
|
+
StyledSegmentedItemLabelWrapper,
|
|
8
|
+
StyledSegmentedItemText,
|
|
9
|
+
StyledSegmentedItemWrapper,
|
|
10
|
+
} from './StyledSegmentedControl';
|
|
11
|
+
import type {
|
|
12
|
+
CounterBadgeType,
|
|
13
|
+
SegmentedControlItemConfig,
|
|
14
|
+
StatusBadgeType,
|
|
15
|
+
} from './types';
|
|
16
|
+
import Box from '../Box';
|
|
17
|
+
|
|
18
|
+
const DOT_CHAR = '\u00B7';
|
|
19
|
+
type TypographyIntent = ComponentProps<typeof Typography.Body>['intent'];
|
|
20
|
+
type IconIntent = ComponentProps<typeof Icon>['intent'];
|
|
21
|
+
|
|
22
|
+
export interface SegmentedItemProps extends SegmentedControlItemConfig {
|
|
23
|
+
/**
|
|
24
|
+
* Whether the segment option is selected.
|
|
25
|
+
*/
|
|
26
|
+
selected?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The size of the segment option.
|
|
29
|
+
*/
|
|
30
|
+
size?: 'medium' | 'large';
|
|
31
|
+
/**
|
|
32
|
+
* The callback function to be called when the segment option is pressed.
|
|
33
|
+
*/
|
|
34
|
+
onPress: () => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const SegmentedItemBadge = ({
|
|
38
|
+
children,
|
|
39
|
+
badge,
|
|
40
|
+
testID,
|
|
41
|
+
}: {
|
|
42
|
+
children?: React.ReactNode;
|
|
43
|
+
badge?: StatusBadgeType | CounterBadgeType;
|
|
44
|
+
testID?: string;
|
|
45
|
+
}) => {
|
|
46
|
+
if (!badge) return children;
|
|
47
|
+
|
|
48
|
+
if (badge.type === 'status') {
|
|
49
|
+
return (
|
|
50
|
+
<Badge.Status visible testID={testID}>
|
|
51
|
+
<Box marginEnd="smallMedium">{children}</Box>
|
|
52
|
+
</Badge.Status>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (badge.type === 'counter') {
|
|
57
|
+
return (
|
|
58
|
+
<>
|
|
59
|
+
<Box marginEnd="xsmall">{children}</Box>
|
|
60
|
+
<Badge
|
|
61
|
+
visible
|
|
62
|
+
content={badge.value}
|
|
63
|
+
max={badge.max}
|
|
64
|
+
testID={testID}
|
|
65
|
+
size="small"
|
|
66
|
+
/>
|
|
67
|
+
</>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const getTextAndIconIntent = ({
|
|
73
|
+
selected,
|
|
74
|
+
disabled,
|
|
75
|
+
}: {
|
|
76
|
+
selected?: boolean;
|
|
77
|
+
disabled?: boolean;
|
|
78
|
+
}): {
|
|
79
|
+
iconIntent: IconIntent;
|
|
80
|
+
textIntent: TypographyIntent;
|
|
81
|
+
subTextIntent: TypographyIntent;
|
|
82
|
+
} => {
|
|
83
|
+
if (disabled) {
|
|
84
|
+
return {
|
|
85
|
+
iconIntent: 'disabled-text',
|
|
86
|
+
textIntent: 'disabled',
|
|
87
|
+
subTextIntent: 'disabled',
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (selected) {
|
|
92
|
+
return {
|
|
93
|
+
iconIntent: 'text',
|
|
94
|
+
textIntent: 'body',
|
|
95
|
+
subTextIntent: 'muted',
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
iconIntent: 'inactive',
|
|
101
|
+
textIntent: 'inactive',
|
|
102
|
+
subTextIntent: 'inactive',
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const SegmentedItem = ({
|
|
107
|
+
label,
|
|
108
|
+
prefix,
|
|
109
|
+
suffix,
|
|
110
|
+
selected = false,
|
|
111
|
+
size = 'medium',
|
|
112
|
+
testID,
|
|
113
|
+
onPress,
|
|
114
|
+
disabled,
|
|
115
|
+
badge,
|
|
116
|
+
subText,
|
|
117
|
+
}: SegmentedItemProps) => {
|
|
118
|
+
const { iconIntent, textIntent, subTextIntent } = getTextAndIconIntent({
|
|
119
|
+
selected,
|
|
120
|
+
disabled,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const shouldShowSuffix = !!label && !!suffix;
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<StyledSegmentedItem
|
|
127
|
+
themeSize={size}
|
|
128
|
+
themeSelected={selected}
|
|
129
|
+
testID={testID}
|
|
130
|
+
onPress={onPress}
|
|
131
|
+
disabled={disabled}
|
|
132
|
+
>
|
|
133
|
+
<SegmentedItemBadge badge={badge} testID={`${testID}-badge`}>
|
|
134
|
+
<StyledSegmentedItemWrapper>
|
|
135
|
+
{/* Prefix */}
|
|
136
|
+
{prefix && (
|
|
137
|
+
<Icon
|
|
138
|
+
icon={prefix}
|
|
139
|
+
intent={iconIntent}
|
|
140
|
+
size="xxxsmall"
|
|
141
|
+
testID={`${testID}-prefix`}
|
|
142
|
+
/>
|
|
143
|
+
)}
|
|
144
|
+
|
|
145
|
+
{/* Label and subtext */}
|
|
146
|
+
|
|
147
|
+
{!!label && (
|
|
148
|
+
<StyledSegmentedItemLabelWrapper>
|
|
149
|
+
{label && (
|
|
150
|
+
<StyledSegmentedItemText
|
|
151
|
+
variant="small-bold"
|
|
152
|
+
intent={textIntent}
|
|
153
|
+
>
|
|
154
|
+
{label}
|
|
155
|
+
</StyledSegmentedItemText>
|
|
156
|
+
)}
|
|
157
|
+
|
|
158
|
+
{subText && (
|
|
159
|
+
<>
|
|
160
|
+
<StyledSegmentedItemText
|
|
161
|
+
variant="small"
|
|
162
|
+
intent={subTextIntent}
|
|
163
|
+
>
|
|
164
|
+
{DOT_CHAR}
|
|
165
|
+
</StyledSegmentedItemText>
|
|
166
|
+
<StyledSegmentedItemText
|
|
167
|
+
variant="small"
|
|
168
|
+
intent={subTextIntent}
|
|
169
|
+
>
|
|
170
|
+
{subText}
|
|
171
|
+
</StyledSegmentedItemText>
|
|
172
|
+
</>
|
|
173
|
+
)}
|
|
174
|
+
</StyledSegmentedItemLabelWrapper>
|
|
175
|
+
)}
|
|
176
|
+
|
|
177
|
+
{/* Suffix, only shown if there is a label and suffix */}
|
|
178
|
+
{shouldShowSuffix && (
|
|
179
|
+
<Icon
|
|
180
|
+
icon={suffix}
|
|
181
|
+
intent={iconIntent}
|
|
182
|
+
size="xxxsmall"
|
|
183
|
+
testID={`${testID}-suffix`}
|
|
184
|
+
/>
|
|
185
|
+
)}
|
|
186
|
+
</StyledSegmentedItemWrapper>
|
|
187
|
+
</SegmentedItemBadge>
|
|
188
|
+
</StyledSegmentedItem>
|
|
189
|
+
);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export default SegmentedItem;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import styled from '@emotion/native';
|
|
2
|
+
import { TouchableOpacity } from 'react-native';
|
|
3
|
+
import Box from '../Box';
|
|
4
|
+
import Typography from '../Typography';
|
|
5
|
+
|
|
6
|
+
const StyledSegmentedControlWrapper = styled(Box)<{
|
|
7
|
+
themeSize: 'medium' | 'large';
|
|
8
|
+
}>(({ themeSize, theme }) => ({
|
|
9
|
+
flexDirection: 'row',
|
|
10
|
+
alignItems: 'center',
|
|
11
|
+
justifyContent: 'center',
|
|
12
|
+
height: theme.__hd__.segmentedControl.sizes.wrapperHeight[themeSize],
|
|
13
|
+
borderRadius: theme.__hd__.segmentedControl.radii.wrapper[themeSize],
|
|
14
|
+
backgroundColor: theme.__hd__.segmentedControl.colors.wrapperBackground,
|
|
15
|
+
alignSelf: 'flex-start',
|
|
16
|
+
paddingHorizontal:
|
|
17
|
+
theme.__hd__.segmentedControl.space.wrapperHorizontalPadding,
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
const StyledSegmentedItem = styled(TouchableOpacity)<{
|
|
21
|
+
themeSize: 'medium' | 'large';
|
|
22
|
+
themeSelected: boolean;
|
|
23
|
+
}>(({ themeSize, theme, themeSelected }) => ({
|
|
24
|
+
flexGrow: 1,
|
|
25
|
+
flexDirection: 'row',
|
|
26
|
+
alignItems: 'center',
|
|
27
|
+
justifyContent: 'center',
|
|
28
|
+
height: theme.__hd__.segmentedControl.sizes.itemHeight[themeSize],
|
|
29
|
+
borderRadius: theme.__hd__.segmentedControl.radii.item[themeSize],
|
|
30
|
+
backgroundColor: themeSelected
|
|
31
|
+
? theme.__hd__.segmentedControl.colors.itemBackground.active
|
|
32
|
+
: theme.__hd__.segmentedControl.colors.itemBackground.inactive,
|
|
33
|
+
...theme.__hd__.segmentedControl.shadows.item[
|
|
34
|
+
themeSelected ? 'active' : 'inactive'
|
|
35
|
+
],
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
const StyledSegmentedItemWrapper = styled(Box)(({ theme }) => ({
|
|
39
|
+
flexDirection: 'row',
|
|
40
|
+
alignItems: 'center',
|
|
41
|
+
justifyContent: 'center',
|
|
42
|
+
gap: theme.__hd__.segmentedControl.space.itemAffixGap,
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
const StyledSegmentedItemLabelWrapper = styled(Box)(({ theme }) => ({
|
|
46
|
+
flexDirection: 'row',
|
|
47
|
+
alignItems: 'center',
|
|
48
|
+
justifyContent: 'center',
|
|
49
|
+
gap: theme.__hd__.segmentedControl.space.itemLabelGap,
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
const StyledSegmentedItemText = styled(Typography.Body)(({ theme }) => ({
|
|
53
|
+
lineHeight: theme.__hd__.segmentedControl.lineHeights.itemText,
|
|
54
|
+
}));
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
StyledSegmentedControlWrapper,
|
|
58
|
+
StyledSegmentedItem,
|
|
59
|
+
StyledSegmentedItemLabelWrapper,
|
|
60
|
+
StyledSegmentedItemText,
|
|
61
|
+
StyledSegmentedItemWrapper,
|
|
62
|
+
};
|