@trackunit/react-components 0.1.398 → 0.1.400
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/index.cjs.js +30 -0
- package/index.esm.js +30 -1
- package/package.json +1 -1
- package/src/components/Polygon/Polygon.d.ts +16 -0
- package/src/components/index.d.ts +2 -1
package/index.cjs.js
CHANGED
|
@@ -4277,6 +4277,35 @@ const Pagination = ({ previousPage, nextPage, canPreviousPage, canNextPage, page
|
|
|
4277
4277
|
: page !== undefined && pageCount !== undefined && pageCount !== null && page >= pageCount - 1, icon: jsxRuntime.jsx(Icon, { name: "ChevronRight", size: "small" }), onClick: () => handlePageChange("next"), size: "small", variant: "ghost-neutral" })] }));
|
|
4278
4278
|
};
|
|
4279
4279
|
|
|
4280
|
+
const STROKE_WIDTH_THRESHOLD = 32;
|
|
4281
|
+
/**
|
|
4282
|
+
* Draws an svg Polygon from a set of points.
|
|
4283
|
+
*
|
|
4284
|
+
* @param { PolygonProps} props - The props for the Polygon component
|
|
4285
|
+
* @returns {JSX.Element} Polygon component
|
|
4286
|
+
*/
|
|
4287
|
+
const Polygon = ({ points, size, color = "black", opaque = true, className, dataTestId }) => {
|
|
4288
|
+
// Calculate the bounds of the points
|
|
4289
|
+
const minX = Math.min(...points.map(coord => coord[0]));
|
|
4290
|
+
const maxX = Math.max(...points.map(coord => coord[0]));
|
|
4291
|
+
const minY = Math.min(...points.map(coord => coord[1]));
|
|
4292
|
+
const maxY = Math.max(...points.map(coord => coord[1]));
|
|
4293
|
+
const strokeWidth = size >= STROKE_WIDTH_THRESHOLD ? 2 : 1;
|
|
4294
|
+
const sizeToNormalizeAgainst = size - strokeWidth * 2; // because strole is centered, so will be clipped on the outside otherwise
|
|
4295
|
+
// Normalize the points to fit within the viewBox
|
|
4296
|
+
const normalizedPoints = points
|
|
4297
|
+
.map(([x, y]) => `${normalize({ value: x, min: minX, max: maxX, size: sizeToNormalizeAgainst })},${normalize({ value: y, min: minY, max: maxY, size: sizeToNormalizeAgainst })}`)
|
|
4298
|
+
.join(" ");
|
|
4299
|
+
return (jsxRuntime.jsx("svg", { className: className, "data-testid": dataTestId, height: size, style: { width: `${size}px`, height: `${size}px` }, viewBox: `0 0 ${size} ${size}`, width: size, xmlns: "http://www.w3.org/2000/svg", children: jsxRuntime.jsx("polygon", { points: normalizedPoints, style: {
|
|
4300
|
+
fill: color,
|
|
4301
|
+
fillOpacity: opaque ? 0.2 : undefined,
|
|
4302
|
+
stroke: color,
|
|
4303
|
+
strokeOpacity: opaque ? 0.8 : undefined,
|
|
4304
|
+
strokeWidth,
|
|
4305
|
+
}, transform: `translate(${strokeWidth}, ${strokeWidth})` }) }));
|
|
4306
|
+
};
|
|
4307
|
+
const normalize = ({ value, min, max, size }) => ((value - min) / (max - min)) * size;
|
|
4308
|
+
|
|
4280
4309
|
function useConfirmExit(confirmExit, when = true) {
|
|
4281
4310
|
reactRouter.useBlocker(confirmExit, when);
|
|
4282
4311
|
}
|
|
@@ -4892,6 +4921,7 @@ exports.Page = Page;
|
|
|
4892
4921
|
exports.PageContent = PageContent;
|
|
4893
4922
|
exports.PageHeader = PageHeader;
|
|
4894
4923
|
exports.Pagination = Pagination;
|
|
4924
|
+
exports.Polygon = Polygon;
|
|
4895
4925
|
exports.Popover = Popover;
|
|
4896
4926
|
exports.PopoverContent = PopoverContent;
|
|
4897
4927
|
exports.PopoverTitle = PopoverTitle;
|
package/index.esm.js
CHANGED
|
@@ -4257,6 +4257,35 @@ const Pagination = ({ previousPage, nextPage, canPreviousPage, canNextPage, page
|
|
|
4257
4257
|
: page !== undefined && pageCount !== undefined && pageCount !== null && page >= pageCount - 1, icon: jsx(Icon, { name: "ChevronRight", size: "small" }), onClick: () => handlePageChange("next"), size: "small", variant: "ghost-neutral" })] }));
|
|
4258
4258
|
};
|
|
4259
4259
|
|
|
4260
|
+
const STROKE_WIDTH_THRESHOLD = 32;
|
|
4261
|
+
/**
|
|
4262
|
+
* Draws an svg Polygon from a set of points.
|
|
4263
|
+
*
|
|
4264
|
+
* @param { PolygonProps} props - The props for the Polygon component
|
|
4265
|
+
* @returns {JSX.Element} Polygon component
|
|
4266
|
+
*/
|
|
4267
|
+
const Polygon = ({ points, size, color = "black", opaque = true, className, dataTestId }) => {
|
|
4268
|
+
// Calculate the bounds of the points
|
|
4269
|
+
const minX = Math.min(...points.map(coord => coord[0]));
|
|
4270
|
+
const maxX = Math.max(...points.map(coord => coord[0]));
|
|
4271
|
+
const minY = Math.min(...points.map(coord => coord[1]));
|
|
4272
|
+
const maxY = Math.max(...points.map(coord => coord[1]));
|
|
4273
|
+
const strokeWidth = size >= STROKE_WIDTH_THRESHOLD ? 2 : 1;
|
|
4274
|
+
const sizeToNormalizeAgainst = size - strokeWidth * 2; // because strole is centered, so will be clipped on the outside otherwise
|
|
4275
|
+
// Normalize the points to fit within the viewBox
|
|
4276
|
+
const normalizedPoints = points
|
|
4277
|
+
.map(([x, y]) => `${normalize({ value: x, min: minX, max: maxX, size: sizeToNormalizeAgainst })},${normalize({ value: y, min: minY, max: maxY, size: sizeToNormalizeAgainst })}`)
|
|
4278
|
+
.join(" ");
|
|
4279
|
+
return (jsx("svg", { className: className, "data-testid": dataTestId, height: size, style: { width: `${size}px`, height: `${size}px` }, viewBox: `0 0 ${size} ${size}`, width: size, xmlns: "http://www.w3.org/2000/svg", children: jsx("polygon", { points: normalizedPoints, style: {
|
|
4280
|
+
fill: color,
|
|
4281
|
+
fillOpacity: opaque ? 0.2 : undefined,
|
|
4282
|
+
stroke: color,
|
|
4283
|
+
strokeOpacity: opaque ? 0.8 : undefined,
|
|
4284
|
+
strokeWidth,
|
|
4285
|
+
}, transform: `translate(${strokeWidth}, ${strokeWidth})` }) }));
|
|
4286
|
+
};
|
|
4287
|
+
const normalize = ({ value, min, max, size }) => ((value - min) / (max - min)) * size;
|
|
4288
|
+
|
|
4260
4289
|
function useConfirmExit(confirmExit, when = true) {
|
|
4261
4290
|
useBlocker(confirmExit, when);
|
|
4262
4291
|
}
|
|
@@ -4841,4 +4870,4 @@ const cvaClickable = cvaMerge([
|
|
|
4841
4870
|
},
|
|
4842
4871
|
});
|
|
4843
4872
|
|
|
4844
|
-
export { Alert, Badge, Breadcrumb, BreadcrumbContainer, BreadcrumbItem, Button, Card, CardBody, CardFooter, CardHeader, Collapse, CompletionStatusIndicator, CopyableText, Drawer, EmptyState, EmptyValue, ExternalLink, Heading, Icon, IconButton, Indicator, KPICard, MenuItem, MenuList, MoreMenu, Notice, PackageNameStoryComponent, Page, PageContent, PageHeader, Pagination, Popover, PopoverContent, PopoverTitle, PopoverTrigger, Prompt, ROLE_CARD, SectionHeader, Sidebar, SkeletonLines, Spacer, Spinner, StarButton, Tab, TabContent, TabList, Tabs, Tag, Text, Timeline, TimelineElement, ToggleGroup, Tooltip, ValueBar, VirtualizedList, WidgetBody, cvaButton, cvaButtonPrefixSuffix, cvaButtonSpinner, cvaButtonSpinnerContainer, cvaClickable, cvaIconButton, cvaIndicator, cvaIndicatorIcon, cvaIndicatorIconBackground, cvaIndicatorLabel, cvaIndicatorPing, cvaInteractableItem, cvaMenuItem, cvaMenuItemLabel, cvaMenuItemPrefix, cvaMenuItemStyle, cvaMenuItemSuffix, docs, getDevicePixelRatio, getValueBarColorByValue, iconColorNames, iconPalette, setLocalStorage, useClickOutside, useContainerProps, useContinuousTimeout, useDebounce, useDevicePixelRatio, useGeometry, useHover, useIsFirstRender, useIsFullscreen, useIsTextCutOff, useLocalStorage, useLocalStorageReducer, useOptionallyElevatedState, useOverflowItems, usePopoverContext, usePrompt, useResize, useSelfUpdatingRef, useTimeout, useWindowActivity };
|
|
4873
|
+
export { Alert, Badge, Breadcrumb, BreadcrumbContainer, BreadcrumbItem, Button, Card, CardBody, CardFooter, CardHeader, Collapse, CompletionStatusIndicator, CopyableText, Drawer, EmptyState, EmptyValue, ExternalLink, Heading, Icon, IconButton, Indicator, KPICard, MenuItem, MenuList, MoreMenu, Notice, PackageNameStoryComponent, Page, PageContent, PageHeader, Pagination, Polygon, Popover, PopoverContent, PopoverTitle, PopoverTrigger, Prompt, ROLE_CARD, SectionHeader, Sidebar, SkeletonLines, Spacer, Spinner, StarButton, Tab, TabContent, TabList, Tabs, Tag, Text, Timeline, TimelineElement, ToggleGroup, Tooltip, ValueBar, VirtualizedList, WidgetBody, cvaButton, cvaButtonPrefixSuffix, cvaButtonSpinner, cvaButtonSpinnerContainer, cvaClickable, cvaIconButton, cvaIndicator, cvaIndicatorIcon, cvaIndicatorIconBackground, cvaIndicatorLabel, cvaIndicatorPing, cvaInteractableItem, cvaMenuItem, cvaMenuItemLabel, cvaMenuItemPrefix, cvaMenuItemStyle, cvaMenuItemSuffix, docs, getDevicePixelRatio, getValueBarColorByValue, iconColorNames, iconPalette, setLocalStorage, useClickOutside, useContainerProps, useContinuousTimeout, useDebounce, useDevicePixelRatio, useGeometry, useHover, useIsFirstRender, useIsFullscreen, useIsTextCutOff, useLocalStorage, useLocalStorageReducer, useOptionallyElevatedState, useOverflowItems, usePopoverContext, usePrompt, useResize, useSelfUpdatingRef, useTimeout, useWindowActivity };
|
package/package.json
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CommonProps } from "../../common/CommonProps";
|
|
2
|
+
type Point = [number, number];
|
|
3
|
+
export interface PolygonProps extends CommonProps {
|
|
4
|
+
points: Point[];
|
|
5
|
+
size: number;
|
|
6
|
+
color?: "white" | "black";
|
|
7
|
+
opaque?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Draws an svg Polygon from a set of points.
|
|
11
|
+
*
|
|
12
|
+
* @param { PolygonProps} props - The props for the Polygon component
|
|
13
|
+
* @returns {JSX.Element} Polygon component
|
|
14
|
+
*/
|
|
15
|
+
export declare const Polygon: ({ points, size, color, opaque, className, dataTestId }: PolygonProps) => import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./Alert";
|
|
2
2
|
export * from "./Badge";
|
|
3
3
|
export * from "./Breadcrumb/Breadcrumb";
|
|
4
|
+
export * from "./buttons";
|
|
4
5
|
export * from "./Card";
|
|
5
6
|
export * from "./Collapse";
|
|
6
7
|
export * from "./CompletionStatusIndicator/CompletionStatusIndicator";
|
|
@@ -18,6 +19,7 @@ export * from "./Notice";
|
|
|
18
19
|
export * from "./Page";
|
|
19
20
|
export * from "./PageHeader";
|
|
20
21
|
export * from "./Pagination/Pagination";
|
|
22
|
+
export * from "./Polygon/Polygon";
|
|
21
23
|
export * from "./Popover";
|
|
22
24
|
export * from "./Popover/Popover";
|
|
23
25
|
export * from "./Prompt";
|
|
@@ -39,4 +41,3 @@ export * from "./Tooltip";
|
|
|
39
41
|
export * from "./ValueBar";
|
|
40
42
|
export * from "./VirtualizedList/VirtualizedList";
|
|
41
43
|
export * from "./Widget";
|
|
42
|
-
export * from "./buttons";
|