Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dotStyle and activeDotStyle #292

Merged
merged 1 commit into from
Jul 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ The following APIs are shared by Slider and Range.
| handleStyle | Array[Object] \| Object | `[{}]` | The style used for handle. (`both for slider(`Object`) and range(`Array of Object`), the array will be used for mutli handle follow element order`) |
| trackStyle | Array[Object] \| Object | `[{}]` | The style used for track. (`both for slider(`Object`) and range(`Array of Object`), the array will be used for mutli track follow element order`)|w
| railStyle | Object | `{}` | The style used for the track base color. |

| dotStyle | Object | `{}` | The style used for the dots. |
| activeDotStyle | Object | `{}` | The style used for the active dots. |

### Slider

Expand Down
4 changes: 4 additions & 0 deletions examples/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ ReactDOM.render(
<p>Basic Slider,`step=20, dots`</p>
<Slider dots step={20} defaultValue={100} onAfterChange={log} />
</div>
<div style={style}>
<p>Basic Slider,`step=20, dots, dotStyle={"{borderColor: 'orange'}"}, activeDotStyle={"{borderColor: 'yellow'}"}`</p>
<Slider dots step={20} defaultValue={100} onAfterChange={log} dotStyle={{ borderColor: 'orange' }} activeDotStyle={{ borderColor: 'yellow' }} />
</div>
<div style={style}>
<p>Slider with tooltip, with custom `tipFormatter`</p>
<SliderWithTooltip
Expand Down
8 changes: 6 additions & 2 deletions src/common/Steps.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ const calcPoints = (vertical, marks, dots, step, min, max) => {
};

const Steps = ({ prefixCls, vertical, marks, dots, step, included,
lowerBound, upperBound, max, min }) => {
lowerBound, upperBound, max, min, dotStyle, activeDotStyle }) => {
const range = max - min;
const elements = calcPoints(vertical, marks, dots, step, min, max).map((point) => {
const offset = `${Math.abs(point - min) / range * 100}%`;
const style = vertical ? { bottom: offset } : { left: offset };

const isActived = (!included && point === upperBound) ||
(included && point <= upperBound && point >= lowerBound);
let style = vertical ? { bottom: offset, ...dotStyle } : { left: offset, ...dotStyle };
if (isActived) {
style = { ...style, ...activeDotStyle };
}

const pointClassName = classNames({
[`${prefixCls}-dot`]: true,
[`${prefixCls}-dot-active`]: isActived,
Expand Down
8 changes: 8 additions & 0 deletions src/common/createSlider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export default function createSlider(Component) {
handleStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.arrayOf(PropTypes.object)]),
trackStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.arrayOf(PropTypes.object)]),
railStyle: PropTypes.object,
dotStyle: PropTypes.object,
activeDotStyle: PropTypes.object,
};

static defaultProps = {
Expand All @@ -60,6 +62,8 @@ export default function createSlider(Component) {
trackStyle: [{}],
handleStyle: [{}],
railStyle: {},
dotStyle: {},
activeDotStyle: {},
};

constructor(props) {
Expand Down Expand Up @@ -216,6 +220,8 @@ export default function createSlider(Component) {
maximumTrackStyle,
style,
railStyle,
dotStyle,
activeDotStyle,
} = this.props;
const { tracks, handles } = super.render();

Expand Down Expand Up @@ -252,6 +258,8 @@ export default function createSlider(Component) {
upperBound={this.getUpperBound()}
max={max}
min={min}
dotStyle={dotStyle}
activeDotStyle={activeDotStyle}
/>
{handles}
<Marks
Expand Down