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

Improve range slider callbacks #459

Merged
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d2addda
add onDebounceChange and onChange, remove type errors
xavierdonnellon Jul 17, 2023
db6a2f0
add onDebounceChange onChange, fix tests
xavierdonnellon Jul 18, 2023
1be8bd8
fix weird typescirpt error
xavierdonnellon Jul 18, 2023
7401beb
cleanup processing logic
xavierdonnellon Jul 18, 2023
3bd08b7
upgrade jest, update snapshots, center drag handle
xavierdonnellon Jul 18, 2023
0333acb
fix ts errors
xavierdonnellon Jul 18, 2023
389b413
dont default onChange to onDrag
xavierdonnellon Jul 18, 2023
e650e4f
fix handle alignment
xavierdonnellon Jul 18, 2023
c6c4672
update snapshots
xavierdonnellon Jul 18, 2023
ffcf341
fix range rail animation, add debounced onRelease callback
xavierdonnellon Jul 18, 2023
0e29b07
add handle snap functionality
xavierdonnellon Jul 31, 2023
5e74f91
ive done it.
xavierdonnellon Jul 31, 2023
7bc5ab5
update snapshots
xavierdonnellon Jul 31, 2023
ac1ed4b
merge main
xavierdonnellon Jul 31, 2023
3843aaa
fix tests?
xavierdonnellon Jul 31, 2023
8cd5d9f
fix snapshots
xavierdonnellon Jul 31, 2023
7c9e8a7
feat(rangeslider): add onChange and onDebounceChange callbacks to sli…
xavierdonnellon Jul 31, 2023
572d5bb
improve types, remove stats.html
xavierdonnellon Aug 1, 2023
ce170e8
merge main
xavierdonnellon Aug 1, 2023
bdcc26b
remove stats
xavierdonnellon Aug 1, 2023
9735856
update stories
xavierdonnellon Aug 1, 2023
4eba83d
update snapshots
xavierdonnellon Aug 1, 2023
c0bddfa
Merge branch 'master' into improve-range-slider-callbacks
xavierdonnellon Aug 1, 2023
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
11 changes: 4 additions & 7 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,7 @@ module.exports = {
// snapshotSerializers: [],

// The test environment that will be used for testing
// TODO: Some part of the create-react-app dependency set doesn't like
// the latest version of jest/react-testing-library
// See https://stackoverflow.com/questions/61036156/react-typescript-testing-typeerror-mutationobserver-is-not-a-constructor
// for entrypoint into the conversation/band-aid fix. We should be able to use
// the native jsdom environment once this issue is resolved.
testEnvironment: 'jest-environment-jsdom-sixteen',
testEnvironment: 'jsdom',

// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},
Expand All @@ -174,7 +169,9 @@ module.exports = {
// testRunner: 'jasmine2',

// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
// testURL: 'http://localhost',
testEnvironmentOptions: {
url: 'http://localhost:9009',
},

// Setting this value to 'fake' allows the use of fake timers for functions such as 'setTimeout'
// timers: 'real',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@
"eslint-plugin-react-hooks": "^4.0.2",
"faker": "^4.1.0",
"husky": "^4.2.5",
"jest": "^26.0.1",
"jest": "^29.6.1",
"jest-axe": "^3.5.0",
"jest-coverage-badges": "^1.1.2",
"jest-environment-jsdom-sixteen": "^1.0.3",
"jest-environment-jsdom": "^29.6.1",
"jest-styled-components": "^7.0.2",
"lodash": "^4.17.15",
"pre-commit": "^1.2.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Label should have asterisk icon if isRequired is true 1`] = `
Object {
{
"asFragment": [Function],
"baseElement": .c0 {
display: -webkit-inline-box;
Expand Down Expand Up @@ -162,7 +162,7 @@ Object {
`;

exports[`Label should have default color text if not given a isValid 1`] = `
Object {
{
"asFragment": [Function],
"baseElement": .c0 {
display: -webkit-inline-box;
Expand Down
81 changes: 25 additions & 56 deletions src/components/RangeSlider/RangeSlider.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React, { useState, useEffect, forwardRef } from 'react';
import styled from 'styled-components';
import { action } from '@storybook/addon-actions';
import { Story, Meta } from '@storybook/react';
import { readableColor, toColorString } from 'polished';

import { withFoundryContext } from '../../../.storybook/decorators';
import fonts from '../../enums/fonts';
import colors from '../../enums/colors';
import RangeSlider, { SlideRail } from './RangeSlider';
import { RangeSliderProps } from './types';
import { RangeSliderProps, ValueProp } from './types';
import Card from '../Card';

const Row = styled.div`
Expand Down Expand Up @@ -68,13 +67,12 @@ export const Default: Story<DefaultProps> = ({
disabled,
showDomainLabels,
showSelectedRange,
motionBlur,
springOnRelease,
min,
max,
debounceInterval,
axisLock,
dragHandleBehavior,
readonly,
debounceInterval,
}: DefaultProps) => {
const [val, setVal] = useState(value);

Expand All @@ -83,7 +81,7 @@ export const Default: Story<DefaultProps> = ({
}, [value]);

const markersSelection = markers;
const markersArray = [];
const markersArray: Array<number | ValueProp> = [];
if (markersSelection === 'all values') {
for (let i = min; i <= max; i++) {
markersArray.push(markerLabels ? { value: i, label: `${i}` } : i);
Expand All @@ -100,22 +98,13 @@ export const Default: Story<DefaultProps> = ({
readonly={readonly}
showDomainLabels={showDomainLabels}
showSelectedRange={showSelectedRange}
motionBlur={motionBlur}
springOnRelease={springOnRelease}
min={min}
max={max}
debounceInterval={debounceInterval}
onDrag={(newVal: number) => {
setVal(Math.round(newVal));
action('onDrag')(newVal);
}}
axisLock={axisLock}
values={[
{
value: val,
label: val,
},
]}
onDebounceChange={newVal => setVal(Math.round(newVal))}
dragHandleBehavior={dragHandleBehavior}
values={[{ value: val, label: val }]}
markers={markersArray as RangeSliderProps['markers']}
/>
</Row>
Expand All @@ -132,10 +121,9 @@ Default.args = {
showDomainLabels: false,
showHandleLabels: true,
showSelectedRange: true,
motionBlur: false,
springOnRelease: true,
debounceInterval: 8,
axisLock: 'x',
dragHandleBehavior: 'snapToValue',
debounceInterval: 10,
};

type RatingProps = Omit<RangeSliderProps, 'markers'> & {
Expand All @@ -147,19 +135,12 @@ export const Rating: Story<RatingProps> = ({
disabled,
showDomainLabels,
showSelectedRange,
motionBlur,
springOnRelease,
min,
max,
debounceInterval,
axisLock,
}: RatingProps) => {
const [val, setVal] = useState(value);

useEffect(() => {
setVal(value);
}, [value]);

return (
<Row>
<span>ReactJS:&nbsp;&nbsp;&nbsp;&nbsp;</span>
Expand All @@ -168,16 +149,10 @@ export const Rating: Story<RatingProps> = ({
disabled={disabled}
showDomainLabels={showDomainLabels}
showSelectedRange={showSelectedRange}
motionBlur={motionBlur}
springOnRelease={springOnRelease}
min={min}
max={max}
debounceInterval={debounceInterval}
onDrag={(newVal: number) => {
setVal(Math.round(newVal));
action('onDrag')(newVal);
xavierdonnellon marked this conversation as resolved.
Show resolved Hide resolved
}}
axisLock={axisLock}
onChange={newVal => setVal(Math.round(newVal))}
values={[
{
value: val,
Expand All @@ -194,12 +169,9 @@ Rating.args = {
disabled: false,
showDomainLabels: false,
showSelectedRange: false,
motionBlur: false,
springOnRelease: true,
min: 0,
max: 5,
debounceInterval: 8,
axisLock: 'x',
};

interface ColorPickerProps {
Expand All @@ -208,6 +180,7 @@ interface ColorPickerProps {
saturation: number;
disabled: boolean;
showDomainLabels: boolean;
debounceInterval: number;
}

export const ColorPicker: Story<ColorPickerProps> = ({
Expand All @@ -216,6 +189,7 @@ export const ColorPicker: Story<ColorPickerProps> = ({
saturation,
disabled,
showDomainLabels,
debounceInterval,
}: ColorPickerProps) => {
const [hue_, setHue] = useState(hue);
const [sat, setSat] = useState(saturation);
Expand Down Expand Up @@ -275,10 +249,8 @@ export const ColorPicker: Story<ColorPickerProps> = ({
showSelectedRange={false}
min={0}
max={360}
onDrag={(val: number) => {
setHue(Math.round(val));
action('onDrag hue')(val);
}}
debounceInterval={debounceInterval}
onDebounceChange={val => setHue(Math.round(val))}
values={[
{
value: hue_,
Expand All @@ -302,10 +274,8 @@ export const ColorPicker: Story<ColorPickerProps> = ({
))}
min={0}
max={100}
onDrag={(val: number) => {
setSat(Math.round(val));
action('onDrag saturation')(val);
}}
debounceInterval={debounceInterval}
onDebounceChange={val => setSat(Math.round(val))}
showDomainLabels={false}
showSelectedRange={false}
values={[
Expand Down Expand Up @@ -333,10 +303,8 @@ export const ColorPicker: Story<ColorPickerProps> = ({
))}
min={0}
max={100}
onDrag={(val: number) => {
setLight(Math.round(val));
action('onDrag light')(val);
}}
debounceInterval={debounceInterval}
onDebounceChange={val => setLight(Math.round(val))}
showDomainLabels={false}
showSelectedRange={false}
values={[
Expand All @@ -357,6 +325,7 @@ ColorPicker.args = {
lightness: 50,
disabled: false,
showDomainLabels: false,
debounceInterval: 10,
};

export default {
Expand Down Expand Up @@ -389,12 +358,6 @@ export default {
step: 1,
},
},
axisLock: {
options: ['x', 'y', ''],
control: {
type: 'select',
},
},
markers: {
options: ['none', 'all values', 'middle value'],
control: {
Expand Down Expand Up @@ -425,6 +388,12 @@ export default {
step: 1,
},
},
dragHandleBehavior: {
control: {
type: 'radio',
},
options: ['followMouse', 'snapToValue'],
},
},
decorators: [withFoundryContext],
parameters: {
Expand Down
Loading
Loading