mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 18:31:06 +00:00
Merge branch 'master' into 285-textinput-add-fluid
This commit is contained in:
commit
dae3cf6dd0
12 changed files with 64 additions and 2408 deletions
|
@ -4,7 +4,7 @@
|
|||
import Slider from "./Slider.svelte";
|
||||
import SliderSkeleton from "./Slider.Skeleton.svelte";
|
||||
|
||||
$: value = 50;
|
||||
let value = 50;
|
||||
</script>
|
||||
|
||||
{#if story === 'skeleton'}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<script>
|
||||
/**
|
||||
* Specify the value of the slider
|
||||
* @type {string} [value=""]
|
||||
* @type {number} [value=0]
|
||||
*/
|
||||
export let value = "";
|
||||
export let value = 0;
|
||||
|
||||
/**
|
||||
* Set the maximum slider value
|
||||
|
@ -101,7 +101,7 @@
|
|||
*/
|
||||
export let ref = null;
|
||||
|
||||
import { createEventDispatcher, afterUpdate } from "svelte";
|
||||
import { createEventDispatcher } from "svelte";
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
|
@ -119,9 +119,18 @@
|
|||
|
||||
function stopHolding() {
|
||||
holding = false;
|
||||
dragging = false;
|
||||
}
|
||||
|
||||
function move() {
|
||||
if (holding) {
|
||||
startDragging();
|
||||
}
|
||||
}
|
||||
|
||||
function calcValue(e) {
|
||||
if (disabled) return;
|
||||
|
||||
const offsetX = e.touches ? e.touches[0].clientX : e.clientX;
|
||||
const { left, width } = trackRef.getBoundingClientRect();
|
||||
let nextValue =
|
||||
|
@ -137,12 +146,6 @@
|
|||
value = nextValue;
|
||||
}
|
||||
|
||||
afterUpdate(() => {
|
||||
if (!holding) {
|
||||
dispatch("change", value);
|
||||
}
|
||||
});
|
||||
|
||||
$: range = max - min;
|
||||
$: left = ((value - min) / range) * 100;
|
||||
$: {
|
||||
|
@ -156,9 +159,20 @@
|
|||
calcValue(event);
|
||||
dragging = false;
|
||||
}
|
||||
|
||||
if (!holding && !disabled) {
|
||||
dispatch("change", value);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:body
|
||||
on:mousemove="{move}"
|
||||
on:touchmove="{move}"
|
||||
on:mouseup="{stopHolding}"
|
||||
on:touchend="{stopHolding}"
|
||||
on:touchcancel="{stopHolding}" />
|
||||
|
||||
<div
|
||||
class:bx--form-item="{true}"
|
||||
{...$$restProps}
|
||||
|
@ -182,21 +196,15 @@
|
|||
tabindex="-1"
|
||||
class:bx--slider="{true}"
|
||||
class:bx--slider--disabled="{disabled}"
|
||||
on:click="{startDragging}"
|
||||
on:mousemove="{() => {
|
||||
if (holding) {
|
||||
startDragging();
|
||||
on:mousedown="{startDragging}"
|
||||
on:mousedown="{startHolding}"
|
||||
on:touchstart="{startHolding}"
|
||||
on:keydown="{({ shiftKey, key }) => {
|
||||
const keys = { ArrowDown: -1, ArrowLeft: -1, ArrowRight: 1, ArrowUp: 1 };
|
||||
if (keys[key]) {
|
||||
value += step * (shiftKey ? range / step / stepMultiplier : 1) * keys[key];
|
||||
}
|
||||
}}"
|
||||
on:touchmove="{() => {
|
||||
if (holding) {
|
||||
startDragging();
|
||||
}
|
||||
}}"
|
||||
on:mouseup="{stopHolding}"
|
||||
on:touchup="{stopHolding}"
|
||||
on:touchend="{stopHolding}"
|
||||
on:touchcancel="{stopHolding}"
|
||||
>
|
||||
<div
|
||||
role="slider"
|
||||
|
@ -206,14 +214,6 @@
|
|||
aria-valuemax="{max}"
|
||||
aria-valuemin="{min}"
|
||||
aria-valuenow="{value}"
|
||||
on:mousedown="{startHolding}"
|
||||
on:touchstart="{startHolding}"
|
||||
on:keydown="{({ shiftKey, key }) => {
|
||||
const keys = { ArrowDown: -1, ArrowLeft: -1, ArrowRight: 1, ArrowUp: 1 };
|
||||
if (keys[key]) {
|
||||
value += step * (shiftKey ? range / step / stepMultiplier : 1) * keys[key];
|
||||
}
|
||||
}}"
|
||||
id="{id}"
|
||||
></div>
|
||||
<div bind:this="{trackRef}" class:bx--slider__track="{true}"></div>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
</script>
|
||||
|
||||
<li class:bx--switcher__item="{true}">
|
||||
<a href="{href}" class:bx--switcher__item-link="{true}" {...$$restProps}>
|
||||
<a href="{href}" class:bx--switcher__item-link="{true}" {...$$restProps} on:click>
|
||||
<slot />
|
||||
</a>
|
||||
</li>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue