react-proportion-slider 0.9.2 → 0.9.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.
- package/README.md +45 -23
- package/dist/ProportionSlider.d.ts +37 -0
- package/dist/components/DynamicChildPositioner.d.ts +10 -0
- package/dist/components/HiddenSpaceTaker.d.ts +6 -0
- package/dist/components/SliderKnob.d.ts +10 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/components/types.d.ts +22 -0
- package/dist/index.d.ts +3 -0
- package/dist/react-proportion-slider.es.js +847 -0
- package/dist/react-proportion-slider.es.js.map +1 -0
- package/dist/react-proportion-slider.umd.js +31 -0
- package/dist/react-proportion-slider.umd.js.map +1 -0
- package/dist/utilities/getClientX.d.ts +3 -0
- package/dist/utilities/index.d.ts +3 -0
- package/dist/utilities/isTouchEvent.d.ts +1 -0
- package/dist/utilities/maths.d.ts +1 -0
- package/package.json +7 -8
package/README.md
CHANGED
@@ -1,68 +1,90 @@
|
|
1
1
|
# React Proportion Slider
|
2
2
|
|
3
|
-
> **Note:** This package is currently in beta
|
3
|
+
> **Note:** This package is currently in beta.
|
4
4
|
|
5
5
|
A React component that allows users to adjust the proportion of two elements using a slider.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
(Not yet published to npm)
|
10
|
-
|
11
9
|
```bash
|
12
10
|
npm install react-proportion-slider
|
13
11
|
```
|
14
12
|
|
13
|
+
```bash
|
14
|
+
yarn add react-proportion-slider
|
15
|
+
```
|
16
|
+
|
15
17
|
## Usage
|
16
18
|
|
17
19
|
```tsx
|
18
|
-
import React from "react";
|
19
|
-
import { ProportionSlider } from "react-proportion-slider";
|
20
|
-
|
21
20
|
function App() {
|
22
21
|
const [proportions, setProportions] = React.useState<[number, number]>([
|
23
22
|
50, 50,
|
24
23
|
]);
|
25
24
|
return (
|
26
|
-
<div
|
27
|
-
style={{
|
28
|
-
height: "100%",
|
29
|
-
flex: 1,
|
30
|
-
padding: "20px 200px",
|
31
|
-
display: "flex",
|
32
|
-
flexDirection: "column",
|
33
|
-
justifyContent: "center",
|
34
|
-
}}
|
35
|
-
>
|
25
|
+
<div>
|
36
26
|
<ProportionSlider
|
37
27
|
value={proportions}
|
28
|
+
width={500}
|
38
29
|
proportions={[
|
39
30
|
{
|
40
|
-
|
31
|
+
label: "Skill",
|
41
32
|
backgroundColor: "#31332E",
|
42
33
|
},
|
43
34
|
{
|
44
|
-
|
35
|
+
label: "3.7 Sonnet",
|
45
36
|
backgroundColor: "#5f625C",
|
46
37
|
},
|
47
38
|
]}
|
48
39
|
onChange={(change) => {
|
49
40
|
setProportions(change);
|
50
41
|
}}
|
51
|
-
|
42
|
+
knobOptions={{
|
52
43
|
width: 5,
|
53
44
|
gap: 5,
|
54
45
|
backgroundColor: "#EC1308",
|
55
46
|
}}
|
56
|
-
|
57
|
-
height: 50,
|
58
|
-
displayValueType: "percentage",
|
59
|
-
}}
|
47
|
+
height={50}
|
60
48
|
/>
|
61
49
|
</div>
|
62
50
|
);
|
63
51
|
}
|
64
52
|
```
|
65
53
|
|
54
|
+
## Props
|
55
|
+
|
56
|
+
| Prop Name | Type | Required | Description |
|
57
|
+
| ----------- | ------------------------------------ | -------- | --------------------------------------------------- |
|
58
|
+
| value | [number, number] | Yes | Current values of the two proportions [left, right] |
|
59
|
+
| proportions | [ProportionDetail, ProportionDetail] | Yes | Details for the two proportions [left, right] |
|
60
|
+
| onChange | (values: [number, number]) => void | No | Callback when values change |
|
61
|
+
| knobOptions | SliderKnobOptions | No | Appearance of the slider knob |
|
62
|
+
| height | number | No | Height of the slider in pixels |
|
63
|
+
| width | number | No | Width of the slider in pixels |
|
64
|
+
| disabled | boolean | No | Whether the slider is disabled |
|
65
|
+
| className | string | No | Custom class name for the slider container |
|
66
|
+
| style | React.CSSProperties | No | Custom styles for the slider container |
|
67
|
+
| ariaLabel | string | No | Accessibility label for the slider |
|
68
|
+
|
69
|
+
### ProportionDetail
|
70
|
+
|
71
|
+
| Property | Type | Required | Description |
|
72
|
+
| --------------- | ------ | -------- | ----------------------------------------------- |
|
73
|
+
| label | string | Yes | Custom label to display |
|
74
|
+
| backgroundColor | string | No | Color of the proportion segment |
|
75
|
+
| data | any | No | Optional data to associate with this proportion |
|
76
|
+
| ariaLabel | string | No | Accessibility label for this proportion |
|
77
|
+
|
78
|
+
### SliderKnobOptions
|
79
|
+
|
80
|
+
| Property | Type | Required | Description |
|
81
|
+
| --------------- | ------------------- | -------- | ------------------------------------ |
|
82
|
+
| width | number | No | Width of the slider knob in pixels |
|
83
|
+
| gap | number | No | Gap around the slider knob in pixels |
|
84
|
+
| backgroundColor | string | No | Color of the slider knob |
|
85
|
+
| className | string | No | Custom class name for the knob |
|
86
|
+
| style | React.CSSProperties | No | Custom styles for the knob |
|
87
|
+
|
66
88
|
## Future Features
|
67
89
|
|
68
90
|
1. Make it possible to adjust the proportion of more than two elements
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { CSSProperties } from 'react';
|
2
|
+
import { ProportionDetail, SliderKnobOptions } from './components';
|
3
|
+
export type ProportionSliderProps = {
|
4
|
+
/**
|
5
|
+
* Current values of the two proportions [left, right]
|
6
|
+
* These should be positive numbers
|
7
|
+
*/
|
8
|
+
value: [number, number];
|
9
|
+
/**
|
10
|
+
* Details for the two proportions [left, right]
|
11
|
+
*/
|
12
|
+
proportions: [ProportionDetail, ProportionDetail];
|
13
|
+
/**
|
14
|
+
* Callback when values change
|
15
|
+
* @param values The new values [left, right]
|
16
|
+
*/
|
17
|
+
onChange?: (values: [number, number]) => void;
|
18
|
+
/**
|
19
|
+
* Appearance of the slider knob
|
20
|
+
*/
|
21
|
+
knobOptions?: SliderKnobOptions;
|
22
|
+
/** Height of the slider in pixels */
|
23
|
+
height?: number;
|
24
|
+
/** Width of the slider in pixels */
|
25
|
+
width?: number;
|
26
|
+
/** Whether the slider is disabled */
|
27
|
+
disabled?: boolean;
|
28
|
+
/** Custom class name for the slider container */
|
29
|
+
className?: string;
|
30
|
+
/** Custom styles for the slider container */
|
31
|
+
style?: CSSProperties;
|
32
|
+
/**
|
33
|
+
* Accessibility options
|
34
|
+
*/
|
35
|
+
ariaLabel?: string;
|
36
|
+
};
|
37
|
+
export declare const ProportionSlider: ({ value, proportions, onChange, knobOptions, disabled, height, ariaLabel, className, style, width, }: ProportionSliderProps) => import("react/jsx-runtime").JSX.Element;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { ProportionDetail } from './types';
|
2
|
+
type DynamicChildPositionerProps = {
|
3
|
+
detail: ProportionDetail;
|
4
|
+
primaryNode: "left" | "right";
|
5
|
+
width: number | string;
|
6
|
+
ariaLabel?: string;
|
7
|
+
valueLabel: string;
|
8
|
+
};
|
9
|
+
export declare const DynamicChildPositioner: ({ detail, valueLabel, primaryNode, width, ariaLabel, }: DynamicChildPositionerProps) => import("react/jsx-runtime").JSX.Element;
|
10
|
+
export {};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { CSSProperties } from 'react';
|
2
|
+
export type SliderKnobProps = {
|
3
|
+
className?: string;
|
4
|
+
width: number;
|
5
|
+
gap: number;
|
6
|
+
backgroundColor?: string;
|
7
|
+
style?: CSSProperties;
|
8
|
+
disabled?: boolean;
|
9
|
+
};
|
10
|
+
export declare const SliderKnob: ({ className, width, gap, backgroundColor, style, disabled, }: SliderKnobProps) => import("react/jsx-runtime").JSX.Element;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { CSSProperties } from 'react';
|
2
|
+
export type SliderKnobOptions = {
|
3
|
+
/** Width of the slider knob in pixels */
|
4
|
+
width?: number;
|
5
|
+
/** Gap around the slider knob in pixels */
|
6
|
+
gap?: number;
|
7
|
+
/** Color of the slider knob */
|
8
|
+
backgroundColor?: string;
|
9
|
+
/** Custom class name for the knob */
|
10
|
+
className?: string;
|
11
|
+
/** Custom styles for the knob */
|
12
|
+
style?: CSSProperties;
|
13
|
+
};
|
14
|
+
export type ProportionDetail = {
|
15
|
+
/** Custom label to display instead of percentage or value */
|
16
|
+
label: string;
|
17
|
+
/** Color of the proportion segment */
|
18
|
+
backgroundColor?: string;
|
19
|
+
/** Optional data to associate with this proportion */
|
20
|
+
data?: unknown;
|
21
|
+
ariaLabel?: string;
|
22
|
+
};
|
package/dist/index.d.ts
ADDED