@datalayer/primer-addons 0.0.5 → 0.0.6

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/README.md CHANGED
@@ -2,11 +2,13 @@
2
2
 
3
3
  [![Become a Sponsor](https://img.shields.io/static/v1?label=Become%20a%20Sponsor&message=%E2%9D%A4&logo=GitHub&style=flat&color=1ABC9C)](https://github.com/sponsors/datalayer)
4
4
 
5
- # ⚛️ Addons for Primer React
5
+ # ⚛️ ➕ Primer Addons
6
+
7
+ > Additional components for Primer React.
6
8
 
7
9
  This repository contains additional React.js components for the [@primer/react](https://github.com/primer/react) tookit.
8
10
 
9
- The componnents are compliant with the Primer theming framework and aims to respect the [Primer design system](https://primer.style).
11
+ The components are compliant with the Primer theming framework and aims to respect the [Primer design system](https://primer.style).
10
12
 
11
13
  A Storybook showcasing the components and their options is available on https://primer-addons.datalayer.tech.
12
14
 
@@ -1,3 +1,19 @@
1
- /// <reference types="react" />
2
- export declare const Slider: () => JSX.Element;
1
+ interface CommonProps {
2
+ min: number;
3
+ max: number;
4
+ value: number;
5
+ displayValue?: boolean;
6
+ orientation?: "horizontal" | "vertical";
7
+ width?: string | number;
8
+ onChange: (value: number) => void;
9
+ }
10
+ type ConditionalProps = {
11
+ markers: true;
12
+ step: number;
13
+ } | {
14
+ markers?: false;
15
+ step?: number;
16
+ };
17
+ export type SliderProps = CommonProps & ConditionalProps;
18
+ export declare const Slider: ({ min, max, value, step, markers, displayValue, orientation, width, onChange, }: SliderProps) => JSX.Element;
3
19
  export default Slider;
@@ -1,5 +1,23 @@
1
- import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
- export const Slider = () => {
3
- return _jsx(_Fragment, { children: "Slider" });
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, CounterLabel } from "@primer/react";
3
+ import { useEffect, useState } from "react";
4
+ export const Slider = ({ min, max, value, step, markers = false, displayValue = false, orientation = "horizontal", width = "200px", onChange, }) => {
5
+ const [sliderVal, setSliderVal] = useState(value);
6
+ useEffect(() => {
7
+ setSliderVal(value);
8
+ }, [value]);
9
+ const handleSliderChange = (event) => {
10
+ const newValue = Number(event.target.value);
11
+ setSliderVal(newValue);
12
+ onChange(newValue);
13
+ };
14
+ // Warning: unreliable
15
+ const sliderStyle = {
16
+ width,
17
+ ...(orientation === "vertical" ? { transform: "rotate(-90deg)" } : {}),
18
+ };
19
+ return (_jsxs(Box, { display: "flex", alignItems: "center", children: [_jsx("input", { type: "range", name: "slider", min: min, max: max, value: sliderVal, step: step ?? "any", list: "slider-markers", style: sliderStyle, onChange: handleSliderChange }), markers && step && (_jsx("datalist", { id: "slider-markers", children: Array.from({ length: Math.floor((max - min) / step) + 1 }, (_, i) => min + i * step).map((e) => (
20
+ // TODO: Supply markers as array and show them here
21
+ _jsx("option", { value: e }, `slider-marker-${e}`))) })), displayValue && orientation === "horizontal" && _jsx(CounterLabel, { sx: { ml: 2 }, children: sliderVal })] }));
4
22
  };
5
23
  export default Slider;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- export interface Props {
2
+ export interface ToolbarProps {
3
3
  align?: "center" | "flex-start" | "flex-end" | "space-evenly" | "space-around" | "space-between";
4
4
  gap?: string;
5
5
  height?: string;
@@ -11,5 +11,5 @@ export interface Props {
11
11
  border?: boolean;
12
12
  children: React.ReactNode | React.ReactNode[];
13
13
  }
14
- export declare const Toolbar: ({ align, height, gap, padding, heading, backgroundColor, borderBottomHeight, borderBottomColor, border, children, }: Props) => JSX.Element;
14
+ export declare const Toolbar: ({ align, height, gap, padding, heading, backgroundColor, borderBottomHeight, borderBottomColor, border, children, }: ToolbarProps) => JSX.Element;
15
15
  export default Toolbar;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datalayer/primer-addons",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "license": "BSD-3-Clause",
5
5
  "scripts": {
6
6
  "dev": "vite",