@tecsinapse/react-core 1.9.0 → 1.10.3
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/CHANGELOG.md +47 -0
- package/dist/components/atoms/Avatar/styled.js +0 -3
- package/dist/components/atoms/Avatar/styled.js.map +1 -1
- package/dist/components/atoms/BoxContent/styled.d.ts +10 -1
- package/dist/components/atoms/BoxContent/styled.js.map +1 -1
- package/dist/components/atoms/Button/States/Error.js +2 -2
- package/dist/components/atoms/Button/States/Error.js.map +1 -1
- package/dist/components/atoms/Button/States/Success.js +2 -2
- package/dist/components/atoms/Button/States/Success.js.map +1 -1
- package/dist/components/atoms/GroupButton/GroupButton.d.ts +2 -1
- package/dist/components/atoms/GroupButton/GroupButton.js +3 -2
- package/dist/components/atoms/GroupButton/GroupButton.js.map +1 -1
- package/dist/components/atoms/GroupButton/GroupButtonOption.d.ts +2 -2
- package/dist/components/atoms/GroupButton/GroupButtonOption.js.map +1 -1
- package/dist/components/atoms/GroupButton/styled.d.ts +1 -1
- package/dist/components/atoms/GroupButton/styled.js +8 -0
- package/dist/components/atoms/GroupButton/styled.js.map +1 -1
- package/dist/components/atoms/Input/InputElement/InputElement.d.ts +5 -4
- package/dist/components/atoms/Input/InputElement/InputElement.js +5 -3
- package/dist/components/atoms/Input/InputElement/InputElement.js.map +1 -1
- package/dist/components/atoms/Input/hooks/useCurrencyMask.d.ts +2 -2
- package/dist/components/atoms/Input/hooks/useCurrencyMask.js.map +1 -1
- package/dist/components/atoms/Input/hooks/useMask.d.ts +5 -5
- package/dist/components/atoms/Input/hooks/useMask.js +1 -1
- package/dist/components/atoms/Input/hooks/useMask.js.map +1 -1
- package/dist/components/atoms/Input/masks/index.js +1 -1
- package/dist/components/atoms/Input/masks/index.js.map +1 -1
- package/dist/components/atoms/Switch/Switch.d.ts +1 -0
- package/dist/components/atoms/Switch/Switch.js +10 -4
- package/dist/components/atoms/Switch/Switch.js.map +1 -1
- package/dist/components/atoms/Switch/animation.d.ts +2 -1
- package/dist/components/atoms/Switch/animation.js.map +1 -1
- package/dist/components/atoms/Tag/Tag.js +2 -2
- package/dist/components/atoms/Tag/Tag.js.map +1 -1
- package/dist/components/molecules/Calendar/Calendar.d.ts +1 -1
- package/dist/components/molecules/Calendar/Calendar.js +35 -156
- package/dist/components/molecules/Calendar/Calendar.js.map +1 -1
- package/dist/components/molecules/Calendar/components/MonthWeek.d.ts +13 -0
- package/dist/components/molecules/Calendar/components/MonthWeek.js +152 -0
- package/dist/components/molecules/Calendar/components/MonthWeek.js.map +1 -0
- package/dist/components/molecules/Calendar/components/Weekdays.d.ts +8 -0
- package/dist/components/molecules/Calendar/components/Weekdays.js +41 -0
- package/dist/components/molecules/Calendar/components/Weekdays.js.map +1 -0
- package/dist/components/molecules/Calendar/components/index.d.ts +2 -0
- package/dist/components/molecules/Calendar/components/index.js +24 -0
- package/dist/components/molecules/Calendar/components/index.js.map +1 -0
- package/dist/components/molecules/DatePicker/Modal.js.map +1 -1
- package/dist/components/molecules/DatePicker/styled.d.ts +4 -25
- package/dist/components/molecules/DatePicker/styled.js.map +1 -1
- package/dist/components/molecules/HintInputContainer/HintInputContainer.d.ts +1 -2
- package/dist/components/molecules/HintInputContainer/HintInputContainer.js.map +1 -1
- package/dist/hooks/useTheme.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/extractNumbersFromString.d.ts +1 -0
- package/dist/utils/extractNumbersFromString.js +5 -1
- package/dist/utils/extractNumbersFromString.js.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +6 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/lightenDarkenColor.js +5 -5
- package/dist/utils/lightenDarkenColor.js.map +1 -1
- package/package.json +2 -2
- package/src/components/atoms/Avatar/styled.ts +0 -1
- package/src/components/atoms/BoxContent/styled.ts +1 -1
- package/src/components/atoms/Button/States/Error.tsx +1 -1
- package/src/components/atoms/Button/States/Success.tsx +1 -1
- package/src/components/atoms/GroupButton/GroupButton.tsx +6 -4
- package/src/components/atoms/GroupButton/GroupButtonOption.tsx +3 -3
- package/src/components/atoms/GroupButton/styled.ts +13 -1
- package/src/components/atoms/Input/InputElement/InputElement.tsx +36 -27
- package/src/components/atoms/Input/hooks/useCurrencyMask.ts +4 -5
- package/src/components/atoms/Input/hooks/useMask.ts +10 -9
- package/src/components/atoms/Input/masks/index.ts +1 -1
- package/src/components/atoms/Switch/Switch.stories.tsx +2 -1
- package/src/components/atoms/Switch/Switch.tsx +17 -6
- package/src/components/atoms/Switch/animation.ts +5 -1
- package/src/components/atoms/Tag/Tag.tsx +2 -2
- package/src/components/molecules/Calendar/Calendar.tsx +60 -162
- package/src/components/molecules/Calendar/components/MonthWeek.tsx +144 -0
- package/src/components/molecules/Calendar/components/Weekdays.tsx +34 -0
- package/src/components/molecules/Calendar/components/index.ts +2 -0
- package/src/components/molecules/DatePicker/Modal.tsx +1 -1
- package/src/components/molecules/DatePicker/styled.ts +1 -2
- package/src/components/molecules/HintInputContainer/HintInputContainer.tsx +1 -2
- package/src/hooks/useTheme.ts +1 -1
- package/src/index.ts +2 -0
- package/src/utils/extractNumbersFromString.ts +6 -0
- package/src/utils/index.ts +4 -1
- package/src/utils/lightenDarkenColor.ts +5 -5
|
@@ -15,7 +15,7 @@ const Template: Story<SwitchProps> = args => {
|
|
|
15
15
|
args.onChange(arg);
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
return <Switch active={active} onChange={onChange} />;
|
|
18
|
+
return <Switch active={active} onChange={onChange} disabled={args.disabled}/>;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
export const Base = Template.bind({});
|
|
@@ -23,4 +23,5 @@ export const Base = Template.bind({});
|
|
|
23
23
|
Base.args = {
|
|
24
24
|
active: true,
|
|
25
25
|
onChange: value => action('Cicked')(value),
|
|
26
|
+
disabled: false,
|
|
26
27
|
};
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import { PressableSurface } from '../PressableSurface';
|
|
10
10
|
import { StyledSwitch } from './styled';
|
|
11
11
|
import { transitionSwitch } from './animation';
|
|
12
|
-
import { extractNumbersFromString } from '../../../utils';
|
|
12
|
+
import { extractNumbersFromString, lightenDarkenColor } from '../../../utils';
|
|
13
13
|
|
|
14
14
|
export interface SwitchProps {
|
|
15
15
|
onChange: (active: boolean) => void;
|
|
@@ -20,6 +20,7 @@ export interface SwitchProps {
|
|
|
20
20
|
inactiveColorTone?: ColorGradationType;
|
|
21
21
|
style?: StyleProp<ViewStyle>;
|
|
22
22
|
dotStyle?: StyleProp<ViewStyle>;
|
|
23
|
+
disabled?: boolean;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
const Switch: FC<SwitchProps> = ({
|
|
@@ -30,6 +31,7 @@ const Switch: FC<SwitchProps> = ({
|
|
|
30
31
|
inactiveColorTone = 'light',
|
|
31
32
|
active,
|
|
32
33
|
dotStyle,
|
|
34
|
+
disabled = false,
|
|
33
35
|
...rest
|
|
34
36
|
}): JSX.Element => {
|
|
35
37
|
const theme = useTheme() as ThemeProp;
|
|
@@ -40,11 +42,15 @@ const Switch: FC<SwitchProps> = ({
|
|
|
40
42
|
const animatedColor = React.useRef(new Animated.Value(active ? 1 : 0))
|
|
41
43
|
.current;
|
|
42
44
|
|
|
45
|
+
const getBackgroundColor = (color: string, variation: number) => {
|
|
46
|
+
return disabled ? lightenDarkenColor(color, variation) : color;
|
|
47
|
+
};
|
|
48
|
+
|
|
43
49
|
const interpolateColor = animatedColor.interpolate({
|
|
44
50
|
inputRange: [0, 1],
|
|
45
51
|
outputRange: [
|
|
46
|
-
theme.color[inactiveColor][inactiveColorTone],
|
|
47
|
-
theme.color[activeColor][activeColorTone],
|
|
52
|
+
getBackgroundColor(theme.color[inactiveColor][inactiveColorTone], 25),
|
|
53
|
+
getBackgroundColor(theme.color[activeColor][activeColorTone], 50),
|
|
48
54
|
],
|
|
49
55
|
});
|
|
50
56
|
|
|
@@ -57,7 +63,7 @@ const Switch: FC<SwitchProps> = ({
|
|
|
57
63
|
transitionSwitch(active, transitionValue, animatedColor);
|
|
58
64
|
}, [active, onChange]);
|
|
59
65
|
|
|
60
|
-
const
|
|
66
|
+
const stylesDefault: ViewStyle = {
|
|
61
67
|
borderRadius: extractNumbersFromString(theme.borderRadius.pill),
|
|
62
68
|
paddingHorizontal: extractNumbersFromString(theme.spacing.micro),
|
|
63
69
|
paddingVertical: 0,
|
|
@@ -67,8 +73,13 @@ const Switch: FC<SwitchProps> = ({
|
|
|
67
73
|
};
|
|
68
74
|
|
|
69
75
|
return (
|
|
70
|
-
<PressableSurface
|
|
71
|
-
|
|
76
|
+
<PressableSurface
|
|
77
|
+
{...rest}
|
|
78
|
+
onPress={handleChange}
|
|
79
|
+
effect="none"
|
|
80
|
+
disabled={disabled}
|
|
81
|
+
>
|
|
82
|
+
<Animated.View style={{ ...animatedStyle, ...stylesDefault }}>
|
|
72
83
|
<StyledSwitch
|
|
73
84
|
style={[dotStyle, { transform: [{ translateX: transitionValue }] }]}
|
|
74
85
|
/>
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Animated } from 'react-native';
|
|
2
2
|
|
|
3
|
-
export const transitionSwitch = (
|
|
3
|
+
export const transitionSwitch = (
|
|
4
|
+
active: boolean,
|
|
5
|
+
transitionValue: Animated.Value,
|
|
6
|
+
animatedColor: Animated.Value
|
|
7
|
+
): void => {
|
|
4
8
|
if (active) {
|
|
5
9
|
Animated.timing(transitionValue, {
|
|
6
10
|
toValue: 0,
|
|
@@ -17,7 +17,7 @@ const Tag: React.FC<TagProps> = ({
|
|
|
17
17
|
icon,
|
|
18
18
|
variant = 'small',
|
|
19
19
|
dismiss: canDismiss = false,
|
|
20
|
-
onDismiss
|
|
20
|
+
onDismiss,
|
|
21
21
|
style,
|
|
22
22
|
...rest
|
|
23
23
|
}): JSX.Element => {
|
|
@@ -34,7 +34,7 @@ const Tag: React.FC<TagProps> = ({
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
const handleDismiss = useCallback(() => {
|
|
37
|
-
onDismiss();
|
|
37
|
+
onDismiss?.();
|
|
38
38
|
fadeOut();
|
|
39
39
|
setTimeout(() => setDismiss(true), duration);
|
|
40
40
|
}, [onDismiss]);
|
|
@@ -1,31 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
add,
|
|
3
|
-
compareAsc as compare,
|
|
4
|
-
differenceInDays,
|
|
5
|
-
format,
|
|
6
|
-
getWeeksInMonth,
|
|
7
|
-
isSameDay,
|
|
8
|
-
set,
|
|
9
|
-
} from 'date-fns';
|
|
1
|
+
import { add, format, getWeeksInMonth, set } from 'date-fns';
|
|
10
2
|
import * as React from 'react';
|
|
11
3
|
import { View, ViewProps } from 'react-native';
|
|
12
4
|
import { Icon } from '../../atoms/Icon';
|
|
13
5
|
import { Text, TextProps } from '../../atoms/Text';
|
|
14
6
|
import {
|
|
15
|
-
Cell,
|
|
16
7
|
Content,
|
|
17
8
|
Control,
|
|
18
9
|
getCapitalizedTextComponent,
|
|
19
|
-
Selected,
|
|
20
10
|
TitleContainer,
|
|
21
|
-
Week,
|
|
22
11
|
} from './styled';
|
|
12
|
+
import { Weekdays, MonthWeek } from './components';
|
|
23
13
|
|
|
24
14
|
export type SelectionType = 'range' | 'day';
|
|
25
15
|
|
|
26
16
|
export type DateRange = { lowest: Date; highest?: Date };
|
|
27
17
|
|
|
28
|
-
type Value<T extends SelectionType> = T extends 'range'
|
|
18
|
+
export type Value<T extends SelectionType> = T extends 'range'
|
|
19
|
+
? DateRange
|
|
20
|
+
: Date;
|
|
29
21
|
|
|
30
22
|
export interface CalendarProps<T extends SelectionType> extends ViewProps {
|
|
31
23
|
TextComponent?: React.FC<TextProps>;
|
|
@@ -59,104 +51,59 @@ function Calendar<T extends SelectionType>({
|
|
|
59
51
|
locale,
|
|
60
52
|
...rest
|
|
61
53
|
}: CalendarProps<T>): JSX.Element {
|
|
62
|
-
const _referenceDate =
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
54
|
+
const _referenceDate = React.useMemo(
|
|
55
|
+
() =>
|
|
56
|
+
_year && _month
|
|
57
|
+
? new Date(_year, _month, 1, 0, 0, 0, 0)
|
|
58
|
+
: _month
|
|
59
|
+
? new Date(now.getFullYear(), _month, 1, 0, 0, 0, 0)
|
|
60
|
+
: now,
|
|
61
|
+
[_year, _month]
|
|
62
|
+
);
|
|
68
63
|
|
|
69
64
|
const [referenceDate, setReferenceDate] = React.useState(_referenceDate);
|
|
70
65
|
|
|
71
|
-
const startingWeekDay =
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
const startingWeekDay = React.useMemo(
|
|
67
|
+
() =>
|
|
68
|
+
dayOfWeekFromWeekStart(
|
|
69
|
+
referenceDate.getDay(),
|
|
70
|
+
locale?.options?.weekStartsOn ?? 0
|
|
71
|
+
),
|
|
72
|
+
[referenceDate, locale]
|
|
74
73
|
);
|
|
75
74
|
|
|
76
|
-
const weeksInMonth =
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const calendar = [...Array(weeksInMonth).keys()].map(week =>
|
|
83
|
-
[...Array(7).keys()].map(weekDayIndex =>
|
|
84
|
-
add(referenceDate, {
|
|
85
|
-
days: 6 * week + week + weekDayIndex - startingWeekDay,
|
|
86
|
-
})
|
|
87
|
-
)
|
|
75
|
+
const weeksInMonth = React.useMemo(
|
|
76
|
+
() =>
|
|
77
|
+
getWeeksInMonth(referenceDate, {
|
|
78
|
+
weekStartsOn: locale?.options?.weekStartsOn ?? 0,
|
|
79
|
+
}),
|
|
80
|
+
[referenceDate, locale]
|
|
88
81
|
);
|
|
89
82
|
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (!highest) return false;
|
|
95
|
-
return compare(lowest, date) <= 0 && compare(highest, date) >= 0;
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const checkIfIsSelected = (date: Date) => {
|
|
100
|
-
if (!value) return false;
|
|
101
|
-
else if (type === 'range' && value) {
|
|
102
|
-
const { lowest, highest } = value as DateRange;
|
|
103
|
-
return (
|
|
104
|
-
isSameDay(lowest, date) || (highest ? isSameDay(highest, date) : false)
|
|
105
|
-
);
|
|
106
|
-
} else {
|
|
107
|
-
return isSameDay(value as Date, date);
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const handlePressCell = (date: Date) => () => {
|
|
112
|
-
if (type === 'day') {
|
|
113
|
-
onChange?.(date as never);
|
|
114
|
-
} else if (!value) {
|
|
115
|
-
onChange?.({ lowest: date } as never);
|
|
116
|
-
} else {
|
|
117
|
-
let newValue;
|
|
118
|
-
const { lowest, highest } = value as DateRange;
|
|
119
|
-
|
|
120
|
-
if (!highest) {
|
|
121
|
-
if (compare(date, lowest) === -1) {
|
|
122
|
-
newValue = { lowest: date, highest: lowest };
|
|
123
|
-
} else if (compare(date, lowest) === 0) {
|
|
124
|
-
newValue = undefined;
|
|
125
|
-
} else {
|
|
126
|
-
newValue = { lowest: lowest, highest: date };
|
|
127
|
-
}
|
|
128
|
-
} else {
|
|
129
|
-
if (compare(date, lowest) === -1) {
|
|
130
|
-
newValue = { lowest: date, highest: highest };
|
|
131
|
-
} else if (compare(date, lowest) === 0) {
|
|
132
|
-
newValue = { lowest: highest, highest: undefined };
|
|
133
|
-
} else {
|
|
134
|
-
if (compare(date, highest) === -1) {
|
|
135
|
-
const lowestDiff = Math.abs(differenceInDays(date, lowest));
|
|
136
|
-
const highestDiff = Math.abs(differenceInDays(date, highest));
|
|
137
|
-
newValue = {
|
|
138
|
-
lowest: lowestDiff < highestDiff ? date : lowest,
|
|
139
|
-
highest: highestDiff <= lowestDiff ? date : highest,
|
|
140
|
-
};
|
|
141
|
-
} else if (compare(date, highest) === 0) {
|
|
142
|
-
newValue = { lowest: lowest, highest: undefined };
|
|
143
|
-
} else {
|
|
144
|
-
newValue = { lowest: lowest, highest: date };
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
83
|
+
const Capitalized = React.useMemo(
|
|
84
|
+
() => getCapitalizedTextComponent(TextComponent),
|
|
85
|
+
[TextComponent]
|
|
86
|
+
);
|
|
148
87
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
88
|
+
const calendar = React.useMemo(
|
|
89
|
+
() =>
|
|
90
|
+
[...Array(weeksInMonth).keys()].map(week =>
|
|
91
|
+
[...Array(7).keys()].map(weekDayIndex =>
|
|
92
|
+
add(referenceDate, {
|
|
93
|
+
days: 6 * week + week + weekDayIndex - startingWeekDay,
|
|
94
|
+
})
|
|
95
|
+
)
|
|
96
|
+
),
|
|
97
|
+
[weeksInMonth, startingWeekDay, referenceDate]
|
|
98
|
+
);
|
|
152
99
|
|
|
153
|
-
const handlePressNext = () => {
|
|
100
|
+
const handlePressNext = React.useCallback(() => {
|
|
154
101
|
setReferenceDate(add(referenceDate, { months: 1 }));
|
|
155
|
-
};
|
|
102
|
+
}, [referenceDate, setReferenceDate]);
|
|
156
103
|
|
|
157
|
-
const handlePressPrev = () => {
|
|
104
|
+
const handlePressPrev = React.useCallback(() => {
|
|
158
105
|
setReferenceDate(add(referenceDate, { months: -1 }));
|
|
159
|
-
};
|
|
106
|
+
}, [referenceDate, setReferenceDate]);
|
|
160
107
|
|
|
161
108
|
return (
|
|
162
109
|
<View {...rest}>
|
|
@@ -188,70 +135,21 @@ function Calendar<T extends SelectionType>({
|
|
|
188
135
|
</Control>
|
|
189
136
|
</TitleContainer>
|
|
190
137
|
<Content>
|
|
191
|
-
<
|
|
192
|
-
{
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
highlighted={false}
|
|
197
|
-
isLineEnd={false}
|
|
198
|
-
isLineStart={false}
|
|
199
|
-
isRangeStart={false}
|
|
200
|
-
isRangeEnd={false}
|
|
201
|
-
pointerEvents={'none'}
|
|
202
|
-
>
|
|
203
|
-
<Capitalized colorVariant={'secondary'} colorTone={'medium'}>
|
|
204
|
-
{format(date, 'EEE', { locale }).slice(0, 3)}
|
|
205
|
-
</Capitalized>
|
|
206
|
-
</Cell>
|
|
207
|
-
))}
|
|
208
|
-
</Week>
|
|
138
|
+
<Weekdays
|
|
139
|
+
locale={locale}
|
|
140
|
+
calendar={calendar}
|
|
141
|
+
Capitalized={Capitalized}
|
|
142
|
+
/>
|
|
209
143
|
{calendar.map((week, index) => (
|
|
210
|
-
<
|
|
211
|
-
{week
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
isRangeStart = highest && isSameDay(lowest, date);
|
|
220
|
-
isRangeEnd = !!highest && isSameDay(highest, date);
|
|
221
|
-
} else {
|
|
222
|
-
isRangeStart = false;
|
|
223
|
-
isRangeEnd = false;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const colorTone = isSelected
|
|
227
|
-
? 'xlight'
|
|
228
|
-
: date.getMonth() === referenceDate.getMonth()
|
|
229
|
-
? 'xdark'
|
|
230
|
-
: 'light';
|
|
231
|
-
|
|
232
|
-
return (
|
|
233
|
-
<Cell
|
|
234
|
-
key={date.getDate()}
|
|
235
|
-
selected={isSelected}
|
|
236
|
-
highlighted={isBetween}
|
|
237
|
-
isLineEnd={index === 6}
|
|
238
|
-
isLineStart={index === 0}
|
|
239
|
-
isRangeStart={isRangeStart}
|
|
240
|
-
isRangeEnd={isRangeEnd}
|
|
241
|
-
onPress={handlePressCell(date)}
|
|
242
|
-
>
|
|
243
|
-
<Selected selected={isSelected} pointerEvents={'none'}>
|
|
244
|
-
<TextComponent
|
|
245
|
-
colorVariant={'secondary'}
|
|
246
|
-
colorTone={colorTone}
|
|
247
|
-
>
|
|
248
|
-
{date.getDate()}
|
|
249
|
-
</TextComponent>
|
|
250
|
-
</Selected>
|
|
251
|
-
</Cell>
|
|
252
|
-
);
|
|
253
|
-
})}
|
|
254
|
-
</Week>
|
|
144
|
+
<MonthWeek
|
|
145
|
+
week={week}
|
|
146
|
+
type={type}
|
|
147
|
+
value={value}
|
|
148
|
+
key={`week-${index}`}
|
|
149
|
+
onChange={onChange}
|
|
150
|
+
TextComponent={TextComponent}
|
|
151
|
+
referenceDate={referenceDate}
|
|
152
|
+
/>
|
|
255
153
|
))}
|
|
256
154
|
</Content>
|
|
257
155
|
</View>
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { compareAsc as compare, differenceInDays, isSameDay } from 'date-fns';
|
|
3
|
+
import { Cell, Selected, Week } from '../styled';
|
|
4
|
+
import { Value, DateRange, SelectionType } from '../Calendar';
|
|
5
|
+
import { TextProps } from '@tecsinapse/react-core';
|
|
6
|
+
|
|
7
|
+
interface IMonthWeek<T extends SelectionType> {
|
|
8
|
+
TextComponent: React.FC<TextProps>;
|
|
9
|
+
/** any as workaround for TS type mismatching */
|
|
10
|
+
onChange?: (value?: any) => void | never;
|
|
11
|
+
type?: T;
|
|
12
|
+
value?: Value<T>;
|
|
13
|
+
week: Date[];
|
|
14
|
+
referenceDate: Date;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const MonthWeek = <T extends SelectionType>({
|
|
18
|
+
week,
|
|
19
|
+
referenceDate,
|
|
20
|
+
type,
|
|
21
|
+
value,
|
|
22
|
+
TextComponent,
|
|
23
|
+
onChange,
|
|
24
|
+
}: IMonthWeek<T>) => {
|
|
25
|
+
const checkIfIsBetween = React.useCallback(
|
|
26
|
+
(date: Date, _value?: Value<T>) => {
|
|
27
|
+
if (type !== 'range' || !_value) return false;
|
|
28
|
+
else {
|
|
29
|
+
const { lowest, highest } = _value as DateRange;
|
|
30
|
+
if (!highest) return false;
|
|
31
|
+
return compare(lowest, date) <= 0 && compare(highest, date) >= 0;
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
[type]
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const checkIfIsSelected = React.useCallback(
|
|
38
|
+
(date: Date, _value?: Value<T>) => {
|
|
39
|
+
if (!_value) return false;
|
|
40
|
+
else if (type === 'range' && _value) {
|
|
41
|
+
const { lowest, highest } = _value as DateRange;
|
|
42
|
+
return (
|
|
43
|
+
isSameDay(lowest, date) ||
|
|
44
|
+
(highest ? isSameDay(highest, date) : false)
|
|
45
|
+
);
|
|
46
|
+
} else {
|
|
47
|
+
return isSameDay(_value as Date, date);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
[type]
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const handlePressCell = React.useCallback(
|
|
54
|
+
(date: Date, _value?: Value<T>) => () => {
|
|
55
|
+
if (type === 'day') {
|
|
56
|
+
onChange?.(date as never);
|
|
57
|
+
} else if (!_value) {
|
|
58
|
+
onChange?.({ lowest: date } as never);
|
|
59
|
+
} else {
|
|
60
|
+
let newValue;
|
|
61
|
+
const { lowest, highest } = _value as DateRange;
|
|
62
|
+
|
|
63
|
+
if (!highest) {
|
|
64
|
+
if (compare(date, lowest) === -1) {
|
|
65
|
+
newValue = { lowest: date, highest: lowest };
|
|
66
|
+
} else if (compare(date, lowest) === 0) {
|
|
67
|
+
newValue = undefined;
|
|
68
|
+
} else {
|
|
69
|
+
newValue = { lowest: lowest, highest: date };
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
if (compare(date, lowest) === -1) {
|
|
73
|
+
newValue = { lowest: date, highest: highest };
|
|
74
|
+
} else if (compare(date, lowest) === 0) {
|
|
75
|
+
newValue = { lowest: highest, highest: undefined };
|
|
76
|
+
} else {
|
|
77
|
+
if (compare(date, highest) === -1) {
|
|
78
|
+
const lowestDiff = Math.abs(differenceInDays(date, lowest));
|
|
79
|
+
const highestDiff = Math.abs(differenceInDays(date, highest));
|
|
80
|
+
newValue = {
|
|
81
|
+
lowest: lowestDiff < highestDiff ? date : lowest,
|
|
82
|
+
highest: highestDiff <= lowestDiff ? date : highest,
|
|
83
|
+
};
|
|
84
|
+
} else if (compare(date, highest) === 0) {
|
|
85
|
+
newValue = { lowest: lowest, highest: undefined };
|
|
86
|
+
} else {
|
|
87
|
+
newValue = { lowest: lowest, highest: date };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
onChange?.(newValue as never);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
[onChange, type]
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<Week>
|
|
100
|
+
{week.map((date, index) => {
|
|
101
|
+
const isSelected = checkIfIsSelected(date, value);
|
|
102
|
+
const isBetween = checkIfIsBetween(date, value);
|
|
103
|
+
|
|
104
|
+
let isRangeStart, isRangeEnd;
|
|
105
|
+
|
|
106
|
+
if (type === 'range' && value) {
|
|
107
|
+
const { lowest, highest } = value as DateRange;
|
|
108
|
+
isRangeStart = highest && isSameDay(lowest, date);
|
|
109
|
+
isRangeEnd = !!highest && isSameDay(highest, date);
|
|
110
|
+
} else {
|
|
111
|
+
isRangeStart = false;
|
|
112
|
+
isRangeEnd = false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const colorTone = isSelected
|
|
116
|
+
? 'xlight'
|
|
117
|
+
: date.getMonth() === referenceDate.getMonth()
|
|
118
|
+
? 'xdark'
|
|
119
|
+
: 'light';
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<Cell
|
|
123
|
+
key={date.getDate()}
|
|
124
|
+
selected={isSelected}
|
|
125
|
+
highlighted={isBetween}
|
|
126
|
+
isLineEnd={index === 6}
|
|
127
|
+
isLineStart={index === 0}
|
|
128
|
+
isRangeStart={isRangeStart}
|
|
129
|
+
isRangeEnd={isRangeEnd}
|
|
130
|
+
onPress={handlePressCell(date, value)}
|
|
131
|
+
>
|
|
132
|
+
<Selected selected={isSelected} pointerEvents={'none'}>
|
|
133
|
+
<TextComponent colorVariant={'secondary'} colorTone={colorTone}>
|
|
134
|
+
{date.getDate()}
|
|
135
|
+
</TextComponent>
|
|
136
|
+
</Selected>
|
|
137
|
+
</Cell>
|
|
138
|
+
);
|
|
139
|
+
})}
|
|
140
|
+
</Week>
|
|
141
|
+
);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export default React.memo(MonthWeek);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Cell, Week } from '../styled';
|
|
3
|
+
import { format } from 'date-fns';
|
|
4
|
+
|
|
5
|
+
interface IWeekdays {
|
|
6
|
+
calendar: Date[][];
|
|
7
|
+
locale?: Locale;
|
|
8
|
+
Capitalized: React.ElementType;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const Weekdays = ({ calendar, locale, Capitalized }: IWeekdays) => {
|
|
12
|
+
return (
|
|
13
|
+
<Week>
|
|
14
|
+
{calendar[0].map(date => (
|
|
15
|
+
<Cell
|
|
16
|
+
key={date.getDate()}
|
|
17
|
+
selected={false}
|
|
18
|
+
highlighted={false}
|
|
19
|
+
isLineEnd={false}
|
|
20
|
+
isLineStart={false}
|
|
21
|
+
isRangeStart={false}
|
|
22
|
+
isRangeEnd={false}
|
|
23
|
+
pointerEvents={'none'}
|
|
24
|
+
>
|
|
25
|
+
<Capitalized colorVariant={'secondary'} colorTone={'medium'}>
|
|
26
|
+
{format(date, 'EEE', { locale }).slice(0, 3)}
|
|
27
|
+
</Capitalized>
|
|
28
|
+
</Cell>
|
|
29
|
+
))}
|
|
30
|
+
</Week>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default React.memo(Weekdays);
|
|
@@ -19,7 +19,7 @@ const Component = <T extends SelectionType>({
|
|
|
19
19
|
bottomOffset = 0,
|
|
20
20
|
locale,
|
|
21
21
|
...modalProps
|
|
22
|
-
}: CalendarProps<T> & ModalProps & DatePickerModalProps<T>) => {
|
|
22
|
+
}: CalendarProps<T> & ModalProps & DatePickerModalProps<T>): JSX.Element => {
|
|
23
23
|
return (
|
|
24
24
|
<RNModal
|
|
25
25
|
transparent
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import styled, { css } from '@emotion/native';
|
|
2
2
|
import { FC } from 'react';
|
|
3
3
|
import { Platform } from 'react-native';
|
|
4
|
-
import { StyleProps } from '../../../types/defaults';
|
|
5
4
|
import { Icon } from '../../atoms/Icon';
|
|
6
5
|
import { disabledInputStyles, InputContainerProps } from '../../atoms/Input';
|
|
7
6
|
import { PressableSurface } from '../../atoms/PressableSurface';
|
|
8
7
|
import { TextProps } from '../../atoms/Text';
|
|
9
|
-
import { hex2rgba } from '@tecsinapse/react-core';
|
|
8
|
+
import { hex2rgba, StyleProps } from '@tecsinapse/react-core';
|
|
10
9
|
|
|
11
10
|
const isWeb = Platform.OS === 'web';
|
|
12
11
|
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
} from '@tecsinapse/react-core';
|
|
8
8
|
import { StyleProp, View, ViewStyle } from 'react-native';
|
|
9
9
|
import * as React from 'react';
|
|
10
|
-
import { FC } from 'react';
|
|
11
10
|
|
|
12
11
|
export interface HintInputContainerProps extends PressableInputContainerProps {
|
|
13
12
|
viewStyle?: StyleProp<ViewStyle>;
|
|
@@ -21,7 +20,7 @@ export interface HintInputContainerProps extends PressableInputContainerProps {
|
|
|
21
20
|
rightComponent?: JSX.Element;
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
const HintInputContainer: FC<HintInputContainerProps> = ({
|
|
23
|
+
const HintInputContainer: React.FC<HintInputContainerProps> = ({
|
|
25
24
|
viewStyle,
|
|
26
25
|
onPress,
|
|
27
26
|
focused,
|
package/src/hooks/useTheme.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
export const extractNumbersFromString = (value: string): number =>
|
|
2
2
|
Number(value.replace(/[^0-9]/g, ''));
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* implemented for the case: string numbers start with 0. Example: 012.345.678-91 Example: 012.345.678-91
|
|
6
|
+
* */
|
|
7
|
+
export const extractDigitsFromString = (value: string): string =>
|
|
8
|
+
value.replace(/[^0-9]/g, '');
|
package/src/utils/index.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
export const lightenDarkenColor = (color: string, variation: number) => {
|
|
2
|
-
|
|
2
|
+
let usePound = false;
|
|
3
3
|
|
|
4
4
|
if (color[0] == '#') {
|
|
5
5
|
color = color.slice(1);
|
|
6
6
|
usePound = true;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
const num = parseInt(color, 16);
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
let r = (num >> 16) + variation;
|
|
12
12
|
if (r > 255) r = 255;
|
|
13
13
|
else if (r < 0) r = 0;
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
let b = ((num >> 8) & 0x00ff) + variation;
|
|
16
16
|
if (b > 255) b = 255;
|
|
17
17
|
else if (b < 0) b = 0;
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
let g = (num & 0x0000ff) + variation;
|
|
20
20
|
if (g > 255) g = 255;
|
|
21
21
|
else if (g < 0) g = 0;
|
|
22
22
|
|