Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const BadgeUnstyled = React.forwardRef(function BadgeUnstyled(props, ref) {
vertical: 'top',
horizontal: 'right',
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a lint rule to disable eslint-disable for some rules? 😁

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahahahha, nah it's just me :D

classes: classesProp = {},
badgeContent: badgeContentProp,
component: Component = 'span',
Expand Down Expand Up @@ -99,7 +98,7 @@ const BadgeUnstyled = React.forwardRef(function BadgeUnstyled(props, ref) {
displayValue = badgeContent > max ? `${max}+` : badgeContent;
}

const classes = useBadgeClasses(stateAndProps);
const classes = useBadgeClasses({ ...stateAndProps, classes: classesProp });

const Root = components.Root || Component;
const rootProps = componentsProps.root || {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as React from 'react';
import { expect } from 'chai';
import { createMount, createClientRender, describeConformance } from 'test/utils';
import BadgeUnstyled from '@material-ui/unstyled/BadgeUnstyled';
import BadgeUnstyled, {
badgeUnstyledClasses as classes,
} from '@material-ui/unstyled/BadgeUnstyled';

describe('<BadgeUnstyled />', () => {
const mount = createMount();
Expand All @@ -12,7 +14,7 @@ describe('<BadgeUnstyled />', () => {
<div />
</BadgeUnstyled>,
() => ({
classes: {},
classes,
inheritComponent: 'span',
mount,
refInstanceof: window.HTMLSpanElement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,17 @@ export interface SliderUnstyledTypeMap<P = {}, D extends React.ElementType = 'sp
};
mark?: {
as?: React.ElementType;
styleProps?: Omit<SliderUnstyledTypeMap<P, D>['props'], 'components' | 'componentsProps'>;
styleProps?: Omit<
SliderUnstyledTypeMap<P, D>['props'],
'components' | 'componentsProps'
> & { markActive?: boolean };
};
markLabel?: {
as?: React.ElementType;
styleProps?: Omit<SliderUnstyledTypeMap<P, D>['props'], 'components' | 'componentsProps'>;
styleProps?: Omit<
SliderUnstyledTypeMap<P, D>['props'],
'components' | 'componentsProps'
> & { markLabelActive?: boolean };
};
valueLabel?: {
as?: React.ElementType;
Expand Down
30 changes: 19 additions & 11 deletions packages/material-ui-unstyled/src/SliderUnstyled/SliderUnstyled.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ const useSliderClasses = (props) => {
const utilityClasses = {
root: clsx(sliderUnstyledClasses['root'], classes['root'], {
[sliderUnstyledClasses['disabled']]: disabled,
[classes['disabled']]: disabled,
[sliderUnstyledClasses['marked']]: marked,
[classes['marked']]: marked,
[sliderUnstyledClasses['vertical']]: orientation === 'vertical',
Expand All @@ -163,12 +164,17 @@ const useSliderClasses = (props) => {
rail: clsx(sliderUnstyledClasses['rail'], classes['rail']),
track: clsx(sliderUnstyledClasses['track'], classes['track']),
mark: clsx(sliderUnstyledClasses['mark'], classes['mark']),
markActive: clsx(sliderUnstyledClasses['markActive'], classes['markActive']),
markLabel: clsx(sliderUnstyledClasses['markLabel'], classes['markLabel']),
markLabelActive: clsx(sliderUnstyledClasses['markLabelActive'], classes['markLabelActive']),
valueLabel: clsx(sliderUnstyledClasses['valueLabel'], classes['valueLabel']),
thumb: clsx(sliderUnstyledClasses['thumb'], classes['thumb'], {
[classes['disabled']]: disabled,
[sliderUnstyledClasses['disabled']]: disabled,
[sliderUnstyledClasses['vertical']]: orientation === 'vertical',
}),
active: clsx(sliderUnstyledClasses['active'], classes['active']),
disabled: clsx(sliderUnstyledClasses['disabled'], classes['disabled']),
focusVisible: clsx(sliderUnstyledClasses['focusVisible'], classes['focusVisible']),
};

return utilityClasses;
Expand All @@ -183,8 +189,7 @@ const SliderUnstyled = React.forwardRef(function SliderUnstyled(props, ref) {
'aria-valuetext': ariaValuetext,
className,
component: Component = 'span',
// eslint-disable-next-line @typescript-eslint/no-unused-vars
classes: classesProps = {},
classes: classesProp = {},
defaultValue,
disabled = false,
getAriaLabel,
Expand Down Expand Up @@ -615,7 +620,7 @@ const SliderUnstyled = React.forwardRef(function SliderUnstyled(props, ref) {
marked: marks.length > 0 && marks.some((mark) => mark.label),
};

const utilityClasses = useSliderClasses(stateAndProps);
const utilityClasses = useSliderClasses({ ...stateAndProps, classes: classesProp });

return (
<Root
Expand Down Expand Up @@ -673,12 +678,12 @@ const SliderUnstyled = React.forwardRef(function SliderUnstyled(props, ref) {
data-index={index}
{...markProps}
{...(!isHostComponent(Mark) && {
styleProps: { ...stateAndProps, ...markProps.styleProps },
styleProps: { ...stateAndProps, ...markProps.styleProps, markActive },
theme,
})}
style={{ ...style, ...markProps.style }}
className={clsx(utilityClasses.mark, markProps.className, {
[sliderUnstyledClasses['markActive']]: markActive,
[utilityClasses['markActive']]: markActive,
})}
/>
{mark.label != null ? (
Expand All @@ -687,12 +692,16 @@ const SliderUnstyled = React.forwardRef(function SliderUnstyled(props, ref) {
data-index={index}
{...markLabelProps}
{...(!isHostComponent(MarkLabel) && {
styleProps: { ...stateAndProps, ...markLabelProps.styleProps },
styleProps: {
...stateAndProps,
...markLabelProps.styleProps,
markLabelActive: markActive,
},
theme,
})}
style={{ ...style, ...markLabelProps.style }}
className={clsx(utilityClasses.markLabel, markLabelProps.className, {
[sliderUnstyledClasses['markLabelActive']]: markActive,
[utilityClasses['markLabelActive']]: markActive,
})}
>
{mark.label}
Expand Down Expand Up @@ -747,9 +756,8 @@ const SliderUnstyled = React.forwardRef(function SliderUnstyled(props, ref) {
onMouseLeave={handleMouseLeave}
{...thumbProps}
className={clsx(utilityClasses.thumb, thumbProps.className, {
[sliderUnstyledClasses['active']]: active === index,
[sliderUnstyledClasses['disabled']]: disabled,
Copy link
Member Author

@mnajdova mnajdova Dec 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is already applied in the useSliderClasses

[sliderUnstyledClasses['focusVisible']]: focusVisible === index,
[utilityClasses['active']]: active === index,
[utilityClasses['focusVisible']]: focusVisible === index,
})}
{...(!isHostComponent(Thumb) && {
styleProps: { ...stateAndProps, ...thumbProps.styleProps },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as React from 'react';
import { expect } from 'chai';
import { createMount, createClientRender, describeConformance } from 'test/utils';
import SliderUnstyled from './SliderUnstyled';
import SliderUnstyled, {
sliderUnstyledClasses as classes,
} from '@material-ui/unstyled/SliderUnstyled';

describe('<SliderUnstyled />', () => {
before(function beforeHook() {
Expand All @@ -14,7 +16,7 @@ describe('<SliderUnstyled />', () => {
const render = createClientRender();

describeConformance(<SliderUnstyled value={0} />, () => ({
classes: {},
classes,
inheritComponent: 'span',
mount,
refInstanceof: window.HTMLSpanElement,
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Badge/Badge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('<Badge />', () => {
<div />
</Badge>,
() => ({
classes: {},
classes,
inheritComponent: BadgeUnstyled,
mount,
refInstanceof: window.HTMLSpanElement,
Expand Down
20 changes: 10 additions & 10 deletions packages/material-ui/src/Slider/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,18 @@ export const SliderThumb = experimentalStyled(
height: 8,
marginLeft: -4,
marginTop: -3,
...(props.styleProps.orientation === 'vertical' && {
marginLeft: -3,
marginBottom: -4,
}),
'&:hover': {
boxShadow: 'none',
},
},
[`&.${sliderClasses.vertical}`]: {
...(props.styleProps.orientation === 'vertical' && {
marginLeft: -5,
marginBottom: -6,
},
[`&.${sliderClasses.vertical}&.${sliderClasses.disabled}`]: {
marginLeft: -3,
marginBottom: -4,
},
}),
...(props.styleProps.color === 'secondary' && {
[`&:hover, &.${sliderClasses.focusVisible}`]: {
boxShadow: `0px 0px 0px 8px ${alpha(props.theme.palette.secondary.main, 0.16)}`,
Expand Down Expand Up @@ -277,10 +277,10 @@ export const SliderMark = experimentalStyled(
height: 2,
borderRadius: 1,
backgroundColor: 'currentColor',
[`&.${sliderClasses.markActive}`]: {
...(props.styleProps.markActive && {
backgroundColor: props.theme.palette.background.paper,
opacity: 0.8,
},
}),
}));

export const SliderMarkLabel = experimentalStyled(
Expand All @@ -305,9 +305,9 @@ export const SliderMarkLabel = experimentalStyled(
left: 31,
}),
},
[`&.${sliderClasses.markLabelActive}`]: {
...(props.styleProps.markLabelActive && {
color: props.theme.palette.text.primary,
},
}),
}));

SliderRoot.propTypes = {
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Slider/Slider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('<Slider />', () => {
const render = createClientRender();

describeConformanceV5(<Slider value={0} />, () => ({
classes: {},
classes,
inheritComponent: SliderUnstyled,
mount,
refInstanceof: window.HTMLSpanElement,
Expand Down
4 changes: 2 additions & 2 deletions test/utils/describeConformance.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ export function testClassName(element, getOptions) {
function testComponentProp(element, getOptions) {
describe('prop: component', () => {
it('can render another root component with the `component` prop', () => {
const { classes, mount, testComponentPropWith: component = 'em' } = getOptions();
const { mount, testComponentPropWith: component = 'em' } = getOptions();

const wrapper = mount(React.cloneElement(element, { component }));

expect(findRootComponent(wrapper, { classes, component }).exists()).to.equal(true);
expect(findRootComponent(wrapper, { component }).exists()).to.equal(true);
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions test/utils/describeConformanceV5.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import {
function testComponentsProp(element, getOptions) {
describe('prop: components', () => {
it('can render another root component with the `components` prop', () => {
const { classes, mount, testComponentsRootPropWith: component = 'em' } = getOptions();
const { mount, testComponentsRootPropWith: component = 'em' } = getOptions();

const wrapper = mount(React.cloneElement(element, { components: { Root: component } }));

expect(findRootComponent(wrapper, { classes, component }).exists()).to.equal(true);
expect(findRootComponent(wrapper, { component }).exists()).to.equal(true);
});
});
}
Expand Down