Skip to content

Commit 99a4e0d

Browse files
Merge pull request #667 from ditadi/headless-progress
feat: progress bar headless and styled
2 parents 411f200 + 24df74b commit 99a4e0d

File tree

18 files changed

+381
-10
lines changed

18 files changed

+381
-10
lines changed

apps/website/src/_state/component-statuses.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const statusByComponent: ComponentKitsStatuses = {
2424
Modal: ComponentStatus.Draft,
2525
Pagination: ComponentStatus.Draft,
2626
Popover: ComponentStatus.Draft,
27+
Progress: ComponentStatus.Draft,
2728
RadioGroup: ComponentStatus.Draft,
2829
Separator: ComponentStatus.Beta,
2930
Skeleton: ComponentStatus.Beta,
@@ -38,6 +39,7 @@ export const statusByComponent: ComponentKitsStatuses = {
3839
Modal: ComponentStatus.Beta,
3940
Pagination: ComponentStatus.Draft,
4041
Popover: ComponentStatus.Beta,
42+
Progress: ComponentStatus.Draft,
4143
Select: ComponentStatus.Beta,
4244
Separator: ComponentStatus.Beta,
4345
Tabs: ComponentStatus.Beta,

apps/website/src/routes/docs/headless/menu.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- [Modal](/docs/headless/modal)
2121
- [Pagination](/docs/headless/pagination)
2222
- [Popover](/docs/headless/popover)
23+
- [Progress](/docs/headless/progress)
2324
- [Select](/docs/headless/select)
2425
- [Separator](/docs/headless/separator)
2526
- [Tabs](/docs/headless/tabs)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { component$, useStyles$ } from '@builder.io/qwik';
2+
import { Progress, ProgressIndicator } from '@qwik-ui/headless';
3+
import styles from '../snippets/progress.css?inline';
4+
5+
export default component$(() => {
6+
useStyles$(styles);
7+
8+
const progress = 30;
9+
10+
return (
11+
<Progress value={progress} class="progress">
12+
<ProgressIndicator
13+
class="progress-indicator"
14+
style={{
15+
transform: `translateX(-${100 - progress}%)`,
16+
}}
17+
/>
18+
</Progress>
19+
);
20+
});
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
title: Qwik UI | Progress
3+
---
4+
5+
import { statusByComponent } from '~/_state/component-statuses';
6+
import { FeatureList } from '~/components/feature-list/feature-list';
7+
import { Note } from '~/components/note/note';
8+
9+
<StatusBanner status={statusByComponent.headless.Progress} />
10+
11+
# Progress
12+
13+
Displays a progress bar related to a task.
14+
15+
<Showcase name="hero" />
16+
17+
Qwik UI's Progress implementation follows the [WAI-Aria](https://www.w3.org/WAI/ARIA/apg/patterns/meter) design pattern, along with some additional API's that enhance the flexibility, types, and performance.
18+
19+
<FeatureList
20+
features={['Provides context for assistive technology to read the progress of a task.']}
21+
/>
22+
23+
<div class="mb-6 flex flex-col gap-2">
24+
[View Source Code ↗️](https://github.com/qwikifiers/qwik-ui/tree/main/packages/kit-headless/src/components/progress)
25+
26+
[Report an issue 🚨](https://github.com/qwikifiers/qwik-ui/issues)
27+
28+
[Edit This Page 🗒️](<https://github.com/qwikifiers/qwik-ui/edit/main/apps/website/src/routes/docs/headless/(components)/progress/index.mdx>)
29+
30+
</div>
31+
32+
## Building blocks
33+
34+
```tsx
35+
import { component$ } from '@builder.io/qwik';
36+
import { Progress, ProgressIndicator } from '@qwik-ui/headless';
37+
38+
export default component$(() => {
39+
const progress = 30;
40+
41+
return (
42+
<Progress value={progress} class="progress">
43+
<ProgressIndicator
44+
class="progress-indicator"
45+
style={{
46+
transform: `translateX(-${100 - progress}%)`,
47+
}}
48+
/>
49+
</Progress>
50+
);
51+
});
52+
```
53+
54+
## Accessibility
55+
56+
Adheres to the [progressbar role requirements](https://www.w3.org/WAI/ARIA/apg/patterns/meter/).
57+
58+
## API
59+
60+
### Root
61+
62+
Contains all of the progress parts.
63+
64+
<APITable
65+
propDescriptors={[
66+
{
67+
name: 'class',
68+
type: 'string',
69+
description: 'CSS classes to apply to the Progress.',
70+
},
71+
{
72+
name: 'value',
73+
type: 'number',
74+
description: 'The progress value.',
75+
},
76+
{
77+
name: 'max',
78+
type: 'number',
79+
description: 'The maximum progress value',
80+
},
81+
{
82+
name: 'getValueLabel',
83+
type: 'function',
84+
description:
85+
'A function to get the accessible label text representing the current value in a human-readable format. If not provided, the value label will be read as the numeric value as a percentage of the max value.',
86+
},
87+
]}
88+
/>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.progress {
2+
height: 1.75rem;
3+
width: 100%;
4+
overflow: hidden;
5+
border-radius: calc(var(--border-radius) / 2);
6+
background-color: hsl(var(--foreground));
7+
}
8+
9+
.progress-indicator {
10+
height: 100%;
11+
width: 100%;
12+
background-color: hsl(var(--primary));
13+
}

apps/website/src/routes/docs/styled/menu.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- [Label](/docs/styled/label)
2626
- [Modal](/docs/styled/modal)
2727
- [Popover](/docs/styled/popover)
28+
- [Progress](/docs/styled/progress)
2829
- [RadioGroup](/docs/styled/radio-group)
2930
- [Separator](/docs/styled/separator)
3031
- [Skeleton](/docs/styled/skeleton)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { component$, useOnWindow, useSignal, $ } from '@builder.io/qwik';
2+
import { Progress } from '@qwik-ui/styled';
3+
4+
export default component$(() => {
5+
const progress = useSignal(30);
6+
7+
useOnWindow(
8+
'load',
9+
$(() => {
10+
setTimeout(() => {
11+
progress.value = 50;
12+
}, 1000);
13+
}),
14+
);
15+
16+
return <Progress value={progress.value} />;
17+
});

apps/website/src/routes/docs/styled/progress/index.mdx

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,50 @@ title: Qwik UI | Styled Progress Component
44

55
import { statusByComponent } from '~/_state/component-statuses';
66

7+
<StatusBanner status={statusByComponent.styled.Progress} />
8+
79
# Progress
810

9-
The Qwik UI Styled progress component is your digital cheerleader, celebrating each step forward with flashy colors and a positive attitude!
11+
Displays an indicator showing the completion progress of a task, typically displayed as a progress bar.
1012

11-
<StatusBanner status={statusByComponent.styled.Progress} />
13+
<Showcase name="hero" />
14+
15+
## Installation
16+
17+
### Run the following cli command or copy/paste the component code into your project
18+
19+
```sh
20+
qwik-ui add progress
21+
```
22+
23+
```tsx
24+
import { cn } from '@qwik-ui/utils';
25+
import {
26+
Progress as QwikUIProgress,
27+
ProgressIndicator as QwikUIProgressIndicator,
28+
} from '@qwik-ui/headless';
29+
import { PropsOf, component$ } from '@builder.io/qwik';
30+
31+
export const Progress = component$<PropsOf<typeof QwikUIProgress>>((props) => {
32+
return (
33+
<QwikUIProgress
34+
class={cn('bg-secondary relative h-4 w-full overflow-hidden rounded', props?.class)}
35+
>
36+
<QwikUIProgressIndicator
37+
class="bg-primary h-full w-full flex-1 transition-all"
38+
style={{ transform: `translateX(-${100 - (props.value || 0)}%)` }}
39+
/>
40+
</QwikUIProgress>
41+
);
42+
});
43+
```
44+
45+
## Usage
46+
47+
```tsx
48+
import { Progress } from '@qwik-ui/styled';
49+
```
50+
51+
```tsx
52+
<Progress value={30} />
53+
```
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './progress-indicator';
2+
export * from './progress';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { createContextId } from '@builder.io/qwik';
2+
3+
export interface ProgressContext {
4+
value: number | null;
5+
max: number;
6+
}
7+
8+
export const ProgressContext = createContextId<ProgressContext>('progress');

0 commit comments

Comments
 (0)