-
Notifications
You must be signed in to change notification settings - Fork 90
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
Showing
9 changed files
with
214 additions
and
31 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 |
---|---|---|
@@ -1,23 +1,21 @@ | ||
--- | ||
title: Progress | ||
sidebar: | ||
label: Progress 🚧 | ||
data: | ||
description: "A progress indicator gives the user an understanding of how long a system operation will take. It should be used when the operation will take more than a second to complete. Two variants are available to accommodate different layout constraints: linear and circular." | ||
description: "Circular Progress and Linear Progress communicate the status of an ongoing operation, such as file downloads or data uploads. The two components accommodate different layout constraints." | ||
|
||
# Fill in the info from the content template's "Metadata" table below. | ||
# To omit optional items, comment them out with # | ||
sourceCodeUrl: "https://github.com/jpmorganchase/salt-ds/tree/main/packages/core/src/progress" | ||
sourceCodeUrl: "https://github.com/jpmorganchase/salt-ds/tree/main/packages/lab/src/progress" | ||
package: | ||
name: "@salt-ds/core" | ||
alsoKnownAs: [] | ||
name: "@salt-ds/lab" | ||
alsoKnownAs: [Progress Bar, Progress Indicator] | ||
relatedComponents: [] | ||
# stickerSheet: "https://figma.com/..." | ||
|
||
status: Lab component | ||
# Leave this as is | ||
layout: DetailComponent | ||
|
||
# TODO: Remove this once the docs are ready | ||
sidebar: | ||
exclude: true | ||
--- | ||
|
||
{/* This area stays blank */} |
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,6 @@ | ||
import { ReactElement } from "react"; | ||
import { CircularProgress } from "@salt-ds/lab"; | ||
|
||
export const Circular = (): ReactElement => ( | ||
<CircularProgress aria-label="Download" value={38} /> | ||
); |
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,6 @@ | ||
import { ReactElement } from "react"; | ||
import { LinearProgress } from "@salt-ds/lab"; | ||
|
||
export const Linear = (): ReactElement => ( | ||
<LinearProgress aria-label="Download" value={38} /> | ||
); |
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,52 @@ | ||
import { ReactElement, useState } from "react"; | ||
import { CircularProgress, LinearProgress } from "@salt-ds/lab"; | ||
import { | ||
FlexItem, | ||
FlexLayout, | ||
FlowLayout, | ||
RadioButton, | ||
RadioButtonGroup, | ||
} from "@salt-ds/core"; | ||
|
||
export const WithMaxVal = (): ReactElement => { | ||
const [selectedType, setSelectedType] = useState("circular"); | ||
|
||
return ( | ||
<FlexLayout direction="column" style={{ height: "100%" }}> | ||
<h3 style={{ textAlign: "center" }}> max = 500, value = 250</h3> | ||
<FlexItem> | ||
<FlowLayout justify="center" className="controls" gap={1}> | ||
<RadioButtonGroup direction="horizontal" defaultChecked> | ||
<RadioButton | ||
key="circular" | ||
label="Circular" | ||
value="circular" | ||
checked | ||
onChange={() => setSelectedType("circular")} | ||
/> | ||
<RadioButton | ||
key="linear" | ||
label="Linear" | ||
value="linear" | ||
onChange={() => setSelectedType("linear")} | ||
/> | ||
</RadioButtonGroup> | ||
</FlowLayout> | ||
</FlexItem> | ||
|
||
<FlexItem align="center" grow={1}> | ||
{selectedType === "circular" && ( | ||
<CircularProgress aria-label="Download" value={250} max={500} /> | ||
)} | ||
{selectedType === "linear" && ( | ||
<LinearProgress | ||
aria-label="Download" | ||
value={250} | ||
max={500} | ||
style={{ height: "100%" }} | ||
/> | ||
)} | ||
</FlexItem> | ||
</FlexLayout> | ||
); | ||
}; |
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,117 @@ | ||
import { ReactElement, useState, useEffect, useCallback } from "react"; | ||
import { CircularProgress, LinearProgress } from "@salt-ds/lab"; | ||
import { | ||
Button, | ||
FlexItem, | ||
FlexLayout, | ||
FlowLayout, | ||
RadioButton, | ||
RadioButtonGroup, | ||
} from "@salt-ds/core"; | ||
|
||
function useProgressingValue(updateInterval = 100) { | ||
const [value, setValue] = useState(0); | ||
const [isProgressing, setIsProgressing] = useState(false); | ||
|
||
const handleStop = useCallback(() => { | ||
if (isProgressing) { | ||
setIsProgressing(false); | ||
} | ||
}, [isProgressing]); | ||
|
||
const handleStart = () => { | ||
if (!isProgressing) { | ||
setIsProgressing(true); | ||
} | ||
}; | ||
|
||
const handleReset = () => { | ||
setValue(0); | ||
handleStop(); | ||
}; | ||
|
||
useEffect(() => { | ||
if (isProgressing) { | ||
const id = setInterval(() => { | ||
setValue((preValue) => preValue + 1); | ||
}, updateInterval); | ||
|
||
return () => { | ||
clearInterval(id); | ||
}; | ||
} | ||
return; | ||
}, [isProgressing, updateInterval]); | ||
|
||
useEffect( | ||
function stopWhenComplete() { | ||
if (value === 100) { | ||
handleStop(); | ||
} | ||
}, | ||
[handleStop, value] | ||
); | ||
|
||
return { | ||
handleReset, | ||
handleStart, | ||
handleStop, | ||
isProgressing, | ||
value, | ||
}; | ||
} | ||
|
||
export const WithProgVal = (): ReactElement => { | ||
const { handleReset, handleStart, handleStop, isProgressing, value } = | ||
useProgressingValue(); | ||
const [selectedType, setSelectedType] = useState("circular"); | ||
|
||
return ( | ||
<FlexLayout direction="column" style={{ height: "100%" }}> | ||
<FlexItem> | ||
<FlowLayout justify="center" className="controls" gap={1}> | ||
<Button disabled={isProgressing} onClick={handleStart}> | ||
Start | ||
</Button> | ||
<Button disabled={!isProgressing} onClick={handleStop}> | ||
Stop | ||
</Button> | ||
<Button onClick={handleReset}>Reset</Button> | ||
</FlowLayout> | ||
</FlexItem> | ||
|
||
<FlexItem> | ||
<FlowLayout justify="center" className="controls" gap={1}> | ||
<RadioButtonGroup direction="horizontal" defaultChecked> | ||
<RadioButton | ||
key="circular" | ||
label="Circular" | ||
value="circular" | ||
checked | ||
onChange={() => setSelectedType("circular")} | ||
/> | ||
<RadioButton | ||
key="linear" | ||
label="Linear" | ||
value="linear" | ||
onChange={() => setSelectedType("linear")} | ||
/> | ||
</RadioButtonGroup> | ||
</FlowLayout> | ||
</FlexItem> | ||
|
||
<FlexItem align="center" grow={1}> | ||
{selectedType === "circular" && ( | ||
<CircularProgress aria-label="Download" value={value} /> | ||
)} | ||
{selectedType === "linear" && ( | ||
<LinearProgress | ||
aria-label="Download" | ||
value={value} | ||
style={{ height: "100%" }} | ||
/> | ||
)} | ||
</FlexItem> | ||
</FlexLayout> | ||
); | ||
}; |
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,4 @@ | ||
export * from "./Circular"; | ||
export * from "./Linear"; | ||
export * from "./WithMaxVal"; | ||
export * from "./WithProgVal"; |
85c9f25
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
saltdesignsystem – ./
saltdesignsystem.vercel.app
saltdesignsystem-git-main-fed-team.vercel.app
saltdesignsystem-fed-team.vercel.app
www.saltdesignsystem.com
next.saltdesignsystem.com