@terraware/web-components 3.5.3 → 3.5.4

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.
@@ -2,7 +2,7 @@ import './styles.scss';
2
2
  export type AntSwitchProps = {
3
3
  checked?: boolean;
4
4
  disabled?: boolean;
5
- onChange: (checked: boolean) => void;
5
+ onChange?: (checked: boolean) => void;
6
6
  };
7
7
  declare const AntSwitch: (props: AntSwitchProps) => import("react/jsx-runtime").JSX.Element;
8
8
  export default AntSwitch;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/AntSwitch/index.tsx"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC;AAEvB,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CACtC,CAAC;AAEF,QAAA,MAAM,SAAS,UAAW,cAAc,4CAQvC,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/AntSwitch/index.tsx"],"names":[],"mappings":"AAEA,OAAO,eAAe,CAAC;AAEvB,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CACvC,CAAC;AAEF,QAAA,MAAM,SAAS,UAAW,cAAc,4CAQvC,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -15,7 +15,7 @@ const AntSwitch = props => {
15
15
  onChange
16
16
  } = props;
17
17
  const onChangeHandler = (0, _react.useCallback)((event, value) => {
18
- onChange(value);
18
+ onChange === null || onChange === void 0 ? void 0 : onChange(value);
19
19
  }, [onChange]);
20
20
  return /*#__PURE__*/_react.default.createElement(_material.Switch, {
21
21
  className: "ant-switch",
@@ -0,0 +1,59 @@
1
+ /// <reference types="react" />
2
+ import { IconName } from '../Icon/icons';
3
+ export type MapLayerItem = {
4
+ disabled?: boolean;
5
+ id: string;
6
+ label: string;
7
+ style: {
8
+ borderColor: string;
9
+ fillColor?: string;
10
+ fillPatternUrl?: string;
11
+ opacity?: number;
12
+ };
13
+ };
14
+ export type MapLayerGroup = {
15
+ type: 'layer';
16
+ items: MapLayerItem[];
17
+ setSelectedLayer: (id: string) => void;
18
+ selectedLayer: string;
19
+ };
20
+ export type MapFeatureItem = {
21
+ disabled?: boolean;
22
+ icon: IconName;
23
+ iconColor: string;
24
+ iconOpacity?: number;
25
+ id: string;
26
+ label: string;
27
+ setVisible?: (visible: boolean) => void;
28
+ visible: boolean;
29
+ };
30
+ export type MapFeatureGroup = {
31
+ type: 'feature';
32
+ items: MapFeatureItem[];
33
+ };
34
+ export type MapHighlightItem = {
35
+ label: string;
36
+ style: {
37
+ borderColor: string;
38
+ fillColor?: string;
39
+ fillPatternUrl?: string;
40
+ opacity?: number;
41
+ };
42
+ };
43
+ export type MapHighlightGroup = {
44
+ type: 'highlight';
45
+ items: MapHighlightItem[];
46
+ setVisible?: (visible: boolean) => void;
47
+ visible: boolean;
48
+ };
49
+ export type MapLegendGroup = {
50
+ disabled?: boolean;
51
+ tooltip?: string;
52
+ title: string;
53
+ } & (MapFeatureGroup | MapLayerGroup | MapHighlightGroup);
54
+ export type MapLegendProps = {
55
+ legends: MapLegendGroup[];
56
+ };
57
+ declare const MapLegend: ({ legends }: MapLegendProps) => JSX.Element;
58
+ export default MapLegend;
59
+ //# sourceMappingURL=MapLegend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapLegend.d.ts","sourceRoot":"","sources":["../../../src/components/Map/MapLegend.tsx"],"names":[],"mappings":";AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,MAAM,M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AC;IAClB,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACxC,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,CAAC,eAAe,GAAG,aAAa,GAAG,iBAAiB,CAAC,CAAC;AAE1D,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,cAAc,EAAE,CAAC;CAC3B,CAAC;AAEF,QAAA,MAAM,SAAS,gBAAiB,cAAc,KAAG,WAyNhD,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _material = require("@mui/material");
10
+ var _utils = require("../../utils");
11
+ var _Icon = _interopRequireDefault(require("../Icon/Icon"));
12
+ var _AntSwitch = _interopRequireDefault(require("../AntSwitch"));
13
+ const MapLegend = _ref => {
14
+ let {
15
+ legends
16
+ } = _ref;
17
+ const theme = (0, _material.useTheme)();
18
+ const {
19
+ isMobile,
20
+ isDesktop
21
+ } = (0, _utils.useDeviceInfo)();
22
+ const legendComponents = legends.map((legend, index) => {
23
+ const isFirst = index === 0;
24
+ const isLast = index === legends.length - 1;
25
+ const switchComponent = legend.type === 'highlight' ? /*#__PURE__*/_react.default.createElement(_AntSwitch.default, {
26
+ disabled: legend.disabled,
27
+ checked: legend.visible,
28
+ onChange: legend.setVisible
29
+ }) : undefined;
30
+ const titleComponent = /*#__PURE__*/_react.default.createElement(_material.Typography, {
31
+ fontSize: "16px",
32
+ fontWeight: 600,
33
+ width: isMobile ? '100%' : undefined,
34
+ marginRight: isMobile ? 0 : theme.spacing(4),
35
+ paddingLeft: switchComponent ? theme.spacing(1) : theme.spacing(0)
36
+ }, legend.title, legend.tooltip && /*#__PURE__*/_react.default.createElement(_material.Tooltip, {
37
+ title: legend.tooltip,
38
+ sx: {
39
+ display: 'inline-block',
40
+ verticalAlign: 'text-top',
41
+ marginLeft: theme.spacing(1)
42
+ }
43
+ }, /*#__PURE__*/_react.default.createElement(_material.Box, {
44
+ display: "flex"
45
+ }, /*#__PURE__*/_react.default.createElement(_Icon.default, {
46
+ fillColor: theme.palette.TwClrIcnInfo,
47
+ name: "info",
48
+ size: "small"
49
+ }))));
50
+ const itemComponents = legend.items.map((item, itemIndex) => {
51
+ const onClick = legend.disabled ? undefined : legend.type === 'layer' ? item.disabled ? undefined : () => legend.setSelectedLayer(item.id) : legend.type === 'feature' ? item.disabled ? undefined : () => {
52
+ var _setVisible, _ref2;
53
+ return (_setVisible = (_ref2 = item).setVisible) === null || _setVisible === void 0 ? void 0 : _setVisible.call(_ref2, !item.visible);
54
+ } : undefined;
55
+ const disabled = legend.disabled || (legend.type === 'layer' ? item.disabled : legend.type === 'feature' ? item.disabled : false) || false;
56
+ const selected = legend.type === 'layer' ? item.id === legend.selectedLayer : legend.type === 'feature' ? item.visible : false;
57
+ const logoComponent = () => {
58
+ var _layerItem$style$opac;
59
+ switch (legend.type) {
60
+ case 'feature':
61
+ const featureItem = item;
62
+ return /*#__PURE__*/_react.default.createElement(_Icon.default, {
63
+ name: featureItem.icon,
64
+ fillColor: featureItem.iconColor,
65
+ style: {
66
+ marginRight: theme.spacing(1),
67
+ opacity: featureItem.iconOpacity
68
+ },
69
+ size: 'small'
70
+ });
71
+ case 'layer':
72
+ case 'highlight':
73
+ const layerItem = item;
74
+ const opacity = (_layerItem$style$opac = layerItem.style.opacity) !== null && _layerItem$style$opac !== void 0 ? _layerItem$style$opac : 1.0;
75
+ return /*#__PURE__*/_react.default.createElement(_material.Box, {
76
+ sx: {
77
+ border: "2px solid ".concat(layerItem.style.borderColor),
78
+ backgroundColor: layerItem.style.fillColor,
79
+ backgroundImage: layerItem.style.fillPatternUrl ? "url('".concat(layerItem.style.fillPatternUrl, "')") : undefined,
80
+ backgroundRepeat: 'repeat',
81
+ opacity: disabled ? 0.7 * opacity : opacity,
82
+ height: '16px',
83
+ width: '24px',
84
+ minWidth: '24px',
85
+ marginRight: theme.spacing(1)
86
+ }
87
+ });
88
+ }
89
+ };
90
+ const visibleComponent = () => {
91
+ switch (legend.type) {
92
+ case 'feature':
93
+ const featureItem = item;
94
+ const visibleIcon = featureItem.visible ? /*#__PURE__*/_react.default.createElement(_Icon.default, {
95
+ name: "iconEye"
96
+ }) : /*#__PURE__*/_react.default.createElement(_Icon.default, {
97
+ name: "iconEyeOff"
98
+ });
99
+ return /*#__PURE__*/_react.default.createElement(_material.Box, {
100
+ display: "flex"
101
+ }, visibleIcon);
102
+ case 'layer':
103
+ const layerLegend = legend;
104
+ const layerItem = item;
105
+ return /*#__PURE__*/_react.default.createElement(_material.Box, {
106
+ display: "flex",
107
+ sx: {
108
+ visibility: layerItem.id === layerLegend.selectedLayer ? 'visible' : 'hidden'
109
+ }
110
+ }, /*#__PURE__*/_react.default.createElement(_Icon.default, {
111
+ name: "checkmark",
112
+ style: {
113
+ marginRight: theme.spacing(1)
114
+ }
115
+ }));
116
+ case 'highlight':
117
+ return undefined;
118
+ }
119
+ };
120
+ return /*#__PURE__*/_react.default.createElement(_material.Box, {
121
+ onClick: onClick,
122
+ display: "flex",
123
+ alignItems: "center",
124
+ sx: {
125
+ cursor: onClick ? 'pointer' : 'default',
126
+ background: selected ? theme.palette.TwClrBgSecondary : 'none',
127
+ borderRadius: theme.spacing(1),
128
+ padding: theme.spacing(1, 1),
129
+ opacity: disabled ? '0.5' : 1
130
+ },
131
+ justifyContent: 'space-between',
132
+ key: "".concat(index, "-").concat(itemIndex)
133
+ }, /*#__PURE__*/_react.default.createElement(_material.Box, {
134
+ display: "flex",
135
+ alignItems: "center",
136
+ paddingRight: theme.spacing(1)
137
+ }, logoComponent(), /*#__PURE__*/_react.default.createElement(_material.Typography, {
138
+ fontSize: "14px",
139
+ fontWeight: 400
140
+ }, item.label)), /*#__PURE__*/_react.default.createElement(_material.Box, {
141
+ display: "flex"
142
+ }, visibleComponent()));
143
+ });
144
+ return /*#__PURE__*/_react.default.createElement(_material.Box, {
145
+ key: legend.title,
146
+ sx: {
147
+ opacity: legend.disabled ? 0.7 : 1
148
+ },
149
+ borderBottom: isLast ? 'none' : "1px solid ".concat(theme.palette.TwClrBrdrTertiary)
150
+ }, /*#__PURE__*/_react.default.createElement(_material.Box, {
151
+ paddingBottom: 2,
152
+ paddingTop: isFirst ? 0 : 2,
153
+ flexDirection: 'column'
154
+ }, /*#__PURE__*/_react.default.createElement(_material.Box, {
155
+ display: "flex",
156
+ alignItems: 'center',
157
+ paddingLeft: theme.spacing(1)
158
+ }, switchComponent, titleComponent), itemComponents));
159
+ });
160
+ return /*#__PURE__*/_react.default.createElement(_material.Box, {
161
+ display: "flex",
162
+ justifyItems: "flex-start",
163
+ border: "1px solid ".concat(theme.palette.TwClrBrdrTertiary),
164
+ borderRadius: "8px",
165
+ padding: theme.spacing(2, 1),
166
+ flexDirection: 'column',
167
+ maxWidth: isDesktop ? '184px' : '100%',
168
+ width: isDesktop ? 'auto' : '100%',
169
+ marginRight: 2,
170
+ marginTop: isDesktop ? 0 : 2
171
+ }, legendComponents);
172
+ };
173
+ var _default = exports.default = MapLegend;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terraware/web-components",
3
- "version": "3.5.3",
3
+ "version": "3.5.4",
4
4
  "author": "Terraformation Inc.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { MapLegendProps } from '../components/Map/MapLegend';
3
+ declare const _default: {
4
+ title: string;
5
+ component: ({ legends }: MapLegendProps) => JSX.Element;
6
+ };
7
+ export default _default;
8
+ export declare const Default: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, MapLegendProps>;
9
+ //# sourceMappingURL=MapLegend.stories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapLegend.stories.d.ts","sourceRoot":"","sources":["../../src/stories/MapLegend.stories.tsx"],"names":[],"mappings":";AAEA,OAAkB,EAAkB,cAAc,EAAE,MAAM,6BAA6B,CAAC;;;;;AAKxF,wBAGE;AAuKF,eAAO,MAAM,OAAO,uGAAoB,CAAC"}