Skip to content

Commit 47ad173

Browse files
committed
docs: Add Loading and TextArea to playgrounds
1 parent 4508a8a commit 47ad173

File tree

14 files changed

+184
-32
lines changed

14 files changed

+184
-32
lines changed

docs/core/api/useDLE.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import { ProfileResource } from './ProfileResource';
5050
function ProfileList(): JSX.Element {
5151
const { data, loading, error } = useDLE(ProfileResource.getList);
5252
if (error) return <div>Error {`${error.status}`}</div>;
53-
if (loading || !data) return <>loading...</>;
53+
if (loading || !data) return <Loading/>;
5454
return (
5555
<div>
5656
{data.map(profile => (
@@ -165,7 +165,7 @@ function ProfileDetail(): JSX.Element {
165165
error,
166166
} = useDLE(ProfileResource.get, { id: 1 });
167167
if (error) return <div>Error {`${error.status}`}</div>;
168-
if (loading || !profile) return <>loading...</>;
168+
if (loading || !profile) return <Loading/>;
169169
return (
170170
<div className="listItem">
171171
<Avatar src={profile.avatar} />
@@ -230,7 +230,7 @@ import { PostResource, UserResource } from './Resources';
230230
export default function PostWithAuthor({ id }: { id: string }) {
231231
const postDLE = useDLE(PostResource.get, { id });
232232
if (postDLE.error) return <div>Error {`${postDLE.error.status}`}</div>;
233-
if (postDLE.loading || !postDLE.data) return <>loading...</>;
233+
if (postDLE.loading || !postDLE.data) return <Loading/>;
234234
const authorDLE = useDLE(
235235
UserResource.get,
236236
postDLE.data.userId
@@ -240,7 +240,7 @@ export default function PostWithAuthor({ id }: { id: string }) {
240240
: null,
241241
);
242242
if (authorDLE.error) return <div>Error {`${authorDLE.error.status}`}</div>;
243-
if (authorDLE.loading || !authorDLE.data) return <>loading...</>;
243+
if (authorDLE.loading || !authorDLE.data) return <Loading/>;
244244

245245
return <div>{authorDLE.data.username}</div>
246246
}
@@ -281,7 +281,7 @@ import { getPosts } from './api/Post';
281281
export default function ArticleList({ page }: { page: string }) {
282282
const { data, loading, error } = useDLE(getPosts, { page });
283283
if (error) return <div>Error {`${error.status}`}</div>;
284-
if (loading || !data) return <>loading...</>;
284+
if (loading || !data) return <Loading/>;
285285
const { results: posts, nextPage, lastPage } = data;
286286
return (
287287
<div>

docs/core/getting-started/data-dependency.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ import { ProfileResource } from './ProfileResource';
252252
function ProfileList(): JSX.Element {
253253
const { data, loading, error } = useDLE(ProfileResource.getList);
254254
if (error) return <div>Error {`${error.status}`}</div>;
255-
if (loading || !data) return <>loading...</>;
255+
if (loading || !data) return <Loading/>;
256256
return (
257257
<div>
258258
{data.map(profile => (

docs/core/shared/_useLoading.mdx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import HooksPlayground from '@site/src/components/HooksPlayground';
2-
import { postFixtures,getInitialInterceptorData } from '@site/src/fixtures/posts';
2+
import {
3+
postFixtures,
4+
getInitialInterceptorData,
5+
} from '@site/src/fixtures/posts';
36

47
<HooksPlayground fixtures={postFixtures} getInitialInterceptorData={getInitialInterceptorData} row>
58

@@ -54,18 +57,18 @@ export default function PostForm({ onSubmit, loading, error }) {
5457
};
5558
return (
5659
<form onSubmit={handleSubmit}>
57-
<TextInput label="Title" name="title" defaultValue="My New Post"
58-
required />
59-
<label>
60-
Body:
61-
<br />
62-
<textarea name="body" rows={12} required>
63-
After clicking 'save', the button will be disabled until
64-
the POST is completed. Upon completion the newly created
65-
post is displayed immediately as Reactive Data Client is
66-
able to use the fetch response to populate the store.
67-
</textarea>
68-
</label>
60+
<TextInput
61+
label="Title"
62+
name="title"
63+
defaultValue="My New Post"
64+
required
65+
/>
66+
<TextArea name="body" rows={12} label="Body" required>
67+
After clicking 'save', the button will be disabled until the POST
68+
is completed. Upon completion the newly created post is displayed
69+
immediately as Reactive Data Client is able to use the fetch
70+
response to populate the store.
71+
</TextArea>
6972
{error ? (
7073
<div className="alert alert--danger">{error.message}</div>
7174
) : null}
@@ -93,8 +96,9 @@ export default function PostCreate({ navigateToPost }) {
9396
},
9497
[ctrl],
9598
);
96-
return <PostForm onSubmit={handleSubmit} loading={loading}
97-
error={error} />;
99+
return (
100+
<PostForm onSubmit={handleSubmit} loading={loading} error={error} />
101+
);
98102
}
99103
```
100104

@@ -119,4 +123,4 @@ function Navigation() {
119123
render(<Navigation />);
120124
```
121125

122-
</HooksPlayground>
126+
</HooksPlayground>

docs/rest/api/Collection.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export default function NewTodo({ userId }: { userId?: string }) {
121121
};
122122

123123
return (
124-
<div>
124+
<div className="listItem nogap">
125125
<TextInput size="small" onKeyDown={handlePress} />
126126
<label>
127127
<input

website/src/components/Demo/code/profile-edit/graphql/PostList.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ function PostList() {
88
return (
99
<div>
1010
<ProfileEdit id={userId} />
11-
<br />
1211
{posts.map(post => (
1312
<PostItem key={post.pk()} post={post} />
1413
))}

website/src/components/Demo/code/profile-edit/rest/PostList.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ function PostList() {
88
return (
99
<div>
1010
<ProfileEdit id={userId} />
11-
<br />
1211
{posts.map(post => (
1312
<PostItem key={post.pk()} post={post} />
1413
))}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.loading {
2+
display:flex;
3+
justify-content: center;
4+
align-items: center;
5+
height: 100%;
6+
}
7+
8+
.loading img {
9+
width:50px;
10+
height:50px;
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import useBaseUrl from '@docusaurus/useBaseUrl';
2+
3+
import styles from './Loading.module.css';
4+
5+
export function Loading() {
6+
const loadingUrl = useBaseUrl('img/loading-logo.svg');
7+
return (
8+
<div className={styles.loading}>
9+
<img src={loadingUrl} />
10+
</div>
11+
);
12+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import classnames from 'clsx';
2+
import React, { type InputHTMLAttributes } from 'react';
3+
4+
export function TextArea({
5+
label,
6+
...props
7+
}: InputHTMLAttributes<HTMLTextAreaElement> & {
8+
label?: React.ReactNode;
9+
}) {
10+
return (
11+
<div className="rt-TextAreaRoot">
12+
<textarea className="rt-TextAreaInput" {...props} />
13+
<label className="rt-TextFieldLabel" htmlFor={props.name}>
14+
{label}
15+
</label>
16+
</div>
17+
);
18+
}

website/src/components/Playground/DesignSystem/design-system.css

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ html[data-theme='dark'] .playground-preview {
1515
border: 1px solid var(--ifm-color-emphasis-400);
1616
border-radius: 4px;
1717
position: relative;
18+
margin-bottom:1ex;
1819
}
1920
html[data-theme='dark'] .rt-TextFieldRoot,
21+
html[data-theme='dark'] .rt-TextAreaRoot,
2022
html[data-theme='dark'] .small.rt-TextFieldRoot:hover,
2123
html[data-theme='dark'] .small.rt-TextFieldRoot:focus-within {
2224
background-color: var(--ifm-color-emphasis-100);
@@ -75,8 +77,7 @@ html[data-theme='dark'] .small.rt-TextFieldRoot:focus-within {
7577
}
7678

7779
/* Focus state for the text field */
78-
.rt-TextFieldInput:focus + .rt-TextFieldLabel,
79-
.rt-TextFieldInput:not(:placeholder-shown) + .rt-TextFieldLabel {
80+
.rt-TextFieldInput:focus + .rt-TextFieldLabel {
8081
color: var(--ifm-color-formfield-active);
8182
}
8283

@@ -108,6 +109,7 @@ html[data-theme='dark'] .small.rt-TextFieldRoot:focus-within {
108109
box-sizing: border-box; /* Include padding and border in element's size */
109110
transition: all 0.2s ease-in-out; /* Quick animation for transitions */
110111
border-radius: 0;
112+
margin-bottom:0;
111113
}
112114
html[data-theme='dark'] .small.rt-TextFieldRoot {
113115
background: none;
@@ -124,4 +126,44 @@ html[data-theme='dark'] .small.rt-TextFieldRoot {
124126

125127
.listItem .rt-TextFieldRoot {
126128
width: calc(100% - 21px);
127-
}
129+
}
130+
131+
132+
133+
134+
/* Root container for the textarea */
135+
.rt-TextAreaRoot {
136+
position: relative;
137+
width: 100%;
138+
background-color: var(--ifm-color-emphasis-0);
139+
border: 1px solid var(--ifm-color-emphasis-400);
140+
border-radius: 4px;
141+
padding-bottom:-5px;
142+
/* overflow: hidden; */
143+
margin: 1.5ex 0 .5ex;
144+
}
145+
146+
/* The textarea element inside the component */
147+
.rt-TextAreaInput {
148+
padding: 0.5em;
149+
width: 100%;
150+
border: none;
151+
outline: none;
152+
font-size: 14px;
153+
color: var(--ifm-color-content);
154+
background: transparent;
155+
resize: vertical; /* Allow vertical resizing */
156+
min-height: 4em; /* Set a minimum height */
157+
box-sizing: border-box;
158+
margin-bottom: -8px;
159+
}
160+
161+
162+
/* Focus state for the textarea */
163+
.rt-TextAreaInput:focus + .rt-TextFieldLabel {
164+
color: var(--ifm-color-formfield-active);
165+
}
166+
167+
.rt-TextAreaRoot:focus-within {
168+
border-color: var(--ifm-color-formfield-active);
169+
}

0 commit comments

Comments
 (0)