-
Notifications
You must be signed in to change notification settings - Fork 14
Add OK basic slider component #3048
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
Open
Copilot
wants to merge
23
commits into
main
Choose a base branch
from
copilot/add-ok-component-for-fast-slider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
016dd15
Add OK basic slider component
Copilot b0cb180
Add OK React slider wrapper
Copilot dbbf9a5
Scope slider to TestHub namespace
Copilot 3577776
Align slider visuals with switch
Copilot ae9ad82
Add slider value feedback
Copilot 8d2ec57
Refine slider thumb and labels
Copilot 26c2893
Keep slider value stable on hover
Copilot 10dd851
Make slider width responsive
Copilot 971f1dc
Make vertical slider height responsive
Copilot aa40e11
Document slider minimum length
Copilot 0d040d0
Match slider fill to pressed thumb
Copilot 63b7623
Minor fixes.
atmgrifter00 6176c12
Remove unused slider token import
Copilot 179c2e2
Show slider range labels while active
Copilot 3e5bf1f
Add slider coverage and CSS convention fixes
Copilot e628e36
Clarify disabled slider hover styles
Copilot b563e06
Address slider review clarity
Copilot 80ad2d9
Simplify slider test fixtures
Copilot e370db1
Combine slider orientation matrix states
Copilot e3860f3
Name slider matrix size
Copilot 00ca867
Disable Vite HMR in karma config to fix flaky test disconnects
Copilot dfea43a
Revert nimble-components test workaround
Copilot e93ac86
Matrix test label style fix
atmgrifter00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@ni-ok-react-7f04b43d-439e-4848-b394-511e0909be4d.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "minor", | ||
| "comment": "Add React wrapper for the basic slider", | ||
| "packageName": "@ni/ok-react", | ||
| "email": "198982749+Copilot@users.noreply.github.com", | ||
| "dependentChangeType": "patch" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| import './slider'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { | ||
| DesignSystem, | ||
| Slider as FoundationSlider, | ||
| sliderTemplate as template, | ||
| type SliderOptions | ||
| } from '@ni/fast-foundation'; | ||
| import { styles } from './styles'; | ||
|
|
||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| 'ok-basic-slider': Slider; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * A Nimble-styled slider control. | ||
| */ | ||
| export class Slider extends FoundationSlider {} | ||
|
|
||
| const okBasicSlider = Slider.compose<SliderOptions>({ | ||
| baseName: 'basic-slider', | ||
| baseClass: FoundationSlider, | ||
| template, | ||
| styles | ||
| }); | ||
|
|
||
| DesignSystem.getOrCreate().withPrefix('ok').register(okBasicSlider()); | ||
| export const sliderTag = 'ok-basic-slider'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| import { css } from '@ni/fast-element'; | ||
| import { | ||
| applicationBackgroundColor, | ||
| bodyDisabledFontColor, | ||
| bodyFont, | ||
| bodyFontColor, | ||
| borderColor, | ||
| borderHoverColor, | ||
| borderRgbPartialColor, | ||
| borderWidth, | ||
| fillDownColor, | ||
| fillSelectedColor, | ||
| smallDelay | ||
| } from '@ni/nimble-components/dist/esm/theme-provider/design-tokens'; | ||
| import { display } from '../../utilities/style/display'; | ||
|
|
||
| export const styles = css` | ||
| @layer base, hover, focusVisible, active, disabled, top; | ||
|
|
||
| @layer base { | ||
| ${display('inline-block')} | ||
|
|
||
| :host { | ||
| width: 240px; | ||
| height: 32px; | ||
| outline: none; | ||
| color: ${bodyFontColor}; | ||
| font: ${bodyFont}; | ||
| cursor: pointer; | ||
| touch-action: none; | ||
| } | ||
|
|
||
| :host([orientation='vertical']) { | ||
| width: 32px; | ||
| height: 240px; | ||
| } | ||
|
|
||
| :host([readonly]) { | ||
| cursor: default; | ||
| } | ||
|
|
||
| .positioning-region { | ||
| position: relative; | ||
| display: flex; | ||
| width: 100%; | ||
| height: 100%; | ||
| align-items: center; | ||
| justify-content: center; | ||
| } | ||
|
|
||
| .track { | ||
| position: relative; | ||
| width: 100%; | ||
| height: 4px; | ||
| border-radius: 2px; | ||
| background-color: rgba(${borderRgbPartialColor}, 0.3); | ||
| } | ||
|
|
||
| .track-start { | ||
| position: absolute; | ||
| inset-block: 0; | ||
| left: 0; | ||
| border-radius: inherit; | ||
| background-color: ${fillSelectedColor}; | ||
| } | ||
|
|
||
| .thumb-container { | ||
| position: absolute; | ||
| top: 50%; | ||
| width: 16px; | ||
| height: 16px; | ||
| box-sizing: border-box; | ||
| border: ${borderWidth} solid ${borderColor}; | ||
| border-radius: 50%; | ||
| background-color: ${applicationBackgroundColor}; | ||
| transform: translate(50%, -50%); | ||
| transition: | ||
| border-color ${smallDelay} ease-in-out, | ||
| box-shadow ${smallDelay} ease-in-out, | ||
| background-color ${smallDelay} ease-in-out; | ||
| } | ||
|
|
||
| :host([orientation='vertical']) .positioning-region { | ||
| align-items: initial; | ||
| } | ||
|
|
||
| :host([orientation='vertical']) .track { | ||
| width: 4px; | ||
| height: 100%; | ||
| } | ||
|
|
||
| :host([orientation='vertical']) .track-start { | ||
| inset-block-start: 0; | ||
| inset-inline: 0; | ||
| } | ||
|
|
||
| :host([orientation='vertical']) .thumb-container { | ||
| top: auto; | ||
| left: 50%; | ||
| transform: translate(-50%, 50%); | ||
| } | ||
|
|
||
| ::slotted(*) { | ||
| color: ${bodyFontColor}; | ||
| font: ${bodyFont}; | ||
| } | ||
| } | ||
|
|
||
| @layer hover { | ||
| :host(:not([disabled]):not([readonly]):hover) .thumb-container { | ||
| border-color: ${borderHoverColor}; | ||
| box-shadow: 0 0 0 ${borderWidth} ${borderHoverColor}; | ||
| } | ||
| } | ||
|
|
||
| @layer focusVisible { | ||
| :host(:focus-visible) .thumb-container { | ||
| border-color: ${borderHoverColor}; | ||
| box-shadow: | ||
| 0 0 0 ${borderWidth} ${applicationBackgroundColor}, | ||
| 0 0 0 calc(${borderWidth} * 2) ${borderHoverColor}; | ||
| } | ||
| } | ||
|
|
||
| @layer active { | ||
| :host(:not([disabled]):not([readonly]):active) .thumb-container { | ||
| border-color: ${borderHoverColor}; | ||
| background-color: ${fillDownColor}; | ||
| } | ||
| } | ||
|
|
||
| @layer disabled { | ||
| :host([disabled]) { | ||
| color: ${bodyDisabledFontColor}; | ||
| cursor: default; | ||
| } | ||
|
|
||
| :host([disabled]) .track { | ||
| background-color: rgba(${borderRgbPartialColor}, 0.1); | ||
| } | ||
|
|
||
| :host([disabled]) .track-start { | ||
| background-color: rgba(${borderRgbPartialColor}, 0.2); | ||
| } | ||
|
|
||
| :host([disabled]) .thumb-container { | ||
| border-color: rgba(${borderRgbPartialColor}, 0.2); | ||
| background-color: ${applicationBackgroundColor}; | ||
| box-shadow: none; | ||
| } | ||
|
|
||
| :host([disabled]) ::slotted(*) { | ||
| color: ${bodyDisabledFontColor}; | ||
| } | ||
| } | ||
|
|
||
| @layer top {} | ||
| `; |
22 changes: 22 additions & 0 deletions
22
packages/ok-components/src/basic/slider/tests/slider.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { html } from '@ni/fast-element'; | ||
| import { Slider, sliderTag } from '..'; | ||
| import { fixture } from '../../../utilities/tests/fixture'; | ||
|
|
||
| describe('Slider', () => { | ||
| it('can construct an element instance', () => { | ||
| expect(document.createElement(sliderTag)).toBeInstanceOf(Slider); | ||
| }); | ||
|
|
||
| it('provides the FAST Foundation slider template', async () => { | ||
| const { element, connect, disconnect } = await fixture<Slider>( | ||
| html`<${sliderTag}></${sliderTag}>` | ||
| ); | ||
| await connect(); | ||
|
|
||
| expect(element.shadowRoot?.querySelector('[part="track-container"]')).not.toBeNull(); | ||
| expect(element.shadowRoot?.querySelector('[part="track-start"]')).not.toBeNull(); | ||
| expect(element.shadowRoot?.querySelector('[part="thumb-container"]')).not.toBeNull(); | ||
|
|
||
| await disconnect(); | ||
| }); | ||
| }); |
18 changes: 18 additions & 0 deletions
18
packages/react-workspace/ok-react/src/basic/slider/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| 'use client'; | ||
|
|
||
| import { | ||
| Slider, | ||
| sliderTag | ||
| } from '@ni/ok-components/dist/esm/basic/slider'; | ||
| import { wrap, type EventName } from '../../utilities/react-wrapper'; | ||
|
|
||
| export { sliderTag }; | ||
| export { type Slider }; | ||
| export const OkBasicSlider = wrap(Slider, { | ||
| events: { | ||
| onChange: 'change' as EventName<SliderChangeEvent> | ||
| } | ||
| }); | ||
| export interface SliderChangeEvent extends CustomEvent { | ||
| target: Slider; | ||
| } |
60 changes: 60 additions & 0 deletions
60
packages/storybook/src/ok/basic/slider/slider-matrix.stories.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import type { Meta, StoryFn } from '@storybook/html-vite'; | ||
| import { html, type ViewTemplate } from '@ni/fast-element'; | ||
| import { sliderTag } from '@ni/ok-components/dist/esm/basic/slider'; | ||
| import { | ||
| cartesianProduct, | ||
| createMatrix, | ||
| createMatrixInteractionsFromStates, | ||
| createMatrixThemeStory, | ||
| sharedMatrixParameters | ||
| } from '../../../utilities/matrix'; | ||
|
|
||
| const metadata: Meta = { | ||
| title: 'Tests Ok/Basic Slider', | ||
| parameters: { | ||
| ...sharedMatrixParameters() | ||
| } | ||
| }; | ||
|
|
||
| export default metadata; | ||
|
|
||
| type SliderState = readonly [string, boolean, boolean]; | ||
|
|
||
| const states: SliderState[] = [ | ||
| ['Enabled', false, false], | ||
| ['Readonly', false, true], | ||
| ['Disabled', true, false] | ||
| ]; | ||
|
|
||
| const interactionStates = cartesianProduct([states] as const); | ||
|
|
||
| const component = ([name, disabled, readOnly]: SliderState): ViewTemplate => html` | ||
| <div style="display: inline-flex; flex-direction: column; gap: 8px; margin: 8px;"> | ||
| <span>${() => name}</span> | ||
| <${sliderTag} | ||
| value="40" | ||
| ?disabled="${() => disabled}" | ||
| ?readonly="${() => readOnly}" | ||
| ></${sliderTag}> | ||
| </div> | ||
| `; | ||
|
|
||
| export const statesThemeMatrix: StoryFn = createMatrixThemeStory( | ||
| createMatrix(component, [states]) | ||
| ); | ||
|
|
||
| export const orientationsThemeMatrix: StoryFn = createMatrixThemeStory(html` | ||
| <div style="display: flex; gap: 32px; align-items: flex-start; padding: 16px;"> | ||
| <${sliderTag} value="40"></${sliderTag}> | ||
| <${sliderTag} value="40" orientation="vertical"></${sliderTag}> | ||
| </div> | ||
| `); | ||
|
|
||
| export const interactionsThemeMatrix: StoryFn = createMatrixThemeStory( | ||
| createMatrixInteractionsFromStates(component, { | ||
| hover: interactionStates, | ||
| hoverActive: interactionStates, | ||
| active: interactionStates, | ||
| focus: interactionStates | ||
| }) | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { Canvas, Controls, Meta, Title } from '@storybook/addon-docs/blocks'; | ||
| import ComponentApisLink from '../../../docs/component-apis-link.mdx'; | ||
| import * as sliderStories from './slider.stories'; | ||
|
|
||
| <Meta of={sliderStories} /> | ||
| <Title of={sliderStories} /> | ||
|
|
||
| A Nimble-styled slider based on the FAST Foundation slider. | ||
|
|
||
| <Canvas of={sliderStories.slider} /> | ||
|
|
||
| ## API | ||
|
|
||
| <Controls of={sliderStories.slider} /> | ||
|
|
||
| <ComponentApisLink /> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.