Skip to content

Commit

Permalink
add webui-range-input
Browse files Browse the repository at this point in the history
  • Loading branch information
basher committed Apr 4, 2024
1 parent 72de993 commit b9210aa
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 99 deletions.
47 changes: 0 additions & 47 deletions ui/src/javascript/modules/range-slider.ts

This file was deleted.

5 changes: 3 additions & 2 deletions ui/src/javascript/ui-init.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Dependencies.
// 1. Modules.
import FormValidate from './modules/form-validate';
import RangeSlider from './modules/range-slider';
import Search from './modules/search';
import Slider from './modules/slider';

Expand All @@ -14,14 +13,14 @@ import WebUIMakeClickable from './web-components/webui-make-clickable';
import WebUIModal from './web-components/webui-modal';
import WebUINotify from './web-components/webui-notify';
import WebUIProse from './web-components/webui-prose';
import WebUIRangeInput from './web-components/webui-range-input';
import WebUIShare from './web-components/webui-share';
import WebUIToggle from './web-components/webui-toggle';
import WebUITabs from './web-components/webui-tabs';
import WebUIVideoPlayer from './web-components/webui-video-player';

export const uiInit = (): void => {
FormValidate.start();
RangeSlider.start();
Search.start();
Slider.start();

Expand All @@ -39,6 +38,8 @@ export const uiInit = (): void => {
customElements.define('webui-notify', WebUINotify);
!customElements.get('webui-prose') &&
customElements.define('webui-prose', WebUIProse);
!customElements.get('webui-range-input') &&
customElements.define('webui-range-input', WebUIRangeInput);
!customElements.get('webui-share') &&
customElements.define('webui-share', WebUIShare);
!customElements.get('webui-tabs') &&
Expand Down
32 changes: 32 additions & 0 deletions ui/src/javascript/web-components/webui-range-input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export default class WebUIRangeInput extends HTMLElement {
private rangeInput: HTMLInputElement | null;
private rangeOutput: HTMLOutputElement | null;

constructor() {
super();

this.rangeInput = this.querySelector('[type="range"]');
this.rangeOutput = this.querySelector('output');

if (!this.rangeInput || !this.rangeOutput) return;

this.rangeOutput.innerHTML = this.rangeInput.value;
this.rangeInput.addEventListener('input', this);
}

private handleValidRanges(
range: HTMLInputElement,
bubble: HTMLOutputElement,
): void {
range.setAttribute('value', range.value);
range.setAttribute('aria-valuenow', range.value);
bubble.innerHTML = range.value;
}

// Handle constructor() event listeners.
handleEvent() {
this.rangeInput &&
this.rangeOutput &&
this.handleValidRanges(this.rangeInput, this.rangeOutput);
}
}
2 changes: 1 addition & 1 deletion ui/src/javascript/web-components/webui-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default class WebUIToggle extends HTMLElement {

constructor() {
super();
this.switch = this.querySelector('[role="switch"]');
this.switch = this.querySelector('[role=switch]');

if (!this.switch) return;

Expand Down
1 change: 0 additions & 1 deletion ui/src/stylesheets/form/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
@use 'input';
@use 'label';
@use 'radio';
@use 'range';
@use 'select';
@use 'textarea';
1 change: 1 addition & 0 deletions ui/src/stylesheets/web-components/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@use 'webui-modal';
@use 'webui-notify';
@use 'webui-prose';
@use 'webui-range-input-slider';
@use 'webui-share';
@use 'webui-tabs';
@use 'webui-toggle';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Dependencies.
block-size: var(--slider-height);
}

.range {
&__bubble {
webui-range-input-slider {
output {
margin-inline: auto;
}
}
Expand Down
19 changes: 0 additions & 19 deletions ui/stories/4. Forms/RangeInputSlider/RangeInputSlider.js

This file was deleted.

12 changes: 0 additions & 12 deletions ui/stories/4. Forms/RangeInputSlider/RangeInputSlider.mdx

This file was deleted.

15 changes: 0 additions & 15 deletions ui/stories/4. Forms/RangeInputSlider/RangeInputSlider.stories.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export const WebUIRangeInputHtml = () => `
<webui-range-input>
<div class="form__field">
<label for="range-input" class="label">
Range slider
</label>
<input
class="input"
type="range"
id="range-input"
value="1"
min="1"
max="10"
aria-valuenow="1"
aria-valuemin="1"
aria-valuemax="10"
/>
<output></output>
</div>
</webui-range-input>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Meta, Canvas } from '@storybook/blocks';
import * as WebUIRangeInput from './WebUIRangeInput.stories';

<Meta of={WebUIRangeInput} />

# `<webui-range-input>`
- JavaScript is required to display the numeric range value inside the `<output>` element.

## Accessibility considerations
- See the [ARIA APG slider pattern](https://www.w3.org/WAI/ARIA/apg/patterns/slider/).

<Canvas of={WebUIRangeInput.WebUIRangeInput} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { WebUIRangeInputHtml } from './WebUIRangeInput';

export default {
title: 'Web Components Or Custom Elements/<webui-range-input>',
parameters: {
status: {
type: 'stable',
},
},
};

export const WebUIRangeInput = {
render: (args) => WebUIRangeInputHtml(args),
};
WebUIRangeInput.storyName = '<webui-range-input>';

0 comments on commit b9210aa

Please sign in to comment.