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

✨ Ny komponent: ProgressBar #2845

Merged
merged 59 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
dd7cdcb
progress bar first commit
larseirikhansen Apr 10, 2024
6e8aaf5
add min-width to bar
larseirikhansen Apr 11, 2024
99f3133
add prelimenary - hopefully not permament, really basic - animation f…
larseirikhansen Apr 12, 2024
457d32b
Merge remote-tracking branch 'origin/main' into progressbar
larseirikhansen Apr 12, 2024
c1b35fb
yarn lock
larseirikhansen Apr 12, 2024
01b50bd
add progress transition for smoothness
larseirikhansen Apr 12, 2024
406977b
Add overcomplicated loading simulator
larseirikhansen Apr 12, 2024
4d240b8
remove demo
larseirikhansen Apr 12, 2024
abc66d5
Refactor ProgressBar component to support different sizes and aria-la…
larseirikhansen Apr 12, 2024
d081bac
Update @navikt/core/css/progress-bar.css
larseirikhansen Apr 12, 2024
0885033
Update @navikt/core/css/progress-bar.css
larseirikhansen Apr 12, 2024
37df3e1
Update @navikt/core/css/progress-bar.css
larseirikhansen Apr 12, 2024
904b906
Merge remote-tracking branch 'origin/progressbar' into progressbar
larseirikhansen Apr 12, 2024
0e7870e
Update @navikt/core/css/progress-bar.css
larseirikhansen Apr 12, 2024
2fec009
Merge remote-tracking branch 'origin/progressbar' into progressbar
larseirikhansen Apr 12, 2024
49a0415
gac "new animation indeterminate state"
larseirikhansen Apr 12, 2024
bc1983a
remove style when indeterminate
larseirikhansen Apr 12, 2024
506eabb
changed how animation works, can go back if it doesnt pan out
larseirikhansen Apr 12, 2024
2ff614c
Refactor progress bar animation and indeterminate state
larseirikhansen Apr 15, 2024
5fc44e7
Merge remote-tracking branch 'origin/main' into progressbar
larseirikhansen Apr 15, 2024
0c70072
added valueMin to stories
larseirikhansen Apr 17, 2024
34a65eb
make indeterminate state more accessible
larseirikhansen Apr 17, 2024
e5e44d3
made default example slower - easier for SR to follow
larseirikhansen Apr 17, 2024
ce647e2
made example easier to udnerstand
larseirikhansen Apr 17, 2024
e0e5762
new aria value text, remove aria busy
larseirikhansen Apr 17, 2024
3b67a4e
comment out example for playwright
larseirikhansen Apr 17, 2024
fb3e39f
remove examples for playwright
larseirikhansen Apr 17, 2024
0204aea
yarn changeset
larseirikhansen Apr 17, 2024
83a97a8
Change name of progress bar-bar to foreground & add tokens
larseirikhansen Apr 17, 2024
14c32d4
jsdoc from no to en
larseirikhansen Apr 17, 2024
4873fe6
round value to closes integer
larseirikhansen Apr 17, 2024
fece14b
clean up a little
larseirikhansen Apr 17, 2024
8bb70cf
change aria labels to work with most screen readers
larseirikhansen Apr 19, 2024
966c751
omit role-tag
larseirikhansen Apr 19, 2024
c353a52
remove width from progress-bar-class
larseirikhansen Apr 19, 2024
1a03d61
update storybook examples
larseirikhansen Apr 19, 2024
4246459
Fix progress bar indeterminate behavior and duration handling
larseirikhansen Apr 19, 2024
8c6aa4d
Merge remote-tracking branch 'origin/main' into progressbar
larseirikhansen Apr 19, 2024
a2d1be1
testing with inset box shadow
larseirikhansen Apr 19, 2024
189941a
change bg to surface neutral subtle
larseirikhansen Apr 22, 2024
80bde97
Adjust JSDOC, round valueMin, valueMax
larseirikhansen Apr 22, 2024
b76cfb7
rm valuemin
larseirikhansen Apr 22, 2024
08e4d5a
change indeterminate state logic
larseirikhansen Apr 22, 2024
6cc0fc0
jsdoc tweaks, code cleaning
larseirikhansen Apr 23, 2024
a3a8960
Merge remote-tracking branch 'origin/main' into progressbar
larseirikhansen Apr 23, 2024
0e93ba1
added css for high contrast
larseirikhansen Apr 23, 2024
0717939
excluded progress bar from reduced motion css
larseirikhansen Apr 23, 2024
91ee4d5
added logic, jsdoc and storybook content for duration=0
larseirikhansen Apr 24, 2024
2bbbd0d
Merge remote-tracking branch 'origin/main' into progressbar
larseirikhansen Apr 24, 2024
bdb2667
Update @navikt/core/react/src/progress-bar/ProgressBar.tsx
larseirikhansen Apr 24, 2024
f2e1b6e
remove old code
larseirikhansen Apr 24, 2024
9ed2c68
Merge branch 'progressbar' of https://github.com/navikt/aksel into pr…
larseirikhansen Apr 24, 2024
13947dc
made value and valueMax optional since adding a duration invalidates …
larseirikhansen Apr 24, 2024
9bf7c9e
Set default valueMax to 100
larseirikhansen Apr 24, 2024
7da6e81
Remove useEffect + timeout and update aria attributes
larseirikhansen Apr 24, 2024
692cc37
jsdoc ValueMax default 100
larseirikhansen Apr 24, 2024
23c3510
changed JSDOC to reflect api changes
larseirikhansen Apr 24, 2024
f8a851d
made short description shorter
larseirikhansen Apr 24, 2024
5d5409f
rm bg token
larseirikhansen Apr 24, 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
6 changes: 6 additions & 0 deletions .changeset/fair-plums-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@navikt/ds-react": minor
"@navikt/ds-css": minor
---

:sparkles: Ny komponent: ProgressBar
2 changes: 1 addition & 1 deletion @navikt/core/css/baseline/_utilities.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* https://web.dev/prefers-reduced-motion/ */
@media (prefers-reduced-motion: reduce) {
*:not(.navds-loader *):not(.navds-loader),
*:not(.navds-loader *):not(.navds-loader):not(.navds-progress-bar *):not(.navds-progress-bar),
::before,
::after {
animation-delay: -1ms !important;
Expand Down
1 change: 1 addition & 0 deletions @navikt/core/css/config/_mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ const StyleMappings = {
},
{ component: "Panel", main: "panel.css" },
{ component: "Popover", main: "popover.css" },
{ component: "ProgressBar", main: "progress-bar.css" },
{ component: "Provider", main: "" },
{ component: "Radio", main: formCss, dependencies: [typoCss] },
{ component: "RadioGroup", main: formCss, dependencies: [typoCss] },
Expand Down
1 change: 1 addition & 0 deletions @navikt/core/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
@import "panel.css";
@import "link-panel.css";
@import "read-more.css";
@import "progress-bar.css";
@import "skeleton.css";
@import "stepper.css";
@import "table.css";
Expand Down
106 changes: 106 additions & 0 deletions @navikt/core/css/progress-bar.css
HalvorHaugan marked this conversation as resolved.
Show resolved Hide resolved
larseirikhansen marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
.navds-progress-bar {
background: var(--a-surface-neutral-subtle);
position: relative;
border-radius: var(--a-border-radius-full);
overflow: hidden;
box-shadow:
inset 0 1px 3px 0 rgba(0 0 0 / 0.15),
inset 0 0 1px 0 rgba(0 0 0 / 0.2);
}

.navds-progress-bar--small {
height: 12px;
min-width: 12px;
}

.navds-progress-bar--medium {
height: 16px;
min-width: 16px;
}

.navds-progress-bar--large {
height: 24px;
min-width: 24px;
}

.navds-progress-bar__foreground {
--__ac-progress-bar-translate: initial;

transform: translateX(var(--__ac-progress-bar-translate));
background: var(--ac-progress-bar-fg, var(--a-surface-alt-3));
transform-origin: left;
position: absolute;
top: 0;
left: 0;
bottom: 0;
width: 100%;
border-radius: inherit;
transition: transform 0.2s ease;
}

.navds-progress-bar__foreground--indeterminate {
--__ac-progress-bar-duration: initial;
--__ac-progress-bar-delay: 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-fill-mode: forwards, none;
animation-iteration-count: 1, infinite;
animation-delay: 0s, calc((var(--__ac-progress-bar-duration) + var(--__ac-progress-bar-delay)));
}

/* navds-progress-bar-indeterminate wave animation */
@keyframes navds-progress-bar-indeterminate {
0% {
left: -50%;
width: 50%;
transform: translateX(0%);
}

50% {
animation-direction: reverse;
left: 100%;
transform: translateX(0%);
width: 50%;
}

100% {
left: -50%;
transform: translateX(0%);
width: 50%;
}
}

@keyframes navds-progress-bar-indeterminate-grow {
0% {
transform: translateX(-100%);
}

20% {
transform: translateX(-80%);
}

30% {
transform: translateX(-40%);
}

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

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

@media (forced-colors: active) {
.navds-progress-bar__foreground {
background: Highlight;
}

.navds-progress-bar {
outline: 1px solid transparent;
}
}
3 changes: 3 additions & 0 deletions @navikt/core/css/tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@
"--ac-popover-bg": "--a-surface-default",
"--ac-popover-border": "--a-border-default"
},
"progress-bar": {
"--ac-progress-bar-fg": "--a-surface-alt-3"
},
"readmore": {
"--ac-read-more-text": "--a-text-action",
"--ac-read-more-hover-bg": "--a-surface-hover",
Expand Down
10 changes: 10 additions & 0 deletions @navikt/core/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,16 @@
"default": "./cjs/popover/index.js"
}
},
"./ProgressBar": {
"import": {
"types": "./esm/progress-bar/index.d.ts",
"default": "./esm/progress-bar/index.js"
},
"require": {
"types": "./cjs/progress-bar/index.d.ts",
"default": "./cjs/progress-bar/index.js"
}
},
"./Provider": {
"import": {
"types": "./esm/provider/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions @navikt/core/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export { Modal, type ModalProps } from "./modal";
export { Pagination, type PaginationProps } from "./pagination";
export { Popover, type PopoverProps } from "./popover";
export { Portal, type PortalProps } from "./portal";
export { ProgressBar, type ProgressBarProps } from "./progress-bar";
export { Provider, type ProviderProps } from "./provider";
export { ReadMore, type ReadMoreProps } from "./read-more";
export { Skeleton, type SkeletonProps } from "./skeleton";
Expand Down
153 changes: 153 additions & 0 deletions @navikt/core/react/src/progress-bar/ProgressBar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import { Meta, StoryFn, StoryObj } from "@storybook/react";
import React from "react";
import { ProgressBar } from ".";
import { VStack } from "../layout/stack";

export default {
title: "ds-react/ProgressBar",
component: ProgressBar,
parameters: {
chromatic: { disable: true },
},
} satisfies Meta<typeof ProgressBar>;

type Story = StoryObj<typeof ProgressBar>;

export const Default: StoryFn = (args) => {
const [value, setValue] = React.useState(0);
React.useEffect(() => {
const withRandomIntervals = (callback: () => void) => {
const interval = Math.random() * 4000 + 500; // Random interval between 0.1-0.8 seconds
return setTimeout(() => {
callback();
withRandomIntervals(callback);
}, interval);
};

const intervalId = withRandomIntervals(() => {
setValue((oldValue) => {
if (oldValue === 100) return 0;
const increment = Math.random() * 25 + 5; // Increase value 5-30 of 100
return oldValue + increment > 100 ? 100 : oldValue + increment;
});
});

return () => {
clearInterval(intervalId);
};
}, []);

return (
<div style={{ width: "400px" }}>
{value < 100 ? (
<>
<p id="progress-bar-label">Laster</p>
<ProgressBar
valueMax={100}
size={args.size}
value={value}
aria-labelledby="progress-bar-label"
duration={args.indeterminate ? 0 : undefined}
/>
</>
) : (
<p>Success screen successfully loaded 🎉</p>
)}
</div>
);
};
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) => {
return (
<div>
<p id="progress-bar-label-small">Fremdrift i søknaden (liten versjon)</p>
<ProgressBar
size="small"
value={0}
valueMax={args.valueMax}
aria-labelledby="progress-bar-label-small"
/>
<p id="progress-bar-label-medium">
Fremdrift i søknaden (medium versjon)
</p>
<ProgressBar
value={6}
valueMax={args.valueMax}
aria-labelledby="progress-bar-label-medium"
/>
<p id="progress-bar-label-large">Fremdrift i søknaden (stor versjon)</p>
<ProgressBar
size="large"
value={12}
valueMax={args.valueMax}
aria-labelledby="progress-bar-label-large"
/>
</div>
);
};

Sizes.args = {
valueMax: 12,
};

export const IndeterminateState: Story = {
render: () => {
const values = [2, 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) => (
larseirikhansen marked this conversation as resolved.
Show resolved Hide resolved
<div key={value}>
<p id={`progress-bar-label-${value}`}>
duration-prop satt til {value} sek
</p>
<ProgressBar
valueMax={100}
duration={value}
size="medium"
value={value}
aria-labelledby={`progress-bar-label-${value}`}
/>
</div>
))}
</>
);
},
};

export const Chromatic: Story = {
render: () => {
return (
<VStack gap="4">
<div>
<Sizes {...Sizes.args} />
</div>
</VStack>
);
},
parameters: {
chromatic: { disable: false },
},
};
Loading
Loading