@sakaniui/react 0.10.1 → 0.11.0

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.
@@ -0,0 +1,49 @@
1
+ import { default as React } from 'react';
2
+ import { LatLng } from './geo';
3
+ export { useMapContext } from './context';
4
+ export type { LatLng } from './geo';
5
+ export interface MapView {
6
+ center: LatLng;
7
+ zoom: number;
8
+ }
9
+ export interface MapProps {
10
+ /** Where the map starts, as [latitude, longitude]. Changing it later flies the map there. */
11
+ center?: LatLng;
12
+ /** Starting zoom, 0 (whole world) to maxZoom. Changing it later animates to it. */
13
+ zoom?: number;
14
+ minZoom?: number;
15
+ maxZoom?: number;
16
+ /** Called whenever the user pans or zooms. */
17
+ onViewChange?: (view: MapView) => void;
18
+ /** Tile URL template with {z}, {x} and {y}. Defaults to OpenStreetMap. */
19
+ tileUrl?: string;
20
+ /**
21
+ * Tiles to use in dark mode, from a provider that has a dark style. Without it the same tiles are
22
+ * darkened with `--map-tile-filter` (flat dark land, blue water, roads darker than the land).
23
+ */
24
+ tileUrlDark?: string;
25
+ /**
26
+ * "auto" follows the surrounding theme (a `.dark` class on <html> or any ancestor). "dark" makes this map dark
27
+ * wherever it sits, like the Figma "Dark" example: tiles, markers, controls and popups all switch.
28
+ */
29
+ theme?: 'auto' | 'dark';
30
+ /** Attribution text required by the tile provider. Pass null to hide it (only if your provider allows). */
31
+ attribution?: React.ReactNode | null;
32
+ /** Show the zoom controls. Defaults to true. */
33
+ controls?: boolean;
34
+ /** Show the locate button (uses the browser's geolocation). Defaults to false. */
35
+ locate?: boolean;
36
+ /** Called with the user's position after the locate button finds it. */
37
+ onLocate?: (position: LatLng) => void;
38
+ /** Called when the locate button cannot find the user (permission denied, no signal, no support). */
39
+ onLocateError?: (error: GeolocationPositionError | Error) => void;
40
+ /** Height in px or any CSS length. Defaults to 400. */
41
+ height?: number | string;
42
+ /** Accessible name for the map region. Defaults to "Map". */
43
+ 'aria-label'?: string;
44
+ className?: string;
45
+ /** MapMarker and MapPopup elements. */
46
+ children?: React.ReactNode;
47
+ }
48
+ export declare const Map: React.FC<MapProps>;
49
+ export default Map;
@@ -0,0 +1,22 @@
1
+ import { default as React } from 'react';
2
+ import { LatLng } from './geo';
3
+ export interface MapClusterPoint {
4
+ id: string | number;
5
+ position: LatLng;
6
+ }
7
+ export interface MapClusterLayerProps<T extends MapClusterPoint = MapClusterPoint> {
8
+ points: T[];
9
+ /** Draws one place that is not clustered, usually a <MapMarker>. Give it the point's `id` as its key. */
10
+ renderPoint: (point: T) => React.ReactNode;
11
+ /** Grid size in px: larger groups more places together. Defaults to 56. */
12
+ radius?: number;
13
+ /** From this zoom up, nothing clusters. Defaults to 16. */
14
+ clusterMaxZoom?: number;
15
+ /** Called after a cluster is clicked, with the places in it. The map zooms to them first. */
16
+ onClusterClick?: (points: T[]) => void;
17
+ }
18
+ export declare function MapClusterLayer<T extends MapClusterPoint = MapClusterPoint>({ points, renderPoint, radius, clusterMaxZoom, onClusterClick, }: MapClusterLayerProps<T>): React.JSX.Element;
19
+ export declare namespace MapClusterLayer {
20
+ var displayName: string;
21
+ }
22
+ export default MapClusterLayer;
@@ -0,0 +1,28 @@
1
+ import { default as React } from 'react';
2
+ import { IconComponent } from '../../icons/types';
3
+ export interface MapControlButtonProps {
4
+ /** The icon, drawn at 16px. */
5
+ icon: IconComponent;
6
+ /** Accessible name; the button has no visible text. */
7
+ 'aria-label': string;
8
+ disabled?: boolean;
9
+ /** Shows the hover appearance without a pointer (documentation and visual tests). */
10
+ hovered?: boolean;
11
+ onClick?: () => void;
12
+ className?: string;
13
+ }
14
+ export declare const MapControlButton: React.FC<MapControlButtonProps>;
15
+ export interface MapControlsProps {
16
+ onZoomIn?: () => void;
17
+ onZoomOut?: () => void;
18
+ /** Disables the zoom-in button, e.g. at the map's maximum zoom. */
19
+ zoomInDisabled?: boolean;
20
+ zoomOutDisabled?: boolean;
21
+ /** Show the zoom group. Defaults to true. */
22
+ zoom?: boolean;
23
+ /** Show the locate button under it (Figma "Show locate"). Defaults to false. */
24
+ locate?: boolean;
25
+ onLocate?: () => void;
26
+ className?: string;
27
+ }
28
+ export declare const MapControls: React.FC<MapControlsProps>;
@@ -0,0 +1,50 @@
1
+ import { default as React } from 'react';
2
+ import { LatLng } from './geo';
3
+ export interface MapGlobeMarker {
4
+ /** [latitude, longitude] */
5
+ position: LatLng;
6
+ /** Draws a pulsing ring around it. */
7
+ active?: boolean;
8
+ /** The larger halo, for the marker the user picked. */
9
+ selected?: boolean;
10
+ /** Shows the hover appearance without a pointer (documentation and visual tests). Real hover works on its own. */
11
+ hovered?: boolean;
12
+ /** Name shown in a small card above the marker while it is hovered or selected; also its accessible name. */
13
+ label?: string;
14
+ }
15
+ export interface MapGlobeArc {
16
+ from: LatLng;
17
+ to: LatLng;
18
+ }
19
+ export interface MapGlobeProps {
20
+ /** Which part gets the bright dots. Defaults to "land". */
21
+ variant?: 'land' | 'ocean';
22
+ /** The place facing the viewer at first, as [latitude, longitude]. */
23
+ center?: LatLng;
24
+ markers?: MapGlobeMarker[];
25
+ arcs?: MapGlobeArc[];
26
+ /** Spin on its own. Defaults to true (off under reduced motion). */
27
+ autoRotate?: boolean;
28
+ /** Degrees per second. Defaults to 6. */
29
+ rotationSpeed?: number;
30
+ /** Let people drag to spin it. Defaults to true. */
31
+ draggable?: boolean;
32
+ /** The soft halo past the edge. Defaults to true. */
33
+ atmosphere?: boolean;
34
+ /** Degrees between dots; smaller is denser. Defaults to 1.3. */
35
+ dotSpacing?: number;
36
+ /**
37
+ * "auto" follows the surrounding theme. "dark" draws light dots wherever the globe sits, for a globe on a
38
+ * dark surface inside a light page. (The globe has no background of its own; it takes the colour behind it.)
39
+ */
40
+ theme?: 'auto' | 'dark';
41
+ /** Called when a marker is clicked or activated from the keyboard (markers with a `label` get a hidden button). */
42
+ onMarkerClick?: (index: number, marker: MapGlobeMarker) => void;
43
+ /** Called when the pointer or keyboard focus moves onto a marker, and with null when it leaves. */
44
+ onMarkerHover?: (index: number | null) => void;
45
+ /** Accessible description. Defaults to "Globe". */
46
+ 'aria-label'?: string;
47
+ className?: string;
48
+ }
49
+ export declare const MapGlobe: React.FC<MapGlobeProps>;
50
+ export default MapGlobe;
@@ -0,0 +1,24 @@
1
+ import { default as React } from 'react';
2
+ import { LatLng } from './geo';
3
+ export type MapMarkerVariant = 'pin' | 'dot' | 'cluster';
4
+ export interface MapMarkerProps {
5
+ /** [latitude, longitude] */
6
+ position: LatLng;
7
+ variant?: MapMarkerVariant;
8
+ /** Number shown on a cluster. */
9
+ count?: number;
10
+ selected?: boolean;
11
+ /** Shows the hover appearance without a pointer (documentation and visual tests). Real hover works on its own. */
12
+ hovered?: boolean;
13
+ /**
14
+ * Milliseconds to slide to a new `position` instead of jumping, for markers fed by a live source
15
+ * (about the interval between updates reads as continuous). Off by default; reduced motion turns it off.
16
+ */
17
+ glide?: number;
18
+ /** Accessible name, e.g. the place's name. */
19
+ label?: string;
20
+ onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;
21
+ className?: string;
22
+ }
23
+ export declare const MapMarker: React.FC<MapMarkerProps>;
24
+ export default MapMarker;
@@ -0,0 +1,21 @@
1
+ import { default as React } from 'react';
2
+ import { LatLng } from './geo';
3
+ export interface MapPopupProps {
4
+ /** [latitude, longitude] the pointer points at. */
5
+ position: LatLng;
6
+ title?: React.ReactNode;
7
+ description?: React.ReactNode;
8
+ /** Shows a close button when given. */
9
+ onClose?: () => void;
10
+ /** Gap between the place and the pointer tip, in px. Defaults to 48 (above a pin); use 14 for a dot. */
11
+ offset?: number;
12
+ /** Show the pointer notch under the card (Figma "Show pointer"). Defaults to true. */
13
+ pointer?: boolean;
14
+ /** Milliseconds to follow a moving `position`; use the same value as the marker it points at. */
15
+ glide?: number;
16
+ /** Extra content under the description (actions, a thumbnail...). */
17
+ children?: React.ReactNode;
18
+ className?: string;
19
+ }
20
+ export declare const MapPopup: React.FC<MapPopupProps>;
21
+ export default MapPopup;
@@ -0,0 +1,18 @@
1
+ import { default as React } from 'react';
2
+ import { LatLng } from './geo';
3
+ export interface MapContextValue {
4
+ /** Container pixel position of a place, or null when it is far outside the view. */
5
+ project: (position: LatLng) => {
6
+ x: number;
7
+ y: number;
8
+ } | null;
9
+ zoom: number;
10
+ /** Ease the map to a place (and zoom). */
11
+ flyTo: (center: LatLng, zoom?: number) => void;
12
+ /** Ease the map so every place in the list is in view. */
13
+ fitBounds: (places: LatLng[], padding?: number) => void;
14
+ maxZoom: number;
15
+ }
16
+ export declare const MapContext: React.Context<MapContextValue | null>;
17
+ /** For MapMarker / MapPopup / MapClusterLayer (and custom overlays): projects places into the map's pixels. */
18
+ export declare function useMapContext(): MapContextValue;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Map maths shared by Map (Web Mercator tiles) and MapGlobe (orthographic
3
+ * dotted sphere). Plain functions, no dependencies.
4
+ */
5
+ /** [latitude, longitude] in degrees. */
6
+ export type LatLng = [number, number];
7
+ export declare const TILE_SIZE = 256;
8
+ export declare const clamp: (v: number, lo: number, hi: number) => number;
9
+ export declare const wrapLng: (lng: number) => number;
10
+ export declare function toWorld([lat, lng]: LatLng, zoom: number): {
11
+ x: number;
12
+ y: number;
13
+ };
14
+ export declare function fromWorld(x: number, y: number, zoom: number): LatLng;
15
+ export declare function isLand(lat: number, lng: number): boolean;
16
+ export interface GlobeDot {
17
+ cp: number;
18
+ sp: number;
19
+ lam: number;
20
+ land: boolean;
21
+ }
22
+ /** Rings of latitude, with dots spaced evenly along each ring. */
23
+ export declare function globeDots(step: number): GlobeDot[];
24
+ /** Orthographic projection centred on [tilt, rotLng]: x right, y up, z toward the viewer. */
25
+ export declare function orthographic(rotLng: number, tilt: number): (cp: number, sp: number, lam: number) => {
26
+ x: number;
27
+ y: number;
28
+ z: number;
29
+ };
30
+ export declare const sphere: ([lat, lng]: LatLng) => {
31
+ cp: number;
32
+ sp: number;
33
+ lam: number;
34
+ };
35
+ /** A great-circle arc between two places, lifted off the surface toward its middle. */
36
+ export declare function arcPath(from: LatLng, to: LatLng, segments?: number, lift?: number): {
37
+ cp: number;
38
+ sp: number;
39
+ lam: number;
40
+ h: number;
41
+ }[];
@@ -0,0 +1,13 @@
1
+ export { Map, default } from './Map';
2
+ export type { MapProps, MapView, LatLng } from './Map';
3
+ export { useMapContext } from './context';
4
+ export { MapMarker } from './MapMarker';
5
+ export type { MapMarkerProps, MapMarkerVariant } from './MapMarker';
6
+ export { MapPopup } from './MapPopup';
7
+ export type { MapPopupProps } from './MapPopup';
8
+ export { MapGlobe } from './MapGlobe';
9
+ export type { MapGlobeProps, MapGlobeMarker, MapGlobeArc } from './MapGlobe';
10
+ export { MapClusterLayer } from './MapClusterLayer';
11
+ export type { MapClusterLayerProps, MapClusterPoint } from './MapClusterLayer';
12
+ export { MapControlButton, MapControls } from './MapControls';
13
+ export type { MapControlButtonProps, MapControlsProps } from './MapControls';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Land mask for MapGlobe: Natural Earth 1:110m land (public domain), via the
3
+ * world-atlas package (ISC), rasterised to 1 degree cells. 360 x 180 bits,
4
+ * row-major from 89.5N, column 0 at 179.5W, most significant bit first.
5
+ * Generated; see THIRD_PARTY_NOTICES.md.
6
+ */
7
+ export declare const LAND_MASK_W = 360;
8
+ export declare const LAND_MASK_H = 180;
9
+ export declare const LAND_MASK_B64: string;
@@ -0,0 +1,8 @@
1
+ import { LatLng } from './geo';
2
+ /**
3
+ * Eases a place from where it was to where it is now, in latitude and longitude, so a marker fed by
4
+ * a live source slides instead of jumping. Interpolating the place (not the pixels) keeps it correct
5
+ * while the map is also being panned or zoomed. Longitude takes the short way round the antimeridian.
6
+ * `ms` of 0, or reduced motion, returns the position untouched.
7
+ */
8
+ export declare function useGlide(position: LatLng, ms?: number): LatLng;