@majoo-ui/react 2.0.1 → 2.1.0-rc.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/charts.esm.js +3 -1453
- package/colors/Colors.esm.js +93 -0
- package/components/accordion/Accordion.esm.js +109 -0
- package/components/alertDialog/AlertDialog.esm.js +440 -0
- package/components/avatar/Avatar.esm.js +83 -0
- package/components/badge/Badge.esm.js +255 -0
- package/components/banner/Banner.esm.js +341 -0
- package/components/barChart/BarChart.esm.js +212 -0
- package/components/breadcrumb/Breadcrumb.esm.js +65 -0
- package/components/breadcrumb/index.esm.js +19 -0
- package/components/button/Button.esm.js +331 -0
- package/components/buttonGroup/ButtonGroup.esm.js +350 -0
- package/components/card/Card.esm.js +236 -0
- package/components/chart/assets/data_kosong.png.esm.js +3 -0
- package/components/chart/lineChart/LineChart.esm.js +358 -0
- package/components/chart/lineChart/components/Comparator.esm.js +82 -0
- package/components/chart/lineChart/components/ComparatorController.esm.js +112 -0
- package/components/chart/lineChart/components/ComparatorItem.esm.js +104 -0
- package/components/chart/lineChart/components/ProductList.esm.js +78 -0
- package/components/chart/lineChart/components/TitleLegend.esm.js +107 -0
- package/components/chart/lineChart/components/Tooltip.esm.js +90 -0
- package/components/chart/utils/index.esm.js +109 -0
- package/components/checkboxTable/CheckboxTable.esm.js +287 -0
- package/components/colorPicker/ColorPicker.esm.js +342 -0
- package/components/colorPicker/InputColorPicker.esm.js +120 -0
- package/components/colorPicker/assets/img_colormap.gif.esm.js +3 -0
- package/components/colorPicker/components/ColorFields.esm.js +144 -0
- package/components/colorPicker/components/ColorMap.esm.js +1188 -0
- package/components/contentEditor/ContentEditor.esm.js +251 -0
- package/components/contentEditor/assets/Inline-code-outline.svg.esm.js +3 -0
- package/components/contentEditor/assets/Link-outline.svg.esm.js +3 -0
- package/components/contentEditor/assets/List-bulleted-outline.svg.esm.js +3 -0
- package/components/contentEditor/assets/List-numbered-outline.svg.esm.js +3 -0
- package/components/contentEditor/assets/Redo-outline.svg.esm.js +3 -0
- package/components/contentEditor/assets/Text-bold-filled.svg.esm.js +3 -0
- package/components/contentEditor/assets/Text-clear-format-outline.svg.esm.js +3 -0
- package/components/contentEditor/assets/Text-italic-outline.svg.esm.js +3 -0
- package/components/contentEditor/assets/Text-strikethrough-outline.svg.esm.js +3 -0
- package/components/contentEditor/assets/Text-underline-outline.svg.esm.js +3 -0
- package/components/contentEditor/assets/Undo-outline.svg.esm.js +3 -0
- package/components/contextMenu/ContextMenu.esm.js +298 -0
- package/components/datePicker/AdvancedOption.esm.js +37 -0
- package/components/datePicker/CustomDatePicker.esm.js +121 -0
- package/components/datePicker/DatePicker.esm.js +244 -0
- package/components/datePicker/DatePickerMulti.esm.js +70 -0
- package/components/datePicker/InputDatePicker.esm.js +290 -0
- package/components/datePicker/InputDateRangePicker.esm.js +174 -0
- package/components/datePicker/components/Calendar.esm.js +654 -0
- package/components/datePicker/components/CalendarMulti.esm.js +407 -0
- package/components/datePicker/components/CalendarTimePicker.esm.js +104 -0
- package/components/datePicker/components/DateNumber.esm.js +89 -0
- package/components/datePicker/components/MobileCalendar.esm.js +522 -0
- package/components/datePicker/state/reducer.esm.js +286 -0
- package/components/datePicker/timePicker/InputTimePicker.esm.js +205 -0
- package/components/datePicker/timePicker/TimePicker.esm.js +481 -0
- package/components/devicePreview/DevicePreview.esm.js +631 -0
- package/components/devicePreview/deviceFrame/android-transparant.png.esm.js +3 -0
- package/components/devicePreview/deviceFrame/android-wide-transparant.png.esm.js +3 -0
- package/components/devicePreview/deviceFrame/bg-email.png.esm.js +3 -0
- package/components/devicePreview/deviceFrame/bg-notification.png.esm.js +3 -0
- package/components/devicePreview/deviceFrame/bg-sms.png.esm.js +3 -0
- package/components/devicePreview/deviceFrame/bg-whatsapp.png.esm.js +3 -0
- package/components/devicePreview/deviceFrame/desktop-transparant.png.esm.js +3 -0
- package/components/devicePreview/deviceFrame/ic-majoo-profpic.png.esm.js +3 -0
- package/components/devicePreview/deviceFrame/iphone-transparant.png.esm.js +3 -0
- package/components/dialog/Dialog.esm.js +106 -0
- package/components/drawer/Drawer.esm.js +294 -0
- package/components/dropdownMenu/DropdownMenu.esm.js +281 -0
- package/components/editableTable/EditableMobile.esm.js +361 -0
- package/components/editableTable/EditableTable.esm.js +618 -0
- package/components/editableTable/transition.esm.js +37 -0
- package/components/form/components/FormGroup/FormGroup.esm.js +142 -0
- package/components/form/components/FormHelper/Helper.esm.js +50 -0
- package/components/form/components/FormLabel/Label.esm.js +90 -0
- package/components/form/components/InputAddon/InputAddon.esm.js +105 -0
- package/components/form/components/InputCheckbox/CheckboxGroup.esm.js +60 -0
- package/components/form/components/InputCheckbox/InputCheckbox.esm.js +129 -0
- package/components/form/components/InputCheckbox/icon/CheckOutline.esm.js +33 -0
- package/components/form/components/InputCheckbox/icon/MinusOutline.esm.js +33 -0
- package/components/form/components/InputCombobox/InputCombobox.esm.js +169 -0
- package/components/form/components/InputCounter/InputCounter.esm.js +226 -0
- package/components/form/components/InputCreatable/InputCreatable.esm.js +229 -0
- package/components/form/components/InputDateRange/InputDateRange.esm.js +46 -0
- package/components/form/components/InputElement/InputElement.esm.js +35 -0
- package/components/form/components/InputGroup/InputGroup.esm.js +188 -0
- package/components/form/components/InputLetter/InputLetter.esm.js +68 -0
- package/components/form/components/InputNumber/InputNumber.esm.js +248 -0
- package/components/form/components/InputNumber/NumberFormat.esm.js +1263 -0
- package/components/form/components/InputOTP/InputOTP.esm.js +70 -0
- package/components/form/components/InputRadio/InputRadio.esm.js +273 -0
- package/components/form/components/InputRadio/InputRadioGroup.esm.js +35 -0
- package/components/form/components/InputRadio/context.esm.js +5 -0
- package/components/form/components/InputResourceList/InputResourceList.esm.js +429 -0
- package/components/form/components/InputSearchbox/CloseFilled.esm.js +34 -0
- package/components/form/components/InputSearchbox/InputSearchbox.esm.js +90 -0
- package/components/form/components/InputSearchbox/SearchOutline.esm.js +26 -0
- package/components/form/components/InputSelect/InputSelect.esm.js +964 -0
- package/components/form/components/InputSelectCheck/InputSelectCheck.esm.js +1388 -0
- package/components/form/components/InputSelectCheck/OptionGroupItem.esm.js +39 -0
- package/components/form/components/InputSelectCheck/icon/CheckOutline.esm.js +33 -0
- package/components/form/components/InputSelectTag/InputSelectTag.esm.js +62 -0
- package/components/form/components/InputSignature/InputSignature.esm.js +122 -0
- package/components/form/components/InputSignature/SignatureModal.esm.js +67 -0
- package/components/form/components/InputSwitch/InputSwitch.esm.js +96 -0
- package/components/form/components/InputSwitch/InputSwitchWithImage.esm.js +136 -0
- package/components/form/components/InputTags/InputTags.esm.js +268 -0
- package/components/form/components/InputText/InputText.esm.js +197 -0
- package/components/form/components/InputTextArea/InputTextArea.esm.js +77 -0
- package/components/heading/Heading.esm.js +64 -0
- package/components/iconButton/IconButton.esm.js +71 -0
- package/components/image/Image.esm.js +141 -0
- package/components/link/Link.esm.js +59 -0
- package/components/loadingBar/LoadingBar.esm.js +113 -0
- package/components/mapPicker/InputMapPicker.esm.js +160 -0
- package/components/mapPicker/MapPicker.esm.js +122 -0
- package/components/mapPicker/MapPicker.styles.esm.js +70 -0
- package/components/mapPicker/assets/images/Mapsicle.png.esm.js +3 -0
- package/components/mapPicker/components/AddressCard.esm.js +25 -0
- package/components/mapPicker/components/ButtonSelect.esm.js +46 -0
- package/components/mapPicker/components/ChangeView.esm.js +20 -0
- package/components/mapPicker/components/InputSearch.esm.js +74 -0
- package/components/mapPicker/components/MarkerIcon.esm.js +22 -0
- package/components/mapPicker/components/MarkerSvg.esm.js +62 -0
- package/components/mapPicker/components/ZoomControls.esm.js +36 -0
- package/components/mapPicker/hooks/useMapSearch.esm.js +161 -0
- package/components/modalDialog/ModalDialog.esm.js +247 -0
- package/components/notificationBadge/NotificationBadge.esm.js +149 -0
- package/components/pageDialog/PageDialog.esm.js +291 -0
- package/components/pageDialog/logo.svg.esm.js +3 -0
- package/components/pagination/Pagination.esm.js +94 -0
- package/components/pagination/PaginationButton.esm.js +346 -0
- package/components/pagination/PaginationInfo.esm.js +146 -0
- package/components/paper/Paper.esm.js +76 -0
- package/components/paragraph/Paragraph.esm.js +52 -0
- package/components/pieChart/PieChart.esm.js +287 -0
- package/components/popover/Popover.esm.js +142 -0
- package/components/progress/Progress.esm.js +170 -0
- package/components/progressIndicator/ProgressIndicator.esm.js +287 -0
- package/components/scrollSync/ScrollSync.esm.js +172 -0
- package/components/scrollSync/ScrollSyncNode.esm.js +87 -0
- package/components/scrollSync/utils.esm.js +9 -0
- package/components/separator/Separator.esm.js +43 -0
- package/components/skeleton/Skeleton.esm.js +131 -0
- package/components/slider/Slider.esm.js +345 -0
- package/components/stepWizard/StepWizard.esm.js +451 -0
- package/components/stepWizard/index.esm.js +14 -0
- package/components/table/MobileTable.esm.js +415 -0
- package/components/table/Table.esm.js +1472 -0
- package/components/table/components/columns/DateColumn.esm.js +26 -0
- package/components/table/components/columns/DecimalColumn.esm.js +36 -0
- package/components/table/components/columns/PriceColumn.esm.js +57 -0
- package/components/table/components/columns/RowDraggableColumn.esm.js +24 -0
- package/components/table/components/columns/RowExpanderColumn.esm.js +32 -0
- package/components/table/components/columns/RowExpanderMultipleColumn.esm.js +24 -0
- package/components/table/components/columns/RowMenuColumn.esm.js +101 -0
- package/components/table/components/columns/RowSelectionCallbackColumn.esm.js +38 -0
- package/components/table/components/columns/RowSelectionColumn.esm.js +34 -0
- package/components/table/images/img-emptydata.webp.esm.js +3 -0
- package/components/table/images/img-emptysearchdata.webp.esm.js +3 -0
- package/components/tableOfContent/TableOfContent.esm.js +267 -0
- package/components/tableOfContent/index.esm.js +18 -0
- package/components/tableOfContent/transition.esm.js +38 -0
- package/components/tabs/Tabs.esm.js +282 -0
- package/components/tag/Tag.esm.js +161 -0
- package/components/tagList/TagList.esm.js +90 -0
- package/components/tagStatus/TagStatus.esm.js +134 -0
- package/components/text/Text.esm.js +140 -0
- package/components/toast/Toast.esm.js +297 -0
- package/components/toast/ToastContainer.esm.js +73 -0
- package/components/toast/context/ToastContext.esm.js +5 -0
- package/components/toast/context/ToastProvider.esm.js +96 -0
- package/components/tooltip/Tooltip.esm.js +175 -0
- package/components/upload/Upload.esm.js +1103 -0
- package/components/upload/utils/canvasPreview.esm.js +39 -0
- package/components/upload/utils/imgPreview.esm.js +21 -0
- package/config/stitches.config.esm.js +216 -0
- package/editor.esm.js +1 -264
- package/hooks/useListOption/useListOption.esm.js +56 -0
- package/hooks/useToggle/useToggle.esm.js +8 -0
- package/index.esm.js +106 -42293
- package/layout/box/Box.esm.js +24 -0
- package/layout/flex/Flex.esm.js +135 -0
- package/layout/grid/Grid.esm.js +270 -0
- package/layout/pageContainer/PageContainer.esm.js +60 -0
- package/majoo-provider/MajooProvider.esm.js +42 -0
- package/majoo-provider/ThemeProvider.esm.js +41 -0
- package/majoo-provider/globalStyles.esm.js +242 -0
- package/majoo-provider/styles/modern-normalize.esm.js +95 -0
- package/map.esm.js +2 -734
- package/package.json +8 -4
- package/utils/calendar.esm.js +26 -0
- package/utils/element.esm.js +21 -0
- package/utils/object.esm.js +12 -0
- package/utils/request.esm.js +74 -0
- package/utils/strings.esm.js +6 -0
- package/{useMediaQuery.esm.js → utils/useMediaQuery.esm.js} +1 -1
- package/utils/useNavigatorOnline.esm.js +19 -0
- package/utils/variant.esm.js +12 -0
- package/wrapper/ConditionalWrapper.esm.js +9 -0
- package/ModalDialog.esm.js +0 -2669
- package/Separator.esm.js +0 -3002
- package/stitches.config.esm.js +0 -2284
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import 'core-js/modules/es.array.includes.js';
|
|
2
|
+
import { CloseOutline } from '@majoo-ui/icons';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { Transition } from 'react-transition-group';
|
|
6
|
+
import { colors, styled, keyframes } from '../../config/stitches.config.esm.js';
|
|
7
|
+
import Flex from '../../layout/flex/Flex.esm.js';
|
|
8
|
+
import Heading from '../heading/Heading.esm.js';
|
|
9
|
+
import Paragraph from '../paragraph/Paragraph.esm.js';
|
|
10
|
+
import { Link } from '../link/Link.esm.js';
|
|
11
|
+
import useMediaQuery from '../../utils/useMediaQuery.esm.js';
|
|
12
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
13
|
+
|
|
14
|
+
const TOAST_WIDTH = 576;
|
|
15
|
+
const ANIMATION_DURATION = 400;
|
|
16
|
+
const TOP_RIGHT_POSITION = 'top-right';
|
|
17
|
+
const TOP_LEFT_POSITION = 'top-left';
|
|
18
|
+
const BOTTOM_RIGHT_POSITION = 'bottom-right';
|
|
19
|
+
const BOTTOM_LEFT_POSITION = 'bottom_left';
|
|
20
|
+
const positions = [TOP_RIGHT_POSITION, TOP_LEFT_POSITION, BOTTOM_RIGHT_POSITION, BOTTOM_LEFT_POSITION];
|
|
21
|
+
const toastEnter = position => keyframes({
|
|
22
|
+
'0%': {
|
|
23
|
+
left: position === 'left' ? `-${TOAST_WIDTH}px` : 'unset',
|
|
24
|
+
right: position === 'right' ? `-${TOAST_WIDTH}px` : 'unset',
|
|
25
|
+
opacity: '0'
|
|
26
|
+
},
|
|
27
|
+
'100%': {
|
|
28
|
+
left: position === 'left' ? '0' : 'unset',
|
|
29
|
+
right: position === 'right' ? '0' : 'unset',
|
|
30
|
+
opacity: '1'
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
const toastExit = position => keyframes({
|
|
34
|
+
'0%': {
|
|
35
|
+
transform: 'translateX(0%)',
|
|
36
|
+
opacity: '1'
|
|
37
|
+
},
|
|
38
|
+
'100%': {
|
|
39
|
+
transform: `translateX(${position === 'right' ? '100%' : '-100%'})`,
|
|
40
|
+
opacity: '0'
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const toastAnimationStyle = position => ({
|
|
44
|
+
'&[state="entering"], &[state="entered"]': {
|
|
45
|
+
animationFillMode: 'forwards',
|
|
46
|
+
animationName: toastEnter(position),
|
|
47
|
+
animationDuration: `${ANIMATION_DURATION}ms`
|
|
48
|
+
},
|
|
49
|
+
'&[state="exiting"]': {
|
|
50
|
+
animationFillMode: 'forwards',
|
|
51
|
+
animationName: toastExit(position),
|
|
52
|
+
animationDuration: `${ANIMATION_DURATION * 2}ms`
|
|
53
|
+
},
|
|
54
|
+
'&[state="entered"]': {
|
|
55
|
+
right: 0,
|
|
56
|
+
opacity: '1'
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
const Root = styled('div', {
|
|
60
|
+
display: 'block',
|
|
61
|
+
maxWidth: `${TOAST_WIDTH}px`,
|
|
62
|
+
// width: `${TOAST_WIDTH}px`,
|
|
63
|
+
height: '100%',
|
|
64
|
+
position: 'relative',
|
|
65
|
+
opacity: 0,
|
|
66
|
+
variants: {
|
|
67
|
+
hPosition: {
|
|
68
|
+
right: toastAnimationStyle('right'),
|
|
69
|
+
left: toastAnimationStyle('left')
|
|
70
|
+
},
|
|
71
|
+
vPosition: {
|
|
72
|
+
top: {
|
|
73
|
+
marginTop: '$spacing-05'
|
|
74
|
+
},
|
|
75
|
+
bottom: {
|
|
76
|
+
marginBottom: '$spacing-05'
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
const StyledToast = styled(Flex, {
|
|
82
|
+
// width: '100%',
|
|
83
|
+
// maxWidth: TOAST_WIDTH,
|
|
84
|
+
padding: '$spacing-03',
|
|
85
|
+
textAlign: 'left',
|
|
86
|
+
borderRadius: 8,
|
|
87
|
+
pointer: 'default',
|
|
88
|
+
variants: {
|
|
89
|
+
variant: {
|
|
90
|
+
info: {
|
|
91
|
+
backgroundColor: '$bgToastInfo',
|
|
92
|
+
border: '1px solid $hlNews'
|
|
93
|
+
},
|
|
94
|
+
warning: {
|
|
95
|
+
backgroundColor: '$bgToastWarning',
|
|
96
|
+
border: '1px solid $hlProcess'
|
|
97
|
+
},
|
|
98
|
+
success: {
|
|
99
|
+
backgroundColor: '$bgToastSuccess',
|
|
100
|
+
border: '1px solid $hlSuccess'
|
|
101
|
+
},
|
|
102
|
+
failed: {
|
|
103
|
+
backgroundColor: '$bgToastFailed',
|
|
104
|
+
border: '1px solid $hlFailed'
|
|
105
|
+
},
|
|
106
|
+
pending: {
|
|
107
|
+
backgroundColor: '$bgToastWarning',
|
|
108
|
+
border: '1px solid $orange500'
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
hasAction: {
|
|
112
|
+
true: {
|
|
113
|
+
cursor: 'pointer'
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
const LeftBar = styled('div', {
|
|
119
|
+
width: '4px',
|
|
120
|
+
alignSelf: 'stretch',
|
|
121
|
+
borderRadius: '$lg',
|
|
122
|
+
marginRight: '$spacing-03',
|
|
123
|
+
variants: {
|
|
124
|
+
variant: {
|
|
125
|
+
info: {
|
|
126
|
+
backgroundColor: '$hlNews'
|
|
127
|
+
},
|
|
128
|
+
warning: {
|
|
129
|
+
backgroundColor: '$hlProcess'
|
|
130
|
+
},
|
|
131
|
+
success: {
|
|
132
|
+
backgroundColor: '$hlSuccess'
|
|
133
|
+
},
|
|
134
|
+
failed: {
|
|
135
|
+
backgroundColor: '$hlFailed'
|
|
136
|
+
},
|
|
137
|
+
pending: {
|
|
138
|
+
backgroundColor: '$orange500'
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
const DescriptionField = styled(Paragraph, {
|
|
144
|
+
display: '-webkit-box',
|
|
145
|
+
'-webkit-line-clamp': '3',
|
|
146
|
+
'-webkit-box-orient': 'vertical',
|
|
147
|
+
overflow: 'hidden',
|
|
148
|
+
whiteSpace: 'unset',
|
|
149
|
+
color: '$gray700'
|
|
150
|
+
});
|
|
151
|
+
const CloseButton = styled(Flex, {
|
|
152
|
+
cursor: 'pointer',
|
|
153
|
+
size: '20px',
|
|
154
|
+
borderRadius: '$round',
|
|
155
|
+
'&:hover': {
|
|
156
|
+
backgroundColor: 'rgba(0, 0, 0, .05)'
|
|
157
|
+
},
|
|
158
|
+
alignSelf: 'start',
|
|
159
|
+
variants: {
|
|
160
|
+
hasTitle: {
|
|
161
|
+
false: {
|
|
162
|
+
alignSelf: 'center'
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
const Toast = ({
|
|
168
|
+
id,
|
|
169
|
+
title,
|
|
170
|
+
description,
|
|
171
|
+
position,
|
|
172
|
+
dismissAfter,
|
|
173
|
+
variant,
|
|
174
|
+
onClick,
|
|
175
|
+
onRemove,
|
|
176
|
+
isExternalOfAction,
|
|
177
|
+
onClickOfAction,
|
|
178
|
+
captionOfAction,
|
|
179
|
+
hrefOfAction,
|
|
180
|
+
...rest
|
|
181
|
+
}) => {
|
|
182
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
183
|
+
const isMobile = useMediaQuery(`(max-width: 767px`);
|
|
184
|
+
const close = React.useCallback(() => {
|
|
185
|
+
setIsOpen(false);
|
|
186
|
+
}, [setIsOpen]);
|
|
187
|
+
React.useEffect(() => {
|
|
188
|
+
let currentTimer = null;
|
|
189
|
+
setIsOpen(true);
|
|
190
|
+
currentTimer = setTimeout(() => {
|
|
191
|
+
close();
|
|
192
|
+
}, dismissAfter);
|
|
193
|
+
return () => {
|
|
194
|
+
if (currentTimer) {
|
|
195
|
+
clearTimeout(currentTimer);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}, [dismissAfter]);
|
|
199
|
+
return /*#__PURE__*/jsx(Transition, {
|
|
200
|
+
appear: true,
|
|
201
|
+
in: isOpen,
|
|
202
|
+
timeout: {
|
|
203
|
+
enter: ANIMATION_DURATION + 100,
|
|
204
|
+
exit: ANIMATION_DURATION + 400
|
|
205
|
+
},
|
|
206
|
+
unmountOnExit: true,
|
|
207
|
+
onExited: onRemove,
|
|
208
|
+
children: state => /*#__PURE__*/jsx(Root, {
|
|
209
|
+
id: id,
|
|
210
|
+
state: state,
|
|
211
|
+
css: {
|
|
212
|
+
maxWidth: isMobile ? '80vw' : TOAST_WIDTH
|
|
213
|
+
},
|
|
214
|
+
hPosition: position.includes('left') ? 'left' : 'right',
|
|
215
|
+
vPosition: position.includes('top') ? 'top' : 'bottom',
|
|
216
|
+
...rest,
|
|
217
|
+
children: /*#__PURE__*/jsx(StyledToast, {
|
|
218
|
+
variant: variant,
|
|
219
|
+
hasAction: !!onClick,
|
|
220
|
+
onClick: onClick,
|
|
221
|
+
children: /*#__PURE__*/jsxs(Flex, {
|
|
222
|
+
direction: "column",
|
|
223
|
+
children: [/*#__PURE__*/jsxs(Flex, {
|
|
224
|
+
direction: "row",
|
|
225
|
+
children: [/*#__PURE__*/jsx(LeftBar, {
|
|
226
|
+
variant: variant
|
|
227
|
+
}), /*#__PURE__*/jsxs(Flex, {
|
|
228
|
+
gap: 2,
|
|
229
|
+
direction: "column",
|
|
230
|
+
css: {
|
|
231
|
+
flex: 1
|
|
232
|
+
},
|
|
233
|
+
children: [title && /*#__PURE__*/jsx(Flex, {
|
|
234
|
+
justify: "between",
|
|
235
|
+
children: /*#__PURE__*/jsx(Heading, {
|
|
236
|
+
heading: "sectionTitle",
|
|
237
|
+
css: {
|
|
238
|
+
lineHeight: '$long-content-regular',
|
|
239
|
+
flex: 1,
|
|
240
|
+
whiteSpace: 'unset',
|
|
241
|
+
overflow: 'hidden',
|
|
242
|
+
textOverflow: 'ellipsis',
|
|
243
|
+
color: '$gray900'
|
|
244
|
+
},
|
|
245
|
+
children: title
|
|
246
|
+
})
|
|
247
|
+
}), /*#__PURE__*/jsx(DescriptionField, {
|
|
248
|
+
paragraph: "longContentRegular",
|
|
249
|
+
children: description
|
|
250
|
+
})]
|
|
251
|
+
}), /*#__PURE__*/jsx(CloseButton, {
|
|
252
|
+
onClick: e => {
|
|
253
|
+
e.preventDefault();
|
|
254
|
+
e.stopPropagation();
|
|
255
|
+
close();
|
|
256
|
+
},
|
|
257
|
+
align: "center",
|
|
258
|
+
justify: "center",
|
|
259
|
+
hasTitle: !!title,
|
|
260
|
+
children: /*#__PURE__*/jsx(CloseOutline, {
|
|
261
|
+
color: colors.iconSecondary,
|
|
262
|
+
size: "16px"
|
|
263
|
+
})
|
|
264
|
+
})]
|
|
265
|
+
}), (hrefOfAction || isExternalOfAction || onClickOfAction) && /*#__PURE__*/jsx(Link, {
|
|
266
|
+
href: hrefOfAction,
|
|
267
|
+
isExternal: isExternalOfAction,
|
|
268
|
+
onClick: onClickOfAction,
|
|
269
|
+
color: variant,
|
|
270
|
+
css: {
|
|
271
|
+
alignSelf: 'self-end',
|
|
272
|
+
marginTop: '$spacing-03'
|
|
273
|
+
},
|
|
274
|
+
children: captionOfAction
|
|
275
|
+
})]
|
|
276
|
+
})
|
|
277
|
+
})
|
|
278
|
+
})
|
|
279
|
+
});
|
|
280
|
+
};
|
|
281
|
+
Toast.displayName = 'Toast';
|
|
282
|
+
Toast.propTypes = {
|
|
283
|
+
id: PropTypes.string,
|
|
284
|
+
title: PropTypes.string,
|
|
285
|
+
description: PropTypes.string,
|
|
286
|
+
position: PropTypes.oneOf(positions).isRequired,
|
|
287
|
+
dismissAfter: PropTypes.number,
|
|
288
|
+
variant: PropTypes.string.isRequired,
|
|
289
|
+
onClick: PropTypes.func,
|
|
290
|
+
onRemove: PropTypes.func,
|
|
291
|
+
disabledOfflineIntercept: PropTypes.bool
|
|
292
|
+
};
|
|
293
|
+
Toast.defaultProps = {
|
|
294
|
+
dismissAfter: 5000
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
export { BOTTOM_LEFT_POSITION, BOTTOM_RIGHT_POSITION, TOP_LEFT_POSITION, TOP_RIGHT_POSITION, Toast as default };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import 'core-js/modules/es.iterator.constructor.js';
|
|
2
|
+
import 'core-js/modules/es.iterator.map.js';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { Portal } from '@majoo-ui/helpers';
|
|
5
|
+
import Toast, { BOTTOM_LEFT_POSITION, BOTTOM_RIGHT_POSITION, TOP_LEFT_POSITION, TOP_RIGHT_POSITION } from './Toast.esm.js';
|
|
6
|
+
import Flex from '../../layout/flex/Flex.esm.js';
|
|
7
|
+
import { styled } from '../../config/stitches.config.esm.js';
|
|
8
|
+
import ToastContext from './context/ToastContext.esm.js';
|
|
9
|
+
import { jsx } from 'react/jsx-runtime';
|
|
10
|
+
|
|
11
|
+
const ToastBox = styled(Flex, {
|
|
12
|
+
position: 'fixed',
|
|
13
|
+
variants: {
|
|
14
|
+
position: {
|
|
15
|
+
[TOP_RIGHT_POSITION]: {
|
|
16
|
+
top: '$toastPosition$top',
|
|
17
|
+
right: '$toastPosition$right',
|
|
18
|
+
flexDirection: 'column-reverse'
|
|
19
|
+
},
|
|
20
|
+
[TOP_LEFT_POSITION]: {
|
|
21
|
+
top: '$toastPosition$top',
|
|
22
|
+
left: '$toastPosition$left',
|
|
23
|
+
flexDirection: 'column-reverse'
|
|
24
|
+
},
|
|
25
|
+
[BOTTOM_RIGHT_POSITION]: {
|
|
26
|
+
bottom: '$toastPosition$bottom',
|
|
27
|
+
right: '$toastPosition$right',
|
|
28
|
+
flexDirection: 'column'
|
|
29
|
+
},
|
|
30
|
+
[BOTTOM_LEFT_POSITION]: {
|
|
31
|
+
bottom: '$toastPosition$bottom',
|
|
32
|
+
left: '$toastPosition$left',
|
|
33
|
+
flexDirection: 'column'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
defaultVariants: {
|
|
38
|
+
position: 'top-right'
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const ToastContainer = ({
|
|
42
|
+
toasts,
|
|
43
|
+
position
|
|
44
|
+
}) => {
|
|
45
|
+
const {
|
|
46
|
+
removeToast,
|
|
47
|
+
theme
|
|
48
|
+
} = React.useContext(ToastContext);
|
|
49
|
+
return /*#__PURE__*/jsx(Portal, {
|
|
50
|
+
theme: theme,
|
|
51
|
+
style: {
|
|
52
|
+
top: 0,
|
|
53
|
+
left: 0,
|
|
54
|
+
position: 'absolute',
|
|
55
|
+
zIndex: 2147483647
|
|
56
|
+
},
|
|
57
|
+
children: /*#__PURE__*/jsx(ToastBox, {
|
|
58
|
+
position: position,
|
|
59
|
+
children: toasts.map((item, index) => {
|
|
60
|
+
const {
|
|
61
|
+
preventDuplicate,
|
|
62
|
+
...toast
|
|
63
|
+
} = item;
|
|
64
|
+
return /*#__PURE__*/jsx(Toast, {
|
|
65
|
+
onRemove: () => removeToast(toast.id),
|
|
66
|
+
...toast
|
|
67
|
+
}, preventDuplicate ? toast.id : `${toast.id}-${index}`);
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export { ToastContainer as default };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import 'core-js/modules/es.iterator.constructor.js';
|
|
2
|
+
import 'core-js/modules/es.iterator.filter.js';
|
|
3
|
+
import 'core-js/modules/es.iterator.for-each.js';
|
|
4
|
+
import 'core-js/modules/es.iterator.some.js';
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import { useState, useCallback } from 'react';
|
|
7
|
+
import { TOP_RIGHT_POSITION, TOP_LEFT_POSITION, BOTTOM_RIGHT_POSITION, BOTTOM_LEFT_POSITION } from '../Toast.esm.js';
|
|
8
|
+
import ToastContainer from '../ToastContainer.esm.js';
|
|
9
|
+
import ToastContext from './ToastContext.esm.js';
|
|
10
|
+
import useNavigatorOnLine from '../../../utils/useNavigatorOnline.esm.js';
|
|
11
|
+
import { useTranslation } from 'react-i18next';
|
|
12
|
+
import { catchError } from '../../../utils/request.esm.js';
|
|
13
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
14
|
+
|
|
15
|
+
let toastCount = 0;
|
|
16
|
+
const ToastProvider = ({
|
|
17
|
+
children,
|
|
18
|
+
theme
|
|
19
|
+
}) => {
|
|
20
|
+
const isOnline = useNavigatorOnLine();
|
|
21
|
+
const [toasts, setToasts] = useState([]);
|
|
22
|
+
const {
|
|
23
|
+
t,
|
|
24
|
+
i18n
|
|
25
|
+
} = useTranslation(['MajooUI/toast', 'translation']);
|
|
26
|
+
const catchError$1 = (e, values) => {
|
|
27
|
+
let errorMsg = catchError(e);
|
|
28
|
+
if (values) {
|
|
29
|
+
Object.keys(values).forEach(key => {
|
|
30
|
+
errorMsg = errorMsg.replace(`$${key}`, values[key]);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return errorMsg;
|
|
34
|
+
};
|
|
35
|
+
const createToastInstance = useCallback(toast => {
|
|
36
|
+
const {
|
|
37
|
+
id,
|
|
38
|
+
disabledOfflineIntercept,
|
|
39
|
+
...rest
|
|
40
|
+
} = toast;
|
|
41
|
+
|
|
42
|
+
// eslint-disable-next-line no-plusplus
|
|
43
|
+
const uniqueId = ++toastCount;
|
|
44
|
+
const toastId = toast.id || `${id || 'toast'}-${uniqueId}`;
|
|
45
|
+
const offlineInstance = {
|
|
46
|
+
title: t('offlineTitle', 'Internet Bermasalah'),
|
|
47
|
+
variant: 'failed',
|
|
48
|
+
description: t('offlineDescription', 'Tidak ada koneksi internet, mohon periksa jaringan'),
|
|
49
|
+
hrefOfAction: false,
|
|
50
|
+
onClickOfAction: false,
|
|
51
|
+
isExternalOfAction: false
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
id: toastId,
|
|
55
|
+
position: TOP_RIGHT_POSITION,
|
|
56
|
+
...rest,
|
|
57
|
+
description: /*#__PURE__*/React.isValidElement(toast.description) ? toast.description : catchError$1(toast.description, toast.values),
|
|
58
|
+
...(!isOnline && !disabledOfflineIntercept && offlineInstance)
|
|
59
|
+
};
|
|
60
|
+
}, [isOnline, t, i18n.language]);
|
|
61
|
+
const addToast = React.useCallback(toast => {
|
|
62
|
+
const toastInstance = createToastInstance(toast);
|
|
63
|
+
setToasts(toastItems => {
|
|
64
|
+
if (!toastItems.some(currToast => toast.id === currToast.id) || !toast.preventDuplicate) {
|
|
65
|
+
return [...toastItems, toastInstance];
|
|
66
|
+
}
|
|
67
|
+
return toastItems;
|
|
68
|
+
});
|
|
69
|
+
return toastInstance;
|
|
70
|
+
}, [createToastInstance]);
|
|
71
|
+
const removeToast = React.useCallback(id => {
|
|
72
|
+
setToasts(toastItems => toastItems.filter(t => t.id !== id));
|
|
73
|
+
}, [setToasts]);
|
|
74
|
+
return /*#__PURE__*/jsxs(ToastContext.Provider, {
|
|
75
|
+
value: {
|
|
76
|
+
addToast,
|
|
77
|
+
removeToast,
|
|
78
|
+
theme
|
|
79
|
+
},
|
|
80
|
+
children: [children, /*#__PURE__*/jsx(ToastContainer, {
|
|
81
|
+
toasts: toasts.filter(toast => toast.position === TOP_RIGHT_POSITION),
|
|
82
|
+
position: TOP_RIGHT_POSITION
|
|
83
|
+
}), /*#__PURE__*/jsx(ToastContainer, {
|
|
84
|
+
toasts: toasts.filter(toast => toast.position === TOP_LEFT_POSITION),
|
|
85
|
+
position: TOP_LEFT_POSITION
|
|
86
|
+
}), /*#__PURE__*/jsx(ToastContainer, {
|
|
87
|
+
toasts: toasts.filter(toast => toast.position === BOTTOM_RIGHT_POSITION),
|
|
88
|
+
position: BOTTOM_RIGHT_POSITION
|
|
89
|
+
}), /*#__PURE__*/jsx(ToastContainer, {
|
|
90
|
+
toasts: toasts.filter(toast => toast.position === BOTTOM_LEFT_POSITION),
|
|
91
|
+
position: BOTTOM_LEFT_POSITION
|
|
92
|
+
})]
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export { ToastProvider as default };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { styled, keyframes } from '../../config/stitches.config.esm.js';
|
|
3
|
+
import * as TooltipPrimitive from '@radix-ui/react-tooltip';
|
|
4
|
+
import { foundations } from '@majoo-ui/core';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
zIndices
|
|
10
|
+
} = foundations;
|
|
11
|
+
const slideUpAndFade = keyframes({
|
|
12
|
+
'0%': {
|
|
13
|
+
opacity: 0,
|
|
14
|
+
transform: 'translateY(2px)'
|
|
15
|
+
},
|
|
16
|
+
'100%': {
|
|
17
|
+
opacity: 1,
|
|
18
|
+
transform: 'translateY(0)'
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
const slideRightAndFade = keyframes({
|
|
22
|
+
'0%': {
|
|
23
|
+
opacity: 0,
|
|
24
|
+
transform: 'translateX(-2px)'
|
|
25
|
+
},
|
|
26
|
+
'100%': {
|
|
27
|
+
opacity: 1,
|
|
28
|
+
transform: 'translateX(0)'
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const slideDownAndFade = keyframes({
|
|
32
|
+
'0%': {
|
|
33
|
+
opacity: 0,
|
|
34
|
+
transform: 'translateY(-2px)'
|
|
35
|
+
},
|
|
36
|
+
'100%': {
|
|
37
|
+
opacity: 1,
|
|
38
|
+
transform: 'translateY(0)'
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const slideLeftAndFade = keyframes({
|
|
42
|
+
'0%': {
|
|
43
|
+
opacity: 0,
|
|
44
|
+
transform: 'translateX(2px)'
|
|
45
|
+
},
|
|
46
|
+
'100%': {
|
|
47
|
+
opacity: 1,
|
|
48
|
+
transform: 'translateX(0)'
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
const StyledContent = styled(TooltipPrimitive.Content, {
|
|
52
|
+
zIndex: zIndices.tooltip,
|
|
53
|
+
borderRadius: 8,
|
|
54
|
+
padding: '8px',
|
|
55
|
+
fontSize: '$helper',
|
|
56
|
+
letterSpacing: '$helper',
|
|
57
|
+
lineHeight: '$helper',
|
|
58
|
+
fontWeight: '400',
|
|
59
|
+
backgroundColor: '$white',
|
|
60
|
+
boxShadow: '$large',
|
|
61
|
+
'@media (prefers-reduced-motion: no-preference)': {
|
|
62
|
+
animationDuration: '400ms',
|
|
63
|
+
animationTimingFunction: 'cubic-bezier(0.16, 1, 0.3, 1)',
|
|
64
|
+
animationFillMode: 'forwards',
|
|
65
|
+
willChange: 'transform, opacity',
|
|
66
|
+
'&[data-state="delayed-open"]': {
|
|
67
|
+
'&[data-side="top"]': {
|
|
68
|
+
animationName: slideDownAndFade
|
|
69
|
+
},
|
|
70
|
+
'&[data-side="right"]': {
|
|
71
|
+
animationName: slideLeftAndFade
|
|
72
|
+
},
|
|
73
|
+
'&[data-side="bottom"]': {
|
|
74
|
+
animationName: slideUpAndFade
|
|
75
|
+
},
|
|
76
|
+
'&[data-side="left"]': {
|
|
77
|
+
animationName: slideRightAndFade
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
maxWidth: '100vw'
|
|
82
|
+
});
|
|
83
|
+
const TriggerSpan = styled('span', {
|
|
84
|
+
display: 'flex'
|
|
85
|
+
});
|
|
86
|
+
const StyledArrow = styled(TooltipPrimitive.Arrow, {
|
|
87
|
+
boxShadow: '$large'
|
|
88
|
+
});
|
|
89
|
+
const TooltipBase = styled(TooltipPrimitive.Root, {
|
|
90
|
+
defaultVariants: {
|
|
91
|
+
color: 'ligth'
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Exports
|
|
96
|
+
const Provider = TooltipPrimitive.Provider;
|
|
97
|
+
const TooltipTrigger = TooltipPrimitive.Trigger;
|
|
98
|
+
const dark = {
|
|
99
|
+
color: foundations.colors.white,
|
|
100
|
+
backgroundColor: foundations.colors.gray800
|
|
101
|
+
};
|
|
102
|
+
const ligth = {
|
|
103
|
+
color: foundations.colors.textPrimary,
|
|
104
|
+
backgroundColor: foundations.colors.bgWhite
|
|
105
|
+
};
|
|
106
|
+
const darkArrow = {
|
|
107
|
+
fill: foundations.colors.gray800
|
|
108
|
+
};
|
|
109
|
+
const lightArrow = {
|
|
110
|
+
fill: foundations.colors.bgWhite
|
|
111
|
+
};
|
|
112
|
+
const Tooltip = ({
|
|
113
|
+
children,
|
|
114
|
+
label,
|
|
115
|
+
color,
|
|
116
|
+
css,
|
|
117
|
+
withClick,
|
|
118
|
+
side,
|
|
119
|
+
align,
|
|
120
|
+
delayDuration,
|
|
121
|
+
...rest
|
|
122
|
+
}) => {
|
|
123
|
+
const [open, setOpen] = useState(false);
|
|
124
|
+
return /*#__PURE__*/jsx(Provider, {
|
|
125
|
+
children: /*#__PURE__*/jsxs(TooltipBase, {
|
|
126
|
+
...rest,
|
|
127
|
+
open: withClick ? open : undefined,
|
|
128
|
+
delayDuration: delayDuration,
|
|
129
|
+
children: [/*#__PURE__*/jsx(TooltipTrigger, {
|
|
130
|
+
asChild: true,
|
|
131
|
+
children: /*#__PURE__*/jsx(TriggerSpan, {
|
|
132
|
+
onClick: () => withClick && !open && setOpen(prev => !prev),
|
|
133
|
+
children: children
|
|
134
|
+
})
|
|
135
|
+
}), /*#__PURE__*/jsx(TooltipPrimitive.Portal, {
|
|
136
|
+
children: /*#__PURE__*/jsxs(StyledContent, {
|
|
137
|
+
align: align,
|
|
138
|
+
side: side,
|
|
139
|
+
sideOffset: 5,
|
|
140
|
+
css: color === 'dark' ? {
|
|
141
|
+
...dark,
|
|
142
|
+
...css
|
|
143
|
+
} : {
|
|
144
|
+
...ligth,
|
|
145
|
+
...css
|
|
146
|
+
},
|
|
147
|
+
onPointerDownOutside: () => setTimeout(() => {
|
|
148
|
+
setOpen(false);
|
|
149
|
+
}, 200),
|
|
150
|
+
children: [label, /*#__PURE__*/jsx(StyledArrow, {
|
|
151
|
+
offset: 10,
|
|
152
|
+
css: color === 'dark' ? darkArrow : lightArrow
|
|
153
|
+
})]
|
|
154
|
+
})
|
|
155
|
+
})]
|
|
156
|
+
})
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
Tooltip.propTypes = {
|
|
160
|
+
children: PropTypes.node,
|
|
161
|
+
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
162
|
+
color: PropTypes.string,
|
|
163
|
+
side: PropTypes.oneOf(['top', 'bottom', 'right', 'left']),
|
|
164
|
+
align: PropTypes.oneOf(['start', 'center', 'end'])
|
|
165
|
+
};
|
|
166
|
+
Tooltip.defaultProps = {
|
|
167
|
+
color: 'dark',
|
|
168
|
+
side: 'bottom',
|
|
169
|
+
align: 'center',
|
|
170
|
+
label: '',
|
|
171
|
+
children: /*#__PURE__*/jsx("div", {}),
|
|
172
|
+
delayDuration: 200
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export { Provider, TooltipBase, TooltipTrigger, Tooltip as default };
|