Skip to content

Commit

Permalink
docs(): attach docs updated
Browse files Browse the repository at this point in the history
  • Loading branch information
denivladislav committed Oct 14, 2024
1 parent 1bb510e commit 68056e2
Show file tree
Hide file tree
Showing 6 changed files with 414 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,72 @@ export function App() {
);
}
```

### Пример использования в форме

```tsx live
import React, { useState } from 'react';
import { Attach, Button } from '@salutejs/{{ package }}';

function App() {
const ids = ['0', '1', '2'];
const [isLoading, setIsLoading] = useState(false);
const [attachedFiles, setAttachedFiles] = useState([]);

const handleAttachFile = (e) => {
setAttachedFiles((prevAttachedFiles) => [
...prevAttachedFiles,
{
fileData: e.target.files[0],
id: e.target.id,
},
]);
};

const handleAttachClear = (id) => {
setAttachedFiles(attachedFiles.filter((file) => file.id !== id));
};

const handleSubmit = (e) => {
e.preventDefault();
setIsLoading(true);

const formData = new FormData(e.target);
console.log('formData', Object.fromEntries(formData));

setTimeout(() => {
setAttachedFiles([]);
setIsLoading(false);
}, 2000);
};

return (
<>
<span>{isLoading ? 'Форма отправляется' : 'Прикрепленные файлы:'}</span>
{!isLoading && attachedFiles.length > 0 && (
<div style=\{{ display: 'flex', flexDirection: 'column', gap: '0px' }}>
{attachedFiles.map((file) => (
<span>{file.fileData.name}</span>
))}
</div>
)}

{!isLoading && (
<form onSubmit={handleSubmit} style=\{{ display: 'flex', flexDirection: 'column', gap: '30px' }}>
{ids.map((id) => (
<Attach
id={id}
name={`attach${id}`}
text={`Загрузить файл ${id}`}
onChange={handleAttachFile}
onClear={() => handleAttachClear(id)}
/>
))}

<Button type="submit">Отправить</Button>
</form>
)}
</>
);
}
```
69 changes: 69 additions & 0 deletions website/plasma-b2c-docs/docs/components/Attach.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,72 @@ export function App() {
);
}
```

### Пример использования в форме

```tsx live
import React, { useState } from 'react';
import { Attach, Button } from '@salutejs/plasma-b2c';

function App() {
const ids = ['0', '1', '2'];
const [isLoading, setIsLoading] = useState(false);
const [attachedFiles, setAttachedFiles] = useState([]);

const handleAttachFile = (e) => {
setAttachedFiles((prevAttachedFiles) => [
...prevAttachedFiles,
{
fileData: e.target.files[0],
id: e.target.id,
},
]);
};

const handleAttachClear = (id) => {
setAttachedFiles(attachedFiles.filter((file) => file.id !== id));
};

const handleSubmit = (e) => {
e.preventDefault();
setIsLoading(true);

const formData = new FormData(e.target);
console.log('formData', Object.fromEntries(formData));

setTimeout(() => {
setAttachedFiles([]);
setIsLoading(false);
}, 2000);
};

return (
<>
<span>{isLoading ? 'Форма отправляется' : 'Прикрепленные файлы:'}</span>
{!isLoading && attachedFiles.length > 0 && (
<div style={{ display: 'flex', flexDirection: 'column', gap: '0px' }}>
{attachedFiles.map((file) => (
<span>{file.fileData.name}</span>
))}
</div>
)}

{!isLoading && (
<form onSubmit={handleSubmit} style={{ display: 'flex', flexDirection: 'column', gap: '30px' }}>
{ids.map((id) => (
<Attach
id={id}
name={`attach${id}`}
text={`Загрузить файл ${id}`}
onChange={handleAttachFile}
onClear={() => handleAttachClear(id)}
/>
))}

<Button type="submit">Отправить</Button>
</form>
)}
</>
);
}
```
69 changes: 69 additions & 0 deletions website/plasma-web-docs/docs/components/Attach.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,72 @@ export function App() {
);
}
```

### Пример использования в форме

```tsx live
import React, { useState } from 'react';
import { Attach, Button } from '@salutejs/plasma-web';

function App() {
const ids = ['0', '1', '2'];
const [isLoading, setIsLoading] = useState(false);
const [attachedFiles, setAttachedFiles] = useState([]);

const handleAttachFile = (e) => {
setAttachedFiles((prevAttachedFiles) => [
...prevAttachedFiles,
{
fileData: e.target.files[0],
id: e.target.id,
},
]);
};

const handleAttachClear = (id) => {
setAttachedFiles(attachedFiles.filter((file) => file.id !== id));
};

const handleSubmit = (e) => {
e.preventDefault();
setIsLoading(true);

const formData = new FormData(e.target);
console.log('formData', Object.fromEntries(formData));

setTimeout(() => {
setAttachedFiles([]);
setIsLoading(false);
}, 2000);
};

return (
<>
<span>{isLoading ? 'Форма отправляется' : 'Прикрепленные файлы:'}</span>
{!isLoading && attachedFiles.length > 0 && (
<div style={{ display: 'flex', flexDirection: 'column', gap: '0px' }}>
{attachedFiles.map((file) => (
<span>{file.fileData.name}</span>
))}
</div>
)}

{!isLoading && (
<form onSubmit={handleSubmit} style={{ display: 'flex', flexDirection: 'column', gap: '30px' }}>
{ids.map((id) => (
<Attach
id={id}
name={`attach${id}`}
text={`Загрузить файл ${id}`}
onChange={handleAttachFile}
onClear={() => handleAttachClear(id)}
/>
))}

<Button type="submit">Отправить</Button>
</form>
)}
</>
);
}
```
69 changes: 69 additions & 0 deletions website/sdds-cs-docs/docs/components/Attach.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,72 @@ export function App() {
);
}
```

### Пример использования в форме

```tsx live
import React, { useState } from 'react';
import { Attach, Button } from '@salutejs/sdds-cs';

function App() {
const ids = ['0', '1', '2'];
const [isLoading, setIsLoading] = useState(false);
const [attachedFiles, setAttachedFiles] = useState([]);

const handleAttachFile = (e) => {
setAttachedFiles((prevAttachedFiles) => [
...prevAttachedFiles,
{
fileData: e.target.files[0],
id: e.target.id,
},
]);
};

const handleAttachClear = (id) => {
setAttachedFiles(attachedFiles.filter((file) => file.id !== id));
};

const handleSubmit = (e) => {
e.preventDefault();
setIsLoading(true);

const formData = new FormData(e.target);
console.log('formData', Object.fromEntries(formData));

setTimeout(() => {
setAttachedFiles([]);
setIsLoading(false);
}, 2000);
};

return (
<>
<span>{isLoading ? 'Форма отправляется' : 'Прикрепленные файлы:'}</span>
{!isLoading && attachedFiles.length > 0 && (
<div style={{ display: 'flex', flexDirection: 'column', gap: '0px' }}>
{attachedFiles.map((file) => (
<span>{file.fileData.name}</span>
))}
</div>
)}

{!isLoading && (
<form onSubmit={handleSubmit} style={{ display: 'flex', flexDirection: 'column', gap: '30px' }}>
{ids.map((id) => (
<Attach
id={id}
name={`attach${id}`}
text={`Загрузить файл ${id}`}
onChange={handleAttachFile}
onClear={() => handleAttachClear(id)}
/>
))}

<Button type="submit">Отправить</Button>
</form>
)}
</>
);
}
```
69 changes: 69 additions & 0 deletions website/sdds-dfa-docs/docs/components/Attach.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,73 @@ export function App() {
</div>
);
}
```

### Пример использования в форме

```tsx live
import React, { useState } from 'react';
import { Attach, Button } from '@salutejs/sdds-dfa';

function App() {
const ids = ['0', '1', '2'];
const [isLoading, setIsLoading] = useState(false);
const [attachedFiles, setAttachedFiles] = useState([]);

const handleAttachFile = (e) => {
setAttachedFiles((prevAttachedFiles) => [
...prevAttachedFiles,
{
fileData: e.target.files[0],
id: e.target.id,
},
]);
};

const handleAttachClear = (id) => {
setAttachedFiles(attachedFiles.filter((file) => file.id !== id));
};

const handleSubmit = (e) => {
e.preventDefault();
setIsLoading(true);

const formData = new FormData(e.target);
console.log('formData', Object.fromEntries(formData));

setTimeout(() => {
setAttachedFiles([]);
setIsLoading(false);
}, 2000);
};

return (
<>
<span>{isLoading ? 'Форма отправляется' : 'Прикрепленные файлы:'}</span>
{!isLoading && attachedFiles.length > 0 && (
<div style={{ display: 'flex', flexDirection: 'column', gap: '0px' }}>
{attachedFiles.map((file) => (
<span>{file.fileData.name}</span>
))}
</div>
)}

{!isLoading && (
<form onSubmit={handleSubmit} style={{ display: 'flex', flexDirection: 'column', gap: '30px' }}>
{ids.map((id) => (
<Attach
id={id}
name={`attach${id}`}
text={`Загрузить файл ${id}`}
onChange={handleAttachFile}
onClear={() => handleAttachClear(id)}
/>
))}

<Button type="submit">Отправить</Button>
</form>
)}
</>
);
}
```
Loading

0 comments on commit 68056e2

Please sign in to comment.