Skip to content

Commit bdd6399

Browse files
committed
feat: list limit and overlay style
1 parent f8e871b commit bdd6399

File tree

14 files changed

+878
-228
lines changed

14 files changed

+878
-228
lines changed

packages/ui/src/components/FileInput/__stories__/Children.stories.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import { Text } from '../../Text'
44
import { FileInput } from '..'
55
import { hereText } from './styles.css'
66

7-
export const Children: StoryFn<typeof FileInput> = () => (
7+
export const Children: StoryFn<typeof FileInput> = args => (
88
<Stack direction="column" gap={2}>
99
<FileInput
1010
aria-label="label"
11+
disabled={args.disabled}
1112
list
1213
title={inputId => (
1314
<label htmlFor={inputId}>Click here to add a file (title)</label>
@@ -28,7 +29,13 @@ export const Children: StoryFn<typeof FileInput> = () => (
2829
</Stack>
2930
)}
3031
</FileInput>
31-
<FileInput aria-label="label-2" list variant="overlay">
32+
<FileInput
33+
aria-label="label-2"
34+
disabled={args.disabled}
35+
list
36+
title="drag here"
37+
variant="overlay"
38+
>
3239
{inputId => (
3340
<>
3441
Drag an drop on me or click{' '}

packages/ui/src/components/FileInput/__stories__/Controlled.stories.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import { Text } from '../../Text'
55
import { FileInput } from '..'
66
import type { FilesType } from '../types'
77

8-
export const Controlled: StoryFn<typeof FileInput> = () => {
8+
export const Controlled: StoryFn<typeof FileInput> = args => {
99
const [files, setFiles] = useState<FilesType[]>([])
1010
const onChange = (f: FilesType[]) => setFiles(f)
1111

1212
return (
1313
<Stack direction="column" gap={3}>
1414
<FileInput
1515
defaultFiles={[]}
16+
disabled={args.disabled}
1617
label="type='dropzone'"
1718
multiple
1819
onChangeFiles={onChange}

packages/ui/src/components/FileInput/__stories__/Disabled.stories.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { PlusIcon, UploadIcon } from '@ultraviolet/icons'
33
import { Stack } from '../../Stack'
44
import { FileInput } from '..'
55

6-
export const Disabled: StoryFn<typeof FileInput> = () => (
6+
export const Disabled: StoryFn<typeof FileInput> = args => (
77
<Stack direction="column" gap={2}>
88
<FileInput
9+
accept={args.accept}
910
disabled
1011
label="medium disabled"
1112
title="Drag and drop files to get started"
@@ -31,5 +32,18 @@ export const Disabled: StoryFn<typeof FileInput> = () => (
3132
title="Click or drag file to this area to upload"
3233
variant="dropzone"
3334
/>
35+
<FileInput
36+
aria-label="label"
37+
disabled
38+
title={
39+
<Stack direction="row" gap={1}>
40+
<UploadIcon />
41+
Click or drag file to this area to upload (disabled)
42+
</Stack>
43+
}
44+
variant="overlay"
45+
>
46+
Some content (drag on me)
47+
</FileInput>
3448
</Stack>
3549
)

packages/ui/src/components/FileInput/__stories__/DropzoneSize.stories.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { Link } from '../../Link'
44
import { Stack } from '../../Stack'
55
import { FileInput } from '..'
66

7-
export const DropzoneSize: StoryFn<typeof FileInput> = () => (
7+
export const DropzoneSize: StoryFn<typeof FileInput> = args => (
88
<Stack direction="column" gap={2}>
99
<FileInput
10+
disabled={args.disabled}
1011
label="medium"
1112
title="Drag and drop files to get started"
1213
variant="dropzone"
@@ -28,6 +29,7 @@ export const DropzoneSize: StoryFn<typeof FileInput> = () => (
2829
</Stack>
2930
</FileInput>
3031
<FileInput
32+
disabled={args.disabled}
3133
label="small"
3234
size="small"
3335
title="Click or drag file to this area to upload"

packages/ui/src/components/FileInput/__stories__/List.stories.tsx

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@ const defaultFile = [
1111
size: 30460,
1212
type: 'image/png',
1313
},
14-
{
15-
error: 'Maximum file size exceeded',
16-
file: 'error.png',
17-
fileName: 'error_example.png',
18-
lastModified: 1,
19-
size: 4046000000,
20-
type: 'image/png',
21-
},
2214
{
2315
file: 'sound.mp3',
2416
fileName: 'sound.mp3',
@@ -48,11 +40,20 @@ const defaultFile = [
4840
size: 40460000,
4941
type: 'application/pdf',
5042
},
43+
{
44+
error: 'Maximum file size exceeded',
45+
file: 'error.png',
46+
fileName: 'error_example.png',
47+
lastModified: 1,
48+
size: 4046000000,
49+
type: 'image/png',
50+
},
5151
]
52-
export const List: StoryFn<typeof FileInput> = () => (
52+
export const List: StoryFn<typeof FileInput> = args => (
5353
<Stack direction="column" gap={3}>
5454
<FileInput
5555
defaultFiles={defaultFile}
56+
disabled={args.disabled}
5657
label="type='dropzone'"
5758
list
5859
multiple
@@ -64,9 +65,11 @@ export const List: StoryFn<typeof FileInput> = () => (
6465
<FileInput
6566
aria-label="label"
6667
defaultFiles={defaultFile}
68+
disabled={args.disabled}
6769
list
6870
listPosition="top"
6971
multiple
72+
title="dnd here"
7073
variant="overlay"
7174
>
7275
Type &quot;ovelay&quot; (listPosition=&quot;top&quot;)
@@ -75,21 +78,35 @@ export const List: StoryFn<typeof FileInput> = () => (
7578
<FileInput
7679
aria-label="label"
7780
defaultFiles={defaultFile}
81+
disabled={args.disabled}
7882
list
7983
listPosition="bottom"
8084
multiple
85+
title="dnd here"
8186
variant="overlay"
8287
>
8388
Type &quot;ovelay&quot; (listPosition=&quot;bottom&quot;)
8489
</FileInput>
90+
<Separator />
91+
<FileInput
92+
defaultFiles={defaultFile}
93+
disabled={args.disabled}
94+
label="With prop listLimit"
95+
list
96+
listLimit={{ limit: 3, overflowText: 'See all' }}
97+
multiple
98+
size="small"
99+
title="Click or drag file here"
100+
variant="dropzone"
101+
/>
85102
</Stack>
86103
)
87104

88105
List.parameters = {
89106
docs: {
90107
description: {
91108
story:
92-
'With prop `list` it is possible to display all the drag&drop files added to the input. When using the FileInput as an overlay, it is possible to add the list on top or beneath the content using prop `listPosition`.',
109+
'With prop `list` it is possible to display all the drag&drop files added to the input. When using the FileInput as an overlay, it is possible to add the list on top or beneath the content using prop `listPosition`. Size is displayed and computed automatically from file.sie (number, in byte). It is also possible to add a limit to the number of visible files in the list using prop `listLimit`.',
93110
},
94111
},
95112
}

packages/ui/src/components/FileInput/__stories__/Multiple.stories.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ const defaultFile = [
1111
type: 'image/png',
1212
},
1313
]
14-
export const Multiple: StoryFn<typeof FileInput> = () => (
14+
export const Multiple: StoryFn<typeof FileInput> = args => (
1515
<Stack direction="column" gap={3}>
1616
<FileInput
1717
defaultFiles={defaultFile}
18+
disabled={args.disabled}
1819
label="Multiple"
1920
list
2021
multiple
@@ -24,6 +25,7 @@ export const Multiple: StoryFn<typeof FileInput> = () => (
2425
/>
2526
<FileInput
2627
defaultFiles={defaultFile}
28+
disabled={args.disabled}
2729
label="Not multiple (default behavior)"
2830
list
2931
size="small"

packages/ui/src/components/FileInput/__stories__/Overlay.stories.tsx

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,53 @@
11
import type { StoryFn } from '@storybook/react-vite'
2+
import { RebootIcon, SendIcon, UploadIcon } from '@ultraviolet/icons'
23
import { useRef, useState } from 'react'
34
import { Avatar } from '../../Avatar'
5+
import { Button } from '../../Button'
46
import { Stack } from '../../Stack'
7+
import { TextInput } from '../../TextInput'
58
import { FileInput } from '..'
9+
import { promptContainer, promptInput } from './styles.css'
610

7-
export const Overlay: StoryFn<typeof FileInput> = () => {
11+
const Prompt = ({ inputId }: { inputId: string }) => (
12+
<Stack
13+
className={promptContainer}
14+
direction="row"
15+
gap={0.5}
16+
width="fit-content"
17+
>
18+
<Button sentiment="neutral" size="medium">
19+
<label htmlFor={inputId}>
20+
<UploadIcon />
21+
</label>
22+
</Button>
23+
<TextInput
24+
className={promptInput}
25+
helper="this is an helper"
26+
placeholder="Placeholder"
27+
size="medium"
28+
/>
29+
<Button sentiment="neutral" size="medium">
30+
<RebootIcon />
31+
</Button>
32+
<Button sentiment="primary" size="medium">
33+
<SendIcon />
34+
</Button>
35+
</Stack>
36+
)
37+
38+
export const Overlay: StoryFn<typeof FileInput> = args => {
839
const [image, setImage] = useState<string | undefined>(undefined)
940
const inputRef = useRef<HTMLInputElement>(null)
1041

1142
return (
12-
<Stack direction="row" gap={2}>
13-
<FileInput aria-label="label" variant="overlay">
43+
<Stack direction="column" gap={2}>
44+
Drag files in here to see the component
45+
<FileInput
46+
aria-label="label"
47+
disabled={args.disabled}
48+
title="dnd here"
49+
variant="overlay"
50+
>
1451
{image ? (
1552
<Avatar
1653
image={image}
@@ -42,6 +79,24 @@ export const Overlay: StoryFn<typeof FileInput> = () => {
4279
<FileInput aria-label="label-2" title="Drop here" variant="overlay">
4380
Some content (this is also an overlay)
4481
</FileInput>
82+
<FileInput
83+
aria-label="prompt"
84+
list
85+
listPosition="top"
86+
title={
87+
<Stack
88+
alignItems="center"
89+
direction="row"
90+
gap={1}
91+
justifyContent="center"
92+
>
93+
<UploadIcon /> Drag file to this area to upload
94+
</Stack>
95+
}
96+
variant="overlay"
97+
>
98+
{inputId => <Prompt inputId={inputId} />}
99+
</FileInput>
45100
</Stack>
46101
)
47102
}

packages/ui/src/components/FileInput/__stories__/styles.css.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { theme } from '@ultraviolet/themes'
12
import { style } from '@vanilla-extract/css'
23

34
export const hereText = style({
@@ -8,3 +9,13 @@ export const hereText = style({
89
},
910
},
1011
})
12+
13+
export const promptContainer = style({
14+
padding: theme.space[3],
15+
paddingBottom: theme.space[1],
16+
background: theme.colors.neutral.backgroundWeak,
17+
border: `1px solid ${theme.colors.neutral.border}`,
18+
})
19+
export const promptInput = style({
20+
width: 500,
21+
})

0 commit comments

Comments
 (0)