Skip to content

Commit

Permalink
FileUpload: 💥 Remove UNSAFE-prefix (#3205)
Browse files Browse the repository at this point in the history
  • Loading branch information
HalvorHaugan authored Oct 7, 2024
1 parent 946cbeb commit 324358d
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-monkeys-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@navikt/ds-react": minor
---

FileUpload: :boom: Remove UNSAFE-prefix
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import { Meta, StoryFn, StoryObj } from "@storybook/react";
import { fireEvent, within } from "@storybook/test";
import React from "react";
import { ImageIcon } from "@navikt/aksel-icons";
import {
type FileObject,
UNSAFE_FileUpload as FileUpload,
type FilesPartitioned,
} from ".";
import { type FileObject, FileUpload, type FilesPartitioned } from ".";

const meta: Meta<typeof FileUpload.Dropzone> = {
title: "ds-react/FileUpload/Dropzone",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta, StoryFn } from "@storybook/react";
import React from "react";
import { FileItem, UNSAFE_FileUpload as FileUpload } from ".";
import { FileItem, FileUpload } from ".";
import { VStack } from "../../layout/stack";

const meta: Meta<typeof FileUpload.Item> = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Meta, StoryFn } from "@storybook/react";
import React, { useEffect, useState } from "react";
import { UploadIcon } from "@navikt/aksel-icons";
import { UNSAFE_FileUpload as FileUpload, FileUploadItemProps } from ".";
import { FileUpload, FileUploadItemProps } from ".";
import { Alert } from "../../alert";
import { Button } from "../../button";
import { VStack } from "../../layout/stack";
Expand Down
8 changes: 4 additions & 4 deletions @navikt/core/react/src/form/file-upload/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use client";
export { default as UNSAFE_FileUpload } from "./FileUpload";
export { default as UNSAFE_FileUploadDropzone } from "./parts/dropzone/Dropzone";
export { default as FileUpload } from "./FileUpload";
export { default as FileUploadDropzone } from "./parts/dropzone/Dropzone";
export { type FileUploadDropzoneProps } from "./parts/dropzone/dropzone.types";
export {
default as UNSAFE_FileUploadTrigger,
default as FileUploadTrigger,
type FileUploadTriggerProps,
} from "./parts/Trigger";
export {
Expand All @@ -15,7 +15,7 @@ export {
type FileRejectionReason,
} from "./FileUpload.types";
export {
default as UNSAFE_FileUploadItem,
default as FileUploadItem,
type FileUploadItemProps,
} from "./parts/item/Item";
export { type FileItem, type FileMetadata } from "./parts/item/Item.types";
2 changes: 1 addition & 1 deletion @navikt/core/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export {
export { ErrorSummary, type ErrorSummaryProps } from "./form/error-summary";
export { Fieldset, type FieldsetProps } from "./form/fieldset";
export {
UNSAFE_FileUpload,
FileUpload,
type FileAccepted,
type FileItem,
type FileMetadata,
Expand Down
8 changes: 4 additions & 4 deletions aksel.nav.no/website/pages/eksempler/file-upload/default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
FileObject,
FileRejected,
FileRejectionReason,
FileUpload,
Heading,
UNSAFE_FileUpload,
VStack,
} from "@navikt/ds-react";
import { withDsExample } from "@/web/examples/withDsExample";
Expand All @@ -21,7 +21,7 @@ const Example = () => {

return (
<VStack gap="6">
<UNSAFE_FileUpload.Dropzone
<FileUpload.Dropzone
label="Last opp filer til søknaden"
description={`Du kan laste opp Word- og PDF-filer. Maks 3 filer. Maks størrelse ${MAX_SIZE_MB} MB.`}
accept=".doc,.docx,.pdf"
Expand All @@ -37,7 +37,7 @@ const Example = () => {
</Heading>
<VStack as="ul" gap="3">
{acceptedFiles.map((file, index) => (
<UNSAFE_FileUpload.Item
<FileUpload.Item
as="li"
key={index}
file={file.file}
Expand All @@ -57,7 +57,7 @@ const Example = () => {
</Heading>
<VStack as="ul" gap="3">
{rejectedFiles.map((rejected, index) => (
<UNSAFE_FileUpload.Item
<FileUpload.Item
as="li"
key={index}
file={rejected.file}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { UNSAFE_FileUpload, VStack } from "@navikt/ds-react";
import { FileUpload, VStack } from "@navikt/ds-react";
import { withDsExample } from "@/web/examples/withDsExample";

const Example = () => (
<VStack gap="12">
<UNSAFE_FileUpload.Dropzone
<FileUpload.Dropzone
label="Last opp filer"
onSelect={console.info}
disabled
/>

<UNSAFE_FileUpload.Dropzone
<FileUpload.Dropzone
label="Last opp filer"
onSelect={console.info}
fileLimit={{ max: 1, current: 1 }}
Expand Down
6 changes: 3 additions & 3 deletions aksel.nav.no/website/pages/eksempler/file-upload/error.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { UNSAFE_FileUpload, VStack } from "@navikt/ds-react";
import { FileUpload, VStack } from "@navikt/ds-react";
import { withDsExample } from "@/web/examples/withDsExample";

const Example = () => (
<VStack gap="12">
<UNSAFE_FileUpload.Dropzone
<FileUpload.Dropzone
label="Last opp filer"
onSelect={console.info}
error="Du må laste opp en fil"
/>

<UNSAFE_FileUpload.Item
<FileUpload.Item
file={{ name: "eksempel.png", size: 200000 }}
error="Filformatet støttes ikke"
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Heading, UNSAFE_FileUpload, VStack } from "@navikt/ds-react";
import { FileUpload, Heading, VStack } from "@navikt/ds-react";
import { withDsExample } from "@/web/examples/withDsExample";

const Example = () => (
<VStack gap="6">
<div>
<Heading size="small">retry</Heading>
<UNSAFE_FileUpload.Item
<FileUpload.Item
file={new File(["abc".repeat(100000)], "eksempel1.pdf")}
button={{
action: "retry",
Expand All @@ -15,7 +15,7 @@ const Example = () => (
</div>
<div>
<Heading size="small">delete</Heading>
<UNSAFE_FileUpload.Item
<FileUpload.Item
file={{ name: "eksempel2.pdf", size: 200000 }}
href="#"
button={{
Expand Down
6 changes: 3 additions & 3 deletions aksel.nav.no/website/pages/eksempler/file-upload/single.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { useState } from "react";
import { FileObject, UNSAFE_FileUpload, VStack } from "@navikt/ds-react";
import { FileObject, FileUpload, VStack } from "@navikt/ds-react";
import { withDsExample } from "@/web/examples/withDsExample";

const Example = () => {
const [files, setFiles] = useState<FileObject[]>([]);

return (
<VStack gap="6">
<UNSAFE_FileUpload.Dropzone
<FileUpload.Dropzone
label="Last opp fødselsattest"
fileLimit={{ max: 1, current: files.length }}
multiple={false}
onSelect={setFiles}
/>
{files.map((file) => (
<UNSAFE_FileUpload.Item
<FileUpload.Item
key={file.file.name}
file={file.file}
button={{
Expand Down
15 changes: 6 additions & 9 deletions aksel.nav.no/website/pages/eksempler/file-upload/translation.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Heading, UNSAFE_FileUpload, VStack } from "@navikt/ds-react";
import { FileUpload, Heading, VStack } from "@navikt/ds-react";
import { withDsExample } from "@/web/examples/withDsExample";

const Example = () => (
<UNSAFE_FileUpload
<FileUpload
translations={{
dropzone: {
dragAndDropMultiple: "Dra og slipp bilder i format .png",
Expand All @@ -14,21 +14,18 @@ const Example = () => (
}}
>
<VStack gap="6">
<UNSAFE_FileUpload.Dropzone
label="Last opp bilder"
onSelect={console.info}
/>
<FileUpload.Dropzone label="Last opp bilder" onSelect={console.info} />
<div>
<Heading level="3" size="xsmall" spacing>
Vedlegg
</Heading>
<VStack as="ul" gap="2">
<UNSAFE_FileUpload.Item
<FileUpload.Item
as="li"
file={{ name: "eksempel.png", size: 200000 }}
status="uploading"
/>
<UNSAFE_FileUpload.Item
<FileUpload.Item
as="li"
file={{ name: "eksempel.png", size: 200000 }}
status="uploading"
Expand All @@ -37,7 +34,7 @@ const Example = () => (
</VStack>
</div>
</VStack>
</UNSAFE_FileUpload>
</FileUpload>
);

// EXAMPLES DO NOT INCLUDE CONTENT BELOW THIS LINE
Expand Down
6 changes: 3 additions & 3 deletions aksel.nav.no/website/pages/eksempler/file-upload/trigger.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { UploadIcon } from "@navikt/aksel-icons";
import { Button, UNSAFE_FileUpload } from "@navikt/ds-react";
import { Button, FileUpload } from "@navikt/ds-react";
import { withDsExample } from "@/web/examples/withDsExample";

const Example = () => {
return (
<UNSAFE_FileUpload.Trigger multiple={false} onSelect={console.info}>
<FileUpload.Trigger multiple={false} onSelect={console.info}>
<Button variant="secondary" icon={<UploadIcon aria-hidden />}>
Last opp filer
</Button>
</UNSAFE_FileUpload.Trigger>
</FileUpload.Trigger>
);
};

Expand Down

0 comments on commit 324358d

Please sign in to comment.