|
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 | | - name: "Skill", |
| 31 | + label: "Skill", |
41 | 32 | backgroundColor: "#31332E", |
42 | 33 | }, |
43 | 34 | { |
44 | | - name: "3.7 Sonnet", |
| 35 | + label: "3.7 Sonnet", |
45 | 36 | backgroundColor: "#5f625C", |
46 | 37 | }, |
47 | 38 | ]} |
48 | 39 | onChange={(change) => { |
49 | 40 | setProportions(change); |
50 | 41 | }} |
51 | | - sliderOptions={{ |
| 42 | + knobOptions={{ |
52 | 43 | width: 5, |
53 | 44 | gap: 5, |
54 | 45 | backgroundColor: "#EC1308", |
55 | 46 | }} |
56 | | - options={{ |
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 commit comments