-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ec9fb1
commit cfa120a
Showing
16 changed files
with
462 additions
and
131 deletions.
There are no files selected for viewing
This file contains 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 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 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,80 @@ | ||
<h2>Range</h2> | ||
<p>A wrapper around the native range input.</p> | ||
|
||
<h3>Default</h3> | ||
<Range /> | ||
|
||
<h3>Disabled</h3> | ||
<Range disabled /> | ||
|
||
<h3>With tooltip hidden</h3> | ||
<Range hideTooltip /> | ||
|
||
<h3>With different constraints</h3> | ||
<Range min="10" max="100" step="5" /> | ||
|
||
<h3>With label</h3> | ||
<Range label="Slide to the right" /> | ||
|
||
<h3>With label and info text</h3> | ||
<Range label="Write some text" info="This is some info for you" /> | ||
|
||
<h3>With label and error and live validation</h3> | ||
<Range label="Move the slider" {error} on:change="{onChange}" value="5" /> | ||
|
||
<h3>With label, info, and error</h3> | ||
<Range label="Move the slider" info="Don't make any mistakes!" error="You did not slide!" /> | ||
|
||
<h3>Label on the left</h3> | ||
<Range label="Label is on the left" labelOnTheLeft="true"/> | ||
|
||
|
||
|
||
<CodeExample html="{exampleHtml}" /> | ||
|
||
<API props="{apiProps}"/> | ||
|
||
|
||
<script> | ||
import { Range } from '../../../../src'; | ||
import { API } from '../../../api-table'; | ||
import { CodeExample } from '../../../code-example'; | ||
const apiProps = [ | ||
{ name: 'class', type: 'string', description: 'Additional css class name to be added to the component.' }, | ||
{ name: 'disabled', description: 'Make the input disabled.' }, | ||
{ name: 'id', type: 'string', description: 'Assign ID to the underlying input.' }, | ||
{ name: 'info', type: 'string', description: 'Show info message above the input.' }, | ||
{ name: 'error', type: 'string', description: 'Error message to show above the input.' }, | ||
{ name: 'hideTooltip', description: 'If present, the value tooltip will not be shown.' }, | ||
{ name: 'name', type: 'string', description: 'Assign title to the underlying input.' }, | ||
{ name: 'label', type: 'string', description: 'Label for the input.' }, | ||
{ name: 'labelOnTheLeft', type: ['true', 'false'], default: 'false', description: 'Put label to the left of the input (instead of at the top). Usually in longer forms, to align labels and inputs, hence input also gets <em>width: 100%</em>, as it will be constraint by the form container.' }, | ||
{ name: 'max', type: ['number'], default: '10', description: 'Max value of the input.' }, | ||
{ name: 'min', type: ['number'], default: '0', description: 'Min value of the input.' }, | ||
{ name: 'step', type: ['number'], default: '1', description: 'Step value of the input.' }, | ||
{ name: 'title', type: 'string', description: 'Assign title to the underlying input.' }, | ||
{ name: 'value', type: 'string', description: 'Initial value of the input.' }, | ||
{ name: 'bind:element', type: 'element', description: 'Exposes the HTML element of the component.' }, | ||
{ name: 'bind:inputElement', type: 'element', description: 'Exposes the HTML element of the underlying input.' }, | ||
{ name: 'on:change', type: 'function', description: 'Triggered when the value changes.' }, | ||
{ name: 'on:input', type: 'function', description: 'Triggered when input value is edited.' }, | ||
]; | ||
const exampleHtml = ` | ||
<Range autogrow on:change="{onChange}" error="Invalid text" /> | ||
<script> | ||
function onChange (e) { | ||
console.log('value', e.target.value); | ||
} | ||
</script> | ||
`; | ||
let error = 'Move to 6.'; | ||
function onChange (e) { | ||
error = e.target.value === '6' ? '' : 'Move to 6.'; | ||
} | ||
</script> |
This file contains 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 @@ | ||
export { default as Range } from './Range.svelte'; |
This file contains 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 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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,84 @@ | ||
.range { | ||
position: relative; | ||
width: 25ch; | ||
vertical-align: top; | ||
--range-size: calc(var(--ui-button-height) / 3 * 2); | ||
} | ||
|
||
.range .range-inner { | ||
display: flex; | ||
flex-flow: column; | ||
gap: 0.5rem; | ||
flex: 1; | ||
padding: 0.75rem 0; | ||
position: relative; | ||
} | ||
|
||
.range input { | ||
-webkit-appearance: none; | ||
appearance: none; | ||
margin: 0; | ||
width: 100%; | ||
height: 0.5rem; | ||
border-radius: 5rem; | ||
padding-inline: 0; | ||
border: 1px solid var(--ui-color-border); | ||
background: var(--ui-color-background-input); | ||
background-image: linear-gradient(var(--ui-color-highlight), var(--ui-color-highlight)); | ||
background-size: 70% 100%; | ||
background-repeat: no-repeat; | ||
background-clip: padding-box; | ||
} | ||
|
||
.range input::-webkit-slider-runnable-track { | ||
-webkit-appearance: none; | ||
display: flex; | ||
align-items: center; | ||
height: 0.5rem; | ||
border-radius: 0.5rem; | ||
} | ||
|
||
.range input::-moz-range-track { | ||
display: flex; | ||
align-items: center; | ||
background-color: var(--ui-color-background-input); | ||
height: 0.5rem; | ||
border-radius: 0.5rem; | ||
} | ||
|
||
.range input::-webkit-slider-thumb { | ||
-webkit-appearance: none; | ||
appearance: none; | ||
background-color: var(--ui-color-text); | ||
height: var(--range-size); | ||
width: var(--range-size); | ||
border-radius: 5rem; | ||
box-shadow: 0 1px 3px #000c; | ||
} | ||
|
||
.range input::-moz-range-thumb { | ||
background-color: var(--ui-color-text); | ||
height: var(--range-size); | ||
width: var(--range-size); | ||
border-radius: 5rem; | ||
box-shadow: 0 1px 3px #000c; | ||
} | ||
|
||
/* Cannot be merged, as it won't work in safari */ | ||
.range:not(.disabled) input::-webkit-slider-thumb:active { transform: scale(0.9); } | ||
.range:not(.disabled) input::-moz-slider-thumb:active { transform: scale(0.9); } | ||
|
||
|
||
.range-tooltip { | ||
position: absolute; | ||
bottom: 0; | ||
width: calc(100% - var(--range-size) - 2px); | ||
margin-inline: calc(var(--range-size) / 2 + 1px); | ||
transform: translateY(calc(var(--range-size) * -1 - 0.3rem)); | ||
display: none; | ||
} | ||
|
||
.range-tooltip .tooltip-plate { display: inline-flex; position: relative; transform: translateX(-50%); } | ||
|
||
.range:not(.disabled):focus-within .range-tooltip, | ||
.range:not(.disabled):active .range-tooltip { display: block; } |
This file contains 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,77 @@ | ||
<div | ||
class="range {className}" | ||
class:has-error="{error}" | ||
class:label-on-the-left="{labelOnTheLeft === true || labelOnTheLeft === 'true'}" | ||
class:disabled | ||
{title} | ||
bind:this="{element}"> | ||
|
||
<Label {label} {disabled} for="{_id}"/> | ||
<Info msg="{info}" /> | ||
|
||
<div class="range-inner" class:disabled> | ||
<InputError id="{errorMessageId}" msg="{error}" /> | ||
<input | ||
type="range" | ||
{name} | ||
{disabled} | ||
{min} | ||
{max} | ||
{step} | ||
id="{_id}" | ||
style="background-size: {progress}% 100%;" | ||
aria-invalid="{error}" | ||
aria-errormessage="{error ? errorMessageId : undefined}" | ||
bind:this="{inputElement}" | ||
bind:value="{value}" | ||
on:change | ||
on:input> | ||
|
||
{#if !hideTooltip} | ||
<div class="range-tooltip"> | ||
<div class="popover-plate popover-top tooltip-plate opened" style="left: {progress}%;"> | ||
<div class="popover tooltip" role="tooltip"> | ||
<div class="popover-content tooltip-content">{value}</div> | ||
</div> | ||
</div> | ||
</div> | ||
{/if} | ||
</div> | ||
</div> | ||
|
||
|
||
<script> | ||
import { guid } from '../../utils'; | ||
import { Info } from '../../info-bar'; | ||
import { InputError } from '../input-error'; | ||
import { Label } from '../label'; | ||
let className = ''; | ||
export { className as class }; | ||
export let id = ''; | ||
export let disabled = false; | ||
export let label = ''; | ||
export let error = undefined; | ||
export let info = undefined; | ||
export let title = undefined; | ||
export let name = undefined; | ||
export let labelOnTheLeft = false; | ||
export let min = 0; | ||
export let max = 10; | ||
export let step = 1; | ||
export let value = min; | ||
export let hideTooltip = false; | ||
export let element = undefined; | ||
export let inputElement = undefined; | ||
$:_id = id || name || guid(); | ||
$:progress = (value - min) / (max - min) * 100; | ||
const errorMessageId = guid(); | ||
</script> |
This file contains 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 @@ | ||
export { default as Range } from './Range.svelte'; |
This file contains 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
Oops, something went wrong.