Skip to content

Implement Spectrum slider components #1070

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

Closed
devongovett opened this issue Sep 16, 2020 · 1 comment · Fixed by #1083
Closed

Implement Spectrum slider components #1070

devongovett opened this issue Sep 16, 2020 · 1 comment · Fixed by #1083
Assignees
Labels
enhancement New feature or request rsp:Slider

Comments

@devongovett
Copy link
Member

🙋 Feature Request

Implement the Spectrum Slider and RangeSlider components using the existing useSlider and useSliderThumb hooks.

imageimage

💁 Possible Solution

The API should look like this:

interface SpectrumBarSliderBase<T> extends BaseSliderProps, ValueBase<T> {
  orientation?: Orientation,
  labelPosition?: LabelPosition,
  /** Whether the value's label is displayed. True by default if there's a `label`, false by default if not. */
  showValueLabel?: boolean,
  /** The content to display as the value's label. Overrides default formatted number. */
  valueLabel?: ReactNode
}

interface SpectrumSliderTicksBase {
  // Enables tick marks if > 0.
  // Ticks will be evenly distributed between the min and max values.
  tickCount?: number,

  // Enables tick labels.
  // By default, labels are formatted using the slider's number formatter,
  // but you can use the tickLabels prop to override these with custom labels.
  showTickLabels?: boolean,
  tickLabels?: Array<ReactNode>
}

interface SpectrumSliderProps extends SpectrumBarSliderBase<number>, SpectrumSliderTicksBase {
  /** Whether a fill color is shown between the start of the slider and the current value. See https://spectrum.adobe.com/page/slider/#Fill */
  isFilled?: boolean,
  /** The offset from which to start the fill. See https://spectrum.adobe.com/page/slider/#Fill-start */
  fillOffset?: number,
  /** The background of the track, e.g. a CSS linear-gradient(). See https://spectrum.adobe.com/page/slider/#Gradient */ 
  trackBackground?: string
}

interface SpectrumRangeSlider extends SpectrumBarSliderBase<RangeValue<number>>, SpectrumSliderTicksBase {}

The existing useSlider and useSliderThumb hooks can be used to implement this. These hooks allow an arbitrary number of thumbs per slider, but Spectrum will be more restricted. The Slider component will support only one thumb with a value prop that is a single number, and the RangeSlider component will support two thumbs with a value prop that is a range object with a start and end property. This should be able to be normalized within the Spectrum components rather than creating new ARIA/Stately hooks, but we could move those out later if we find it a common shortcut people need.

Intl.NumberFormat should be used for number formatting. The option in Spectrum to show the +/- sign is available in the unitDisplay format option, but it is not yet implemented in Safari so we may need to polyfill it (TBD). Also the unit options don't include px, so we will potentially need to find an alternate solution to that later on.

💻 Examples

See https://spectrum.adobe.com/page/slider/ and contributions (internal) for design mocks, and https://opensource.adobe.com/spectrum-css/slider.html for the existing Spectrum CSS implementation.

🧢 Your Company/Team

RSP

@mischnic
Copy link
Contributor

(unitDisplay signDisplay)

majornista added a commit to majornista/react-spectrum-v3 that referenced this issue Oct 6, 2020
…layValue

Pressing the displayValue should focus the corresponding input.
majornista added a commit to majornista/react-spectrum-v3 that referenced this issue Nov 3, 2020
majornista added a commit to majornista/react-spectrum-v3 that referenced this issue Nov 3, 2020
…layValue

Pressing the displayValue should focus the corresponding input.

fix(adobe#1070) A11y: updates per code review

Co-Authored-By: Robert Snow <[email protected]>
majornista added a commit to majornista/react-spectrum-v3 that referenced this issue Nov 3, 2020
…pdate Slider (hook) stories

Co-Authored-By: Robert Snow <[email protected]>
majornista added a commit to majornista/react-spectrum-v3 that referenced this issue Nov 4, 2020
dannify pushed a commit that referenced this issue Dec 16, 2020
* fix(#1070) A11y: add minimum/maximum labels, use output for displayValue

Pressing the displayValue should focus the corresponding input.

fix(#1070) A11y: updates per code review

Co-Authored-By: Robert Snow <[email protected]>

* fix(#1070) refactor minimum/maximum labels into useSliderThumb/update Slider (hook) stories

Co-Authored-By: Robert Snow <[email protected]>

* fix(#1070) A11y: remove slider/intl/index.js which is no longer necessary

Co-Authored-By: Robert Snow <[email protected]>

* Slider refactoring

* Fix translation files

* fix(i18n): Apply suggestions from code review

Co-authored-by: Daniel Lu <[email protected]>

* refactor(per code review): remove duplicate style declaration

Co-authored-by: Michael Jordan <[email protected]>
Co-authored-by: Robert Snow <[email protected]>
Co-authored-by: Michael Jordan <[email protected]>
Co-authored-by: Daniel Lu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request rsp:Slider
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants