@carto/ps-react-ui 4.3.3 → 4.3.5
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/dist/components.js +3 -3
- package/dist/components.js.map +1 -1
- package/dist/{lasso-tool-BwRzEW7k.js → lasso-tool-wFqOD6wk.js} +13 -13
- package/dist/lasso-tool-wFqOD6wk.js.map +1 -0
- package/dist/types/components/common-types.d.ts +41 -0
- package/dist/types/components/types.d.ts +1 -1
- package/dist/types/widgets/echart/echart-ui.d.ts +1 -1
- package/dist/types/widgets/echart/types.d.ts +4 -0
- package/dist/widgets/actions.js +1 -1
- package/dist/widgets/bar.js +1 -1
- package/dist/widgets/category.js +1 -1
- package/dist/widgets/echart.js +96 -85
- package/dist/widgets/echart.js.map +1 -1
- package/dist/widgets/formula.js +1 -1
- package/dist/widgets/histogram.js +1 -1
- package/dist/widgets/markdown.js +1 -1
- package/dist/widgets/pie.js +1 -1
- package/dist/widgets/scatterplot.js +1 -1
- package/dist/widgets/spread.js +1 -1
- package/dist/widgets/table.js +1 -1
- package/dist/widgets/timeseries.js +1 -1
- package/dist/widgets/toolbar-actions.js.map +1 -1
- package/dist/widgets/wrapper.js +1 -1
- package/package.json +8 -3
- package/src/components/basemaps/basemaps.test.tsx +196 -0
- package/src/components/basemaps/basemaps.tsx +128 -0
- package/src/components/basemaps/const.ts +13 -0
- package/src/components/basemaps/group-wrapper.test.tsx +38 -0
- package/src/components/basemaps/group-wrapper.tsx +28 -0
- package/src/components/basemaps/group.test.tsx +52 -0
- package/src/components/basemaps/group.tsx +42 -0
- package/src/components/basemaps/header.test.tsx +54 -0
- package/src/components/basemaps/header.tsx +36 -0
- package/src/components/basemaps/styles.ts +76 -0
- package/src/components/basemaps/types.ts +30 -0
- package/src/components/common-types.ts +1 -0
- package/src/components/geolocation-controls/const.ts +6 -0
- package/src/components/geolocation-controls/geolocation-controls.test.tsx +133 -0
- package/src/components/geolocation-controls/geolocation-controls.tsx +95 -0
- package/src/components/geolocation-controls/types.ts +17 -0
- package/src/components/index.ts +64 -0
- package/src/components/lasso-tool/chip.tsx +37 -0
- package/src/components/lasso-tool/const.tsx +70 -0
- package/src/components/lasso-tool/icons.tsx +91 -0
- package/src/components/lasso-tool/lasso-tool-inline.test.tsx +168 -0
- package/src/components/lasso-tool/lasso-tool-inline.tsx +245 -0
- package/src/components/lasso-tool/lasso-tool.test.tsx +212 -0
- package/src/components/lasso-tool/lasso-tool.tsx +479 -0
- package/src/components/lasso-tool/styles.ts +143 -0
- package/src/components/lasso-tool/types.ts +114 -0
- package/src/components/list-data/list-data-skeleton.test.tsx +10 -0
- package/src/components/list-data/list-data-skeleton.tsx +40 -0
- package/src/components/list-data/list-data.test.tsx +94 -0
- package/src/components/list-data/list-data.tsx +106 -0
- package/src/components/list-data/styles.ts +37 -0
- package/src/components/list-data/types.ts +25 -0
- package/src/components/measurement-tools/const.tsx +108 -0
- package/src/components/measurement-tools/icons.tsx +54 -0
- package/src/components/measurement-tools/measurement-tools.test.tsx +165 -0
- package/src/components/measurement-tools/measurement-tools.tsx +443 -0
- package/src/components/measurement-tools/styles.ts +91 -0
- package/src/components/measurement-tools/types.ts +77 -0
- package/src/components/no-data-alert/no-data-alert.test.tsx +31 -0
- package/src/components/no-data-alert/no-data-alert.tsx +59 -0
- package/src/components/responsive-drawer/responsive-drawer.test.tsx +91 -0
- package/src/components/responsive-drawer/responsive-drawer.tsx +53 -0
- package/src/components/smart-tooltip/smart-tooltip.test.tsx +168 -0
- package/src/components/smart-tooltip/smart-tooltip.tsx +40 -0
- package/src/components/tooltip/tooltip.test.tsx +86 -0
- package/src/components/tooltip/tooltip.tsx +30 -0
- package/src/components/types.ts +1 -0
- package/src/components/zoom-controls/styles.ts +27 -0
- package/src/components/zoom-controls/types.ts +19 -0
- package/src/components/zoom-controls/zoom-controls.test.tsx +101 -0
- package/src/components/zoom-controls/zoom-controls.tsx +114 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/use-debounce.ts +55 -0
- package/src/hooks/use-skeleton.test.tsx +32 -0
- package/src/hooks/use-skeleton.ts +19 -0
- package/src/hooks/use-widget-ref.ts +33 -0
- package/src/widgets/README.md +277 -0
- package/src/widgets/_shared/chart-config/config-factory.ts +67 -0
- package/src/widgets/_shared/chart-config/csv-modifiers.ts +56 -0
- package/src/widgets/_shared/chart-config/index.ts +21 -0
- package/src/widgets/_shared/chart-config/option-builders.ts +203 -0
- package/src/widgets/_shared/skeleton/index.ts +5 -0
- package/src/widgets/_shared/skeleton/styles.ts +20 -0
- package/src/widgets/actions/change-column/change-column-icon.tsx +10 -0
- package/src/widgets/actions/change-column/change-column.test.tsx +163 -0
- package/src/widgets/actions/change-column/change-column.tsx +141 -0
- package/src/widgets/actions/change-column/sortable-column-item.tsx +49 -0
- package/src/widgets/actions/change-column/types.ts +20 -0
- package/src/widgets/actions/download/download.test.tsx +322 -0
- package/src/widgets/actions/download/download.tsx +118 -0
- package/src/widgets/actions/download/exports.test.tsx +275 -0
- package/src/widgets/actions/download/exports.tsx +103 -0
- package/src/widgets/actions/download/types.ts +21 -0
- package/src/widgets/actions/fullscreen/fullscreen.test.tsx +269 -0
- package/src/widgets/actions/fullscreen/fullscreen.tsx +82 -0
- package/src/widgets/actions/fullscreen/styles.ts +17 -0
- package/src/widgets/actions/fullscreen/types.ts +27 -0
- package/src/widgets/actions/index.ts +51 -0
- package/src/widgets/actions/lock-selection/lock-selection.test.tsx +186 -0
- package/src/widgets/actions/lock-selection/lock-selection.tsx +133 -0
- package/src/widgets/actions/lock-selection/types.ts +41 -0
- package/src/widgets/actions/relative-data/relative-data.test.tsx +267 -0
- package/src/widgets/actions/relative-data/relative-data.tsx +133 -0
- package/src/widgets/actions/relative-data/style.ts +9 -0
- package/src/widgets/actions/relative-data/types.ts +31 -0
- package/src/widgets/actions/relative-data/utils.test.ts +223 -0
- package/src/widgets/actions/relative-data/utils.ts +58 -0
- package/src/widgets/actions/searcher/searcher-toggle.test.tsx +354 -0
- package/src/widgets/actions/searcher/searcher-toggle.tsx +73 -0
- package/src/widgets/actions/searcher/searcher.tsx +205 -0
- package/src/widgets/actions/searcher/types.ts +72 -0
- package/src/widgets/actions/shared/styles.ts +12 -0
- package/src/widgets/actions/stack-toggle/grouped-bar-chart-icon.tsx +14 -0
- package/src/widgets/actions/stack-toggle/stack-toggle.test.tsx +270 -0
- package/src/widgets/actions/stack-toggle/stack-toggle.tsx +146 -0
- package/src/widgets/actions/stack-toggle/types.ts +29 -0
- package/src/widgets/actions/zoom-toggle/index.ts +2 -0
- package/src/widgets/actions/zoom-toggle/style.ts +14 -0
- package/src/widgets/actions/zoom-toggle/types.ts +44 -0
- package/src/widgets/actions/zoom-toggle/zoom-toggle.tsx +186 -0
- package/src/widgets/bar/config.ts +122 -0
- package/src/widgets/bar/index.ts +9 -0
- package/src/widgets/bar/skeleton.tsx +60 -0
- package/src/widgets/bar/style.ts +33 -0
- package/src/widgets/bar/types.ts +16 -0
- package/src/widgets/category/category-ui.test.tsx +399 -0
- package/src/widgets/category/category-ui.tsx +156 -0
- package/src/widgets/category/components/category-bar.tsx +28 -0
- package/src/widgets/category/components/category-legend.tsx +30 -0
- package/src/widgets/category/components/category-row-multi.tsx +50 -0
- package/src/widgets/category/components/category-row-other.tsx +23 -0
- package/src/widgets/category/components/category-row-single.tsx +47 -0
- package/src/widgets/category/components/index.ts +14 -0
- package/src/widgets/category/config.ts +85 -0
- package/src/widgets/category/index.ts +30 -0
- package/src/widgets/category/skeleton.tsx +24 -0
- package/src/widgets/category/style.ts +133 -0
- package/src/widgets/category/types.ts +40 -0
- package/src/widgets/echart/const.ts +1 -0
- package/src/widgets/echart/echart-ui.test.tsx +537 -0
- package/src/widgets/echart/echart-ui.tsx +92 -0
- package/src/widgets/echart/echart.test.tsx +562 -0
- package/src/widgets/echart/echart.tsx +68 -0
- package/src/widgets/echart/index.ts +16 -0
- package/src/widgets/echart/options.ts +53 -0
- package/src/widgets/echart/types.ts +45 -0
- package/src/widgets/echart/utils.ts +169 -0
- package/src/widgets/error/error.test.tsx +331 -0
- package/src/widgets/error/error.tsx +40 -0
- package/src/widgets/error/index.ts +2 -0
- package/src/widgets/error/types.ts +14 -0
- package/src/widgets/formula/components/item.test.tsx +249 -0
- package/src/widgets/formula/components/item.tsx +18 -0
- package/src/widgets/formula/components/prefix.test.tsx +341 -0
- package/src/widgets/formula/components/prefix.tsx +18 -0
- package/src/widgets/formula/components/row.test.tsx +364 -0
- package/src/widgets/formula/components/row.tsx +21 -0
- package/src/widgets/formula/components/series.tsx +34 -0
- package/src/widgets/formula/components/suffix.test.tsx +383 -0
- package/src/widgets/formula/components/suffix.tsx +28 -0
- package/src/widgets/formula/components/value.test.tsx +329 -0
- package/src/widgets/formula/components/value.tsx +29 -0
- package/src/widgets/formula/config.ts +27 -0
- package/src/widgets/formula/formula-ui.test.tsx +399 -0
- package/src/widgets/formula/formula-ui.tsx +27 -0
- package/src/widgets/formula/index.ts +24 -0
- package/src/widgets/formula/serializer.test.tsx +144 -0
- package/src/widgets/formula/serializer.ts +28 -0
- package/src/widgets/formula/skeleton.tsx +10 -0
- package/src/widgets/formula/style.ts +23 -0
- package/src/widgets/formula/types.ts +50 -0
- package/src/widgets/histogram/config.ts +143 -0
- package/src/widgets/histogram/index.ts +8 -0
- package/src/widgets/histogram/skeleton.tsx +52 -0
- package/src/widgets/histogram/style.ts +8 -0
- package/src/widgets/histogram/types.ts +17 -0
- package/src/widgets/index.ts +25 -0
- package/src/widgets/loader/index.ts +4 -0
- package/src/widgets/loader/loader.tsx +70 -0
- package/src/widgets/loader/types.ts +11 -0
- package/src/widgets/loader/utils.test.ts +112 -0
- package/src/widgets/loader/utils.ts +35 -0
- package/src/widgets/markdown/config.ts +18 -0
- package/src/widgets/markdown/index.ts +14 -0
- package/src/widgets/markdown/markdown-ui.test.tsx +341 -0
- package/src/widgets/markdown/markdown-ui.tsx +52 -0
- package/src/widgets/markdown/markdown.tsx +20 -0
- package/src/widgets/markdown/skeleton.tsx +12 -0
- package/src/widgets/markdown/style.ts +28 -0
- package/src/widgets/markdown/types.ts +28 -0
- package/src/widgets/no-data/index.ts +2 -0
- package/src/widgets/no-data/no-data.test.tsx +447 -0
- package/src/widgets/no-data/no-data.tsx +116 -0
- package/src/widgets/no-data/style.ts +18 -0
- package/src/widgets/no-data/types.ts +72 -0
- package/src/widgets/note/index.ts +2 -0
- package/src/widgets/note/note.test.tsx +391 -0
- package/src/widgets/note/note.tsx +114 -0
- package/src/widgets/note/style.ts +29 -0
- package/src/widgets/note/types.ts +9 -0
- package/src/widgets/pie/config.ts +177 -0
- package/src/widgets/pie/index.ts +8 -0
- package/src/widgets/pie/skeleton.tsx +70 -0
- package/src/widgets/pie/style.ts +8 -0
- package/src/widgets/pie/types.ts +16 -0
- package/src/widgets/range/components/range-item.tsx +213 -0
- package/src/widgets/range/config.ts +10 -0
- package/src/widgets/range/index.ts +16 -0
- package/src/widgets/range/range-ui.test.tsx +203 -0
- package/src/widgets/range/range-ui.tsx +11 -0
- package/src/widgets/range/serializer.test.ts +70 -0
- package/src/widgets/range/serializer.ts +27 -0
- package/src/widgets/range/skeleton.tsx +14 -0
- package/src/widgets/range/style.ts +37 -0
- package/src/widgets/range/types.ts +39 -0
- package/src/widgets/scatterplot/config.ts +138 -0
- package/src/widgets/scatterplot/index.ts +8 -0
- package/src/widgets/scatterplot/skeleton.tsx +59 -0
- package/src/widgets/scatterplot/style.ts +21 -0
- package/src/widgets/scatterplot/types.ts +17 -0
- package/src/widgets/selection-summary/index.ts +6 -0
- package/src/widgets/selection-summary/selection-summary.tsx +46 -0
- package/src/widgets/selection-summary/style.ts +10 -0
- package/src/widgets/selection-summary/types.ts +14 -0
- package/src/widgets/skeleton-loader/index.ts +2 -0
- package/src/widgets/skeleton-loader/skeleton-loader.test.tsx +139 -0
- package/src/widgets/skeleton-loader/skeleton-loader.tsx +28 -0
- package/src/widgets/skeleton-loader/types.ts +8 -0
- package/src/widgets/spread/components/max-value.tsx +29 -0
- package/src/widgets/spread/components/min-value.tsx +29 -0
- package/src/widgets/spread/components/separator.tsx +6 -0
- package/src/widgets/spread/config.ts +34 -0
- package/src/widgets/spread/index.ts +23 -0
- package/src/widgets/spread/skeleton.tsx +10 -0
- package/src/widgets/spread/spread-ui.test.tsx +368 -0
- package/src/widgets/spread/spread-ui.tsx +29 -0
- package/src/widgets/spread/style.ts +22 -0
- package/src/widgets/spread/types.ts +47 -0
- package/src/widgets/stores/index.ts +9 -0
- package/src/widgets/stores/types.ts +192 -0
- package/src/widgets/stores/widget-store.test.ts +601 -0
- package/src/widgets/stores/widget-store.ts +239 -0
- package/src/widgets/subheader/index.ts +3 -0
- package/src/widgets/subheader/style.ts +20 -0
- package/src/widgets/subheader/subheader.test.tsx +45 -0
- package/src/widgets/subheader/subheader.tsx +16 -0
- package/src/widgets/subheader/types.ts +11 -0
- package/src/widgets/table/components/cell-header.tsx +58 -0
- package/src/widgets/table/components/cell.tsx +80 -0
- package/src/widgets/table/components/index.ts +4 -0
- package/src/widgets/table/components/pagination-actions.tsx +67 -0
- package/src/widgets/table/components/pagination.tsx +41 -0
- package/src/widgets/table/components/row.tsx +60 -0
- package/src/widgets/table/config.ts +71 -0
- package/src/widgets/table/helpers.test.ts +244 -0
- package/src/widgets/table/helpers.ts +107 -0
- package/src/widgets/table/hooks/index.ts +7 -0
- package/src/widgets/table/hooks/use-pagination.test.ts +294 -0
- package/src/widgets/table/hooks/use-pagination.ts +155 -0
- package/src/widgets/table/hooks/use-selection.test.ts +504 -0
- package/src/widgets/table/hooks/use-selection.ts +189 -0
- package/src/widgets/table/hooks/use-sort.test.ts +296 -0
- package/src/widgets/table/hooks/use-sort.ts +138 -0
- package/src/widgets/table/index.ts +53 -0
- package/src/widgets/table/serializer.ts +54 -0
- package/src/widgets/table/skeleton.tsx +48 -0
- package/src/widgets/table/style.ts +34 -0
- package/src/widgets/table/table-ui.tsx +64 -0
- package/src/widgets/table/types.ts +223 -0
- package/src/widgets/timeseries/config.ts +135 -0
- package/src/widgets/timeseries/index.ts +8 -0
- package/src/widgets/timeseries/skeleton.tsx +55 -0
- package/src/widgets/timeseries/style.ts +36 -0
- package/src/widgets/timeseries/types.ts +17 -0
- package/src/widgets/toolbar-actions/index.ts +6 -0
- package/src/widgets/toolbar-actions/styles.ts +38 -0
- package/src/widgets/toolbar-actions/toolbar-actions.test.tsx +691 -0
- package/src/widgets/toolbar-actions/toolbar-actions.tsx +145 -0
- package/src/widgets/toolbar-actions/types.ts +60 -0
- package/src/widgets/wrapper/components/actions.test.tsx +101 -0
- package/src/widgets/wrapper/components/actions.tsx +30 -0
- package/src/widgets/wrapper/components/options.test.tsx +323 -0
- package/src/widgets/wrapper/components/options.tsx +73 -0
- package/src/widgets/wrapper/components/title.test.tsx +126 -0
- package/src/widgets/wrapper/components/title.tsx +32 -0
- package/src/widgets/wrapper/index.ts +16 -0
- package/src/widgets/wrapper/styles.ts +98 -0
- package/src/widgets/wrapper/types.ts +55 -0
- package/src/widgets/wrapper/wrapper-ui.test.tsx +232 -0
- package/src/widgets/wrapper/wrapper-ui.tsx +57 -0
- package/src/widgets/wrapper/wrapper.test.tsx +365 -0
- package/src/widgets/wrapper/wrapper.tsx +50 -0
- package/dist/lasso-tool-BwRzEW7k.js.map +0 -1
- package/dist/types/common/common.d.ts +0 -3
- package/dist/types/common/index.d.ts +0 -26
- package/dist/types/common/lasso-tools.d.ts +0 -36
- package/dist/types/common/measurement-tools.d.ts +0 -65
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
import { ArrowDropDown, MoreVertOutlined } from '@mui/icons-material'
|
|
2
|
+
import {
|
|
3
|
+
Box,
|
|
4
|
+
Divider,
|
|
5
|
+
IconButton,
|
|
6
|
+
ListItemIcon,
|
|
7
|
+
ListItemText,
|
|
8
|
+
Menu,
|
|
9
|
+
MenuItem,
|
|
10
|
+
Paper,
|
|
11
|
+
SvgIcon,
|
|
12
|
+
ToggleButton,
|
|
13
|
+
Typography,
|
|
14
|
+
type SxProps,
|
|
15
|
+
type Theme,
|
|
16
|
+
} from '@mui/material'
|
|
17
|
+
import deepmerge from 'deepmerge'
|
|
18
|
+
import {
|
|
19
|
+
useMemo,
|
|
20
|
+
useState,
|
|
21
|
+
type ComponentProps,
|
|
22
|
+
type JSX,
|
|
23
|
+
type MouseEvent,
|
|
24
|
+
type PropsWithChildren,
|
|
25
|
+
type ReactNode,
|
|
26
|
+
} from 'react'
|
|
27
|
+
import type { PickDeep } from 'type-fest'
|
|
28
|
+
import { Tooltip } from '../tooltip/tooltip'
|
|
29
|
+
import type { LassoToolsModes } from '../types'
|
|
30
|
+
import { LassoToolsUIChip } from './chip'
|
|
31
|
+
import { LASSO_TOOLS_LABELS } from './const'
|
|
32
|
+
import { styles } from './styles'
|
|
33
|
+
import type { LassoToolsComponentProps, OptionsChildrenProps } from './types'
|
|
34
|
+
|
|
35
|
+
export function LassoToolsUI({
|
|
36
|
+
enabled,
|
|
37
|
+
values = [],
|
|
38
|
+
actionProps,
|
|
39
|
+
chipProps,
|
|
40
|
+
labels,
|
|
41
|
+
modes,
|
|
42
|
+
modesMapping,
|
|
43
|
+
modeSelected,
|
|
44
|
+
PaperProps: { sx, ...PaperProps } = {},
|
|
45
|
+
onActionToggle,
|
|
46
|
+
onChipToggle,
|
|
47
|
+
onDelete,
|
|
48
|
+
onChangeMode,
|
|
49
|
+
onAllChipToggle,
|
|
50
|
+
onAllDelete,
|
|
51
|
+
ChipsSlot = LassoToolsUI.Chips,
|
|
52
|
+
ActionSlot = LassoToolsUI.Action,
|
|
53
|
+
SecondaryActionsSlot = LassoToolsUI.SecondaryActions,
|
|
54
|
+
OptionsSlot = LassoToolsUI.Options,
|
|
55
|
+
}: LassoToolsComponentProps): JSX.Element {
|
|
56
|
+
const slotArgs = {
|
|
57
|
+
enabled,
|
|
58
|
+
values,
|
|
59
|
+
actionProps,
|
|
60
|
+
chipProps,
|
|
61
|
+
labels,
|
|
62
|
+
modes,
|
|
63
|
+
modesMapping,
|
|
64
|
+
modeSelected,
|
|
65
|
+
PaperProps,
|
|
66
|
+
onActionToggle,
|
|
67
|
+
onChipToggle,
|
|
68
|
+
onDelete,
|
|
69
|
+
onChangeMode,
|
|
70
|
+
onAllChipToggle,
|
|
71
|
+
onAllDelete,
|
|
72
|
+
}
|
|
73
|
+
return (
|
|
74
|
+
<Paper
|
|
75
|
+
sx={{
|
|
76
|
+
...styles.container,
|
|
77
|
+
...sx,
|
|
78
|
+
}}
|
|
79
|
+
{...PaperProps}
|
|
80
|
+
>
|
|
81
|
+
{!!ActionSlot && <ActionSlot {...slotArgs} />}
|
|
82
|
+
{!!OptionsSlot && (
|
|
83
|
+
<Options>
|
|
84
|
+
{(props) => {
|
|
85
|
+
return <OptionsSlot {...slotArgs} {...props} />
|
|
86
|
+
}}
|
|
87
|
+
</Options>
|
|
88
|
+
)}
|
|
89
|
+
{!!ChipsSlot && <ChipsSlot {...slotArgs} />}
|
|
90
|
+
{!!SecondaryActionsSlot && <SecondaryActionsSlot {...slotArgs} />}
|
|
91
|
+
</Paper>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function LassoToolsUIAction({
|
|
96
|
+
actionProps,
|
|
97
|
+
labels,
|
|
98
|
+
enabled,
|
|
99
|
+
children,
|
|
100
|
+
onActionToggle,
|
|
101
|
+
}: PropsWithChildren<
|
|
102
|
+
Pick<
|
|
103
|
+
LassoToolsComponentProps,
|
|
104
|
+
'actionProps' | 'enabled' | 'onActionToggle'
|
|
105
|
+
> & {
|
|
106
|
+
labels?: PickDeep<LassoToolsComponentProps['labels'], 'action'>['action']
|
|
107
|
+
}
|
|
108
|
+
>) {
|
|
109
|
+
const actionState = enabled ? 'active' : 'inactive'
|
|
110
|
+
const actionLabel =
|
|
111
|
+
labels?.tooltip?.[actionState] ??
|
|
112
|
+
LASSO_TOOLS_LABELS.action.tooltip[actionState]
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<Tooltip
|
|
116
|
+
title={actionLabel}
|
|
117
|
+
placement='right'
|
|
118
|
+
{...actionProps?.TooltipProps}
|
|
119
|
+
>
|
|
120
|
+
<ToggleButton
|
|
121
|
+
value='toggle'
|
|
122
|
+
sx={styles.actions.icon}
|
|
123
|
+
onClick={() => onActionToggle(!enabled)}
|
|
124
|
+
aria-label={actionLabel}
|
|
125
|
+
selected={enabled}
|
|
126
|
+
>
|
|
127
|
+
{children}
|
|
128
|
+
</ToggleButton>
|
|
129
|
+
</Tooltip>
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function Options({
|
|
134
|
+
TriggerProps: { Icon = <ArrowDropDown />, sx } = {},
|
|
135
|
+
MenuProps,
|
|
136
|
+
children,
|
|
137
|
+
}: {
|
|
138
|
+
TriggerProps?: {
|
|
139
|
+
Icon?: ReactNode
|
|
140
|
+
sx?: SxProps<Theme>
|
|
141
|
+
}
|
|
142
|
+
MenuProps?: Partial<ComponentProps<typeof Menu>>
|
|
143
|
+
children: (props: OptionsChildrenProps) => JSX.Element
|
|
144
|
+
}) {
|
|
145
|
+
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null)
|
|
146
|
+
|
|
147
|
+
const open = Boolean(anchorEl)
|
|
148
|
+
|
|
149
|
+
const handleToggle = (event: MouseEvent<HTMLButtonElement>) => {
|
|
150
|
+
setAnchorEl(event.currentTarget)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const handleClose = () => {
|
|
154
|
+
setAnchorEl(null)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<>
|
|
159
|
+
<IconButton
|
|
160
|
+
sx={{
|
|
161
|
+
...styles.options.icon,
|
|
162
|
+
...sx,
|
|
163
|
+
}}
|
|
164
|
+
onClick={handleToggle}
|
|
165
|
+
>
|
|
166
|
+
{Icon}
|
|
167
|
+
</IconButton>
|
|
168
|
+
<Menu
|
|
169
|
+
id='lasso-menu'
|
|
170
|
+
anchorEl={anchorEl}
|
|
171
|
+
open={open}
|
|
172
|
+
onClose={handleClose}
|
|
173
|
+
MenuListProps={{
|
|
174
|
+
'aria-labelledby': 'lasso-button',
|
|
175
|
+
sx: styles.options.menu,
|
|
176
|
+
}}
|
|
177
|
+
{...MenuProps}
|
|
178
|
+
>
|
|
179
|
+
<div>
|
|
180
|
+
{children({
|
|
181
|
+
onClose: handleClose,
|
|
182
|
+
})}
|
|
183
|
+
</div>
|
|
184
|
+
</Menu>
|
|
185
|
+
</>
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function ModeList({
|
|
190
|
+
data,
|
|
191
|
+
labels,
|
|
192
|
+
children,
|
|
193
|
+
}: {
|
|
194
|
+
labels?: PickDeep<LassoToolsComponentProps['labels'], 'options'>['options']
|
|
195
|
+
data: LassoToolsComponentProps['modes'][keyof LassoToolsModes][]
|
|
196
|
+
children: ReactNode
|
|
197
|
+
}) {
|
|
198
|
+
if (data.length <= 1) {
|
|
199
|
+
return null
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const modeTitle = labels?.mode?.title ?? LASSO_TOOLS_LABELS.options.mode.title
|
|
203
|
+
|
|
204
|
+
return (
|
|
205
|
+
<>
|
|
206
|
+
<Typography
|
|
207
|
+
variant='subtitle2'
|
|
208
|
+
color='text.secondary'
|
|
209
|
+
sx={styles.options.title}
|
|
210
|
+
>
|
|
211
|
+
{modeTitle}
|
|
212
|
+
</Typography>
|
|
213
|
+
{children}
|
|
214
|
+
</>
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function OptionsList({
|
|
219
|
+
data,
|
|
220
|
+
modeSelected,
|
|
221
|
+
labels,
|
|
222
|
+
onChangeMode,
|
|
223
|
+
onClose,
|
|
224
|
+
}: Required<Pick<LassoToolsComponentProps, 'modeSelected' | 'onChangeMode'>> & {
|
|
225
|
+
labels?: PickDeep<LassoToolsComponentProps['labels'], 'options'>['options']
|
|
226
|
+
data: (LassoToolsComponentProps['modes'] &
|
|
227
|
+
LassoToolsComponentProps['modesMapping'])[keyof LassoToolsModes][]
|
|
228
|
+
onClose: OptionsChildrenProps['onClose']
|
|
229
|
+
}) {
|
|
230
|
+
const handleClick = (
|
|
231
|
+
e: MouseEvent<HTMLLIElement>,
|
|
232
|
+
value: (typeof data)[number]['value'],
|
|
233
|
+
) => {
|
|
234
|
+
e.preventDefault()
|
|
235
|
+
onChangeMode?.(value)
|
|
236
|
+
onClose()
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return data.map((mode) => {
|
|
240
|
+
const options =
|
|
241
|
+
labels?.mode?.options ?? LASSO_TOOLS_LABELS.options.mode.options
|
|
242
|
+
const label = options[mode.value]
|
|
243
|
+
|
|
244
|
+
return (
|
|
245
|
+
<MenuItem
|
|
246
|
+
key={mode.value}
|
|
247
|
+
disabled={!!mode.disabled}
|
|
248
|
+
onClick={(e) => handleClick(e, mode.value)}
|
|
249
|
+
selected={mode.value === modeSelected}
|
|
250
|
+
>
|
|
251
|
+
<ListItemIcon sx={styles.options.icons}>
|
|
252
|
+
<SvgIcon>{mode.icon}</SvgIcon>
|
|
253
|
+
</ListItemIcon>
|
|
254
|
+
<ListItemText>{label}</ListItemText>
|
|
255
|
+
</MenuItem>
|
|
256
|
+
)
|
|
257
|
+
})
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function SecondaryActionsWrapper({
|
|
261
|
+
values,
|
|
262
|
+
labels,
|
|
263
|
+
onAllChipToggle,
|
|
264
|
+
onAllDelete,
|
|
265
|
+
}: Partial<
|
|
266
|
+
Omit<
|
|
267
|
+
LassoToolsComponentProps,
|
|
268
|
+
'ChipsSlot' | 'ActionsSlot' | 'OptionsSlot' | 'SecondaryActionsSlot'
|
|
269
|
+
>
|
|
270
|
+
>) {
|
|
271
|
+
if (!values?.length || values.length <= 1) {
|
|
272
|
+
return null
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const hasVisible = values?.some((value) => value.visible)
|
|
276
|
+
|
|
277
|
+
const toggleAllLabel = hasVisible
|
|
278
|
+
? (labels?.actions?.toggleAll?.active ??
|
|
279
|
+
LASSO_TOOLS_LABELS.actions.toggleAll.active)
|
|
280
|
+
: (labels?.actions?.toggleAll?.inactive ??
|
|
281
|
+
LASSO_TOOLS_LABELS.actions.toggleAll.inactive)
|
|
282
|
+
|
|
283
|
+
const deleteAllLabel =
|
|
284
|
+
labels?.actions?.deleteAll ?? LASSO_TOOLS_LABELS.actions.deleteAll
|
|
285
|
+
|
|
286
|
+
return (
|
|
287
|
+
<>
|
|
288
|
+
<Divider orientation='vertical' flexItem />
|
|
289
|
+
<Options
|
|
290
|
+
TriggerProps={{ Icon: <MoreVertOutlined />, sx: styles.options.more }}
|
|
291
|
+
MenuProps={{
|
|
292
|
+
anchorOrigin: {
|
|
293
|
+
vertical: 'bottom',
|
|
294
|
+
horizontal: 'right',
|
|
295
|
+
},
|
|
296
|
+
transformOrigin: {
|
|
297
|
+
vertical: 'top',
|
|
298
|
+
horizontal: 'right',
|
|
299
|
+
},
|
|
300
|
+
}}
|
|
301
|
+
>
|
|
302
|
+
{(props) => {
|
|
303
|
+
return (
|
|
304
|
+
<>
|
|
305
|
+
<MenuItem
|
|
306
|
+
color='inherit'
|
|
307
|
+
onClick={() => {
|
|
308
|
+
onAllChipToggle?.()
|
|
309
|
+
props.onClose()
|
|
310
|
+
}}
|
|
311
|
+
>
|
|
312
|
+
{toggleAllLabel}
|
|
313
|
+
</MenuItem>
|
|
314
|
+
<Divider />
|
|
315
|
+
<MenuItem
|
|
316
|
+
color='error'
|
|
317
|
+
onClick={() => {
|
|
318
|
+
onAllDelete?.()
|
|
319
|
+
props.onClose()
|
|
320
|
+
}}
|
|
321
|
+
>
|
|
322
|
+
<Typography variant='body2' color='error'>
|
|
323
|
+
{deleteAllLabel}
|
|
324
|
+
</Typography>
|
|
325
|
+
</MenuItem>
|
|
326
|
+
</>
|
|
327
|
+
)
|
|
328
|
+
}}
|
|
329
|
+
</Options>
|
|
330
|
+
</>
|
|
331
|
+
)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
LassoToolsUI.Action = function ActionsWrapper({
|
|
335
|
+
modes,
|
|
336
|
+
modesMapping,
|
|
337
|
+
modeSelected,
|
|
338
|
+
actionProps,
|
|
339
|
+
enabled,
|
|
340
|
+
labels,
|
|
341
|
+
onActionToggle,
|
|
342
|
+
}: Partial<
|
|
343
|
+
Omit<
|
|
344
|
+
LassoToolsComponentProps,
|
|
345
|
+
'ChipsSlot' | 'ActionsSlot' | 'OptionsSlot' | 'SecondaryActionsSlot'
|
|
346
|
+
>
|
|
347
|
+
> & {
|
|
348
|
+
labels?: PickDeep<LassoToolsComponentProps['labels'], 'actions'>['actions']
|
|
349
|
+
}) {
|
|
350
|
+
const data = useMemo(() => {
|
|
351
|
+
return deepmerge(modes ?? {}, modesMapping ?? {})
|
|
352
|
+
}, [modes, modesMapping])
|
|
353
|
+
|
|
354
|
+
const handleToggle: LassoToolsComponentProps['onActionToggle'] = (data) => {
|
|
355
|
+
return onActionToggle?.(data)
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const modeExists = modeSelected ? modeSelected in (modes ?? {}) : false
|
|
359
|
+
|
|
360
|
+
const mode = (
|
|
361
|
+
modeExists ? modeSelected : Object.keys(data)[0]
|
|
362
|
+
) as keyof typeof data
|
|
363
|
+
|
|
364
|
+
const modeSelectedValue = data[mode]
|
|
365
|
+
|
|
366
|
+
return (
|
|
367
|
+
<LassoToolsUIAction
|
|
368
|
+
actionProps={actionProps}
|
|
369
|
+
labels={labels?.action}
|
|
370
|
+
enabled={enabled ?? false}
|
|
371
|
+
onActionToggle={handleToggle}
|
|
372
|
+
>
|
|
373
|
+
{modeSelectedValue?.icon}
|
|
374
|
+
</LassoToolsUIAction>
|
|
375
|
+
)
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
LassoToolsUI.Chips = function ChipsWrapper({
|
|
379
|
+
values,
|
|
380
|
+
labels,
|
|
381
|
+
chipProps,
|
|
382
|
+
onDelete,
|
|
383
|
+
onChipToggle,
|
|
384
|
+
onActionToggle,
|
|
385
|
+
}: Partial<
|
|
386
|
+
Omit<
|
|
387
|
+
LassoToolsComponentProps,
|
|
388
|
+
'ChipsSlot' | 'ActionsSlot' | 'OptionsSlot' | 'SecondaryActionsSlot'
|
|
389
|
+
>
|
|
390
|
+
>) {
|
|
391
|
+
const handleDelete: LassoToolsComponentProps['onDelete'] = (valueId) => {
|
|
392
|
+
onActionToggle?.(false)
|
|
393
|
+
return onDelete?.(valueId)
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return (
|
|
397
|
+
!!values?.length && (
|
|
398
|
+
<Box sx={styles.chip.container}>
|
|
399
|
+
{values?.map((value) => (
|
|
400
|
+
<LassoToolsUIChip
|
|
401
|
+
key={value.id}
|
|
402
|
+
value={value}
|
|
403
|
+
labels={labels?.chip}
|
|
404
|
+
chipProps={chipProps}
|
|
405
|
+
onDelete={handleDelete}
|
|
406
|
+
onChipToggle={(id, data) => onChipToggle?.(id, data)}
|
|
407
|
+
/>
|
|
408
|
+
))}
|
|
409
|
+
</Box>
|
|
410
|
+
)
|
|
411
|
+
)
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
LassoToolsUI.SecondaryActions = SecondaryActionsWrapper
|
|
415
|
+
|
|
416
|
+
LassoToolsUI.Options = function OptionsWrapper({
|
|
417
|
+
values,
|
|
418
|
+
modes,
|
|
419
|
+
modesMapping,
|
|
420
|
+
modeSelected,
|
|
421
|
+
labels,
|
|
422
|
+
onChangeMode,
|
|
423
|
+
...props
|
|
424
|
+
}: Partial<
|
|
425
|
+
Omit<
|
|
426
|
+
LassoToolsComponentProps,
|
|
427
|
+
'ChipsSlot' | 'ActionsSlot' | 'OptionsSlot' | 'SecondaryActionsSlot'
|
|
428
|
+
>
|
|
429
|
+
> &
|
|
430
|
+
OptionsChildrenProps) {
|
|
431
|
+
const data = useMemo(() => {
|
|
432
|
+
return deepmerge(modes ?? {}, modesMapping ?? {})
|
|
433
|
+
}, [modes, modesMapping])
|
|
434
|
+
|
|
435
|
+
const { edit, ..._modes } = data
|
|
436
|
+
|
|
437
|
+
const modeExists = modeSelected ? modeSelected in (modes ?? {}) : false
|
|
438
|
+
|
|
439
|
+
const mode = (
|
|
440
|
+
modeExists ? modeSelected : Object.keys(data)[0]
|
|
441
|
+
) as keyof typeof data
|
|
442
|
+
|
|
443
|
+
const modesValues = Object.values(_modes)
|
|
444
|
+
|
|
445
|
+
const handleChangeMode: LassoToolsComponentProps['onChangeMode'] = (data) => {
|
|
446
|
+
return onChangeMode?.(data)
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
return (
|
|
450
|
+
<>
|
|
451
|
+
<ModeList data={modesValues} labels={labels?.options}>
|
|
452
|
+
<OptionsList
|
|
453
|
+
{...props}
|
|
454
|
+
labels={labels?.options}
|
|
455
|
+
data={modesValues}
|
|
456
|
+
modeSelected={mode}
|
|
457
|
+
onChangeMode={handleChangeMode}
|
|
458
|
+
/>
|
|
459
|
+
</ModeList>
|
|
460
|
+
{!!edit && (
|
|
461
|
+
<>
|
|
462
|
+
<Divider />
|
|
463
|
+
<OptionsList
|
|
464
|
+
{...props}
|
|
465
|
+
labels={labels?.options}
|
|
466
|
+
data={[
|
|
467
|
+
{
|
|
468
|
+
...edit,
|
|
469
|
+
disabled: !values?.length,
|
|
470
|
+
},
|
|
471
|
+
]}
|
|
472
|
+
modeSelected={mode}
|
|
473
|
+
onChangeMode={handleChangeMode}
|
|
474
|
+
/>
|
|
475
|
+
</>
|
|
476
|
+
)}
|
|
477
|
+
</>
|
|
478
|
+
)
|
|
479
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { alpha, type SxProps, type Theme } from '@mui/material'
|
|
2
|
+
|
|
3
|
+
export const styles = {
|
|
4
|
+
container: {
|
|
5
|
+
display: 'flex',
|
|
6
|
+
flexDirection: 'row',
|
|
7
|
+
alignItems: 'center',
|
|
8
|
+
justifyContent: 'flex-start',
|
|
9
|
+
overflow: 'hidden',
|
|
10
|
+
|
|
11
|
+
'&.inline': {
|
|
12
|
+
flexDirection: 'column',
|
|
13
|
+
alignItems: 'flex-start',
|
|
14
|
+
gap: ({ spacing }) => spacing(1),
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
actions: {
|
|
18
|
+
icon: {
|
|
19
|
+
width: ({ spacing }) => spacing(4),
|
|
20
|
+
height: ({ spacing }) => spacing(4),
|
|
21
|
+
borderRadius: 0,
|
|
22
|
+
'.MuiTouchRipple-ripple .MuiTouchRipple-child': {
|
|
23
|
+
borderRadius: 0,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
options: {
|
|
28
|
+
menu: {
|
|
29
|
+
paddingTop: ({ spacing }) => spacing(1),
|
|
30
|
+
'&.inline': {
|
|
31
|
+
boxShadow: 'none',
|
|
32
|
+
backgroundColor: 'transparent',
|
|
33
|
+
borderRadius: ({ spacing }) => spacing(0.5),
|
|
34
|
+
|
|
35
|
+
'& .MuiDivider-root': {
|
|
36
|
+
height: ({ spacing }) => spacing(4),
|
|
37
|
+
|
|
38
|
+
'&.MuiToggleButtonGroup-groupedHorizontal': {
|
|
39
|
+
height: ({ spacing }) => spacing(4),
|
|
40
|
+
},
|
|
41
|
+
'&.MuiToggleButtonGroup-groupedVertical': {
|
|
42
|
+
height: 'auto',
|
|
43
|
+
width: ({ spacing }) => spacing(4),
|
|
44
|
+
margin: ({ spacing }) => `${spacing(0.5, 0, 1)} !important`,
|
|
45
|
+
borderRadius: '0 !important',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
'& .MuiToggleButton-sizeSmall': {
|
|
50
|
+
margin: 0,
|
|
51
|
+
|
|
52
|
+
'&.MuiToggleButtonGroup-grouped:not(.MuiDivider-root)': {
|
|
53
|
+
margin: 0,
|
|
54
|
+
},
|
|
55
|
+
'& + .MuiDivider-root.MuiToggleButtonGroup-groupedHorizontal': {
|
|
56
|
+
height: ({ spacing }) => spacing(3),
|
|
57
|
+
},
|
|
58
|
+
'& + .MuiDivider-root.MuiToggleButtonGroup-groupedVertical': {
|
|
59
|
+
height: 'auto',
|
|
60
|
+
width: ({ spacing }) => spacing(3),
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
'.MuiToggleButtonGroup-grouped:not(.MuiDivider-root)': {
|
|
65
|
+
margin: 0,
|
|
66
|
+
|
|
67
|
+
'&:first-of-type': {
|
|
68
|
+
marginLeft: 0,
|
|
69
|
+
},
|
|
70
|
+
'&:not(:last-of-type)': {
|
|
71
|
+
marginRight: ({ spacing }) => spacing(0.5),
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
'&.MuiToggleButtonGroup-horizontal:not(.MuiDivider-root)': {
|
|
75
|
+
'.MuiToggleButtonGroup-grouped': {
|
|
76
|
+
margin: ({ spacing }) => spacing(0, 0.5),
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
'&.MuiToggleButtonGroup-vertical:not(.MuiDivider-root)': {
|
|
80
|
+
'.MuiToggleButtonGroup-grouped': {
|
|
81
|
+
margin: ({ spacing }) => spacing(0, 0, 0.5),
|
|
82
|
+
|
|
83
|
+
'&:not(:last-of-type)': {
|
|
84
|
+
marginRight: 0,
|
|
85
|
+
},
|
|
86
|
+
'&:last-of-type': {
|
|
87
|
+
marginBottom: 0,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
icon: {
|
|
94
|
+
borderRadius: 0,
|
|
95
|
+
width: ({ spacing }) => spacing(3),
|
|
96
|
+
},
|
|
97
|
+
title: {
|
|
98
|
+
paddingX: ({ spacing }) => spacing(2),
|
|
99
|
+
paddingBottom: ({ spacing }) => spacing(0.5),
|
|
100
|
+
|
|
101
|
+
'&.inline': {
|
|
102
|
+
paddingX: 0,
|
|
103
|
+
paddingBottom: 0,
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
icons: {
|
|
107
|
+
color: ({ palette }) => palette.text.primary,
|
|
108
|
+
},
|
|
109
|
+
tag: {
|
|
110
|
+
borderRadius: ({ spacing }) => spacing(0.25),
|
|
111
|
+
border: '1px solid',
|
|
112
|
+
borderColor: ({ palette }) => palette.primary.main,
|
|
113
|
+
paddingX: ({ spacing }) => spacing(0.5),
|
|
114
|
+
color: ({ palette }) => palette.primary.main,
|
|
115
|
+
backgroundColor: ({ palette }) => alpha(palette.primary.main, 0.08),
|
|
116
|
+
},
|
|
117
|
+
more: {
|
|
118
|
+
width: ({ spacing }) => spacing(4),
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
chip: {
|
|
122
|
+
container: {
|
|
123
|
+
display: 'flex',
|
|
124
|
+
flexDirection: 'row',
|
|
125
|
+
alignItems: 'center',
|
|
126
|
+
gap: ({ spacing }) => spacing(0.5),
|
|
127
|
+
overflowX: 'auto',
|
|
128
|
+
scrollbarWidth: 'none',
|
|
129
|
+
paddingX: ({ spacing }) => spacing(1),
|
|
130
|
+
|
|
131
|
+
'&.inline': {
|
|
132
|
+
overflowX: 'visible',
|
|
133
|
+
flexWrap: 'wrap',
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
chip: {
|
|
137
|
+
marginRight: ({ spacing }) => spacing(0.5),
|
|
138
|
+
},
|
|
139
|
+
disabled: {
|
|
140
|
+
opacity: ({ palette }) => palette.action.disabledOpacity,
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
} satisfies Record<string, SxProps<Theme>>
|