Skip to content

Commit

Permalink
docs(root): add code examples for dropdown and file upload buttons
Browse files Browse the repository at this point in the history
Add code examples for dropdown and file upload buttons

. #845
  • Loading branch information
GCHQ-Developer-530 committed Mar 14, 2024
1 parent 741fa0b commit 031e7d9
Showing 1 changed file with 91 additions and 3 deletions.
94 changes: 91 additions & 3 deletions src/content/structured/components/buttons/code.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
path: "/components/button/code"

date: "2023-10-03"
date: "2024-03-13"

title: "Button"

Expand Down Expand Up @@ -67,12 +67,14 @@ export const snippetsOtherStates = [
{
language: "Web component",
snippet: `<ic-button variant="primary" disabled="true">Add to order</ic-button>
<ic-button variant="secondary" loading="true">Loading button</ic-button>`,
<ic-button variant="secondary" loading="true">Loading button</ic-button>
<ic-button variant="primary" dropdown="true">Add to order</ic-button>`,
},
{
language: "React",
snippet: `<IcButton variant="primary" disabled>Add to order</IcButton>
<IcButton variant="secondary" loading>Loading button</IcButton>`,
<IcButton variant="secondary" loading>Loading button</IcButton>
<IcButton variant="primary" dropdown>Add to order</IcButton>`,
},
];

Expand All @@ -83,6 +85,9 @@ export const snippetsOtherStates = [
<IcButton variant="secondary" loading>
Loading button
</IcButton>
<IcButton variant="primary" dropdown>
Add to order
</IcButton>
</ComponentPreview>

### With icon
Expand Down Expand Up @@ -247,3 +252,86 @@ export const snippetsColour = [
Add to order
</IcButton>
</ComponentPreview>

### File upload

export const FileUpload = () => {
function updateFileList(fileArray) {
const fileList = [];
Array.from(fileArray).forEach((file) => {
fileList.push(file.name);
});
return fileList.join(", ");
}
return (
<IcButton
variant="primary"
fileUpload
accept=".doc, text/plain, .json, .png"
onClick={() =>
document.addEventListener("icFileSelection", (event) =>
console.log(updateFileList(event.detail))
)
}
>
Upload File
</IcButton>
);
};

export const snippetsFileUpload = [
{
language: "Web component",
snippet: `<ic-button
variant="primary"
id="file-button"
file-upload="true"
accept=".doc, text/plain, .json, .png"
>
Upload File
</ic-button>
<script>
var file;
onclick = document
.querySelector("#file-button")
.addEventListener("icFileSelection", (ev) => {
const fileArray = ev.detail;
const fileList = [];
Array.from(fileArray).forEach((file) => {
fileList.push(file.name);
});
console.log(fileList.join(", "));
});
</script>`,
},
{
language: "React",
snippet: `export const FileUpload = () => {
function updateFileList(fileArray) {
const fileList = [];
Array.from(fileArray).forEach((file) => {
fileList.push(file.name);
});
return fileList.join(", ");
}
return (
<IcButton
variant="primary"
fileUpload
accept=".doc, text/plain, .json, .png"
onClick={(event) =>
document.addEventListener("icFileSelection", (event) =>
console.log(updateFileList(event.detail))
)
}
>
Upload File
</IcButton>
);
};`,
},
];

<ComponentPreview snippets={snippetsFileUpload}>
<FileUpload />
</ComponentPreview>

0 comments on commit 031e7d9

Please sign in to comment.