Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progressbar tweaks (etter docs-møtet) #2892

Merged
merged 34 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6efe481
made demos
larseirikhansen Apr 29, 2024
1d64853
Merge remote-tracking branch 'origin/main' into progressbar-demos
larseirikhansen Apr 29, 2024
36992ad
ammend demo order
larseirikhansen Apr 29, 2024
0cdb64c
name change :usedInForm to interactive
larseirikhansen Apr 29, 2024
11cc9e9
move setRandomInterval into useEffect bc of sandbox
larseirikhansen Apr 29, 2024
44bf235
spacing in jsx for visibility
larseirikhansen Apr 29, 2024
83426d2
change div style to vstack
larseirikhansen Apr 29, 2024
bc764ff
gac remove static variant
larseirikhansen Apr 29, 2024
9251503
change demo index
larseirikhansen Apr 29, 2024
3f0c720
change name from loading bar to loading
larseirikhansen Apr 29, 2024
87b661a
button gap and progress carousel
larseirikhansen Apr 29, 2024
8a2e023
change demo labels to norwegian
larseirikhansen Apr 29, 2024
ed04a52
change demo labels and layout
larseirikhansen Apr 29, 2024
16e91e9
change aria-label interactive demo
larseirikhansen Apr 29, 2024
ec4ace1
Merge remote-tracking branch 'origin/main' into progressbar-demos
larseirikhansen Apr 29, 2024
5c3381b
remove references to forms
larseirikhansen Apr 29, 2024
295c877
add onIndeterminate to API, tweak demos, delete duplicate file
larseirikhansen Apr 29, 2024
1d754ec
Merge remote-tracking branch 'origin/main' into progressbar-tweaks
larseirikhansen Apr 29, 2024
3f5cb8a
comment out 'onIndeterminate' bc playwright didn't play right with @t…
larseirikhansen Apr 29, 2024
7a61a6a
Merge branch 'main' into progressbar-tweaks
larseirikhansen Apr 29, 2024
28e9a60
changeset
JulianNymark Apr 30, 2024
3fa0527
Revert "changeset"
JulianNymark Apr 30, 2024
0489be7
merge and change duration api to simulated api
larseirikhansen May 3, 2024
1373f39
yarn lock
larseirikhansen May 3, 2024
4c4e5b8
new animation without animation-delay
larseirikhansen May 3, 2024
5f71173
Update aksel.nav.no/website/pages/eksempler/progress-bar/interactive.tsx
larseirikhansen May 3, 2024
d7f3323
Update @navikt/core/react/src/progress-bar/ProgressBar.tsx
larseirikhansen May 3, 2024
38f0c5d
Update @navikt/core/react/src/progress-bar/ProgressBar.tsx
larseirikhansen May 7, 2024
b518a63
forgot to remove delay :brainfart:
larseirikhansen May 7, 2024
bf04bb0
onTimeout function outside render cycle
larseirikhansen May 7, 2024
c438523
Merge remote-tracking branch 'origin/main' into progressbar-tweaks
larseirikhansen May 7, 2024
d0b8b8d
uncomment indeterminate example
larseirikhansen May 7, 2024
0ab3bcd
changeset
larseirikhansen May 7, 2024
af2f0d4
aria-hidden must be true if used
larseirikhansen May 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions @navikt/core/css/progress-bar.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@
}

.navds-progress-bar__foreground--indeterminate {
--__ac-progress-bar-duration: initial;
--__ac-progress-bar-delay: initial;
--__ac-progress-bar-simulated: initial;

animation-name: navds-progress-bar-indeterminate-grow, navds-progress-bar-indeterminate;
animation-timing-function: ease-in-out, ease-in-out;
animation-duration: var(--__ac-progress-bar-duration), 2500ms;
animation-duration: var(--__ac-progress-bar-simulated), 2500ms;
animation-fill-mode: forwards, none;
animation-iteration-count: 1, infinite;
animation-delay: 0s, calc((var(--__ac-progress-bar-duration) + var(--__ac-progress-bar-delay)));
animation-delay: 0s, var(--__ac-progress-bar-simulated);
}

/* navds-progress-bar-indeterminate wave animation */
Expand Down Expand Up @@ -85,11 +84,14 @@
transform: translateX(-40%);
}

40%,
50% {
transform: translateX(-20%);
}

75% {
transform: translateX(-10%);
}

100% {
transform: translateX(-10%);
}
Expand Down
31 changes: 10 additions & 21 deletions @navikt/core/react/src/progress-bar/ProgressBar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export const Default: StoryFn = (args) => {
size={args.size}
value={value}
aria-labelledby="progress-bar-label"
/* duration={args.indeterminate ? 0 : undefined} */
/>
</>
) : (
Expand All @@ -58,16 +57,12 @@ export const Default: StoryFn = (args) => {
};
Default.args = {
size: "medium",
indeterminate: false,
};
Default.argTypes = {
size: {
options: ["large", "medium", "small"],
control: { type: "radio" },
},
indeterminate: {
control: { type: "boolean" },
},
};

export const Sizes: StoryFn = (args) => {
Expand Down Expand Up @@ -103,35 +98,29 @@ Sizes.args = {
valueMax: 12,
};

/**
* Duration is temp disabled due to potential API-updates
*/
export const IndeterminateState: Story = {
render: () => {
const values = [2, 5, 10, 20];
const values = [0, 5, 10, 20];
return (
<>
<p id="progress-bar-label-immediate-indeterminate">
Duration prop satt til 0 sek
</p>
<ProgressBar
valueMax={100}
/* duration={0} */
size="medium"
value={50}
aria-labelledby="progress-bar-label-immediate-indeterminate"
/>
{values.map((value) => (
<div key={value}>
<p id={`progress-bar-label-${value}`}>
duration-prop satt til {value} sek
Simulert til å laste i opptil {value} sek.
{value === 0 &&
" Ved 0 sek vises indeterminate state umiddelbart."}
</p>
<ProgressBar
valueMax={100}
/* duration={value} */
size="medium"
value={value}
aria-labelledby={`progress-bar-label-${value}`}
simulated={{
seconds: value,
onTimeout: () => {
console.log("Ferdig!");
},
}}
/>
</div>
))}
Expand Down
59 changes: 41 additions & 18 deletions @navikt/core/react/src/progress-bar/ProgressBar.tsx
larseirikhansen marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface ProgressBarPropsBase
*/
size?: "large" | "medium" | "small";
/**
* Current progress. When duration is set, value is ignored.
* Current progress. If set, the `simulated` prop overrides `value`.
*/
value?: number;
/**
Expand All @@ -18,13 +18,20 @@ interface ProgressBarPropsBase
*/
valueMax?: number;
/**
* Expected task duration in seconds.
* ProgressBar grows with a preset animation for {duration} seconds.
* After a 4 sec delay, it then shows an indeterminate animation.
* A duration of 0 will show an indeterminate animation immediately.
* Temporary removed to avoid conflicts when updating API
* Visually simulates loading.
* ProgressBar grows with a preset animation for set number of seconds,
* then shows an indeterminate animation on timeout.
*/
//duration?: number;
simulated?: {
/**
* Duration in seconds.
*/
seconds: number;
/**
* Callback function when progress is indeterminate.
*/
onTimeout: () => void;
};
/**
* String ID of the element that labels the progress bar.
* Not needed if `aria-label` is used.
Expand Down Expand Up @@ -61,7 +68,11 @@ export type ProgressBarProps = ProgressBarPropsBase &
*
* @example
* // For loading content with an approximate duration in sec.
* <ProgressBar duration={30} />
* <ProgressBar simulated={
* seconds:30,
* onTimeout:() => { console.log("Oops, this is taking more time than expected!")
* }
* />
larseirikhansen marked this conversation as resolved.
Show resolved Hide resolved
*
* @example
* // As a step indicator for forms, questionnaires, etc.
Expand All @@ -76,12 +87,22 @@ export const ProgressBar = forwardRef<HTMLDivElement, ProgressBarProps>(
"aria-labelledby": ariaLabelledBy,
"aria-label": ariaLabel,
className,
simulated,
...rest
},
ref,
) => {
const translate = 100 - (Math.round(value) / valueMax) * 100;
const duration = undefined;

React.useEffect(() => {
if (simulated?.seconds && simulated?.onTimeout) {
const timeout = setTimeout(
() => simulated.onTimeout(),
larseirikhansen marked this conversation as resolved.
Show resolved Hide resolved
simulated.seconds * 1000 + 4000,
HalvorHaugan marked this conversation as resolved.
Show resolved Hide resolved
);
return () => clearTimeout(timeout);
}
}, [simulated, simulated?.seconds, simulated?.onTimeout]);
larseirikhansen marked this conversation as resolved.
Show resolved Hide resolved

return (
<div
Expand All @@ -91,11 +112,11 @@ export const ProgressBar = forwardRef<HTMLDivElement, ProgressBarProps>(
`navds-progress-bar--${size}`,
className,
)}
aria-valuemax={duration ? 0 : Math.round(valueMax)}
aria-valuenow={duration ? 0 : Math.round(value)}
aria-valuemax={simulated?.seconds ? 0 : Math.round(valueMax)}
aria-valuenow={simulated?.seconds ? 0 : Math.round(value)}
aria-valuetext={
duration
? "Fremdrift kan ikke beregnes"
simulated?.seconds
? `Fremdrift kan ikke beregnes, antatt tid er: ${simulated?.seconds} sekunder`
: `${Math.round(value)} av ${Math.round(valueMax)}`
}
role="progressbar"
Expand All @@ -105,14 +126,16 @@ export const ProgressBar = forwardRef<HTMLDivElement, ProgressBarProps>(
>
<div
className={cl("navds-progress-bar__foreground", {
"navds-progress-bar__foreground--indeterminate":
Number.isInteger(duration),
"navds-progress-bar__foreground--indeterminate": Number.isInteger(
simulated?.seconds,
),
})}
style={{
"--__ac-progress-bar-duration": Number.isInteger(duration)
? `${duration}s`
"--__ac-progress-bar-simulated": Number.isInteger(
simulated?.seconds,
)
? `${simulated?.seconds}s`
: undefined,
"--__ac-progress-bar-delay": `${duration === 0 ? 0 : 4}s`,
"--__ac-progress-bar-translate": `-${translate}%`,
}}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import React from "react";
import { ProgressBar } from "@navikt/ds-react";
import { withDsExample } from "@/web/examples/withDsExample";

const Example = () => {
// const [isIndeterminate, setIsIndeterminate] = React.useState(false);
return (
<div>
<p id="indeterminate">Laster opp fil</p>
{/* TODO: Remove outcommented duration prop */}
<ProgressBar /* duration={6} */ aria-labelledby="indeterminate" />
<div style={{ width: "300px" }}>
<p id="indeterminate-working">Jobber med saken</p>
<ProgressBar
// simulated={{
// seconds: 6,
// onTimeout: () => {
// console.log("Ferdig!");
// setIsIndeterminate(true);
// },
// }}
aria-labelledby="indeterminate-working"
/>
{/* {isIndeterminate && <p>Oi, dette tok lenger tid en forventet!</p>} */}
larseirikhansen marked this conversation as resolved.
Show resolved Hide resolved
</div>
);
};
Expand All @@ -21,5 +32,5 @@ export const Demo = {

export const args = {
index: 3,
desc: "Med duration-propen kan man legge inn et anslag i sekunder, så simulerer komponenten progresjon.",
desc: "Med simulated-propen kan man legge inn et anslag i sekunder, så simulerer komponenten progresjon.",
};
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ export const Demo = {

export const args = {
index: 2,
desc: "Progress bar kan brukes til å vise hvor i en flyt brukeren er",
larseirikhansen marked this conversation as resolved.
Show resolved Hide resolved
};
45 changes: 0 additions & 45 deletions aksel.nav.no/website/pages/eksempler/progress-bar/loadingBar.tsx

This file was deleted.

8 changes: 3 additions & 5 deletions aksel.nav.no/website/pages/eksempler/progress-bar/sizes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@ import { withDsExample } from "@/web/examples/withDsExample";
const Example = () => {
return (
<VStack gap="4">
<p id="progress-bar-label-small">Fremdrift i søknaden (liten versjon)</p>
<p id="progress-bar-label-small">Fremdrift (liten versjon)</p>
<ProgressBar
value={1}
valueMax={12}
size="small"
aria-labelledby="progress-bar-label-small"
/>

<p id="progress-bar-label-medium">
Fremdrift i søknaden (medium versjon)
</p>
<p id="progress-bar-label-medium">Fremdrift (medium versjon)</p>
<ProgressBar
value={6}
valueMax={12}
size="medium"
aria-labelledby="progress-bar-label-medium"
/>

<p id="progress-bar-label-large">Fremdrift i søknaden (stor versjon)</p>
<p id="progress-bar-label-large">Fremdrift (stor versjon)</p>
<ProgressBar
value={11}
valueMax={12}
Expand Down
Loading
Loading