Skip to content

Commit

Permalink
[DST-494]: add loading states pattern (#4152)
Browse files Browse the repository at this point in the history
* DST-494: add loading states pattern

* DST-494: extend XLoader mode in fullsize and inline

* DST-494: add full section demo

* Create large-cows-explain.md

* DST-494: resolve comments

* DST-494: resolve comments

* DST-494: fix inline loading button example

* Update loading-states.mdx

Updated content to remove references to a one-second-delay, as we decided not to do this.

* DST-494: replace related content with teaser list

* docs: fix the badge backgroundcolor (#4203)

* DST-494: replace related content with teaser list

* Update loading-states.mdx

Added missing links, code formatting + made a few small wording changes to clarify points.

---------

Co-authored-by: tirado-rx <[email protected]>
Co-authored-by: sarahgm <[email protected]>
  • Loading branch information
3 people authored Oct 8, 2024
1 parent aed025c commit f18c8aa
Show file tree
Hide file tree
Showing 10 changed files with 509 additions and 9 deletions.
8 changes: 8 additions & 0 deletions .changeset/large-cows-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@marigold/docs": patch
"@marigold/components": patch
---

[DST-494]: add loading states pattern

[DST-494]: added prop `mode`to the `<XLoader />` to support inline and full-section loading
2 changes: 1 addition & 1 deletion docs/content/components/form/number-field/number-field.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ the user about the error. The message disappears automatically when all requirem
},
{
title: 'Forms',
href: '../recipes/forms',
href: '../../recipes/form-recipes',
caption: 'Here you can find some recipes for some form components.',
icon: (
<svg
Expand Down
2 changes: 1 addition & 1 deletion docs/content/components/form/textfield/textfield.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ the user about the error. The message disappears automatically when all requirem
},
{
title: 'Forms',
href: '../recipes/forms',
href: '../../recipes/form-recipes',
caption: 'Here you can find some recipes for some form components.',
icon: (
<svg
Expand Down
74 changes: 69 additions & 5 deletions docs/content/patterns/feedback-messages/feedback-messages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,72 @@ A [section message](/components/section-message) is a block-level component that
- Understanding and fighting alert fatigue ([English](https://www.atlassian.com/incident-management/on-call/alert-fatigue#The%20-psychology-of-alert-fatigue), [German](https://www.atlassian.com/de/incident-management/on-call/alert-fatigue#What-is-alert-fatigue?))
- [Web Content Accessililty Guidelines (WCAG) 2.0](https://www.w3.org/TR/WCAG20/#minimize-error)

## Related pages

- [Dialog](/components/overlay/dialog)
- [SectionMessage](/components/content/section-message)
- [Validation](/foundations/validation)
## Related

<TeaserList
items={[
{
title: 'Dialog',
href: '../../components/overlay/dialog',
caption: 'Component for displaying dialogs.',
icon: (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth="1.5"
stroke="currentColor"
className="size-6"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M20.25 8.511c.884.284 1.5 1.128 1.5 2.097v4.286c0 1.136-.847 2.1-1.98 2.193-.34.027-.68.052-1.02.072v3.091l-3-3c-1.354 0-2.694-.055-4.02-.163a2.115 2.115 0 0 1-.825-.242m9.345-8.334a2.126 2.126 0 0 0-.476-.095 48.64 48.64 0 0 0-8.048 0c-1.131.094-1.976 1.057-1.976 2.192v4.286c0 .837.46 1.58 1.155 1.951m9.345-8.334V6.637c0-1.621-1.152-3.026-2.76-3.235A48.455 48.455 0 0 0 11.25 3c-2.115 0-4.198.137-6.24.402-1.608.209-2.76 1.614-2.76 3.235v6.226c0 1.621 1.152 3.026 2.76 3.235.577.075 1.157.14 1.74.194V21l4.155-4.155"
/>
</svg>
),
},
{
title: 'Section Message',
href: '../../components/content/section-message',
caption: 'Display a short message with important informations.',
icon: (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth="1.5"
stroke="currentColor"
className="size-6"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M2.25 12.76c0 1.6 1.123 2.994 2.707 3.227 1.068.157 2.148.279 3.238.364.466.037.893.281 1.153.671L12 21l2.652-3.978c.26-.39.687-.634 1.153-.67 1.09-.086 2.17-.208 3.238-.365 1.584-.233 2.707-1.626 2.707-3.228V6.741c0-1.602-1.123-2.995-2.707-3.228A48.394 48.394 0 0 0 12 3c-2.392 0-4.744.175-7.043.513C3.373 3.746 2.25 5.14 2.25 6.741v6.018Z"
/>
</svg>
),
},
{
title: 'Validation',
href: '../../foundations/validation',
caption: 'Learn about how to use form validation with Marigold.',
icon: (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth="1.5"
stroke="currentColor"
className="size-6"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M9 12.75 11.25 15 15 9.75M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"
/>
</svg>
),
},
]}
/>
65 changes: 65 additions & 0 deletions docs/content/patterns/loading-states/full-section.demo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { FormEvent, useState } from 'react';
import {
Button,
FieldGroup,
Form,
Headline,
Stack,
TextField,
XLoader,
} from '@marigold/components';

export default () => {
const [isLoading, setIsLoading] = useState<boolean>(false);
const [searchTerm, setSearchTerm] = useState<string>('');

const api = (inputValue: string): Promise<string> => {
return new Promise(resolve => {
setTimeout(() => {
resolve(inputValue);
}, 3000);
});
};

const handleOnSubmit = async (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
const formData = new FormData(e.target as HTMLFormElement);
const data: { [bookInput: string]: FormDataEntryValue } =
Object.fromEntries(formData);

setIsLoading(true);
const res = await api(data['bookInput'].toString());
setSearchTerm(res);
setIsLoading(false);
};

return (
<div>
<Form onSubmit={handleOnSubmit}>
<FieldGroup labelWidth="100px">
<Headline level={2}>Book search</Headline>
<TextField
label="Book name:"
description="Please enter a book name"
placeholder="Book name"
name="bookInput"
/>
<Stack space={2}>
<Stack alignX="right">
<Button
variant="primary"
size="small"
type="submit"
className="w-20"
>
Submit
</Button>
</Stack>
{searchTerm && `You searched for ${searchTerm}.`}
</Stack>
</FieldGroup>
</Form>
{isLoading && <XLoader mode="fullsize" size={80} />}
</div>
);
};
74 changes: 74 additions & 0 deletions docs/content/patterns/loading-states/inline-indicator.demo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { FormEvent, useState } from 'react';
import {
Button,
FieldGroup,
Form,
Headline,
Stack,
TextField,
XLoader,
} from '@marigold/components';

export default () => {
const [isLoading, setIsLoading] = useState<boolean>(false);
const [searchTerm, setSearchTerm] = useState<string>('');

const api = (inputValue: string): Promise<string> => {
return new Promise(resolve => {
setTimeout(() => {
resolve(inputValue);
}, 3000);
});
};

const handleOnSubmit = async (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
const formData = new FormData(e.target as HTMLFormElement);
const data: { [bookInput: string]: FormDataEntryValue } =
Object.fromEntries(formData);

setIsLoading(true);
const res = await api(data['bookInput'].toString());
setSearchTerm(res);
setIsLoading(false);
};

return (
<Form onSubmit={handleOnSubmit}>
<FieldGroup labelWidth="100px">
<Headline level={2}>Book search</Headline>
<TextField
label="Book name:"
description="Please enter a book name"
placeholder="Book name"
name="bookInput"
/>
<Stack space={2}>
<Stack alignX="right">
{isLoading ? (
<Button
variant="primary"
size="small"
type="submit"
className="h-8 w-20 !cursor-progress"
disabled
>
<XLoader size={16} className="fill-gray-700" />
</Button>
) : (
<Button
variant="primary"
size="small"
type="submit"
className="w-20"
>
Submit
</Button>
)}
</Stack>
{searchTerm && `You searched for <b>${searchTerm}</b>.`}
</Stack>
</FieldGroup>
</Form>
);
};
Loading

0 comments on commit f18c8aa

Please sign in to comment.