-
Notifications
You must be signed in to change notification settings - Fork 38
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
3f65eee
commit e1a85df
Showing
4 changed files
with
64 additions
and
11 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
45 changes: 45 additions & 0 deletions
45
aksel.nav.no/website/pages/eksempler/progress-bar/loading.tsx
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,45 @@ | ||
import React from "react"; | ||
import { ProgressBar } from "@navikt/ds-react"; | ||
import { withDsExample } from "@/web/examples/withDsExample"; | ||
|
||
const Example = () => { | ||
const [value, setValue] = React.useState(3); | ||
|
||
// This useEffect is used to simulate loading | ||
React.useEffect(() => { | ||
const setRandomInterval = (callback: () => void) => { | ||
const interval = Math.random() * 4000 + 500; | ||
return setTimeout(() => { | ||
callback(); | ||
setRandomInterval(callback); | ||
}, interval); | ||
}; | ||
const intervalId = setRandomInterval(() => { | ||
setValue((oldValue) => { | ||
if (oldValue === 100) return 3; | ||
const increment = Math.random() * 25 + 5; | ||
return oldValue + increment > 100 ? 100 : oldValue + increment; | ||
}); | ||
}); | ||
return () => clearInterval(intervalId); | ||
}, []); | ||
|
||
return ( | ||
<div style={{ width: "300px" }}> | ||
<div id="loading">Laster innhold</div> | ||
<ProgressBar value={value} aria-labelledby="loading" /> | ||
</div> | ||
); | ||
}; | ||
|
||
// EXAMPLES DO NOT INCLUDE CONTENT BELOW THIS LINE | ||
export default withDsExample(Example); | ||
|
||
/* Storybook story */ | ||
export const Demo = { | ||
render: Example, | ||
}; | ||
|
||
export const args = { | ||
index: 1, | ||
}; |
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 |
---|---|---|
|
@@ -42,5 +42,5 @@ export const Demo = { | |
}; | ||
|
||
export const args = { | ||
index: 2, | ||
index: 0, | ||
}; |