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

feat(range): add reference point for start position of range slider #25598

Merged
merged 20 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions angular/src/directives/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1304,13 +1304,13 @@ mouse drag, touch gesture, or keyboard interaction.

@ProxyCmp({
defineCustomElementFn: undefined,
inputs: ['color', 'debounce', 'disabled', 'dualKnobs', 'max', 'min', 'mode', 'name', 'pin', 'pinFormatter', 'snaps', 'step', 'ticks', 'value']
inputs: ['barActiveStart', 'color', 'debounce', 'disabled', 'dualKnobs', 'max', 'min', 'mode', 'name', 'pin', 'pinFormatter', 'snaps', 'step', 'ticks', 'value']
})
@Component({
selector: 'ion-range',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
inputs: ['color', 'debounce', 'disabled', 'dualKnobs', 'max', 'min', 'mode', 'name', 'pin', 'pinFormatter', 'snaps', 'step', 'ticks', 'value']
inputs: ['barActiveStart', 'color', 'debounce', 'disabled', 'dualKnobs', 'max', 'min', 'mode', 'name', 'pin', 'pinFormatter', 'snaps', 'step', 'ticks', 'value']
})
export class IonRange {
protected el: HTMLElement;
Expand Down
1 change: 1 addition & 0 deletions core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ ion-radio-group,prop,value,any,undefined,false,false
ion-radio-group,event,ionChange,RadioGroupChangeEventDetail<any>,true

ion-range,shadow
ion-range,prop,barActiveStart,number,this.min,false,false
ion-range,prop,color,"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined,undefined,false,true
ion-range,prop,debounce,number,0,false,false
ion-range,prop,disabled,boolean,false,false,false
Expand Down
8 changes: 8 additions & 0 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2076,6 +2076,10 @@ export namespace Components {
"value"?: any | null;
}
interface IonRange {
/**
* The start position of the range active bar, only available with a single knob (dualKnobs="false"). Valid values are between the `min` and `max` values.
*/
"barActiveStart"?: number;
/**
* The color to use from your application's color palette. Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`. For more information on colors, see [theming](/docs/theming/basics).
*/
Expand Down Expand Up @@ -5961,6 +5965,10 @@ declare namespace LocalJSX {
"value"?: any | null;
}
interface IonRange {
/**
* The start position of the range active bar, only available with a single knob (dualKnobs="false"). Valid values are between the `min` and `max` values.
*/
"barActiveStart"?: number;
/**
* The color to use from your application's color palette. Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`. For more information on colors, see [theming](/docs/theming/basics).
*/
Expand Down
47 changes: 43 additions & 4 deletions core/src/components/range/range.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
import { findClosestIonContent, disableContentScrollY, resetContentScrollY } from '../../utils/content';
import type { Attributes } from '../../utils/helpers';
import { inheritAriaAttributes, clamp, debounceEvent, getAriaLabel, renderHiddenInput } from '../../utils/helpers';
import { printIonWarning } from '../../utils/logging';
import { isRTL } from '../../utils/rtl';
import { createColorClasses, hostContext } from '../../utils/theme';

Expand Down Expand Up @@ -142,6 +143,29 @@ export class Range implements ComponentInterface {
*/
@Prop() ticks = true;

/**
* The start position of the range active bar, only available with a single knob (dualKnobs="false").
sean-perkins marked this conversation as resolved.
Show resolved Hide resolved
* Valid values are between the `min` and `max` values.
sean-perkins marked this conversation as resolved.
Show resolved Hide resolved
*/
@Prop() barActiveStart?: number;
@Watch('barActiveStart')
sean-perkins marked this conversation as resolved.
Show resolved Hide resolved
protected barActiveStartChanged() {
const { barActiveStart } = this;
if (barActiveStart !== undefined) {
if (barActiveStart > this.max) {
printIonWarning(
`Range: The value of barActiveStart (${barActiveStart}) is greater than the max (${this.max}). Accepted values are between the min and max values of the range.`,
this.el
);
} else if (barActiveStart < this.min) {
printIonWarning(
`Range: The value of barActiveStart (${barActiveStart}) is less than the min (${this.min}). Accepted values are between the min and max values of the range.`,
this.el
);
}
}
}

/**
* If `true`, the user cannot interact with the range.
*/
Expand Down Expand Up @@ -252,6 +276,7 @@ export class Range implements ComponentInterface {
this.updateRatio();
this.debounceChanged();
this.disabledChanged();
this.barActiveStartChanged();

/**
* If we have not yet rendered
Expand Down Expand Up @@ -395,7 +420,11 @@ export class Range implements ComponentInterface {
if (this.dualKnobs) {
return Math.min(this.ratioA, this.ratioB);
}
return 0;
const { barActiveStart } = this;
if (barActiveStart == null) {
return 0;
}
return valueToRatio(barActiveStart, this.min, this.max);
}

private get ratioUpper() {
Expand Down Expand Up @@ -484,8 +513,8 @@ export class Range implements ComponentInterface {
labelText = inheritedAttributes['aria-label'];
}
const mode = getIonMode(this);
const barStart = `${ratioLower * 100}%`;
const barEnd = `${100 - ratioUpper * 100}%`;
let barStart = `${ratioLower * 100}%`;
let barEnd = `${100 - ratioUpper * 100}%`;

const rtl = isRTL(this.el);

Expand All @@ -498,6 +527,16 @@ export class Range implements ComponentInterface {
};
};

if (this.dualKnobs === false) {
if (this.valA < (this.barActiveStart ?? this.min)) {
barStart = `${ratioUpper * 100}%`;
barEnd = `${100 - ratioLower * 100}%`;
} else {
barStart = `${ratioLower * 100}%`;
barEnd = `${100 - ratioUpper * 100}%`;
}
}

sean-perkins marked this conversation as resolved.
Show resolved Hide resolved
const barStyle = {
[start]: barStart,
[end]: barEnd,
Expand All @@ -510,7 +549,7 @@ export class Range implements ComponentInterface {

const tick: any = {
ratio,
active: ratio >= ratioLower && ratio <= ratioUpper,
active: ratio >= Math.min(ratioLower, ratioUpper) && ratio <= Math.max(ratioLower, ratioUpper),
sean-perkins marked this conversation as resolved.
Show resolved Hide resolved
};

tick[start] = `${ratio * 100}%`;
Expand Down
141 changes: 141 additions & 0 deletions core/src/components/range/test/barActiveStart/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8" />
<title>Range - barActiveStart</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<link href="../../../../../css/core.css" rel="stylesheet" />
<link href="../../../../../scripts/testing/styles.css" rel="stylesheet" />
<script src="../../../../../scripts/testing/scripts.js"></script>
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
</head>

<body>
sean-perkins marked this conversation as resolved.
Show resolved Hide resolved
<ion-app>
<ion-header>
<ion-toolbar>
<ion-title>Range - barActiveStart</ion-title>
</ion-toolbar>
</ion-header>
<ion-content class="ion-padding" id="content">
<ion-list>
<ion-item>
<ion-label position="stacked">barActiveStart is 0 and value is 0.</ion-label>
<ion-range
class="ion-no-padding"
min="-100"
max="100"
snaps="10"
step="10"
pin="true"
bar-active-start="0"
value="0"
>
</ion-range>
</ion-item>
<ion-item>
<ion-label position="stacked"> barActiveStart is 0 and value is 70. </ion-label>
<ion-range
class="ion-no-padding"
min="-100"
max="100"
snaps="10"
step="10"
pin="true"
bar-active-start="0"
value="70"
>
</ion-range>
</ion-item>
<ion-item>
<ion-label position="stacked"> barActiveStart is 0 and value is -70. </ion-label>
<ion-range
class="ion-no-padding"
min="-100"
max="100"
snaps="10"
step="10"
pin="true"
bar-active-start="0"
value="-70"
>
</ion-range>
</ion-item>
<ion-item>
<ion-label position="stacked"> barActiveStart is -30 and value is 0. </ion-label>
<ion-range
class="ion-no-padding"
min="-100"
max="100"
snaps="10"
step="10"
pin="true"
bar-active-start="-30"
value="0"
>
</ion-range>
</ion-item>
<ion-item>
<ion-label position="stacked"> barActiveStart is 30 and value is 0. </ion-label>
<ion-range
class="ion-no-padding"
min="-100"
max="100"
snaps="10"
step="10"
pin="true"
bar-active-start="30"
value="0"
>
</ion-range>
</ion-item>
<ion-item>
<ion-label position="stacked">barActiveStart is between steps</ion-label>
<ion-range
class="ion-no-padding"
min="-100"
max="100"
snaps="10"
step="10"
pin="true"
bar-active-start="25"
value="0"
></ion-range>
</ion-item>
<ion-item>
<ion-label position="stacked">invalid barActiveStart value (less than min)</ion-label>
<ion-range class="ion-no-padding" min="0" max="100" snaps="10" step="10" pin="true" bar-active-start="-30">
</ion-range>
</ion-item>
<ion-item>
<ion-label position="stacked">invalid barActiveStart value (greater than max)</ion-label>
<ion-range class="ion-no-padding" min="0" max="100" snaps="10" step="10" pin="true" bar-active-start="110">
</ion-range>
</ion-item>
<ion-item>
<ion-label position="stacked"> barActiveStart is ignored with dual knobs enabled. </ion-label>
<ion-range
class="ion-no-padding"
min="-100"
max="100"
snaps="10"
step="10"
pin="true"
bar-active-start="-30"
dual-knobs="true"
value="30"
></ion-range>
</ion-item>
</ion-list>
</ion-content>
</ion-app>
</body>
</html>
12 changes: 12 additions & 0 deletions core/src/components/range/test/barActiveStart/range.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';

test.describe('range: barActiveStart', () => {
test('should not have visual regressions', async ({ page }) => {
await page.goto(`/src/components/range/test/barActiveStart`);

await page.setIonViewport();

expect(await page.screenshot()).toMatchSnapshot(`range-barActiveStart-diff-${page.getSnapshotSettings()}.png`);
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions core/src/utils/logging/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @param message - The string message to be logged to the console.
*/
export const printIonWarning = (message: string) => {
return console.warn(`[Ionic Warning]: ${message}`);
export const printIonWarning = (message: string, ...params: any[]) => {
return console.warn(`[Ionic Warning]: ${message}`, ...params);
};

/*
Expand Down
1 change: 1 addition & 0 deletions packages/vue/src/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ export const IonRange = /*@__PURE__*/ defineContainer<JSX.IonRange>('ion-range',
'snaps',
'step',
'ticks',
'barActiveStart',
'disabled',
'value',
'ionChange',
Expand Down