mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 03:26:36 +00:00
feat(progress-bar): add ProgressBar
This commit is contained in:
parent
76b1d9ea17
commit
5fcecda4b4
11 changed files with 280 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
|||
# Component Index
|
||||
|
||||
> 167 components exported from carbon-components-svelte@0.36.0.
|
||||
> 168 components exported from carbon-components-svelte@0.36.0.
|
||||
|
||||
## Components
|
||||
|
||||
|
@ -99,6 +99,7 @@
|
|||
- [`PaginationSkeleton`](#paginationskeleton)
|
||||
- [`PasswordInput`](#passwordinput)
|
||||
- [`Popover`](#popover)
|
||||
- [`ProgressBar`](#progressbar)
|
||||
- [`ProgressIndicator`](#progressindicator)
|
||||
- [`ProgressIndicatorSkeleton`](#progressindicatorskeleton)
|
||||
- [`ProgressStep`](#progressstep)
|
||||
|
@ -2816,6 +2817,28 @@ None.
|
|||
| :------------ | :--------- | :----- |
|
||||
| click:outside | dispatched | -- |
|
||||
|
||||
## `ProgressBar`
|
||||
|
||||
### Props
|
||||
|
||||
| Prop name | Kind | Reactive | Type | Default value | Description |
|
||||
| :--------- | :--------------- | :------- | :------------------- | ------------------ | --------------------------------------------- |
|
||||
| value | <code>let</code> | No | <code>number</code> | -- | Specify the current value |
|
||||
| max | <code>let</code> | No | <code>number</code> | <code>100</code> | Specify the maximum value |
|
||||
| labelText | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the label text |
|
||||
| hideLabel | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to visually hide the label text |
|
||||
| helperText | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the helper text |
|
||||
|
||||
### Slots
|
||||
|
||||
| Slot name | Default | Props | Fallback |
|
||||
| :-------- | :------ | :---- | :----------------------- |
|
||||
| labelText | No | -- | <code>{labelText}</code> |
|
||||
|
||||
### Events
|
||||
|
||||
None.
|
||||
|
||||
## `ProgressIndicator`
|
||||
|
||||
### Props
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"total": 167,
|
||||
"total": 168,
|
||||
"components": [
|
||||
{
|
||||
"moduleName": "Accordion",
|
||||
|
@ -7302,6 +7302,72 @@
|
|||
"typedefs": [],
|
||||
"rest_props": { "type": "Element", "name": "div" }
|
||||
},
|
||||
{
|
||||
"moduleName": "ProgressBar",
|
||||
"filePath": "src/ProgressBar/ProgressBar.svelte",
|
||||
"props": [
|
||||
{
|
||||
"name": "value",
|
||||
"kind": "let",
|
||||
"description": "Specify the current value",
|
||||
"type": "number",
|
||||
"isFunction": false,
|
||||
"constant": false,
|
||||
"reactive": false
|
||||
},
|
||||
{
|
||||
"name": "max",
|
||||
"kind": "let",
|
||||
"description": "Specify the maximum value",
|
||||
"type": "number",
|
||||
"value": "100",
|
||||
"isFunction": false,
|
||||
"constant": false,
|
||||
"reactive": false
|
||||
},
|
||||
{
|
||||
"name": "labelText",
|
||||
"kind": "let",
|
||||
"description": "Specify the label text",
|
||||
"type": "string",
|
||||
"value": "\"\"",
|
||||
"isFunction": false,
|
||||
"constant": false,
|
||||
"reactive": false
|
||||
},
|
||||
{
|
||||
"name": "hideLabel",
|
||||
"kind": "let",
|
||||
"description": "Set to `true` to visually hide the label text",
|
||||
"type": "boolean",
|
||||
"value": "false",
|
||||
"isFunction": false,
|
||||
"constant": false,
|
||||
"reactive": false
|
||||
},
|
||||
{
|
||||
"name": "helperText",
|
||||
"kind": "let",
|
||||
"description": "Specify the helper text",
|
||||
"type": "string",
|
||||
"value": "\"\"",
|
||||
"isFunction": false,
|
||||
"constant": false,
|
||||
"reactive": false
|
||||
}
|
||||
],
|
||||
"slots": [
|
||||
{
|
||||
"name": "labelText",
|
||||
"default": false,
|
||||
"fallback": "{labelText}",
|
||||
"slot_props": "{}"
|
||||
}
|
||||
],
|
||||
"events": [],
|
||||
"typedefs": [],
|
||||
"rest_props": { "type": "Element", "name": "div" }
|
||||
},
|
||||
{
|
||||
"moduleName": "ProgressIndicator",
|
||||
"filePath": "src/ProgressIndicator/ProgressIndicator.svelte",
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
import Footer from "../components/Footer.svelte";
|
||||
|
||||
const deprecated = ["ToggleSmall", "Icon"];
|
||||
const new_components = ["Popover", "ContextMenu"];
|
||||
const new_components = ["ProgressBar"];
|
||||
|
||||
let isOpen = false;
|
||||
let isSideNavOpen = true;
|
||||
|
|
24
docs/src/pages/components/ProgressBar.svx
Normal file
24
docs/src/pages/components/ProgressBar.svx
Normal file
|
@ -0,0 +1,24 @@
|
|||
<script>
|
||||
import { ProgressBar } from "carbon-components-svelte";
|
||||
import Preview from "../../components/Preview.svelte";
|
||||
</script>
|
||||
|
||||
### Default
|
||||
|
||||
Without a specified `value` prop, the progress bar is indeterminate.
|
||||
|
||||
<ProgressBar helperText="Loading..." />
|
||||
|
||||
### Percentage
|
||||
|
||||
<ProgressBar value={40} labelText="Upload status" helperText="40 MB of 100 MB" />
|
||||
|
||||
### Custom max value
|
||||
|
||||
The default `max` value is `100`.
|
||||
|
||||
<ProgressBar value={40} max={200} labelText="Upload status" helperText="40 MB of 200 MB" />
|
||||
|
||||
### Hidden label
|
||||
|
||||
<ProgressBar hideLabel value={40} labelText="Upload status" helperText="40 MB of 100 MB" />
|
36
docs/src/pages/framed/ProgressBar/ProgressBarUx.svelte
Normal file
36
docs/src/pages/framed/ProgressBar/ProgressBarUx.svelte
Normal file
|
@ -0,0 +1,36 @@
|
|||
<script>
|
||||
import { onMount } from "svelte";
|
||||
import { ProgressBar } from "carbon-components-svelte";
|
||||
|
||||
let max = 328;
|
||||
let value = 0;
|
||||
let timer = undefined;
|
||||
|
||||
onMount(() => {
|
||||
timer = setTimeout(() => {
|
||||
const interval = setInterval(() => {
|
||||
const delta = Math.random() * 10;
|
||||
|
||||
if (value + delta < max) {
|
||||
value += delta;
|
||||
} else {
|
||||
value = max;
|
||||
clearInterval(interval);
|
||||
}
|
||||
}, 20);
|
||||
}, 2000);
|
||||
|
||||
return () => clearTimeout(timer);
|
||||
});
|
||||
|
||||
$: helperText =
|
||||
value > 0 ? `${value.toFixed(0)}MB of ${max}MB` : "Preparing upload...";
|
||||
$: if (value === max) helperText = "Done";
|
||||
</script>
|
||||
|
||||
<ProgressBar
|
||||
labelText="Upload status"
|
||||
value="{value}"
|
||||
max="{max}"
|
||||
helperText="{helperText}"
|
||||
/>
|
60
src/ProgressBar/ProgressBar.svelte
Normal file
60
src/ProgressBar/ProgressBar.svelte
Normal file
|
@ -0,0 +1,60 @@
|
|||
<script>
|
||||
/**
|
||||
* Specify the current value
|
||||
* @type {number}
|
||||
*/
|
||||
export let value = undefined;
|
||||
|
||||
/** Specify the maximum value */
|
||||
export let max = 100;
|
||||
|
||||
/** Specify the label text */
|
||||
export let labelText = "";
|
||||
|
||||
/** Set to `true` to visually hide the label text */
|
||||
export let hideLabel = false;
|
||||
|
||||
/** Specify the helper text */
|
||||
export let helperText = "";
|
||||
|
||||
let id = "ccs-" + Math.random().toString(36);
|
||||
let helperId = "ccs-" + Math.random().toString(36);
|
||||
|
||||
$: indeterminate = value === undefined;
|
||||
$: capped = value > max ? max : value < 0 ? 0 : value;
|
||||
</script>
|
||||
|
||||
<div
|
||||
class:bx--progress-bar="{true}"
|
||||
class:bx--progress-bar--indeterminate="{indeterminate}"
|
||||
{...$$restProps}
|
||||
>
|
||||
<label
|
||||
for="{id}"
|
||||
class:bx--progress-bar__label="{true}"
|
||||
class:bx--visually-hidden="{hideLabel}"
|
||||
>
|
||||
<slot name="labelText">
|
||||
{labelText}
|
||||
</slot>
|
||||
</label>
|
||||
<div
|
||||
role="progressbar"
|
||||
id="{id}"
|
||||
class:bx--progress-bar__track="{true}"
|
||||
aria-valuemin="{indeterminate ? undefined : 0}"
|
||||
aria-valuemax="{indeterminate ? undefined : max}"
|
||||
aria-valuenow="{indeterminate ? undefined : capped}"
|
||||
aria-describedby="{helperText ? helperId : null}"
|
||||
>
|
||||
<div
|
||||
class:bx--progress-bar__bar="{true}"
|
||||
style="transform: scaleX({capped / max})"
|
||||
></div>
|
||||
</div>
|
||||
{#if helperText}
|
||||
<div id="{helperId}" class:bx--progress-bar__helper-text="{true}">
|
||||
{helperText}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
1
src/ProgressBar/index.js
Normal file
1
src/ProgressBar/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
export { default as ProgressBar } from "./ProgressBar.svelte";
|
|
@ -85,6 +85,7 @@ export { OverflowMenu, OverflowMenuItem } from "./OverflowMenu";
|
|||
export { Pagination, PaginationSkeleton } from "./Pagination";
|
||||
export { PaginationNav } from "./PaginationNav";
|
||||
export { Popover } from "./Popover";
|
||||
export { ProgressBar } from "./ProgressBar";
|
||||
export {
|
||||
ProgressIndicator,
|
||||
ProgressIndicatorSkeleton,
|
||||
|
|
25
tests/ProgressBar.test.svelte
Normal file
25
tests/ProgressBar.test.svelte
Normal file
|
@ -0,0 +1,25 @@
|
|||
<script>
|
||||
import { ProgressBar } from "../types";
|
||||
</script>
|
||||
|
||||
<ProgressBar helperText="Loading..." />
|
||||
|
||||
<ProgressBar
|
||||
value="{40}"
|
||||
labelText="Upload status"
|
||||
helperText="40 MB of 100 MB"
|
||||
/>
|
||||
|
||||
<ProgressBar
|
||||
value="{40}"
|
||||
max="{200}"
|
||||
labelText="Upload status"
|
||||
helperText="40 MB of 100 MB"
|
||||
/>
|
||||
|
||||
<ProgressBar
|
||||
hideLabel
|
||||
value="{40}"
|
||||
labelText="Upload status"
|
||||
helperText="40 MB of 100 MB"
|
||||
/>
|
40
types/ProgressBar/ProgressBar.d.ts
vendored
Normal file
40
types/ProgressBar/ProgressBar.d.ts
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
/// <reference types="svelte" />
|
||||
import { SvelteComponentTyped } from "svelte";
|
||||
|
||||
export interface ProgressBarProps
|
||||
extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["div"]> {
|
||||
/**
|
||||
* Specify the current value
|
||||
*/
|
||||
value?: number;
|
||||
|
||||
/**
|
||||
* Specify the maximum value
|
||||
* @default 100
|
||||
*/
|
||||
max?: number;
|
||||
|
||||
/**
|
||||
* Specify the label text
|
||||
* @default ""
|
||||
*/
|
||||
labelText?: string;
|
||||
|
||||
/**
|
||||
* Set to `true` to visually hide the label text
|
||||
* @default false
|
||||
*/
|
||||
hideLabel?: boolean;
|
||||
|
||||
/**
|
||||
* Specify the helper text
|
||||
* @default ""
|
||||
*/
|
||||
helperText?: string;
|
||||
}
|
||||
|
||||
export default class ProgressBar extends SvelteComponentTyped<
|
||||
ProgressBarProps,
|
||||
{},
|
||||
{ labelText: {} }
|
||||
> {}
|
1
types/index.d.ts
vendored
1
types/index.d.ts
vendored
|
@ -92,6 +92,7 @@ export { default as Pagination } from "./Pagination/Pagination";
|
|||
export { default as PaginationSkeleton } from "./Pagination/PaginationSkeleton";
|
||||
export { default as PaginationNav } from "./PaginationNav/PaginationNav";
|
||||
export { default as Popover } from "./Popover/Popover";
|
||||
export { default as ProgressBar } from "./ProgressBar/ProgressBar";
|
||||
export { default as ProgressIndicator } from "./ProgressIndicator/ProgressIndicator";
|
||||
export { default as ProgressIndicatorSkeleton } from "./ProgressIndicator/ProgressIndicatorSkeleton";
|
||||
export { default as ProgressStep } from "./ProgressIndicator/ProgressStep";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue