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

[RangeSlider] Add magic tone #11472

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .changeset/slow-eagles-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': minor
---

- Added `tone` prop with `magic` value to `RangeSlider`
21 changes: 21 additions & 0 deletions polaris-react/src/components/RangeSlider/RangeSlider.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ export function Default() {
);
}

export function Magic() {
const [rangeValue, setRangeValue] = useState(32);

const handleRangeSliderChange = useCallback(
(value) => setRangeValue(value),
[],
);

return (
<LegacyCard sectioned title="Background color">
<RangeSlider
label="Opacity percentage"
value={rangeValue}
onChange={handleRangeSliderChange}
output
tone="magic"
/>
</LegacyCard>
);
}

export function WithMinAndMax() {
const [rangeValue, setRangeValue] = useState(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ $range-wrapper: 28px;
// stylelint-enable
}

.toneMagic & {
// stylelint-disable -- Polaris component custom properties
--pc-dual-thumb-selected-range: var(--p-color-bg-fill-magic);
--pc-dual-thumb-gradient-colors: var(--pc-dual-thumb-unselected-range) 0%,
var(--pc-dual-thumb-unselected-range)
var(--pc-range-slider-progress-lower),
var(--pc-dual-thumb-selected-range) var(--pc-range-slider-progress-lower),
var(--pc-dual-thumb-selected-range) var(--pc-range-slider-progress-upper),
var(--pc-dual-thumb-unselected-range)
var(--pc-range-slider-progress-upper),
var(--pc-dual-thumb-unselected-range) 100%;
background-image: linear-gradient(
to right,
var(--pc-dual-thumb-gradient-colors)
);
// stylelint-enable
}

.disabled & {
background: var(--p-color-border-disabled) none;
}
Expand Down Expand Up @@ -127,6 +145,14 @@ $range-wrapper: 28px;
var(--p-color-bg-fill-critical)
);
}

.toneMagic & {
border-color: var(--p-color-bg-fill-magic);
background: linear-gradient(
var(--p-color-bg-fill-magic),
var(--p-color-bg-fill-magic)
);
}
}

$range-output-size: 32px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {Component, createRef} from 'react';

import {debounce} from '../../../../utilities/debounce';
import {classNames} from '../../../../utilities/css';
import {classNames, variationName} from '../../../../utilities/css';
import {FeaturesContext} from '../../../../utilities/features';
import type {RangeSliderProps, DualValue} from '../../types';
import {Labelled, labelID} from '../../../Labelled';
Expand Down Expand Up @@ -137,6 +137,7 @@ export class DualThumb extends Component<DualThumbProps, State> {
labelAction,
labelHidden,
helpText,
tone,
} = this.props;
const {value} = this.state;

Expand All @@ -157,6 +158,7 @@ export class DualThumb extends Component<DualThumbProps, State> {
styles.TrackWrapper,
error && styles.error,
disabled && styles.disabled,
tone && styles[variationName('tone', tone)],
);

const thumbLowerClassName = classNames(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@
}
}

.toneMagic & {
// stylelint-disable -- Polaris component custom properties
--pc-single-thumb-progress-lower: var(--p-color-bg-fill-magic);

@include range-thumb-selectors {
border-color: var(--p-color-bg-fill-magic);
background: var(--p-color-bg-fill-magic);
}
// stylelint-enable
}

.disabled & {
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
@include range-track-selectors {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import {classNames} from '../../../../utilities/css';
import {classNames, variationName} from '../../../../utilities/css';
import {clamp} from '../../../../utilities/clamp';
import {Labelled, helpTextID} from '../../../Labelled';
import {Text} from '../../../Text';
Expand Down Expand Up @@ -36,6 +36,7 @@ export function SingleThumb(props: SingleThumbProps) {
step,
onBlur,
onFocus,
tone,
} = props;
const clampedValue = clamp(value, min, max);
const describedBy: string[] = [];
Expand Down Expand Up @@ -82,6 +83,7 @@ export function SingleThumb(props: SingleThumbProps) {
sharedStyles.RangeSlider,
error && styles.error,
disabled && styles.disabled,
tone && styles[variationName('tone', tone)],
);

/* eslint-disable @shopify/react-require-autocomplete */
Expand Down
2 changes: 2 additions & 0 deletions polaris-react/src/components/RangeSlider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ export interface RangeSliderProps {
onFocus?(): void;
/** Callback when focus is removed */
onBlur?(): void;
/** Indicates the tone of the range input */
tone?: 'magic';
}
Loading