@via-profit/ui-kit 0.1.0-rc.97 → 0.1.1
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/Avatar/index.js +2 -2
- package/Badge/BadgeDeleteButton.js +1 -1
- package/Badge/BadgeStandard.js +2 -2
- package/Button/ButtonStandard.js +2 -2
- package/Calendar/CalendarCell.d.ts +1 -0
- package/Calendar/CalendarCell.js +8 -3
- package/Calendar/CalendarDayBadge.js +1 -1
- package/Calendar/CalendarMonthsSelector.d.ts +4 -0
- package/Calendar/{CalendarMonthesSelector.js → CalendarMonthsSelector.js} +2 -2
- package/Calendar/index.d.ts +10 -9
- package/Calendar/index.js +63 -15
- package/Calendar/reducer.d.ts +8 -8
- package/Calendar/reducer.js +14 -6
- package/Calendar/use-calendar.d.ts +2 -1
- package/Calendar/use-calendar.js +2 -2
- package/Color/index.d.ts +5 -4
- package/Color/index.js +13 -6
- package/DatePicker/index.js +2 -2
- package/DatePicker/useDatePickerFormat.js +3 -3
- package/Menu/MenuContainer.js +2 -1
- package/PhoneField/templates.js +2 -0
- package/package.json +2 -2
- package/Avatar/AvatarStandard.d.ts +0 -5
- package/Avatar/AvatarStandard.js +0 -119
- package/Calendar/CalendarMonthesSelector.d.ts +0 -4
package/Avatar/index.js
CHANGED
|
@@ -25,7 +25,7 @@ const StyledAvatarBase = (0, styled_1.default)(AvatarBase_1.default) `
|
|
|
25
25
|
background-color: ${({ $background }) => $background.toString()};
|
|
26
26
|
${({ $background }) => {
|
|
27
27
|
switch (true) {
|
|
28
|
-
case $background.
|
|
28
|
+
case $background.getLuminance() > 0.49:
|
|
29
29
|
return $background.darken(40).alpha(0.8).toString();
|
|
30
30
|
default:
|
|
31
31
|
return $background.darken(20).alpha(0.5).toString();
|
|
@@ -95,7 +95,7 @@ const Avatar = (props, ref) => {
|
|
|
95
95
|
}
|
|
96
96
|
return {
|
|
97
97
|
$background,
|
|
98
|
-
$color: $background.
|
|
98
|
+
$color: $background.getContrast(theme.color.textPrimary) > 5
|
|
99
99
|
? theme.color.textPrimary
|
|
100
100
|
: theme.color.surface,
|
|
101
101
|
};
|
|
@@ -73,7 +73,7 @@ const BadgeDeleteButton = (props, ref) => {
|
|
|
73
73
|
};
|
|
74
74
|
case variant === 'standard' && typeof color === 'string':
|
|
75
75
|
return {
|
|
76
|
-
$color: new Color_1.default(color).
|
|
76
|
+
$color: new Color_1.default(color).getContrast(theme.color.textPrimary) > 5
|
|
77
77
|
? theme.color.textPrimary
|
|
78
78
|
: theme.color.surface,
|
|
79
79
|
$background: new Color_1.default(color),
|
package/Badge/BadgeStandard.js
CHANGED
|
@@ -27,7 +27,7 @@ const StyledStandardBadge = (0, styled_1.default)(BadgeBase_1.default) `
|
|
|
27
27
|
background-color: ${({ $background }) => $background.toString()};
|
|
28
28
|
${({ $background }) => {
|
|
29
29
|
switch (true) {
|
|
30
|
-
case $background.
|
|
30
|
+
case $background.getLuminance() > 0.49:
|
|
31
31
|
return $background.darken(40).alpha(0.8).toString();
|
|
32
32
|
default:
|
|
33
33
|
return $background.darken(20).alpha(0.5).toString();
|
|
@@ -81,7 +81,7 @@ const BadgeStandard = (props, ref) => {
|
|
|
81
81
|
}
|
|
82
82
|
return {
|
|
83
83
|
$background,
|
|
84
|
-
$color: $background.
|
|
84
|
+
$color: $background.getContrast(theme.color.textPrimary) > 5
|
|
85
85
|
? theme.color.textPrimary
|
|
86
86
|
: theme.color.surface,
|
|
87
87
|
};
|
package/Button/ButtonStandard.js
CHANGED
|
@@ -38,7 +38,7 @@ const StyledStandardButton = (0, styled_1.default)(ButtonBase_1.default) `
|
|
|
38
38
|
}};
|
|
39
39
|
${({ $background }) => {
|
|
40
40
|
switch (true) {
|
|
41
|
-
case $background.
|
|
41
|
+
case $background.getLuminance() > 0.49:
|
|
42
42
|
return $background.darken(40).alpha(0.8).toString();
|
|
43
43
|
default:
|
|
44
44
|
return $background.darken(20).alpha(0.5).toString();
|
|
@@ -94,7 +94,7 @@ const ButtonStandard = (props, ref) => {
|
|
|
94
94
|
}
|
|
95
95
|
return {
|
|
96
96
|
$background,
|
|
97
|
-
$color: $background.
|
|
97
|
+
$color: ($background === null || $background === void 0 ? void 0 : $background.getContrast(theme.color.textPrimary.rgbString())) > 5
|
|
98
98
|
? theme.color.textPrimary
|
|
99
99
|
: theme.color.surface,
|
|
100
100
|
};
|
|
@@ -17,6 +17,7 @@ export interface CalendarCellProps extends React.ButtonHTMLAttributes<HTMLButton
|
|
|
17
17
|
* Possibility variants: `primary` `secondary` or custom color string like hex or rgb format
|
|
18
18
|
*/
|
|
19
19
|
readonly accentColor?: 'primary' | 'secondary' | string;
|
|
20
|
+
readonly fill?: boolean;
|
|
20
21
|
}
|
|
21
22
|
declare const _default: React.ForwardRefExoticComponent<CalendarCellProps & React.RefAttributes<HTMLButtonElement>>;
|
|
22
23
|
export default _default;
|
package/Calendar/CalendarCell.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
const react_1 = __importDefault(require("react"));
|
|
18
18
|
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
19
19
|
const Button_1 = __importDefault(require("../Button"));
|
|
20
|
+
const react_2 = require("@emotion/react");
|
|
20
21
|
const Btn = (0, styled_1.default)(Button_1.default) `
|
|
21
22
|
display: flex;
|
|
22
23
|
align-items: center;
|
|
@@ -28,10 +29,14 @@ const Btn = (0, styled_1.default)(Button_1.default) `
|
|
|
28
29
|
min-width: 0;
|
|
29
30
|
outline: none;
|
|
30
31
|
position: relative;
|
|
31
|
-
border-radius: ${({ theme }) => theme.shape.radiusFactor * 3}em;
|
|
32
|
+
border-radius: ${({ theme, $fill }) => ($fill ? 0 : theme.shape.radiusFactor * 3)}em;
|
|
33
|
+
${({ $fill, theme }) => $fill &&
|
|
34
|
+
(0, react_2.css) `
|
|
35
|
+
background-color: ${theme.color.accentPrimary.alpha(0.2).toString()};
|
|
36
|
+
`};
|
|
32
37
|
`;
|
|
33
38
|
const CalendarCell = (props, ref) => {
|
|
34
|
-
const { isToday, children, isSelected, isDisabled, accentColor } = props, restProps = __rest(props, ["isToday", "children", "isSelected", "isDisabled", "accentColor"]);
|
|
35
|
-
return (react_1.default.createElement(Btn, Object.assign({ iconOnly: true, type: "button", variant: isSelected ? 'standard' : isToday ? 'outlined' : 'plain', color: isSelected || isToday ? accentColor : 'default', tabIndex: isDisabled ? -1 : restProps.tabIndex, disabled: isDisabled }, restProps, { ref: ref }), children));
|
|
39
|
+
const { isToday, children, isSelected, isDisabled, accentColor, fill } = props, restProps = __rest(props, ["isToday", "children", "isSelected", "isDisabled", "accentColor", "fill"]);
|
|
40
|
+
return (react_1.default.createElement(Btn, Object.assign({ iconOnly: true, type: "button", "$fill": fill, variant: isSelected ? 'standard' : isToday ? 'outlined' : 'plain', color: isSelected || isToday ? accentColor : 'default', tabIndex: isDisabled ? -1 : restProps.tabIndex, disabled: isDisabled }, restProps, { ref: ref }), children));
|
|
36
41
|
};
|
|
37
42
|
exports.default = react_1.default.forwardRef(CalendarCell);
|
|
@@ -62,7 +62,7 @@ const CalendarDayBadge = (props, ref) => {
|
|
|
62
62
|
const clr = new Color_1.default(accentColor);
|
|
63
63
|
return {
|
|
64
64
|
$backgroundColor: accentColor,
|
|
65
|
-
$color: clr.
|
|
65
|
+
$color: clr.getContrast(accentColor) > 5
|
|
66
66
|
? theme.color.textPrimary.toString()
|
|
67
67
|
: theme.color.surface.toString(),
|
|
68
68
|
};
|
|
@@ -23,8 +23,8 @@ const SelectorContainer = styled_1.default.div `
|
|
|
23
23
|
overflow-y: auto;
|
|
24
24
|
padding: 0.8em;
|
|
25
25
|
`;
|
|
26
|
-
const
|
|
26
|
+
const CalendarMonthsSelector = (props, ref) => {
|
|
27
27
|
const { children } = props, restProps = __rest(props, ["children"]);
|
|
28
28
|
return (react_1.default.createElement(SelectorContainer, Object.assign({}, restProps, { ref: ref }), children));
|
|
29
29
|
};
|
|
30
|
-
exports.default = react_1.default.forwardRef(
|
|
30
|
+
exports.default = react_1.default.forwardRef(CalendarMonthsSelector);
|
package/Calendar/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { CalendarWeekRowProps } from './CalendarWeekRow';
|
|
|
8
8
|
import { CalendarDateContainerProps } from './CalendarDateContainer';
|
|
9
9
|
import { CalendarToolbarProps } from './CalendarToolbar';
|
|
10
10
|
import { CalendarYearsSelectorProps } from './CalendarYearsSelector';
|
|
11
|
-
import {
|
|
11
|
+
import { CalendarMonthsSelectorProps } from './CalendarMonthsSelector';
|
|
12
12
|
import { CalendarMonthCellProps } from './CalendarMonthCell';
|
|
13
13
|
import { CalendarYearCellProps } from './CalendarYearCell';
|
|
14
14
|
import { CalendarDayBadgeProps } from './CalendarDayBadge';
|
|
@@ -19,24 +19,25 @@ import { CalendarSubheadingProps } from './CalendarSubheading';
|
|
|
19
19
|
import { CalendarIconPrevProps } from './CalendarIconPrev';
|
|
20
20
|
import { CalendarIconNextProps } from './IconChevronRight';
|
|
21
21
|
import { CalendarWeekDaysBarProps, WeekNameLabelFormat } from './CalendarWeekDaysBar';
|
|
22
|
-
import { WeekDayName } from './use-calendar';
|
|
22
|
+
import { CalendarValue, WeekDayName } from './use-calendar';
|
|
23
23
|
import { CalendarView as CalendarViewName } from './reducer';
|
|
24
24
|
export * from './use-calendar';
|
|
25
25
|
export * from './CalendarWeekDaysBar';
|
|
26
26
|
export type CalendarView = CalendarViewName;
|
|
27
|
-
export type CalendarProps = {
|
|
27
|
+
export type CalendarProps<Range extends boolean | undefined = undefined> = {
|
|
28
|
+
readonly range?: Range;
|
|
28
29
|
/**
|
|
29
30
|
* Selected date
|
|
30
31
|
*/
|
|
31
|
-
readonly value?:
|
|
32
|
+
readonly value?: CalendarValue<Range>;
|
|
32
33
|
/**
|
|
33
|
-
* selected value if your
|
|
34
|
+
* selected value if your component should not be controlled
|
|
34
35
|
*/
|
|
35
|
-
readonly defaultValue?:
|
|
36
|
+
readonly defaultValue?: CalendarValue<Range>;
|
|
36
37
|
/**
|
|
37
38
|
* It will be called at the moment of selecting the given
|
|
38
39
|
*/
|
|
39
|
-
readonly onChange: (dates:
|
|
40
|
+
readonly onChange: (dates: CalendarValue<Range>) => void;
|
|
40
41
|
/**
|
|
41
42
|
* calendar locale\
|
|
42
43
|
* **Default:** `ru-RU`
|
|
@@ -168,7 +169,7 @@ export interface CalendarOverrides {
|
|
|
168
169
|
/**
|
|
169
170
|
* Monthes list element (month view)
|
|
170
171
|
*/
|
|
171
|
-
readonly
|
|
172
|
+
readonly MonthsSelector?: React.ForwardRefExoticComponent<CalendarMonthsSelectorProps & React.RefAttributes<HTMLDivElement>>;
|
|
172
173
|
/**
|
|
173
174
|
* Month cell element in monthes list
|
|
174
175
|
*/
|
|
@@ -215,5 +216,5 @@ export type CalendarBadge = {
|
|
|
215
216
|
readonly badgeContent: React.ReactNode;
|
|
216
217
|
readonly accentColor?: 'primary' | 'secondary' | string;
|
|
217
218
|
};
|
|
218
|
-
declare const Calendar: React.
|
|
219
|
+
declare const Calendar: <Range_1 extends boolean | undefined = undefined>(props: CalendarProps<Range_1>) => React.ReactNode;
|
|
219
220
|
export default Calendar;
|
package/Calendar/index.js
CHANGED
|
@@ -27,7 +27,7 @@ const CalendarWeekRow_1 = __importDefault(require("./CalendarWeekRow"));
|
|
|
27
27
|
const CalendarDateContainer_1 = __importDefault(require("./CalendarDateContainer"));
|
|
28
28
|
const CalendarToolbar_1 = __importDefault(require("./CalendarToolbar"));
|
|
29
29
|
const CalendarYearsSelector_1 = __importDefault(require("./CalendarYearsSelector"));
|
|
30
|
-
const
|
|
30
|
+
const CalendarMonthsSelector_1 = __importDefault(require("./CalendarMonthsSelector"));
|
|
31
31
|
const CalendarMonthCell_1 = __importDefault(require("./CalendarMonthCell"));
|
|
32
32
|
const CalendarYearCell_1 = __importDefault(require("./CalendarYearCell"));
|
|
33
33
|
const CalendarDayBadge_1 = __importDefault(require("./CalendarDayBadge"));
|
|
@@ -42,8 +42,8 @@ const use_calendar_1 = require("./use-calendar");
|
|
|
42
42
|
const reducer_1 = require("./reducer");
|
|
43
43
|
__exportStar(require("./use-calendar"), exports);
|
|
44
44
|
__exportStar(require("./CalendarWeekDaysBar"), exports);
|
|
45
|
-
const Calendar = props => {
|
|
46
|
-
const { minDate = new Date(new Date().getFullYear() - 100, 0, 1, 0, 0, 0), maxDate = new Date(new Date().getFullYear() + 100, 0, 1, 0, 0, 0), weekStartDay = 'monday', locale = 'ru-RU', displayLeadingZero = false, onChange, badges = [], value, defaultValue, markToday, weekDayLabelFormat = 'short', accentColor = 'primary', prevMonthButtonTooltip, nextMonthButtonTooltip, changeMonthButtonTooltip, changeYearButtonTooltip, initialView = reducer_1.
|
|
45
|
+
const Calendar = (props) => {
|
|
46
|
+
const { minDate = new Date(new Date().getFullYear() - 100, 0, 1, 0, 0, 0), maxDate = new Date(new Date().getFullYear() + 100, 0, 1, 0, 0, 0), weekStartDay = 'monday', locale = 'ru-RU', displayLeadingZero = false, onChange, badges = [], value, defaultValue, markToday, weekDayLabelFormat = 'short', accentColor = 'primary', prevMonthButtonTooltip, nextMonthButtonTooltip, changeMonthButtonTooltip, changeYearButtonTooltip, initialView = (0, reducer_1.createDefaultState)(false).calendarCurrentView, resetButtonLabel, toodayButtonLabel, heading, subheading, footer, overrides, range = false, } = props;
|
|
47
47
|
if (typeof value !== 'undefined' && typeof onChange === 'undefined') {
|
|
48
48
|
throw new Error('You provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultValue`. Otherwise, set either `onChange`.');
|
|
49
49
|
}
|
|
@@ -57,7 +57,7 @@ const Calendar = props => {
|
|
|
57
57
|
DateContainer: (overrides === null || overrides === void 0 ? void 0 : overrides.DateContainer) || CalendarDateContainer_1.default,
|
|
58
58
|
Toolbar: (overrides === null || overrides === void 0 ? void 0 : overrides.Toolbar) || CalendarToolbar_1.default,
|
|
59
59
|
YearsSelector: (overrides === null || overrides === void 0 ? void 0 : overrides.YearsSelector) || CalendarYearsSelector_1.default,
|
|
60
|
-
|
|
60
|
+
MonthsSelector: (overrides === null || overrides === void 0 ? void 0 : overrides.MonthsSelector) || CalendarMonthsSelector_1.default,
|
|
61
61
|
MonthCell: (overrides === null || overrides === void 0 ? void 0 : overrides.MonthCell) || CalendarMonthCell_1.default,
|
|
62
62
|
YearCell: (overrides === null || overrides === void 0 ? void 0 : overrides.YearCell) || CalendarYearCell_1.default,
|
|
63
63
|
DayBadge: (overrides === null || overrides === void 0 ? void 0 : overrides.DayBadge) || CalendarDayBadge_1.default,
|
|
@@ -79,8 +79,9 @@ const Calendar = props => {
|
|
|
79
79
|
badges,
|
|
80
80
|
initialView,
|
|
81
81
|
});
|
|
82
|
-
const
|
|
83
|
-
const
|
|
82
|
+
const initialState = Object.assign(Object.assign({}, (0, reducer_1.createDefaultState)(range)), { calendarValue: realValue, calendarDate: Array.isArray(realValue) ? realValue[0] : realValue, calendarCurrentView: initialView });
|
|
83
|
+
const [state, dispatch] = react_1.default.useReducer(reducer_1.reducer, initialState);
|
|
84
|
+
const { isSameDay, getWeeks, getDayLabel, getMonthLabel, getYearLabel, getYearsRange, getMonthsRange, } = (0, use_calendar_1.useCalendar)({
|
|
84
85
|
minDate,
|
|
85
86
|
maxDate,
|
|
86
87
|
weekStartDay,
|
|
@@ -101,12 +102,12 @@ const Calendar = props => {
|
|
|
101
102
|
* Date props was changed
|
|
102
103
|
*/
|
|
103
104
|
react_1.default.useEffect(() => {
|
|
104
|
-
if (typeof value !== 'undefined'
|
|
105
|
+
if (typeof value !== 'undefined') {
|
|
105
106
|
dispatch({
|
|
106
107
|
type: 'setPartial',
|
|
107
108
|
payload: {
|
|
108
109
|
calendarValue: value,
|
|
109
|
-
calendarDate: value,
|
|
110
|
+
// calendarDate: Array.isArray(value) ? value[0] : value,
|
|
110
111
|
},
|
|
111
112
|
});
|
|
112
113
|
}
|
|
@@ -116,9 +117,41 @@ const Calendar = props => {
|
|
|
116
117
|
*/
|
|
117
118
|
const handleCellDateClick = react_1.default.useCallback((selectedDate) => () => {
|
|
118
119
|
if (typeof onChange === 'function') {
|
|
119
|
-
|
|
120
|
+
if (range) {
|
|
121
|
+
const [fromDate, toDate] = calendarValue;
|
|
122
|
+
dispatch({
|
|
123
|
+
type: 'setPartial',
|
|
124
|
+
payload: { calendarDate: selectedDate },
|
|
125
|
+
});
|
|
126
|
+
if (selectedDate.getTime() >= toDate.getTime()) {
|
|
127
|
+
onChange([fromDate, selectedDate]);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (selectedDate.getTime() < fromDate.getTime()) {
|
|
131
|
+
onChange([selectedDate, toDate]);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (selectedDate.getTime() > fromDate.getTime() &&
|
|
135
|
+
selectedDate.getTime() < toDate.getTime()) {
|
|
136
|
+
const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
|
|
137
|
+
const daysBetweenFromDate = Math.round(Math.abs((fromDate.getTime() - selectedDate.getTime()) / oneDay));
|
|
138
|
+
const daysBetweenToDate = Math.round(Math.abs((toDate.getTime() - selectedDate.getTime()) / oneDay));
|
|
139
|
+
if (daysBetweenToDate <= daysBetweenFromDate) {
|
|
140
|
+
onChange([fromDate, selectedDate]);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (daysBetweenToDate > daysBetweenFromDate) {
|
|
144
|
+
onChange([selectedDate, toDate]);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
throw new Error('Oooops. I don`t know whats is it');
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
onChange(selectedDate);
|
|
152
|
+
}
|
|
120
153
|
}
|
|
121
|
-
if (!
|
|
154
|
+
if (!calendarValue) {
|
|
122
155
|
dispatch({
|
|
123
156
|
type: 'setPartial',
|
|
124
157
|
payload: {
|
|
@@ -126,7 +159,7 @@ const Calendar = props => {
|
|
|
126
159
|
},
|
|
127
160
|
});
|
|
128
161
|
}
|
|
129
|
-
}, [onChange,
|
|
162
|
+
}, [onChange, calendarValue, range]);
|
|
130
163
|
/**
|
|
131
164
|
* Handle of click on year item
|
|
132
165
|
*/
|
|
@@ -212,24 +245,39 @@ const Calendar = props => {
|
|
|
212
245
|
});
|
|
213
246
|
}, []);
|
|
214
247
|
return (react_1.default.createElement(overridesMap.Paper, null,
|
|
248
|
+
JSON.stringify(calendarDate),
|
|
215
249
|
react_1.default.createElement(overridesMap.Header, null,
|
|
216
250
|
typeof heading !== 'undefined' && react_1.default.createElement(overridesMap.Heading, null, heading),
|
|
217
251
|
typeof subheading !== 'undefined' && (react_1.default.createElement(overridesMap.Subheading, null, subheading)),
|
|
218
252
|
react_1.default.createElement(overridesMap.Toolbar, null,
|
|
219
253
|
react_1.default.createElement(overridesMap.ControlButton, { iconOnly: true, onClick: handleChangeMonthClick('prev'), title: prevMonthButtonTooltip, disabled: calendarCurrentView !== 'days' },
|
|
220
254
|
react_1.default.createElement(overridesMap.IconPrev, null)),
|
|
221
|
-
react_1.default.createElement(overridesMap.ControlButton, { title: changeMonthButtonTooltip, isActive: calendarCurrentView === '
|
|
255
|
+
react_1.default.createElement(overridesMap.ControlButton, { title: changeMonthButtonTooltip, isActive: calendarCurrentView === 'months', disabled: !calendarViewVariants.includes('months'), onClick: handleChangeView(calendarCurrentView === 'months' ? 'days' : 'months') }, getMonthLabel(calendarDate)),
|
|
222
256
|
react_1.default.createElement(overridesMap.ControlButton, { isActive: calendarCurrentView === 'years', disabled: !calendarViewVariants.includes('years'), title: changeYearButtonTooltip, onClick: handleChangeView(calendarCurrentView === 'years' ? 'days' : 'years') }, getYearLabel(calendarDate)),
|
|
223
257
|
react_1.default.createElement(overridesMap.ControlButton, { iconOnly: true, onClick: handleChangeMonthClick('next'), title: nextMonthButtonTooltip, disabled: calendarCurrentView !== 'days' },
|
|
224
258
|
react_1.default.createElement(overridesMap.IconNext, null)))),
|
|
225
259
|
react_1.default.createElement(overridesMap.WeekDaysBar, { locale: locale, week: getWeeks(calendarDate)[0], format: weekDayLabelFormat || 'short' }),
|
|
226
260
|
react_1.default.createElement(overridesMap.Body, null,
|
|
227
|
-
calendarCurrentView === 'years' && (react_1.default.createElement(overridesMap.YearsSelector, null, getYearsRange(minDate, maxDate).map(year =>
|
|
228
|
-
|
|
261
|
+
calendarCurrentView === 'years' && (react_1.default.createElement(overridesMap.YearsSelector, null, getYearsRange(minDate, maxDate).map(year => {
|
|
262
|
+
const a = Array.isArray(calendarValue) ? calendarValue : [calendarValue];
|
|
263
|
+
const isSelected = a.find(d => d.getFullYear() === year) !== undefined;
|
|
264
|
+
return (react_1.default.createElement(overridesMap.YearCell, { key: year, accentColor: accentColor, isSelected: isSelected, onClick: handleYearSelected(year) }, getYearLabel(new Date(year, calendarDate.getMonth(), calendarDate.getDate(), 0, 0, 0, 0))));
|
|
265
|
+
}))),
|
|
266
|
+
calendarCurrentView === 'months' && (react_1.default.createElement(overridesMap.MonthsSelector, null, getMonthsRange(minDate, maxDate).map(monthIndex => {
|
|
267
|
+
const a = Array.isArray(calendarValue) ? calendarValue : [calendarValue];
|
|
268
|
+
const isSelected = a.find(d => d.getMonth() === monthIndex) !== undefined;
|
|
269
|
+
return (react_1.default.createElement(overridesMap.MonthCell, { key: monthIndex, accentColor: accentColor, isSelected: isSelected, onClick: handleMonthSelected(monthIndex) }, getMonthLabel(new Date(calendarDate.getFullYear(), monthIndex, 1, 0, 0, 0, 0))));
|
|
270
|
+
}))),
|
|
229
271
|
calendarCurrentView === 'days' && (react_1.default.createElement(overridesMap.DateContainer, null, getWeeks(calendarDate).map(week => (react_1.default.createElement(overridesMap.WeekRow, { key: week.weekNumber.toString() }, week.days.map(day => {
|
|
230
272
|
if (day.date.getMonth() === calendarDate.getMonth()) {
|
|
231
273
|
const badge = badges.find(b => isSameDay(b.date, day.date));
|
|
232
|
-
|
|
274
|
+
const a = Array.isArray(calendarValue) ? calendarValue : [calendarValue];
|
|
275
|
+
const isSelected = isSameDay(a[0], day.date) || isSameDay(a[1], day.date);
|
|
276
|
+
const fill = Array.isArray(calendarValue)
|
|
277
|
+
? day.date.getTime() > calendarValue[0].getTime() &&
|
|
278
|
+
day.date.getTime() < calendarValue[1].getTime()
|
|
279
|
+
: false;
|
|
280
|
+
return (react_1.default.createElement(overridesMap.Cell, { key: day.date.getTime(), isToday: markToday && day.isToday, isDisabled: day.isDisabled, accentColor: accentColor, isSelected: isSelected, onClick: handleCellDateClick(day.date), fill: fill },
|
|
233
281
|
getDayLabel(day.date),
|
|
234
282
|
typeof badge !== 'undefined' && (react_1.default.createElement(overridesMap.DayBadge, { badgeContent: badge.badgeContent, isToday: day.isToday, accentColor: badge.accentColor }))));
|
|
235
283
|
}
|
package/Calendar/reducer.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
export type State = {
|
|
3
|
-
readonly calendarValue: Date;
|
|
1
|
+
import { CalendarValue } from './use-calendar';
|
|
2
|
+
export type State<Range extends boolean | undefined = undefined> = {
|
|
4
3
|
readonly calendarDate: Date;
|
|
4
|
+
readonly calendarValue: CalendarValue<Range>;
|
|
5
5
|
readonly calendarCurrentView: CalendarView;
|
|
6
6
|
readonly calendarViewVariants: readonly CalendarView[];
|
|
7
7
|
};
|
|
8
|
-
export type CalendarView = 'days' | '
|
|
9
|
-
export declare const
|
|
10
|
-
export type Action = {
|
|
8
|
+
export type CalendarView = 'days' | 'months' | 'years';
|
|
9
|
+
export declare const createDefaultState: <Range_1 extends boolean | undefined = undefined>(range?: Range_1 | undefined) => State<Range_1>;
|
|
10
|
+
export type Action<Range extends boolean | undefined = undefined> = {
|
|
11
11
|
readonly type: 'setPartial';
|
|
12
|
-
readonly payload: Partial<State
|
|
12
|
+
readonly payload: Partial<State<Range>>;
|
|
13
13
|
};
|
|
14
|
-
export declare const reducer:
|
|
14
|
+
export declare const reducer: <Range_1 extends boolean | undefined = undefined>(state: State<Range_1>, action: Action<Range_1>) => State<Range_1>;
|
package/Calendar/reducer.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.reducer = exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
exports.reducer = exports.createDefaultState = void 0;
|
|
4
|
+
const createDefaultState = (range) => {
|
|
5
|
+
const currentDate = new Date();
|
|
6
|
+
const nextDate = new Date();
|
|
7
|
+
nextDate.setDate(nextDate.getDate() + 3);
|
|
8
|
+
return {
|
|
9
|
+
calendarValue: range
|
|
10
|
+
? [currentDate, nextDate]
|
|
11
|
+
: new Date(),
|
|
12
|
+
calendarDate: range ? currentDate : new Date(),
|
|
13
|
+
calendarCurrentView: 'days',
|
|
14
|
+
calendarViewVariants: ['years', 'months', 'days'],
|
|
15
|
+
};
|
|
9
16
|
};
|
|
17
|
+
exports.createDefaultState = createDefaultState;
|
|
10
18
|
const reducer = (state, action) => {
|
|
11
19
|
switch (action.type) {
|
|
12
20
|
case 'setPartial':
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type CalendarValue<Multiple> = Multiple extends undefined ? Date : [Date, Date];
|
|
1
2
|
export type WeekDayName = 'sunday' | 'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday';
|
|
2
3
|
export type Day = {
|
|
3
4
|
readonly date: Date;
|
|
@@ -62,7 +63,7 @@ export type UseCalendarPayload = {
|
|
|
62
63
|
/**
|
|
63
64
|
* Returns range of monthes (array of month indexes) between passed dates
|
|
64
65
|
*/
|
|
65
|
-
|
|
66
|
+
getMonthsRange: (minDate: Date, maxDate: Date) => number[];
|
|
66
67
|
};
|
|
67
68
|
export declare const useCalendar: (props: UseCalendarProps) => UseCalendarPayload;
|
|
68
69
|
export default useCalendar;
|
package/Calendar/use-calendar.js
CHANGED
|
@@ -66,7 +66,7 @@ const useCalendar = (props) => {
|
|
|
66
66
|
}
|
|
67
67
|
return y;
|
|
68
68
|
}, []);
|
|
69
|
-
const
|
|
69
|
+
const getMonthsRange = react_1.default.useCallback((minDate, maxDate) => {
|
|
70
70
|
const m = [];
|
|
71
71
|
const y = new Date().getFullYear();
|
|
72
72
|
for (let index = 0; index < 12; index++) {
|
|
@@ -201,7 +201,7 @@ const useCalendar = (props) => {
|
|
|
201
201
|
getMonthLabel,
|
|
202
202
|
getYearLabel,
|
|
203
203
|
getYearsRange,
|
|
204
|
-
|
|
204
|
+
getMonthsRange,
|
|
205
205
|
};
|
|
206
206
|
};
|
|
207
207
|
exports.useCalendar = useCalendar;
|
package/Color/index.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ declare class Color {
|
|
|
50
50
|
/**
|
|
51
51
|
* Returns color luminance value
|
|
52
52
|
*/
|
|
53
|
-
|
|
53
|
+
getLuminance(): number;
|
|
54
54
|
/**
|
|
55
55
|
* Returns the contrast level between the\
|
|
56
56
|
* current and transmitted colors
|
|
@@ -60,7 +60,7 @@ declare class Color {
|
|
|
60
60
|
* const { colors } = themes;
|
|
61
61
|
* const contrast = colors
|
|
62
62
|
* .accentPrimary
|
|
63
|
-
* .
|
|
63
|
+
* .getContrast(color.textPrimary.rgbString());
|
|
64
64
|
*
|
|
65
65
|
* if (contrast > 5) {
|
|
66
66
|
* return color.textPrimary.toString();
|
|
@@ -69,12 +69,13 @@ declare class Color {
|
|
|
69
69
|
* }
|
|
70
70
|
* ```
|
|
71
71
|
*/
|
|
72
|
-
|
|
72
|
+
getContrast(rgb2: string | Color): number;
|
|
73
73
|
/**
|
|
74
74
|
* Lighten or darknest color to lum steps
|
|
75
75
|
* lum - 0-25
|
|
76
76
|
*/
|
|
77
77
|
private shade;
|
|
78
|
+
luminance(lum: number): this;
|
|
78
79
|
static stringToHashCode(str: string): number;
|
|
79
80
|
/**
|
|
80
81
|
* Convert the integer value to a string color value
|
|
@@ -102,7 +103,7 @@ declare class Color {
|
|
|
102
103
|
*/
|
|
103
104
|
rgbString(): string;
|
|
104
105
|
/**
|
|
105
|
-
* Returns the current color as
|
|
106
|
+
* Returns the current color as a hex string
|
|
106
107
|
*/
|
|
107
108
|
hexString(): string;
|
|
108
109
|
/**
|
package/Color/index.js
CHANGED
|
@@ -75,7 +75,7 @@ class Color {
|
|
|
75
75
|
/**
|
|
76
76
|
* Returns color luminance value
|
|
77
77
|
*/
|
|
78
|
-
|
|
78
|
+
getLuminance() {
|
|
79
79
|
const RED = 0.2126;
|
|
80
80
|
const GREEN = 0.7152;
|
|
81
81
|
const BLUE = 0.0722;
|
|
@@ -95,7 +95,7 @@ class Color {
|
|
|
95
95
|
* const { colors } = themes;
|
|
96
96
|
* const contrast = colors
|
|
97
97
|
* .accentPrimary
|
|
98
|
-
* .
|
|
98
|
+
* .getContrast(color.textPrimary.rgbString());
|
|
99
99
|
*
|
|
100
100
|
* if (contrast > 5) {
|
|
101
101
|
* return color.textPrimary.toString();
|
|
@@ -104,10 +104,10 @@ class Color {
|
|
|
104
104
|
* }
|
|
105
105
|
* ```
|
|
106
106
|
*/
|
|
107
|
-
|
|
107
|
+
getContrast(rgb2) {
|
|
108
108
|
const color2 = rgb2 instanceof Color ? rgb2 : new Color(rgb2);
|
|
109
|
-
const lum1 = this.
|
|
110
|
-
const lum2 = color2.
|
|
109
|
+
const lum1 = this.getLuminance();
|
|
110
|
+
const lum2 = color2.getLuminance();
|
|
111
111
|
const brightest = Math.max(lum1, lum2);
|
|
112
112
|
const darkest = Math.min(lum1, lum2);
|
|
113
113
|
return (brightest + 0.05) / (darkest + 0.05);
|
|
@@ -122,6 +122,13 @@ class Color {
|
|
|
122
122
|
__classPrivateFieldGet(this, _Color_color, "f").b = parseInt('0' + Math.min(255, Math.max(0, __classPrivateFieldGet(this, _Color_color, "f").b + lum)), 10);
|
|
123
123
|
return this;
|
|
124
124
|
}
|
|
125
|
+
luminance(lum) {
|
|
126
|
+
const { r, g, b } = __classPrivateFieldGet(this, _Color_color, "f");
|
|
127
|
+
__classPrivateFieldGet(this, _Color_color, "f").r = Math.round(Math.min(Math.max(0, r + r * lum), 255));
|
|
128
|
+
__classPrivateFieldGet(this, _Color_color, "f").g = Math.round(Math.min(Math.max(0, g + g * lum), 255));
|
|
129
|
+
__classPrivateFieldGet(this, _Color_color, "f").b = Math.round(Math.min(Math.max(0, b + b * lum), 255));
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
125
132
|
static stringToHashCode(str) {
|
|
126
133
|
let hash = 0;
|
|
127
134
|
for (let i = 0; i < str.length; i++) {
|
|
@@ -172,7 +179,7 @@ class Color {
|
|
|
172
179
|
return result;
|
|
173
180
|
}
|
|
174
181
|
/**
|
|
175
|
-
* Returns the current color as
|
|
182
|
+
* Returns the current color as a hex string
|
|
176
183
|
*/
|
|
177
184
|
hexString() {
|
|
178
185
|
const colorToHex = (color) => {
|
package/DatePicker/index.js
CHANGED
|
@@ -52,7 +52,7 @@ const DatePicker = props => {
|
|
|
52
52
|
const { value, template, onChange, calendarButtonTooltip, readOnly, disabled, minDate = new Date(new Date().getFullYear() - 100, 0, 1, 0, 0, 0), maxDate = new Date(new Date().getFullYear() + 100, 0, 1, 0, 0, 0), weekStartDay = 'monday', locale = 'ru-RU', badges = [], displayLeadingZero = false, prevMonthButtonTooltip, nextMonthButtonTooltip, changeMonthButtonTooltip, changeYearButtonTooltip, resetButtonLabel, toodayButtonLabel, heading, subheading, initialView, footer, overrides } = props, restInputProps = __rest(props, ["value", "template", "onChange", "calendarButtonTooltip", "readOnly", "disabled", "minDate", "maxDate", "weekStartDay", "locale", "badges", "displayLeadingZero", "prevMonthButtonTooltip", "nextMonthButtonTooltip", "changeMonthButtonTooltip", "changeYearButtonTooltip", "resetButtonLabel", "toodayButtonLabel", "heading", "subheading", "initialView", "footer", "overrides"]);
|
|
53
53
|
const {
|
|
54
54
|
// Calendar overrides
|
|
55
|
-
Body, Cell, EmptyCell, Paper, Header, WeekRow, DateContainer, Toolbar, YearsSelector,
|
|
55
|
+
Body, Cell, EmptyCell, Paper, Header, WeekRow, DateContainer, Toolbar, YearsSelector, MonthsSelector, MonthCell, YearCell, DayBadge, Footer, ControlButton, Heading, Subheading, IconPrev, IconNext, WeekDaysBar,
|
|
56
56
|
// Textfield overrides
|
|
57
57
|
Input, ErrorText, IconWrapper, InputWrapper, Label, Asterisk, Container, } = overrides || {};
|
|
58
58
|
const [currentValue, setCurrentValue] = react_1.default.useState(value);
|
|
@@ -132,7 +132,7 @@ const DatePicker = props => {
|
|
|
132
132
|
DateContainer,
|
|
133
133
|
Toolbar,
|
|
134
134
|
YearsSelector,
|
|
135
|
-
|
|
135
|
+
MonthsSelector,
|
|
136
136
|
MonthCell,
|
|
137
137
|
YearCell,
|
|
138
138
|
DayBadge,
|
|
@@ -42,7 +42,7 @@ const useDatePickerFormat = () => {
|
|
|
42
42
|
}
|
|
43
43
|
const data = {
|
|
44
44
|
days: [],
|
|
45
|
-
|
|
45
|
+
months: [],
|
|
46
46
|
years: [],
|
|
47
47
|
};
|
|
48
48
|
template.split('').forEach((char, charIndex) => {
|
|
@@ -51,7 +51,7 @@ const useDatePickerFormat = () => {
|
|
|
51
51
|
data.years.push(input[charIndex]);
|
|
52
52
|
break;
|
|
53
53
|
case 'm':
|
|
54
|
-
data.
|
|
54
|
+
data.months.push(input[charIndex]);
|
|
55
55
|
break;
|
|
56
56
|
case 'd':
|
|
57
57
|
data.days.push(input[charIndex]);
|
|
@@ -61,7 +61,7 @@ const useDatePickerFormat = () => {
|
|
|
61
61
|
break;
|
|
62
62
|
}
|
|
63
63
|
});
|
|
64
|
-
return new Date(parseInt(data.years.join(''), 10), parseInt(data.
|
|
64
|
+
return new Date(parseInt(data.years.join(''), 10), parseInt(data.months.join(''), 10) - 1, // Fucking month indexes
|
|
65
65
|
parseInt(data.days.join(''), 10));
|
|
66
66
|
}, [validateTemplate]);
|
|
67
67
|
/**
|
package/Menu/MenuContainer.js
CHANGED
|
@@ -31,8 +31,9 @@ const context_1 = __importStar(require("./context"));
|
|
|
31
31
|
const MenuList_1 = __importDefault(require("./MenuList"));
|
|
32
32
|
const Popper_1 = __importDefault(require("../Popper"));
|
|
33
33
|
const ClickOutside_1 = __importDefault(require("../ClickOutside"));
|
|
34
|
+
const onRequestCloseDefault = () => undefined;
|
|
34
35
|
const MenuContainer = react_1.default.forwardRef((props, ref) => {
|
|
35
|
-
const { items, value, anchorElement, overrides, children, closeOutsideClick = true, isOpen = props.anchorPos === 'static'
|
|
36
|
+
const { items, value, anchorElement, overrides, children, closeOutsideClick = true, isOpen = props.anchorPos === 'static', anchorPos = 'auto', multiple = false, autofocus = true, closeOnSelect = !multiple, onRequestClose = onRequestCloseDefault, zIndex, onSelectItem, getOptionSelected, } = props;
|
|
36
37
|
const overridesMap = react_1.default.useMemo(() => ({
|
|
37
38
|
List: (overrides === null || overrides === void 0 ? void 0 : overrides.List) || MenuList_1.default,
|
|
38
39
|
Popper: (overrides === null || overrides === void 0 ? void 0 : overrides.Popper) || Popper_1.default,
|
package/PhoneField/templates.js
CHANGED
|
@@ -13,6 +13,7 @@ const UA_1 = __importDefault(require("../CountryFlags/UA"));
|
|
|
13
13
|
const JP_1 = __importDefault(require("../CountryFlags/JP"));
|
|
14
14
|
const US_1 = __importDefault(require("../CountryFlags/US"));
|
|
15
15
|
const IL_1 = __importDefault(require("../CountryFlags/IL"));
|
|
16
|
+
const CN_1 = __importDefault(require("../CountryFlags/CN"));
|
|
16
17
|
exports.templates = [
|
|
17
18
|
// Russian template
|
|
18
19
|
['RU', react_1.default.createElement(RU_1.default, { key: "ru-1" }), '7', '+x (xxx) xxx-xx-xx', '+7 (987) 654-32-10', /^\+$/], // must be at first (Default RU)
|
|
@@ -27,6 +28,7 @@ exports.templates = [
|
|
|
27
28
|
], // +79...
|
|
28
29
|
// Other fucking countries
|
|
29
30
|
['BY', react_1.default.createElement(BY_1.default, { key: "by" }), '375', '+375 (xx) xxx-xx-xx', '+375 (98) 765-43-21', /^\+{0,1}375/],
|
|
31
|
+
['CN', react_1.default.createElement(CN_1.default, { key: "cn" }), '86', '+86 (xxx) xxxx-xxxx', '+86 (138) 0013-8000', /^\+{0,1}86/],
|
|
30
32
|
['KZ', react_1.default.createElement(KZ_1.default, { key: "kz-1" }), '7', '+997 (xx) xxx-xx-xx', '+997 (98) 765-43-21', /^\+{0,1}997/],
|
|
31
33
|
[
|
|
32
34
|
'KZ',
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@via-profit/ui-kit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "UI Kit",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git@github.com
|
|
7
|
+
"url": "git+ssh://git@github.com/via-profit/ui-kit.git"
|
|
8
8
|
},
|
|
9
9
|
"engines": {
|
|
10
10
|
"node": ">=16.x"
|
package/Avatar/AvatarStandard.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
const react_1 = __importDefault(require("react"));
|
|
18
|
-
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
19
|
-
const react_2 = require("@emotion/react");
|
|
20
|
-
const Color_1 = __importDefault(require("../Color"));
|
|
21
|
-
const AvatarBase_1 = __importDefault(require("./AvatarBase"));
|
|
22
|
-
const AvatarOnlineBadge_1 = __importDefault(require("./AvatarOnlineBadge"));
|
|
23
|
-
const Container = styled_1.default.span `
|
|
24
|
-
position: relative;
|
|
25
|
-
width: ${({ size }) => (size ? size : '2.5em')};
|
|
26
|
-
height: ${({ size }) => (size ? size : '2.5em')};
|
|
27
|
-
`;
|
|
28
|
-
const StyledStandardAvatar = (0, styled_1.default)(AvatarBase_1.default) `
|
|
29
|
-
color: ${({ $color }) => $color.toString()};
|
|
30
|
-
background-color: ${({ $background }) => $background.toString()};
|
|
31
|
-
${({ $background }) => {
|
|
32
|
-
switch (true) {
|
|
33
|
-
case $background.luminance() > 0.49:
|
|
34
|
-
return $background.darken(40).alpha(0.8).toString();
|
|
35
|
-
default:
|
|
36
|
-
return $background.darken(20).alpha(0.5).toString();
|
|
37
|
-
}
|
|
38
|
-
}};
|
|
39
|
-
&:hover {
|
|
40
|
-
background-color: ${({ $background, $clickable }) => $clickable && $background.darken(30).toString()};
|
|
41
|
-
}
|
|
42
|
-
&:focus-visible {
|
|
43
|
-
outline-color: ${({ theme, $background }) => $background.rgbString() === theme.color.accentPrimary.rgbString()
|
|
44
|
-
? theme.color.textPrimary.toString()
|
|
45
|
-
: theme.color.accentPrimary.toString()};
|
|
46
|
-
}
|
|
47
|
-
${({ $clickable }) => $clickable &&
|
|
48
|
-
(0, react_2.css) `
|
|
49
|
-
cursor: pointer;
|
|
50
|
-
`}
|
|
51
|
-
|
|
52
|
-
${({ variant, theme }) => {
|
|
53
|
-
switch (variant) {
|
|
54
|
-
case 'rounded':
|
|
55
|
-
return (0, react_2.css) `
|
|
56
|
-
border-radius: ${theme.shape.radiusFactor * 0.8}em;
|
|
57
|
-
`;
|
|
58
|
-
case 'square':
|
|
59
|
-
return (0, react_2.css) `
|
|
60
|
-
border-radius: inherit;
|
|
61
|
-
`;
|
|
62
|
-
default:
|
|
63
|
-
return (0, react_2.css) `
|
|
64
|
-
border-radius: 100%;
|
|
65
|
-
`;
|
|
66
|
-
}
|
|
67
|
-
}}
|
|
68
|
-
`;
|
|
69
|
-
const AvatarStandard = (props, ref) => {
|
|
70
|
-
const { children, color, onClick, isOnline, size } = props, restProps = __rest(props, ["children", "color", "onClick", "isOnline", "size"]);
|
|
71
|
-
const theme = (0, react_2.useTheme)();
|
|
72
|
-
const clickable = react_1.default.useMemo(() => typeof onClick === 'function', [onClick]);
|
|
73
|
-
const { $background, $color } = react_1.default.useMemo(() => {
|
|
74
|
-
switch (true) {
|
|
75
|
-
case color === 'primary':
|
|
76
|
-
return {
|
|
77
|
-
$color: theme.color.accentPrimaryContrast,
|
|
78
|
-
$background: theme.color.accentPrimary,
|
|
79
|
-
};
|
|
80
|
-
case color === 'secondary':
|
|
81
|
-
return {
|
|
82
|
-
$color: theme.color.accentSecondaryContrast,
|
|
83
|
-
$background: theme.color.accentSecondary,
|
|
84
|
-
};
|
|
85
|
-
case typeof color === 'undefined':
|
|
86
|
-
case color === 'default':
|
|
87
|
-
return {
|
|
88
|
-
$background: theme.color.surface.darken(10),
|
|
89
|
-
$color: theme.color.textPrimary,
|
|
90
|
-
};
|
|
91
|
-
case typeof color === 'string': {
|
|
92
|
-
let $background = theme.color.surface;
|
|
93
|
-
try {
|
|
94
|
-
if (color) {
|
|
95
|
-
$background = new Color_1.default(color);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
catch (err) {
|
|
99
|
-
console.error(`invalid color value «${color}»`);
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
$background,
|
|
103
|
-
$color: $background.contrast(theme.color.textPrimary) > 5
|
|
104
|
-
? theme.color.textPrimary
|
|
105
|
-
: theme.color.surface,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
default:
|
|
109
|
-
return {
|
|
110
|
-
$background: theme.color.surface,
|
|
111
|
-
$color: theme.color.textPrimary,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
}, [color, theme.color]);
|
|
115
|
-
return (react_1.default.createElement(Container, { size: size },
|
|
116
|
-
react_1.default.createElement(StyledStandardAvatar, Object.assign({ variant: "circular", "$clickable": clickable, "$color": $color, "$background": $background, color: color, onClick: onClick, size: size }, restProps, { tabIndex: clickable ? 0 : -1, ref: ref }), children),
|
|
117
|
-
isOnline && react_1.default.createElement(AvatarOnlineBadge_1.default, null)));
|
|
118
|
-
};
|
|
119
|
-
exports.default = react_1.default.forwardRef(AvatarStandard);
|