-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Slider - mergestyle conversion #5379
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
Changes from 3 commits
9134a8d
6238f6b
ea70b36
788c50b
b2535dd
cc51cbe
6e83c67
c9c3ece
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "office-ui-fabric-react", | ||
| "comment": "Convert Slider to merge-styles", | ||
| "type": "patch" | ||
| } | ||
| ], | ||
| "packageName": "office-ui-fabric-react", | ||
| "email": "kchau@microsoft.com" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,17 @@ | ||
| import * as React from 'react'; | ||
| import { BaseComponent, KeyCodes, css, getId, getRTL, getRTLSafeKeyCode, createRef } from '../../Utilities'; | ||
| import { ISliderProps, ISlider } from './Slider.types'; | ||
| import { | ||
| BaseComponent, | ||
| KeyCodes, | ||
| css, | ||
| getId, | ||
| getRTL, | ||
| getRTLSafeKeyCode, | ||
| createRef, | ||
| customizable | ||
| } from '../../Utilities'; | ||
| import { ISliderProps, ISlider, ISliderStyleProps, ISliderStyles } from './Slider.types'; | ||
| import { classNamesFunction } from '../../Utilities'; | ||
| import { Label } from '../../Label'; | ||
| import * as stylesImport from './Slider.scss'; | ||
| const styles: any = stylesImport; | ||
|
|
||
| export interface ISliderState { | ||
| value?: number; | ||
|
|
@@ -18,6 +26,8 @@ export enum ValuePosition { | |
| Next = 1 | ||
| } | ||
|
|
||
| const getClassNames = classNamesFunction<ISliderStyleProps, ISliderStyles>(); | ||
| @customizable('Label', ['theme', 'styles']) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought we were no longer using this decorator? Styled is doing the same thing... |
||
| export class SliderBase extends BaseComponent<ISliderProps, ISliderState> implements ISlider { | ||
| public static defaultProps: ISliderProps = { | ||
| step: 1, | ||
|
|
@@ -65,29 +75,44 @@ export class SliderBase extends BaseComponent<ISliderProps, ISliderState> implem | |
| } | ||
|
|
||
| public render(): React.ReactElement<{}> { | ||
| const { ariaLabel, className, disabled, label, max, min, showValue, buttonProps, vertical } = this.props; | ||
| const { | ||
| ariaLabel, | ||
| className, | ||
| disabled, | ||
| label, | ||
| max, | ||
| min, | ||
| showValue, | ||
| buttonProps, | ||
| vertical, | ||
| styles, | ||
| theme | ||
| } = this.props; | ||
| const { value, renderedValue } = this.state; | ||
| const thumbOffsetPercent: number = ((renderedValue! - min!) / (max! - min!)) * 100; | ||
| const lengthString = vertical ? 'height' : 'width'; | ||
| const onMouseDownProp: {} = disabled ? {} : { onMouseDown: this._onMouseDownOrTouchStart }; | ||
| const onTouchStartProp: {} = disabled ? {} : { onTouchStart: this._onMouseDownOrTouchStart }; | ||
| const onKeyDownProp: {} = disabled ? {} : { onKeyDown: this._onKeyDown }; | ||
| const classNames = getClassNames(styles, { | ||
| className, | ||
| rootIsDisabled: disabled, | ||
| rootIsEnabled: !disabled, | ||
| rootIsVertical: vertical, | ||
| rootIsHorizontal: !vertical, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know it was in original code, but isn't it enough to just have one of each of these variables in the styles props interface? Seems redundant...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. um very much agreed. I'm gonna clean this up |
||
| showTransitions: renderedValue === value, | ||
| showValue, | ||
| theme: theme! | ||
| }); | ||
|
|
||
| return ( | ||
| <div | ||
| className={css('ms-Slider', styles.root, className, { | ||
| ['ms-Slider-enabled ' + styles.rootIsEnabled]: !disabled, | ||
| ['ms-Slider-disabled ' + styles.rootIsDisabled]: disabled, | ||
| ['ms-Slider-row ' + styles.rootIsHorizontal]: !vertical, | ||
| ['ms-Slider-column ' + styles.rootIsVertical]: vertical | ||
| })} | ||
| > | ||
| <div className={classNames.root}> | ||
| {label && ( | ||
| <Label className={styles.titleLabel} {...(ariaLabel ? {} : { htmlFor: this._id })}> | ||
| <Label className={classNames.titleLabel} {...(ariaLabel ? {} : { htmlFor: this._id })}> | ||
| {label} | ||
| </Label> | ||
| )} | ||
| <div className={css('ms-Slider-container', styles.container)}> | ||
| <div className={classNames.container}> | ||
| <button | ||
| aria-valuenow={value} | ||
| aria-valuemin={min} | ||
|
|
@@ -98,35 +123,29 @@ export class SliderBase extends BaseComponent<ISliderProps, ISliderState> implem | |
| {...onTouchStartProp} | ||
| {...onKeyDownProp} | ||
| {...buttonProps} | ||
| className={css( | ||
| 'ms-Slider-slideBox', | ||
| styles.slideBox, | ||
| buttonProps!.className, | ||
| !!showValue && 'ms-Slider-showValue', | ||
| renderedValue === value && 'ms-Slider-showTransitions ' + styles.showTransitions | ||
| )} | ||
| className={css(classNames.slideBox, buttonProps!.className)} | ||
| id={this._id} | ||
| disabled={disabled} | ||
| type="button" | ||
| role="slider" | ||
| > | ||
| <div ref={this._sliderLine} className={css('ms-Slider-line', styles.line)}> | ||
| <div ref={this._sliderLine} className={classNames.line}> | ||
| <span | ||
| ref={this._thumb} | ||
| className={css('ms-Slider-thumb', styles.thumb)} | ||
| className={classNames.thumb} | ||
| style={this._getThumbStyle(vertical, thumbOffsetPercent)} | ||
| /> | ||
| <span | ||
| className={css('ms-Slider-active', styles.lineContainer, styles.activeSection)} | ||
| className={css(classNames.lineContainer, classNames.activeSection)} | ||
| style={{ [lengthString]: thumbOffsetPercent + '%' }} | ||
| /> | ||
| <span | ||
| className={css('ms-Slider-inactive', styles.lineContainer, styles.inactiveSection)} | ||
| className={css(classNames.lineContainer, classNames.inactiveSection)} | ||
| style={{ [lengthString]: 100 - thumbOffsetPercent + '%' }} | ||
| /> | ||
| </div> | ||
| </button> | ||
| {showValue && <Label className={css('ms-Slider-value', styles.valueLabel)}>{value}</Label>} | ||
| {showValue && <Label className={classNames.valueLabel}>{value}</Label>} | ||
| </div> | ||
| </div> | ||
| ) as React.ReactElement<{}>; | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be minor since interfaces changed